Krazy/EBN: qMin is better than QMIN
[kphotoalbum.git] / MainWindow / RunDialog.cpp
blob1e6ab6d126a4637de32a7bfdb1e836841abd1afe
1 /* Copyright (C) 2009-2010 Wes Hardaker <kpa@capturedonearth.com>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "RunDialog.h"
20 #include <KDialog>
21 #include <QWidget>
22 #include <QLabel>
23 #include <QVBoxLayout>
24 #include <MainWindow/Window.h>
25 #include <klocale.h>
26 #include <krun.h>
27 #include <kshell.h>
29 MainWindow::RunDialog::RunDialog( QWidget* parent, QStringList fileList )
30 : KDialog( parent ), _fileList(fileList)
32 QWidget* top = new QWidget;
33 QVBoxLayout* layout = new QVBoxLayout( top );
34 setMainWidget(top);
36 QString txt = i18n("<p>Enter your command to run below:</p>"
37 "<p><i>%all will be replaced with a file list</i></p>");
38 QLabel* label = new QLabel(txt);
39 layout->addWidget(label);
41 _cmd = new QLineEdit();
42 layout->addWidget(_cmd);
43 txt = i18n("<p>Enter the command you want to run on your image file(s). "
44 "KPhotoAlbum will run your command and replace any '%all' tokens "
45 "with a list of your files. For example, if you entered:</p>"
46 "<ul><li>cp %all /tmp</li></ul>"
47 "<p>Then the files you selected would be copied to the /tmp "
48 "directory</p>"
49 "<p>You can also use %each to have a command be run once per "
50 "file.</p>");
51 _cmd->setWhatsThis(txt);
52 label->setWhatsThis(txt);
54 connect( this, SIGNAL( okClicked() ), this, SLOT( slotMarkGo() ) );
57 void MainWindow::RunDialog::slotMarkGo( )
59 QString cmdString = _cmd->text();
60 QRegExp replaceall = QRegExp(i18n("%all"));
61 QRegExp replaceeach = QRegExp(i18n("%each"));
63 // Replace the %all argument first
64 cmdString.replace(replaceall, KShell::joinArgs(_fileList));
66 if (cmdString.contains(replaceeach)) {
67 // cmdString should be run multiple times, once per "each"
68 QString cmdOnce;
69 for( QStringList::Iterator it = _fileList.begin(); it != _fileList.end(); ++it ) {
70 cmdOnce = cmdString;
71 cmdOnce.replace(replaceeach, *it);
72 KRun::runCommand(cmdOnce, MainWindow::Window::theMainWindow());
74 } else {
75 KRun::runCommand(cmdString, MainWindow::Window::theMainWindow());
80 void MainWindow::RunDialog::show()
82 KDialog::show();