File indexing completed on 2022-10-04 17:30:12

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