File indexing completed on 2024-04-14 15:51:31

0001 /***************************************************************************
0002                           dirsortplugin.h  -  description
0003                              -------------------
0004     begin                : Sun Dec 27 2009
0005     copyright            : (C) 2009 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 DIR_SORT_PLUGIN_H
0019 #define DIR_SORT_PLUGIN_H
0020 
0021 #include "plugin.h"
0022 #include "ui_dirsortpluginwidget.h"
0023 
0024 #include <QUrl>
0025 
0026 class DirSortPlugin : public Plugin
0027 {
0028 public:
0029     explicit DirSortPlugin(PluginLoader *loader);
0030     ~DirSortPlugin();
0031 
0032     /**
0033      * @returns a name of the plugin that can be displayed
0034      *          to the user. This name should be internationalized.
0035      */
0036     virtual const QString name() const;
0037 
0038     /**
0039      * Determines the type of the plugin.
0040      * Different enum values may be or'ed together.
0041      *
0042      * @returns the type of the plugin.
0043      */
0044     virtual int type() const;
0045 
0046     /**
0047      * @returns an icon for this plugin.
0048      */
0049     virtual const QPixmap icon() const;
0050 
0051     /**
0052      * @returns true if this plugins is always enabled
0053      *
0054      * Warning: If you return true here, the user has no possibility to
0055      *          disable this plugin.
0056      */
0057     virtual bool alwaysEnabled() const;
0058 
0059     /**
0060      * This function is the core of your plugin.
0061      *
0062      * It does the actual processing of a file, filename or token depending of the type
0063      * of your plugin.
0064      *
0065      * \see type()
0066      *
0067      * @param b the parent BatchRenamer instance calling this plugin
0068      * @param index the index of the current file (i.e. the first file has index 0,
0069      *              the second file to be renamed has index 1 ....)
0070      * @param filenameOrToken this parameter depends on the type of your plugin.
0071      *                        If type is ePluginType_File, this is the absolute path
0072      *                        or URL to the renamed file.
0073      *                        If type is ePluginType_Filename, this is the filename
0074      *                        (without path) as created by KRename.
0075      *                        If type is ePluginType_Token, this is the contents of a token
0076      *                        in brackets. If your plugin supports the token [example],
0077      *                        KRename will pass the strign "example" to your method.
0078      * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type)
0079      *
0080      * @returns the result of the function, depending on type().
0081      * @returns QString::null if this plugin has nothing to do.
0082      * @returns A new filename if type is ePluginType_Filename
0083      * @returns the value of the token if type is ePluginType_Token
0084      * @returns an error message or QString::null if type is ePluginType_File
0085      */
0086     virtual QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType);
0087 
0088     /** Get a list of all tokens supported by this plugin.
0089      *
0090      *  If the token type != ePluginType_Token you have to return an empty list
0091      *
0092      *  @returns a list of all supported tokens. The returned strings will be treated
0093      *           as regular expressions to find a plugin which supports a token.
0094      */
0095     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     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     virtual void createUI(QWidget *parent) const;
0111 
0112 private:
0113     /**
0114      * Create a new subdirectory with the current setting
0115      * from m_digits and m_dirCounter.
0116      *
0117      * \returns the URL of the new subdirectory.
0118      */
0119     QUrl createNewSubdirectory() const;
0120 
0121 protected:
0122     int m_dirCounter;
0123     int m_fileCounter;
0124     int m_filesPerDir;
0125     int m_digits;
0126 
0127     QUrl m_baseDirectory;
0128     QUrl m_currentDirectory;
0129 
0130     Ui::DirSortPluginWidget *m_widget;
0131     QStringList m_emptyList;
0132 
0133     bool m_valid;
0134 
0135 };
0136 
0137 #endif // DIR_SORT_PLUGIN