summaryrefslogtreecommitdiffstats
path: root/kexi/core/kexiactioncategories.cpp
blob: 03c09433b0c4a5bb812beadb15c4e2f261d6d985 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* This file is part of the KDE project
   Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>

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

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "kexiactioncategories.h"

#include <kstaticdeleter.h>
#include <kdebug.h>

#include <tqmap.h>
#include <tqasciidict.h>

namespace Kexi {

//! @internal
class ActionInternal
{
	public:
		ActionInternal(int _categories) 
		 : categories(_categories)
		 , supportedObjectTypes(0)
		 , allObjectTypesAreSupported(false)
		{
		}
		~ActionInternal() {
			delete supportedObjectTypes;
		}
		int categories;
		TQMap<int, bool> *supportedObjectTypes;
		bool allObjectTypesAreSupported : 1;
};

static KStaticDeleter<ActionCategories> Kexi_actionCategoriesDeleter;
ActionCategories* Kexi_actionCategories = 0;

//! @internal
class ActionCategories::Private
{
	public:
		Private()
		{
			actions.setAutoDelete(true);
		}

	TQAsciiDict<ActionInternal> actions;
};

KEXICORE_EXPORT ActionCategories *actionCategories()
{
	if (!Kexi_actionCategories)
		Kexi_actionCategoriesDeleter.setObject( Kexi_actionCategories, new ActionCategories() );
	return Kexi_actionCategories;
}

}

using namespace Kexi;

//----------------------------------

ActionCategories::ActionCategories()
 : d( new Private() )
{
}

ActionCategories::~ActionCategories()
{
	delete d;
}

void ActionCategories::addAction(const char* name, int categories,
	KexiPart::ObjectTypes supportedObjectType1, KexiPart::ObjectTypes supportedObjectType2,
	KexiPart::ObjectTypes supportedObjectType3, KexiPart::ObjectTypes supportedObjectType4, 
	KexiPart::ObjectTypes supportedObjectType5, KexiPart::ObjectTypes supportedObjectType6,
	KexiPart::ObjectTypes supportedObjectType7, KexiPart::ObjectTypes supportedObjectType8)
{
	ActionInternal * a = d->actions.find( name );
	if (a) {
		a->categories |= categories;
	}
	else {
		a = new ActionInternal(categories);
		d->actions.insert(name, a);
	}
	if (supportedObjectType1) {
		if (!a->supportedObjectTypes)
			a->supportedObjectTypes = new TQMap<int, bool>();
		a->supportedObjectTypes->insert(supportedObjectType1, true);
		if (supportedObjectType2) {
			a->supportedObjectTypes->insert(supportedObjectType2, true);
			if (supportedObjectType3) {
				a->supportedObjectTypes->insert(supportedObjectType3, true);
				if (supportedObjectType4) {
					a->supportedObjectTypes->insert(supportedObjectType4, true);
					if (supportedObjectType5) {
						a->supportedObjectTypes->insert(supportedObjectType5, true);
						if (supportedObjectType6) {
							a->supportedObjectTypes->insert(supportedObjectType6, true);
							if (supportedObjectType7) {
								a->supportedObjectTypes->insert(supportedObjectType7, true);
								if (supportedObjectType8) {
									a->supportedObjectTypes->insert(supportedObjectType8, true);
								}
							}
						}
					}
				}
			}
		}
	}
}

void ActionCategories::setAllObjectTypesSupported(const char* name, bool set)
{
	ActionInternal * a = d->actions.find( name );
	if (a)
		a->allObjectTypesAreSupported = set;
	else
		kexiwarn << "ActionCategories::setAllObjectTypesSupported(): no such action \"" << name << "\"" << endl;
}

int ActionCategories::actionCategories(const char* name) const
{
	const ActionInternal * a = d->actions.find( name );
	return a ? a->categories : 0;
}

bool ActionCategories::actionSupportsObjectType(const char* name, KexiPart::ObjectTypes objectType) const
{
	const ActionInternal * a = d->actions.find( name );
	if (a && a->allObjectTypesAreSupported)
		return true;
	return (a && a->supportedObjectTypes) ? a->supportedObjectTypes->contains(objectType) : false;
}