/***************************************************************************
- * Copyright (C) 2005-07 by The Quassel Team *
+ * Copyright (C) 2005-07 by the Quassel IRC Team *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
+ * (at your option) version 3. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#include "networkinfo.h"
#include "signalproxy.h"
-#include "synchronizer.h"
#include "ircuser.h"
#include "ircchannel.h"
// ====================
// Public:
// ====================
-NetworkInfo::NetworkInfo(const uint &networkid, SignalProxy *proxy, QObject *parent)
+NetworkInfo::NetworkInfo(const uint &networkid, QObject *parent)
: QObject(parent),
_networkId(networkid),
_initialized(false),
_networkName(QString()),
_currentServer(QString()),
_prefixes(QString()),
- _prefixModes(QString())
+ _prefixModes(QString()),
+ _proxy(NULL)
{
setObjectName(QString::number(networkid));
- _synchronizer = new Synchronizer(this, proxy);
}
// I think this is unnecessary since IrcUsers have us as their daddy :)
-// NetworkInfo::~NetworkInfo() {
+//NetworkInfo::~NetworkInfo() {
// QHashIterator<QString, IrcUser *> ircuser(_ircUsers);
// while (ircuser.hasNext()) {
// ircuser.next();
// delete ircuser.value();
// }
-// }
+//}
uint NetworkInfo::networkId() const {
return _networkId;
return _initialized;
}
-Synchronizer *NetworkInfo::synchronizer() {
- return _synchronizer;
+SignalProxy *NetworkInfo::proxy() const {
+ return _proxy;
+}
+
+void NetworkInfo::setProxy(SignalProxy *proxy) {
+ _proxy = proxy;
+ proxy->synchronize(this);
}
bool NetworkInfo::isMyNick(const QString &nick) const {
}
IrcUser *NetworkInfo::newIrcUser(const QString &hostmask) {
- QString nick(nickFromMask(hostmask));
+ QString nick(nickFromMask(hostmask).toLower());
if(!_ircUsers.contains(nick)) {
IrcUser *ircuser = new IrcUser(hostmask, this);
- new Synchronizer(ircuser, synchronizer()->proxy());
+ // mark IrcUser as already initialized to keep the SignalProxy from requesting initData
+ if(initialized())
+ ircuser->setInitialized();
+ if(proxy())
+ proxy()->synchronize(ircuser);
+ else
+ qWarning() << "unable to synchronize new IrcUser" << hostmask << "forgot to call NetworkInfo::setProxy(SignalProxy *)?";
+
connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
connect(ircuser, SIGNAL(initDone()), this, SIGNAL(ircUserInitDone()));
connect(ircuser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed()));
_ircUsers[nick] = ircuser;
emit ircUserAdded(hostmask);
}
- return _ircUsers[nick];
+ return _ircUsers[nick];
+}
+
+void NetworkInfo::removeIrcUser(IrcUser *ircuser) {
+ QString nick = _ircUsers.key(ircuser);
+ if(nick.isNull())
+ return;
+
+ _ircUsers.remove(nick);
+ ircuser->deleteLater();
+ emit ircUserRemoved(nick);
}
-IrcUser *NetworkInfo::ircUser(const QString &nickname) const {
+void NetworkInfo::removeIrcUser(QString nick) {
+ IrcUser *ircuser;
+ if((ircuser = ircUser(nick)) != 0)
+ removeIrcUser(ircuser);
+}
+
+IrcUser *NetworkInfo::ircUser(QString nickname) const {
+ nickname = nickname.toLower();
if(_ircUsers.contains(nickname))
return _ircUsers[nickname];
else
}
IrcChannel *NetworkInfo::newIrcChannel(const QString &channelname) {
- if(!_ircChannels.contains(channelname)) {
+ if(!_ircChannels.contains(channelname.toLower())) {
IrcChannel *channel = new IrcChannel(channelname, this);
- new Synchronizer(channel, synchronizer()->proxy());
+ // mark IrcUser as already initialized to keep the SignalProxy from requesting initData
+ if(initialized())
+ channel->setInitialized();
+
+ if(proxy())
+ proxy()->synchronize(channel);
+ else
+ qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call NetworkInfo::setProxy(SignalProxy *)?";
+
connect(channel, SIGNAL(initDone()), this, SIGNAL(ircChannelInitDone()));
connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed()));
- _ircChannels[channelname] = channel;
+ _ircChannels[channelname.toLower()] = channel;
emit ircChannelAdded(channelname);
}
- return _ircChannels[channelname];
+ return _ircChannels[channelname.toLower()];
}
-IrcChannel *NetworkInfo::ircChannel(const QString &channelname) {
+IrcChannel *NetworkInfo::ircChannel(QString channelname) {
+ channelname = channelname.toLower();
if(_ircChannels.contains(channelname))
return _ircChannels[channelname];
else
void NetworkInfo::ircUserNickChanged(QString newnick) {
QString oldnick = _ircUsers.key(qobject_cast<IrcUser*>(sender()));
-
+
if(oldnick.isNull())
return;
- _ircUsers[newnick] = _ircUsers.take(oldnick);
+ _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
if(myNick() == oldnick)
setMyNick(newnick);
}
void NetworkInfo::ircUserDestroyed() {
- IrcUser *ircuser = qobject_cast<IrcUser *>(sender());
- // in case this assert triggers we probably need a static_cast
- // dynamic_casts seem to screw things up when using the destroyed signal
+ IrcUser *ircuser = static_cast<IrcUser *>(sender());
Q_ASSERT(ircuser);
- _ircUsers.remove(_ircUsers.key(ircuser));
+ removeIrcUser(ircuser);
}
void NetworkInfo::channelDestroyed() {
- IrcChannel *channel = qobject_cast<IrcChannel *>(sender());
- // in case this assert triggers we probably need a static_cast
- // dynamic_casts seem to screw things up when using the destroyed signal
+ IrcChannel *channel = static_cast<IrcChannel *>(sender());
Q_ASSERT(channel);
_ircChannels.remove(_ircChannels.key(channel));
}
_prefixes = PREFIX.section(")", 1);
_prefixModes = PREFIX.mid(1).section(")", 0, 0);
} else {
- QString defaultPrefixes("@%+");
- QString defaultPrefixModes("ohv");
+ QString defaultPrefixes("~&@%+");
+ QString defaultPrefixModes("qaohv");
// we just assume that in PREFIX are only prefix chars stored
for(int i = 0; i < defaultPrefixes.size(); i++) {