summaryrefslogtreecommitdiffstats
path: root/ksquirrel/sq_kipimanager.h
blob: 7eeccc91084b3f88324ed055a69011e7272c12a9 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/***************************************************************************
                          sq_kipimanager.h  -  description
                             -------------------
    begin                :  Feb 5 2007
    copyright            : (C) 2007 by Baryshev Dmitry
    email                : ksquirrel.iv@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 SQ_KIPIMANAGER_H
#define SQ_KIPIMANAGER_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef Q_MOC_RUN
#define SQ_HAVE_KIPI
#endif // Q_MOC_RUN

#ifdef SQ_HAVE_KIPI

#include <tqmap.h>
#include <tqvaluevector.h>

#include <kaction.h>

#include <libkipi/plugin.h>

namespace KIPI { class PluginLoader; }

class TQWidget;

class KPopupMenu;

/*
 *  This subclass of KActionMenu should know which KActions
 *  are currently plugged in it.
 */
class SQ_ActionMenu : public KActionMenu
{
    public:
        SQ_ActionMenu(const TQString &text, TQObject *parent = 0, const char *name = 0);
        SQ_ActionMenu(const TQString &text, const TQString &icon, TQObject *parent = 0, const char *name = 0);

        /*
         *  remove() all KActions currently plugged.
         */
        ~SQ_ActionMenu();

        /*
         *  Reimplement insert() to let us remember "ka"
         */
        void insert(KAction *ka, int index = -1);

        int count() const;

    private:
        // Currently plugged KActions
        TQValueVector<KAction *> plugged;
};

inline
int SQ_ActionMenu::count() const
{
    return plugged.count();
}

/*
 *  KIPI plugins manager. It loads KIPI plugins and creates popup
 *  menu with all available actions.
 */
class SQ_KIPIManager : public TQObject
{
    Q_OBJECT
  TQ_OBJECT

    public:
	SQ_KIPIManager(TQWidget *_parent, const char *name = 0);
	~SQ_KIPIManager();

        KPopupMenu* popup() const;

        void loadPlugins();

    private:
        void clearMap();

    private slots:
        void slotReplug();
        void slotAboutToShow();

    private:
        typedef TQMap<KIPI::Category, SQ_ActionMenu*> CategoryMap;

        KIPI::PluginLoader *mPluginLoader;
        CategoryMap cmenus;
        KAction *noPlugin;
        TQWidget *parent;
        KPopupMenu *p;
        bool loaded;
};

inline
KPopupMenu* SQ_KIPIManager::popup() const
{
     return p;
}

#endif

#endif