4ec49eb81e4aac378ef1735d0950c8d429d1b612
[quassel.git] / src / common / 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 3
26
27 #define BACKLOG_FORMAT 2
28 #define BACKLOG_STRING "QuasselIRC Backlog File"
29
30 #define DEFAULT_PORT 4242
31
32 #include <QHash>
33 #include <QMutex>
34 #include <QString>
35 #include <QVariant>
36
37 /* Some global stuff */
38
39 typedef uint UserId;
40 typedef uint MsgId;
41
42 namespace Global {
43   enum RunMode { Monolithic, ClientOnly, CoreOnly };
44   extern RunMode runMode;
45   extern QString quasselDir;
46 }
47
48 struct Exception {
49     Exception(QString msg = "Unknown Exception") : _msg(msg) {};
50     virtual ~Exception() {}; // make gcc happy
51     virtual inline QString msg() { return _msg; }
52
53   protected:
54     QString _msg;
55
56 };
57
58 class BufferId {
59   public:
60     BufferId() { id = gid = 0; } // FIXME
61     BufferId(uint uid, QString net, QString buf, uint gid = 0);
62
63     inline uint uid() const { return id; }
64     inline uint groupId() const { return gid; }
65     inline QString network() const { return net; }
66     QString buffer() const; // nickfrommask?
67
68     void setGroupId(uint _gid) { gid = _gid; }
69
70     inline bool operator==(const BufferId &other) const { return id == other.id; }
71
72   private:
73     uint id;
74     uint gid;
75     QString net;
76     QString buf;
77
78     friend uint qHash(const BufferId &);
79     friend QDataStream &operator<<(QDataStream &out, const BufferId &bufferId);
80     friend QDataStream &operator>>(QDataStream &in, BufferId &bufferId);
81 };
82
83 QDataStream &operator<<(QDataStream &out, const BufferId &bufferId);
84 QDataStream &operator>>(QDataStream &in, BufferId &bufferId);
85
86 Q_DECLARE_METATYPE(BufferId);
87
88 uint qHash(const BufferId &);
89
90 #endif