File indexing completed on 2024-04-21 16:32:29

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