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