diff --git a/src/datetimeplugin.h b/src/datetimeplugin.h index 8073f13..6076596 100644 --- a/src/datetimeplugin.h +++ b/src/datetimeplugin.h @@ -1,162 +1,162 @@ /*************************************************************************** datetimeplugin.h - description ------------------- begin : Sun Mar 9 2008 copyright : (C) 2002 by Dominik Seichter email : domseichter@web.de ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef DATE_TIME_PLUGIN_H #define DATE_TIME_PLUGIN_H #include #ifndef Q_OS_WIN #include "plugin.h" #include namespace Ui { class DateTimePluginWidget; }; class QDate; class QTime; /** This is the abstract interface that has to be implemented * by all KRename plugins. */ class DateTimePlugin : public QObject, public Plugin { Q_OBJECT public: explicit DateTimePlugin(PluginLoader *loader); ~DateTimePlugin() override; /** * @returns a name of the plugin that can be displayed * to the user. This name should be internationalized. */ const QString name() const override; /** * Determines the type of the plugin. * Different enum values may be or'ed together. * * @returns the type of the plugin. */ inline int type() const override; /** * @returns an icon for this plugin. */ const QPixmap icon() const override; /** * @returns true if this plugins is always enabled * * Warning: If you return true here, the user has no possibility to * disable this plugin. */ - inline bool alwaysEnabled() const override; + inline bool enabledByDefault() const override; /** * This function is the core of your plugin. * * It does the actual processing of a file, filename or token depending of the type * of your plugin. * * \see type() * * @param b the parent BatchRenamer instance calling this plugin * @param index the index of the current file (i.e. the first file has index 0, * the second file to be renamed has index 1 ....) * @param filenameOrToken this parameter depends on the type of your plugin. * If type is ePluginType_File, this is the absolute path * or URL to the renamed file. * If type is ePluginType_Filename, this is the filename * (without path) as created by KRename. * If type is ePluginType_Token, this is the contents of a token * in brackets. If your plugin supports the token [example], * KRename will pass the strign "example" to your method. * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type) * * @returns the result of the function, depending on type(). * @returns QString::null if this plugin has nothing to do. * @returns A new filename if type is ePluginType_Filename * @returns the value of the token if type is ePluginType_Token * @returns an error message or QString::null if type is ePluginType_File */ QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) override; /** Get a list of all tokens supported by this plugin. * * If the token type != ePluginType_Token you have to return an empty list * * @returns a list of all supported tokens. The returned strings will be treated * as regular expressions to find a plugin which supports a token. */ inline const QStringList &supportedTokens() const override; /** Returns help descriptions for the supported tokens * * The returned stringlist contains strings that are the tokens * and the description separated by ;; * * @returns a stringlist containing help on the supported tokens */ inline const QStringList &help() const override; /** Create a user interface for this plugin * * @param parent the parent widget of this plugin */ void createUI(QWidget *parent) const override; private Q_SLOTS: void slotGetCurrentTime(); private: QString changeDateTime(const QString &filename, bool bModification, bool bAccess, const QDate &date, const QTime &time); private: Ui::DateTimePluginWidget *m_widget; QStringList m_tmp; ///< Dummy empty list so that we can return a reference for supported tokens and help }; inline int DateTimePlugin::type() const { return ePluginType_File; } -inline bool DateTimePlugin::alwaysEnabled() const +inline bool DateTimePlugin::enabledByDefault() const { return false; } inline const QStringList &DateTimePlugin::supportedTokens() const { return m_tmp; } inline const QStringList &DateTimePlugin::help() const { return m_tmp; } #endif // Q_OS_WIN #endif /* DATE_TIME_PLUGIN_H */ diff --git a/src/dirsortplugin.cpp b/src/dirsortplugin.cpp index 2bb8bbc..eea1652 100644 --- a/src/dirsortplugin.cpp +++ b/src/dirsortplugin.cpp @@ -1,167 +1,167 @@ /*************************************************************************** dirsortplugin.cpp - description ------------------- begin : Sun Dec 27 2009 copyright : (C) 2009 by Dominik Seichter email : domseichter@web.de ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ // Own includes #include "dirsortplugin.h" #include "batchrenamer.h" // KDE includes #include #include #include #include DirSortPlugin::DirSortPlugin(PluginLoader *loader) : Plugin(loader) { m_widget = new Ui::DirSortPluginWidget(); } DirSortPlugin::~DirSortPlugin() { delete m_widget; } const QString DirSortPlugin::name() const { return i18n("Subfolder-Sort Plugin"); } int DirSortPlugin::type() const { return ePluginType_File; } -bool DirSortPlugin::alwaysEnabled() const +bool DirSortPlugin::enabledByDefault() const { return false; } const QPixmap DirSortPlugin::icon() const { return KIconLoader::global()->loadIcon("folder", KIconLoader::NoGroup, KIconLoader::SizeSmall); } void DirSortPlugin::createUI(QWidget *parent) const { m_widget->setupUi(parent); m_widget->outputUrl->setMode(KFile::Directory | KFile::ExistingOnly); } /* void DirSortPlugin::fillStructure() { fpd = spinFiles->value(); fpd--; dir = outputdir->text(); filecounter = 0; dircounter = spinStart->value(); curdir = dir + QString("/%1/").arg( dircounter ); d = new QDir( dir ); d->mkdir( curdir ); } */ QString DirSortPlugin::processFile(BatchRenamer *b, int index, const QString &, EPluginType) { QString errorMsg; if (index == 0) { // Initialize plugin m_dirCounter = m_widget->spinStart->value(); m_fileCounter = 0; m_filesPerDir = m_widget->spinFiles->value(); m_digits = m_widget->spinDigits->value(); m_baseDirectory = m_widget->outputUrl->url(); KIO::StatJob *statJob = KIO::stat(m_baseDirectory, KIO::StatJob::DestinationSide, 2); KJobWidgets::setWindow(statJob, m_widget->spinStart); statJob->exec(); if (statJob->error()) { m_valid = false; return i18n("%1: The output folder %2 does not exist.", this->name(), m_baseDirectory.toDisplayString(QUrl::PreferLocalFile)); } else { m_valid = true; m_currentDirectory = createNewSubdirectory(); } } if (!m_valid) { return errorMsg; } if (m_fileCounter == m_filesPerDir) { m_fileCounter = 0; m_dirCounter++; m_currentDirectory = createNewSubdirectory(); } QUrl srcUrl = b->buildDestinationUrl((*b->files())[index]); QUrl dstUrl = m_currentDirectory; dstUrl = dstUrl.adjusted(QUrl::StripTrailingSlash); dstUrl.setPath(dstUrl.path() + '/' + (srcUrl.fileName())); KIO::JobFlags flags = KIO::DefaultFlags | KIO::HideProgressInfo; KIO::Job *job = KIO::file_move(srcUrl, dstUrl, -1, flags); m_fileCounter++; KJobWidgets::setWindow(job, m_widget->spinStart); job->exec(); if (!job->exec()) { errorMsg = i18n("Error renaming %2 (to %1)", dstUrl.toDisplayString(QUrl::PreferLocalFile), srcUrl.toDisplayString(QUrl::PreferLocalFile)); } return errorMsg; } const QStringList &DirSortPlugin::supportedTokens() const { return m_emptyList; } const QStringList &DirSortPlugin::help() const { return m_emptyList; } QUrl DirSortPlugin::createNewSubdirectory() const { QUrl url = m_baseDirectory; QString dir; dir.sprintf("%0*i", m_digits, m_dirCounter); url = url.adjusted(QUrl::StripTrailingSlash); url.setPath(url.path() + '/' + (dir)); KIO::MkdirJob *job = KIO::mkdir(url); KJobWidgets::setWindow(job, m_widget->groupBox); // we just need a random widget, FIXME use the proper parent if (!job->exec()) { KMessageBox::error(m_widget->groupBox, i18n("Cannot create folder %1", url.toDisplayString(QUrl::PreferLocalFile))); } return url; } diff --git a/src/dirsortplugin.h b/src/dirsortplugin.h index 841f099..f9f823a 100644 --- a/src/dirsortplugin.h +++ b/src/dirsortplugin.h @@ -1,137 +1,137 @@ /*************************************************************************** dirsortplugin.h - description ------------------- begin : Sun Dec 27 2009 copyright : (C) 2009 by Dominik Seichter email : domseichter@web.de ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef DIR_SORT_PLUGIN_H #define DIR_SORT_PLUGIN_H #include "plugin.h" #include "ui_dirsortpluginwidget.h" #include class DirSortPlugin : public Plugin { public: explicit DirSortPlugin(PluginLoader *loader); ~DirSortPlugin() override; /** * @returns a name of the plugin that can be displayed * to the user. This name should be internationalized. */ const QString name() const override; /** * Determines the type of the plugin. * Different enum values may be or'ed together. * * @returns the type of the plugin. */ int type() const override; /** * @returns an icon for this plugin. */ const QPixmap icon() const override; /** * @returns true if this plugins is always enabled * * Warning: If you return true here, the user has no possibility to * disable this plugin. */ - bool alwaysEnabled() const override; + bool enabledByDefault() const override; /** * This function is the core of your plugin. * * It does the actual processing of a file, filename or token depending of the type * of your plugin. * * \see type() * * @param b the parent BatchRenamer instance calling this plugin * @param index the index of the current file (i.e. the first file has index 0, * the second file to be renamed has index 1 ....) * @param filenameOrToken this parameter depends on the type of your plugin. * If type is ePluginType_File, this is the absolute path * or URL to the renamed file. * If type is ePluginType_Filename, this is the filename * (without path) as created by KRename. * If type is ePluginType_Token, this is the contents of a token * in brackets. If your plugin supports the token [example], * KRename will pass the strign "example" to your method. * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type) * * @returns the result of the function, depending on type(). * @returns QString::null if this plugin has nothing to do. * @returns A new filename if type is ePluginType_Filename * @returns the value of the token if type is ePluginType_Token * @returns an error message or QString::null if type is ePluginType_File */ QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) override; /** Get a list of all tokens supported by this plugin. * * If the token type != ePluginType_Token you have to return an empty list * * @returns a list of all supported tokens. The returned strings will be treated * as regular expressions to find a plugin which supports a token. */ const QStringList &supportedTokens() const override; /** Returns help descriptions for the supported tokens * * The returned stringlist contains strings that are the tokens * and the description separated by ;; * * @returns a stringlist containing help on the supported tokens */ const QStringList &help() const override; /** Create a user interface for this plugin * * @param parent the parent widget of this plugin */ void createUI(QWidget *parent) const override; private: /** * Create a new subdirectory with the current setting * from m_digits and m_dirCounter. * * \returns the URL of the new subdirectory. */ QUrl createNewSubdirectory() const; protected: int m_dirCounter; int m_fileCounter; int m_filesPerDir; int m_digits; QUrl m_baseDirectory; QUrl m_currentDirectory; Ui::DirSortPluginWidget *m_widget; QStringList m_emptyList; bool m_valid; }; #endif // DIR_SORT_PLUGIN diff --git a/src/fileplugin.h b/src/fileplugin.h index cf58795..bc366bc 100644 --- a/src/fileplugin.h +++ b/src/fileplugin.h @@ -1,174 +1,174 @@ /*************************************************************************** fileplugin.h - description ------------------- begin : Mon Jul 1 2002 copyright : (C) 2002 by Dominik Seichter email : domseichter@web.de ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef FILE_PLUGIN_H #define FILE_PLUGIN_H #include "plugin.h" class KService; class FilePlugin : public Plugin { public: /** Create a new FilePlugin from a KService * * @param service pointer to a KService */ FilePlugin(PluginLoader *loader, KService *service); ~FilePlugin() override; /** * @returns a name of the plugin that can be displayed * to the user. This name should be internationalized. */ inline const QString name() const override; /** * @returns the type of the plugin. */ inline int type() const override; /** * @returns an icon for this plugin. */ const QPixmap icon() const override; /** * @returns true if this plugins is always enabled * * Warning: If you return true here, the user has no possibility to * disable this plugin. */ - inline bool alwaysEnabled() const override; + inline bool enabledByDefault() const override; /** * This function is the core of your plugin. * * It does the actual processing of a file, filename or token depending of the type * of your plugin. * * \see type() * * @param b the parent BatchRenamer instance calling this plugin * @param index the index of the current file (i.e. the first file has index 0, * the second file to be renamed has index 1 ....) * @param filenameOrToken this parameter depends on the type of your plugin. * If type is ePluginType_File, this is the absolute path * or URL to the renamed file. * If type is ePluginType_Filename, this is the filename * (without path) as created by KRename. * If type is ePluginType_Token, this is the contents of a token * in brackets. If your plugin supports the token [example], * KRename will pass the strign "example" to your method. * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type) * * @returns the result of the function, depending on type(). * @returns QString::null if this plugin has nothing to do. * @returns A new filename if type is ePluginType_Filename * @returns the value of the token if type is ePluginType_Token * @returns an error message or QString::null if type is ePluginType_File */ QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) override = 0; /** Get a list of all tokens supported by this plugin. * * If the token type != ePluginType_Token you have to return an empty list * * @returns a list of all supported tokens. */ inline const QStringList &supportedTokens() const override; /** Returns help descriptions for the supported tokens * * The returned stringlist contains strings that are the tokens * and the description separated by ;; * * @returns a stringlist containing help on the supported tokens */ inline const QStringList &help() const override; /** Create a user interface for this plugin * * @param parent the parent widget of this plugin * * This is implemented here for all FilePlugin based classed */ void createUI(QWidget *parent) const override; protected: FilePlugin(PluginLoader *loader); /** * Checks if a token is supported by this plugin. * * @param token a token * @returns true if the token is supported * * @see addSupportedToken */ bool supports(const QString &token); /** * Adds a token to the list of supported tokens * * @param token will be a supported token from now on * * @see supports */ inline void addSupportedToken(const QString &token) { m_keys.append(token); } protected: QString m_name; QString m_comment; QString m_icon; private: QStringList m_keys; }; inline const QString FilePlugin::name() const { return m_name; } -inline bool FilePlugin::alwaysEnabled() const +inline bool FilePlugin::enabledByDefault() const { return true; } inline int FilePlugin::type() const { return ePluginType_Token; } inline const QStringList &FilePlugin::supportedTokens() const { return m_keys; } inline const QStringList &FilePlugin::help() const { return m_keys; } #endif // FILE_PLUGIN_H diff --git a/src/increasecounterplugin.h b/src/increasecounterplugin.h index ab09ba8..72b6cd7 100644 --- a/src/increasecounterplugin.h +++ b/src/increasecounterplugin.h @@ -1,159 +1,159 @@ /*************************************************************************** increasecounterplugin.h - description ------------------- begin : Tue Jul 15 2008 copyright : (C) 2008 by Dominik Seichter email : domseichter@web.de ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef INCREASE_COUNTER_PLUGIN_H #define INCREASE_COUNTER_PLUGIN_H #include namespace Ui { class IncreaseCounterPluginWidget; }; /** This is the abstract interface that has to be implemented * by all KRename plugins. */ class IncreaseCounterPlugin : public QObject, public Plugin { Q_OBJECT public: explicit IncreaseCounterPlugin(PluginLoader *loader); ~IncreaseCounterPlugin() override; /** * @returns a name of the plugin that can be displayed * to the user. This name should be internationalized. */ const QString name() const override; /** * Determines the type of the plugin. * Different enum values may be or'ed together. * * @returns the type of the plugin. */ inline int type() const override; /** * @returns an icon for this plugin. */ const QPixmap icon() const override; /** * @returns true if this plugins is always enabled * * Warning: If you return true here, the user has no possibility to * disable this plugin. */ - inline bool alwaysEnabled() const override; + inline bool enabledByDefault() const override; /** * This function is the core of your plugin. * * It does the actual processing of a file, filename or token depending of the type * of your plugin. * * \see type() * * @param b the parent BatchRenamer instance calling this plugin * @param index the index of the current file (i.e. the first file has index 0, * the second file to be renamed has index 1 ....) * @param filenameOrToken this parameter depends on the type of your plugin. * If type is ePluginType_File, this is the absolute path * or URL to the renamed file. * If type is ePluginType_Filename, this is the filename * (without path) as created by KRename. * If type is ePluginType_Token, this is the contents of a token * in brackets. If your plugin supports the token [example], * KRename will pass the strign "example" to your method. * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type) * * @returns the result of the function, depending on type(). * @returns QString::null if this plugin has nothing to do. * @returns A new filename if type is ePluginType_Filename * @returns the value of the token if type is ePluginType_Token * @returns an error message or QString::null if type is ePluginType_File */ QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) override; /** Get a list of all tokens supported by this plugin. * * If the token type != ePluginType_Token you have to return an empty list * * @returns a list of all supported tokens. The returned strings will be treated * as regular expressions to find a plugin which supports a token. */ inline const QStringList &supportedTokens() const override; /** Returns help descriptions for the supported tokens * * The returned stringlist contains strings that are the tokens * and the description separated by ;; * * @returns a stringlist containing help on the supported tokens */ inline const QStringList &help() const override; /** Create a user interface for this plugin * * @param parent the parent widget of this plugin */ void createUI(QWidget *parent) const override; private Q_SLOTS: /** * Called when the user changes the offset through the UI * * @param offset the new offset */ void slotOffsetChanged(int offset); private: Ui::IncreaseCounterPluginWidget *m_widget; int m_offset; ///< Increase counter by this offset QStringList m_tmp; ///< Dummy empty list so that we can return a reference for supported tokens and help QStringList m_users; ///< List of all usernames on the system QStringList m_groups; ///< List of all groups on the system }; inline int IncreaseCounterPlugin::type() const { return ePluginType_Filename; } -inline bool IncreaseCounterPlugin::alwaysEnabled() const +inline bool IncreaseCounterPlugin::enabledByDefault() const { return false; } inline const QStringList &IncreaseCounterPlugin::supportedTokens() const { return m_tmp; } inline const QStringList &IncreaseCounterPlugin::help() const { return m_tmp; } #endif // INCREASE_COUNTER_PLUGIN_H diff --git a/src/krenamewindow.cpp b/src/krenamewindow.cpp index 3a356db..bf0249e 100644 --- a/src/krenamewindow.cpp +++ b/src/krenamewindow.cpp @@ -1,1197 +1,1197 @@ /*************************************************************************** krenamewindow.cpp - description ------------------- begin : Sat Mar 24 2007 copyright : (C) 2007 by Dominik Seichter email : domseichter@web.de ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include "krenamewindow.h" #include "krenamemodel.h" #include "plugin.h" #include "pluginloader.h" #include "richtextitemdelegate.h" #include "startupinfo.h" #include "tokensortmodedialog.h" #include "ui_krenamefiles.h" #include "ui_krenamedestination.h" //#include "ui_krenamesimple.h" #include "ui_krenameplugins.h" #include "ui_krenamefilename.h" #include #include #include #include #include #include #include #include #include #include static const KRenameWindow::TGuiMode tAdvancedMode = { 4, { I18N_NOOP("&1. Files"), I18N_NOOP("&2. Destination"), I18N_NOOP("&3. Plugins"), I18N_NOOP("&4. Filename") }, { 0, 1, 2, 3 }, { "document-open-folder", "document-save", "configure", "edit-rename" } }; KRenameWindow::KRenameWindow(QWidget *parent) : KMainWindow(parent), m_curPage(0), m_guiMode(nullptr), m_fileCount(0) { QWidget *center = new QWidget(); QVBoxLayout *layout = new QVBoxLayout(center); m_delegate = new RichTextItemDelegate(this); m_tabBar = new QTabBar(center); m_stack = new QStackedWidget(center); m_buttons = new QDialogButtonBox(center); layout->addWidget(m_tabBar); layout->addWidget(m_stack); layout->addWidget(new KSeparator(Qt::Horizontal, center)); layout->addWidget(m_buttons); layout->setStretchFactor(m_stack, 2); this->setCentralWidget(center); for (int i = 0; i < tAdvancedMode.numPages; i++) { const QIcon &icon = KIconLoader::global()->loadIcon(tAdvancedMode.pageIcons[i], KIconLoader::NoGroup, KIconLoader::SizeSmall); m_tabBar->addTab(icon, i18n(tAdvancedMode.pageTitles[i])); } m_pageFiles = new Ui::KRenameFiles(); m_pageDests = new Ui::KRenameDestination(); m_pagePlugins = new Ui::KRenamePlugins(); m_pageFilename = new Ui::KRenameFilename(); // add files page QWidget *page = new QWidget(m_stack); m_pageFiles->setupUi(page); m_stack->addWidget(page); // add destination page page = new QWidget(m_stack); m_pageDests->setupUi(page); m_stack->addWidget(page); // add plugin page page = new QWidget(m_stack); m_pagePlugins->setupUi(page); m_stack->addWidget(page); // add filename page page = new QWidget(m_stack); m_pageFilename->setupUi(page); m_stack->addWidget(page); setupGui(); setupPlugins(); setupIcons(); StartUpInfo *startUp = new StartUpInfo(); connect(startUp, &StartUpInfo::addFiles, this, &KRenameWindow::addFiles); connect(startUp, &StartUpInfo::enterTemplate, this, &KRenameWindow::slotGotoTemplatesPage); m_pageDests->urlrequester->setMode(KFile::Directory | KFile::ExistingOnly); m_pageFiles->fileList->setItemDelegate(m_delegate); m_pageFiles->fileList->setInfoWidget(startUp); // Make sure that now signal occurs before setupGui was called connect(m_tabBar, &QTabBar::currentChanged, this, &KRenameWindow::showPage); connect(m_buttonClose, &QPushButton::clicked, this, &KRenameWindow::close); connect(m_buttons, &QDialogButtonBox::accepted, this, &KRenameWindow::slotFinish); this->setAutoSaveSettings("KRenameWindowSettings", true); // Show the first page in any mode showPage(0); } KRenameWindow::~KRenameWindow() { } void KRenameWindow::loadConfig() { // ExtHistoryCombo needs an object name m_pageFilename->filenameTemplate->setObjectName("FILENAME_TEMPLATE"); m_pageFilename->extensionTemplate->setObjectName("EXTENSION_TEMPLATE"); m_pageFilename->comboFilenameCustom->setObjectName("FILENAME_CUSTOM_TEMPLATE"); m_pageFilename->comboExtensionCustom->setObjectName("EXTENSION_CUSTOM_TEMPLATE"); m_pageFilename->comboPrefixCustom->setObjectName("PREVIX_CUSTOM_TEMPLATE"); m_pageFilename->comboSuffixCustom->setObjectName("SUFFIX_CUSTOM_TEMPLATE"); m_pageFilename->filenameTemplate->loadConfig(); m_pageFilename->extensionTemplate->loadConfig(); m_pageFilename->comboFilenameCustom->loadConfig(); m_pageFilename->comboExtensionCustom->loadConfig(); m_pageFilename->comboPrefixCustom->loadConfig(); m_pageFilename->comboSuffixCustom->loadConfig(); KSharedConfigPtr config = KSharedConfig::openConfig(); KConfigGroup groupGui = config->group(QString("GUISettings")); int width = groupGui.readEntry("Column0", QVariant(this->previewColumnWidth(0))).toInt(); if (width > 0) { this->setPreviewColumnWidth(0, width); } width = groupGui.readEntry("Column1", QVariant(this->previewColumnWidth(1))).toInt(); if (width > 0) { this->setPreviewColumnWidth(1, width); } } void KRenameWindow::saveConfig() { m_pageFilename->filenameTemplate->saveConfig(); m_pageFilename->extensionTemplate->saveConfig(); m_pageFilename->comboFilenameCustom->saveConfig(); m_pageFilename->comboExtensionCustom->saveConfig(); m_pageFilename->comboPrefixCustom->saveConfig(); m_pageFilename->comboSuffixCustom->saveConfig(); KSharedConfigPtr config = KSharedConfig::openConfig(); KConfigGroup groupGui = config->group(QString("GUISettings")); groupGui.writeEntry("Column0", this->previewColumnWidth(0)); groupGui.writeEntry("Column1", this->previewColumnWidth(1)); } void KRenameWindow::setupGui() { m_buttons->clear(); m_guiMode = &tAdvancedMode; m_buttonFinish = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-ok")), i18n("&Finish")); m_buttons->setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Close); m_buttons->addButton(m_buttonFinish, QDialogButtonBox::AcceptRole); m_buttonClose = m_buttons->button(QDialogButtonBox::Close); m_buttonClose->setShortcut(QKeySequence(QKeySequence::Quit)); KHelpMenu *helpMenu = new KHelpMenu(this, QString(), false); helpMenu->menu()->removeAction(helpMenu->action(KHelpMenu::menuHelpContents)); m_buttons->button(QDialogButtonBox::Help)->setMenu(helpMenu->menu()); setupSlots(); slotEnableControls(); } void KRenameWindow::setupPlugins() { PluginLoader *loader = PluginLoader::Instance(); const QList &list = loader->plugins(); QList::const_iterator it = list.begin(); m_pluginsWidgetHash.reserve(list.count()); m_pluginsHash.reserve(list.count()); m_pagePlugins->searchPlugins->searchLine()->setTreeWidget(m_pagePlugins->listPlugins); while (it != list.end()) { // create plugin gui QWidget *widget = new QWidget(m_pagePlugins->stackPlugins); (*it)->createUI(widget); int idx = m_pagePlugins->stackPlugins->addWidget(widget); m_pagePlugins->stackPlugins->setCurrentIndex(idx); m_pluginsHash[(*it)->name()] = (*it); m_pluginsWidgetHash[(*it)->name()] = widget; // add to list of all plugins QTreeWidgetItem *item = new QTreeWidgetItem(m_pagePlugins->listPlugins); item->setText(0, (*it)->name()); item->setIcon(0, (*it)->icon()); slotPluginChanged(item); ++it; } m_pagePlugins->splitter->setStretchFactor(0, 0); m_pagePlugins->splitter->setStretchFactor(1, 8); m_pagePlugins->listPlugins->sortColumn(); } void KRenameWindow::setupIcons() { QPixmap upIcon = KIconLoader::global()->loadIcon("arrow-up", KIconLoader::NoGroup, KIconLoader::SizeSmall); QPixmap downIcon = KIconLoader::global()->loadIcon("arrow-down", KIconLoader::NoGroup, KIconLoader::SizeSmall); // Page 1 icons QPixmap openIcon = KIconLoader::global()->loadIcon("document-open", KIconLoader::NoGroup, KIconLoader::SizeSmall); QPixmap removeIcon = KIconLoader::global()->loadIcon("list-remove", KIconLoader::NoGroup, KIconLoader::SizeSmall); m_pageFiles->buttonAdd->setIcon(openIcon); m_pageFiles->buttonRemove->setIcon(removeIcon); m_pageFiles->buttonUp->setIcon(upIcon); m_pageFiles->buttonDown->setIcon(downIcon); // Page 4 icons QPixmap helpIcon = KIconLoader::global()->loadIcon("help-hint", KIconLoader::NoGroup, KIconLoader::SizeSmall); QPixmap findIcon = KIconLoader::global()->loadIcon("edit-find", KIconLoader::NoGroup, KIconLoader::SizeSmall); m_pageFilename->buttonHelp1->setIcon(helpIcon); m_pageFilename->buttonHelp2->setIcon(helpIcon); m_pageFilename->buttonHelp3->setIcon(helpIcon); m_pageFilename->buttonHelp4->setIcon(helpIcon); m_pageFilename->buttonFunctions->setIcon(helpIcon); m_pageFilename->buttonFind->setIcon(findIcon); m_pageFilename->buttonFindSimple->setIcon(findIcon); m_pageFilename->buttonUp->setIcon(upIcon); m_pageFilename->buttonDown->setIcon(downIcon); } void KRenameWindow::setupSlots() { connect(m_pageFiles->buttonAdd, &QPushButton::clicked, this, &KRenameWindow::addFiles); connect(m_pageFiles->buttonRemove, &QPushButton::clicked, this, &KRenameWindow::removeFiles); connect(m_pageFiles->buttonRemoveAll, &QPushButton::clicked, this, &KRenameWindow::removeAllFiles); connect(m_pageFiles->checkPreview, &QCheckBox::clicked, this, &KRenameWindow::slotPreviewChanged); connect(m_pageFiles->checkName, &QCheckBox::clicked, this, &KRenameWindow::slotPreviewChanged); connect(m_pageFiles->comboSort, static_cast(&QComboBox::currentIndexChanged), this, &KRenameWindow::slotSortChanged); connect(m_pageFiles->fileList, &KRenameListView::doubleClicked, this, &KRenameWindow::slotOpenFile); connect(m_pageFiles->buttonUp, &QPushButton::clicked, this, &KRenameWindow::slotMoveUp); connect(m_pageFiles->buttonDown, &QPushButton::clicked, this, &KRenameWindow::slotMoveDown); connect(m_pageDests->optionRename, &QRadioButton::clicked, this, &KRenameWindow::slotRenameModeChanged); connect(m_pageDests->optionCopy, &QRadioButton::clicked, this, &KRenameWindow::slotRenameModeChanged); connect(m_pageDests->optionMove, &QRadioButton::clicked, this, &KRenameWindow::slotRenameModeChanged); connect(m_pageDests->optionLink, &QRadioButton::clicked, this, &KRenameWindow::slotRenameModeChanged); connect(m_pageDests->checkOverwrite, &QCheckBox::clicked, this, &KRenameWindow::overwriteFilesChanged); connect(m_pagePlugins->listPlugins, &QTreeWidget::currentItemChanged, this, &KRenameWindow::slotPluginChanged); connect(m_pagePlugins->checkEnablePlugin, &QCheckBox::clicked, this, &KRenameWindow::slotPluginEnabled); connect(m_pageFilename->checkExtension, &QCheckBox::clicked, this, &KRenameWindow::slotEnableControls); connect(m_pageFilename->buttonNumbering, &QPushButton::clicked, this, &KRenameWindow::showAdvancedNumberingDialog); connect(m_pageFilename->buttonInsert, &QPushButton::clicked, this, &KRenameWindow::showInsertPartFilenameDialog); connect(m_pageFilename->buttonFind, &QPushButton::clicked, this, &KRenameWindow::showFindReplaceDialog); connect(m_pageFilename->filenameTemplate, &ExtHistoryCombo::delayedTextChanged, this, &KRenameWindow::slotTemplateChanged); connect(m_pageFilename->extensionTemplate, &ExtHistoryCombo::delayedTextChanged, this, &KRenameWindow::slotTemplateChanged); connect(m_pageFilename->checkExtension, &QCheckBox::clicked, this, &KRenameWindow::slotTemplateChanged); connect(m_pageFilename->buttonFunctions, &QPushButton::clicked, this, &KRenameWindow::slotTokenHelpRequested); connect(m_pageFilename->comboExtension, static_cast(&QComboBox::currentIndexChanged), this, &KRenameWindow::slotExtensionSplitModeChanged); connect(m_pageFilename->buttonUp, &QPushButton::clicked, this, &KRenameWindow::slotMoveUpPreview); connect(m_pageFilename->buttonDown, &QPushButton::clicked, this, &KRenameWindow::slotMoveDownPreview); connect(m_pageFilename->listPreview, &PreviewList::addFiles, this, &KRenameWindow::addFiles); connect(m_pageFilename->listPreview, &PreviewList::updateCount, this, &KRenameWindow::updateCount); connect(m_pageFilename->comboFilenameCustom, &ExtHistoryCombo::delayedTextChanged, this, &KRenameWindow::slotSimpleTemplateChanged); connect(m_pageFilename->comboSuffixCustom, &ExtHistoryCombo::delayedTextChanged, this, &KRenameWindow::slotSimpleTemplateChanged); connect(m_pageFilename->comboPrefixCustom, &ExtHistoryCombo::delayedTextChanged, this, &KRenameWindow::slotSimpleTemplateChanged); connect(m_pageFilename->comboExtensionCustom, &ExtHistoryCombo::delayedTextChanged, this, &KRenameWindow::slotSimpleTemplateChanged); connect(m_pageFilename->comboPrefix, static_cast(&QComboBox::currentIndexChanged), this, &KRenameWindow::slotSimpleTemplateChanged); connect(m_pageFilename->comboSuffix, static_cast(&QComboBox::currentIndexChanged), this, &KRenameWindow::slotSimpleTemplateChanged); connect(m_pageFilename->comboFilenameSimple, static_cast(&QComboBox::currentIndexChanged), this, &KRenameWindow::slotSimpleTemplateChanged); connect(m_pageFilename->comboExtensionSimple, static_cast(&QComboBox::currentIndexChanged), this, &KRenameWindow::slotSimpleTemplateChanged); connect(m_pageFilename->comboExtensionSimple, static_cast(&QComboBox::currentIndexChanged), this, &KRenameWindow::slotEnableControls); connect(m_pageFilename->comboFilenameSimple, static_cast(&QComboBox::currentIndexChanged), this, &KRenameWindow::slotEnableControls); connect(m_pageFilename->buttonHelp1, &QPushButton::clicked, this, &KRenameWindow::slotTokenHelpRequestedWizard1); connect(m_pageFilename->buttonHelp2, &QPushButton::clicked, this, &KRenameWindow::slotTokenHelpRequestedWizard2); connect(m_pageFilename->buttonHelp3, &QPushButton::clicked, this, &KRenameWindow::slotTokenHelpRequestedWizard3); connect(m_pageFilename->buttonHelp4, &QPushButton::clicked, this, &KRenameWindow::slotTokenHelpRequestedWizard4); connect(m_pageFilename->buttonFindSimple, &QPushButton::clicked, this, &KRenameWindow::showFindReplaceDialog); connect(m_pageFilename->spinDigits, static_cast(&QSpinBox::valueChanged), this, &KRenameWindow::slotSimpleTemplateChanged); connect(m_pageFilename->spinIndex, static_cast(&QSpinBox::valueChanged), this, &KRenameWindow::slotSimpleStartIndexChanged); } void KRenameWindow::showPage(int index) { if (index >= 0 && index < m_guiMode->numPages) { m_curPage = index; m_stack->setCurrentIndex(m_guiMode->mapIndex[index]); slotEnableControls(); } } void KRenameWindow::slotEnableControls() { // TODO: // Disable all extension widgets // if splitMode is NOEXTENSION if (m_buttonFinish) { bool enable = (m_curPage == m_guiMode->numPages - 1) && m_fileCount > 0; m_buttonFinish->setEnabled(enable); } // enable gui controls m_pageFiles->buttonRemove->setEnabled(m_fileCount); m_pageFiles->buttonRemoveAll->setEnabled(m_fileCount); m_pageFiles->checkName->setEnabled(m_pageFiles->checkPreview->isChecked()); m_pageFiles->buttonUp->setEnabled(m_fileCount); m_pageFiles->buttonDown->setEnabled(m_fileCount); m_pageDests->urlrequester->setEnabled(!m_pageDests->optionRename->isChecked()); m_pageFilename->extensionTemplate->setEnabled(!m_pageFilename->checkExtension->isChecked()); m_pageFilename->buttonFind->setEnabled(m_fileCount != 0); m_pageFilename->buttonNumbering->setEnabled(m_fileCount != 0); m_pageFilename->buttonInsert->setEnabled(m_fileCount != 0); m_pageFilename->buttonFindSimple->setEnabled(m_fileCount != 0); m_pageFilename->buttonHelp3->setEnabled(m_pageFilename->comboFilenameSimple->currentIndex() == m_pageFilename->comboFilenameSimple->count() - 1); m_pageFilename->comboFilenameCustom->setEnabled(m_pageFilename->comboFilenameSimple->currentIndex() == m_pageFilename->comboFilenameSimple->count() - 1); m_pageFilename->buttonHelp4->setEnabled(m_pageFilename->comboExtensionSimple->currentIndex() == m_pageFilename->comboExtensionSimple->count() - 1); m_pageFilename->comboExtensionCustom->setEnabled(m_pageFilename->comboExtensionSimple->currentIndex() == m_pageFilename->comboExtensionSimple->count() - 1); m_pageFilename->buttonUp->setEnabled(m_fileCount); m_pageFilename->buttonDown->setEnabled(m_fileCount); } void KRenameWindow::setCount(unsigned int count) { m_fileCount = count; m_pageFiles->labelCount->setText(i18n("Files: %1", m_fileCount)); m_pageFiles->fileList->slotUpdateCount(); this->slotEnableControls(); } void KRenameWindow::setFilenameTemplate(const QString &templ, bool insert) { if (insert) { m_pageFilename->filenameTemplate->lineEdit()->insert(templ); } else { m_pageFilename->filenameTemplate->lineEdit()->setText(templ); } } void KRenameWindow::setExtensionTemplate(const QString &templ, bool insert) { m_pageFilename->checkExtension->setChecked(true); m_pageFilename->comboExtensionSimple->setCurrentIndex( m_pageFilename->comboExtensionSimple->count() - 1); if (insert) { m_pageFilename->extensionTemplate->lineEdit()->insert(templ); } else { m_pageFilename->extensionTemplate->lineEdit()->setText(templ); } } void KRenameWindow::setRenameMode(ERenameMode eMode) { m_pageDests->optionRename->setChecked(false); m_pageDests->optionCopy->setChecked(false); m_pageDests->optionMove->setChecked(false); m_pageDests->optionLink->setChecked(false); switch (eMode) { case eRenameMode_Rename: m_pageDests->optionRename->setChecked(true); break; case eRenameMode_Copy: m_pageDests->optionCopy->setChecked(true); break; case eRenameMode_Move: m_pageDests->optionMove->setChecked(true); break; case eRenameMode_Link: m_pageDests->optionLink->setChecked(true); break; default: // Default m_pageDests->optionRename->setChecked(true); break; } this->slotEnableControls(); emit renameModeChanged(eMode); } void KRenameWindow::setDestinationUrl(const QUrl &url) { m_pageDests->urlrequester->setUrl(url); } void KRenameWindow::resetFileList() { m_pageFiles->fileList->reset(); } void KRenameWindow::setModel(KRenameModel *model) { m_pageFiles->fileList->setModel(model); m_pageFilename->listPreview->setKRenameModel(model); connect(model, &KRenameModel::maxDotsChanged, this, &KRenameWindow::slotMaxDotsChanged); } void KRenameWindow::setPreviewModel(KRenamePreviewModel *model) { m_pageFilename->listPreview->setModel(model); } const QUrl KRenameWindow::destinationUrl() const { return m_pageDests->urlrequester->url(); } QList KRenameWindow::selectedFileItems() const { QList selected; QItemSelectionModel *selection = m_pageFiles->fileList->selectionModel(); QModelIndexList indices = selection->selectedIndexes(); QModelIndexList::const_iterator it = indices.constBegin(); while (it != indices.constEnd()) { selected.append((*it).row()); ++it; } return selected; } QList KRenameWindow::selectedFileItemsPreview() const { QList selected; QItemSelectionModel *selection = m_pageFilename->listPreview->selectionModel(); QModelIndexList indices = selection->selectedIndexes(); QModelIndexList::const_iterator it = indices.constBegin(); while (it != indices.constEnd()) { selected.append((*it).row()); ++it; } return selected; } bool KRenameWindow::isPreviewEnabled() const { return m_pageFiles->checkPreview->isChecked(); } void KRenameWindow::setPreviewEnabled(bool bPreview) { m_pageFiles->checkPreview->setChecked(bPreview); slotPreviewChanged(); } bool KRenameWindow::isPreviewNamesEnabled() const { return m_pageFiles->checkName->isChecked(); } void KRenameWindow::setPreviewNamesEnabled(bool bPreview) { m_pageFiles->checkName->setChecked(bPreview); slotPreviewChanged(); } int KRenameWindow::numberStartIndex() const { return m_pageFilename->spinIndex->value(); } void KRenameWindow::setNumberStartIndex(int index) { m_pageFilename->spinIndex->setValue(index); } int KRenameWindow::sortMode() const { return m_pageFiles->comboSort->currentIndex(); } void KRenameWindow::setSortMode(int sortMode, const QString &customToken, int customSortMode) { KRenameModel *model = static_cast(m_pageFiles->fileList->model()); bool bPrevious = m_pageFiles->comboSort->blockSignals(true); QString customTokenText; if (sortMode == eSortMode_Token) { customTokenText = customToken; } m_pageFiles->comboSort->setCurrentIndex(sortMode); m_pageFiles->labelCustomSort->setText(customTokenText); model->sortFiles(static_cast(sortMode), customToken, static_cast(customSortMode)); m_pageFiles->comboSort->blockSignals(bPrevious); } int KRenameWindow::previewColumnWidth(int index) { return m_pageFilename->listPreview->columnWidth(index); } void KRenameWindow::setPreviewColumnWidth(int index, int width) { m_pageFilename->listPreview->setColumnWidth(index, width); } bool KRenameWindow::isAdvancedMode() const { return (m_pageFilename->tabWidget->currentIndex() == 0); } void KRenameWindow::setAdvancedMode(bool bAdvanced) { m_pageFilename->tabWidget->setCurrentIndex(bAdvanced ? 0 : 1); } void KRenameWindow::showFilenameTab() { m_tabBar->setCurrentIndex(MAX_PAGES - 1); if (this->isAdvancedMode()) { m_pageFilename->filenameTemplate->setFocus(); m_pageFilename->filenameTemplate->selectAll(); } else { m_pageFilename->comboPrefixCustom->setFocus(); m_pageFilename->comboPrefixCustom->selectAll(); } } void KRenameWindow::setPrefixSuffixSimple(QComboBox *combo, QComboBox *comboCustom, const QString &templ) { if (templ.isEmpty()) { comboCustom->lineEdit()->setText(templ); combo->setCurrentIndex(0); } else { QString number('#'); int c = m_pageFilename->spinDigits->value() - 1; while (c-- > 0) { number += '#'; } number += QString("{%1}").arg(m_pageFilename->spinIndex->value()); if (templ.startsWith(number)) { QString value = templ.right(templ.length() - number.length()); combo->setCurrentIndex(1); comboCustom->lineEdit()->setText(value); } else if (templ.startsWith(QLatin1String("[date]"))) { QString value = templ.right(templ.length() - 6); combo->setCurrentIndex(2); comboCustom->lineEdit()->setText(value); } else { combo->setCurrentIndex(0); comboCustom->lineEdit()->setText(templ); } } } QString KRenameWindow::getPrefixSuffixSimple(QComboBox *combo, QComboBox *comboCustom) { QString str; QString number('#'); int c = m_pageFilename->spinDigits->value() - 1; while (c-- > 0) { number += '#'; } number += QString("{%1}").arg(m_pageFilename->spinIndex->value()); if (combo->currentIndex() == 1) { str = number; } else if (combo->currentIndex() == 2) { str = "[date]"; // TODO date } str += comboCustom->currentText(); return str; } QString KRenameWindow::getFilenameSimple(QComboBox *combo, QComboBox *comboCustom) { QString str; // TODO: Replace strings with constants switch (combo->currentIndex()) { default: case 0: str = '$'; break; case 1: str = '%'; break; case 2: str = '&'; break; case 3: str = '*'; break; case 4: str = comboCustom->currentText(); } return str; } void KRenameWindow::slotBack() { this->showPage(m_curPage - 1); } void KRenameWindow::slotNext() { this->showPage(m_curPage + 1); } void KRenameWindow::slotFinish() { emit accepted(); } void KRenameWindow::slotRenameModeChanged() { ERenameMode mode = eRenameMode_Rename; if (m_pageDests->optionRename->isChecked()) { mode = eRenameMode_Rename; } else if (m_pageDests->optionCopy->isChecked()) { mode = eRenameMode_Copy; } else if (m_pageDests->optionMove->isChecked()) { mode = eRenameMode_Move; } else if (m_pageDests->optionLink->isChecked()) { mode = eRenameMode_Link; } emit renameModeChanged(mode); this->slotEnableControls(); } void KRenameWindow::slotGotoTemplatesPage() { m_tabBar->setCurrentIndex(3); } void KRenameWindow::slotSimpleStartIndexChanged() { emit startIndexChanged(m_pageFilename->spinIndex->value()); slotSimpleTemplateChanged(); } void KRenameWindow::slotTemplateChanged() { QString filename; QString extension; filename = m_pageFilename->filenameTemplate->currentText(); extension = m_pageFilename->checkExtension->isChecked() ? "$" : m_pageFilename->extensionTemplate->currentText(); // set the new templates also for simple mode blockSignalsRecursive(this, true); this->setSimpleTemplate(filename, extension); blockSignalsRecursive(this, false); this->templatesChanged(filename, extension); } void KRenameWindow::slotSimpleTemplateChanged() { QString filename = getFilenameSimple(m_pageFilename->comboFilenameSimple, m_pageFilename->comboFilenameCustom); QString extension = getFilenameSimple(m_pageFilename->comboExtensionSimple, m_pageFilename->comboExtensionCustom); QString prefix = getPrefixSuffixSimple(m_pageFilename->comboPrefix, m_pageFilename->comboPrefixCustom); QString suffix = getPrefixSuffixSimple(m_pageFilename->comboSuffix, m_pageFilename->comboSuffixCustom); filename = prefix + filename + suffix; // set the new templates, but make sure signals // are blockes so that slotTemplateChanged emits updatePreview() // which is calculation intensive only once! blockSignalsRecursive(this, true); m_pageFilename->filenameTemplate->lineEdit()->setText(filename); m_pageFilename->extensionTemplate->lineEdit()->setText(extension); m_pageFilename->checkExtension->setChecked(false); blockSignalsRecursive(this, false); this->templatesChanged(filename, extension); } void KRenameWindow::templatesChanged(const QString &filename, const QString &extension) { emit filenameTemplateChanged(filename); emit extensionTemplateChanged(extension); emit updatePreview(); m_pageFilename->buttonNumbering->setEnabled(filename.contains('#') || extension.contains('#')); this->slotEnableControls(); } void KRenameWindow::setSimpleTemplate(const QString &filename, const QString &extension) { // First set the simple extension from a template string if (extension == "$") { m_pageFilename->comboExtensionSimple->setCurrentIndex(0); } else if (extension == "%") { m_pageFilename->comboExtensionSimple->setCurrentIndex(1); } else if (extension == "&") { m_pageFilename->comboExtensionSimple->setCurrentIndex(2); } else if (extension == "*") { m_pageFilename->comboExtensionSimple->setCurrentIndex(3); } else { m_pageFilename->comboExtensionSimple->setCurrentIndex(4); m_pageFilename->comboExtensionCustom->lineEdit()->setText(extension); } // Now split the filename in prefix and suffix and set it as template // TODO: Make sure we do not find something like [*5-] or \$ int index = 4; int pos = filename.indexOf("$"); if (pos == -1) { pos = filename.indexOf("%"); if (pos == -1) { pos = filename.indexOf("&"); if (pos == -1) { pos = filename.indexOf("*"); if (pos != -1) { index = 3; } } else { index = 2; } } else { index = 1; } } else { index = 0; } m_pageFilename->comboFilenameSimple->setCurrentIndex(index); if (pos == -1) { // No token found, so we have no prefix or suffix but // a custom name. m_pageFilename->comboPrefixCustom->lineEdit()->setText(QString()); m_pageFilename->comboPrefix->setCurrentIndex(0); m_pageFilename->comboSuffixCustom->lineEdit()->setText(QString()); m_pageFilename->comboSuffix->setCurrentIndex(0); m_pageFilename->comboFilenameCustom->lineEdit()->setText(filename); } else { QString prefix = (pos > 0 ? filename.left(pos) : QString()); QString suffix = (pos < filename.length() ? filename.right(filename.length() - pos - 1) : QString()); setPrefixSuffixSimple(m_pageFilename->comboPrefix, m_pageFilename->comboPrefixCustom, prefix); setPrefixSuffixSimple(m_pageFilename->comboSuffix, m_pageFilename->comboSuffixCustom, suffix); } } void KRenameWindow::slotTokenHelpRequested() { emit showTokenHelpDialog(m_pageFilename->filenameTemplate->lineEdit()); } void KRenameWindow::slotTokenHelpRequestedWizard1() { emit showTokenHelpDialog(m_pageFilename->comboPrefixCustom->lineEdit()); } void KRenameWindow::slotTokenHelpRequestedWizard2() { emit showTokenHelpDialog(m_pageFilename->comboSuffixCustom->lineEdit()); } void KRenameWindow::slotTokenHelpRequestedWizard3() { emit showTokenHelpDialog(m_pageFilename->comboFilenameCustom->lineEdit()); } void KRenameWindow::slotTokenHelpRequestedWizard4() { emit showTokenHelpDialog(m_pageFilename->comboExtensionCustom->lineEdit()); } void KRenameWindow::setExtensionSplitMode(ESplitMode splitMode, int dot) { int index; switch (splitMode) { default: case eSplitMode_FirstDot: index = 0; break; case eSplitMode_LastDot: index = 1; break; case eSplitMode_NoExtension: index = 2; break; case eSplitMode_CustomDot: index = dot + 1; break; } m_pageFilename->comboExtension->setCurrentIndex(index); } void KRenameWindow::slotExtensionSplitModeChanged(int index) { ESplitMode splitMode; switch (index) { case 0: splitMode = eSplitMode_FirstDot; break; case 1: splitMode = eSplitMode_LastDot; break; case 2: splitMode = eSplitMode_NoExtension; break; default: splitMode = eSplitMode_CustomDot; break; } emit extensionSplitModeChanged(splitMode, index - 1); } void KRenameWindow::slotPreviewChanged() { KRenameModel *model = static_cast(m_pageFiles->fileList->model()); if (m_pageFiles->checkPreview->isChecked() && !m_pageFiles->checkName->isChecked()) { m_pageFiles->fileList->setViewMode(QListView::IconMode); } else { m_pageFiles->fileList->setViewMode(QListView::ListMode); } model->setEnablePreview(m_pageFiles->checkPreview->isChecked(), m_pageFiles->checkName->isChecked()); emit filePreviewChanged(m_pageFiles->checkPreview->isChecked(), m_pageFiles->checkName->isChecked()); m_pageFiles->fileList->setAcceptDrops(true); m_pageFiles->fileList->repaint(); this->slotEnableControls(); } void KRenameWindow::slotSortChanged(int index) { ESortMode eMode; KRenameModel *model = static_cast(m_pageFiles->fileList->model()); KRenameTokenSorter::ESimpleSortMode eCustomSortMode = model->getSortModeCustomMode(); QString customToken; switch (index) { default: case 0: eMode = eSortMode_Unsorted; break; case 1: eMode = eSortMode_Ascending; break; case 2: eMode = eSortMode_Descending; break; case 3: eMode = eSortMode_Numeric; break; case 4: eMode = eSortMode_Random; break; case 5: eMode = eSortMode_AscendingDate; break; case 6: eMode = eSortMode_DescendingDate; break; case 7: { eMode = eSortMode_Token; QPointer dlg = new TokenSortModeDialog(eCustomSortMode, this); if (dlg->exec() == QDialog::Accepted) { customToken = dlg->getToken(); eCustomSortMode = dlg->getSortMode(); } else { eMode = model->getSortMode(); // Do not change anything // Reset combo box m_pageFiles->comboSort->setCurrentIndex(eMode); return; } delete dlg; break; } } m_pageFiles->labelCustomSort->setText(customToken); model->sortFiles(eMode, customToken, eCustomSortMode); } void KRenameWindow::slotMaxDotsChanged(int dots) { int i; const int FILE_EXTENSION_VARIABLE_ITEMS_START = 3; for (i = FILE_EXTENSION_VARIABLE_ITEMS_START; i < m_pageFilename->comboExtension->count(); i++) { m_pageFilename->comboExtension->removeItem(i); } for (i = 1; i <= dots; ++i) { m_pageFilename->comboExtension->addItem(QString::number(i)); } } void KRenameWindow::slotOpenFile(const QModelIndex &index) { KRenameModel *model = static_cast(m_pageFiles->fileList->model()); model->run(index, this); } void KRenameWindow::slotMoveUp() { QList sel = this->selectedFileItems(); KRenameModel *model = static_cast(m_pageFiles->fileList->model()); model->moveFilesUp(sel); QItemSelectionModel *selection = m_pageFiles->fileList->selectionModel(); QList::const_iterator it = sel.constBegin(); while (it != sel.constEnd()) { if (*it - 1 > 0) { selection->select(model->createIndex(*it - 1), QItemSelectionModel::Select); } ++it; } // make sure that the first item is visible // TODO: Maybe it is better to calculate the minimum index here if (sel.size()) { m_pageFiles->fileList->scrollTo(model->createIndex(sel.front() - 1), QAbstractItemView::EnsureVisible); } } void KRenameWindow::slotMoveDown() { QList sel = this->selectedFileItems(); KRenameModel *model = static_cast(m_pageFiles->fileList->model()); model->moveFilesDown(sel); QItemSelectionModel *selection = m_pageFiles->fileList->selectionModel(); QList::const_iterator it = sel.constBegin(); while (it != sel.constEnd()) { if (*it + 1 < model->rowCount()) { selection->select(model->createIndex(*it + 1), QItemSelectionModel::Select); } ++it; } // make sure that the last item is visible // TODO: Maybe it is better to calculate the maximum index here if (sel.size()) { m_pageFiles->fileList->scrollTo(model->createIndex(sel.back() + 1), QAbstractItemView::EnsureVisible); } } void KRenameWindow::slotMoveUpPreview() { QList sel = this->selectedFileItemsPreview(); QAbstractItemView *view = m_pageFilename->listPreview; moveUp(sel, view); } void KRenameWindow::slotMoveDownPreview() { QList sel = this->selectedFileItemsPreview(); QAbstractItemView *view = m_pageFilename->listPreview; moveDown(sel, view); } void KRenameWindow::moveUp(const QList &selected, QAbstractItemView *view) { KRenameModel *model = static_cast(m_pageFiles->fileList->model()); model->moveFilesUp(selected); emit updatePreview(); QItemSelectionModel *selection = view->selectionModel(); QList::const_iterator it = selected.begin(); while (it != selected.end()) { if (*it - 1 > 0) { selection->select(model->createIndex(*it - 1), QItemSelectionModel::Select); } ++it; } // make sure that the first item is visible // TODO: Maybe it is better to calculate the minimum index here if (selected.size()) { view->scrollTo(model->createIndex(selected.front() - 1), QAbstractItemView::EnsureVisible); } } void KRenameWindow::moveDown(const QList &selected, QAbstractItemView *view) { KRenameModel *model = static_cast(m_pageFiles->fileList->model()); model->moveFilesDown(selected); emit updatePreview(); QItemSelectionModel *selection = view->selectionModel(); QList::const_iterator it = selected.begin(); while (it != selected.end()) { if (*it + 1 < model->rowCount()) { selection->select(model->createIndex(*it + 1), QItemSelectionModel::Select); } ++it; } // make sure that the last item is visible // TODO: Maybe it is better to calculate the maximum index here if (selected.size()) { view->scrollTo(model->createIndex(selected.back() + 1), QAbstractItemView::EnsureVisible); } } void KRenameWindow::slotPluginChanged(QTreeWidgetItem *selected) { QWidget *w = m_pluginsWidgetHash[selected->text(0)]; Plugin *p = m_pluginsHash[selected->text(0)]; - if (p->alwaysEnabled()) { + if (p->enabledByDefault()) { m_pagePlugins->checkEnablePlugin->setChecked(true); } else { m_pagePlugins->checkEnablePlugin->setChecked(p->isEnabled()); } - m_pagePlugins->checkEnablePlugin->setEnabled(!p->alwaysEnabled()); + //m_pagePlugins->checkEnablePlugin->setEnabled(!p->enabledByDefault()); m_pagePlugins->stackPlugins->setCurrentWidget(w); slotPluginEnabled(); } void KRenameWindow::slotPluginEnabled() { QTreeWidgetItem *selected = m_pagePlugins->listPlugins->currentItem(); if (selected) { QWidget *w = m_pluginsWidgetHash[selected->text(0)]; Plugin *p = m_pluginsHash[selected->text(0)]; p->setEnabled(m_pagePlugins->checkEnablePlugin->isChecked()); - w->setEnabled(p->alwaysEnabled() || m_pagePlugins->checkEnablePlugin->isChecked()); + w->setEnabled(p->enabledByDefault() || m_pagePlugins->checkEnablePlugin->isChecked()); } } void KRenameWindow::blockSignalsRecursive(QObject *obj, bool b) { if (obj) { obj->blockSignals(b); QList list = obj->children(); QList::iterator it = list.begin(); QObject *o = nullptr; while (it != list.end()) { o = *it; if (o && o != obj) { blockSignalsRecursive(o, b); } ++it; } } } diff --git a/src/permissionsplugin.h b/src/permissionsplugin.h index 4bf2e79..e18881a 100644 --- a/src/permissionsplugin.h +++ b/src/permissionsplugin.h @@ -1,170 +1,170 @@ /*************************************************************************** permissionsplugin.h - description ------------------- begin : Sun Mar 9 2008 copyright : (C) 2002 by Dominik Seichter email : domseichter@web.de ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef PERMISSIONS_PLUGIN_H #define PERMISSIONS_PLUGIN_H #include #ifndef Q_OS_WIN #include "plugin.h" #include namespace Ui { class PermissionsPluginWidget; }; /** This is the abstract interface that has to be implemented * by all KRename plugins. */ class PermissionsPlugin : public QObject, public Plugin { Q_OBJECT public: explicit PermissionsPlugin(PluginLoader *loader); ~PermissionsPlugin() override; /** * @returns a name of the plugin that can be displayed * to the user. This name should be internationalized. */ const QString name() const override; /** * Determines the type of the plugin. * Different enum values may be or'ed together. * * @returns the type of the plugin. */ inline int type() const override; /** * @returns an icon for this plugin. */ const QPixmap icon() const override; /** * @returns true if this plugins is always enabled * * Warning: If you return true here, the user has no possibility to * disable this plugin. */ - inline bool alwaysEnabled() const override; + inline bool enabledByDefault() const override; /** * This function is the core of your plugin. * * It does the actual processing of a file, filename or token depending of the type * of your plugin. * * \see type() * * @param b the parent BatchRenamer instance calling this plugin * @param index the index of the current file (i.e. the first file has index 0, * the second file to be renamed has index 1 ....) * @param filenameOrToken this parameter depends on the type of your plugin. * If type is ePluginType_File, this is the absolute path * or URL to the renamed file. * If type is ePluginType_Filename, this is the filename * (without path) as created by KRename. * If type is ePluginType_Token, this is the contents of a token * in brackets. If your plugin supports the token [example], * KRename will pass the strign "example" to your method. * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type) * * @returns the result of the function, depending on type(). * @returns QString::null if this plugin has nothing to do. * @returns A new filename if type is ePluginType_Filename * @returns the value of the token if type is ePluginType_Token * @returns an error message or QString::null if type is ePluginType_File */ QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) override; /** Get a list of all tokens supported by this plugin. * * If the token type != ePluginType_Token you have to return an empty list * * @returns a list of all supported tokens. The returned strings will be treated * as regular expressions to find a plugin which supports a token. */ inline const QStringList &supportedTokens() const override; /** Returns help descriptions for the supported tokens * * The returned stringlist contains strings that are the tokens * and the description separated by ;; * * @returns a stringlist containing help on the supported tokens */ inline const QStringList &help() const override; /** Create a user interface for this plugin * * @param parent the parent widget of this plugin */ void createUI(QWidget *parent) const override; private Q_SLOTS: void slotEnableControls(); void slotAdvancedPermissions(); void slotUpdatePermissions(); private: int getGid(const QString &group) const; int getUid(const QString &owner) const; //void setCurrentPermissions( int perm ); private: Ui::PermissionsPluginWidget *m_widget; int m_curPermission; ///< The current permissions QStringList m_tmp; ///< Dummy empty list so that we can return a reference for supported tokens and help QStringList m_users; ///< List of all usernames on the system QStringList m_groups; ///< List of all groups on the system }; inline int PermissionsPlugin::type() const { return ePluginType_File; } -inline bool PermissionsPlugin::alwaysEnabled() const +inline bool PermissionsPlugin::enabledByDefault() const { return false; } inline const QStringList &PermissionsPlugin::supportedTokens() const { return m_tmp; } inline const QStringList &PermissionsPlugin::help() const { return m_tmp; } #endif // Q_OS_WIN #endif /* PERMISSIONS_PLUGIN_H */ diff --git a/src/plugin.h b/src/plugin.h index 21cc9ea..43a8b83 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -1,205 +1,203 @@ /*************************************************************************** plugin.h - description ------------------- begin : Sun Dec 30 2001 copyright : (C) 2001 by Dominik Seichter email : domseichter@web.de ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef PLUGIN_H #define PLUGIN_H #include #include #include #include class BatchRenamer; class KConfigGroup; class PluginLoader; /** An enum to determine the correct plugin type. * * A plugin may be of different types at a time. */ enum EPluginType { ePluginType_Token = 0x01, ///< A plugin that handles a token in brackets [ ] ePluginType_Filename = 0x02, ///< A plugin that transforms the complete final filename ePluginType_File = 0x04 ///< A plugin that changes the finally renamed file }; /** This is the abstract interface that has to be implemented * by all KRename plugins. */ class Plugin { public: explicit Plugin(PluginLoader *loader); virtual ~Plugin(); /** * Creates a help entry for the QStringList returned by help, * adds correct separator and brackets where necessary. * * \param token the token ([ brackets ] will be added to surround it) * \help help for the token * * \see help() */ static QString createHelpEntry(const QString &token, const QString &help); /** * @returns a name of the plugin that can be displayed * to the user. This name should be internationalized. */ virtual const QString name() const = 0; /** * Determines the type of the plugin. * Different enum values may be or'ed together. * * @returns the type of the plugin. */ virtual int type() const = 0; /** * @returns an icon for this plugin. */ virtual const QPixmap icon() const = 0; /** Set the enabled state of a plugin * so that it can be used. * * \param b the enabled state of the plugin. - * - * This has no effect if alwaysEnabled returns true */ inline void setEnabled(bool b); /** * @returns true if this plugin is enabled. * Only use it if it is enabled. */ inline bool isEnabled() const; /** * @returns true if this plugins is always enabled * * Warning: If you return true here, the user has no possibility to * disable this plugin. */ - virtual bool alwaysEnabled() const = 0; + virtual bool enabledByDefault() const = 0; /** * This function is the core of your plugin. * * It does the actual processing of a file, filename or token depending of the type * of your plugin. * * \see type() * * @param b the parent BatchRenamer instance calling this plugin * @param index the index of the current file (i.e. the first file has index 0, * the second file to be renamed has index 1 ....) * @param filenameOrToken this parameter depends on the type of your plugin. * If type is ePluginType_File, this is the absolute path * or URL to the renamed file. * If type is ePluginType_Filename, this is the filename * (without path) as created by KRename. * If type is ePluginType_Token, this is the contents of a token * in brackets. If your plugin supports the token [example], * KRename will pass the strign "example" to your method. * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type) * * @returns the result of the function, depending on type(). * @returns QString::null if this plugin has nothing to do. * @returns A new filename if type is ePluginType_Filename * @returns the value of the token if type is ePluginType_Token * @returns an error message or QString::null if type is ePluginType_File */ virtual QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) = 0; /** Get a list of all tokens supported by this plugin. * * If the token type != ePluginType_Token you have to return an empty list * * @returns a list of all supported tokens. The returned strings will be treated * as regular expressions to find a plugin which supports a token. */ virtual const QStringList &supportedTokens() const = 0; /** Returns help descriptions for the supported tokens * * The returned stringlist contains strings that are the tokens * and the description separated by ;; * * @returns a stringlist containing help on the supported tokens */ virtual const QStringList &help() const = 0; /** Create a user interface for this plugin * * @param parent the parent widget of this plugin */ virtual void createUI(QWidget *parent) const = 0; /** Load the plugin configuration. * * Called when plugins should load their configuration. * * @param group config group where the configuration should be read from */ virtual void loadConfig(KConfigGroup &group); /** Save the plugin configuration. * * Called when plugins should save their configuration. * * @param group config group where the configuration should be stored */ virtual void saveConfig(KConfigGroup &group) const; /* virtual bool checkError() = 0; virtual void drawInterface( QWidget* w, QVBoxLayout* l ) = 0; virtual void fillStructure() { } virtual QString processFile( BatchRenamer* b, int i, QString token, int mode ) = 0; virtual void finished() { } virtual void addHelp( HelpDialogData* data ); virtual void removeHelp( HelpDialogData* data ); virtual void clearCache(); virtual const QPixmap getIcon() const; virtual const QStringList getKeys() const; */ protected: PluginLoader *m_pluginLoader; private: bool m_enabled; }; inline void Plugin::setEnabled(bool b) { m_enabled = b; } inline bool Plugin::isEnabled() const { - return this->alwaysEnabled() || m_enabled; + return this->enabledByDefault() || m_enabled; } #endif // PLUGIN_H diff --git a/src/scriptplugin.h b/src/scriptplugin.h index 424b22a..7efd8b8 100644 --- a/src/scriptplugin.h +++ b/src/scriptplugin.h @@ -1,227 +1,227 @@ /*************************************************************************** scriptplugin.h - description ------------------- begin : Fri Nov 9 2007 copyright : (C) 2007 by Dominik Seichter email : domseichter@web.de ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef SCRIPT_PLUGIN_H #define SCRIPT_PLUGIN_H #include "plugin.h" class QMenu; class KJSInterpreter; class KRenameFile; namespace Ui { class ScriptPluginWidget; }; class ScriptPlugin : public QObject, public Plugin { Q_OBJECT public: /** Create a new ScriptPlugin from * */ explicit ScriptPlugin(PluginLoader *loader); ~ScriptPlugin() override; /** * @returns a name of the plugin that can be displayed * to the user. This name should be internationalized. */ inline const QString name() const override; /** * @returns the type of the plugin. */ inline int type() const override; /** * @returns an icon for this plugin. */ const QPixmap icon() const override; /** * @returns true if this plugins is always enabled * * Warning: If you return true here, the user has no possibility to * disable this plugin. */ - inline bool alwaysEnabled() const override; + inline bool enabledByDefault() const override; /** * This function is the core of your plugin. * * It does the actual processing of a file, filename or token depending of the type * of your plugin. * * \see type() * * @param b the parent BatchRenamer instance calling this plugin * @param index the index of the current file (i.e. the first file has index 0, * the second file to be renamed has index 1 ....) * @param filenameOrToken this parameter depends on the type of your plugin. * If type is ePluginType_File, this is the absolute path * or URL to the renamed file. * If type is ePluginType_Filename, this is the filename * (without path) as created by KRename. * If type is ePluginType_Token, this is the contents of a token * in brackets. If your plugin supports the token [example], * KRename will pass the strign "example" to your method. * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type) * * @returns the result of the function, depending on type(). * @returns QString::null if this plugin has nothing to do. * @returns A new filename if type is ePluginType_Filename * @returns the value of the token if type is ePluginType_Token * @returns an error message or QString::null if type is ePluginType_File */ QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) override; /** Get a list of all tokens supported by this plugin. * * If the token type != ePluginType_Token you have to return an empty list * * @returns a list of all supported tokens. */ inline const QStringList &supportedTokens() const override; /** Returns help descriptions for the supported tokens * * The returned stringlist contains strings that are the tokens * and the description separated by ;; * * @returns a stringlist containing help on the supported tokens */ inline const QStringList &help() const override; /** Create a user interface for this plugin * * @param parent the parent widget of this plugin * * This is implemented here for all FilePlugin based classed */ void createUI(QWidget *parent) const override; /** Load the plugin configuration. * * Called when plugins should load their configuration. * * @param group config group where the configuration should be read from */ void loadConfig(KConfigGroup &group) override; /** Save the plugin configuration. * * Called when plugins should save their configuration. * * @param group config group where the configuration should be stored */ void saveConfig(KConfigGroup &group) const override; protected: /** * Adds a token to the list of supported tokens * * @param token will be a supported token from now on * * @see supports */ inline void addSupportedToken(const QString &token) { m_keys.append(token); } /** * Set all KRename internal variables on the internal * Interpreter object. * * @param file the KRenameFile where the values can be retrieved * @param index index of the current file */ void initKRenameVars(const KRenameFile &file, int index); /** * Insert a variable in the definitions textfield * at the current cursor position * * @param name variable name */ void insertVariable(const char *name); private Q_SLOTS: void slotEnableControls(); void slotAdd(); void slotRemove(); void slotSave(); void slotLoad(); void slotTest(); void slotInsertIndex(); void slotInsertUrl(); void slotInsertFilename(); void slotInsertExtension(); void slotInsertDirectory(); private: QString m_name; QString m_icon; QStringList m_keys; QStringList m_help; KJSInterpreter *m_interpreter; QWidget *m_parent; QMenu *m_menu; Ui::ScriptPluginWidget *m_widget; static const char *s_pszFileDialogLocation; ///< Static URL for KFileDialog static const char *s_pszVarNameIndex; static const char *s_pszVarNameUrl; static const char *s_pszVarNameFilename; static const char *s_pszVarNameExtension; static const char *s_pszVarNameDirectory; }; inline const QString ScriptPlugin::name() const { return m_name; } -inline bool ScriptPlugin::alwaysEnabled() const +inline bool ScriptPlugin::enabledByDefault() const { return true; } inline int ScriptPlugin::type() const { return ePluginType_Token; } inline const QStringList &ScriptPlugin::supportedTokens() const { return m_keys; } inline const QStringList &ScriptPlugin::help() const { return m_help; } #endif // FILE_PLUGIN_H