c62d44638f237d9f2be806e15109aef4754852bb
[quassel.git] / src / common / network.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
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 #include "network.h"
21
22 #include "signalproxy.h"
23 #include "ircuser.h"
24 #include "ircchannel.h"
25
26 #include <QDebug>
27 #include <QTextCodec>
28
29 #include "util.h"
30
31 QTextCodec *Network::_defaultCodecForEncoding = 0;
32 QTextCodec *Network::_defaultCodecForDecoding = 0;
33
34 // ====================
35 //  Public:
36 // ====================
37 Network::Network(const NetworkId &networkid, QObject *parent) : SyncableObject(parent),
38     _networkId(networkid),
39     _identity(0),
40     _myNick(QString()),
41     _networkName(QString("<not initialized>")),
42     _currentServer(QString()),
43     _connected(false),
44     _connectionState(Disconnected),
45     _prefixes(QString()),
46     _prefixModes(QString()),
47     _proxy(0),
48     _codecForEncoding(0),
49     _codecForDecoding(0)
50 {
51   setObjectName(QString::number(networkid.toInt()));
52 }
53
54 // I think this is unnecessary since IrcUsers have us as their daddy :)
55
56 Network::~Network() {
57   emit aboutToBeDestroyed();
58 //  QHashIterator<QString, IrcUser *> ircuser(_ircUsers);
59 //  while (ircuser.hasNext()) {
60 //    ircuser.next();
61 //    delete ircuser.value();
62 //  }
63 //  qDebug() << "Destroying net" << networkName() << networkId();
64 }
65
66
67 NetworkId Network::networkId() const {
68   return _networkId;
69 }
70
71 SignalProxy *Network::proxy() const {
72   return _proxy;
73 }
74
75 void Network::setProxy(SignalProxy *proxy) {
76   _proxy = proxy;
77   //proxy->synchronize(this);  // we should to this explicitly from the outside!
78 }
79
80 bool Network::isMyNick(const QString &nick) const {
81   return (myNick().toLower() == nick.toLower());
82 }
83
84 bool Network::isMe(IrcUser *ircuser) const {
85   return (ircuser->nick().toLower() == myNick().toLower());
86 }
87
88 bool Network::isChannelName(const QString &channelname) const {
89   if(channelname.isEmpty())
90     return false;
91   
92   if(supports("CHANTYPES"))
93     return support("CHANTYPES").contains(channelname[0]);
94   else
95     return QString("#&!+").contains(channelname[0]);
96 }
97
98 bool Network::isConnected() const {
99   return _connected;
100 }
101
102 //Network::ConnectionState Network::connectionState() const {
103 int Network::connectionState() const {
104   return _connectionState;
105 }
106
107 NetworkInfo Network::networkInfo() const {
108   NetworkInfo info;
109   info.networkName = networkName();
110   info.networkId = networkId();
111   info.identity = identity();
112   info.codecForEncoding = codecForEncoding();
113   info.codecForDecoding = codecForDecoding();
114   info.serverList = serverList();
115   info.useRandomServer = useRandomServer();
116   info.perform = perform();
117   info.useAutoIdentify = useAutoIdentify();
118   info.autoIdentifyService = autoIdentifyService();
119   info.autoIdentifyPassword = autoIdentifyPassword();
120   info.useAutoReconnect = useAutoReconnect();
121   info.autoReconnectInterval = autoReconnectInterval();
122   info.autoReconnectRetries = autoReconnectRetries();
123   info.rejoinChannels = rejoinChannels();
124   return info;
125 }
126
127 void Network::setNetworkInfo(const NetworkInfo &info) {
128   // we don't set our ID!
129   if(!info.networkName.isEmpty() && info.networkName != networkName()) setNetworkName(info.networkName);
130   if(info.identity > 0 && info.identity != identity()) setIdentity(info.identity);
131   if(info.codecForEncoding != codecForEncoding()) setCodecForEncoding(QTextCodec::codecForName(info.codecForEncoding));
132   if(info.codecForDecoding != codecForDecoding()) setCodecForDecoding(QTextCodec::codecForName(info.codecForDecoding));
133   if(info.serverList.count()) setServerList(info.serverList); // FIXME compare components
134   if(info.useRandomServer != useRandomServer()) setUseRandomServer(info.useRandomServer);
135   if(info.perform != perform()) setPerform(info.perform);
136   if(info.useAutoIdentify != useAutoIdentify()) setUseAutoIdentify(info.useAutoIdentify);
137   if(info.autoIdentifyService != autoIdentifyService()) setAutoIdentifyService(info.autoIdentifyService);
138   if(info.autoIdentifyPassword != autoIdentifyPassword()) setAutoIdentifyPassword(info.autoIdentifyPassword);
139   if(info.useAutoReconnect != useAutoReconnect()) setUseAutoReconnect(info.useAutoReconnect);
140   if(info.autoReconnectInterval != autoReconnectInterval()) setAutoReconnectInterval(info.autoReconnectInterval);
141   if(info.autoReconnectRetries != autoReconnectRetries()) setAutoReconnectRetries(info.autoReconnectRetries);
142   if(info.rejoinChannels != rejoinChannels()) setRejoinChannels(info.rejoinChannels);
143 }
144
145 QString Network::prefixToMode(const QString &prefix) {
146   if(prefixes().contains(prefix))
147     return QString(prefixModes()[prefixes().indexOf(prefix)]);
148   else
149     return QString();
150 }
151
152 QString Network::prefixToMode(const QCharRef &prefix) {
153   return prefixToMode(QString(prefix));
154 }
155
156 QString Network::modeToPrefix(const QString &mode) {
157   if(prefixModes().contains(mode))
158     return QString(prefixes()[prefixModes().indexOf(mode)]);
159   else
160     return QString();
161 }
162
163 QString Network::modeToPrefix(const QCharRef &mode) {
164   return modeToPrefix(QString(mode));
165 }
166   
167 QString Network::networkName() const {
168   return _networkName;
169 }
170
171 QString Network::currentServer() const {
172   return _currentServer;
173 }
174
175 QString Network::myNick() const {
176   return _myNick;
177 }
178
179 IdentityId Network::identity() const {
180   return _identity;
181 }
182
183 QStringList Network::nicks() const {
184   // we don't use _ircUsers.keys() since the keys may be
185   // not up to date after a nick change
186   QStringList nicks;
187   foreach(IrcUser *ircuser, _ircUsers.values()) {
188     nicks << ircuser->nick();
189   }
190   return nicks;
191 }
192
193 QStringList Network::channels() const {
194   return _ircChannels.keys();
195 }
196
197 QVariantList Network::serverList() const {
198   return _serverList;
199 }
200
201 bool Network::useRandomServer() const {
202   return _useRandomServer;
203 }
204
205 QStringList Network::perform() const {
206   return _perform;
207 }
208
209 bool Network::useAutoIdentify() const {
210   return _useAutoIdentify;
211 }
212
213 QString Network::autoIdentifyService() const {
214   return _autoIdentifyService;
215 }
216
217 QString Network::autoIdentifyPassword() const {
218   return _autoIdentifyPassword;
219 }
220
221 bool Network::useAutoReconnect() const {
222   return _useAutoReconnect;
223 }
224
225 quint32 Network::autoReconnectInterval() const {
226   return _autoReconnectInterval;
227 }
228
229 qint16 Network::autoReconnectRetries() const {
230   return _autoReconnectRetries;
231 }
232
233 bool Network::rejoinChannels() const {
234   return _rejoinChannels;
235 }
236
237 QString Network::prefixes() {
238   if(_prefixes.isNull())
239     determinePrefixes();
240   
241   return _prefixes;
242 }
243
244 QString Network::prefixModes() {
245   if(_prefixModes.isNull())
246     determinePrefixes();
247
248   return _prefixModes;
249 }
250
251 bool Network::supports(const QString &param) const {
252   return _supports.contains(param);
253 }
254
255 QString Network::support(const QString &param) const {
256   QString support_ = param.toUpper();
257   if(_supports.contains(support_))
258     return _supports[support_];
259   else
260     return QString();
261 }
262
263 IrcUser *Network::newIrcUser(const QString &hostmask) {
264   QString nick(nickFromMask(hostmask).toLower());
265   if(!_ircUsers.contains(nick)) {
266     IrcUser *ircuser = new IrcUser(hostmask, this);
267     // mark IrcUser as already initialized to keep the SignalProxy from requesting initData
268     //if(isInitialized())
269     //  ircuser->setInitialized();
270     if(proxy())
271       proxy()->synchronize(ircuser);
272     else
273       qWarning() << "unable to synchronize new IrcUser" << hostmask << "forgot to call Network::setProxy(SignalProxy *)?";
274     
275     connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
276     connect(ircuser, SIGNAL(initDone()), this, SLOT(ircUserInitDone()));
277     _ircUsers[nick] = ircuser;
278     emit ircUserAdded(hostmask);
279     emit ircUserAdded(ircuser);
280   }
281   return _ircUsers[nick];
282 }
283
284 IrcUser *Network::newIrcUser(const QByteArray &hostmask) {
285   return newIrcUser(decodeString(hostmask));
286 }
287
288 void Network::removeIrcUser(IrcUser *ircuser) {
289   QString nick = _ircUsers.key(ircuser);
290   if(nick.isNull())
291     return;
292
293   _ircUsers.remove(nick);
294   disconnect(ircuser, 0, this, 0);
295   emit ircUserRemoved(nick);
296   emit ircUserRemoved(ircuser);
297   ircuser->deleteLater();
298 }
299
300 void Network::removeChansAndUsers() {
301   QList<IrcUser *> users = ircUsers();
302   foreach(IrcUser *user, users) {
303     removeIrcUser(user);
304   }
305   QList<IrcChannel *> channels = ircChannels();
306   foreach(IrcChannel *channel, channels) {
307     removeIrcChannel(channel);
308   }
309 }
310
311 void Network::removeIrcUser(const QString &nick) {
312   IrcUser *ircuser;
313   if((ircuser = ircUser(nick)) != 0)
314     removeIrcUser(ircuser);
315 }
316
317 IrcUser *Network::ircUser(QString nickname) const {
318   nickname = nickname.toLower();
319   if(_ircUsers.contains(nickname))
320     return _ircUsers[nickname];
321   else
322     return 0;
323 }
324
325 IrcUser *Network::ircUser(const QByteArray &nickname) const {
326   return ircUser(decodeString(nickname));
327 }
328
329 QList<IrcUser *> Network::ircUsers() const {
330   return _ircUsers.values();
331 }
332
333 quint32 Network::ircUserCount() const {
334   return _ircUsers.count();
335 }
336
337 IrcChannel *Network::newIrcChannel(const QString &channelname) {
338   if(!_ircChannels.contains(channelname.toLower())) {
339     IrcChannel *channel = new IrcChannel(channelname, this);
340     // mark IrcUser as already initialized to keep the SignalProxy from requesting initData
341     //if(isInitialized())
342     //  channel->setInitialized();
343
344     if(proxy())
345       proxy()->synchronize(channel);
346     else
347       qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?";
348
349     connect(channel, SIGNAL(initDone()), this, SLOT(ircChannelInitDone()));
350     connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed()));
351     _ircChannels[channelname.toLower()] = channel;
352     emit ircChannelAdded(channelname);
353     emit ircChannelAdded(channel);
354   }
355   return _ircChannels[channelname.toLower()];
356 }
357
358 IrcChannel *Network::newIrcChannel(const QByteArray &channelname) {
359   return newIrcChannel(decodeString(channelname));
360 }
361
362 IrcChannel *Network::ircChannel(QString channelname) const {
363   channelname = channelname.toLower();
364   if(_ircChannels.contains(channelname))
365     return _ircChannels[channelname];
366   else
367     return 0;
368 }
369
370 IrcChannel *Network::ircChannel(const QByteArray &channelname) const {
371   return ircChannel(decodeString(channelname));
372 }
373
374
375 QList<IrcChannel *> Network::ircChannels() const {
376   return _ircChannels.values();
377 }
378
379 quint32 Network::ircChannelCount() const {
380   return _ircChannels.count();
381 }
382
383 QByteArray Network::defaultCodecForEncoding() {
384   if(_defaultCodecForEncoding) return _defaultCodecForEncoding->name();
385   return QByteArray();
386 }
387
388 void Network::setDefaultCodecForEncoding(const QByteArray &name) {
389   _defaultCodecForEncoding = QTextCodec::codecForName(name);
390 }
391
392 QByteArray Network::defaultCodecForDecoding() {
393   if(_defaultCodecForDecoding) return _defaultCodecForDecoding->name();
394   return QByteArray();
395 }
396
397 void Network::setDefaultCodecForDecoding(const QByteArray &name) {
398   _defaultCodecForDecoding = QTextCodec::codecForName(name);
399 }
400
401 QByteArray Network::codecForEncoding() const {
402   if(_codecForEncoding) return _codecForEncoding->name();
403   return QByteArray();
404 }
405
406 void Network::setCodecForEncoding(const QByteArray &name) {
407   setCodecForEncoding(QTextCodec::codecForName(name));
408 }
409
410 void Network::setCodecForEncoding(QTextCodec *codec) {
411   _codecForEncoding = codec;
412   emit codecForEncodingSet(codecForEncoding());
413 }
414
415 QByteArray Network::codecForDecoding() const {
416   if(_codecForDecoding) return _codecForDecoding->name();
417   else return QByteArray();
418 }
419
420 void Network::setCodecForDecoding(const QByteArray &name) {
421   setCodecForDecoding(QTextCodec::codecForName(name));
422 }
423
424 void Network::setCodecForDecoding(QTextCodec *codec) {
425   _codecForDecoding = codec;
426   emit codecForDecodingSet(codecForDecoding());
427 }
428
429 QString Network::decodeString(const QByteArray &text) const {
430   if(_codecForDecoding) return ::decodeString(text, _codecForDecoding);
431   else return ::decodeString(text, _defaultCodecForDecoding);
432 }
433
434 QByteArray Network::encodeString(const QString string) const {
435   if(_codecForEncoding) {
436     return _codecForEncoding->fromUnicode(string);
437   }
438   if(_defaultCodecForEncoding) {
439     return _defaultCodecForEncoding->fromUnicode(string);
440   }
441   return string.toAscii();
442 }
443
444 // ====================
445 //  Public Slots:
446 // ====================
447 void Network::setNetworkName(const QString &networkName) {
448   _networkName = networkName;
449   emit networkNameSet(networkName);
450 }
451
452 void Network::setCurrentServer(const QString &currentServer) {
453   _currentServer = currentServer;
454   emit currentServerSet(currentServer);
455 }
456
457 void Network::setConnected(bool connected) {
458   _connected = connected;
459   if(!connected)
460     removeChansAndUsers();
461   emit connectedSet(connected);
462 }
463
464 //void Network::setConnectionState(ConnectionState state) {
465 void Network::setConnectionState(int state) {
466   _connectionState = (ConnectionState)state;
467   //qDebug() << "netstate" << networkId() << networkName() << state;
468   emit connectionStateSet(state);
469   emit connectionStateSet(_connectionState);
470 }
471
472 void Network::setMyNick(const QString &nickname) {
473   _myNick = nickname;
474   emit myNickSet(nickname);
475 }
476
477 void Network::setIdentity(IdentityId id) {
478   _identity = id;
479   emit identitySet(id);
480 }
481
482 void Network::setServerList(const QVariantList &serverList) {
483   _serverList = serverList;
484   emit serverListSet(serverList);
485 }
486
487 void Network::setUseRandomServer(bool use) {
488   _useRandomServer = use;
489   emit useRandomServerSet(use);
490 }
491
492 void Network::setPerform(const QStringList &perform) {
493   _perform = perform;
494   emit performSet(perform);
495 }
496
497 void Network::setUseAutoIdentify(bool use) {
498   _useAutoIdentify = use;
499   emit useAutoIdentifySet(use);
500 }
501
502 void Network::setAutoIdentifyService(const QString &service) {
503   _autoIdentifyService = service;
504   emit autoIdentifyServiceSet(service);
505 }
506
507 void Network::setAutoIdentifyPassword(const QString &password) {
508   _autoIdentifyPassword = password;
509   emit autoIdentifyPasswordSet(password);
510 }
511
512 void Network::setUseAutoReconnect(bool use) {
513   _useAutoReconnect = use;
514   emit useAutoReconnectSet(use);
515 }
516
517 void Network::setAutoReconnectInterval(quint32 interval) {
518   _autoReconnectInterval = interval;
519   emit autoReconnectIntervalSet(interval);
520 }
521
522 void Network::setAutoReconnectRetries(qint16 retries) {
523   _autoReconnectRetries = retries;
524   emit autoReconnectRetriesSet(retries);
525 }
526
527 void Network::setRejoinChannels(bool rejoin) {
528   _rejoinChannels = rejoin;
529   emit rejoinChannelsSet(rejoin);
530 }
531
532 void Network::addSupport(const QString &param, const QString &value) {
533   if(!_supports.contains(param)) {
534     _supports[param] = value;
535     emit supportAdded(param, value);
536   }
537 }
538
539 void Network::removeSupport(const QString &param) {
540   if(_supports.contains(param)) {
541     _supports.remove(param);
542     emit supportRemoved(param);
543   }
544 }
545
546 QVariantMap Network::initSupports() const {
547   QVariantMap supports;
548   QHashIterator<QString, QString> iter(_supports);
549   while(iter.hasNext()) {
550     iter.next();
551     supports[iter.key()] = iter.value();
552   }
553   return supports;
554 }
555
556 QVariantList Network::initServerList() const {
557   return serverList();
558 }
559
560 QStringList Network::initIrcUsers() const {
561   QStringList hostmasks;
562   foreach(IrcUser *ircuser, ircUsers()) {
563     hostmasks << ircuser->hostmask();
564   }
565   return hostmasks;
566 }
567
568 QStringList Network::initIrcChannels() const {
569   return _ircChannels.keys();
570 }
571
572 void Network::initSetSupports(const QVariantMap &supports) {
573   QMapIterator<QString, QVariant> iter(supports);
574   while(iter.hasNext()) {
575     iter.next();
576     addSupport(iter.key(), iter.value().toString());
577   }
578 }
579
580 void Network::initSetServerList(const QVariantList & serverList) {
581   setServerList(serverList);
582 }
583
584 void Network::initSetIrcUsers(const QStringList &hostmasks) {
585   if(!_ircUsers.empty())
586     return;
587   foreach(QString hostmask, hostmasks) {
588     newIrcUser(hostmask);
589   }
590 }
591
592 void Network::initSetChannels(const QStringList &channels) {
593   if(!_ircChannels.empty())
594     return;
595   foreach(QString channel, channels)
596     newIrcChannel(channel);
597 }
598
599 IrcUser *Network::updateNickFromMask(const QString &mask) {
600   QString nick(nickFromMask(mask).toLower());
601   IrcUser *ircuser;
602   
603   if(_ircUsers.contains(nick)) {
604     ircuser = _ircUsers[nick];
605     ircuser->updateHostmask(mask);
606   } else {
607     ircuser = newIrcUser(mask);
608   }
609   return ircuser;
610 }
611
612 void Network::ircUserNickChanged(QString newnick) {
613   QString oldnick = _ircUsers.key(qobject_cast<IrcUser*>(sender()));
614
615   if(oldnick.isNull())
616     return;
617
618   if(newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
619
620   if(myNick().toLower() == oldnick)
621     setMyNick(newnick);
622 }
623
624 void Network::ircUserInitDone() {
625   IrcUser *ircuser = static_cast<IrcUser *>(sender());
626   Q_ASSERT(ircuser);
627   emit ircUserInitDone(ircuser);
628 }
629
630 void Network::ircChannelInitDone() {
631   IrcChannel *ircchannel = static_cast<IrcChannel *>(sender());
632   Q_ASSERT(ircchannel);
633   emit ircChannelInitDone(ircchannel);
634 }
635
636 void Network::removeIrcChannel(IrcChannel *channel) {
637   QString chanName = _ircChannels.key(channel);
638   if(chanName.isNull())
639     return;
640   
641   _ircChannels.remove(chanName);
642   disconnect(channel, 0, this, 0);
643   emit ircChannelRemoved(chanName);
644   emit ircChannelRemoved(channel);
645   channel->deleteLater();
646 }
647
648 void Network::removeIrcChannel(const QString &channel) {
649   IrcChannel *chan;
650   if((chan = ircChannel(channel)) != 0)
651     removeIrcChannel(chan);
652 }
653
654 void Network::channelDestroyed() {
655   IrcChannel *channel = static_cast<IrcChannel *>(sender());
656   Q_ASSERT(channel);
657   _ircChannels.remove(_ircChannels.key(channel));
658   emit ircChannelRemoved(channel);
659 }
660
661 void Network::requestConnect() const {
662   if(!proxy()) return;
663   if(proxy()->proxyMode() == SignalProxy::Client) emit connectRequested(); // on the client this triggers calling this slot on the core
664   else {
665     if(connectionState() != Disconnected) {
666       qWarning() << "Requesting connect while not being disconnected!";
667       return;
668     }
669     emit connectRequested(networkId());  // and this is for CoreSession :)
670   }
671 }
672
673 void Network::requestDisconnect() const {
674   if(!proxy()) return;
675   if(proxy()->proxyMode() == SignalProxy::Client) emit disconnectRequested(); // on the client this triggers calling this slot on the core
676   else {
677     if(connectionState() == Disconnected) {
678       qWarning() << "Requesting disconnect while not being connected!";
679       return;
680     }
681     emit disconnectRequested(networkId());  // and this is for CoreSession :)
682   }
683 }
684
685 void Network::emitConnectionError(const QString &errorMsg) {
686   emit connectionError(errorMsg);
687 }
688
689 // ====================
690 //  Private:
691 // ====================
692 void Network::determinePrefixes() {
693   // seems like we have to construct them first
694   QString PREFIX = support("PREFIX");
695   
696   if(PREFIX.startsWith("(") && PREFIX.contains(")")) {
697     _prefixes = PREFIX.section(")", 1);
698     _prefixModes = PREFIX.mid(1).section(")", 0, 0);
699   } else {
700     QString defaultPrefixes("~&@%+");
701     QString defaultPrefixModes("qaohv");
702
703     // we just assume that in PREFIX are only prefix chars stored
704     for(int i = 0; i < defaultPrefixes.size(); i++) {
705       if(PREFIX.contains(defaultPrefixes[i])) {
706         _prefixes += defaultPrefixes[i];
707         _prefixModes += defaultPrefixModes[i];
708       }
709     }
710     // check for success
711     if(!_prefixes.isNull())
712       return;
713     
714     // well... our assumption was obviously wrong...
715     // check if it's only prefix modes
716     for(int i = 0; i < defaultPrefixes.size(); i++) {
717       if(PREFIX.contains(defaultPrefixModes[i])) {
718         _prefixes += defaultPrefixes[i];
719         _prefixModes += defaultPrefixModes[i];
720       }
721     }
722     // now we've done all we've could...
723   }
724 }
725
726 /************************************************************************
727  * NetworkInfo
728  ************************************************************************/
729
730 bool NetworkInfo::operator==(const NetworkInfo &other) const {
731   if(networkId != other.networkId) return false;
732   if(networkName != other.networkName) return false;
733   if(identity != other.identity) return false;
734   if(codecForEncoding != other.codecForEncoding) return false;
735   if(codecForDecoding != other.codecForDecoding) return false;
736   if(serverList != other.serverList) return false;
737   if(useRandomServer != other.useRandomServer) return false;
738   if(perform != other.perform) return false;
739   if(useAutoIdentify != other.useAutoIdentify) return false;
740   if(autoIdentifyService != other.autoIdentifyService) return false;
741   if(autoIdentifyPassword != other.autoIdentifyPassword) return false;
742   if(useAutoReconnect != other.useAutoReconnect) return false;
743   if(autoReconnectInterval != other.autoReconnectInterval) return false;
744   if(autoReconnectRetries != other.autoReconnectRetries) return false;
745   if(rejoinChannels != other.rejoinChannels) return false;
746   return true;
747 }
748
749 bool NetworkInfo::operator!=(const NetworkInfo &other) const {
750   return !(*this == other);
751 }
752
753 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info) {
754   QVariantMap i;
755   i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
756   i["NetworkName"] = info.networkName;
757   i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
758   i["CodecForEncoding"] = info.codecForEncoding;
759   i["CodecForDecoding"] = info.codecForDecoding;
760   i["ServerList"] = info.serverList;
761   i["UseRandomServer"] = info.useRandomServer;
762   i["Perform"] = info.perform;
763   i["UseAutoIdentify"] = info.useAutoIdentify;
764   i["AutoIdentifyService"] = info.autoIdentifyService;
765   i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
766   i["UseAutoReconnect"] = info.useAutoReconnect;
767   i["AutoReconnectInterval"] = info.autoReconnectInterval;
768   i["AutoReconnectRetries"] = info.autoReconnectRetries;
769   i["RejoinChannels"] = info.rejoinChannels;
770   out << i;
771   return out;
772 }
773
774 QDataStream &operator>>(QDataStream &in, NetworkInfo &info) {
775   QVariantMap i;
776   in >> i;
777   info.networkId = i["NetworkId"].value<NetworkId>();
778   info.networkName = i["NetworkName"].toString();
779   info.identity = i["Identity"].value<IdentityId>();
780   info.codecForEncoding = i["CodecForEncoding"].toByteArray();
781   info.codecForDecoding = i["CodecForDecoding"].toByteArray();
782   info.serverList = i["ServerList"].toList();
783   info.useRandomServer = i["UseRandomServer"].toBool();
784   info.perform = i["Perform"].toStringList();
785   info.useAutoIdentify = i["UseAutoIdentify"].toBool();
786   info.autoIdentifyService = i["AutoIdentifyService"].toString();
787   info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
788   info.useAutoReconnect = i["UseAutoReconnect"].toBool();
789   info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
790   info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
791   info.rejoinChannels = i["RejoinChannels"].toBool();
792   return in;
793 }
794
795
796
797
798
799
800
801
802
803