Newest version of QuasselTopia, and some minor random fixes.
[quassel.git] / src / common / networkinfo.h
1 /***************************************************************************
2  *   Copyright (C) 2005/06 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 _NETWORKINFO_H_
22 #define _NETWORKINFO_H_
23
24 #include <QString>
25 #include <QStringList>
26 #include <QList>
27 #include <QHash>
28 #include <QVariantMap>
29 #include <QPointer>
30
31 class SignalProxy;
32 class Synchronizer;
33 class IrcUser;
34 class IrcChannel;
35
36
37 class NetworkInfo : public QObject {
38   Q_OBJECT
39
40   Q_PROPERTY(QString networkName READ networkName WRITE setNetworkName STORED false)
41   Q_PROPERTY(QString currentServer READ currentServer WRITE setCurrentServer STORED false)
42   Q_PROPERTY(QString myNick READ myNick WRITE setMyNick STORED false)
43
44 public:
45   NetworkInfo(const uint &networkid, SignalProxy *proxy, QObject *parent = 0);
46   //  virtual ~NetworkInfo();
47
48   uint networkId() const;
49   bool initialized() const;
50   Synchronizer *synchronizer();
51
52   bool isMyNick(const QString &nick) const;
53   bool isMyNick(IrcUser *ircuser) const;
54
55   bool isChannelName(const QString &channelname) const;
56
57   QString prefixToMode(const QString &prefix);
58   QString prefixToMode(const QCharRef &prefix);
59   QString modeToPrefix(const QString &mode);
60   QString modeToPrefix(const QCharRef &mode);
61   
62   QString networkName() const;
63   QString currentServer() const;
64   QString myNick() const;
65   QStringList nicks() const;
66   QStringList channels() const;
67
68   QString prefixes();
69   QString prefixModes();
70
71   bool supports(const QString &param) const;
72   QString support(const QString &param) const;
73   
74   IrcUser *newIrcUser(const QString &hostmask);
75   IrcUser *ircUser(const QString &nickname) const;
76   QList<IrcUser *> ircUsers() const;
77   
78   IrcChannel *newIrcChannel(const QString &channelname);
79   IrcChannel *ircChannel(const QString &channelname);
80   QList<IrcChannel *> ircChannels() const;
81
82 public slots:
83   void setNetworkName(const QString &networkName);
84   void setCurrentServer(const QString &currentServer);
85   void setMyNick(const QString &mynick);
86
87   void addSupport(const QString &param, const QString &value = QString());
88   void removeSupport(const QString &param);
89
90   inline void addIrcUser(const QString &hostmask) { newIrcUser(hostmask); }
91   
92   //init geters
93   QVariantMap initSupports() const;
94   QStringList initIrcUsers() const;
95   QStringList initIrcChannels() const;
96   
97   //init seters
98   void initSetSupports(const QVariantMap &supports);
99   void initSetIrcUsers(const QStringList &hostmasks);
100   void initSetChannels(const QStringList &channels);
101   
102   IrcUser *updateNickFromMask(const QString &mask);
103
104   // these slots are to keep the hashlists of all users and the
105   // channel lists up to date
106   void ircUserNickChanged(QString newnick);
107
108   void ircUserDestroyed();
109   void channelDestroyed();
110
111   void setInitialized();
112   
113 signals:
114   void networkNameSet(const QString &networkName);
115   void currentServerSet(const QString &currentServer);
116   void myNickSet(const QString &mynick);
117
118   void supportAdded(const QString &param, const QString &value = QString());
119   void supportRemoved(const QString &param);
120   
121   void ircUserAdded(QString hostmask);
122   void ircChannelAdded(QString channelname);
123
124   void initDone();
125   void ircUserInitDone();
126   void ircChannelInitDone();
127   
128 private:
129   uint _networkId;
130   bool _initialized;
131   
132   QString _myNick;
133   QString _networkName;
134   QString _currentServer;
135
136   QString _prefixes;
137   QString _prefixModes;
138
139   QHash<QString, IrcUser *> _ircUsers;  // stores all known nicks for the server
140   QHash<QString, IrcChannel *> _ircChannels; // stores all known channels
141   QHash<QString, QString> _supports;  // stores results from RPL_ISUPPORT
142
143   //QVariantMap networkSettings;
144   //QVariantMap identity;
145   
146   QPointer<Synchronizer> _synchronizer;
147   
148   void determinePrefixes();
149 };
150
151 #endif