kexi

kexiactioncategories.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexiactioncategories.h"
21
22#include <kstaticdeleter.h>
23#include <kdebug.h>
24
25#include <tqmap.h>
26#include <tqasciidict.h>
27
28namespace Kexi {
29
31class ActionInternal
32{
33 public:
34 ActionInternal(int _categories)
35 : categories(_categories)
36 , supportedObjectTypes(0)
37 , allObjectTypesAreSupported(false)
38 {
39 }
40 ~ActionInternal() {
41 delete supportedObjectTypes;
42 }
43 int categories;
44 TQMap<int, bool> *supportedObjectTypes;
45 bool allObjectTypesAreSupported : 1;
46};
47
48static KStaticDeleter<ActionCategories> Kexi_actionCategoriesDeleter;
49ActionCategories* Kexi_actionCategories = 0;
50
52class ActionCategories::Private
53{
54 public:
55 Private()
56 {
57 actions.setAutoDelete(true);
58 }
59
60 TQAsciiDict<ActionInternal> actions;
61};
62
64{
65 if (!Kexi_actionCategories)
66 Kexi_actionCategoriesDeleter.setObject( Kexi_actionCategories, new ActionCategories() );
67 return Kexi_actionCategories;
68}
69
70}
71
72using namespace Kexi;
73
74//----------------------------------
75
76ActionCategories::ActionCategories()
77 : d( new Private() )
78{
79}
80
81ActionCategories::~ActionCategories()
82{
83 delete d;
84}
85
86void ActionCategories::addAction(const char* name, int categories,
87 KexiPart::ObjectTypes supportedObjectType1, KexiPart::ObjectTypes supportedObjectType2,
88 KexiPart::ObjectTypes supportedObjectType3, KexiPart::ObjectTypes supportedObjectType4,
89 KexiPart::ObjectTypes supportedObjectType5, KexiPart::ObjectTypes supportedObjectType6,
90 KexiPart::ObjectTypes supportedObjectType7, KexiPart::ObjectTypes supportedObjectType8)
91{
92 ActionInternal * a = d->actions.find( name );
93 if (a) {
94 a->categories |= categories;
95 }
96 else {
97 a = new ActionInternal(categories);
98 d->actions.insert(name, a);
99 }
100 if (supportedObjectType1) {
101 if (!a->supportedObjectTypes)
102 a->supportedObjectTypes = new TQMap<int, bool>();
103 a->supportedObjectTypes->insert(supportedObjectType1, true);
104 if (supportedObjectType2) {
105 a->supportedObjectTypes->insert(supportedObjectType2, true);
106 if (supportedObjectType3) {
107 a->supportedObjectTypes->insert(supportedObjectType3, true);
108 if (supportedObjectType4) {
109 a->supportedObjectTypes->insert(supportedObjectType4, true);
110 if (supportedObjectType5) {
111 a->supportedObjectTypes->insert(supportedObjectType5, true);
112 if (supportedObjectType6) {
113 a->supportedObjectTypes->insert(supportedObjectType6, true);
114 if (supportedObjectType7) {
115 a->supportedObjectTypes->insert(supportedObjectType7, true);
116 if (supportedObjectType8) {
117 a->supportedObjectTypes->insert(supportedObjectType8, true);
118 }
119 }
120 }
121 }
122 }
123 }
124 }
125 }
126}
127
128void ActionCategories::setAllObjectTypesSupported(const char* name, bool set)
129{
130 ActionInternal * a = d->actions.find( name );
131 if (a)
132 a->allObjectTypesAreSupported = set;
133 else
134 kexiwarn << "ActionCategories::setAllObjectTypesSupported(): no such action \"" << name << "\"" << endl;
135}
136
137int ActionCategories::actionCategories(const char* name) const
138{
139 const ActionInternal * a = d->actions.find( name );
140 return a ? a->categories : 0;
141}
142
143bool ActionCategories::actionSupportsObjectType(const char* name, KexiPart::ObjectTypes objectType) const
144{
145 const ActionInternal * a = d->actions.find( name );
146 if (a && a->allObjectTypesAreSupported)
147 return true;
148 return (a && a->supportedObjectTypes) ? a->supportedObjectTypes->contains(objectType) : false;
149}
A set of functions used to declare action categories.
void addAction(const char *name, int categories, KexiPart::ObjectTypes supportedObjectType1=(KexiPart::ObjectTypes) 0, KexiPart::ObjectTypes supportedObjectType2=(KexiPart::ObjectTypes) 0, KexiPart::ObjectTypes supportedObjectType3=(KexiPart::ObjectTypes) 0, KexiPart::ObjectTypes supportedObjectType4=(KexiPart::ObjectTypes) 0, KexiPart::ObjectTypes supportedObjectType5=(KexiPart::ObjectTypes) 0, KexiPart::ObjectTypes supportedObjectType6=(KexiPart::ObjectTypes) 0, KexiPart::ObjectTypes supportedObjectType7=(KexiPart::ObjectTypes) 0, KexiPart::ObjectTypes supportedObjectType8=(KexiPart::ObjectTypes) 0)
void setAllObjectTypesSupported(const char *name, bool set)
bool actionSupportsObjectType(const char *name, KexiPart::ObjectTypes objectType) const
int actionCategories(const char *name) const
Namespace for general Kexi functions.
Definition kexi.h:38
KEXICORE_EXPORT ActionCategories * actionCategories()