Encodings are now honored for both sending and receiving. Cleaned up encode/decode
[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     setCurrentServer(QString());
462   }
463   emit connectedSet(connected);
464 }
465
466 //void Network::setConnectionState(ConnectionState state) {
467 void Network::setConnectionState(int state) {
468   _connectionState = (ConnectionState)state;
469   //qDebug() << "netstate" << networkId() << networkName() << state;
470   emit connectionStateSet(state);
471   emit connectionStateSet(_connectionState);
472 }
473
474 void Network::setMyNick(const QString &nickname) {
475   _myNick = nickname;
476   emit myNickSet(nickname);
477 }
478
479 void Network::setIdentity(IdentityId id) {
480   _identity = id;
481   emit identitySet(id);
482 }
483
484 void Network::setServerList(const QVariantList &serverList) {
485   _serverList = serverList;
486   emit serverListSet(serverList);
487 }
488
489 void Network::setUseRandomServer(bool use) {
490   _useRandomServer = use;
491   emit useRandomServerSet(use);
492 }
493
494 void Network::setPerform(const QStringList &perform) {
495   _perform = perform;
496   emit performSet(perform);
497 }
498
499 void Network::setUseAutoIdentify(bool use) {
500   _useAutoIdentify = use;
501   emit useAutoIdentifySet(use);
502 }
503
504 void Network::setAutoIdentifyService(const QString &service) {
505   _autoIdentifyService = service;
506   emit autoIdentifyServiceSet(service);
507 }
508
509 void Network::setAutoIdentifyPassword(const QString &password) {
510   _autoIdentifyPassword = password;
511   emit autoIdentifyPasswordSet(password);
512 }
513
514 void Network::setUseAutoReconnect(bool use) {
515   _useAutoReconnect = use;
516   emit useAutoReconnectSet(use);
517 }
518
519 void Network::setAutoReconnectInterval(quint32 interval) {
520   _autoReconnectInterval = interval;
521   emit autoReconnectIntervalSet(interval);
522 }
523
524 void Network::setAutoReconnectRetries(qint16 retries) {
525   _autoReconnectRetries = retries;
526   emit autoReconnectRetriesSet(retries);
527 }
528
529 void Network::setRejoinChannels(bool rejoin) {
530   _rejoinChannels = rejoin;
531   emit rejoinChannelsSet(rejoin);
532 }
533
534 void Network::addSupport(const QString &param, const QString &value) {
535   if(!_supports.contains(param)) {
536     _supports[param] = value;
537     emit supportAdded(param, value);
538   }
539 }
540
541 void Network::removeSupport(const QString &param) {
542   if(_supports.contains(param)) {
543     _supports.remove(param);
544     emit supportRemoved(param);
545   }
546 }
547
548 QVariantMap Network::initSupports() const {
549   QVariantMap supports;
550   QHashIterator<QString, QString> iter(_supports);
551   while(iter.hasNext()) {
552     iter.next();
553     supports[iter.key()] = iter.value();
554   }
555   return supports;
556 }
557
558 QVariantList Network::initServerList() const {
559   return serverList();
560 }
561
562 QStringList Network::initIrcUsers() const {
563   QStringList hostmasks;
564   foreach(IrcUser *ircuser, ircUsers()) {
565     hostmasks << ircuser->hostmask();
566   }
567   return hostmasks;
568 }
569
570 QStringList Network::initIrcChannels() const {
571   return _ircChannels.keys();
572 }
573
574 void Network::initSetSupports(const QVariantMap &supports) {
575   QMapIterator<QString, QVariant> iter(supports);
576   while(iter.hasNext()) {
577     iter.next();
578     addSupport(iter.key(), iter.value().toString());
579   }
580 }
581
582 void Network::initSetServerList(const QVariantList & serverList) {
583   setServerList(serverList);
584 }
585
586 void Network::initSetIrcUsers(const QStringList &hostmasks) {
587   if(!_ircUsers.empty())
588     return;
589   foreach(QString hostmask, hostmasks) {
590     newIrcUser(hostmask);
591   }
592 }
593
594 void Network::initSetChannels(const QStringList &channels) {
595   if(!_ircChannels.empty())
596     return;
597   foreach(QString channel, channels)
598     newIrcChannel(channel);
599 }
600
601 IrcUser *Network::updateNickFromMask(const QString &mask) {
602   QString nick(nickFromMask(mask).toLower());
603   IrcUser *ircuser;
604   
605   if(_ircUsers.contains(nick)) {
606     ircuser = _ircUsers[nick];
607     ircuser->updateHostmask(mask);
608   } else {
609     ircuser = newIrcUser(mask);
610   }
611   return ircuser;
612 }
613
614 void Network::ircUserNickChanged(QString newnick) {
615   QString oldnick = _ircUsers.key(qobject_cast<IrcUser*>(sender()));
616
617   if(oldnick.isNull())
618     return;
619
620   if(newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
621
622   if(myNick().toLower() == oldnick)
623     setMyNick(newnick);
624 }
625
626 void Network::ircUserInitDone() {
627   IrcUser *ircuser = static_cast<IrcUser *>(sender());
628   Q_ASSERT(ircuser);
629   emit ircUserInitDone(ircuser);
630 }
631
632 void Network::ircChannelInitDone() {
633   IrcChannel *ircchannel = static_cast<IrcChannel *>(sender());
634   Q_ASSERT(ircchannel);
635   emit ircChannelInitDone(ircchannel);
636 }
637
638 void Network::removeIrcChannel(IrcChannel *channel) {
639   QString chanName = _ircChannels.key(channel);
640   if(chanName.isNull())
641     return;
642   
643   _ircChannels.remove(chanName);
644   disconnect(channel, 0, this, 0);
645   emit ircChannelRemoved(chanName);
646   emit ircChannelRemoved(channel);
647   channel->deleteLater();
648 }
649
650 void Network::removeIrcChannel(const QString &channel) {
651   IrcChannel *chan;
652   if((chan = ircChannel(channel)) != 0)
653     removeIrcChannel(chan);
654 }
655
656 void Network::channelDestroyed() {
657   IrcChannel *channel = static_cast<IrcChannel *>(sender());
658   Q_ASSERT(channel);
659   _ircChannels.remove(_ircChannels.key(channel));
660   emit ircChannelRemoved(channel);
661 }
662
663 void Network::requestConnect() const {
664   if(!proxy()) return;
665   if(proxy()->proxyMode() == SignalProxy::Client) emit connectRequested(); // on the client this triggers calling this slot on the core
666   else {
667     if(connectionState() != Disconnected) {
668       qWarning() << "Requesting connect while not being disconnected!";
669       return;
670     }
671     emit connectRequested(networkId());  // and this is for CoreSession :)
672   }
673 }
674
675 void Network::requestDisconnect() const {
676   if(!proxy()) return;
677   if(proxy()->proxyMode() == SignalProxy::Client) emit disconnectRequested(); // on the client this triggers calling this slot on the core
678   else {
679     if(connectionState() == Disconnected) {
680       qWarning() << "Requesting disconnect while not being connected!";
681       return;
682     }
683     emit disconnectRequested(networkId());  // and this is for CoreSession :)
684   }
685 }
686
687 void Network::emitConnectionError(const QString &errorMsg) {
688   emit connectionError(errorMsg);
689 }
690
691 // ====================
692 //  Private:
693 // ====================
694 void Network::determinePrefixes() {
695   // seems like we have to construct them first
696   QString PREFIX = support("PREFIX");
697   
698   if(PREFIX.startsWith("(") && PREFIX.contains(")")) {
699     _prefixes = PREFIX.section(")", 1);
700     _prefixModes = PREFIX.mid(1).section(")", 0, 0);
701   } else {
702     QString defaultPrefixes("~&@%+");
703     QString defaultPrefixModes("qaohv");
704
705     // we just assume that in PREFIX are only prefix chars stored
706     for(int i = 0; i < defaultPrefixes.size(); i++) {
707       if(PREFIX.contains(defaultPrefixes[i])) {
708         _prefixes += defaultPrefixes[i];
709         _prefixModes += defaultPrefixModes[i];
710       }
711     }
712     // check for success
713     if(!_prefixes.isNull())
714       return;
715     
716     // well... our assumption was obviously wrong...
717     // check if it's only prefix modes
718     for(int i = 0; i < defaultPrefixes.size(); i++) {
719       if(PREFIX.contains(defaultPrefixModes[i])) {
720         _prefixes += defaultPrefixes[i];
721         _prefixModes += defaultPrefixModes[i];
722       }
723     }
724     // now we've done all we've could...
725   }
726 }
727
728 /************************************************************************
729  * NetworkInfo
730  ************************************************************************/
731
732 bool NetworkInfo::operator==(const NetworkInfo &other) const {
733   if(networkId != other.networkId) return false;
734   if(networkName != other.networkName) return false;
735   if(identity != other.identity) return false;
736   if(codecForEncoding != other.codecForEncoding) return false;
737   if(codecForDecoding != other.codecForDecoding) return false;
738   if(serverList != other.serverList) return false;
739   if(useRandomServer != other.useRandomServer) return false;
740   if(perform != other.perform) return false;
741   if(useAutoIdentify != other.useAutoIdentify) return false;
742   if(autoIdentifyService != other.autoIdentifyService) return false;
743   if(autoIdentifyPassword != other.autoIdentifyPassword) return false;
744   if(useAutoReconnect != other.useAutoReconnect) return false;
745   if(autoReconnectInterval != other.autoReconnectInterval) return false;
746   if(autoReconnectRetries != other.autoReconnectRetries) return false;
747   if(rejoinChannels != other.rejoinChannels) return false;
748   return true;
749 }
750
751 bool NetworkInfo::operator!=(const NetworkInfo &other) const {
752   return !(*this == other);
753 }
754
755 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info) {
756   QVariantMap i;
757   i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
758   i["NetworkName"] = info.networkName;
759   i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
760   i["CodecForEncoding"] = info.codecForEncoding;
761   i["CodecForDecoding"] = info.codecForDecoding;
762   i["ServerList"] = info.serverList;
763   i["UseRandomServer"] = info.useRandomServer;
764   i["Perform"] = info.perform;
765   i["UseAutoIdentify"] = info.useAutoIdentify;
766   i["AutoIdentifyService"] = info.autoIdentifyService;
767   i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
768   i["UseAutoReconnect"] = info.useAutoReconnect;
769   i["AutoReconnectInterval"] = info.autoReconnectInterval;
770   i["AutoReconnectRetries"] = info.autoReconnectRetries;
771   i["RejoinChannels"] = info.rejoinChannels;
772   out << i;
773   return out;
774 }
775
776 QDataStream &operator>>(QDataStream &in, NetworkInfo &info) {
777   QVariantMap i;
778   in >> i;
779   info.networkId = i["NetworkId"].value<NetworkId>();
780   info.networkName = i["NetworkName"].toString();
781   info.identity = i["Identity"].value<IdentityId>();
782   info.codecForEncoding = i["CodecForEncoding"].toByteArray();
783   info.codecForDecoding = i["CodecForDecoding"].toByteArray();
784   info.serverList = i["ServerList"].toList();
785   info.useRandomServer = i["UseRandomServer"].toBool();
786   info.perform = i["Perform"].toStringList();
787   info.useAutoIdentify = i["UseAutoIdentify"].toBool();
788   info.autoIdentifyService = i["AutoIdentifyService"].toString();
789   info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
790   info.useAutoReconnect = i["UseAutoReconnect"].toBool();
791   info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
792   info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
793   info.rejoinChannels = i["RejoinChannels"].toBool();
794   return in;
795 }
796
797
798
799
800
801
802
803
804
805