File indexing completed on 2024-04-21 04:02:53

0001 //
0002 // C++ Interface: cActionManager
0003 //
0004 // Description: action manager
0005 //
0006 /*
0007 Copyright 2005-2011 Tomas Mecir <kmuddy@kmuddy.com>
0008 
0009 This program is free software; you can redistribute it and/or
0010 modify it under the terms of the GNU General Public License as
0011 published by the Free Software Foundation; either version 2 of 
0012 the License, or (at your option) any later version.
0013 
0014 This program is distributed in the hope that it will be useful,
0015 but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 GNU General Public License for more details.
0018 
0019 You should have received a copy of the GNU General Public License
0020 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #ifndef CACTIONMANAGER_H
0024 #define CACTIONMANAGER_H
0025 
0026 class cTextChunk;
0027 struct cActionManagerPrivate;
0028 
0029 class QWidget;
0030 class KActionCollection;
0031 class KMainWindow;
0032 
0033 #include <cactionbase.h>
0034 
0035 #include <list>
0036 
0037 #include <kmuddy_export.h>
0038 
0039 using namespace std;
0040 
0041 /**
0042 This is the action manager, it registers objects, actions and events, everyone who wants to use it must register with it. Registration is done automatically in cActionBase.
0043 
0044 It remembers who wants to receive which event and routes them as needed, also remembers the session-specific objects belonging to each session and returns pointers to them if needed.
0045 
0046 
0047 @author Tomas Mecir
0048 */
0049 class KMUDDY_EXPORT cActionManager {
0050  public:
0051   static cActionManager *self ();
0052   /** destructor */
0053   ~cActionManager ();
0054   
0055   void registerSession (int id);
0056   void unregisterSession (int id);
0057   bool sessionExists (int id);
0058   list<int> sessionList ();
0059   /** Session count. */
0060   int sessions ();
0061   
0062   void setSessionAttrib (int sess, const QString &name, int value);
0063   void setSessionStrAttrib (int sess, const QString &name, const QString &value);
0064   int sessionAttrib (int sess, const QString &name);
0065   QString sessionStrAttrib (int sess, const QString &name);
0066   
0067   int activeSession ();
0068   void setActiveSession (int sess);
0069 
0070   void registerObject (cActionBase *ab, int session = -1);
0071   void unregisterObject (cActionBase *ab, int session = -1);
0072 
0073   cActionBase *object (const QString &name, int session = 0);  
0074 
0075   /** add action of an object - name must be unique (per object) */
0076   void addEventHandler (cActionBase *ab, int session, QString name, int priority, ParamType pt);
0077   void removeEventHandler (cActionBase *ab, int session, QString name);
0078   
0079   /** call an object's action - PT_INT parameter */
0080   QString callAction (QString objectName, QString action, int session, int par1, int par2=0);
0081   /** call an object's action - PT_STRING parameter */
0082   QString callAction (QString objectName, QString action, int session,
0083       QString &par1, const QString &par2=QString());
0084   /** as above, but with const string */
0085   QString callAction (QString objectName, QString action, int session,
0086       const QString &par1, const QString &par2=QString());
0087   /** call an object's action - PT_NOTHING parameter */
0088   QString callAction (QString objectName, QString action, int session);
0089   /** call an object's action - PT_TEXTCHUNK parameter */
0090   QString callAction (QString objectName, QString action, int session, cTextChunk *par);
0091   /** call an object's action - PT_POINTER parameter */
0092   QString callAction (QString objectName, QString action, int session, void *par);
0093 
0094   /** invoke an event - PT_INT parameter */
0095   void invokeEvent (QString event, int session, int par1, int par2 = 0);
0096   /** invoke an event - PT_STRING parameter */
0097   void invokeEvent (QString event, int session, QString &par1,
0098       const QString &par2 = QString());
0099   /** as above, but const string */
0100   void invokeEvent (QString event, int session, const QString &par1,
0101       const QString &par2 = QString());
0102   /** invoke an event - PT_NOTHING parameter */
0103   void invokeEvent (QString event, int session);
0104   /** invoke an event - PT_TEXTCHUNK parameter */
0105   void invokeEvent (QString event, int session, cTextChunk *par);
0106   /** invoke an event - PT_POINTER parameter */
0107   void invokeEvent (QString event, int session, void *par);
0108 
0109   // Shortcuts
0110   void createACol (QWidget *widget);
0111   KActionCollection *getACol ();
0112 
0113   /** Set pointer to the main window. */
0114   void setMainWindow (KMainWindow *window);
0115   /** Pointer to the main window. */
0116   KMainWindow *mainWindow ();
0117   /** Pointer to the main window as a QWidget. */
0118   QWidget *mainWidget ();
0119  private:
0120   /** constructor */
0121   cActionManager ();
0122   static cActionManager *_self;
0123   cActionManagerPrivate *d;
0124 };
0125 
0126 #endif