File indexing completed on 2022-11-29 20:25:13

0001 /***************************************************************************
0002                           fileplugin.h  -  description
0003                              -------------------
0004     begin                : Mon Jul 1 2002
0005     copyright            : (C) 2002 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 FILE_PLUGIN_H
0019 #define FILE_PLUGIN_H
0020 
0021 #include "plugin.h"
0022 
0023 class KService;
0024 
0025 class FilePlugin : public Plugin
0026 {
0027 public:
0028     /** Create a new FilePlugin from a KService
0029      *
0030      *  @param service pointer to a KService
0031      */
0032     FilePlugin(PluginLoader *loader, KService *service);
0033 
0034     virtual ~FilePlugin();
0035 
0036     /**
0037      * @returns a name of the plugin that can be displayed
0038      *          to the user. This name should be internationalized.
0039      */
0040     inline virtual const QString name() const;
0041 
0042     /**
0043      * @returns the type of the plugin.
0044      */
0045     inline virtual int type() const;
0046 
0047     /**
0048      * @returns an icon for this plugin.
0049      */
0050     virtual const QPixmap icon() const;
0051 
0052     /**
0053      * @returns true if this plugins is always enabled
0054      *
0055      * Warning: If you return true here, the user has no possibility to
0056      *          disable this plugin.
0057      */
0058     inline virtual bool alwaysEnabled() const;
0059 
0060     /**
0061      * This function is the core of your plugin.
0062      *
0063      * It does the actual processing of a file, filename or token depending of the type
0064      * of your plugin.
0065      *
0066      * \see type()
0067      *
0068      * @param b the parent BatchRenamer instance calling this plugin
0069      * @param index the index of the current file (i.e. the first file has index 0,
0070      *              the second file to be renamed has index 1 ....)
0071      * @param filenameOrToken this parameter depends on the type of your plugin.
0072      *                        If type is ePluginType_File, this is the absolute path
0073      *                        or URL to the renamed file.
0074      *                        If type is ePluginType_Filename, this is the filename
0075      *                        (without path) as created by KRename.
0076      *                        If type is ePluginType_Token, this is the contents of a token
0077      *                        in brackets. If your plugin supports the token [example],
0078      *                        KRename will pass the strign "example" to your method.
0079      * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type)
0080      *
0081      * @returns the result of the function, depending on type().
0082      * @returns QString::null if this plugin has nothing to do.
0083      * @returns A new filename if type is ePluginType_Filename
0084      * @returns the value of the token if type is ePluginType_Token
0085      * @returns an error message or QString::null if type is ePluginType_File
0086      */
0087     virtual QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) = 0;
0088 
0089     /** Get a list of all tokens supported by this plugin.
0090      *
0091      *  If the token type != ePluginType_Token you have to return an empty list
0092      *
0093      *  @returns a list of all supported tokens.
0094      */
0095     inline virtual const QStringList &supportedTokens() const;
0096 
0097     /** Returns help descriptions for the supported tokens
0098      *
0099      *  The returned stringlist contains strings that are the tokens
0100      *  and the description separated by ;;
0101      *
0102      *  @returns a stringlist containing help on the supported tokens
0103      */
0104     inline virtual const QStringList &help() const;
0105 
0106     /** Create a user interface for this plugin
0107      *
0108      *  @param parent the parent widget of this plugin
0109      *
0110      *  This is implemented here for all FilePlugin based classed
0111      */
0112     void createUI(QWidget *parent) const;
0113 
0114 protected:
0115     FilePlugin(PluginLoader *loader);
0116 
0117     /**
0118      *  Checks if a token is supported by this plugin.
0119      *
0120      *  @param token a token
0121      *  @returns true if the token is supported
0122      *
0123      *  @see addSupportedToken
0124      */
0125     bool supports(const QString &token);
0126 
0127     /**
0128      *  Adds a token to the list of supported tokens
0129      *
0130      *  @param token will be a supported token from now on
0131      *
0132      *  @see supports
0133      */
0134     inline void addSupportedToken(const QString &token)
0135     {
0136         m_keys.append(token);
0137     }
0138 
0139 protected:
0140 
0141     QString m_name;
0142     QString m_comment;
0143     QString m_icon;
0144 
0145 private:
0146     QStringList m_keys;
0147 };
0148 
0149 inline const QString FilePlugin::name() const
0150 {
0151     return m_name;
0152 }
0153 
0154 inline bool FilePlugin::alwaysEnabled() const
0155 {
0156     return true;
0157 }
0158 
0159 inline int FilePlugin::type() const
0160 {
0161     return ePluginType_Token;
0162 }
0163 
0164 inline const QStringList &FilePlugin::supportedTokens() const
0165 {
0166     return m_keys;
0167 }
0168 
0169 inline const QStringList &FilePlugin::help() const
0170 {
0171     return m_keys;
0172 }
0173 
0174 #endif // FILE_PLUGIN_H