File indexing completed on 2024-04-21 05:51:47

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2007 Dominik Seichter <domseichter@web.de>
0003 
0004 #ifndef SYSTEM_PLUGIN_H
0005 #define SYSTEM_PLUGIN_H
0006 
0007 #include "fileplugin.h"
0008 
0009 class SystemPlugin : public FilePlugin
0010 {
0011 public:
0012     /** Create a new SystemPlugin
0013      */
0014     explicit SystemPlugin(PluginLoader *loader);
0015 
0016     ~SystemPlugin() 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     inline const QString name() const override;
0023 
0024     /**
0025      * @returns the type of the plugin.
0026      */
0027     inline int type() const override;
0028 
0029     /**
0030      * This function is the core of your plugin.
0031      *
0032      * It does the actual processing of a file, filename or token depending of the type
0033      * of your plugin.
0034      *
0035      * \see type()
0036      *
0037      * @param b the parent BatchRenamer instance calling this plugin
0038      * @param index the index of the current file (i.e. the first file has index 0,
0039      *              the second file to be renamed has index 1 ....)
0040      * @param filenameOrToken this parameter depends on the type of your plugin.
0041      *                        If type is ePluginType_File, this is the absolute path
0042      *                        or URL to the renamed file.
0043      *                        If type is ePluginType_Filename, this is the filename
0044      *                        (without path) as created by KRename.
0045      *                        If type is ePluginType_Token, this is the contents of a token
0046      *                        in brackets. If your plugin supports the token [example],
0047      *                        KRename will pass the strign "example" to your method.
0048      * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type)
0049      *
0050      * @returns the result of the function, depending on type().
0051      * @returns an empty QString if this plugin has nothing to do.
0052      * @returns A new filename if type is ePluginType_Filename
0053      * @returns the value of the token if type is ePluginType_Token
0054      * @returns an error message or an empty QString if type is ePluginType_File
0055      */
0056     QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) override;
0057 
0058     /** Returns help descriptions for the supported tokens
0059      *
0060      *  The returned stringlist contains strings that are the tokens
0061      *  and the description separated by ;;
0062      *
0063      *  @returns a stringlist containing help on the supported tokens
0064      */
0065     inline const QStringList &help() const override;
0066 
0067 private:
0068     const QString time(time_t time, const QString &format);
0069 
0070 private:
0071     QStringList m_help;
0072 
0073 };
0074 
0075 inline const QString SystemPlugin::name() const
0076 {
0077     return m_name;
0078 }
0079 
0080 inline int SystemPlugin::type() const
0081 {
0082     return ePluginType_Token;
0083 }
0084 
0085 inline const QStringList &SystemPlugin::help() const
0086 {
0087     return m_help;
0088 }
0089 
0090 #endif // SYSTEM_PLUGIN_H