new mainwindow.ui
[quassel.git] / main / global.h
1 /***************************************************************************
2  *   Copyright (C) 2005 by The Quassel Team                                *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _GLOBAL_H_
22 #define _GLOBAL_H_
23
24 /** The protocol version we use fo the communication between core and GUI */
25 #define GUI_PROTOCOL 1
26
27 class Global;
28
29 #include <QtCore>
30 //#include <QMutex>
31
32 /* Some global stuff */
33 typedef QMap<QString, QVariant> VarMap;
34 extern Global *global;
35
36 /**
37  * This class is mostly a globally synchronized data store, meant for storing systemwide settings such
38  * as identities or network lists. This class is a singleton, but not static as we'd like to use signals and
39  * slots with it.
40  * The global object is used in both Core and GUI clients. Storing and retrieving data is thread-safe.
41  * \note While updated data is propagated to all the remote parts of Quassel quite quickly, the synchronization
42  *       protocol is in no way designed to guarantee strict consistency at all times. In other words, it may
43  *       well happen that different instances of global data differ from one another for a little while until
44  *       all update messages have been processed. You should never rely on all global data stores being consistent.
45 */
46 class Global : public QObject {
47   Q_OBJECT
48
49   public:
50     Global();
51     //static Logger *getLogger();
52     //static void setLogger(Logger *);
53
54 //    static QIcon *getIcon(QString symbol);
55
56     QVariant getData(QString key, QVariant defaultValue = QVariant());
57     QStringList getKeys();
58
59   public slots:
60     void putData(QString key, QVariant data);      ///< Store data changed locally, will be propagated to all other clients and the core
61     void updateData(QString key, QVariant data);   ///< Update stored data if requested by the core or other clients
62
63   signals:
64     void dataPutLocally(QString key);
65     void dataUpdatedRemotely(QString key);  // sent by remote update only!
66
67   public:
68     enum RunMode { Monolithic, GUIOnly, CoreOnly };
69     static RunMode runMode;
70
71   private:
72     static void initIconMap();
73
74     //static Logger *logger;
75
76 //    static QString iconPath;
77     QHash<QString, QString> iconMap;
78     QMutex mutex;
79     QHash<QString, QVariant> data;
80 };
81
82 class Exception {
83   public:
84     Exception(QString msg = "Unknown Exception") : _msg(msg) {};
85     virtual inline QString msg() { return _msg; }
86
87   protected:
88     QString _msg;
89
90 };
91
92 #endif