File indexing completed on 2024-04-28 17:06:31
0001 /* 0002 SPDX-FileCopyrightText: 2006 Shie Erlich <erlich@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2006 Rafi Yanai <yanai@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2006-2022 Krusader Krew <https://krusader.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "kractionbase.h" 0010 0011 // QtWidgets 0012 #include <QInputDialog> 0013 0014 #include <KI18n/KLocalizedString> 0015 #include <KWidgetsAddons/KMessageBox> 0016 0017 #include "../krglobal.h" 0018 #include "kraction.h" 0019 0020 KrActionBase::~KrActionBase() = default; 0021 0022 void KrActionBase::exec() 0023 { 0024 KrActionProc *proc = nullptr; 0025 0026 // replace %% and prepare string 0027 QStringList commandList; 0028 if (doSubstitution()) { 0029 Expander exp; 0030 exp.expand(command(), acceptURLs()); 0031 if (exp.error()) { 0032 handleError(exp.error()); 0033 return; 0034 } 0035 commandList = exp.result(); 0036 } else 0037 commandList << command(); 0038 // TODO: query expander for status and may skip the rest of the function 0039 0040 // stop here if the commandline is empty 0041 if (commandList.count() == 1 && commandList[0].trimmed().isEmpty()) 0042 return; 0043 0044 if (confirmExecution()) { 0045 for (auto &it : commandList) { 0046 bool exec = true; 0047 it = QInputDialog::getText(krMainWindow, i18n("Confirm Execution"), i18n("Command being executed:"), QLineEdit::Normal, it, &exec); 0048 if (exec) { 0049 proc = actionProcFactoryMethod(); 0050 proc->start(it); 0051 } 0052 } // for 0053 } // if ( _properties->confirmExecution() ) 0054 else { 0055 proc = actionProcFactoryMethod(); 0056 proc->start(commandList); 0057 } 0058 } 0059 0060 void KrActionBase::handleError(const Error &err) 0061 { 0062 // once qtHandler is instantiated, it keeps on showing all qDebug() messages 0063 // QErrorMessage::qtHandler()->showMessage(err.what()); 0064 const QString &errorMessage = err.description(); 0065 if (!errorMessage.isEmpty()) { 0066 KMessageBox::error(krMainWindow, errorMessage); 0067 } 0068 } 0069 0070 KrActionProc *KrActionBase::actionProcFactoryMethod() 0071 { 0072 return new KrActionProc(this); 0073 }