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

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