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