File indexing completed on 2022-12-06 21:12:04

0001 /***************************************************************************
0002                    increasecounterplugin.h  -  description
0003                              -------------------
0004     begin                : Tue Jul 15 2008
0005     copyright            : (C) 2008 by Dominik Seichter
0006     email                : domseichter@web.de
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #ifndef INCREASE_COUNTER_PLUGIN_H
0019 #define INCREASE_COUNTER_PLUGIN_H
0020 
0021 #include <plugin.h>
0022 
0023 namespace Ui
0024 {
0025 class IncreaseCounterPluginWidget;
0026 };
0027 
0028 /** This is the abstract interface that has to be implemented
0029  *  by all KRename plugins.
0030  */
0031 class IncreaseCounterPlugin : public QObject, public Plugin
0032 {
0033 
0034     Q_OBJECT
0035 
0036 public:
0037     explicit IncreaseCounterPlugin(PluginLoader *loader);
0038     virtual ~IncreaseCounterPlugin();
0039 
0040     /**
0041      * @returns a name of the plugin that can be displayed
0042      *          to the user. This name should be internationalized.
0043      */
0044     virtual const QString name() const;
0045 
0046     /**
0047      * Determines the type of the plugin.
0048      * Different enum values may be or'ed together.
0049      *
0050      * @returns the type of the plugin.
0051      */
0052     inline virtual int type() const;
0053 
0054     /**
0055      * @returns an icon for this plugin.
0056      */
0057     virtual const QPixmap icon() const;
0058 
0059     /**
0060      * @returns true if this plugins is always enabled
0061      *
0062      * Warning: If you return true here, the user has no possibility to
0063      *          disable this plugin.
0064      */
0065     inline virtual bool alwaysEnabled() const;
0066 
0067     /**
0068      * This function is the core of your plugin.
0069      *
0070      * It does the actual processing of a file, filename or token depending of the type
0071      * of your plugin.
0072      *
0073      * \see type()
0074      *
0075      * @param b the parent BatchRenamer instance calling this plugin
0076      * @param index the index of the current file (i.e. the first file has index 0,
0077      *              the second file to be renamed has index 1 ....)
0078      * @param filenameOrToken this parameter depends on the type of your plugin.
0079      *                        If type is ePluginType_File, this is the absolute path
0080      *                        or URL to the renamed file.
0081      *                        If type is ePluginType_Filename, this is the filename
0082      *                        (without path) as created by KRename.
0083      *                        If type is ePluginType_Token, this is the contents of a token
0084      *                        in brackets. If your plugin supports the token [example],
0085      *                        KRename will pass the strign "example" to your method.
0086      * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type)
0087      *
0088      * @returns the result of the function, depending on type().
0089      * @returns QString::null if this plugin has nothing to do.
0090      * @returns A new filename if type is ePluginType_Filename
0091      * @returns the value of the token if type is ePluginType_Token
0092      * @returns an error message or QString::null if type is ePluginType_File
0093      */
0094     virtual QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType);
0095 
0096     /** Get a list of all tokens supported by this plugin.
0097      *
0098      *  If the token type != ePluginType_Token you have to return an empty list
0099      *
0100      *  @returns a list of all supported tokens. The returned strings will be treated
0101      *           as regular expressions to find a plugin which supports a token.
0102      */
0103     inline virtual const QStringList &supportedTokens() const;
0104 
0105     /** Returns help descriptions for the supported tokens
0106      *
0107      *  The returned stringlist contains strings that are the tokens
0108      *  and the description separated by ;;
0109      *
0110      *  @returns a stringlist containing help on the supported tokens
0111      */
0112     inline virtual const QStringList &help() const;
0113 
0114     /** Create a user interface for this plugin
0115      *
0116      *  @param parent the parent widget of this plugin
0117      */
0118     virtual void createUI(QWidget *parent) const;
0119 
0120 private Q_SLOTS:
0121     /**
0122      * Called when the user changes the offset through the UI
0123      *
0124      * @param offset the new offset
0125      */
0126     void slotOffsetChanged(int offset);
0127 
0128 private:
0129     Ui::IncreaseCounterPluginWidget *m_widget;
0130 
0131     int m_offset;         ///< Increase counter by this offset
0132 
0133     QStringList m_tmp;    ///< Dummy empty list so that we can return a reference for supported tokens and help
0134     QStringList m_users;  ///< List of all usernames on the system
0135     QStringList m_groups; ///< List of all groups on the system
0136 };
0137 
0138 inline int IncreaseCounterPlugin::type() const
0139 {
0140     return ePluginType_Filename;
0141 }
0142 
0143 inline bool IncreaseCounterPlugin::alwaysEnabled() const
0144 {
0145     return false;
0146 }
0147 
0148 inline const QStringList &IncreaseCounterPlugin::supportedTokens() const
0149 {
0150     return m_tmp;
0151 }
0152 
0153 inline const QStringList &IncreaseCounterPlugin::help() const
0154 {
0155     return m_tmp;
0156 }
0157 
0158 #endif // INCREASE_COUNTER_PLUGIN_H
0159