File: kractionbase.cpp

package info (click to toggle)
krusader 2%3A2.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,448 kB
  • sloc: cpp: 56,112; ansic: 1,187; xml: 811; sh: 23; makefile: 3
file content (73 lines) | stat: -rw-r--r-- 2,061 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
    SPDX-FileCopyrightText: 2006 Shie Erlich <erlich@users.sourceforge.net>
    SPDX-FileCopyrightText: 2006 Rafi Yanai <yanai@users.sourceforge.net>
    SPDX-FileCopyrightText: 2006-2022 Krusader Krew <https://krusader.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "kractionbase.h"

// QtWidgets
#include <QInputDialog>

#include <KLocalizedString>
#include <KMessageBox>

#include "../krglobal.h"
#include "kraction.h"

KrActionBase::~KrActionBase() = default;

void KrActionBase::exec()
{
    KrActionProc *proc = nullptr;

    // replace %% and prepare string
    QStringList commandList;
    if (doSubstitution()) {
        Expander exp;
        exp.expand(command(), acceptURLs());
        if (exp.error()) {
            handleError(exp.error());
            return;
        }
        commandList = exp.result();
    } else
        commandList << command();
    // TODO: query expander for status and may skip the rest of the function

    // stop here if the commandline is empty
    if (commandList.count() == 1 && commandList[0].trimmed().isEmpty())
        return;

    if (confirmExecution()) {
        for (auto &it : commandList) {
            bool exec = true;
            it = QInputDialog::getText(krMainWindow, i18n("Confirm Execution"), i18n("Command being executed:"), QLineEdit::Normal, it, &exec);
            if (exec) {
                proc = actionProcFactoryMethod();
                proc->start(it);
            }
        } // for
    } // if ( _properties->confirmExecution() )
    else {
        proc = actionProcFactoryMethod();
        proc->start(commandList);
    }
}

void KrActionBase::handleError(const Error &err)
{
    // once qtHandler is instantiated, it keeps on showing all qDebug() messages
    // QErrorMessage::qtHandler()->showMessage(err.what());
    const QString &errorMessage = err.description();
    if (!errorMessage.isEmpty()) {
        KMessageBox::error(krMainWindow, errorMessage);
    }
}

KrActionProc *KrActionBase::actionProcFactoryMethod()
{
    return new KrActionProc(this);
}