diff --git a/krusader/ActionMan/actionman.cpp b/krusader/ActionMan/actionman.cpp index 69bd3c44..861108d8 100644 --- a/krusader/ActionMan/actionman.cpp +++ b/krusader/ActionMan/actionman.cpp @@ -1,84 +1,85 @@ /***************************************************************************** * Copyright (C) 2006 Jonas Bähr * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "actionman.h" -#include -#include -#include +// QtWidgets +#include +#include +#include #include #include #include "useractionpage.h" #include "../krusader.h" #include "../UserAction/useraction.h" ActionMan::ActionMan(QWidget * parent) : QDialog(parent) { setWindowModality(Qt::WindowModal); setWindowTitle(i18n("ActionMan - Manage Your Useractions")); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); userActionPage = new UserActionPage(this); mainLayout->addWidget(userActionPage); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close|QDialogButtonBox::Apply); mainLayout->addWidget(buttonBox); applyButton = buttonBox->button(QDialogButtonBox::Apply); applyButton->setEnabled(false); connect(buttonBox, SIGNAL(rejected()), SLOT(slotClose())); connect(applyButton, SIGNAL(clicked()), SLOT(slotApply())); connect(userActionPage, SIGNAL(changed()), SLOT(slotEnableApplyButton())); connect(userActionPage, SIGNAL(applied()), SLOT(slotDisableApplyButton())); exec(); krApp->updateUserActions(); } ActionMan::~ActionMan() { } void ActionMan::slotClose() { if (userActionPage->readyToQuit()) reject(); } void ActionMan::slotApply() { userActionPage->applyChanges(); } void ActionMan::slotEnableApplyButton() { applyButton->setEnabled(true); } void ActionMan::slotDisableApplyButton() { applyButton->setEnabled(false); } diff --git a/krusader/ActionMan/actionman.h b/krusader/ActionMan/actionman.h index 1c9936f4..7becccc5 100644 --- a/krusader/ActionMan/actionman.h +++ b/krusader/ActionMan/actionman.h @@ -1,47 +1,48 @@ /***************************************************************************** * Copyright (C) 2006 Jonas Bähr * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef ACTIONMAN_H #define ACTIONMAN_H -#include +// QtWidgets +#include class UserActionPage; /** * This manages all useractions */ class ActionMan : public QDialog { Q_OBJECT public: ActionMan(QWidget* parent = 0); ~ActionMan(); protected slots: void slotClose(); void slotApply(); void slotEnableApplyButton(); void slotDisableApplyButton(); private: UserActionPage* userActionPage; QPushButton *applyButton; }; #endif // ifndef ACTIONMAN_H diff --git a/krusader/ActionMan/actionproperty.cpp b/krusader/ActionMan/actionproperty.cpp index 5e608f67..65c92887 100644 --- a/krusader/ActionMan/actionproperty.cpp +++ b/krusader/ActionMan/actionproperty.cpp @@ -1,517 +1,518 @@ /***************************************************************************** * Copyright (C) 2004-2007 Jonas Bähr * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "actionproperty.h" #include "addplaceholderpopup.h" #include "../UserAction/useraction.h" #include "../UserAction/kraction.h" #include "../krusader.h" #include "../krglobal.h" -#include -#include +// QtWidgets +#include +#include #include #include #include #include #define ICON(N) KIconLoader::global()->loadIcon(N, KIconLoader::Small) ActionProperty::ActionProperty(QWidget *parent, KrAction *action) : QWidget(parent), _modified(false) { setupUi(this); if (action) { _action = action; updateGUI(_action); } ButtonAddPlaceholder->setIcon(ICON("list-add")); ButtonAddStartpath->setIcon(ICON("document-open")); // fill with all existing categories cbCategory->addItems(krUserAction->allCategories()); connect(ButtonAddPlaceholder, SIGNAL(clicked()), this, SLOT(addPlaceholder())); connect(ButtonAddStartpath, SIGNAL(clicked()), this, SLOT(addStartpath())); connect(ButtonNewProtocol, SIGNAL(clicked()), this, SLOT(newProtocol())); connect(ButtonEditProtocol, SIGNAL(clicked()), this, SLOT(editProtocol())); connect(ButtonRemoveProtocol, SIGNAL(clicked()), this, SLOT(removeProtocol())); connect(ButtonAddPath, SIGNAL(clicked()), this, SLOT(addPath())); connect(ButtonEditPath, SIGNAL(clicked()), this, SLOT(editPath())); connect(ButtonRemovePath, SIGNAL(clicked()), this, SLOT(removePath())); connect(ButtonAddMime, SIGNAL(clicked()), this, SLOT(addMime())); connect(ButtonEditMime, SIGNAL(clicked()), this, SLOT(editMime())); connect(ButtonRemoveMime, SIGNAL(clicked()), this, SLOT(removeMime())); connect(ButtonNewFile, SIGNAL(clicked()), this, SLOT(newFile())); connect(ButtonEditFile, SIGNAL(clicked()), this, SLOT(editFile())); connect(ButtonRemoveFile, SIGNAL(clicked()), this, SLOT(removeFile())); connect(KeyButtonShortcut, SIGNAL(keySequenceChanged(const QKeySequence&)), this, SLOT(changedShortcut(const QKeySequence &))); // track modifications: connect(leDistinctName, SIGNAL(textChanged(const QString&)), SLOT(setModified())); connect(leTitle, SIGNAL(textChanged(const QString&)), SLOT(setModified())); connect(ButtonIcon, SIGNAL(iconChanged(QString)), SLOT(setModified())); connect(cbCategory, SIGNAL(currentTextChanged(QString)), SLOT(setModified())); connect(leTooltip, SIGNAL(textChanged(const QString&)), SLOT(setModified())); connect(textDescription, SIGNAL(textChanged()), SLOT(setModified())); connect(leCommandline, SIGNAL(textChanged(const QString&)), SLOT(setModified())); connect(leStartpath, SIGNAL(textChanged(const QString&)), SLOT(setModified())); connect(chkSeparateStdError, SIGNAL(clicked()), SLOT(setModified())); connect(radioCollectOutput, SIGNAL(clicked()), SLOT(setModified())); connect(radioNormal, SIGNAL(clicked()), SLOT(setModified())); connect(radioTE, SIGNAL(clicked()), SLOT(setModified())); connect(radioTerminal, SIGNAL(clicked()), SLOT(setModified())); connect(radioLocal, SIGNAL(clicked()), SLOT(setModified())); connect(radioUrl, SIGNAL(clicked()), SLOT(setModified())); connect(KeyButtonShortcut, SIGNAL(keySequenceChanged(const QKeySequence&)), SLOT(setModified())); connect(chkEnabled, SIGNAL(clicked()), SLOT(setModified())); connect(leDifferentUser, SIGNAL(textChanged(const QString&)), SLOT(setModified())); connect(chkDifferentUser, SIGNAL(clicked()), SLOT(setModified())); connect(chkConfirmExecution, SIGNAL(clicked()), SLOT(setModified())); connect(chkSeparateStdError, SIGNAL(clicked()), SLOT(setModified())); // The modified-state of the ShowOnly-lists is tracked in the access-functions below } ActionProperty::~ActionProperty() { } void ActionProperty::changedShortcut(const QKeySequence& shortcut) { KeyButtonShortcut->setKeySequence(shortcut); } void ActionProperty::clear() { _action = 0; // This prevents the changed-signal from being emitted during the GUI-update _modified = true; // The real state is set at the end of this function. leDistinctName->clear(); cbCategory->clearEditText(); leTitle->clear(); leTooltip->clear(); textDescription->clear(); leCommandline->clear(); leStartpath->clear(); KeyButtonShortcut->clearKeySequence(); lbShowonlyProtocol->clear(); lbShowonlyPath->clear(); lbShowonlyMime->clear(); lbShowonlyFile->clear(); chkSeparateStdError->setChecked(false); radioNormal->setChecked(true); radioLocal->setChecked(true); chkEnabled->setChecked(true); chkConfirmExecution->setChecked(false); ButtonIcon->resetIcon(); leDifferentUser->clear(); chkDifferentUser->setChecked(false); setModified(false); } void ActionProperty::updateGUI(KrAction *action) { if (action) _action = action; if (! _action) return; // This prevents the changed-signal from being emitted during the GUI-update. _modified = true; // The real state is set at the end of this function. leDistinctName->setText(_action->objectName()); cbCategory->lineEdit()->setText(_action->category()); leTitle->setText(_action->text()); leTooltip->setText(_action->toolTip()); textDescription->setText(_action->whatsThis()); leCommandline->setText(_action->command()); leCommandline->home(false); leStartpath->setText(_action->startpath()); KeyButtonShortcut->setKeySequence(_action->shortcut()); lbShowonlyProtocol->clear(); lbShowonlyProtocol->addItems(_action->showonlyProtocol()); lbShowonlyPath->clear(); lbShowonlyPath->addItems(_action->showonlyPath()); lbShowonlyMime->clear(); lbShowonlyMime->addItems(_action->showonlyMime()); lbShowonlyFile->clear(); lbShowonlyFile->addItems(_action->showonlyFile()); chkSeparateStdError->setChecked(false); switch (_action->execType()) { case KrAction::CollectOutputSeparateStderr: chkSeparateStdError->setChecked(true); radioCollectOutput->setChecked(true); break; case KrAction::CollectOutput: radioCollectOutput->setChecked(true); break; case KrAction::Terminal: radioTerminal->setChecked(true); break; case KrAction::RunInTE: radioTE->setChecked(true); break; default: // case KrAction::Normal: radioNormal->setChecked(true); break; } if (_action->acceptURLs()) radioUrl->setChecked(true); else radioLocal->setChecked(true); chkEnabled->setChecked(_action->isVisible()); chkConfirmExecution->setChecked(_action->confirmExecution()); if (! _action->icon().isNull()) ButtonIcon->setIcon(_action->icon()); else ButtonIcon->resetIcon(); leDifferentUser->setText(_action->user()); if (_action->user().isEmpty()) chkDifferentUser->setChecked(false); else chkDifferentUser->setChecked(true); setModified(false); } void ActionProperty::updateAction(KrAction *action) { if (action) _action = action; if (! _action) return; if (_action->category() != cbCategory->currentText()) { _action->setCategory(cbCategory->currentText()); // Update the category-list cbCategory->clear(); cbCategory->addItems(krUserAction->allCategories()); cbCategory->lineEdit()->setText(_action->category()); } _action->setObjectName(leDistinctName->text()); _action->setText(leTitle->text()); _action->setToolTip(leTooltip->text()); _action->setWhatsThis(textDescription->toPlainText()); _action->setCommand(leCommandline->text()); _action->setStartpath(leStartpath->text()); _action->setShortcut(KeyButtonShortcut->keySequence()); QStringList list; for (int i1 = 0; i1 != lbShowonlyProtocol->count(); i1++) { QListWidgetItem* lbi = lbShowonlyProtocol->item(i1); list << lbi->text(); } _action->setShowonlyProtocol(list); list = QStringList(); for (int i1 = 0; i1 != lbShowonlyPath->count(); i1++) { QListWidgetItem* lbi = lbShowonlyPath->item(i1); list << lbi->text(); } _action->setShowonlyPath(list); list = QStringList(); for (int i1 = 0; i1 != lbShowonlyMime->count(); i1++) { QListWidgetItem* lbi = lbShowonlyMime->item(i1); list << lbi->text(); } _action->setShowonlyMime(list); list = QStringList(); for (int i1 = 0; i1 != lbShowonlyFile->count(); i1++) { QListWidgetItem* lbi = lbShowonlyFile->item(i1); list << lbi->text(); } _action->setShowonlyFile(list); if (radioCollectOutput->isChecked() && chkSeparateStdError->isChecked()) _action->setExecType(KrAction::CollectOutputSeparateStderr); else if (radioCollectOutput->isChecked() && ! chkSeparateStdError->isChecked()) _action->setExecType(KrAction::CollectOutput); else if (radioTerminal->isChecked()) _action->setExecType(KrAction::Terminal); else if (radioTE->isChecked()) _action->setExecType(KrAction::RunInTE); else _action->setExecType(KrAction::Normal); if (radioUrl->isChecked()) _action->setAcceptURLs(true); else _action->setAcceptURLs(false); _action->setEnabled(chkEnabled->isChecked()); _action->setVisible(chkEnabled->isChecked()); _action->setConfirmExecution(chkConfirmExecution->isChecked()); _action->setIcon(QIcon::fromTheme(ButtonIcon->icon())); _action->setIconName(ButtonIcon->icon()); _action->setUser(leDifferentUser->text()); setModified(false); } void ActionProperty::addPlaceholder() { AddPlaceholderPopup popup(this); QString exp = popup.getPlaceholder(mapToGlobal( QPoint( ButtonAddPlaceholder->pos().x() + ButtonAddPlaceholder->width() + 6, // 6 is the default margin ButtonAddPlaceholder->pos().y() ) )); leCommandline->insert(exp); } void ActionProperty::addStartpath() { QString folder = QFileDialog::getExistingDirectory(this); if (!folder.isEmpty()) { leStartpath->setText(folder); } } void ActionProperty::newProtocol() { bool ok; QString currentText; if (lbShowonlyProtocol->currentItem()) currentText = lbShowonlyProtocol->currentItem()->text(); QString text = QInputDialog::getText(this, i18n("New protocol"), i18n("Set a protocol:"), QLineEdit::Normal, currentText, &ok); if (ok && !text.isEmpty()) { lbShowonlyProtocol->addItems(text.split(';')); setModified(); } } void ActionProperty::editProtocol() { if (lbShowonlyProtocol->currentItem() == 0) return; bool ok; QString currentText = lbShowonlyProtocol->currentItem()->text(); QString text = QInputDialog::getText(this, i18n("Edit Protocol"), i18n("Set another protocol:"), QLineEdit::Normal, currentText, &ok); if (ok && !text.isEmpty()) { lbShowonlyProtocol->currentItem()->setText(text); setModified(); } } void ActionProperty::removeProtocol() { if (lbShowonlyProtocol->currentItem() != 0) { delete lbShowonlyProtocol->currentItem(); setModified(); } } void ActionProperty::addPath() { QString folder = QFileDialog::getExistingDirectory(this); if (!folder.isEmpty()) { lbShowonlyPath->addItem(folder); setModified(); } } void ActionProperty::editPath() { if (lbShowonlyPath->currentItem() == 0) return; bool ok; QString currentText = lbShowonlyPath->currentItem()->text(); QString text = QInputDialog::getText(this, i18n("Edit Path"), i18n("Set another path:"), QLineEdit::Normal, currentText, &ok); if (ok && !text.isEmpty()) { lbShowonlyPath->currentItem()->setText(text); setModified(); } } void ActionProperty::removePath() { if (lbShowonlyPath->currentItem() != 0) { delete lbShowonlyPath->currentItem(); setModified(); } } void ActionProperty::addMime() { bool ok; QString currentText; if (lbShowonlyMime->currentItem()) currentText = lbShowonlyMime->currentItem()->text(); QString text = QInputDialog::getText(this, i18n("New MIME Type"), i18n("Set a MIME type:"), QLineEdit::Normal, currentText, &ok); if (ok && !text.isEmpty()) { lbShowonlyMime->addItems(text.split(';')); setModified(); } } void ActionProperty::editMime() { if (lbShowonlyMime->currentItem() == 0) return; bool ok; QString currentText = lbShowonlyMime->currentItem()->text(); QString text = QInputDialog::getText(this, i18n("Edit MIME Type"), i18n("Set another MIME type:"), QLineEdit::Normal, currentText, &ok); if (ok && !text.isEmpty()) { lbShowonlyMime->currentItem()->setText(text); setModified(); } } void ActionProperty::removeMime() { if (lbShowonlyMime->currentItem() != 0) { delete lbShowonlyMime->currentItem(); setModified(); } } void ActionProperty::newFile() { bool ok; QString currentText; if (lbShowonlyFile->currentItem()) currentText = lbShowonlyFile->currentItem()->text(); QString text = QInputDialog::getText(this, i18n("New File Name"), i18n("Set a file name:"), QLineEdit::Normal, currentText, &ok); if (ok && !text.isEmpty()) { lbShowonlyFile->addItems(text.split(';')); setModified(); } } void ActionProperty::editFile() { if (lbShowonlyFile->currentItem() == 0) return; bool ok; QString currentText = lbShowonlyFile->currentItem()->text(); QString text = QInputDialog::getText(this, i18n("Edit File Name"), i18n("Set another file name:"), QLineEdit::Normal, currentText, &ok); if (ok && !text.isEmpty()) { lbShowonlyFile->currentItem()->setText(text); setModified(); } } void ActionProperty::removeFile() { if (lbShowonlyFile->currentItem() != 0) { delete lbShowonlyFile->currentItem(); setModified(); } } bool ActionProperty::validProperties() { if (leDistinctName->text().simplified().isEmpty()) { KMessageBox::error(this, i18n("Please set a unique name for the useraction")); leDistinctName->setFocus(); return false; } if (leTitle->text().simplified().isEmpty()) { KMessageBox::error(this, i18n("Please set a title for the menu entry")); leTitle->setFocus(); return false; } if (leCommandline->text().simplified().isEmpty()) { KMessageBox::error(this, i18n("Command line is empty")); leCommandline->setFocus(); return false; } if (leDistinctName->isEnabled()) if (krApp->actionCollection()->action(leDistinctName->text())) { KMessageBox::error(this, i18n("There already is an action with this name.\n" "If you do not have such a useraction the name is used by Krusader for an internal action.") ); leDistinctName->setFocus(); return false; } return true; } void ActionProperty::setModified(bool m) { if (m && !_modified) { // emit only when the state _changes_to_true_, emit changed(); } _modified = m; } diff --git a/krusader/ActionMan/addplaceholderpopup.cpp b/krusader/ActionMan/addplaceholderpopup.cpp index c52815b5..027aa83a 100644 --- a/krusader/ActionMan/addplaceholderpopup.cpp +++ b/krusader/ActionMan/addplaceholderpopup.cpp @@ -1,700 +1,701 @@ /***************************************************************************** * Copyright (C) 2004 Shie Erlich * * Copyright (C) 2004 Rafi Yanai * * Copyright (C) Jonas Bähr * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "addplaceholderpopup.h" #include "../UserAction/expander.h" // for ParameterDialog #include "../krglobal.h" // for konfig-access #include "../BookMan/krbookmarkbutton.h" #include "../GUI/profilemanager.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +// QtWidgets +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include #include #define ACTIVE_MASK 0x0100 #define OTHER_MASK 0x0200 #define LEFT_MASK 0x0400 #define RIGHT_MASK 0x0800 #define INDEPENDENT_MASK 0x1000 #define EXECUTABLE_ID 0xFFFF AddPlaceholderPopup::AddPlaceholderPopup(QWidget *parent) : QMenu(parent) { _activeSub = new QMenu(i18n("Active panel"), this); _otherSub = new QMenu(i18n("Other panel"), this); _leftSub = new QMenu(i18n("Left panel"), this); _rightSub = new QMenu(i18n("Right panel"), this); _independentSub = new QMenu(i18n("Panel independent"), this); addMenu(_activeSub); addMenu(_otherSub); addMenu(_leftSub); addMenu(_rightSub); addMenu(_independentSub); QAction *chooseExecAct = _independentSub->addAction(i18n("Choose executable...")); chooseExecAct->setData(QVariant(EXECUTABLE_ID)); _independentSub->addSeparator(); // read the expressions array from the user menu and populate menus Expander expander; for (int i = 0; i < expander.placeholderCount(); ++i) { if (expander.placeholder(i)->expression().isEmpty()) { if (expander.placeholder(i)->needPanel()) { _activeSub->addSeparator(); _otherSub->addSeparator(); _leftSub->addSeparator(); _rightSub->addSeparator(); } else _independentSub->addSeparator(); } else { QAction * action; if (expander.placeholder(i)->needPanel()) { action = _activeSub->addAction(i18n(expander.placeholder(i)->description().toUtf8())); action->setData(QVariant(i | ACTIVE_MASK)); action = _otherSub->addAction(i18n(expander.placeholder(i)->description().toUtf8())); action->setData(QVariant(i | OTHER_MASK)); action = _leftSub->addAction(i18n(expander.placeholder(i)->description().toUtf8())); action->setData(QVariant(i | LEFT_MASK)); action = _rightSub->addAction(i18n(expander.placeholder(i)->description().toUtf8())); action->setData(QVariant(i | RIGHT_MASK)); } else { action = _independentSub->addAction(i18n(expander.placeholder(i)->description().toUtf8())); action->setData(QVariant(i | INDEPENDENT_MASK)); } } } } QString AddPlaceholderPopup::getPlaceholder(const QPoint& pos) { QAction *res = exec(pos); if (res == 0) return QString(); // add the selected flag to the command line if (res->data().toInt() == EXECUTABLE_ID) { // did the user need an executable ? // select an executable QString filename = QFileDialog::getOpenFileName(this); if (!filename.isEmpty()) { return filename + ' '; // with extra space // return filename; // without extra space } } else { // user selected something from the menus Expander expander; const exp_placeholder* currentPlaceholder = expander.placeholder(res->data().toInt() & ~(ACTIVE_MASK | OTHER_MASK | LEFT_MASK | RIGHT_MASK | INDEPENDENT_MASK)); // if ( ¤tPlaceholder->expFunc == 0 ) { // KMessageBox::sorry( this, "BOFH Excuse #93:\nFeature not yet implemented" ); // return QString(); // } ParameterDialog* parameterDialog = new ParameterDialog(currentPlaceholder, this); QString panel, parameter = parameterDialog->getParameter(); delete parameterDialog; // indicate the panel with 'a' 'o', 'l', 'r' or '_'. if (res->data().toInt() & ACTIVE_MASK) panel = 'a'; else if (res->data().toInt() & OTHER_MASK) panel = 'o'; else if (res->data().toInt() & LEFT_MASK) panel = 'l'; else if (res->data().toInt() & RIGHT_MASK) panel = 'r'; else if (res->data().toInt() & INDEPENDENT_MASK) panel = '_'; //return '%' + panel + currentPlaceholder->expression() + parameter + "% "; // with extra space return '%' + panel + currentPlaceholder->expression() + parameter + '%'; // without extra space } return QString(); } //////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////// ParameterDialog //////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// ParameterDialog::ParameterDialog(const exp_placeholder* currentPlaceholder, QWidget *parent) : QDialog(parent) { setWindowTitle(i18n("User Action Parameter Dialog")); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); _parameter.clear(); _parameterCount = currentPlaceholder->parameterCount(); QWidget *page = new QWidget(this); mainLayout->addWidget(page); QVBoxLayout* layout = new QVBoxLayout(page); layout->setSpacing(11); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n("This placeholder allows some parameter:"), page)); for (int i = 0; i < _parameterCount; ++i) { if (currentPlaceholder->parameter(i).preset() == "__placeholder") _parameter.append(new ParameterPlaceholder(currentPlaceholder->parameter(i), page)); else if (currentPlaceholder->parameter(i).preset() == "__yes") _parameter.append(new ParameterYes(currentPlaceholder->parameter(i), page)); else if (currentPlaceholder->parameter(i).preset() == "__no") _parameter.append(new ParameterNo(currentPlaceholder->parameter(i), page)); else if (currentPlaceholder->parameter(i).preset() == "__file") _parameter.append(new ParameterFile(currentPlaceholder->parameter(i), page)); else if (currentPlaceholder->parameter(i).preset().indexOf("__choose") != -1) _parameter.append(new ParameterChoose(currentPlaceholder->parameter(i), page)); else if (currentPlaceholder->parameter(i).preset() == "__select") _parameter.append(new ParameterSelect(currentPlaceholder->parameter(i), page)); else if (currentPlaceholder->parameter(i).preset() == "__goto") _parameter.append(new ParameterGoto(currentPlaceholder->parameter(i), page)); else if (currentPlaceholder->parameter(i).preset() == "__syncprofile") _parameter.append(new ParameterSyncprofile(currentPlaceholder->parameter(i), page)); else if (currentPlaceholder->parameter(i).preset() == "__searchprofile") _parameter.append(new ParameterSearch(currentPlaceholder->parameter(i), page)); else if (currentPlaceholder->parameter(i).preset() == "__panelprofile") _parameter.append(new ParameterPanelprofile(currentPlaceholder->parameter(i), page)); else if (currentPlaceholder->parameter(i).preset().indexOf("__int") != -1) _parameter.append(new ParameterInt(currentPlaceholder->parameter(i), page)); else _parameter.append(new ParameterText(currentPlaceholder->parameter(i), page)); layout->addWidget(_parameter.last()); } QFrame * line = new QFrame(page); line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken); layout->addWidget(line); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults); mainLayout->addWidget(buttonBox); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(okButton, SIGNAL(clicked()), this, SLOT(slotOk())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), this, SLOT(reset())); } QString ParameterDialog::getParameter() { if (_parameterCount == 0) // meaning no parameters return QString(); if (exec() == -1) return QString(); int lastParameter = _parameterCount; while (--lastParameter > -1) { if (_parameter[ lastParameter ]->text() != _parameter[ lastParameter ]->preset() || _parameter[ lastParameter ]->necessary()) break; } if (lastParameter < 0) // all parameters have default-values return QString(); QString parameter; for (int i = 0; i <= lastParameter; ++i) { if (i > 0) parameter += ", "; parameter += "\"" + _parameter[ i ]->text().replace("\"", "\\\"") + "\""; } return '(' + parameter + ')'; } void ParameterDialog::reset() { for (int i = 0; i < _parameterCount; ++i) _parameter[ i ]->reset(); } void ParameterDialog::slotOk() { bool valid = true; for (int i = 0; i < _parameterCount; ++i) { if (_parameter[ i ]->necessary() && ! _parameter[ i ]->valid()) valid = false; } if (valid) accept(); } ///////////// ParameterText ParameterText::ParameterText(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this)); layout->addWidget(_lineEdit = new KLineEdit(parameter.preset(), this)); _preset = parameter.preset(); } QString ParameterText::text() { return _lineEdit->text(); } QString ParameterText::preset() { return _preset; } void ParameterText::reset() { _lineEdit->setText(_preset); } bool ParameterText::valid() { if (_lineEdit->text().isEmpty()) return false; else return true; } ///////////// ParameterPlaceholder ParameterPlaceholder::ParameterPlaceholder(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this)); QWidget * hboxWidget = new QWidget(this); layout->addWidget(hboxWidget); QHBoxLayout * hbox = new QHBoxLayout(hboxWidget); hbox->setContentsMargins(0, 0, 0, 0); hbox->setSpacing(6); _lineEdit = new KLineEdit(hboxWidget); hbox->addWidget(_lineEdit); _button = new QToolButton(hboxWidget); _button->setIcon(QIcon::fromTheme("list-add")); hbox->addWidget(_button); connect(_button, SIGNAL(clicked()), this, SLOT(addPlaceholder())); } QString ParameterPlaceholder::text() { return _lineEdit->text(); } QString ParameterPlaceholder::preset() { return QString(); } void ParameterPlaceholder::reset() { _lineEdit->setText(QString()); } bool ParameterPlaceholder::valid() { if (_lineEdit->text().isEmpty()) return false; else return true; } void ParameterPlaceholder::addPlaceholder() { AddPlaceholderPopup* popup = new AddPlaceholderPopup(this); QString exp = popup->getPlaceholder(mapToGlobal(QPoint(_button->pos().x() + _button->width() + 6, _button->pos().y() + _button->height() / 2))); _lineEdit->insert(exp); delete popup; } ///////////// ParameterYes ParameterYes::ParameterYes(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(_checkBox = new QCheckBox(i18n(parameter.description().toUtf8()), this)); _checkBox->setChecked(true); } QString ParameterYes::text() { if (_checkBox->isChecked()) return QString(); else return "No"; } QString ParameterYes::preset() { return QString(); } void ParameterYes::reset() { _checkBox->setChecked(true); } bool ParameterYes::valid() { return true; } ///////////// ParameterNo ParameterNo::ParameterNo(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(_checkBox = new QCheckBox(i18n(parameter.description().toUtf8()), this)); _checkBox->setChecked(false); } QString ParameterNo::text() { if (_checkBox->isChecked()) return "Yes"; else return QString(); } QString ParameterNo::preset() { return QString(); } void ParameterNo::reset() { _checkBox->setChecked(false); } bool ParameterNo::valid() { return true; } ///////////// ParameterFile ParameterFile::ParameterFile(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this)); QWidget * hboxWidget = new QWidget(this); layout->addWidget(hboxWidget); QHBoxLayout * hbox = new QHBoxLayout(hboxWidget); hbox->setContentsMargins(0, 0, 0, 0); hbox->setSpacing(6); _lineEdit = new KLineEdit(hboxWidget); hbox->addWidget(_lineEdit); _button = new QToolButton(hboxWidget); hbox->addWidget(_button); _button->setIcon(QIcon::fromTheme("document-open")); connect(_button, SIGNAL(clicked()), this, SLOT(addFile())); } QString ParameterFile::text() { return _lineEdit->text(); } QString ParameterFile::preset() { return QString(); } void ParameterFile::reset() { _lineEdit->setText(QString()); } bool ParameterFile::valid() { if (_lineEdit->text().isEmpty()) return false; else return true; } void ParameterFile::addFile() { QString filename = QFileDialog::getOpenFileName(this); _lineEdit->insert(filename); } ///////////// ParameterChoose ParameterChoose::ParameterChoose(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this)); layout->addWidget(_combobox = new KComboBox(this)); _combobox->addItems(parameter.preset().section(':', 1).split(';')); } QString ParameterChoose::text() { return _combobox->currentText(); } QString ParameterChoose::preset() { return _combobox->itemText(0); } void ParameterChoose::reset() { _combobox->setCurrentIndex(0); } bool ParameterChoose::valid() { return true; } ///////////// ParameterSelect ParameterSelect::ParameterSelect(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this)); layout->addWidget(_combobox = new KComboBox(this)); _combobox->setEditable(true); KConfigGroup group(krConfig, "Private"); QStringList lst = group.readEntry("Predefined Selections", QStringList()); if (lst.size() > 0) _combobox->addItems(lst); _combobox->lineEdit()->setText("*"); } QString ParameterSelect::text() { return _combobox->currentText(); } QString ParameterSelect::preset() { return "*"; } void ParameterSelect::reset() { _combobox->lineEdit()->setText("*"); } bool ParameterSelect::valid() { return true; } ///////////// ParameterGoto ParameterGoto::ParameterGoto(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this)); QWidget * hboxWidget = new QWidget(this); QHBoxLayout * hbox = new QHBoxLayout(hboxWidget); hbox->setContentsMargins(0, 0, 0, 0); hbox->setSpacing(6); _lineEdit = new KLineEdit(hboxWidget); _lineEdit->setCompletionObject(new KUrlCompletion(KUrlCompletion::DirCompletion)); hbox->addWidget(_lineEdit); _dirButton = new QToolButton(hboxWidget); hbox->addWidget(_dirButton); _dirButton->setIcon(QIcon::fromTheme("document-open")); connect(_dirButton, SIGNAL(clicked()), this, SLOT(setDir())); _placeholderButton = new QToolButton(hboxWidget); _placeholderButton->setIcon(QIcon::fromTheme("list-add")); hbox->addWidget(_placeholderButton); connect(_placeholderButton, SIGNAL(clicked()), this, SLOT(addPlaceholder())); layout->addWidget(hboxWidget); } QString ParameterGoto::text() { return _lineEdit->text(); } QString ParameterGoto::preset() { return QString(); } void ParameterGoto::reset() { _lineEdit->setText(QString()); } bool ParameterGoto::valid() { if (_lineEdit->text().isEmpty()) return false; else return true; } void ParameterGoto::setDir() { QString folder = QFileDialog::getExistingDirectory(this); _lineEdit->setText(folder); } void ParameterGoto::addPlaceholder() { AddPlaceholderPopup* popup = new AddPlaceholderPopup(this); QString exp = popup->getPlaceholder(mapToGlobal(QPoint(_placeholderButton->pos().x() + _placeholderButton->width() + 6, _placeholderButton->pos().y() + _placeholderButton->height() / 2))); _lineEdit->insert(exp); delete popup; } ///////////// ParameterSyncprofile ParameterSyncprofile::ParameterSyncprofile(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this)); layout->addWidget(_combobox = new KComboBox(this)); _combobox->addItems(ProfileManager::availableProfiles("SynchronizerProfile")); } QString ParameterSyncprofile::text() { return _combobox->currentText(); } QString ParameterSyncprofile::preset() { return _combobox->itemText(0); } void ParameterSyncprofile::reset() { _combobox->setCurrentIndex(0); } bool ParameterSyncprofile::valid() { return true; } ///////////// ParameterSearch ParameterSearch::ParameterSearch(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this)); layout->addWidget(_combobox = new KComboBox(this)); _combobox->addItems(ProfileManager::availableProfiles("SearcherProfile")); } QString ParameterSearch::text() { return _combobox->currentText(); } QString ParameterSearch::preset() { return _combobox->itemText(0); } void ParameterSearch::reset() { _combobox->setCurrentIndex(0); } bool ParameterSearch::valid() { return true; } ///////////// ParameterPanelprofile ParameterPanelprofile::ParameterPanelprofile(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this)); layout->addWidget(_combobox = new KComboBox(this)); _combobox->addItems(ProfileManager::availableProfiles("Panel")); } QString ParameterPanelprofile::text() { return _combobox->currentText(); } QString ParameterPanelprofile::preset() { return _combobox->itemText(0); } void ParameterPanelprofile::reset() { _combobox->setCurrentIndex(0); } bool ParameterPanelprofile::valid() { return true; } ///////////// ParameterInt ParameterInt::ParameterInt(const exp_parameter& parameter, QWidget* parent) : ParameterBase(parameter, parent) { QHBoxLayout* layout = new QHBoxLayout(this); layout->setSpacing(6); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(new QLabel(i18n(parameter.description().toUtf8()), this)); layout->addWidget(_spinbox = new QSpinBox(this)); QStringList para = parameter.preset().section(':', 1).split(';'); _spinbox->setMinimum(para[0].toInt()); _spinbox->setMaximum(para[1].toInt()); _spinbox->setSingleStep(para[2].toInt()); _spinbox->setValue(para[3].toInt()); _default = _spinbox->value(); } QString ParameterInt::text() { return _spinbox->text(); } QString ParameterInt::preset() { return QString("%1").arg(_default); } void ParameterInt::reset() { return _spinbox->setValue(_default); } bool ParameterInt::valid() { return true; } diff --git a/krusader/ActionMan/addplaceholderpopup.h b/krusader/ActionMan/addplaceholderpopup.h index d12f92bb..ebaf9e74 100644 --- a/krusader/ActionMan/addplaceholderpopup.h +++ b/krusader/ActionMan/addplaceholderpopup.h @@ -1,344 +1,346 @@ /***************************************************************************** * Copyright (C) 2004 Shie Erlich * * Copyright (C) 2004 Rafi Yanai * * Copyright (C) Jonas Bähr * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef ADDPLACEHOLDERPOPUP_H #define ADDPLACEHOLDERPOPUP_H -#include -#include -#include +// QtCore +#include +// QtWidgets +#include +#include #include "../UserAction/expander.h" class QString; class KLineEdit; class QToolButton; class QCheckBox; class KComboBox; class QSpinBox; /** * This reads Expander::placeholder[] and * fills a popup for easy access to the UserAction Placeholder */ class AddPlaceholderPopup : public QMenu { public: AddPlaceholderPopup(QWidget *parent); /** * Use this to exec the popup. * @param pos Position where the popup should appear * @return the expression which can be placed in the UserAction commandline */ QString getPlaceholder(const QPoint& pos); protected: /** * This is calles when a Placeholder got parameter. * @param currentPlaceholder A pointer to the Placeholder the user has chosen * @return a parameter-string */ QString getParameter(exp_placeholder* currentPlaceholder); private: QMenu *_activeSub, *_otherSub, *_leftSub, *_rightSub, *_independentSub; }; //////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////// Parameter Widgets /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// /** * abstract baseclass for all Parameter widgets */ class ParameterBase : public QWidget { public: inline ParameterBase(const exp_parameter& parameter, QWidget* parent) : QWidget(parent) { _necessary = parameter.necessary(); } /** * @return the text for the parameter */ virtual QString text() = 0; /** * @return the default of the parameter */ virtual QString preset() = 0; /** * re-init the parameter with the default */ virtual void reset() = 0; /** * @return true if the Parameter as a valid value */ virtual bool valid() = 0; /** * @return true if the Placeholder really needs this parameter */ inline bool necessary() { return _necessary; } private: bool _necessary; }; /** * The simple Parameter widgets: a line-edit with the description above * used by default */ class ParameterText : public ParameterBase { public: ParameterText(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: KLineEdit * _lineEdit; QString _preset; }; /** * A line-edit with the "addPlaceholder"-button * used with default = "__placeholder" */ class ParameterPlaceholder : public ParameterBase { Q_OBJECT public: ParameterPlaceholder(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: KLineEdit * _lineEdit; QToolButton* _button; private slots: void addPlaceholder(); }; /** * A Checkbox, default: checked; retuns "No" if unchecked * used with default = "__yes" */ class ParameterYes : public ParameterBase { public: ParameterYes(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: QCheckBox* _checkBox; }; /** * A Checkbox, default: unchecked; retuns "Yes" if checked * used with default = "__no" */ class ParameterNo : public ParameterBase { public: ParameterNo(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: QCheckBox* _checkBox; }; /** * A line-edit with the "file open"-button * used with default = "__file" */ class ParameterFile : public ParameterBase { Q_OBJECT public: ParameterFile(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: KLineEdit * _lineEdit; QToolButton* _button; private slots: void addFile(); }; /** * A ComboBox with the description above * used with default = "__choose:item1;item2;..." */ class ParameterChoose : public ParameterBase { public: ParameterChoose(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: KComboBox * _combobox; }; /** * An editable ComboBox with the predifined selections * used with default = "__select" */ class ParameterSelect : public ParameterBase { public: ParameterSelect(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: KComboBox * _combobox; }; /** * A line-edit with a "choose dir"- and a bookmark-button * used with default = "__goto" */ class ParameterGoto : public ParameterBase { Q_OBJECT public: ParameterGoto(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: KLineEdit * _lineEdit; QToolButton* _dirButton, *_placeholderButton; private slots: void setDir(); void addPlaceholder(); }; /** * A ComboBox with all profiles available for the Synchronizer * used with default = "__syncprofile" */ class ParameterSyncprofile : public ParameterBase { public: ParameterSyncprofile(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: KComboBox * _combobox; }; /** * A ComboBox with all profiles available for the panels * used with default = "__panelprofile" */ class ParameterPanelprofile : public ParameterBase { public: ParameterPanelprofile(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: KComboBox * _combobox; }; /** * A ComboBox with all profiles available for the Searchmodule * used with default = "__searchprofile" */ class ParameterSearch : public ParameterBase { public: ParameterSearch(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: KComboBox * _combobox; }; /** * A SpinBox for integer * used with default = "__int:min;max;step;value" */ class ParameterInt : public ParameterBase { public: ParameterInt(const exp_parameter& parameter, QWidget* parent); QString text(); QString preset(); void reset(); bool valid(); private: QSpinBox * _spinbox; int _default; }; //////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////// ParameterDialog //////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// /** * Opens a dialog for the parameter. Depending on the default (preset) a differend widget is used. * See Parameter-Classes for details */ class ParameterDialog : public QDialog { Q_OBJECT public: ParameterDialog(const exp_placeholder* currentPlaceholder, QWidget *parent); /** * Use this to execute the dialog. * @return a QString with all paremeters; omitting the optional ones if they have the default-value. */ QString getParameter(); private: typedef QList ParameterList; ParameterList _parameter; int _parameterCount; private slots: void reset(); void slotOk(); }; #endif // ADDPLACEHOLDERPOPUP_H diff --git a/krusader/ActionMan/useractionlistview.cpp b/krusader/ActionMan/useractionlistview.cpp index 40981cdf..8a722462 100644 --- a/krusader/ActionMan/useractionlistview.cpp +++ b/krusader/ActionMan/useractionlistview.cpp @@ -1,251 +1,253 @@ /***************************************************************************** * Copyright (C) 2006 Jonas Bähr * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "useractionlistview.h" -#include -#include +// QtCore +#include +// QtXml +#include #include #include #include "../krglobal.h" #include "../UserAction/kraction.h" #include "../UserAction/useraction.h" #define COL_TITLE 0 // UserActionListView UserActionListView::UserActionListView(QWidget * parent) : KrTreeWidget(parent) { setHeaderLabel(i18n("Title")); setRootIsDecorated(true); setSelectionMode(QAbstractItemView::ExtendedSelection); // normaly select single items but one may use Ctrl or Shift to select multiple setSortingEnabled(true); sortItems(COL_TITLE, Qt::AscendingOrder); connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), SLOT(slotCurrentItemChanged(QTreeWidgetItem*))); update(); } UserActionListView::~UserActionListView() { } QSize UserActionListView::sizeHint() const { return QSize(200, 400); } void UserActionListView::update() { clear(); UserAction::KrActionList list = krUserAction->actionList(); QListIterator it(list); while (it.hasNext()) insertAction(it.next()); } void UserActionListView::update(KrAction* action) { UserActionListViewItem* item = findActionItem(action); if (item) { // deleting & re-inserting is _much_easyer then tracking all possible cases of category changes! bool current = (item == currentItem()); bool selected = item->isSelected(); delete item; item = insertAction(action); if (current) setCurrentItem(item); if (selected) item->setSelected(true); } } UserActionListViewItem* UserActionListView::insertAction(KrAction* action) { if (! action) return 0; UserActionListViewItem* item; if (action->category().isEmpty()) item = new UserActionListViewItem(this, action); else { QTreeWidgetItem* categoryItem = findCategoryItem(action->category()); if (! categoryItem) { categoryItem = new QTreeWidgetItem(this); // create the new category item it not already present categoryItem->setText(0, action->category()); categoryItem->setFlags(Qt::ItemIsEnabled); } item = new UserActionListViewItem(categoryItem, action); } item->setAction(action); return item; } QTreeWidgetItem* UserActionListView::findCategoryItem(const QString& category) { QTreeWidgetItemIterator it(this); while (*it) { if ((*it)->text(COL_TITLE) == category && !((*it)->flags() & Qt::ItemIsSelectable)) return *it; it++; } return 0; } UserActionListViewItem* UserActionListView::findActionItem(const KrAction* action) { QTreeWidgetItemIterator it(this); while (*it) { if (UserActionListViewItem* item = dynamic_cast(*it)) { if (item->action() == action) return item; } it++; } return 0; } KrAction * UserActionListView::currentAction() const { if (UserActionListViewItem* item = dynamic_cast(currentItem())) return item->action(); else return 0; } void UserActionListView::setCurrentAction(const KrAction* action) { UserActionListViewItem* item = findActionItem(action); if (item) { setCurrentItem(item); } } void UserActionListView::setFirstActionCurrent() { QTreeWidgetItemIterator it(this); while (*it) { if (UserActionListViewItem* item = dynamic_cast(*it)) { setCurrentItem(item); break; } it++; } } void UserActionListView::slotCurrentItemChanged(QTreeWidgetItem* item) { if (! item) return; scrollTo(indexOf(item)); } QDomDocument UserActionListView::dumpSelectedActions(QDomDocument* mergeDoc) const { QList list = selectedItems(); QDomDocument doc; if (mergeDoc) doc = *mergeDoc; else doc = UserAction::createEmptyDoc(); QDomElement root = doc.documentElement(); for (int i = 0; i < list.size(); ++i) { QTreeWidgetItem* item = list.at(i); if (UserActionListViewItem* actionItem = dynamic_cast(item)) root.appendChild(actionItem->action()->xmlDump(doc)); } return doc; } void UserActionListView::removeSelectedActions() { QList list = selectedItems(); for (int i = 0; i < list.size(); ++i) { QTreeWidgetItem* item = list.at(i); if (UserActionListViewItem* actionItem = dynamic_cast(item)) { delete actionItem->action(); // remove the action itself delete actionItem; // remove the action from the list } // if } } // UserActionListViewItem UserActionListViewItem::UserActionListViewItem(QTreeWidget* view, KrAction* action) : QTreeWidgetItem(view) { setAction(action); } UserActionListViewItem::UserActionListViewItem(QTreeWidgetItem* item, KrAction * action) : QTreeWidgetItem(item) { setAction(action); } UserActionListViewItem::~UserActionListViewItem() { } void UserActionListViewItem::setAction(KrAction * action) { if (! action) return; _action = action; update(); } KrAction * UserActionListViewItem::action() const { return _action; } void UserActionListViewItem::update() { if (! _action) return; if (! _action->icon().isNull()) setIcon(COL_TITLE, KIconLoader::global()->loadIcon(_action->iconName(), KIconLoader::Small)); setText(COL_TITLE, _action->text()); } bool UserActionListViewItem::operator<(const QTreeWidgetItem &other) const { // FIXME some how this only produces bullshit :-/ // if ( i->text( COL_NAME ).isEmpty() ) { // categories only have titles // //qDebug() << "this->title: " << text(COL_TITLE) << " |=| i->title: " << i->text(COL_TITLE) << endl; // return ( ascending ? -1 : 1 ); // <0 means this is smaller then i // } // else return QTreeWidgetItem::operator<(other); } diff --git a/krusader/ActionMan/useractionpage.cpp b/krusader/ActionMan/useractionpage.cpp index 63875727..45d67f81 100644 --- a/krusader/ActionMan/useractionpage.cpp +++ b/krusader/ActionMan/useractionpage.cpp @@ -1,353 +1,356 @@ /***************************************************************************** * Copyright (C) 2006 Shie Erlich * * Copyright (C) 2006 Rafi Yanai * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "useractionpage.h" -#include -#include -#include -#include -#include -#include -#include -#include +// QtWidgets +#include +#include +#include +#include +#include +#include +// QtGui +#include +// QtXml +#include #include #include #include #include #include #include "actionproperty.h" #include "useractionlistview.h" #include "../UserMenu/usermenu.h" //FIXME this should not be needed here! #include "../UserAction/useraction.h" #include "../UserAction/kraction.h" #include "../krusader.h" #include "../krglobal.h" #define ICON(N) KIconLoader::global()->loadIcon(N, KIconLoader::Toolbar) //This is the filter in the QFileDialog of Import/Export: static const char* FILE_FILTER = I18N_NOOP("*.xml|XML files\n*|All files"); UserActionPage::UserActionPage(QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(6); // 0px margin, 6px item-spacing // ======== pseudo-toolbar start ======== QHBoxLayout* toolbarLayout = new QHBoxLayout; // neither margin nor spacing for the toolbar with autoRaise toolbarLayout->setSpacing(0); toolbarLayout->setContentsMargins(0, 0, 0, 0); newButton = new QToolButton(this); newButton->setIcon(ICON("document-new")); newButton->setAutoRaise(true); newButton->setToolTip(i18n("Create new useraction")); importButton = new QToolButton(this); importButton->setIcon(ICON("document-import")); importButton->setAutoRaise(true); importButton->setToolTip(i18n("Import useractions")); exportButton = new QToolButton(this); exportButton->setIcon(ICON("document-export")); exportButton->setAutoRaise(true); exportButton->setToolTip(i18n("Export useractions")); copyButton = new QToolButton(this); copyButton->setIcon(ICON("edit-copy")); copyButton->setAutoRaise(true); copyButton->setToolTip(i18n("Copy useractions to clipboard")); pasteButton = new QToolButton(this); pasteButton->setIcon(ICON("edit-paste")); pasteButton->setAutoRaise(true); pasteButton->setToolTip(i18n("Paste useractions from clipboard")); removeButton = new QToolButton(this); removeButton->setIcon(ICON("edit-delete")); removeButton->setAutoRaise(true); removeButton->setToolTip(i18n("Delete selected useractions")); toolbarLayout->addWidget(newButton); toolbarLayout->addWidget(importButton); toolbarLayout->addWidget(exportButton); toolbarLayout->addWidget(copyButton); toolbarLayout->addWidget(pasteButton); toolbarLayout->addSpacing(6); // 6 pixel nothing toolbarLayout->addWidget(removeButton); toolbarLayout->addStretch(1000); // some very large stretch-factor // ======== pseudo-toolbar end ======== /* This seems obsolete now! // Display some help KMessageBox::information( this, // parent i18n( "When you apply changes to an action, the modifications " "become available in the current session immediately.\n" "When closing ActionMan, you will be asked to save the changes permanently." ), QString(), // caption "show UserAction help" //dontShowAgainName for the config ); */ layout->addLayout(toolbarLayout); QSplitter *split = new QSplitter(this); layout->addWidget(split, 1000); // again a very large stretch-factor to fix the height of the toolbar actionTree = new UserActionListView(split); actionTree->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); actionProperties = new ActionProperty(split); actionProperties->setEnabled(false); // if there are any actions in the list, the first is displayed and this widget is enabled connect(actionTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), SLOT(slotChangeCurrent())); connect(newButton, SIGNAL(clicked()), SLOT(slotNewAction())); connect(removeButton, SIGNAL(clicked()), SLOT(slotRemoveAction())); connect(importButton, SIGNAL(clicked()), SLOT(slotImport())); connect(exportButton, SIGNAL(clicked()), SLOT(slotExport())); connect(copyButton, SIGNAL(clicked()), SLOT(slotToClip())); connect(pasteButton, SIGNAL(clicked()), SLOT(slotFromClip())); // forwards the changed signal of the properties connect(actionProperties, SIGNAL(changed()), SIGNAL(changed())); actionTree->setFirstActionCurrent(); actionTree->setFocus(); } UserActionPage::~UserActionPage() { } bool UserActionPage::continueInSpiteOfChanges() { if (! actionProperties->isModified()) return true; int answer = KMessageBox::questionYesNoCancel(this, i18n("The current action has been modified. Do you want to apply these changes?") ); if (answer == KMessageBox::Cancel) { disconnect(actionTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(slotChangeCurrent())); actionTree->setCurrentAction(actionProperties->action()); connect(actionTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), SLOT(slotChangeCurrent())); return false; } if (answer == KMessageBox::Yes) { if (! actionProperties->validProperties()) { disconnect(actionTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(slotChangeCurrent())); actionTree->setCurrentAction(actionProperties->action()); connect(actionTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), SLOT(slotChangeCurrent())); return false; } slotUpdateAction(); } // if Yes return true; } void UserActionPage::slotChangeCurrent() { if (! continueInSpiteOfChanges()) return; KrAction* action = actionTree->currentAction(); if (action) { actionProperties->setEnabled(true); // the discinct name is used as ID it is not allowd to change it afterwards because it is may referenced anywhere else actionProperties->leDistinctName->setEnabled(false); actionProperties->updateGUI(action); } else { // If the current item in the tree is no action (i.e. a cathegory), disable the properties actionProperties->clear(); actionProperties->setEnabled(false); } emit applied(); // to disable the apply-button } void UserActionPage::slotUpdateAction() { // check that we have a command line, title and a name if (! actionProperties->validProperties()) return; if (actionProperties->leDistinctName->isEnabled()) { // := new entry KrAction* action = new KrAction(krApp->actionCollection(), actionProperties->leDistinctName->text()); krUserAction->addKrAction(action); actionProperties->updateAction(action); UserActionListViewItem* item = actionTree->insertAction(action); actionTree->setCurrentItem(item); krApp->userMenu->update(); } else { // := edit an existing actionProperties->updateAction(); actionTree->update(actionProperties->action()); // update the listviewitem as well... } apply(); } void UserActionPage::slotNewAction() { if (continueInSpiteOfChanges()) { actionTree->clearSelection(); // else the user may think that he is overwriting the selected action actionProperties->clear(); actionProperties->setEnabled(true); // it may be disabled because the tree has the focus on a category actionProperties->leDistinctName->setEnabled(true); actionProperties->leDistinctName->setFocus(); } } void UserActionPage::slotRemoveAction() { if (! dynamic_cast(actionTree->currentItem())) return; int messageDelete = KMessageBox::warningContinueCancel(this, //parent i18n("Are you sure that you want to remove all selected actions?"), //text i18n("Remove Selected Actions?"), //caption KStandardGuiItem::remove(), //Label for the continue-button KStandardGuiItem::cancel(), "Confirm Remove UserAction", //dontAskAgainName (for the config-file) KMessageBox::Dangerous | KMessageBox::Notify) ; if (messageDelete != KMessageBox::Continue) return; actionProperties->clear(); actionProperties->setEnabled(false); actionTree->removeSelectedActions(); apply(); } void UserActionPage::slotImport() { QString filename = QFileDialog::getOpenFileName(this, QString(), QString(), i18n(FILE_FILTER)); if (filename.isEmpty()) return; UserAction::KrActionList newActions; krUserAction->readFromFile(filename, UserAction::renameDoublicated, &newActions); QListIterator it(newActions); while (it.hasNext()) actionTree->insertAction(it.next()); if (newActions.count() > 0) { apply(); } } void UserActionPage::slotExport() { if (! dynamic_cast(actionTree->currentItem())) return; QString filename = QFileDialog::getSaveFileName(this, QString(), QString(), i18n(FILE_FILTER)); if (filename.isEmpty()) return; QDomDocument doc = QDomDocument(ACTION_DOCTYPE); QFile file(filename); int answer = 0; if (file.open(QIODevice::ReadOnly)) { // getting here, means the file already exists an can be read if (doc.setContent(&file)) // getting here means the file exists and already contains an UserAction-XML-tree answer = KMessageBox::warningYesNoCancel(this, //parent i18n("This file already contains some useractions.\nDo you want to overwrite it or should it be merged with the selected actions?"), //text i18n("Overwrite or Merge?"), //caption KStandardGuiItem::overwrite(), //label for Yes-Button KGuiItem(i18n("Merge")) //label for No-Button ); file.close(); } if (answer == 0 && file.exists()) answer = KMessageBox::warningContinueCancel(this, //parent i18n("This file already exists. Do you want to overwrite it?"), //text i18n("Overwrite Existing File?"), //caption KStandardGuiItem::overwrite() //label for Continue-Button ); if (answer == KMessageBox::Cancel) return; if (answer == KMessageBox::No) // that means the merge-button doc = actionTree->dumpSelectedActions(&doc); // merge else // Yes or Continue means overwrite doc = actionTree->dumpSelectedActions(); bool success = UserAction::writeToFile(doc, filename); if (! success) KMessageBox::error(this, i18n("Cannot open %1 for writing.\nNothing exported.", filename), i18n("Export Failed") ); } void UserActionPage::slotToClip() { if (! dynamic_cast(actionTree->currentItem())) return; QDomDocument doc = actionTree->dumpSelectedActions(); QApplication::clipboard()->setText(doc.toString()); } void UserActionPage::slotFromClip() { QDomDocument doc(ACTION_DOCTYPE); if (doc.setContent(QApplication::clipboard()->text())) { QDomElement root = doc.documentElement(); UserAction::KrActionList newActions; krUserAction->readFromElement(root, UserAction::renameDoublicated, &newActions); QListIterator it(newActions); while (it.hasNext()) actionTree->insertAction(it.next()); if (newActions.count() > 0) { apply(); } } // if ( doc.setContent ) } bool UserActionPage::readyToQuit() { // Check if the current UserAction has changed if (! continueInSpiteOfChanges()) return false; krUserAction->writeActionFile(); return true; } void UserActionPage::apply() { krUserAction->writeActionFile(); emit applied(); } void UserActionPage::applyChanges() { slotUpdateAction(); } diff --git a/krusader/ActionMan/useractionpage.h b/krusader/ActionMan/useractionpage.h index 8ec18861..7c82b565 100644 --- a/krusader/ActionMan/useractionpage.h +++ b/krusader/ActionMan/useractionpage.h @@ -1,79 +1,80 @@ /***************************************************************************** * Copyright (C) 2006 Shie Erlich * * Copyright (C) 2006 Rafi Yanai * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef USERACTIONPAGE_H #define USERACTIONPAGE_H -#include +// QtWidgets +#include class UserActionListView; class ActionProperty; class QToolButton; class UserActionPage : public QWidget { Q_OBJECT public: UserActionPage(QWidget* parent); ~UserActionPage(); /** * Be sure to call this function before you delete this page!! * @return true if this page can be closed */ bool readyToQuit(); void applyChanges(); signals: void changed(); ///< emitted on changes to an action (used to enable the apply-button) void applied(); ///< emitted when changes are applied to an action (used to disable the apply-button) private: /** * If there are modifications in the property-widget, the user is asked * what to do. Apply, discard or continue editing. In the first case, * saving is done in this function. * @return true if a new action can be loaded in the property-widget. */ bool continueInSpiteOfChanges(); /** * applyes all changes by writing the actionfile and emits "applied" */ void apply(); //bool _modified; ///< true if the action-tree was changed (= changes were applied to an action) UserActionListView *actionTree; ActionProperty *actionProperties; QToolButton *importButton, *exportButton; QToolButton *copyButton, *pasteButton; QToolButton *removeButton, *newButton; private slots: void slotChangeCurrent(); //loads a new action into the detail-view void slotUpdateAction(); //updates the action to the xml-file void slotNewAction(); void slotRemoveAction(); void slotImport(); void slotExport(); void slotToClip(); void slotFromClip(); }; #endif