File indexing completed on 2024-04-28 13:44:21
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 // SPDX-FileCopyrightText: 2009 Dominik Seichter <domseichter@web.de> 0003 0004 #ifndef DIR_SORT_PLUGIN_H 0005 #define DIR_SORT_PLUGIN_H 0006 0007 #include "plugin.h" 0008 #include "ui_dirsortpluginwidget.h" 0009 0010 #include <QUrl> 0011 0012 class DirSortPlugin : public Plugin 0013 { 0014 public: 0015 explicit DirSortPlugin(PluginLoader *loader); 0016 ~DirSortPlugin() override; 0017 0018 /** 0019 * @returns a name of the plugin that can be displayed 0020 * to the user. This name should be internationalized. 0021 */ 0022 const QString name() const override; 0023 0024 /** 0025 * Determines the type of the plugin. 0026 * Different enum values may be or'ed together. 0027 * 0028 * @returns the type of the plugin. 0029 */ 0030 int type() const override; 0031 0032 /** 0033 * @returns an icon for this plugin. 0034 */ 0035 const QIcon icon() const override; 0036 0037 /** 0038 * @returns true if this plugins is always enabled 0039 * 0040 * Warning: If you return true here, the user has no possibility to 0041 * disable this plugin. 0042 */ 0043 bool enabledByDefault() const override; 0044 0045 /** 0046 * This function is the core of your plugin. 0047 * 0048 * It does the actual processing of a file, filename or token depending of the type 0049 * of your plugin. 0050 * 0051 * \see type() 0052 * 0053 * @param b the parent BatchRenamer instance calling this plugin 0054 * @param index the index of the current file (i.e. the first file has index 0, 0055 * the second file to be renamed has index 1 ....) 0056 * @param filenameOrToken this parameter depends on the type of your plugin. 0057 * If type is ePluginType_File, this is the absolute path 0058 * or URL to the renamed file. 0059 * If type is ePluginType_Filename, this is the filename 0060 * (without path) as created by KRename. 0061 * If type is ePluginType_Token, this is the contents of a token 0062 * in brackets. If your plugin supports the token [example], 0063 * KRename will pass the strign "example" to your method. 0064 * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type) 0065 * 0066 * @returns the result of the function, depending on type(). 0067 * @returns an empty QString if this plugin has nothing to do. 0068 * @returns A new filename if type is ePluginType_Filename 0069 * @returns the value of the token if type is ePluginType_Token 0070 * @returns an error message or an empty QString if type is ePluginType_File 0071 */ 0072 QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) override; 0073 0074 /** Get a list of all tokens supported by this plugin. 0075 * 0076 * If the token type != ePluginType_Token you have to return an empty list 0077 * 0078 * @returns a list of all supported tokens. The returned strings will be treated 0079 * as regular expressions to find a plugin which supports a token. 0080 */ 0081 const QStringList &supportedTokens() const override; 0082 0083 /** Returns help descriptions for the supported tokens 0084 * 0085 * The returned stringlist contains strings that are the tokens 0086 * and the description separated by ;; 0087 * 0088 * @returns a stringlist containing help on the supported tokens 0089 */ 0090 const QStringList &help() const override; 0091 0092 /** Create a user interface for this plugin 0093 * 0094 * @param parent the parent widget of this plugin 0095 */ 0096 void createUI(QWidget *parent) const override; 0097 0098 private: 0099 /** 0100 * Create a new subdirectory with the current setting 0101 * from m_digits and m_dirCounter. 0102 * 0103 * \returns the URL of the new subdirectory. 0104 */ 0105 QUrl createNewSubdirectory() const; 0106 0107 protected: 0108 int m_dirCounter; 0109 int m_fileCounter; 0110 int m_filesPerDir; 0111 int m_digits; 0112 0113 QUrl m_baseDirectory; 0114 QUrl m_currentDirectory; 0115 0116 Ui::DirSortPluginWidget *m_widget; 0117 QStringList m_emptyList; 0118 0119 bool m_valid; 0120 0121 }; 0122 0123 #endif // DIR_SORT_PLUGIN