From 44b22c4419f478a20f6324f9f3a700a2dec56302 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 1 Aug 2007 22:38:13 +0000 Subject: [PATCH] OK Folks, my first commit after quite a while, and while Quassel looks the same as before, a lot of changed under the hood. This includes * Parts of the new settings system, includin session data which is gonna replace Global * Multi-user core * Complete separation of core and client even in th monolithic client Basically now most of the multi-user core and core connection code is in place, as well as most of the skeleton for the authentification. Since parts of the UI, disconnecting from a core and connecting to a remote core don't work yet, I have most of it disabled or hidden. Things will fall back in place piece by piece, without requiring too many changes to the source in the future I hope. Oh yeah, due to the new settings stuff, you will have to enter identity, network and other data anew. Maybe this is a good opportunity to wipe out your .config... --- Quassel.kdevelop.filelist | 4 + src/client/CMakeLists.txt | 5 +- src/client/buffer.cpp | 1 + src/client/client.cpp | 52 +++- src/client/client.h | 5 + src/client/clientsettings.cpp | 87 ++++++ src/client/clientsettings.h | 61 ++++ src/client/treemodel.cpp | 1 + src/client/treemodel.h | 5 +- src/common/CMakeLists.txt | 4 +- src/common/global.h | 2 + src/common/main.cpp | 2 +- src/common/settings.cpp | 51 ++-- src/common/settings.h | 37 ++- src/core/core.cpp | 2 +- src/core/core.h | 4 +- src/core/coresession.cpp | 2 +- src/core/server.cpp | 9 +- src/core/server.h | 2 - src/qtgui/CMakeLists.txt | 6 +- src/qtgui/coreconnectdlg.cpp | 240 ++++++++++++++-- src/qtgui/coreconnectdlg.h | 22 +- src/qtgui/guisettings.cpp | 19 ++ src/qtgui/guisettings.h | 48 ++++ src/qtgui/identities.cpp | 9 +- src/qtgui/mainwin.cpp | 63 +++- src/qtgui/mainwin.h | 3 + src/qtgui/serverlist.cpp | 30 +- src/qtgui/serverlist.h | 2 +- src/qtgui/ui/coreconnectdlg.ui | 512 ++++++++++++++++++++++----------- src/qtgui/ui/mainwin.ui | 21 +- 31 files changed, 1024 insertions(+), 287 deletions(-) create mode 100644 src/client/clientsettings.cpp create mode 100644 src/client/clientsettings.h create mode 100644 src/qtgui/guisettings.cpp create mode 100644 src/qtgui/guisettings.h diff --git a/Quassel.kdevelop.filelist b/Quassel.kdevelop.filelist index dc089253..07efc40b 100644 --- a/Quassel.kdevelop.filelist +++ b/Quassel.kdevelop.filelist @@ -97,3 +97,7 @@ src/qtgui/ui/nickeditdlg.ui src/qtgui/ui/servereditdlg.ui src/qtgui/ui/serverlistdlg.ui src/qtgui/ui/settingsdlg.ui +src/client/clientsettings.h +src/client/clientsettings.cpp +src/qtgui/guisettings.h +src/qtgui/guisettings.cpp diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 920eb977..159b4f1a 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -1,6 +1,7 @@ -SET(client_SRCS buffer.cpp buffertreemodel.cpp client.cpp clientproxy.cpp treemodel.cpp) +SET(client_SRCS buffer.cpp buffertreemodel.cpp client.cpp clientproxy.cpp clientsettings.cpp treemodel.cpp) SET(client_HDRS ) -SET(client_MOCS buffer.h buffertreemodel.h client.h clientproxy.h treemodel.h) +SET(client_MOCS buffer.h buffertreemodel.h client.h clientproxy.h clientsettings.h treemodel.h) QT4_WRAP_CPP(_MOC ${client_MOCS}) ADD_LIBRARY(client ${client_SRCS} ${_MOC}) +TARGET_LINK_LIBRARIES(client common) \ No newline at end of file diff --git a/src/client/buffer.cpp b/src/client/buffer.cpp index 7f4d885a..7afc15b5 100644 --- a/src/client/buffer.cpp +++ b/src/client/buffer.cpp @@ -43,6 +43,7 @@ Buffer::Buffer(BufferId bufid) { } Buffer::~Buffer() { + //qDebug() << "destroying buffer"; //delete widget; /* QSettings s; diff --git a/src/client/client.cpp b/src/client/client.cpp index 9a74119d..b591f2c4 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -30,10 +30,12 @@ Client * Client::instanceptr = 0; bool Client::connectedToCore = false; Client::ClientMode Client::clientMode; +VarMap Client::coreConnectionInfo; QHash Client::buffers; QHash Client::bufferIds; QHash > Client::nicks; QHash Client::netConnected; +QStringList Client::netsAwaitingInit; QHash Client::ownNick; Client *Client::instance() { @@ -126,15 +128,17 @@ bool Client::isConnected() { return connectedToCore; } void Client::connectToCore(const VarMap &conn) { // TODO implement SSL + coreConnectionInfo = conn; if(isConnected()) { - qDebug() << "Already connected to core!"; + emit coreConnectionError(tr("Already connected to Core!")); return; } if(conn["Host"].toString().isEmpty()) { clientMode = LocalCore; - syncToCore(); // TODO send user and pw from conn info + syncToCore(); } else { clientMode = RemoteCore; + emit coreConnectionMsg(tr("Connecting...")); socket.connectToHost(conn["Host"].toString(), conn["Port"].toUInt()); } } @@ -146,7 +150,14 @@ void Client::disconnectFromCore() { disconnectFromLocalCore(); coreDisconnected(); } - // TODO clear internal data + /* Clear internal data. Hopefully nothing relies on it at this point. */ + coreConnectionInfo.clear(); + sessionData.clear(); + //foreach(Buffer *buf, buffers.values()) delete buf; + qDebug() << "barfoo"; + _bufferModel->clear(); + //qDeleteAll(buffers); + qDebug() << "foobar"; } void Client::coreConnected() { @@ -162,9 +173,9 @@ void Client::coreDisconnected() { void Client::syncToCore() { VarMap state; if(clientMode == LocalCore) { - state = connectToLocalCore("Default", "password").toMap(); // TODO make this configurable + state = connectToLocalCore(coreConnectionInfo["User"].toString(), coreConnectionInfo["Password"].toString()).toMap(); } else { - + // TODO connect to remote cores } VarMap data = state["CoreData"].toMap(); @@ -176,6 +187,10 @@ void Client::syncToCore() { //} VarMap sessionState = state["SessionState"].toMap(); + VarMap sessData = sessionState["SessionData"].toMap(); + foreach(QString key, sessData.keys()) { + recvSessionData(key, sessData[key]); + } QList coreBuffers = sessionState["Buffers"].toList(); /* make lookups by id faster */ foreach(QVariant vid, coreBuffers) { @@ -183,9 +198,17 @@ void Client::syncToCore() { bufferIds[id.uid()] = id; // make lookups by id faster buffer(id); // create all buffers, so we see them in the network views } + netsAwaitingInit = sessionState["Networks"].toStringList(); connectedToCore = true; - emit connected(); - emit requestNetworkStates(); + if(netsAwaitingInit.count()) { + emit coreConnectionMsg(tr("Requesting network states...")); + emit coreConnectionProgress(0, netsAwaitingInit.count()); + emit requestNetworkStates(); + } + else { + emit coreConnectionProgress(1, 1); + emit connected(); + } } void Client::updateCoreData(UserId, QString key) { @@ -202,7 +225,6 @@ void Client::recvSessionData(const QString &key, const QVariant &data) { sessionData[key] = data; emit sessionDataChanged(key, data); emit sessionDataChanged(key); - qDebug() << "stored data in client:" << key; } void Client::storeSessionData(const QString &key, const QVariant &data) { @@ -217,6 +239,10 @@ QVariant Client::retrieveSessionData(const QString &key, const QVariant &def) { else return def; } +QStringList Client::sessionDataKeys() { + return instance()->sessionData.keys(); +} + void Client::recvProxySignal(ClientSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) { if(clientMode == LocalCore) return; QList sigdata; @@ -244,6 +270,7 @@ void Client::serverHasData() { } void Client::networkConnected(QString net) { + Q_ASSERT(!netsAwaitingInit.contains(net)); netConnected[net] = true; BufferId id = statusBufferId(net); Buffer *b = buffer(id); @@ -260,6 +287,12 @@ void Client::networkDisconnected(QString net) { b->setActive(false); } netConnected[net] = false; + if(netsAwaitingInit.contains(net)) { + qDebug() << "Network" << net << "disconnected while not yet initialized!"; + netsAwaitingInit.removeAll(net); + emit coreConnectionProgress(netConnected.count(), netConnected.count() + netsAwaitingInit.count()); + if(!netsAwaitingInit.count()) emit connected(); + } } void Client::updateBufferId(BufferId id) { @@ -299,6 +332,7 @@ QList Client::allBufferIds() { } void Client::recvNetworkState(QString net, QVariant state) { + netsAwaitingInit.removeAll(net); netConnected[net] = true; setOwnNick(net, state.toMap()["OwnNick"].toString()); buffer(statusBufferId(net))->setActive(true); @@ -313,6 +347,8 @@ void Client::recvNetworkState(QString net, QVariant state) { foreach(QString nick, n.keys()) { addNick(net, nick, n[nick].toMap()); } + emit coreConnectionProgress(netConnected.count(), netConnected.count() + netsAwaitingInit.count()); + if(!netsAwaitingInit.count()) emit connected(); } void Client::recvMessage(const Message &msg) { diff --git a/src/client/client.h b/src/client/client.h index 1b3a4e8d..9bb606ac 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -57,6 +57,7 @@ class Client : public QObject { static void storeSessionData(const QString &key, const QVariant &data); static QVariant retrieveSessionData(const QString &key, const QVariant &def = QVariant()); + static QStringList sessionDataKeys(); signals: void sendInput(BufferId, QString message); @@ -71,6 +72,8 @@ class Client : public QObject { void recvPartialItem(quint32 avail, quint32 size); void coreConnectionError(QString errorMsg); + void coreConnectionMsg(const QString &msg); + void coreConnectionProgress(uint part, uint total); void connected(); void disconnected(); @@ -134,10 +137,12 @@ class Client : public QObject { quint32 blockSize; static bool connectedToCore; + static VarMap coreConnectionInfo; static QHash buffers; static QHash bufferIds; static QHash > nicks; static QHash netConnected; + static QStringList netsAwaitingInit; static QHash ownNick; QTimer *layoutTimer; diff --git a/src/client/clientsettings.cpp b/src/client/clientsettings.cpp new file mode 100644 index 00000000..6f40a235 --- /dev/null +++ b/src/client/clientsettings.cpp @@ -0,0 +1,87 @@ +/*************************************************************************** + * Copyright (C) 2005-07 by The Quassel IRC Development 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "client.h" +#include "clientsettings.h" + +#include + +ClientSettings::ClientSettings(QString g) : Settings(g) { + + +} + +ClientSettings::~ClientSettings() { + + +} + +QStringList ClientSettings::sessionKeys() { + return Client::sessionDataKeys(); +} + +void ClientSettings::setSessionValue(const QString &key, const QVariant &data) { + Client::storeSessionData(key, data); +} + +QVariant ClientSettings::sessionValue(const QString &key, const QVariant &def) { + return Client::retrieveSessionData(key, def); +} + +/***********************************************************************************************/ + +AccountSettings::AccountSettings() : ClientSettings("Accounts") { + + +} + +QStringList AccountSettings::knownAccounts() { + return localChildGroups(); +} + +QString AccountSettings::lastAccount() { + return localValue("LastAccount", "").toString(); +} + +void AccountSettings::setLastAccount(const QString &account) { + setLocalValue("LastAccount", account); +} + +QString AccountSettings::autoConnectAccount() { + return localValue("AutoConnectAccount", "").toString(); +} + +void AccountSettings::setAutoConnectAccount(const QString &account) { + setLocalValue("AutoConnectAccount", account); +} + +void AccountSettings::setValue(const QString &account, const QString &key, const QVariant &data) { + setLocalValue(QString("%1/%2").arg(account).arg(key), data); +} + +QVariant AccountSettings::value(const QString &account, const QString &key, const QVariant &def) { + return localValue(QString("%1/%2").arg(account).arg(key), def); +} + +void AccountSettings::removeAccount(const QString &account) { + removeLocalKey(account); +} + + diff --git a/src/client/clientsettings.h b/src/client/clientsettings.h new file mode 100644 index 00000000..b14cb451 --- /dev/null +++ b/src/client/clientsettings.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2005-07 by The Quassel IRC Development 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _CLIENTSETTINGS_H_ +#define _CLIENTSETTINGS_H_ + +#include "settings.h" + +class ClientSettings : public Settings { + Q_OBJECT + + public: + virtual ~ClientSettings(); + + protected: + ClientSettings(QString group = "General"); + + //virtual QStringList allSessionKeys() = 0; + virtual QStringList sessionKeys(); + + virtual void setSessionValue(const QString &key, const QVariant &data); + virtual QVariant sessionValue(const QString &key, const QVariant &def = QVariant()); + +}; + +class AccountSettings : public ClientSettings { + Q_OBJECT + + public: + AccountSettings(); + + QStringList knownAccounts(); + QString lastAccount(); + void setLastAccount(const QString &account); + QString autoConnectAccount(); + void setAutoConnectAccount(const QString &account); + + void setValue(const QString &account, const QString &key, const QVariant &data); + QVariant value(const QString &account, const QString &key, const QVariant &def = QVariant()); + void removeAccount(const QString &account); + +}; + +#endif diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index fef6a216..0d6111fb 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -194,6 +194,7 @@ bool TreeModel::removeRows(int row, int count, const QModelIndex &parent) { beginRemoveRows(parent, row, row + count - 1); + for(int i = row + count - 1; i >= 0; i--) { item->removeChild(i); } diff --git a/src/client/treemodel.h b/src/client/treemodel.h index f979d113..2b7928c5 100644 --- a/src/client/treemodel.h +++ b/src/client/treemodel.h @@ -71,11 +71,12 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; + void clear(); + protected: bool removeRow(int row, const QModelIndex &parent = QModelIndex()); bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); - void clear(); - + TreeItem *rootItem; }; diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d44d9c7e..d63db6bd 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,6 +1,6 @@ SET(common_SRCS global.cpp logger.cpp message.cpp settings.cpp util.cpp ircuser.cpp) -SET(common_HDRS message.h settings.h util.h) -SET(common_MOCS global.h logger.h ircuser.h quasselui.h) +SET(common_HDRS message.h util.h) +SET(common_MOCS global.h logger.h ircuser.h quasselui.h settings.h) QT4_WRAP_CPP(_MOC ${common_MOCS}) ADD_LIBRARY(common ${common_SRCS} ${_MOC}) diff --git a/src/common/global.h b/src/common/global.h index 2723b66b..efa27aa1 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -27,6 +27,8 @@ #define BACKLOG_FORMAT 2 #define BACKLOG_STRING "QuasselIRC Backlog File" +#define DEFAULT_PORT 4242 + class Global; #include diff --git a/src/common/main.cpp b/src/common/main.cpp index c53daabc..c47d8b74 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -64,7 +64,7 @@ int main(int argc, char **argv) { Core::instance(); // create and init the core #endif - Settings::init(); + //Settings::init(); #ifndef BUILD_CORE Style::init(); diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 77144c7b..4f061854 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -19,45 +19,58 @@ ***************************************************************************/ #include +#include +#include #include "settings.h" -Settings *settings; +Settings::Settings(QString g) : QObject(), group(g) { + -void Settings::init() { - curProfile = QObject::tr("Default"); } -/* + Settings::~Settings() { - qDebug() << "destructing"; } -*/ -void Settings::setProfile(const QString &profile) { - curProfile = profile; +void Settings::setGroup(QString g) { + group = g; + +} + +QStringList Settings::allLocalKeys() { + QSettings s; + s.beginGroup(group); + return s.allKeys(); +} + +QStringList Settings::localChildKeys() { + QSettings s; + s.beginGroup(group); + return s.childKeys(); } -void Settings::setGuiValue(const QString &key, const QVariant &value) { +QStringList Settings::localChildGroups() { QSettings s; - //s.setValue("GUI/Default/BufferStates/QuakeNet/#quassel/voicedExpanded", true); - //QString k = QString("GUI/%1/%2").arg(curProfile).arg(key); - s.setValue(QString("GUI/%1/%2").arg(curProfile).arg(key), value); + s.beginGroup(group); + return s.childGroups(); } -QVariant Settings::guiValue(const QString &key, const QVariant &defaultValue) { +void Settings::setLocalValue(const QString &key, const QVariant &data) { QSettings s; - return s.value(QString("GUI/%1/%2").arg(curProfile).arg(key), defaultValue); + s.beginGroup(group); + s.setValue(key, data); } -void Settings::setCoreValue(const QString &user, const QString &key, const QVariant &value) { +QVariant Settings::localValue(const QString &key, const QVariant &def) { QSettings s; - s.setValue(QString("Core/%1/%2").arg(user).arg(key), value); + s.beginGroup(group); + return s.value(key, def); } -QVariant Settings::coreValue(const QString &user, const QString &key, const QVariant &defaultValue) { +void Settings::removeLocalKey(const QString &key) { QSettings s; - return s.value(QString("Core/%1/%2").arg(user).arg(key), defaultValue); + s.beginGroup(group); + s.remove(key); } -QString Settings::curProfile; diff --git a/src/common/settings.h b/src/common/settings.h index 4ef26640..efa03d7a 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -24,25 +24,36 @@ #include #include -class Settings { +class Settings : public QObject { + Q_OBJECT public: - //Settings(); - //~Settings(); - static void init(); - static void setProfile(const QString &string); - static QString profile(); + virtual ~Settings(); - static void setGuiValue(const QString &key, const QVariant &value); - static QVariant guiValue (const QString &key, const QVariant &defaultValue = QVariant()); - static void setCoreValue(const QString &user, const QString &key, const QVariant &value); - static QVariant coreValue (const QString &user, const QString& key, const QVariant &defaultValue = QVariant()); + static void setGuiValue(QString, QVariant) {}; + static QVariant guiValue(QString, QVariant = QVariant()) { return QVariant(); } + protected: + Settings(QString group = "General"); - private: - static QString curProfile; + void setGroup(QString group); + virtual QStringList allLocalKeys(); + virtual QStringList localChildKeys(); + virtual QStringList localChildGroups(); + //virtual QStringList allSessionKeys() = 0; + virtual QStringList sessionKeys() = 0; + + virtual void setLocalValue(const QString &key, const QVariant &data); + virtual QVariant localValue(const QString &key, const QVariant &def = QVariant()); + + virtual void setSessionValue(const QString &key, const QVariant &data) = 0; + virtual QVariant sessionValue(const QString &key, const QVariant &def = QVariant()) = 0; + + virtual void removeLocalKey(const QString &key); + + QString group; }; -//extern Settings *settings; + #endif diff --git a/src/core/core.cpp b/src/core/core.cpp index e6b8c7f3..9385c64e 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -179,7 +179,7 @@ QVariant Core::connectLocalClient(QString user, QString passwd) { return reply; } -QVariant Core::disconnectLocalClient() { +void Core::disconnectLocalClient() { qDebug() << "Local client disconnected."; instance()->guiUser = 0; Global::setGuiUser(0); diff --git a/src/core/core.h b/src/core/core.h index 374d8210..15a2e90a 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -43,11 +43,11 @@ class Core : public QObject { static CoreSession * createSession(UserId); static QVariant connectLocalClient(QString user, QString passwd); - static QVariant disconnectLocalClient(); + static void disconnectLocalClient(); private slots: void recvProxySignal(CoreSignal, QVariant, QVariant, QVariant); - bool startListening(uint port = 4242); + bool startListening(uint port = DEFAULT_PORT); void stopListening(); void incomingConnection(); void clientHasData(); diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index 49467118..e10b3599 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -181,7 +181,7 @@ QVariant CoreSession::sessionState() { mutex.lock(); v["SessionData"] = sessionData; mutex.unlock(); - + v["Networks"] = QVariant(servers.keys()); return v; } diff --git a/src/core/server.cpp b/src/core/server.cpp index 44d66ab5..6bccd564 100644 --- a/src/core/server.cpp +++ b/src/core/server.cpp @@ -24,6 +24,8 @@ #include #include "util.h" +#include "core.h" +#include "coresession.h" Server::Server(UserId uid, QString net) : user(uid), network(net) { QString MQUOTE = QString('\020'); @@ -68,8 +70,11 @@ void Server::sendState() { void Server::connectToIrc(QString net) { if(net != network) return; // not me! - networkSettings = Global::data(user, "Networks").toMap()[net].toMap(); - identity = Global::data(user, "Identities").toMap()[networkSettings["Identity"].toString()].toMap(); + CoreSession *sess = Core::session(user); + //networkSettings = Global::data(user, "Networks").toMap()[net].toMap(); + networkSettings = sess->retrieveSessionData("Networks").toMap()[net].toMap(); + //identity = Global::data(user, "Identities").toMap()[networkSettings["Identity"].toString()].toMap(); + identity = sess->retrieveSessionData("Identities").toMap()[networkSettings["Identity"].toString()].toMap(); QList servers = networkSettings["Servers"].toList(); QString host = servers[0].toMap()["Address"].toString(); quint16 port = servers[0].toMap()["Port"].toUInt(); diff --git a/src/core/server.h b/src/core/server.h index bcc7ffdb..dd8aac9b 100644 --- a/src/core/server.h +++ b/src/core/server.h @@ -31,8 +31,6 @@ #include "message.h" #include "serverinfo.h" -#define DEFAULT_PORT 6667 - /*! * This is a server object, managing a single connection to an IRC server, handling the associated channels and so on. diff --git a/src/qtgui/CMakeLists.txt b/src/qtgui/CMakeLists.txt index cef85a46..d50af804 100644 --- a/src/qtgui/CMakeLists.txt +++ b/src/qtgui/CMakeLists.txt @@ -1,8 +1,8 @@ SET(qtgui_SRCS bufferview.cpp bufferviewfilter.cpp bufferwidget.cpp channelwidgetinput.cpp chatline.cpp chatwidget.cpp coreconnectdlg.cpp - identities.cpp mainwin.cpp qtgui.cpp serverlist.cpp settingsdlg.cpp settingspages.cpp style.cpp tabcompleter.cpp) + guisettings.cpp identities.cpp mainwin.cpp qtgui.cpp serverlist.cpp settingsdlg.cpp settingspages.cpp style.cpp tabcompleter.cpp) SET(qtgui_HDRS style.h) SET(qtgui_MOCS bufferview.h bufferviewfilter.h bufferwidget.h channelwidgetinput.h chatline.h chatwidget.h coreconnectdlg.h - identities.h mainwin.h qtgui.h serverlist.h settingsdlg.h settingspages.h tabcompleter.h) + guisettings.h identities.h mainwin.h qtgui.h serverlist.h settingsdlg.h settingspages.h tabcompleter.h) SET(qtgui_UICS identitiesdlg.ui identitieseditdlg.ui networkeditdlg.ui mainwin.ui nickeditdlg.ui serverlistdlg.ui servereditdlg.ui coreconnectdlg.ui ircwidget.ui bufferviewwidget.ui bufferwidget.ui settingsdlg.ui @@ -19,4 +19,4 @@ QT4_WRAP_CPP(_MOC ${qtgui_MOCS}) #INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) ADD_LIBRARY(qtgui ${qtgui_SRCS} ${_MOC} ${_UIC}) -TARGET_LINK_LIBRARIES(qtgui common) \ No newline at end of file +TARGET_LINK_LIBRARIES(qtgui common client) \ No newline at end of file diff --git a/src/qtgui/coreconnectdlg.cpp b/src/qtgui/coreconnectdlg.cpp index 102c3cc5..90efe6fc 100644 --- a/src/qtgui/coreconnectdlg.cpp +++ b/src/qtgui/coreconnectdlg.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005/06 by The Quassel Team * + * Copyright (C) 2005-07 by The Quassel Team * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -23,24 +23,212 @@ #include "clientproxy.h" #include "global.h" #include "client.h" +#include "clientsettings.h" + +CoreConnectDlg::CoreConnectDlg(QWidget *parent, bool /*doAutoConnect*/) : QDialog(parent) { + ui.setupUi(this); //qDebug() << "new dlg"; -CoreConnectDlg::CoreConnectDlg(QWidget *parent) : QDialog(parent) { - ui.setupUi(this); - ui.progressBar->hide(); coreState = 0; - QSettings s; - /* - connect(ui.hostName, SIGNAL(textChanged(QString)), this, SLOT(hostEditChanged(QString))); - connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(hostSelected())); - - ui.hostName->setText(s.value("GUI/CoreHost", "localhost").toString()); - ui.hostName->setSelection(0, ui.hostName->text().length()); - ui.hostPort->setValue(s.value("GUI/CorePort", 4242).toInt()); - ui.autoConnect->setChecked(s.value("GUI/CoreAutoConnect", true).toBool()); - if(s.value("GUI/CoreAutoConnect").toBool()) { - hostSelected(); + if(Global::runMode == Global::Monolithic) { + connect(ui.internalCore, SIGNAL(toggled(bool)), ui.hostEdit, SLOT(setDisabled(bool))); + connect(ui.internalCore, SIGNAL(toggled(bool)), ui.port, SLOT(setDisabled(bool))); + ui.internalCore->setChecked(true); + } else { + ui.internalCore->hide(); + } + connect(ui.newAccount, SIGNAL(clicked()), this, SLOT(createAccount())); + connect(ui.delAccount, SIGNAL(clicked()), this, SLOT(removeAccount())); + connect(ui.buttonBox1, SIGNAL(accepted()), this, SLOT(doConnect())); + connect(ui.hostEdit, SIGNAL(textChanged(const QString &)), this, SLOT(checkInputValid())); + connect(ui.userEdit, SIGNAL(textChanged(const QString &)), this, SLOT(checkInputValid())); + connect(ui.internalCore, SIGNAL(toggled(bool)), this, SLOT(checkInputValid())); + connect(ui.accountList, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(accountChanged(const QString &))); + connect(ui.autoConnect, SIGNAL(clicked(bool)), this, SLOT(autoConnectToggled(bool))); + + connect(Client::instance(), SIGNAL(coreConnectionMsg(const QString &)), ui.connectionStatus, SLOT(setText(const QString &))); + connect(Client::instance(), SIGNAL(coreConnectionProgress(uint, uint)), this, SLOT(updateProgressBar(uint, uint))); + connect(Client::instance(), SIGNAL(coreConnectionError(QString)), this, SLOT(coreConnectionError(QString))); + connect(Client::instance(), SIGNAL(connected()), this, SLOT(coreConnected())); + + AccountSettings s; + ui.accountList->addItems(s.knownAccounts()); + curacc = s.lastAccount(); + if(!ui.accountList->count()) { + //if(doAutoConnect) reject(); + /* + setAccountEditEnabled(false); + QString newacc = QInputDialog::getText(this, tr("Create Account"), tr( + "In order to connect to a Quassel Core, you need to create an account.
" + "Please enter a name for this account now:"), QLineEdit::Normal, tr("Default")); + if(!newacc.isEmpty()) { + ui.accountList->addItem(newacc); + ui.hostEdit->setText("localhost"); + ui.port->setValue(DEFAULT_PORT); + ui.internalCore->setChecked(false); + setAccountEditEnabled(true); + } + */ + // FIXME We create a default account here that just connects to the internal core + curacc = "Default"; + ui.accountList->addItem("Default"); + ui.internalCore->setChecked(true); + ui.userEdit->setText("Default"); + ui.passwdEdit->setText("password"); + ui.rememberPasswd->setChecked(true); + accountChanged(curacc); + ui.passwdEdit->setText("password"); + ui.accountList->setCurrentIndex(0); + ui.autoConnect->setChecked(true); + autoConnectToggled(true); + + } else { + if(!curacc.isEmpty()) { + //if(doAutoConnect) { qDebug() << "auto"; + // AccountSettings s; + // int idx = ui.accountList->findText(s.autoConnectAccount()); + // if(idx < 0) reject(); + // else { + // ui.accountList->setCurrentIndex(idx); + // doConnect(); + // } + //} else { + int idx = ui.accountList->findText(curacc); + ui.accountList->setCurrentIndex(idx); + //} + } + } +} + +void CoreConnectDlg::setAccountEditEnabled(bool en) { + ui.accountList->setEnabled(en); + ui.hostEdit->setEnabled(en && !ui.internalCore->isChecked()); + ui.userEdit->setEnabled(en); + ui.passwdEdit->setEnabled(en); + ui.port->setEnabled(en && !ui.internalCore->isChecked()); + ui.editAccount->setEnabled(en); + ui.delAccount->setEnabled(en); + ui.internalCore->setEnabled(en); + ui.rememberPasswd->setEnabled(en); + //ui.autoConnect->setEnabled(en); + ui.autoConnect->setEnabled(false); // FIXME temporär + ui.buttonBox1->button(QDialogButtonBox::Ok)->setEnabled(en && checkInputValid()); +} + +void CoreConnectDlg::accountChanged(const QString &text) { + AccountSettings s; + if(!curacc.isEmpty()) { + VarMap oldAcc; + oldAcc["User"] = ui.userEdit->text(); + oldAcc["Host"] = ui.hostEdit->text(); + oldAcc["Port"] = ui.port->value(); + oldAcc["InternalCore"] = ui.internalCore->isChecked(); + if(ui.rememberPasswd->isChecked()) oldAcc["Password"] = ui.passwdEdit->text(); + s.setValue(curacc, "AccountData", oldAcc); + } + ui.autoConnect->setChecked(false); + if(!text.isEmpty()) { // empty text: just save stuff + curacc = text; + s.setLastAccount(curacc); + VarMap newAcc = s.value(curacc, "AccountData").toMap(); + ui.userEdit->setText(newAcc["User"].toString()); + ui.hostEdit->setText(newAcc["Host"].toString()); + ui.port->setValue(newAcc["Port"].toInt()); + ui.internalCore->setChecked(newAcc["InternalCore"].toBool()); + if(newAcc.contains("Password")) { + ui.passwdEdit->setText(newAcc["Password"].toString()); + ui.rememberPasswd->setChecked(true); + } else ui.rememberPasswd->setChecked(false); + if(s.autoConnectAccount() == curacc) ui.autoConnect->setChecked(true); + } +} + +void CoreConnectDlg::autoConnectToggled(bool autoConnect) { + AccountSettings s; + if(autoConnect) s.setAutoConnectAccount(curacc); + else s.setAutoConnectAccount(""); +} + +bool CoreConnectDlg::checkInputValid() { + bool res = (ui.internalCore->isChecked() || ui.hostEdit->text().count()) && ui.userEdit->text().count(); + ui.buttonBox1->button(QDialogButtonBox::Ok)->setEnabled(res); + return res; +} + +void CoreConnectDlg::createAccount() { + QString accname = QInputDialog::getText(this, tr("Create Account"), tr("Please enter a name for the new account:")); + if(accname.isEmpty()) return; + if(ui.accountList->findText(accname) >= 0) { + QMessageBox::warning(this, tr("Account name already exists!"), tr("An account named '%1' already exists, and account names must be unique!").arg(accname)); + return; + } + VarMap defdata; + ui.accountList->addItem(accname); + ui.accountList->setCurrentIndex(ui.accountList->findText(accname)); + setAccountEditEnabled(true); +} + +void CoreConnectDlg::removeAccount() { + QString acc = ui.accountList->currentText(); + int res = QMessageBox::warning(this, tr("Delete account?"), tr("Do you really want to delete the data for the account '%1'?
" + "Note that this only affects your local account settings and will not remove " + "any data from the core.").arg(acc), + QMessageBox::Yes|QMessageBox::No, QMessageBox::No); + if(res == QMessageBox::Yes) { + AccountSettings s; + s.removeAccount(acc); + curacc = ""; + ui.accountList->removeItem(ui.accountList->findText(acc)); + if(!ui.accountList->count()) setAccountEditEnabled(false); + } +} + +bool CoreConnectDlg::willDoInternalAutoConnect() { + AccountSettings s; + if(ui.autoConnect->isChecked() && s.autoConnectAccount() == curacc && ui.internalCore->isChecked()) { + return true; + } + return false; +} + +void CoreConnectDlg::doAutoConnect() { + AccountSettings s; + if(s.autoConnectAccount() == curacc) { + doConnect(); } - */ +} + +void CoreConnectDlg::doConnect() { + accountChanged(); // save current account info + + VarMap conninfo; + ui.stackedWidget->setCurrentIndex(1); + if(ui.internalCore->isChecked()) { + ui.connectionGroupBox->setTitle(tr("Connecting to internal core")); + ui.connectionProgress->hide(); + } else { + ui.connectionGroupBox->setTitle(tr("Connecting to %1").arg(ui.hostEdit->text())); + conninfo["Host"] = ui.hostEdit->text(); + conninfo["Post"] = ui.port->value(); + } + conninfo["User"] = ui.userEdit->text(); + conninfo["Password"] = ui.passwdEdit->text(); + ui.profileLabel->hide(); ui.guiProfile->hide(); + ui.newGuiProfile->hide(); ui.alwaysUseProfile->hide(); + ui.connectionProgress->show(); + try { + Client::instance()->connectToCore(conninfo); + } catch(Exception e) { + QString msg; + //if(!e.msg().isEmpty()) msg = tr("
%1").arg(e.msg()); // FIXME throw more detailed (vulgo: any) error msg + coreConnectionError(tr("Invalid user or password. Pleasy try again.%1").arg(msg)); + //QMessageBox::warning(this, tr("Unknown account"), tr("Invalid user or password. Pleasy try again.%1").arg(msg)); + //cancelConnect(); + return; + } +} + +void CoreConnectDlg::cancelConnect() { + ui.stackedWidget->setCurrentIndex(0); } void CoreConnectDlg::setStartState() { /* @@ -49,10 +237,11 @@ void CoreConnectDlg::setStartState() { /* ui.buttonBox->button(QDialogButtonBox::Ok)->show(); ui.hostName->setEnabled(true); ui.hostPort->setEnabled(true); ui.hostName->setSelection(0, ui.hostName->text().length()); */ + ui.stackedWidget->setCurrentIndex(0); } -void CoreConnectDlg::hostEditChanged(QString txt) { - ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(txt.length()); +void CoreConnectDlg::hostEditChanged(QString /*txt*/) { + //ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(txt.length()); } void CoreConnectDlg::hostSelected() { /* @@ -78,22 +267,27 @@ void CoreConnectDlg::coreConnected() { /* VarMap initmsg; initmsg["GUIProtocol"] = GUI_PROTOCOL; // FIXME guiProxy->send(GS_CLIENT_INIT, QVariant(initmsg)); */ + ui.connectionStatus->setText(tr("Connected to core.")); + accept(); } void CoreConnectDlg::coreConnectionError(QString err) { + ui.stackedWidget->setCurrentIndex(0); + show(); // just in case we started hidden QMessageBox::warning(this, tr("Connection Error"), tr("Could not connect to Quassel Core!
\n") + err, QMessageBox::Retry); disconnect(ClientProxy::instance(), 0, this, 0); - ui.autoConnect->setChecked(false); + //ui.autoConnect->setChecked(false); setStartState(); } -void CoreConnectDlg::updateProgressBar(quint32 recv, quint32 avail) { - ui.progressBar->setMaximum(avail); - ui.progressBar->setValue(recv); +void CoreConnectDlg::updateProgressBar(uint partial, uint total) { + ui.connectionProgress->setMaximum(total); + ui.connectionProgress->setValue(partial); + //qDebug() << "progress:" << partial << total; } void CoreConnectDlg::recvCoreState(QVariant state) { - ui.progressBar->hide(); + //ui.progressBar->hide(); coreState = state; accept(); } diff --git a/src/qtgui/coreconnectdlg.h b/src/qtgui/coreconnectdlg.h index 53fc4256..056e9ab4 100644 --- a/src/qtgui/coreconnectdlg.h +++ b/src/qtgui/coreconnectdlg.h @@ -22,28 +22,46 @@ #define _CORECONNECTDLG_H #include "ui_coreconnectdlg.h" +#include "global.h" class CoreConnectDlg: public QDialog { Q_OBJECT public: - CoreConnectDlg(QWidget *); + CoreConnectDlg(QWidget *parent, bool doAutoConnect = false); QVariant getCoreState(); + bool willDoInternalAutoConnect(); + + public slots: + void doAutoConnect(); + private slots: + void createAccount(); + void removeAccount(); + void accountChanged(const QString & = ""); + void setAccountEditEnabled(bool); + void autoConnectToggled(bool); + bool checkInputValid(); void hostEditChanged(QString); void hostSelected(); + void doConnect(); void coreConnected(); void coreConnectionError(QString); - void updateProgressBar(quint32 bytes, quint32 avail); + //void coreConnectionMsg(const QString &); + //void coreConnectionProgress(uint partial, uint total); + void updateProgressBar(uint partial, uint total); void recvCoreState(QVariant); private: Ui::CoreConnectDlg ui; QVariant coreState; + void cancelConnect(); void setStartState(); + VarMap accountData; + QString curacc; }; #endif diff --git a/src/qtgui/guisettings.cpp b/src/qtgui/guisettings.cpp new file mode 100644 index 00000000..9151cb79 --- /dev/null +++ b/src/qtgui/guisettings.cpp @@ -0,0 +1,19 @@ +/*************************************************************************** + * Copyright (C) 2005-07 by The Quassel IRC Development 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ diff --git a/src/qtgui/guisettings.h b/src/qtgui/guisettings.h new file mode 100644 index 00000000..a34f57b2 --- /dev/null +++ b/src/qtgui/guisettings.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2005-07 by The Quassel IRC Development 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _GUISETTINGS_H_ +#define _GUISETTINGS_H_ + +#include "clientsettings.h" + +class GuiSettings : public ClientSettings { + Q_OBJECT + + public: + GuiSettings(); + + +}; + +class GuiProfile : public ClientSettings { + Q_OBJECT + + public: + GuiProfile(); + + static QStringList availableProfiles(); + static GuiProfile *profile(QString name); + + + +}; + +#endif diff --git a/src/qtgui/identities.cpp b/src/qtgui/identities.cpp index 31617179..b0850145 100644 --- a/src/qtgui/identities.cpp +++ b/src/qtgui/identities.cpp @@ -19,6 +19,7 @@ ***************************************************************************/ #include "identities.h" +#include "client.h" IdentitiesDlg::IdentitiesDlg(QWidget *parent, QString selected) : QDialog(parent) { ui.setupUi(this); @@ -26,7 +27,7 @@ IdentitiesDlg::IdentitiesDlg(QWidget *parent, QString selected) : QDialog(parent connect(ui.enableAutoAway, SIGNAL(stateChanged(int)), this, SLOT(autoAwayChecked())); - identities = Global::data("Identities").toMap(); + identities = Client::retrieveSessionData("Identities").toMap(); foreach(QString name, identities.keys()) { nameMapping[name] = name; } @@ -236,9 +237,9 @@ void IdentitiesDlg::accept() { updateIdentity(getCurIdentity()); QString result = checkValidity(); if(result.length() == 0) { - Global::putData("Identities", identities); + Client::storeSessionData("Identities", identities); // We have to care about renamed identities and update the network list appropriately... - VarMap networks = Global::data("Networks").toMap(); + VarMap networks = Client::retrieveSessionData("Networks").toMap(); foreach(QString netname, networks.keys()) { VarMap net = networks[netname].toMap(); if(nameMapping.contains(net["Identity"].toString())) { @@ -246,7 +247,7 @@ void IdentitiesDlg::accept() { } else net["Identity"] = "Default"; networks[netname] = net; } - Global::putData("Networks", networks); + Client::storeSessionData("Networks", networks); QDialog::accept(); } else { QMessageBox::warning(this, tr("Invalid Identity!"), diff --git a/src/qtgui/mainwin.cpp b/src/qtgui/mainwin.cpp index 6b89e20e..8398042e 100644 --- a/src/qtgui/mainwin.cpp +++ b/src/qtgui/mainwin.cpp @@ -46,12 +46,12 @@ void MainWin::init() { show(); - VarMap connInfo; - connInfo["User"] = "Default"; - connInfo["Password"] = "password"; - connectToCore(connInfo); + //VarMap connInfo; + //connInfo["User"] = "Default"; + //connInfo["Password"] = "password"; + //connectToCore(connInfo); - statusBar()->showMessage(tr("Ready.")); + statusBar()->showMessage(tr("Not connected to core.")); systray = new QSystemTrayIcon(this); systray->setIcon(QIcon(":/qirc-icon.png")); systray->show(); @@ -71,10 +71,14 @@ void MainWin::init() { if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray()); s.endGroup(); - s.beginGroup("Buffers"); - QString net = s.value("CurrentNetwork", "").toString(); - QString buf = s.value("CurrentBuffer", "").toString(); - s.endGroup(); + //s.beginGroup("Buffers"); + //QString net = s.value("CurrentNetwork", "").toString(); + //QString buf = s.value("CurrentBuffer", "").toString(); + //s.endGroup(); + + disconnectedFromCore(); // Disable menus and stuff + showCoreConnectionDlg(true); // autoconnect if appropriate + //ui.actionConnectCore->activate(QAction::Trigger); } MainWin::~MainWin() { @@ -95,6 +99,8 @@ void MainWin::setupSettingsDlg() { */ void MainWin::setupMenus() { + connect(ui.actionConnectCore, SIGNAL(triggered()), this, SLOT(showCoreConnectionDlg())); + connect(ui.actionDisconnectCore, SIGNAL(triggered()), Client::instance(), SLOT(disconnectFromCore())); connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList())); connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities())); connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg())); @@ -109,12 +115,12 @@ void MainWin::setupViews() { BufferTreeModel *model = Client::bufferModel(); connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *))); - + addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QStringList()); - addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QStringList()); - addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QStringList()); - addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QStringList()); - addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QStringList()); + //addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QStringList()); + //addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QStringList()); + //addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QStringList()); + //addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QStringList()); ui.menuViews->addSeparator(); } @@ -140,16 +146,43 @@ void MainWin::connectedToCore() { foreach(BufferId id, Client::allBufferIds()) { emit requestBacklog(id, 100, -1); } + + ui.menuViews->setEnabled(true); + ui.menuCore->setEnabled(true); + ui.actionDisconnectCore->setEnabled(false); // FIXME + ui.actionNetworkList->setEnabled(true); + ui.bufferWidget->show(); } void MainWin::disconnectedFromCore() { - + ui.menuViews->setEnabled(false); + ui.menuCore->setEnabled(false); + ui.actionDisconnectCore->setEnabled(false); + ui.actionNetworkList->setEnabled(false); + ui.bufferWidget->hide(); + ui.actionConnectCore->setEnabled(false); // FIXME + qDebug() << "mainwin disconnected"; } AbstractUiMsg *MainWin::layoutMsg(const Message &msg) { return new ChatLine(msg); } +void MainWin::showCoreConnectionDlg(bool autoConnect) { + coreConnectDlg = new CoreConnectDlg(this, autoConnect); + connect(coreConnectDlg, SIGNAL(finished(int)), this, SLOT(coreConnectionDlgFinished(int))); + coreConnectDlg->setModal(true); + if(!autoConnect || !coreConnectDlg->willDoInternalAutoConnect()) + coreConnectDlg->show(); // avoid flicker and show dlg only if we do remote connect, which needs a progress bar + if(autoConnect) coreConnectDlg->doAutoConnect(); +} + +void MainWin::coreConnectionDlgFinished(int /*code*/) { + + delete coreConnectDlg; +} + + void MainWin::showServerList() { // if(!serverListDlg) { // serverListDlg = new ServerListDlg(this); diff --git a/src/qtgui/mainwin.h b/src/qtgui/mainwin.h index 24e6ccb8..60ffc184 100644 --- a/src/qtgui/mainwin.h +++ b/src/qtgui/mainwin.h @@ -57,6 +57,8 @@ class MainWin : public QMainWindow { void showServerList(); void showSettingsDlg(); + void showCoreConnectionDlg(bool autoConnect = false); + void coreConnectionDlgFinished(int result); void showBuffer(BufferId); void showBuffer(Buffer *); @@ -86,6 +88,7 @@ class MainWin : public QMainWindow { SettingsDlg *settingsDlg; uint currentBuffer; + QString currentProfile; QList netViews; diff --git a/src/qtgui/serverlist.cpp b/src/qtgui/serverlist.cpp index 9b36fcc3..b1b68bac 100644 --- a/src/qtgui/serverlist.cpp +++ b/src/qtgui/serverlist.cpp @@ -20,6 +20,7 @@ #include "serverlist.h" #include "identities.h" +#include "client.h" #include "clientproxy.h" /* NOTE: This dialog holds not only the server list, but also the identities. @@ -36,15 +37,16 @@ ServerListDlg::ServerListDlg(QWidget *parent) : QDialog(parent) { updateNetworkTree(); connect(ui.networkTree, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons())); + connect(Client::instance(), SIGNAL(sessionDataChanged(const QString &)), this, SLOT(updateNetworkTree())); settings.endGroup(); // check if we already have a valid identity - if(!Global::data("Identities", VarMap()).toMap().contains("Default")) editIdentities(true); + //if(!Global::data("Identities", VarMap()).toMap().contains("Default")) editIdentities(true); // FIXME connect(this, SIGNAL(requestConnect(QStringList)), ClientProxy::instance(), SLOT(gsRequestConnect(QStringList))); // Autoconnect QStringList list; - VarMap networks = Global::data("Networks").toMap(); + VarMap networks = Client::retrieveSessionData("Networks").toMap(); foreach(QString net, networks.keys()) { if(networks[net].toMap()["AutoConnect"].toBool()) { list << net; @@ -58,7 +60,7 @@ ServerListDlg::~ServerListDlg() { } void ServerListDlg::updateNetworkTree() { - VarMap networks = Global::data("Networks").toMap(); + VarMap networks = Client::retrieveSessionData("Networks").toMap(); //QStringList headers; //headers << "Network" << "Autoconnect"; ui.networkTree->clear(); @@ -92,7 +94,7 @@ void ServerListDlg::updateNetworkTree() { //item->setCheckState(1, Qt::Unchecked); } ui.networkTree->sortItems(0, Qt::AscendingOrder); - + updateButtons(); } void ServerListDlg::updateButtons() { @@ -110,23 +112,23 @@ bool ServerListDlg::showOnStartup() { void ServerListDlg::on_addButton_clicked() { NetworkEditDlg dlg(this, VarMap()); if(dlg.exec() == QDialog::Accepted) { - VarMap networks = Global::data("Networks").toMap(); + VarMap networks = Client::retrieveSessionData("Networks").toMap(); VarMap net = dlg.getNetwork(); networks[net["Name"].toString()] = net; - Global::putData("Networks", networks); + Client::storeSessionData("Networks", networks); updateNetworkTree(); } } void ServerListDlg::on_editButton_clicked() { QString curnet = ui.networkTree->currentItem()->text(0); - VarMap networks = Global::data("Networks").toMap(); + VarMap networks = Client::retrieveSessionData("Networks").toMap(); NetworkEditDlg dlg(this, networks[curnet].toMap()); if(dlg.exec() == QDialog::Accepted) { VarMap net = dlg.getNetwork(); networks.remove(curnet); networks[net["Name"].toString()] = net; - Global::putData("Networks", networks); + Client::storeSessionData("Networks", networks); updateNetworkTree(); } } @@ -134,12 +136,12 @@ void ServerListDlg::on_editButton_clicked() { void ServerListDlg::on_deleteButton_clicked() { if(QMessageBox::warning(this, tr("Remove Network?"), tr("Are you sure you want to delete the selected network(s)?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - VarMap networks = Global::data("Networks").toMap(); + VarMap networks = Client::retrieveSessionData("Networks").toMap(); QList sel = ui.networkTree->selectedItems(); foreach(QTreeWidgetItem *item, sel) { networks.remove(item->text(0)); } - Global::putData("Networks", networks); + Client::storeSessionData("Networks", networks); updateNetworkTree(); } } @@ -183,14 +185,14 @@ NetworkEditDlg::NetworkEditDlg(QWidget *parent, VarMap _network) : QDialog(paren connect(ui.serverList, SIGNAL(itemSelectionChanged()), this, SLOT(updateServerButtons())); - VarMap identities = Global::data("Identities").toMap(); + VarMap identities = Client::retrieveSessionData("Identities").toMap(); ui.identityList->addItem(tr("Default Identity")); foreach(QString id, identities.keys()) { if(id != "Default") ui.identityList->addItem(id); } QStringList groups; groups << ""; - VarMap nets = Global::data("Networks").toMap(); + VarMap nets = Client::retrieveSessionData("Networks").toMap(); foreach(QString net, nets.keys()) { QString gr = nets[net].toMap()["Group"].toString(); if(!groups.contains(gr) && !gr.isEmpty()) { @@ -273,7 +275,7 @@ void NetworkEditDlg::accept() { QString NetworkEditDlg::checkValidity() { QString r; - VarMap nets = Global::data("Networks").toMap(); + VarMap nets = Client::retrieveSessionData("Networks").toMap(); if(ui.networkName->text() != oldName && nets.keys().contains(ui.networkName->text())) { r += tr(" Network name already exists."); } @@ -338,7 +340,7 @@ void NetworkEditDlg::on_editIdentities_clicked() { else id = "Default"; IdentitiesDlg dlg(this, id); if(dlg.exec() == QDialog::Accepted) { - VarMap identities = Global::data("Identities").toMap(); + VarMap identities = Client::retrieveSessionData("Identities").toMap(); ui.identityList->clear(); ui.identityList->addItem(tr("Default Identity")); foreach(QString i, identities.keys()) { diff --git a/src/qtgui/serverlist.h b/src/qtgui/serverlist.h index 706e0231..aa4c825b 100644 --- a/src/qtgui/serverlist.h +++ b/src/qtgui/serverlist.h @@ -50,6 +50,7 @@ class ServerListDlg : public QDialog { private slots: void updateButtons(); + void updateNetworkTree(); void on_showOnStartup_stateChanged(int); void on_addButton_clicked(); void on_editButton_clicked(); @@ -58,7 +59,6 @@ class ServerListDlg : public QDialog { private: Ui::ServerListDlg ui; - void updateNetworkTree(); //VarMap networks; //VarMap identities; <-- this is now stored in global }; diff --git a/src/qtgui/ui/coreconnectdlg.ui b/src/qtgui/ui/coreconnectdlg.ui index 1311565b..4610cea3 100644 --- a/src/qtgui/ui/coreconnectdlg.ui +++ b/src/qtgui/ui/coreconnectdlg.ui @@ -5,8 +5,8 @@ 0 0 - 498 - 270 + 484 + 215 @@ -25,178 +25,366 @@ false + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + - - - Core Connection Settings - - - - - - - - - - - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Host:</span></p></body></html> - - - - - - - quassel.mindpool.net:4242 - - - - - - - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">User:</span></p></body></html> - - - - - - - quasseluser - - - - - - - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Password:</span></p></body></html> - - - - - - - QLineEdit::Password - - - - - - - Edit... - - - - - - - New... - - - - - - - Remember - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - + + 0 - - Qt::Horizontal - + + + + + + Account Settings + + + + + + Account: + + + + + + + false + + + QComboBox::InsertAlphabetically + + + + + + + ... + + + :/default/edit.png + + + + + + + ... + + + :/default/edit_add.png + + + + + + + ... + + + :/default/edit_remove.png + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + Host: + + + + + + + + + + Use internal + + + false + + + + + + + Port: + + + + + + + 1024 + + + 65535 + + + 4242 + + + + + + + Qt::Horizontal + + + + 211 + 20 + + + + + + + + User: + + + + + + + + + + Password: + + + + + + + QLineEdit::Password + + + + + + + Remember + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Always use this account + + + false + + + + + + + Qt::Horizontal + + + + 101 + 31 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + + + + + + + + + + + Connecting to... + + + + + + Connecting... + + + + + + + 0 + + + Qt::Horizontal + + + + + + + + + GUI Profile: + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + New... + + + + + + + + + Always use this profile + + + + + + + + + + Qt::Vertical + + + + 20 + 31 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QDialogButtonBox::Abort|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + + + + + - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Connect automatically - - - true - - - - - - - Qt::Horizontal - - - - 101 - 31 - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok - - - - - - - buttonBox + buttonBox1 rejected() CoreConnectDlg reject() diff --git a/src/qtgui/ui/mainwin.ui b/src/qtgui/ui/mainwin.ui index 82c7e6e9..9a35511e 100644 --- a/src/qtgui/ui/mainwin.ui +++ b/src/qtgui/ui/mainwin.ui @@ -46,20 +46,14 @@ 0 0 800 - 28 + 32 Connection - - - Connect to Core - - - - + @@ -222,10 +216,21 @@ + + false + Disconnect from Core + + + false + + + Connect to Core... + + -- 2.20.1