1 /***************************************************************************
2                       datetimeplugin.h  -  description
3                              -------------------
4     begin                : Sun Mar 9 2008
5     copyright            : (C) 2002 by Dominik Seichter
6     email                : domseichter@web.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef DATE_TIME_PLUGIN_H
19 #define DATE_TIME_PLUGIN_H
20 
21 #include <QtGlobal>
22 #ifndef Q_OS_WIN
23 
24 #include "plugin.h"
25 
26 #include <QObject>
27 
28 namespace Ui
29 {
30 class DateTimePluginWidget;
31 };
32 
33 class QDate;
34 class QTime;
35 
36 /** This is the abstract interface that has to be implemented
37  *  by all KRename plugins.
38  */
39 class DateTimePlugin : public QObject, public Plugin
40 {
41 
42     Q_OBJECT
43 
44 public:
45     explicit DateTimePlugin(PluginLoader *loader);
46     virtual ~DateTimePlugin();
47 
48     /**
49      * @returns a name of the plugin that can be displayed
50      *          to the user. This name should be internationalized.
51      */
52     virtual const QString name() const;
53 
54     /**
55      * Determines the type of the plugin.
56      * Different enum values may be or'ed together.
57      *
58      * @returns the type of the plugin.
59      */
60     inline virtual int type() const;
61 
62     /**
63      * @returns an icon for this plugin.
64      */
65     virtual const QPixmap icon() const;
66 
67     /**
68      * @returns true if this plugins is always enabled
69      *
70      * Warning: If you return true here, the user has no possibility to
71      *          disable this plugin.
72      */
73     inline virtual bool alwaysEnabled() const;
74 
75     /**
76      * This function is the core of your plugin.
77      *
78      * It does the actual processing of a file, filename or token depending of the type
79      * of your plugin.
80      *
81      * \see type()
82      *
83      * @param b the parent BatchRenamer instance calling this plugin
84      * @param index the index of the current file (i.e. the first file has index 0,
85      *              the second file to be renamed has index 1 ....)
86      * @param filenameOrToken this parameter depends on the type of your plugin.
87      *                        If type is ePluginType_File, this is the absolute path
88      *                        or URL to the renamed file.
89      *                        If type is ePluginType_Filename, this is the filename
90      *                        (without path) as created by KRename.
91      *                        If type is ePluginType_Token, this is the contents of a token
92      *                        in brackets. If your plugin supports the token [example],
93      *                        KRename will pass the strign "example" to your method.
94      * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type)
95      *
96      * @returns the result of the function, depending on type().
97      * @returns QString::null if this plugin has nothing to do.
98      * @returns A new filename if type is ePluginType_Filename
99      * @returns the value of the token if type is ePluginType_Token
100      * @returns an error message or QString::null if type is ePluginType_File
101      */
102     virtual QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType);
103 
104     /** Get a list of all tokens supported by this plugin.
105      *
106      *  If the token type != ePluginType_Token you have to return an empty list
107      *
108      *  @returns a list of all supported tokens. The returned strings will be treated
109      *           as regular expressions to find a plugin which supports a token.
110      */
111     inline virtual const QStringList &supportedTokens() const;
112 
113     /** Returns help descriptions for the supported tokens
114      *
115      *  The returned stringlist contains strings that are the tokens
116      *  and the description separated by ;;
117      *
118      *  @returns a stringlist containing help on the supported tokens
119      */
120     inline virtual const QStringList &help() const;
121 
122     /** Create a user interface for this plugin
123      *
124      *  @param parent the parent widget of this plugin
125      */
126     virtual void createUI(QWidget *parent) const;
127 
128 private Q_SLOTS:
129     void slotGetCurrentTime();
130 
131 private:
132     QString changeDateTime(const QString &filename, bool bModification, bool bAccess, const QDate &date, const QTime &time);
133 
134 private:
135     Ui::DateTimePluginWidget *m_widget;
136 
137     QStringList m_tmp; ///< Dummy empty list so that we can return a reference for supported tokens and help
138 };
139 
type()140 inline int DateTimePlugin::type() const
141 {
142     return ePluginType_File;
143 }
144 
alwaysEnabled()145 inline bool DateTimePlugin::alwaysEnabled() const
146 {
147     return false;
148 }
149 
supportedTokens()150 inline const QStringList &DateTimePlugin::supportedTokens() const
151 {
152     return m_tmp;
153 }
154 
help()155 inline const QStringList &DateTimePlugin::help() const
156 {
157     return m_tmp;
158 }
159 
160 #endif // Q_OS_WIN
161 
162 #endif /* DATE_TIME_PLUGIN_H */
163