kexi

kexiactioncategories.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kexiactioncategories.h"
00021 
00022 #include <kstaticdeleter.h>
00023 #include <kdebug.h>
00024 
00025 #include <qmap.h>
00026 #include <qasciidict.h>
00027 
00028 namespace Kexi {
00029 
00031 class ActionInternal
00032 {
00033     public:
00034         ActionInternal(int _categories) 
00035          : categories(_categories)
00036          , supportedObjectTypes(0)
00037          , allObjectTypesAreSupported(false)
00038         {
00039         }
00040         ~ActionInternal() {
00041             delete supportedObjectTypes;
00042         }
00043         int categories;
00044         QMap<int, bool> *supportedObjectTypes;
00045         bool allObjectTypesAreSupported : 1;
00046 };
00047 
00048 static KStaticDeleter<ActionCategories> Kexi_actionCategoriesDeleter;
00049 ActionCategories* Kexi_actionCategories = 0;
00050 
00052 class ActionCategories::Private
00053 {
00054     public:
00055         Private()
00056         {
00057             actions.setAutoDelete(true);
00058         }
00059 
00060     QAsciiDict<ActionInternal> actions;
00061 };
00062 
00063 KEXICORE_EXPORT ActionCategories *actionCategories()
00064 {
00065     if (!Kexi_actionCategories)
00066         Kexi_actionCategoriesDeleter.setObject( Kexi_actionCategories, new ActionCategories() );
00067     return Kexi_actionCategories;
00068 }
00069 
00070 }
00071 
00072 using namespace Kexi;
00073 
00074 //----------------------------------
00075 
00076 ActionCategories::ActionCategories()
00077  : d( new Private() )
00078 {
00079 }
00080 
00081 ActionCategories::~ActionCategories()
00082 {
00083     delete d;
00084 }
00085 
00086 void ActionCategories::addAction(const char* name, int categories,
00087     KexiPart::ObjectTypes supportedObjectType1, KexiPart::ObjectTypes supportedObjectType2,
00088     KexiPart::ObjectTypes supportedObjectType3, KexiPart::ObjectTypes supportedObjectType4, 
00089     KexiPart::ObjectTypes supportedObjectType5, KexiPart::ObjectTypes supportedObjectType6,
00090     KexiPart::ObjectTypes supportedObjectType7, KexiPart::ObjectTypes supportedObjectType8)
00091 {
00092     ActionInternal * a = d->actions.find( name );
00093     if (a) {
00094         a->categories |= categories;
00095     }
00096     else {
00097         a = new ActionInternal(categories);
00098         d->actions.insert(name, a);
00099     }
00100     if (supportedObjectType1) {
00101         if (!a->supportedObjectTypes)
00102             a->supportedObjectTypes = new QMap<int, bool>();
00103         a->supportedObjectTypes->insert(supportedObjectType1, true);
00104         if (supportedObjectType2) {
00105             a->supportedObjectTypes->insert(supportedObjectType2, true);
00106             if (supportedObjectType3) {
00107                 a->supportedObjectTypes->insert(supportedObjectType3, true);
00108                 if (supportedObjectType4) {
00109                     a->supportedObjectTypes->insert(supportedObjectType4, true);
00110                     if (supportedObjectType5) {
00111                         a->supportedObjectTypes->insert(supportedObjectType5, true);
00112                         if (supportedObjectType6) {
00113                             a->supportedObjectTypes->insert(supportedObjectType6, true);
00114                             if (supportedObjectType7) {
00115                                 a->supportedObjectTypes->insert(supportedObjectType7, true);
00116                                 if (supportedObjectType8) {
00117                                     a->supportedObjectTypes->insert(supportedObjectType8, true);
00118                                 }
00119                             }
00120                         }
00121                     }
00122                 }
00123             }
00124         }
00125     }
00126 }
00127 
00128 void ActionCategories::setAllObjectTypesSupported(const char* name, bool set)
00129 {
00130     ActionInternal * a = d->actions.find( name );
00131     if (a)
00132         a->allObjectTypesAreSupported = set;
00133     else
00134         kexiwarn << "ActionCategories::setAllObjectTypesSupported(): no such action \"" << name << "\"" << endl;
00135 }
00136 
00137 int ActionCategories::actionCategories(const char* name) const
00138 {
00139     const ActionInternal * a = d->actions.find( name );
00140     return a ? a->categories : 0;
00141 }
00142 
00143 bool ActionCategories::actionSupportsObjectType(const char* name, KexiPart::ObjectTypes objectType) const
00144 {
00145     const ActionInternal * a = d->actions.find( name );
00146     if (a && a->allObjectTypesAreSupported)
00147         return true;
00148     return (a && a->supportedObjectTypes) ? a->supportedObjectTypes->contains(objectType) : false;
00149 }
KDE Home | KDE Accessibility Home | Description of Access Keys