coreConnectionInfo.clear();
netsToSync.clear();
- channelsToSync.clear();
- usersToSync.clear();
blockSize = 0;
//restartPhaseNull();
}
// create buffers
// FIXME: get rid of this crap
QVariantList bufferinfos = sessionState["BufferInfos"].toList();
- foreach(QVariant vinfo, bufferinfos) Client::buffer(vinfo.value<BufferInfo>()); // create Buffers and BufferItems
+ foreach(QVariant vinfo, bufferinfos)
+ Client::buffer(vinfo.value<BufferInfo>()); // create Buffers and BufferItems
QVariantList networkids = sessionState["NetworkIds"].toList();
- // prepare sync progress thingys... FIXME: Care about removal of networks
+ // prepare sync progress thingys...
+ // FIXME: Care about removal of networks
numNetsToSync = networkids.count();
- numChannelsToSync = 0; //sessionState["IrcChannelCount"].toUInt();
- numUsersToSync = 0; // sessionState["IrcUserCount"].toUInt(); qDebug() << numUsersToSync;
emit networksProgress(0, numNetsToSync);
- emit channelsProgress(0, numChannelsToSync);
- emit ircUsersProgress(0, numUsersToSync);
// create network objects
foreach(QVariant networkid, networkids) {
Network *net = new Network(netid, Client::instance());
netsToSync.insert(net);
connect(net, SIGNAL(initDone()), this, SLOT(networkInitDone()));
- connect(net, SIGNAL(ircUserInitDone(IrcUser *)), this, SLOT(ircUserInitDone(IrcUser *)));
- connect(net, SIGNAL(ircUserAdded(IrcUser *)), this, SLOT(ircUserAdded(IrcUser *)));
- connect(net, SIGNAL(ircUserRemoved(QObject *)), this, SLOT(ircUserRemoved(QObject *)));
- connect(net, SIGNAL(ircChannelInitDone(IrcChannel *)), this, SLOT(ircChannelInitDone(IrcChannel *)));
- connect(net, SIGNAL(ircChannelAdded(IrcChannel *)), this, SLOT(ircChannelAdded(IrcChannel *)));
- connect(net, SIGNAL(ircChannelRemoved(QObject *)), this, SLOT(ircChannelRemoved(QObject *)));
Client::addNetwork(net);
}
checkSyncState();
checkSyncState();
}
-void ClientSyncer::ircChannelInitDone(IrcChannel *chan) {
- channelsToSync.remove(chan);
- emit channelsProgress(numChannelsToSync - channelsToSync.count(), numChannelsToSync);
- checkSyncState();
-}
-
-void ClientSyncer::ircChannelAdded(IrcChannel *chan) {
- if(!chan->isInitialized()) {
- channelsToSync.insert(chan);
- numChannelsToSync++;
- emit channelsProgress(numChannelsToSync - channelsToSync.count(), numChannelsToSync);
- checkSyncState();
- }
-}
-
-void ClientSyncer::ircChannelRemoved(QObject *chan) {
- if(channelsToSync.contains(chan)) {
- numChannelsToSync--;
- channelsToSync.remove(chan);
- emit channelsProgress(numChannelsToSync - channelsToSync.count(), numChannelsToSync);
- checkSyncState();
- }
-}
-
-void ClientSyncer::ircUserInitDone(IrcUser *user) {
- usersToSync.remove(user);
- emit ircUsersProgress(numUsersToSync - usersToSync.count(), numUsersToSync);
- checkSyncState();
-}
-
-void ClientSyncer::ircUserAdded(IrcUser *user) {
- if(!user->isInitialized()) {
- usersToSync.insert(user);
- numUsersToSync++;
- emit ircUsersProgress(numUsersToSync - usersToSync.count(), numUsersToSync);
- checkSyncState();
- }
-}
-
-void ClientSyncer::ircUserRemoved(QObject *user) {
- if(usersToSync.contains(user)) {
- numUsersToSync--;
- usersToSync.remove(user);
- emit ircUsersProgress(numUsersToSync - usersToSync.count(), numUsersToSync);
- checkSyncState();
- }
-}
-
void ClientSyncer::checkSyncState() {
- if(usersToSync.count() + channelsToSync.count() + netsToSync.count() == 0) {
- // done syncing!
- /*
- qDebug() << "done";
- foreach(Network *net, _networks.values()) {
- //disconnect(net, 0, this, SLOT(networkInitDone()));
- //disconnect(net, 0, this, SLOT(ircUserInitDone(IrcUser *)));
- //disconnect(net, 0, this, SLOT(ircUserAdded(IrcUser *)));
- //disconnect(net, 0, this, SLOT(ircUserRemoved(QObject *)));
- //disconnect(net, 0, this, SLOT(ircChannelInitDone(IrcChannel *)));
- //disconnect(net, 0, this, SLOT(ircChannelAdded(IrcChannel *)));
- //disconnect(net, 0, this, SLOT(ircChannelRemoved(QObject *)));
- qDebug() << "disconnecting";
- disconnect(net, SIGNAL(initDone()), this, SLOT(networkInitDone()));
- disconnect(net, SIGNAL(ircUserInitDone(IrcUser *)), this, SLOT(ircUserInitDone(IrcUser *)));
- disconnect(net, SIGNAL(ircUserAdded(IrcUser *)), this, SLOT(ircUserAdded(IrcUser *)));
- disconnect(net, SIGNAL(ircUserRemoved(QObject *)), this, SLOT(ircUserRemoved(QObject *)));
- disconnect(net, SIGNAL(ircChannelInitDone(IrcChannel *)), this, SLOT(ircChannelInitDone(IrcChannel *)));
- disconnect(net, SIGNAL(ircChannelAdded(IrcChannel *)), this, SLOT(ircChannelAdded(IrcChannel *)));
- disconnect(net, SIGNAL(ircChannelRemoved(QObject *)), this, SLOT(ircChannelRemoved(QObject *)));
- }
- */
-
+ if(netsToSync.isEmpty()) {
Client::instance()->setSyncedToCore();
emit syncFinished();
- //emit connected();
- //emit connectionStateChanged(true);
-
}
}
class ClientSyncer : public QObject {
Q_OBJECT
- public:
- ClientSyncer(QObject *parent = 0);
- ~ClientSyncer();
-
- signals:
- void recvPartialItem(quint32 avail, quint32 size);
- void connectionError(const QString &errorMsg);
- void connectionMsg(const QString &msg);
- void sessionProgress(quint32 part, quint32 total);
- void networksProgress(quint32 part, quint32 total);
- void channelsProgress(quint32 part, quint32 total);
- void ircUsersProgress(quint32 part, quint32 total);
- void socketStateChanged(QAbstractSocket::SocketState);
- void socketDisconnected();
-
- void startLogin();
- void loginFailed(const QString &error);
- void loginSuccess();
- void syncFinished();
- void startCoreSetup(const QVariantList &);
- void coreSetupSuccess();
- void coreSetupFailed(const QString &error);
-
- void encrypted(bool);
-
- public slots:
- void connectToCore(const QVariantMap &);
- void loginToCore(const QString &user, const QString &passwd);
- void disconnectFromCore();
-
- private slots:
- void coreSocketError(QAbstractSocket::SocketError);
- void coreHasData();
- void coreSocketConnected();
- void coreSocketDisconnected();
-
- void clientInitAck(const QVariantMap &msg);
-
+public:
+ ClientSyncer(QObject *parent = 0);
+ ~ClientSyncer();
+
+signals:
+ void recvPartialItem(quint32 avail, quint32 size);
+ void connectionError(const QString &errorMsg);
+ void connectionMsg(const QString &msg);
+ void sessionProgress(quint32 part, quint32 total);
+ void networksProgress(quint32 part, quint32 total);
+ void socketStateChanged(QAbstractSocket::SocketState);
+ void socketDisconnected();
+
+ void startLogin();
+ void loginFailed(const QString &error);
+ void loginSuccess();
+ void syncFinished();
+ void startCoreSetup(const QVariantList &);
+ void coreSetupSuccess();
+ void coreSetupFailed(const QString &error);
+
+ void encrypted(bool);
+
+public slots:
+ void connectToCore(const QVariantMap &);
+ void loginToCore(const QString &user, const QString &passwd);
+ void disconnectFromCore();
+
+private slots:
+ void coreSocketError(QAbstractSocket::SocketError);
+ void coreHasData();
+ void coreSocketConnected();
+ void coreSocketDisconnected();
+
+ void clientInitAck(const QVariantMap &msg);
+
// for sync progress
- void networkInitDone();
- void ircUserAdded(IrcUser *);
- void ircUserRemoved(QObject *);
- void ircUserInitDone(IrcUser *);
- void ircChannelAdded(IrcChannel *);
- void ircChannelRemoved(QObject *);
- void ircChannelInitDone(IrcChannel *);
- void checkSyncState();
-
- void syncToCore(const QVariantMap &sessionState);
- void sessionStateReceived(const QVariantMap &state);
-
- void doCoreSetup(const QVariant &setupData);
+ void networkInitDone();
+ void checkSyncState();
+
+ void syncToCore(const QVariantMap &sessionState);
+ void sessionStateReceived(const QVariantMap &state);
+
+ void doCoreSetup(const QVariant &setupData);
#ifndef QT_NO_OPENSSL
void sslErrors(const QList<QSslError> &errors);
#endif
- private:
- QPointer<QIODevice> socket;
- quint32 blockSize;
- QVariantMap coreConnectionInfo;
-
- QSet<QObject *> netsToSync, channelsToSync, usersToSync;
- int numNetsToSync, numChannelsToSync, numUsersToSync;
-
+private:
+ QPointer<QIODevice> socket;
+ quint32 blockSize;
+ QVariantMap coreConnectionInfo;
+
+ QSet<QObject *> netsToSync;
+ int numNetsToSync;
};
#endif
connect(ircChannel, SIGNAL(ircUserModeRemoved(IrcUser *, QString)),
this, SLOT(userModeChanged(IrcUser *)));
- if(!ircChannel->ircUsers().isEmpty()) {
- qWarning() << "Channel" << ircChannel->name() << "has already users which is quite surprising :)";
+ if(!ircChannel->ircUsers().isEmpty())
join(ircChannel->ircUsers());
- }
emit dataChanged();
}
return supports;
}
-QStringList Network::initIrcUsers() const {
- QStringList hostmasks;
- foreach(IrcUser *ircuser, ircUsers()) {
- hostmasks << ircuser->hostmask();
+QVariantMap Network::initIrcUsersAndChannels() const {
+ QVariantMap usersAndChannels;
+ QVariantMap users;
+ QVariantMap channels;
+
+ QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
+ QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
+ while(userIter != userIterEnd) {
+ users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
+ userIter++;
}
- return hostmasks;
+ usersAndChannels["users"] = users;
+
+ QHash<QString, IrcChannel *>::const_iterator channelIter = _ircChannels.constBegin();
+ QHash<QString, IrcChannel *>::const_iterator channelIterEnd = _ircChannels.constEnd();
+ while(channelIter != channelIterEnd) {
+ channels[channelIter.key()] = channelIter.value()->toVariantMap();
+ channelIter++;
+ }
+ usersAndChannels["channels"] = channels;
+
+ return usersAndChannels;
}
-QStringList Network::initIrcChannels() const {
- QStringList channels;
- QHash<QString, IrcChannel *>::const_iterator iter = _ircChannels.constBegin();
- while(iter != _ircChannels.constEnd()) {
- channels << iter.value()->name();
- iter++;
+void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) {
+ Q_ASSERT(proxy());
+ if(!_ircUsers.isEmpty() || !_ircChannels.isEmpty()) {
+ qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!";
+ return;
+ }
+
+ QVariantMap users = usersAndChannels.value("users").toMap();
+
+ QVariantMap::const_iterator userIter = users.constBegin();
+ QVariantMap::const_iterator userIterEnd = users.constEnd();
+ IrcUser *ircUser = 0;
+ QString hostmask;
+ while(userIter != userIterEnd) {
+ hostmask = userIter.key();
+ ircUser = new IrcUser(hostmask, this);
+ ircUser->fromVariantMap(userIter.value().toMap());
+ ircUser->setInitialized();
+ proxy()->synchronize(ircUser);
+
+ connect(ircUser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
+ connect(ircUser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed()));
+
+ _ircUsers[nickFromMask(hostmask).toLower()] = ircUser;
+
+ emit ircUserAdded(hostmask);
+ emit ircUserAdded(ircUser);
+ emit ircUserInitDone(ircUser);
+
+ userIter++;
}
- return channels;
+
+
+ QVariantMap channels = usersAndChannels.value("channels").toMap();
+ QVariantMap::const_iterator channelIter = channels.constBegin();
+ QVariantMap::const_iterator channelIterEnd = channels.constEnd();
+ IrcChannel *ircChannel = 0;
+ QString channelName;
+
+ while(channelIter != channelIterEnd) {
+ channelName = channelIter.key();
+ ircChannel = new IrcChannel(channelName, this);
+ ircChannel->fromVariantMap(channelIter.value().toMap());
+ ircChannel->setInitialized();
+ proxy()->synchronize(ircChannel);
+
+ connect(ircChannel, SIGNAL(destroyed()), this, SLOT(channelDestroyed()));
+ _ircChannels[channelName.toLower()] = ircChannel;
+
+ emit ircChannelAdded(channelName);
+ emit ircChannelAdded(ircChannel);
+ emit ircChannelInitDone(ircChannel);
+
+ channelIter++;
+ }
+
}
void Network::initSetSupports(const QVariantMap &supports) {
}
}
-void Network::initSetIrcUsers(const QStringList &hostmasks) {
- if(!_ircUsers.empty())
- return;
- foreach(QString hostmask, hostmasks) {
- newIrcUser(hostmask);
- }
-}
-
-void Network::initSetIrcChannels(const QStringList &channels) {
- if(!_ircChannels.empty())
- return;
- foreach(QString channel, channels)
- newIrcChannel(channel);
-}
-
IrcUser *Network::updateNickFromMask(const QString &mask) {
QString nick(nickFromMask(mask).toLower());
IrcUser *ircuser;
void Network::ircUserInitDone() {
IrcUser *ircuser = static_cast<IrcUser *>(sender());
Q_ASSERT(ircuser);
+ connect(ircuser, SIGNAL(initDone()), this, SLOT(ircUserInitDone()));
emit ircUserInitDone(ircuser);
}
void Network::ircChannelInitDone() {
- IrcChannel *ircchannel = static_cast<IrcChannel *>(sender());
- Q_ASSERT(ircchannel);
- emit ircChannelInitDone(ircchannel);
+ IrcChannel *ircChannel = static_cast<IrcChannel *>(sender());
+ Q_ASSERT(ircChannel);
+ disconnect(ircChannel, SIGNAL(initDone()), this, SLOT(ircChannelInitDone()));
+ emit ircChannelInitDone(ircChannel);
}
void Network::removeIrcChannel(IrcChannel *channel) {
//init geters
QVariantMap initSupports() const;
inline QVariantList initServerList() const { return serverList(); }
- QStringList initIrcUsers() const;
- QStringList initIrcChannels() const;
+ virtual QVariantMap initIrcUsersAndChannels() const;
+// QStringList initIrcUsers() const;
+// QStringList initIrcChannels() const;
//init seters
void initSetSupports(const QVariantMap &supports);
inline void initSetServerList(const QVariantList &serverList) { setServerList(serverList); }
- void initSetIrcUsers(const QStringList &hostmasks);
- void initSetIrcChannels(const QStringList &channels);
+ virtual void initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels);
+// void initSetIrcUsers(const QStringList &hostmasks);
+// void initSetIrcChannels(const QStringList &channels);
IrcUser *updateNickFromMask(const QString &mask);
connect(clientSyncer, SIGNAL(startCoreSetup(const QVariantList &)), this, SLOT(startCoreConfig(const QVariantList &)));
connect(clientSyncer, SIGNAL(sessionProgress(quint32, quint32)), this, SLOT(coreSessionProgress(quint32, quint32)));
connect(clientSyncer, SIGNAL(networksProgress(quint32, quint32)), this, SLOT(coreNetworksProgress(quint32, quint32)));
- connect(clientSyncer, SIGNAL(channelsProgress(quint32, quint32)), this, SLOT(coreChannelsProgress(quint32, quint32)));
- connect(clientSyncer, SIGNAL(ircUsersProgress(quint32, quint32)), this, SLOT(coreIrcUsersProgress(quint32, quint32)));
connect(clientSyncer, SIGNAL(syncFinished()), this, SLOT(syncFinished()));
connect(ui.user, SIGNAL(textChanged(const QString &)), this, SLOT(setLoginWidgetStates()));
ui.sessionProgress->setValue(0);
ui.networksProgress->setRange(0, 1);
ui.networksProgress->setValue(0);
- ui.channelsProgress->setRange(0, 1);
- ui.channelsProgress->setValue(0);
- ui.ircUsersProgress->setRange(0, 1);
- ui.ircUsersProgress->setValue(0);
ui.stackedWidget->setCurrentWidget(ui.syncPage);
// clean up old page
}
}
-void CoreConnectDlg::coreChannelsProgress(quint32 val, quint32 max) {
- if(max == 0) {
- ui.channelsProgress->setFormat("0/0");
- ui.channelsProgress->setRange(0, 1);
- ui.channelsProgress->setValue(1);
- } else {
- ui.channelsProgress->setFormat("%v/%m");
- ui.channelsProgress->setRange(0, max);
- ui.channelsProgress->setValue(val);
- }
-}
-
-void CoreConnectDlg::coreIrcUsersProgress(quint32 val, quint32 max) {
- if(max == 0) {
- ui.ircUsersProgress->setFormat("0/0");
- ui.ircUsersProgress->setRange(0, 1);
- ui.ircUsersProgress->setValue(1);
- } else {
- if(val % 100) return;
- ui.ircUsersProgress->setFormat("%v/%m");
- ui.ircUsersProgress->setRange(0, max);
- ui.ircUsersProgress->setValue(val);
- }
-}
-
void CoreConnectDlg::syncFinished() {
if(!wizard) accept();
else {
void coreSessionProgress(quint32, quint32);
void coreNetworksProgress(quint32, quint32);
- void coreChannelsProgress(quint32, quint32);
- void coreIrcUsersProgress(quint32, quint32);
private:
Ui::CoreConnectDlg ui;
<rect>
<x>0</x>
<y>0</y>
- <width>519</width>
- <height>325</height>
+ <width>563</width>
+ <height>356</height>
</rect>
</property>
<property name="sizePolicy" >
</sizepolicy>
</property>
<property name="currentIndex" >
- <number>0</number>
+ <number>2</number>
</property>
<widget class="QWidget" name="accountPage" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
- <width>511</width>
- <height>317</height>
+ <width>539</width>
+ <height>331</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<rect>
<x>0</x>
<y>0</y>
- <width>511</width>
- <height>317</height>
+ <width>539</width>
+ <height>332</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<rect>
<x>0</x>
<y>0</y>
- <width>485</width>
- <height>147</height>
+ <width>501</width>
+ <height>145</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<rect>
<x>0</x>
<y>0</y>
- <width>511</width>
- <height>317</height>
+ <width>539</width>
+ <height>332</height>
</rect>
</property>
<layout class="QVBoxLayout" >
</property>
</widget>
</item>
- <item row="2" column="0" >
- <widget class="QLabel" name="label_4" >
- <property name="text" >
- <string>Channel states:</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1" >
- <widget class="QProgressBar" name="channelsProgress" >
- <property name="maximum" >
- <number>1</number>
- </property>
- <property name="value" >
- <number>0</number>
- </property>
- <property name="format" >
- <string>0/0</string>
- </property>
- </widget>
- </item>
- <item row="3" column="0" >
- <widget class="QLabel" name="label_5" >
- <property name="text" >
- <string>User states:</string>
- </property>
- </widget>
- </item>
- <item row="3" column="1" >
- <widget class="QProgressBar" name="ircUsersProgress" >
- <property name="minimum" >
- <number>0</number>
- </property>
- <property name="maximum" >
- <number>1</number>
- </property>
- <property name="value" >
- <number>0</number>
- </property>
- <property name="format" >
- <string>0/0</string>
- </property>
- </widget>
- </item>
</layout>
</item>
<item>
//! This is the fallback version number in case we can't autogenerate one
quasselBaseVersion = "0.3.0-pre";
-protocolVersion = 1; //< Version of the client/core protocol
+protocolVersion = 2; //< Version of the client/core protocol
-coreNeedsProtocol = 1; //< Minimum protocol version the core needs
-clientNeedsProtocol = 1; //< Minimum protocol version the client needs
+coreNeedsProtocol = 2; //< Minimum protocol version the core needs
+clientNeedsProtocol = 2; //< Minimum protocol version the client needs