summaryrefslogtreecommitdiffstats
path: root/krename/pluginloader.h
blob: 234a35c930dd4722284d786aa43c81dbd1815d98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/***************************************************************************
                          pluginloader.h  -  description
                             -------------------
    begin                : Sun Dec 30 2001
    copyright            : (C) 2001 by Dominik Seichter
    email                : domseichter@web.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef PLUGINLOADER_H
#define PLUGINLOADER_H

// Own includes
#include "batchrenamer.h"
#include "plugin.h"

#include <qmap.h>
#include <qptrlist.h>

class QCheckBox;
class QVBoxLayout;
class QString;
class QWidget;

#define NUM_INTERNAL_PLUGINS 8

enum pluginType {
    TYPE_BRACKET = 2,       // Plugin argument is in brackets like [artist] or [1-2]
    TYPE_TOKEN = 4,         // Plugin has its own reserved token like ,& or /
    TYPE_FINAL_FILE = 8,    // Plugin does something with the final file
                            // i.e. that is not changing its name but its permission or similar!
    TYPE_FINAL_FILENAME = 16  // Plugin changes the final filename before renaming
};

class PluginLoader {
    public:
        // For RedHat :)
        struct PluginLibrary {
            Plugin *plugin;
            bool usePlugin;

            /* access this member only
             * from within KRenameImpl
             * when the GUI is already constructed!
             */
            QCheckBox* check;
        };

        static PluginLoader* instance();

        void loadPlugins( bool fileplugins );
        QPtrList<PluginLoader::PluginLibrary> libs;
        
        Plugin* findPlugin( const QString & token );
        
        inline bool filePluginsLoaded() const;

        void clearCache();
        
    private:
        PluginLoader();
        ~PluginLoader();

        void addPlugin( Plugin* plugin );
        void loadFilePlugins();
        
    private:

        Plugin* m_internal_plugins[NUM_INTERNAL_PLUGINS];
        static PluginLoader* m_plugin;

        QMap<QString,Plugin*> m_bracket_map;
        QMap<QString,Plugin*> m_bracket_cache;
        
        bool m_loaded;
        bool m_file;
};

bool PluginLoader::filePluginsLoaded() const
{ 
    return m_file;
}

#endif