* Mostly finished dialogs for network settings, identities, network list.
* Network settings are also already mostly honored by our TelnetDeluxe the core still is.
This means that the connect button works, we will connect to the first server we defined
for this network, and we can also autoconnect. We still don't use identities yet, i.e.
the nick is still hardcoded.
* Started implementing buffer management in the core. Cleaned up the framework, the core now
creates server objects for all networks it connects to, and the signals we use to connect
everything have a format that allows us to use network and buffer names.
* Threw out a lot of the temporary dirty-hack-stuff we used for testing so far. Most of the
code we have now is actually clean and there to stay, although of course enough is still to
be added to it :)
INCLUDE_DIRECTORIES(${SDIRS})
# We need Qt4 support.
-SET(QT_MIN_VERSION "4.2.0")
+SET(QT_MIN_VERSION "4.2.0")
FIND_PACKAGE(Qt4 REQUIRED)
# Set needed libraries
-# Doxyfile 1.4.7
+# Doxyfile 1.4.1-KDevelop
#---------------------------------------------------------------------------
# Project related configuration options
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = YES
INHERIT_DOCS = YES
-SEPARATE_MEMBER_PAGES = NO
+DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 8
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
-BUILTIN_STL_SUPPORT = NO
-DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
#---------------------------------------------------------------------------
# Build related configuration options
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
-REFERENCES_LINK_SOURCE = YES
-USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = NO
MACRO_EXPANSION = NO
-EXPAND_ONLY_PREDEF = YES
-SEARCH_INCLUDES = YES
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = NO
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
-SKIP_FUNCTION_MACROS = YES
+SKIP_FUNCTION_MACROS = NO
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
-CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
main/global.cpp
main/global.h
gui/channelwidget-old.ui
+gui/identities.cpp
+gui/identities.h
+network/buffer.cpp
+network/buffer.h
Core::Core() {
if(core) qFatal("Trying to instantiate more than one Core object!");
- connect(coreProxy, SIGNAL(gsRequestConnect(QString, quint16)), this, SLOT(connectToIrc(QString, quint16)));
+ connect(coreProxy, SIGNAL(gsRequestConnect(QStringList)), this, SLOT(connectToIrc(QStringList)));
connect(coreProxy, SIGNAL(gsUserInput(QString)), this, SLOT(inputLine(QString)));
+ connect(this, SIGNAL(sendMessage(QString, QString, QString)), coreProxy, SLOT(csSendMessage(QString, QString, QString)));
+ connect(this, SIGNAL(sendStatusMsg(QString, QString)), coreProxy, SLOT(csSendStatusMsg(QString, QString)));
- connect(&server, SIGNAL(recvLine(QString)), coreProxy, SLOT(csCoreMessage(QString)));
-
- // Read global settings from config file
+ // Read global settings from config file
QSettings s;
s.beginGroup("Global");
QString key;
connect(global, SIGNAL(dataUpdatedRemotely(QString)), SLOT(globalDataUpdated(QString)));
connect(global, SIGNAL(dataPutLocally(QString)), SLOT(globalDataUpdated(QString)));
- server.start();
}
-void Core::connectToIrc(const QString &h, quint16 port) {
- if(server.isConnected()) return;
- qDebug() << "Core: Connecting to " << h << ":" << port;
- server.connectToIrc(h, port);
+void Core::globalDataUpdated(QString key) {
+ QVariant data = global->getData(key);
+ QSettings s;
+ s.setValue(QString("Global/")+key, data);
}
+// temp
void Core::inputLine(QString s) {
- server.putRawLine(s);
+ emit msgFromGUI("", "", s);
}
-void Core::globalDataUpdated(QString key) {
- QVariant data = global->getData(key);
- QSettings s;
- s.setValue(QString("Global/")+key, data);
+void Core::connectToIrc(QStringList networks) {
+ foreach(QString net, networks) {
+ if(servers.contains(net)) {
+
+ } else {
+ Server *server = new Server(net);
+ connect(this, SIGNAL(connectToIrc(QString)), server, SLOT(connectToIrc(QString)));
+ connect(this, SIGNAL(disconnectFromIrc(QString)), server, SLOT(disconnectFromIrc(QString)));
+ connect(this, SIGNAL(msgFromGUI(QString, QString, QString)), server, SLOT(userInput(QString, QString, QString)));
+ connect(server, SIGNAL(sendMessage(QString, QString)), this, SLOT(recvMessageFromServer(QString, QString)));
+ connect(server, SIGNAL(sendStatusMsg(QString)), this, SLOT(recvStatusMsgFromServer(QString)));
+ // add error handling
+
+ server->start();
+ servers[net] = server;
+ }
+ emit connectToIrc(net);
+ }
+}
+
+void Core::recvMessageFromServer(QString buf, QString msg) {
+ Q_ASSERT(sender());
+ QString net = qobject_cast<Server*>(sender())->getNetwork();
+ emit sendMessage(net, buf, msg);
+}
+
+void Core::recvStatusMsgFromServer(QString msg) {
+ Q_ASSERT(sender());
+ QString net = qobject_cast<Server*>(sender())->getNetwork();
+ qDebug() << "sent status:"<<msg;
+ emit sendStatusMsg(net, msg);
}
+
Core *core = 0;
public:
Core();
- void init();
- VarMap loadNetworks();
- void storeNetworks(VarMap);
- VarMap loadIdentities();
- void storeIdentities(VarMap);
+ //~Core();
public slots:
void inputLine(QString); // temp
- void connectToIrc(const QString &, quint16 port = 6667);
+ void connectToIrc(QStringList);
signals:
void outputLine(const QString &); // temp
+ void msgFromGUI(QString network, QString channel, QString message);
+ void sendMessage(QString network, QString channel, QString message);
+ void sendStatusMsg(QString, QString);
+
+ void connectToIrc(QString net);
+ void disconnectFromIrc(QString net);
private slots:
void globalDataUpdated(QString);
+ void recvStatusMsgFromServer(QString msg);
+ void recvMessageFromServer(QString buffer, QString msg);
private:
- //void run();
-
- Server server; // temp
+ QHash<QString, Server *> servers;
};
switch(sig) {
case GS_UPDATE_GLOBAL_DATA: emit gsPutGlobalData(arg1.toString(), arg2); break;
case GS_USER_INPUT: emit gsUserInput(arg1.toString()); break;
- case GS_REQUEST_CONNECT: emit gsRequestConnect(arg1.toString(), arg2.toUInt()); break;
+ case GS_REQUEST_CONNECT: emit gsRequestConnect(arg1.toStringList()); break;
default: qWarning() << "Unknown signal in CoreProxy::recv: " << sig;
}
}
CoreProxy();
public slots:
- inline void csCoreMessage(QString s) { send(CS_CORE_MESSAGE, s); }
- inline void csUpdateGlobalData(QString key, QVariant data) { send(CS_UPDATE_GLOBAL_DATA, key, data); }
+ inline void csUpdateGlobalData(QString key, QVariant data) { send(CS_UPDATE_GLOBAL_DATA, key, data); }
+ inline void csSendMessage(QString net, QString chan, QString msg) { send(CS_SEND_MESSAGE, net, chan, msg); }
+ inline void csSendStatusMsg(QString net, QString msg) { send(CS_SEND_STATUS_MSG, net, msg); }
signals:
void gsPutGlobalData(QString, QVariant);
void gsUserInput(QString);
- void gsRequestConnect(QString, quint16);
+ void gsRequestConnect(QStringList networks);
private:
void send(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
-SET(gui_SRCS channelwidget.cpp mainwin.cpp serverlist.cpp coreconnectdlg.cpp guiproxy.cpp)
+SET(gui_SRCS channelwidget.cpp mainwin.cpp serverlist.cpp identities.cpp coreconnectdlg.cpp guiproxy.cpp)
SET(gui_HDRS )
-SET(gui_MOCS channelwidget.h mainwin.h serverlist.h coreconnectdlg.h guiproxy.h)
-SET(gui_UICS channelwidget.ui identitiesdlg.ui identitieseditdlg.ui networkeditdlg.ui nickeditdlg.ui serverlistdlg.ui coreconnectdlg.ui)
+SET(gui_MOCS channelwidget.h mainwin.h serverlist.h identities.h coreconnectdlg.h guiproxy.h)
+SET(gui_UICS channelwidget.ui identitiesdlg.ui identitieseditdlg.ui networkeditdlg.ui nickeditdlg.ui serverlistdlg.ui servereditdlg.ui coreconnectdlg.ui)
QT4_WRAP_UI(_UIC ${gui_UICS})
QT4_WRAP_CPP(_MOC ${gui_MOCS})
ChannelWidget::ChannelWidget(QWidget *parent) : QWidget(parent) {
ui.setupUi(this);
//ui.inputEdit->grabKeyboard();
- ui.inputEdit->setFocus();
/* //ui.splitter->
ui.textBrowser->setHtml("[17:21] <em>--> Dante has joined #quassel (~hurz@p1af2242.dip.t-dialin.net)</em><br>"
//connect(this, SIGNAL(inputLine( const QString& )), &core, SLOT(inputLine( const QString& )));
connect(this, SIGNAL(inputLine(QString)), guiProxy, SLOT(gsUserInput(QString)));
- connect(this, SIGNAL(requestConnect(QString, quint16)), guiProxy, SLOT(gsRequestConnect(QString, quint16)));
- connect(guiProxy, SIGNAL(csCoreMessage(QString)), this, SLOT(lineReceived(QString)));
-
- //emit requestConnect("irc.scortum.moep.net", 6668);
- //emit requestConnect("irc.quakenet.org", 6668);
+ connect(guiProxy, SIGNAL(csSendMessage(QString, QString, QString)), this, SLOT(msgReceived(QString, QString, QString)));
+ connect(guiProxy, SIGNAL(csSendStatusMsg(QString, QString)), this, SLOT(statusMsgReceived(QString, QString)));
+ ui.inputEdit->setFocus();
}
void ChannelWidget::enterPressed() {
- QString l = ui.inputEdit->text();
- if(l == "/c") emit requestConnect("irc.quakenet.org", 6668);
- else emit inputLine(ui.inputEdit->text());
+ emit inputLine(ui.inputEdit->text());
ui.inputEdit->clear();
}
-void ChannelWidget::lineReceived(QString s) {
- ui.chatWidget->insertPlainText(s + "\n");
+void ChannelWidget::msgReceived(QString net, QString chan, QString msg) {
+ ui.chatWidget->insertPlainText(QString("[%1:%2] %3\n").arg(net).arg(chan).arg(msg));
ui.chatWidget->ensureCursorVisible();
}
+
+void ChannelWidget::statusMsgReceived(QString net, QString msg) {
+ msgReceived(net, "STATUS", msg);
+}
signals:
void requestConnect(QString, quint16);
void inputLine(QString);
-
+
private slots:
void enterPressed();
- void lineReceived(QString);
+ void msgReceived(QString, QString, QString);
+ void statusMsgReceived(QString net, QString msg);
private:
Ui::ChannelWidget ui;
case CS_CORE_STATE: emit csCoreState(arg1); break;
case CS_UPDATE_GLOBAL_DATA: emit csUpdateGlobalData(arg1.toString(), arg2); break;
//case CS_GLOBAL_DATA_CHANGED: emit csGlobalDataChanged(arg1.toString()); break;
- case CS_CORE_MESSAGE: emit csCoreMessage(arg1.toString()); break;
+ case CS_SEND_MESSAGE: emit csSendMessage(arg1.toString(), arg2.toString(), arg3.toString()); break;
+ case CS_SEND_STATUS_MSG: emit csSendStatusMsg(arg1.toString(), arg2.toString()); break;
+
default: qWarning() << "Unknown signal in GUIProxy::recv: " << sig;
}
}
#include <QObject>
#include <QVariant>
#include <QTcpSocket>
+#include <QStringList>
/** This class is the GUI side of the proxy. The GUI connects its signals and slots to it,
* and the calls are marshalled and sent to (or received and unmarshalled from) the CoreProxy.
public slots:
inline void gsUserInput(QString s) { send(GS_USER_INPUT, s); }
- inline void gsRequestConnect(QString host, quint16 port) { send(GS_REQUEST_CONNECT, host, port); }
- //inline void gsPutQuasselData(QString key, QVariant data) { send(GS_PUT_QUASSEL_DATA, key, data); }
+ inline void gsRequestConnect(QStringList networks) { send(GS_REQUEST_CONNECT, networks); }
void connectToCore(QString host, quint16 port);
void disconnectFromCore();
signals:
void csCoreState(QVariant);
- void csCoreMessage(QString);
+ void csSendMessage(QString, QString, QString);
+ void csSendStatusMsg(QString, QString);
void csUpdateGlobalData(QString key, QVariant data);
void csGlobalDataChanged(QString key);
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005/06 by The Quassel 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 "identities.h"
+
+IdentitiesDlg::IdentitiesDlg(QWidget *parent, QString selected) : QDialog(parent) {
+ ui.setupUi(this);
+ connect(global, SIGNAL(dataUpdatedRemotely(QString)), this, SLOT(globalDataUpdated(QString)));
+
+ connect(ui.enableAutoAway, SIGNAL(stateChanged(int)), this, SLOT(autoAwayChecked()));
+
+ identities = global->getData("Identities").toMap();
+ foreach(QString name, identities.keys()) {
+ nameMapping[name] = name;
+ }
+ if(identities.size() == 0) {
+ VarMap id = createDefaultIdentity();
+ id["IdName"] = "Default";
+ identities["Default"] = id;
+ nameMapping["Default"] = "Default";
+ }
+ ui.identityList->addItem(tr("Default Identity"));
+
+ foreach(QString id, identities.keys()) {
+ if(id != "Default") ui.identityList->addItem(id);
+ if(id == selected) ui.identityList->setCurrentIndex(ui.identityList->count()-1);
+ }
+ updateWidgets();
+ lastIdentity = getCurIdentity();
+ connect(ui.identityList, SIGNAL(activated(QString)), this, SLOT(identityChanged(QString)));
+ connect(ui.editIdentitiesButton, SIGNAL(clicked()), this, SLOT(editIdentities()));
+ connect(ui.nickList, SIGNAL(itemSelectionChanged()), this, SLOT(nickSelectionChanged()));
+ connect(ui.addNickButton, SIGNAL(clicked()), this, SLOT(addNick()));
+ connect(ui.editNickButton, SIGNAL(clicked()), this, SLOT(editNick()));
+ connect(ui.delNickButton, SIGNAL(clicked()), this, SLOT(delNick()));
+ connect(ui.upNickButton, SIGNAL(clicked()), this, SLOT(upNick()));
+ connect(ui.downNickButton, SIGNAL(clicked()), this, SLOT(downNick()));
+}
+
+/* this needs more work! mapping? */
+void IdentitiesDlg::globalDataUpdated(QString key) {
+ if(key == "Identities") {
+ if(QMessageBox::warning(this, tr("Data changed remotely!"), tr("<b>Some other GUI client changed the identities data!</b><br>"
+ "Apply updated settings, losing all changes done locally?"),
+ QMessageBox::Apply|QMessageBox::Discard) == QMessageBox::Apply) {
+ //identities = global->getData(key).toMap();
+ //updateWidgets();
+ reject();
+ }
+ }
+}
+
+VarMap IdentitiesDlg::createDefaultIdentity() {
+ VarMap id;
+ id["RealName"] = "foo";
+ id["Ident"] = "";
+ id["NickList"] = QStringList();
+ id["enableAwayNick"] = false;
+ id["AwayNick"] = "";
+ id["enableAwayReason"] = false;
+ id["AwayReason"] = "";
+ id["enableReturnMessage"] = false;
+ id["ReturnMessage"] = "";
+ id["enableAutoAway"] = false;
+ id["AutoAwayTime"] = 10;
+ id["enableAutoAwayReason"] = false;
+ id["AutoAwayReason"] = "";
+ id["enableAutoAwayReturn"] = false;
+ id["AutoAwayReturn"] = "";
+ id["PartReason"] = "Quasseling elsewhere.";
+ id["QuitReason"] = "Every Quassel comes to its end.";
+ id["KickReason"] = "No more quasseling for you!";
+
+ return id;
+}
+
+QString IdentitiesDlg::getCurIdentity() {
+ if(ui.identityList->currentIndex() == 0) return "Default";
+ return ui.identityList->currentText();
+}
+
+void IdentitiesDlg::updateWidgets() {
+ VarMap id = identities[getCurIdentity()].toMap();
+ ui.realNameEdit->setText(id["RealName"].toString());
+ ui.identEdit->setText(id["Ident"].toString());
+ ui.nickList->clear();
+ ui.nickList->addItems(id["NickList"].toStringList());
+ if(ui.nickList->count()>0) ui.nickList->setCurrentRow(0);
+ ui.enableAwayNick->setChecked(id["enableAwayNick"].toBool());
+ ui.awayNickEdit->setText(id["AwayNick"].toString());
+ ui.awayNickEdit->setEnabled(ui.enableAwayNick->isChecked());
+ ui.enableAwayReason->setChecked(id["enableAwayReason"].toBool());
+ ui.awayReasonEdit->setText(id["AwayReason"].toString());
+ ui.awayReasonEdit->setEnabled(ui.enableAwayReason->isChecked());
+ ui.enableReturnMessage->setChecked(id["enableReturnMessage"].toBool());
+ ui.returnMessageEdit->setText(id["ReturnMessage"].toString());
+ ui.returnMessageEdit->setEnabled(ui.enableReturnMessage->isChecked());
+ ui.enableAutoAway->setChecked(id["enableAutoAway"].toBool());
+ ui.autoAwayTime->setValue(id["AutoAwayTime"].toInt());
+ ui.enableAutoAwayReason->setChecked(id["enableAutoAwayReason"].toBool());
+ ui.autoAwayReasonEdit->setText(id["AutoAwayReason"].toString());
+ ui.enableAutoAwayReturn->setChecked(id["enableAutoAwayReturn"].toBool());
+ ui.autoAwayReturnEdit->setText(id["AutoAwayReturn"].toString());
+ ui.partReasonEdit->setText(id["PartReason"].toString());
+ ui.kickReasonEdit->setText(id["KickReason"].toString());
+ ui.quitReasonEdit->setText(id["QuitReason"].toString());
+ // set enabled states correctly
+ autoAwayChecked();
+ nickSelectionChanged();
+}
+
+void IdentitiesDlg::updateIdentity(QString idName) {
+ VarMap id;
+ id["RealName"] = ui.realNameEdit->text();
+ id["Ident"] = ui.identEdit->text();
+ QStringList nicks;
+ for(int i = 0; i < ui.nickList->count(); i++) nicks << ui.nickList->item(i)->text();
+ id["NickList"] = nicks;
+ id["enableAwayNick"] = ui.enableAwayNick->isChecked();
+ id["AwayNick"] = ui.awayNickEdit->text();
+ id["enableAwayReason"] = ui.enableAwayReason->isChecked();
+ id["AwayReason"] = ui.awayReasonEdit->text();
+ id["enableReturnMessage"] = ui.enableReturnMessage->isChecked();
+ id["ReturnMessage"] = ui.returnMessageEdit->text();
+ id["enableAutoAway"] = ui.enableAutoAway->isChecked();
+ id["AutoAwayTime"] = ui.autoAwayTime->value();
+ id["enableAutoAwayReason"] = ui.enableAutoAwayReason->isChecked();
+ id["AutoAwayReason"] = ui.autoAwayReasonEdit->text();
+ id["enableAutoAwayReturn"] = ui.enableAutoAwayReturn->isChecked();
+ id["AutoAwayReturn"] = ui.autoAwayReturnEdit->text();
+ id["PartReason"] = ui.partReasonEdit->text();
+ id["KickReason"] = ui.kickReasonEdit->text();
+ id["QuitReason"] = ui.quitReasonEdit->text();
+
+ id["IdName"] = idName;
+ identities[idName] = id;
+}
+
+void IdentitiesDlg::identityChanged(QString) {
+ updateIdentity(lastIdentity);
+ lastIdentity = getCurIdentity();
+ updateWidgets();
+}
+
+void IdentitiesDlg::autoAwayChecked() {
+ if(ui.enableAutoAway->isChecked()) {
+ ui.autoAwayLabel_1->setEnabled(1);
+ ui.autoAwayLabel_2->setEnabled(1);
+ ui.autoAwayTime->setEnabled(1);
+ ui.enableAutoAwayReason->setEnabled(1);
+ ui.enableAutoAwayReturn->setEnabled(1);
+ ui.autoAwayReasonEdit->setEnabled(ui.enableAutoAwayReason->isChecked());
+ ui.autoAwayReturnEdit->setEnabled(ui.enableAutoAwayReturn->isChecked());
+ } else {
+ ui.autoAwayLabel_1->setEnabled(0);
+ ui.autoAwayLabel_2->setEnabled(0);
+ ui.autoAwayTime->setEnabled(0);
+ ui.enableAutoAwayReason->setEnabled(0);
+ ui.enableAutoAwayReturn->setEnabled(0);
+ ui.autoAwayReasonEdit->setEnabled(0);
+ ui.autoAwayReturnEdit->setEnabled(0);
+ }
+}
+
+void IdentitiesDlg::nickSelectionChanged() {
+ Q_ASSERT(ui.nickList->selectedItems().size() <= 1);
+ int curidx;
+ if(ui.nickList->selectedItems().isEmpty()) curidx = -1;
+ else curidx = ui.nickList->row(ui.nickList->selectedItems()[0]);
+ ui.editNickButton->setEnabled(curidx >= 0);
+ ui.delNickButton->setEnabled(curidx >= 0);
+ ui.upNickButton->setEnabled(curidx > 0);
+ ui.downNickButton->setEnabled(curidx >= 0 && curidx < ui.nickList->count() - 1);
+}
+
+void IdentitiesDlg::addNick() {
+ NickEditDlg dlg(this);
+ if(dlg.exec() == QDialog::Accepted) {
+ QListWidgetItem *item = new QListWidgetItem(ui.nickList);
+ item->setText(dlg.getNick());
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ ui.nickList->setCurrentItem(item);
+ nickSelectionChanged();
+ }
+}
+
+void IdentitiesDlg::editNick() {
+ NickEditDlg dlg(this, ui.nickList->currentItem()->text());
+ if(dlg.exec() == QDialog::Accepted) {
+ ui.nickList->currentItem()->setText(dlg.getNick());
+ }
+}
+
+void IdentitiesDlg::delNick() {
+ int row = ui.nickList->currentRow();
+ delete ui.nickList->takeItem(row);
+ if(row <= ui.nickList->count() - 1) ui.nickList->setCurrentRow(row);
+ else if(row > 0) ui.nickList->setCurrentRow(ui.nickList->count()-1);
+ nickSelectionChanged();
+}
+
+void IdentitiesDlg::upNick() {
+ int row = ui.nickList->currentRow();
+ QListWidgetItem *item = ui.nickList->takeItem(row);
+ ui.nickList->insertItem(row-1, item);
+ ui.nickList->setCurrentRow(row-1);
+ nickSelectionChanged();
+}
+
+void IdentitiesDlg::downNick() {
+ int row = ui.nickList->currentRow();
+ QListWidgetItem *item = ui.nickList->takeItem(row);
+ ui.nickList->insertItem(row+1, item);
+ ui.nickList->setCurrentRow(row+1);
+ nickSelectionChanged();
+}
+
+void IdentitiesDlg::accept() {
+ updateIdentity(getCurIdentity());
+ QString result = checkValidity();
+ if(result.length() == 0) {
+ global->putData("Identities", identities);
+ // We have to care about renamed identities and update the network list appropriately...
+ VarMap networks = global->getData("Networks").toMap();
+ foreach(QString netname, networks.keys()) {
+ VarMap net = networks[netname].toMap();
+ if(nameMapping.contains(net["Identity"].toString())) {
+ net["Identity"] = nameMapping[net["Identity"].toString()];
+ } else net["Identity"] = "Default";
+ networks[netname] = net;
+ }
+ global->putData("Networks", networks);
+ QDialog::accept();
+ } else {
+ QMessageBox::warning(this, tr("Invalid Identity!"),
+ tr("One or more of your identities do not contain all necessary information:\n\n%1\n"
+ "Please fill in any missing information.").arg(result));
+ }
+}
+
+QString IdentitiesDlg::checkValidity() {
+ QString reason;
+ foreach(QString name, identities.keys()) {
+ QString r;
+ VarMap id = identities[name].toMap();
+ if(name == "Default") name = tr("Default Identity");
+ if(id["RealName"].toString().isEmpty()) {
+ r += tr(" You have not set a real name.");
+ }
+ if(id["Ident"].toString().isEmpty()) {
+ r += tr(" You have to specify an Ident.");
+ }
+ if(id["NickList"].toStringList().size() == 0) {
+ r += tr(" You haven't entered any nicknames.");
+ }
+ if(r.length()>0) {
+ reason += tr("[%1]%2\n").arg(name).arg(r);
+ }
+ }
+ return reason;
+}
+
+void IdentitiesDlg::editIdentities() {
+ updateIdentity(getCurIdentity());
+ IdentitiesEditDlg dlg(this, identities, nameMapping, createDefaultIdentity(), getCurIdentity());
+ if(dlg.exec() == QDialog::Accepted) {
+ identities = dlg.getIdentities();
+ nameMapping = dlg.getMapping();
+ ui.identityList->clear();
+ ui.identityList->addItem(tr("Default Identity"));
+ foreach(QString id, identities.keys()) {
+ if(id != "Default") ui.identityList->addItem(id);
+ if(id == dlg.getSelectedIdentity()) ui.identityList->setCurrentIndex(ui.identityList->count()-1);
+ }
+ lastIdentity = getCurIdentity();
+ updateWidgets();
+ }
+}
+
+/******************************************************************************/
+
+IdentitiesEditDlg::IdentitiesEditDlg(QWidget *parent, VarMap _identities, QMap<QString, QString> _mapping, VarMap templ, QString selected)
+ : QDialog(parent) {
+ ui.setupUi(this);
+ identities = _identities;
+ mapping = _mapping;
+ identTemplate = templ;
+
+ foreach(QString name, identities.keys()) {
+ if(name == "Default") continue;
+ ui.identList->addItem(name);
+ if(name == selected) ui.identList->setCurrentRow(ui.identList->count()-1);
+ }
+ ui.identList->sortItems();
+ ui.identList->insertItem(0, tr("Default Identity"));
+ if(ui.identList->selectedItems().count()!=1) ui.identList->setCurrentRow(0);
+ selectionChanged();
+ connect(ui.identList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
+ connect(ui.addButton, SIGNAL(clicked()), this, SLOT(addIdentity()));
+ connect(ui.duplicateButton, SIGNAL(clicked()), this, SLOT(duplicateIdentity()));
+ connect(ui.renameButton, SIGNAL(clicked()), this, SLOT(renameIdentity()));
+ connect(ui.deleteButton, SIGNAL(clicked()), this, SLOT(deleteIdentity()));
+ }
+
+ void IdentitiesEditDlg::selectionChanged() {
+ Q_ASSERT(ui.identList->selectedItems().size() == 1);
+ int idx = ui.identList->row(ui.identList->selectedItems()[0]);
+ ui.duplicateButton->setEnabled(idx >= 0);
+ ui.renameButton->setEnabled(idx > 0);
+ ui.deleteButton->setEnabled(idx > 0);
+ }
+
+ void IdentitiesEditDlg::addIdentity() {
+ RenameIdentityDlg dlg(this, identities.keys());
+ if(dlg.exec() == QDialog::Accepted) {
+ VarMap id = identTemplate;
+ identities[dlg.getName()] = id;
+ Q_ASSERT(!mapping.contains(dlg.getName()));
+ mapping[dlg.getName()] = dlg.getName();
+ QListWidgetItem *item = new QListWidgetItem(dlg.getName(), ui.identList);
+ sortList();
+ ui.identList->setCurrentItem(item);
+ selectionChanged();
+ }
+ }
+
+ void IdentitiesEditDlg::duplicateIdentity() {
+ RenameIdentityDlg dlg(this, identities.keys());
+ if(dlg.exec() == QDialog::Accepted) {
+ QString curname = ui.identList->currentRow() == 0 ? "Default" : ui.identList->currentItem()->text();
+ QVariant id = identities[curname];
+ identities[dlg.getName()] = id;
+ Q_ASSERT(!mapping.contains(dlg.getName()));
+ mapping[dlg.getName()] = dlg.getName();
+ QListWidgetItem *item = new QListWidgetItem(dlg.getName(), ui.identList);
+ sortList();
+ ui.identList->setCurrentItem(item);
+ selectionChanged();
+ }
+ }
+
+ void IdentitiesEditDlg::renameIdentity() {
+ QList<QString> names;
+ QString curname = ui.identList->currentItem()->text();
+ foreach(QString n, identities.keys()) {
+ if(n != curname) names.append(n);
+ }
+ RenameIdentityDlg dlg(this, names, curname);
+ if(dlg.exec() == QDialog::Accepted) {
+ QString newname = dlg.getName();
+ foreach(QString key, mapping.keys()) {
+ if(mapping[key] == curname) {
+ mapping[key] = newname;
+ break;
+ }
+ }
+ QVariant id = identities.take(curname);
+ identities[newname] = id;
+ QListWidgetItem *item = ui.identList->currentItem();
+ item->setText(newname);
+ sortList();
+ ui.identList->setCurrentItem(item);
+ selectionChanged();
+ }
+ }
+
+ void IdentitiesEditDlg::deleteIdentity() {
+ QString curname = ui.identList->currentItem()->text();
+ if(QMessageBox::question(this, tr("Delete Identity?"),
+ tr("Do you really want to delete identity \"%1\"?\nNetworks using this identity "
+ "will be reset to use the default identity.").arg(curname),
+ tr("&Delete"), tr("&Cancel"), QString(), 1, 1) == 0) {
+ delete ui.identList->takeItem(ui.identList->currentRow());
+ foreach(QString key, mapping.keys()) {
+ if(mapping[key] == curname) {
+ mapping.remove(key); break;
+ }
+ }
+ identities.remove(curname);
+ selectionChanged();
+ }
+ }
+
+ void IdentitiesEditDlg::sortList() {
+ QListWidgetItem *def = ui.identList->takeItem(0);
+ ui.identList->sortItems();
+ ui.identList->insertItem(0, def);
+ }
+
+ /******************************************************************************/
+
+ NickEditDlg::NickEditDlg(QWidget *parent, QString nick) : QDialog(parent) {
+ ui.setupUi(this);
+ ui.lineEdit->setText(nick);
+ connect(ui.lineEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
+ textChanged(nick);
+ }
+
+ void NickEditDlg::textChanged(QString text) {
+ ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || text == "");
+ }
+
+ QString NickEditDlg::getNick() {
+ return ui.lineEdit->text();
+ }
+
+ /*******************************************************************************/
+
+ RenameIdentityDlg::RenameIdentityDlg(QWidget *parent, QList<QString> _reserved, QString name) : QDialog(parent) {
+ ui.setupUi(this);
+ reserved = _reserved;
+ setWindowTitle(tr("Edit Identity Name"));
+ ui.label->setText(tr("Identity:"));
+ ui.lineEdit->setText(name);
+ connect(ui.lineEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
+ textChanged(name);
+ }
+
+ void RenameIdentityDlg::textChanged(QString text) {
+ if(text.length() == 0) { ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(true); return; }
+ ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(reserved.contains(text));
+ }
+
+ QString RenameIdentityDlg::getName() {
+ return ui.lineEdit->text();
+ }
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005/06 by The Quassel 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 _IDENTITIES_H_
+#define _IDENTITIES_H_
+
+#include <QtGui>
+#include <QtCore>
+
+#include "global.h"
+#include "ui_identitiesdlg.h"
+#include "ui_identitieseditdlg.h"
+#include "ui_nickeditdlg.h"
+
+class IdentitiesDlg : public QDialog {
+ Q_OBJECT
+
+ public:
+ IdentitiesDlg(QWidget *parent, QString selectedId = QString());
+
+ VarMap getIdentities() { return identities; }
+ QMap<QString, QString> getNameMapping() { return nameMapping; }
+
+ public slots:
+ virtual void accept();
+
+ private slots:
+ void autoAwayChecked();
+ void identityChanged(QString);
+ void nickSelectionChanged();
+
+ void addNick();
+ void editNick();
+ void delNick();
+ void upNick();
+ void downNick();
+
+ void editIdentities();
+
+ void globalDataUpdated(QString);
+
+ private:
+ Ui::IdentitiesDlg ui;
+ VarMap identities;
+ QMap<QString, QString> nameMapping;
+ QString lastIdentity;
+
+ QString checkValidity();
+ VarMap createDefaultIdentity();
+ QString getCurIdentity();
+ void updateWidgets();
+ void updateIdentity(QString);
+};
+
+class NickEditDlg : public QDialog {
+ Q_OBJECT
+
+ public:
+ NickEditDlg(QWidget *parent, QString nick = QString());
+
+ QString getNick();
+
+ private slots:
+ void textChanged(QString);
+
+ private:
+ Ui::NickEditDlg ui;
+
+};
+
+class IdentitiesEditDlg : public QDialog {
+ Q_OBJECT
+
+ public:
+ IdentitiesEditDlg(QWidget *parent, VarMap identities, QMap<QString, QString> mapping, VarMap templ, QString selected = QString());
+
+ VarMap getIdentities() { return identities; }
+ QMap<QString, QString> getMapping() { return mapping; }
+ QString getSelectedIdentity() { return ui.identList->currentItem()->text(); }
+
+ //virtual void accept();
+
+ private slots:
+ void selectionChanged();
+
+ void addIdentity();
+ void duplicateIdentity();
+ void renameIdentity();
+ void deleteIdentity();
+
+ private:
+ Ui::IdentitiesEditDlg ui;
+
+ VarMap identities;
+ VarMap identTemplate;
+ QMap<QString, QString> mapping;
+
+ void sortList();
+};
+
+class RenameIdentityDlg : public QDialog {
+ Q_OBJECT
+
+ public:
+ RenameIdentityDlg(QWidget *parent, QList<QString> reserved, QString name = QString());
+
+ QString getName();
+
+ private slots:
+ void textChanged(QString);
+
+ private:
+ Ui::NickEditDlg ui;
+ QList<QString> reserved;
+};
+
+#endif
<rect>
<x>0</x>
<y>0</y>
- <width>434</width>
- <height>458</height>
+ <width>385</width>
+ <height>449</height>
</rect>
</property>
<property name="windowTitle" >
<property name="spacing" >
<number>6</number>
</property>
- <item row="2" column="0" >
+ <item row="3" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Identity:</string>
</property>
</widget>
</item>
- <item row="0" column="1" >
- <widget class="QLineEdit" name="networkName" />
+ <item row="2" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Group:</string>
+ </property>
+ </widget>
</item>
<item row="2" column="1" >
+ <widget class="QComboBox" name="networkGroup" >
+ <property name="editable" >
+ <bool>true</bool>
+ </property>
+ <property name="insertPolicy" >
+ <enum>QComboBox::NoInsert</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</item>
</layout>
</item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="networkName" />
+ </item>
<item row="1" column="1" >
- <widget class="QComboBox" name="networkGroup" >
- <property name="insertPolicy" >
- <enum>QComboBox::NoInsert</enum>
- </property>
- </widget>
+ <widget class="QLineEdit" name="networkDesc" />
</item>
<item row="1" column="0" >
- <widget class="QLabel" name="label_2" >
+ <widget class="QLabel" name="label_5" >
<property name="text" >
- <string>Group:</string>
+ <string>Comment:</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableAutoConnect" >
<property name="text" >
- <string>Auto-connect at startup</string>
+ <string>Auto-connect on startup</string>
</property>
</widget>
</item>
- <item>
- <widget class="QWidget" native="1" name="widget" />
- </item>
<item>
<widget class="QTabWidget" name="tabWidget" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
<property name="currentIndex" >
<number>0</number>
</property>
- <widget class="QWidget" name="tab" >
+ <widget class="QWidget" name="serversTab" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
<attribute name="title" >
<string>Servers</string>
</attribute>
- <layout class="QVBoxLayout" >
+ <layout class="QHBoxLayout" >
<property name="margin" >
- <number>8</number>
+ <number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
- <layout class="QHBoxLayout" >
+ <widget class="QListWidget" name="serverList" />
+ </item>
+ <item>
+ <layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<number>6</number>
</property>
<item>
- <widget class="QListWidget" name="serverList" />
+ <widget class="QPushButton" name="addServer" >
+ <property name="text" >
+ <string>&Add...</string>
+ </property>
+ </widget>
</item>
<item>
- <layout class="QVBoxLayout" >
- <property name="margin" >
- <number>0</number>
+ <widget class="QPushButton" name="editServer" >
+ <property name="text" >
+ <string>&Edit...</string>
</property>
- <property name="spacing" >
- <number>6</number>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deleteServer" >
+ <property name="text" >
+ <string>De&lete</string>
</property>
- <item>
- <widget class="QPushButton" name="addServer" >
- <property name="text" >
- <string>&Add...</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="editServer" >
- <property name="text" >
- <string>&Edit...</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="deleteServer" >
- <property name="text" >
- <string>De&lete</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="upServer" >
- <property name="text" >
- <string>Move &Up</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="downServer" >
- <property name="text" >
- <string>Move &Down</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="upServer" >
+ <property name="text" >
+ <string>Move &Up</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="downServer" >
+ <property name="text" >
+ <string>Move &Down</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
</item>
</layout>
</item>
</layout>
- <widget class="QWidget" native="1" name="widget" >
- <property name="geometry" >
- <rect>
- <x>230</x>
- <y>20</y>
- <width>87</width>
- <height>151</height>
- </rect>
- </property>
- </widget>
</widget>
- <widget class="QWidget" name="tab" >
+ <widget class="QWidget" name="performTab" >
<attribute name="title" >
<string>Perform</string>
</attribute>
<number>6</number>
</property>
<item>
- <widget class="QTextEdit" name="performEdit" />
+ <widget class="QTextEdit" name="performEdit" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="html" >
+ <string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Not implemented yet</span></p></body></html></string>
+ </property>
+ </widget>
</item>
<item>
<widget class="QLabel" name="label_4" >
--- /dev/null
+<ui version="4.0" >
+ <class>ServerEditDlg</class>
+ <widget class="QDialog" name="ServerEditDlg" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>320</width>
+ <height>110</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Enter Server Details</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="1" column="0" >
+ <widget class="QLineEdit" name="serverAddress" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" colspan="2" >
+ <widget class="QSpinBox" name="serverPort" >
+ <property name="maximum" >
+ <number>65535</number>
+ </property>
+ <property name="minimum" >
+ <number>1024</number>
+ </property>
+ <property name="value" >
+ <number>6667</number>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Server address:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Port:</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>302</width>
+ <height>16</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>ServerEditDlg</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>ServerEditDlg</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
***************************************************************************/
#include "serverlist.h"
-#include "global.h"
+#include "identities.h"
+#include "guiproxy.h"
/* NOTE: This dialog holds not only the server list, but also the identities.
* This makes perfect sense given the fact that connections are initiated from
QSettings settings;
settings.beginGroup("GUI");
ui.showOnStartup->setChecked(settings.value("ShowServerListOnStartup", true).toBool());
- // create some default entries
- VarMap s1, s2, s3, s4;
-
- s1["group"] = "Private Servers";
- networks["mindNet"] = s1;
- s2["group"] = "Private Servers";
- networks["fooBar"] = s2;
- s3["group"] = "";
- networks["Single"] = s3;
- s4["group"] = "Public Servers";
- networks["public"] = s4;
-
- // load networks from QSettings here instead
- // [...]
-
- // Construct tree widget (and its items) from networks
- QStringList headers;
- headers << "Network" << "Autoconnect";
- ui.networkTree->setHeaderLabels(headers);
+
+ updateNetworkTree();
+ connect(ui.networkTree, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons()));
+
+ settings.endGroup();
+ // check if we already have a valid identity
+ if(!global->getData("Identities", VarMap()).toMap().contains("Default")) editIdentities(true);
+ connect(this, SIGNAL(requestConnect(QStringList)), guiProxy, SLOT(gsRequestConnect(QStringList)));
+
+ // Autoconnect
+ QStringList list;
+ VarMap networks = global->getData("Networks").toMap();
+ foreach(QString net, networks.keys()) {
+ if(networks[net].toMap()["AutoConnect"].toBool()) {
+ list << net;
+ }
+ }
+ qDebug() << "Autoconnect:"<<list;
+ if(!list.isEmpty()) emit requestConnect(list);
+}
+
+ServerListDlg::~ServerListDlg() {
+
+}
+
+void ServerListDlg::updateNetworkTree() {
+ VarMap networks = global->getData("Networks").toMap();
+ //QStringList headers;
+ //headers << "Network" << "Autoconnect";
+ ui.networkTree->clear();
+ //ui.networkTree->setHeaderLabels(headers);
+ ui.networkTree->setHeaderLabel("Networks");
QHash<QString, QTreeWidgetItem *> groups;
foreach(QString net, networks.keys()) {
VarMap s = networks[net].toMap();
- QString gr = s["group"].toString();
+ QString gr = s["Group"].toString();
QTreeWidgetItem *item = 0;
- if(gr == "") {
+ if(gr.isEmpty()) {
item = new QTreeWidgetItem(ui.networkTree);
} else {
if(groups.contains(gr)) {
item = new QTreeWidgetItem(groups[gr]);
} else {
QTreeWidgetItem *newgr = new QTreeWidgetItem(ui.networkTree);
+ //ui.networkTree->addTopLevelItem(newgr);
newgr->setText(0, gr);
newgr->setFlags(newgr->flags() & ~Qt::ItemIsSelectable);
- ui.networkTree->expandItem(newgr);
groups[gr] = newgr;
item = new QTreeWidgetItem(newgr);
+ newgr->setExpanded(true);
+ ui.networkTree->addTopLevelItem(newgr);
+ //ui.networkTree->expandItem(newgr); //<-- buggy Qt?
}
}
item->setText(0, net);
+ item->setToolTip(0, s["Description"].toString());
//item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
- item->setCheckState(1, Qt::Unchecked);
+ //item->setCheckState(1, Qt::Unchecked);
}
- connect(ui.networkTree, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons()));
-
- loadIdentities();
- settings.endGroup();
-}
-
-ServerListDlg::~ServerListDlg() {
+ ui.networkTree->sortItems(0, Qt::AscendingOrder);
}
}
void ServerListDlg::on_addButton_clicked() {
- NetworkEditDlg dlg(this, VarMap(), identities);
+ NetworkEditDlg dlg(this, VarMap());
if(dlg.exec() == QDialog::Accepted) {
-
+ VarMap networks = global->getData("Networks").toMap();
+ VarMap net = dlg.getNetwork();
+ networks[net["Name"].toString()] = net;
+ global->putData("Networks", networks);
+ updateNetworkTree();
}
}
-void ServerListDlg::loadNetworks() {
-
-}
-
-void ServerListDlg::storeNetworks() {
-
-}
-
-void ServerListDlg::loadIdentities() {
- identities = global->getData("Identities", VarMap()).toMap();
- while(!identities.contains("Default")) {
- editIdentities();
+void ServerListDlg::on_editButton_clicked() {
+ QString curnet = ui.networkTree->currentItem()->text(0);
+ VarMap networks = global->getData("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);
+ updateNetworkTree();
}
}
-void ServerListDlg::storeIdentities() {
- global->putData("Identities", identities);
+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->getData("Networks").toMap();
+ QList<QTreeWidgetItem *> sel = ui.networkTree->selectedItems();
+ foreach(QTreeWidgetItem *item, sel) {
+ networks.remove(item->text(0));
+ }
+ global->putData("Networks", networks);
+ updateNetworkTree();
+ }
}
-void ServerListDlg::editIdentities() {
- IdentitiesDlg dlg(this, identities);
+void ServerListDlg::editIdentities(bool end) {
+ IdentitiesDlg dlg(this);
if(dlg.exec() == QDialog::Accepted) {
- identities = dlg.getIdentities();
- QMap<QString, QString> mapping = dlg.getNameMapping();
+ /* Should now all be handled within the dialog class. Global settings rulez0rs. */
+ //identities = dlg.getIdentities();
+ //QMap<QString, QString> mapping = dlg.getNameMapping();
// add mapping here <-- well, I don't fucking know anymore what I meant by this back in 2005...
//
- storeIdentities();
- storeNetworks(); // ? how to treat mapping and NOT save changes not yet applied to the server list?
+ //storeIdentities();
+ //storeNetworks(); // ? how to treat mapping and NOT save changes not yet applied to the server list?
}
+ else if(end) exit(0);
}
void ServerListDlg::on_showOnStartup_stateChanged(int) {
s.setValue("GUI/ShowServerListOnStartup", ui.showOnStartup->isChecked());
}
-/***************************************************************************/
-
-NetworkEditDlg::NetworkEditDlg(QWidget *parent, VarMap _network, VarMap _identities) : QDialog(parent) {
- ui.setupUi(this);
- network = _network;
- identities = _identities;
-
- ui.identityList->addItem(tr("Default Identity"));
-
- foreach(QString id, identities.keys()) {
- if(id != "Default") ui.identityList->addItem(id);
+void ServerListDlg::accept() {
+ QStringList nets;
+ QList<QTreeWidgetItem *> list = ui.networkTree->selectedItems();
+ foreach(QTreeWidgetItem *item, list) {
+ nets << item->text(0);
}
-
-}
-
-VarMap NetworkEditDlg::createDefaultNetwork() {
- VarMap net;
-
- net["group"] = "";
-
- return net;
+ emit requestConnect(nets);
+ QDialog::accept();
}
/***************************************************************************/
-IdentitiesDlg::IdentitiesDlg(QWidget *parent, VarMap _identities) : QDialog(parent) {
+NetworkEditDlg::NetworkEditDlg(QWidget *parent, VarMap _network) : QDialog(parent) {
ui.setupUi(this);
- connect(global, SIGNAL(dataUpdatedRemotely(QString)), this, SLOT(globalDataUpdated(QString)));
+ network = _network;
+ oldName = network["Name"].toString();
- connect(ui.enableAutoAway, SIGNAL(stateChanged(int)), this, SLOT(autoAwayChecked()));
+ connect(ui.serverList, SIGNAL(itemSelectionChanged()), this, SLOT(updateServerButtons()));
- identities = _identities;
- foreach(QString name, identities.keys()) {
- nameMapping[name] = name;
- }
- if(identities.size() == 0) {
- VarMap id = createDefaultIdentity();
- id["IdName"] = "Default";
- identities["Default"] = id;
- }
- ui.identityList->addItem(tr("Default Identity"));
+ VarMap identities = global->getData("Identities").toMap();
+ ui.identityList->addItem(tr("Default Identity"));
foreach(QString id, identities.keys()) {
if(id != "Default") ui.identityList->addItem(id);
}
- updateWidgets();
- lastIdentity = getCurIdentity();
- connect(ui.identityList, SIGNAL(activated(QString)), this, SLOT(identityChanged(QString)));
- connect(ui.editIdentitiesButton, SIGNAL(clicked()), this, SLOT(editIdentities()));
- connect(ui.nickList, SIGNAL(itemSelectionChanged()), this, SLOT(nickSelectionChanged()));
- connect(ui.addNickButton, SIGNAL(clicked()), this, SLOT(addNick()));
- connect(ui.editNickButton, SIGNAL(clicked()), this, SLOT(editNick()));
- connect(ui.delNickButton, SIGNAL(clicked()), this, SLOT(delNick()));
- connect(ui.upNickButton, SIGNAL(clicked()), this, SLOT(upNick()));
- connect(ui.downNickButton, SIGNAL(clicked()), this, SLOT(downNick()));
-}
-
-void IdentitiesDlg::globalDataUpdated(QString key) {
- if(key == "Identities") {
- if(QMessageBox::warning(this, tr("Data changed remotely!"), tr("<b>Some other GUI client changed the identities data!</b><br>"
- "Apply updated settings, losing all changes done locally?"),
- QMessageBox::Apply|QMessageBox::Discard) == QMessageBox::Apply) {
- identities = global->getData(key).toMap();
- updateWidgets();
+ QStringList groups; groups << "";
+ VarMap nets = global->getData("Networks").toMap();
+ foreach(QString net, nets.keys()) {
+ QString gr = nets[net].toMap()["Group"].toString();
+ if(!groups.contains(gr) && !gr.isEmpty()) {
+ groups.append(gr);
}
}
-}
-
-VarMap IdentitiesDlg::createDefaultIdentity() {
- VarMap id;
- id["RealName"] = "foo";
- id["Ident"] = "";
- id["NickList"] = QStringList();
- id["enableAwayNick"] = false;
- id["AwayNick"] = "";
- id["enableAwayReason"] = false;
- id["AwayReason"] = "";
- id["enableReturnMessage"] = false;
- id["ReturnMessage"] = "";
- id["enableAutoAway"] = false;
- id["AutoAwayTime"] = 10;
- id["enableAutoAwayReason"] = false;
- id["AutoAwayReason"] = "";
- id["enableAutoAwayReturn"] = false;
- id["AutoAwayReturn"] = "";
- id["PartReason"] = "Quasseling elsewhere.";
- id["QuitReason"] = "Every Quassel comes to its end.";
- id["KickReason"] = "No more quasseling for you!";
-
- return id;
-}
+ ui.networkGroup->addItems(groups);
+ if(network.size() == 0) network = createDefaultNetwork();
+
+ ui.networkName->setText(network["Name"].toString());
+ if(network["Group"].toString().isEmpty()) ui.networkGroup->setCurrentIndex(0);
+ else ui.networkGroup->setCurrentIndex(ui.networkGroup->findText(network["Group"].toString()));
+ if(network["Identity"].toString().isEmpty() || network["Identity"].toString() == "Default") ui.identityList->setCurrentIndex(0);
+ else ui.identityList->setCurrentIndex(ui.identityList->findText(network["Identity"].toString()));
+ ui.enableAutoConnect->setChecked(network["AutoConnect"].toBool());
+ updateWidgets();
-QString IdentitiesDlg::getCurIdentity() {
- if(ui.identityList->currentIndex() == 0) return "Default";
- return ui.identityList->currentText();
+ on_networkName_textChanged(ui.networkName->text());
+ ui.networkName->setFocus();
}
-void IdentitiesDlg::updateWidgets() {
- VarMap id = identities[getCurIdentity()].toMap();
- ui.realNameEdit->setText(id["RealName"].toString());
- ui.identEdit->setText(id["Ident"].toString());
- ui.nickList->clear();
- ui.nickList->addItems(id["NickList"].toStringList());
- if(ui.nickList->count()>0) ui.nickList->setCurrentRow(0);
- ui.enableAwayNick->setChecked(id["enableAwayNick"].toBool());
- ui.awayNickEdit->setText(id["AwayNick"].toString());
- ui.awayNickEdit->setEnabled(ui.enableAwayNick->isChecked());
- ui.enableAwayReason->setChecked(id["enableAwayReason"].toBool());
- ui.awayReasonEdit->setText(id["AwayReason"].toString());
- ui.awayReasonEdit->setEnabled(ui.enableAwayReason->isChecked());
- ui.enableReturnMessage->setChecked(id["enableReturnMessage"].toBool());
- ui.returnMessageEdit->setText(id["ReturnMessage"].toString());
- ui.returnMessageEdit->setEnabled(ui.enableReturnMessage->isChecked());
- ui.enableAutoAway->setChecked(id["enableAutoAway"].toBool());
- ui.autoAwayTime->setValue(id["AutoAwayTime"].toInt());
- ui.enableAutoAwayReason->setChecked(id["enableAutoAwayReason"].toBool());
- ui.autoAwayReasonEdit->setText(id["AutoAwayReason"].toString());
- ui.enableAutoAwayReturn->setChecked(id["enableAutoAwayReturn"].toBool());
- ui.autoAwayReturnEdit->setText(id["AutoAwayReturn"].toString());
- ui.partReasonEdit->setText(id["PartReason"].toString());
- ui.kickReasonEdit->setText(id["KickReason"].toString());
- ui.quitReasonEdit->setText(id["QuitReason"].toString());
- // set enabled states correctly
- autoAwayChecked();
- nickSelectionChanged();
-}
+VarMap NetworkEditDlg::createDefaultNetwork() {
+ VarMap net;
-void IdentitiesDlg::updateIdentity(QString idName) {
- VarMap id;
- id["RealName"] = ui.realNameEdit->text();
- id["Ident"] = ui.identEdit->text();
- QStringList nicks;
- for(int i = 0; i < ui.nickList->count(); i++) nicks << ui.nickList->item(i)->text();
- id["NickList"] = nicks;
- id["enableAwayNick"] = ui.enableAwayNick->isChecked();
- id["AwayNick"] = ui.awayNickEdit->text();
- id["enableAwayReason"] = ui.enableAwayReason->isChecked();
- id["AwayReason"] = ui.awayReasonEdit->text();
- id["enableReturnMessage"] = ui.enableReturnMessage->isChecked();
- id["ReturnMessage"] = ui.returnMessageEdit->text();
- id["enableAutoAway"] = ui.enableAutoAway->isChecked();
- id["AutoAwayTime"] = ui.autoAwayTime->value();
- id["enableAutoAwayReason"] = ui.enableAutoAwayReason->isChecked();
- id["AutoAwayReason"] = ui.autoAwayReasonEdit->text();
- id["enableAutoAwayReturn"] = ui.enableAutoAwayReturn->isChecked();
- id["AutoAwayReturn"] = ui.autoAwayReturnEdit->text();
- id["PartReason"] = ui.partReasonEdit->text();
- id["KickReason"] = ui.kickReasonEdit->text();
- id["QuitReason"] = ui.quitReasonEdit->text();
-
- id["IdName"] = idName;
- identities[idName] = id;
-}
+ net["Name"] = QString();
+ net["Group"] = QString();
+ net["Identity"] = QString("Default");
-void IdentitiesDlg::identityChanged(QString) {
- updateIdentity(lastIdentity);
- lastIdentity = getCurIdentity();
- updateWidgets();
+ return net;
}
-void IdentitiesDlg::autoAwayChecked() {
- if(ui.enableAutoAway->isChecked()) {
- ui.autoAwayLabel_1->setEnabled(1);
- ui.autoAwayLabel_2->setEnabled(1);
- ui.autoAwayTime->setEnabled(1);
- ui.enableAutoAwayReason->setEnabled(1);
- ui.enableAutoAwayReturn->setEnabled(1);
- ui.autoAwayReasonEdit->setEnabled(ui.enableAutoAwayReason->isChecked());
- ui.autoAwayReturnEdit->setEnabled(ui.enableAutoAwayReturn->isChecked());
- } else {
- ui.autoAwayLabel_1->setEnabled(0);
- ui.autoAwayLabel_2->setEnabled(0);
- ui.autoAwayTime->setEnabled(0);
- ui.enableAutoAwayReason->setEnabled(0);
- ui.enableAutoAwayReturn->setEnabled(0);
- ui.autoAwayReasonEdit->setEnabled(0);
- ui.autoAwayReturnEdit->setEnabled(0);
+void NetworkEditDlg::updateWidgets() {
+ ui.serverList->clear();
+ foreach(QVariant s, network["Servers"].toList()) {
+ VarMap server = s.toMap();
+ QString entry = QString("%1:%2").arg(server["Address"].toString()).arg(server["Port"].toInt());
+ QListWidgetItem *item = new QListWidgetItem(entry);
+ //if(server["Exclude"].toBool()) item->setCheckState(Qt::Checked);
+ ui.serverList->addItem(item);
}
+ updateServerButtons();
}
-void IdentitiesDlg::nickSelectionChanged() {
- Q_ASSERT(ui.nickList->selectedItems().size() == 1);
- int curidx = ui.nickList->row(ui.nickList->selectedItems()[0]);
- ui.editNickButton->setEnabled(curidx >= 0);
- ui.delNickButton->setEnabled(curidx >= 0);
- ui.upNickButton->setEnabled(curidx > 0);
- ui.downNickButton->setEnabled(curidx >= 0 && curidx < ui.nickList->count() - 1);
-}
+void NetworkEditDlg::updateServerButtons() {
+ Q_ASSERT(ui.serverList->selectedItems().size() <= 1);
+ int curidx;
+ if(ui.serverList->selectedItems().isEmpty()) curidx = -1;
+ else curidx = ui.serverList->row(ui.serverList->selectedItems()[0]);
+ ui.editServer->setEnabled(curidx >= 0);
+ ui.deleteServer->setEnabled(curidx >= 0);
+ ui.upServer->setEnabled(curidx > 0);
+ ui.downServer->setEnabled(curidx >= 0 && curidx < ui.serverList->count() - 1);
-void IdentitiesDlg::addNick() {
- NickEditDlg dlg(this);
- if(dlg.exec() == QDialog::Accepted) {
- QListWidgetItem *item = new QListWidgetItem(ui.nickList);
- item->setText(dlg.getNick());
- item->setFlags(item->flags() | Qt::ItemIsEditable);
- ui.nickList->setCurrentItem(item);
- nickSelectionChanged();
- }
}
-void IdentitiesDlg::editNick() {
- NickEditDlg dlg(this, ui.nickList->currentItem()->text());
- if(dlg.exec() == QDialog::Accepted) {
- ui.nickList->currentItem()->setText(dlg.getNick());
- }
+void NetworkEditDlg::on_networkName_textChanged(QString text) {
+ ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
}
-void IdentitiesDlg::delNick() {
- int row = ui.nickList->currentRow();
- delete ui.nickList->takeItem(row);
- if(row <= ui.nickList->count() - 1) ui.nickList->setCurrentRow(row);
- else if(row > 0) ui.nickList->setCurrentRow(ui.nickList->count()-1);
- nickSelectionChanged();
-}
-
-void IdentitiesDlg::upNick() {
- int row = ui.nickList->currentRow();
- QListWidgetItem *item = ui.nickList->takeItem(row);
- ui.nickList->insertItem(row-1, item);
- ui.nickList->setCurrentRow(row-1);
- nickSelectionChanged();
-}
+void NetworkEditDlg::accept() {
+ QString reason = checkValidity();
+ if(reason.isEmpty()) {
+ network["Name"] = ui.networkName->text();
+ network["Description"] = ui.networkDesc->text();
+ /*if(ui.networkGroup->currentText() == "<none>") network["Group"] = "";
+ else */ network["Group"] = ui.networkGroup->currentText();
+ network["AutoConnect"] = ui.enableAutoConnect->isChecked();
+ if(ui.identityList->currentIndex()) network["Identity"] = ui.identityList->currentText();
+ else network["Identity"] = "Default";
+ QDialog::accept();
+ } else {
+ QMessageBox::warning(this, tr("Invalid Network Settings!"),
+ tr("<b>Your network settings are invalid!</b><br>%1").arg(reason));
+ }
-void IdentitiesDlg::downNick() {
- int row = ui.nickList->currentRow();
- QListWidgetItem *item = ui.nickList->takeItem(row);
- ui.nickList->insertItem(row+1, item);
- ui.nickList->setCurrentRow(row+1);
- nickSelectionChanged();
}
-void IdentitiesDlg::accept() {
- updateIdentity(getCurIdentity());
- QString result = checkValidity();
- if(result.length() == 0) QDialog::accept();
- else {
- QMessageBox::warning(this, tr("Invalid Identity!"),
- tr("One or more of your identities do not contain all necessary information:\n\n%1\n"
- "Please fill in any missing information.").arg(result));
+QString NetworkEditDlg::checkValidity() {
+ QString r;
+ VarMap nets = global->getData("Networks").toMap();
+ if(ui.networkName->text() != oldName && nets.keys().contains(ui.networkName->text())) {
+ r += tr(" Network name already exists.");
}
-}
-
-QString IdentitiesDlg::checkValidity() {
- QString reason;
- foreach(QString name, identities.keys()) {
- QString r;
- VarMap id = identities[name].toMap();
- if(name == "Default") name = tr("Default Identity");
- if(id["RealName"].toString().length() == 0) {
- r += tr(" You have not set a real name.");
- }
- if(id["Ident"].toString().length() == 0) {
- r += tr(" You have to specify an Ident.");
- }
- if(id["NickList"].toStringList().size() == 0) {
- r += tr(" You haven't entered any nicknames.");
- }
- if(r.length()>0) {
- reason += tr("[%1]%2\n").arg(name).arg(r);
- }
+ if(network["Servers"].toList().isEmpty()) {
+ r += tr(" You need to enter at least one server for this network.");
}
- return reason;
+ return r;
}
-void IdentitiesDlg::editIdentities() {
- updateIdentity(getCurIdentity());
- IdentitiesEditDlg dlg(this, identities, nameMapping, createDefaultIdentity());
+void NetworkEditDlg::on_addServer_clicked() {
+ ServerEditDlg dlg(this);
if(dlg.exec() == QDialog::Accepted) {
- identities = dlg.getIdentities();
- nameMapping = dlg.getMapping();
- ui.identityList->clear();
- ui.identityList->addItem(tr("Default Identity"));
- foreach(QString id, identities.keys()) {
- if(id != "Default") ui.identityList->addItem(id);
- }
- lastIdentity = getCurIdentity();
+ QList<QVariant> list = network["Servers"].toList();
+ list.append(dlg.getServer());
+ network["Servers"] = list;
updateWidgets();
}
}
-/******************************************************************************/
-
-IdentitiesEditDlg::IdentitiesEditDlg(QWidget *parent, VarMap _identities, QMap<QString, QString> _mapping, VarMap templ)
- : QDialog(parent) {
- ui.setupUi(this);
- identities = _identities;
- mapping = _mapping;
- identTemplate = templ;
-
- foreach(QString name, identities.keys()) {
- if(name == "Default") continue;
- ui.identList->addItem(name);
+void NetworkEditDlg::on_editServer_clicked() {
+ int idx = ui.serverList->currentRow();
+ ServerEditDlg dlg(this, network["Servers"].toList()[idx].toMap());
+ if(dlg.exec() == QDialog::Accepted) {
+ QList<QVariant> list = network["Servers"].toList();
+ list[idx] = dlg.getServer();
+ network["Servers"] = list;
+ updateWidgets();
}
- ui.identList->sortItems();
- ui.identList->insertItem(0, tr("Default Identity"));
- ui.identList->setCurrentRow(0);
- selectionChanged();
- connect(ui.identList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
- connect(ui.addButton, SIGNAL(clicked()), this, SLOT(addIdentity()));
- connect(ui.duplicateButton, SIGNAL(clicked()), this, SLOT(duplicateIdentity()));
- connect(ui.renameButton, SIGNAL(clicked()), this, SLOT(renameIdentity()));
- connect(ui.deleteButton, SIGNAL(clicked()), this, SLOT(deleteIdentity()));
}
-void IdentitiesEditDlg::selectionChanged() {
- Q_ASSERT(ui.identList->selectedItems().size() == 1);
- int idx = ui.identList->row(ui.identList->selectedItems()[0]);
- ui.duplicateButton->setEnabled(idx >= 0);
- ui.renameButton->setEnabled(idx > 0);
- ui.deleteButton->setEnabled(idx > 0);
+void NetworkEditDlg::on_deleteServer_clicked() {
+ int idx = ui.serverList->currentRow();
+ QList<QVariant> list = network["Servers"].toList();
+ list.removeAt(idx);
+ network["Servers"] = list;
+ updateWidgets();
+ if(idx < ui.serverList->count()) ui.serverList->setCurrentRow(idx);
+ else if(ui.serverList->count()) ui.serverList->setCurrentRow(ui.serverList->count()-1);
}
-void IdentitiesEditDlg::addIdentity() {
- RenameIdentityDlg dlg(this, identities.keys());
- if(dlg.exec() == QDialog::Accepted) {
- VarMap id = identTemplate;
- identities[dlg.getName()] = id;
- QListWidgetItem *item = new QListWidgetItem(dlg.getName(), ui.identList);
- sortList();
- ui.identList->setCurrentItem(item);
- selectionChanged();
- }
+void NetworkEditDlg::on_upServer_clicked() {
+ int idx = ui.serverList->currentRow();
+ QList<QVariant> list = network["Servers"].toList();
+ list.swap(idx, idx-1);
+ network["Servers"] = list;
+ updateWidgets();
+ ui.serverList->setCurrentRow(idx-1);
}
-void IdentitiesEditDlg::duplicateIdentity() {
- RenameIdentityDlg dlg(this, identities.keys());
- if(dlg.exec() == QDialog::Accepted) {
- QString curname = ui.identList->currentRow() == 0 ? "Default" : ui.identList->currentItem()->text();
- QVariant id = identities[curname];
- identities[dlg.getName()] = id;
- QListWidgetItem *item = new QListWidgetItem(dlg.getName(), ui.identList);
- sortList();
- ui.identList->setCurrentItem(item);
- selectionChanged();
- }
+void NetworkEditDlg::on_downServer_clicked() {
+ int idx = ui.serverList->currentRow();
+ QList<QVariant> list = network["Servers"].toList();
+ list.swap(idx, idx+1);
+ network["Servers"] = list;
+ updateWidgets();
+ ui.serverList->setCurrentRow(idx+1);
}
-void IdentitiesEditDlg::renameIdentity() {
- QList<QString> names;
- QString curname = ui.identList->currentItem()->text();
- foreach(QString n, identities.keys()) {
- if(n != curname) names.append(n);
- }
- RenameIdentityDlg dlg(this, names, curname);
+void NetworkEditDlg::on_editIdentities_clicked() {
+ QString id;
+ if(ui.identityList->currentIndex() > 0) id = ui.identityList->currentText();
+ else id = "Default";
+ IdentitiesDlg dlg(this, id);
if(dlg.exec() == QDialog::Accepted) {
- QString newname = dlg.getName();
- foreach(QString key, mapping.keys()) {
- if(mapping[key] == curname) {
- mapping[key] = newname;
- break;
- }
+ VarMap identities = global->getData("Identities").toMap();
+ ui.identityList->clear();
+ ui.identityList->addItem(tr("Default Identity"));
+ foreach(QString i, identities.keys()) {
+ if(i != "Default") ui.identityList->addItem(i);
}
- QVariant id = identities.take(curname);
- identities[newname] = id;
- QListWidgetItem *item = ui.identList->currentItem();
- item->setText(newname);
- sortList();
- ui.identList->setCurrentItem(item);
- selectionChanged();
- }
-}
-
-void IdentitiesEditDlg::deleteIdentity() {
- QString curname = ui.identList->currentItem()->text();
- if(QMessageBox::question(this, tr("Delete Identity?"),
- tr("Do you really want to delete identity \"%1\"?\nNetworks using this identity "
- "will be reset to use the default identity.").arg(curname),
- tr("&Delete"), tr("&Cancel"), QString(), 1, 1) == 0) {
- delete ui.identList->takeItem(ui.identList->currentRow());
- foreach(QString key, mapping.keys()) {
- if(mapping[key] == curname) {
- mapping.remove(key); break;
- }
- }
- identities.remove(curname);
- selectionChanged();
+ QMap<QString, QString> mapping = dlg.getNameMapping();
+ if(mapping.contains(id)) id = mapping[id];
+ else id = "Default";
+ if(id != "Default") ui.identityList->setCurrentIndex(ui.identityList->findText(id));
+ else ui.identityList->setCurrentIndex(0);
+ network["Identity"] = id;
}
}
-void IdentitiesEditDlg::sortList() {
- QListWidgetItem *def = ui.identList->takeItem(0);
- ui.identList->sortItems();
- ui.identList->insertItem(0, def);
-}
-
-/******************************************************************************/
+/***************************************************************************/
-NickEditDlg::NickEditDlg(QWidget *parent, QString nick) : QDialog(parent) {
+ServerEditDlg::ServerEditDlg(QWidget *parent, VarMap server) {
ui.setupUi(this);
- ui.lineEdit->setText(nick);
- connect(ui.lineEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
- textChanged(nick);
-}
-
-void NickEditDlg::textChanged(QString text) {
- ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || text == "");
-}
-QString NickEditDlg::getNick() {
- return ui.lineEdit->text();
+ if(!server.isEmpty()) {
+ ui.serverAddress->setText(server["Address"].toString());
+ ui.serverPort->setValue(server["Port"].toInt());
+ } else {
+ ui.serverAddress->setText(QString());
+ ui.serverPort->setValue(6667);
+ }
+ on_serverAddress_textChanged();
}
-/*******************************************************************************/
-
-RenameIdentityDlg::RenameIdentityDlg(QWidget *parent, QList<QString> _reserved, QString name) : QDialog(parent) {
- ui.setupUi(this);
- reserved = _reserved;
- setWindowTitle(tr("Edit Identity Name"));
- ui.label->setText(tr("Identity:"));
- ui.lineEdit->setText(name);
- connect(ui.lineEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
- textChanged(name);
+void ServerEditDlg::on_serverAddress_textChanged() {
+ ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!ui.serverAddress->text().isEmpty());
}
-void RenameIdentityDlg::textChanged(QString text) {
- if(text.length() == 0) { ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(true); return; }
- ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(reserved.contains(text));
+VarMap ServerEditDlg::getServer() {
+ VarMap s;
+ s["Address"] = ui.serverAddress->text();
+ s["Port"] = ui.serverPort->text();
+ return s;
}
-QString RenameIdentityDlg::getName() {
- return ui.lineEdit->text();
-}
+/***************************************************************************/
#include <QMap>
#include <QList>
#include <QVariant>
+#include "global.h"
#include "ui_serverlistdlg.h"
-#include "ui_identitiesdlg.h"
-#include "ui_identitieseditdlg.h"
-#include "ui_nickeditdlg.h"
#include "ui_networkeditdlg.h"
-
-typedef QMap<QString, QVariant> VarMap;
+#include "ui_servereditdlg.h"
class ServerListDlg : public QDialog {
Q_OBJECT
bool showOnStartup();
public slots:
- void editIdentities();
+ void editIdentities(bool end = false);
+ virtual void reject() { exit(0); }
+ virtual void accept();
+
+ signals:
+ void requestConnect(QStringList networks);
private slots:
void updateButtons();
void on_showOnStartup_stateChanged(int);
void on_addButton_clicked();
+ void on_editButton_clicked();
+ void on_deleteButton_clicked();
private:
Ui::ServerListDlg ui;
- void loadNetworks();
- void storeNetworks();
- void loadIdentities();
- void storeIdentities();
-
- VarMap networks;
- VarMap identities;
+ void updateNetworkTree();
+ //VarMap networks;
+ //VarMap identities; <-- this is now stored in global
};
class NetworkEditDlg : public QDialog {
Q_OBJECT
public:
- NetworkEditDlg(QWidget *parent, VarMap network, VarMap identities);
-
- private:
- Ui::NetworkEditDlg ui;
-
- VarMap network;
- VarMap identities;
-
- VarMap createDefaultNetwork();
-};
-
-class IdentitiesDlg : public QDialog {
- Q_OBJECT
-
- public:
- IdentitiesDlg(QWidget *parent, VarMap identities);
-
- VarMap getIdentities() { return identities; }
- QMap<QString, QString> getNameMapping() { return nameMapping; }
+ NetworkEditDlg(QWidget *parent, VarMap network);
+ VarMap getNetwork() { return network; }
public slots:
virtual void accept();
private slots:
- void autoAwayChecked();
- void identityChanged(QString);
- void nickSelectionChanged();
-
- void addNick();
- void editNick();
- void delNick();
- void upNick();
- void downNick();
+ void on_networkName_textChanged(QString);
+ void on_addServer_clicked();
+ void on_editServer_clicked();
+ void on_deleteServer_clicked();
+ void on_upServer_clicked();
+ void on_downServer_clicked();
+ void on_editIdentities_clicked();
- void editIdentities();
-
- void globalDataUpdated(QString);
-
- private:
- Ui::IdentitiesDlg ui;
- VarMap identities;
- QMap<QString, QString> nameMapping;
- QString lastIdentity;
-
- QString checkValidity();
- VarMap createDefaultIdentity();
- QString getCurIdentity();
void updateWidgets();
- void updateIdentity(QString);
-};
-
-class NickEditDlg : public QDialog {
- Q_OBJECT
-
- public:
- NickEditDlg(QWidget *parent, QString nick = QString());
-
- QString getNick();
-
- private slots:
- void textChanged(QString);
-
+ void updateServerButtons();
private:
- Ui::NickEditDlg ui;
+ Ui::NetworkEditDlg ui;
+ VarMap network;
+ //VarMap identities;
+ QString oldName;
+
+ VarMap createDefaultNetwork();
+ QString checkValidity();
};
-class IdentitiesEditDlg : public QDialog {
+class ServerEditDlg : public QDialog {
Q_OBJECT
public:
- IdentitiesEditDlg(QWidget *parent, VarMap identities, QMap<QString, QString> mapping, VarMap templ);
+ ServerEditDlg(QWidget *parent, VarMap server = VarMap());
- VarMap getIdentities() { return identities; }
- QMap<QString, QString> getMapping() { return mapping; }
+ VarMap getServer();
private slots:
- void selectionChanged();
-
- void addIdentity();
- void duplicateIdentity();
- void renameIdentity();
- void deleteIdentity();
+ void on_serverAddress_textChanged();
private:
- Ui::IdentitiesEditDlg ui;
-
- VarMap identities;
- VarMap identTemplate;
- QMap<QString, QString> mapping;
+ Ui::ServerEditDlg ui;
- void sortList();
};
-class RenameIdentityDlg : public QDialog {
- Q_OBJECT
-
- public:
- RenameIdentityDlg(QWidget *parent, QList<QString> reserved, QString name = QString());
-
- QString getName();
-
- private slots:
- void textChanged(QString);
-
- private:
- Ui::NickEditDlg ui;
- QList<QString> reserved;
-};
-
#endif
<ui version="4.0" >
- <author></author>
- <comment></comment>
- <exportmacro></exportmacro>
<class>ServerListDlg</class>
<widget class="QDialog" name="ServerListDlg" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
- <width>757</width>
+ <width>430</width>
<height>444</height>
</rect>
</property>
<bool>false</bool>
</property>
<property name="alternatingRowColors" >
- <bool>true</bool>
+ <bool>false</bool>
</property>
<property name="selectionMode" >
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="sortingEnabled" >
- <bool>true</bool>
+ <bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
- <widget class="QWidget" name="widget" >
+ <widget class="QWidget" native="1" name="widget" >
<property name="geometry" >
<rect>
<x>9</x>
</rect>
</property>
</widget>
- <widget class="QWidget" name="widget_2" >
+ <widget class="QWidget" native="1" name="widget_2" >
<property name="geometry" >
<rect>
<x>9</x>
</rect>
</property>
</widget>
- <widget class="QWidget" name="widget_3" >
+ <widget class="QWidget" native="1" name="widget_3" >
<property name="geometry" >
<rect>
<x>660</x>
</property>
</widget>
</widget>
- <pixmapfunction></pixmapfunction>
<resources>
<include location="../images/icons.qrc" />
</resources>
void GUIProxy::connectToCore(QString host, quint16 port) {
socket.connectToHost(host, port);
- //VarMap initmsg;
- //initmsg["GUIProtocol"] = GUI_PROTOCOL;
- //send(GS_CLIENT_INIT, QVariant(initmsg));
}
void GUIProxy::disconnectFromCore() {
void GUIProxy::serverError(QAbstractSocket::SocketError) {
emit coreConnectionError(socket.errorString());
+ //qFatal(QString("Connection error: %1").arg(socket.errorString()).toAscii());
}
void GUIProxy::serverHasData() {
};
-enum CoreSignal { CS_CORE_STATE, CS_CORE_MESSAGE, CS_UPDATE_GLOBAL_DATA,
+enum CoreSignal { CS_CORE_STATE, CS_SEND_MESSAGE, CS_SEND_STATUS_MSG, CS_UPDATE_GLOBAL_DATA,
};
-SET(network_SRCS server.cpp)
+SET(network_SRCS server.cpp buffer.cpp)
SET(network_HDRS )
-SET(network_MOCS server.h)
+SET(network_MOCS server.h buffer.h)
QT4_WRAP_CPP(_MOC ${network_MOCS})
ADD_LIBRARY(network ${_MOC} ${network_SRCS} ${network_HDRS})
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005/06 by The Quassel 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. *
+ ***************************************************************************/
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2005/06 by The Quassel 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 _BUFFER_H_
+#define _BUFFER_H_
+
+#include <QtCore>
+
+class Buffer : public QObject {
+ Q_OBJECT
+
+
+
+
+};
+
+
+
+#endif
#include <QMetaObject>
-Server::Server() {
+Server::Server(QString net) : network(net) {
}
}
-void Server::init() {
- //Message::init(&dispatchServerMsg, &dispatchUserMsg);
-}
-
void Server::run() {
connect(&socket, SIGNAL(connected()), this, SLOT(socketConnected()));
connect(&socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
exec();
}
-void Server::connectToIrc( const QString & host, quint16 port ) {
- qDebug() << "Connecting...";
+void Server::connectToIrc(QString net) {
+ if(net != network) return; // not me!
+ QList<QVariant> servers = global->getData("Networks").toMap()[net].toMap()["Servers"].toList();
+ qDebug() << "Connecting to"<< servers[0].toMap();
+ QString host = servers[0].toMap()["Address"].toString();
+ quint16 port = servers[0].toMap()["Port"].toUInt();
+ sendStatusMsg(QString("Connecting to %1:%2...").arg(host).arg(port));
socket.connectToHost(host, port);
}
-void Server::disconnectFromIrc( ) {
+void Server::disconnectFromIrc(QString net) {
+ if(net != network) return; // not me!
socket.disconnectFromHost();
}
void Server::socketHasData() {
while(socket.canReadLine()) {
QString s = socket.readLine().trimmed();
- qDebug() << "Read: " << s;
+ //qDebug() << "Read: " << s;
emit recvRawServerMsg(s);
//Message *msg = Message::createFromServerString(this, s);
handleServerMsg(s);
qDebug() << "Socket state changed: " << state;
}
+void Server::userInput(QString net, QString buf, QString msg) {
+ putRawLine(msg);
+}
+
void Server::putRawLine(QString s) {
qDebug() << "SentRaw: " << s;
s += "\r\n";
defaultHandlerForServer(cmd, prefix, params);
}
} catch(Exception e) {
- emit recvLine(e.msg());
+ emit sendStatusMsg(e.msg());
}
}
void Server::defaultHandlerForServer(QString cmd, QString prefix, QStringList params) {
uint num = cmd.toUInt();
if(num) {
- recvLine(cmd + " " + params.join(" "));
+ emit sendMessage("", cmd + " " + params.join(" "));
} else {
- recvLine(QString("Unknown: ") + cmd + " " + params.join(" "));
+ emit sendMessage("", QString("Unknown: ") + cmd + " " + params.join(" "));
}
}
}
-/*
-void Server::handleServerMsg(Message *msg) {
- int cmdCode = msg->getCmdCode();
- QString prefix = msg->getPrefix();
- QStringList params = msg->getParams();
- if(cmdCode < 0) {
- switch(-cmdCode) {
- case CMD_PING:
- // PING <server1> [<server2>]
- if(params.size() < 1 || params.size() > 2) throw ParseError(msg);
- putCmd("PONG", params);
- break;
-
- default:
- throw Exception(QString("No handler installed for command: ") + msg->getCmd() + " " + msg->getParams().join(" "));
- }
- } else if(msg->getCmdCode() > 0) {
- switch(msg->getCmdCode()) {
-
- default:
- //
- throw Exception(msg->getCmd() + " " + msg->getParams().join(" "));
- }
-
- } else {
- throw UnknownCmdError(msg);
- }
-}
-*/
-
void Server::handleNoticeFromServer(QString prefix, QStringList params) {
- recvLine(params.join(" "));
+ sendMessage("", params.join(" "));
}
#include <QtNetwork>
#include "global.h"
+#include "buffer.h"
#define DEFAULT_PORT 6667
/*! \class Server
* This is a server object, managing a single connection to an IRC server, handling the associated channels and so on.
- * We have this run in its own thread mainly to not block other server objects or the core if something goes wrong,
+ * We have this running in its own thread mainly to not block other server objects or the core if something goes wrong,
* e.g. if some scripts starts running wild...
*/
Q_OBJECT
public:
- Server();
+ Server(QString network);
~Server();
- static void init();
-
- void run();
// serverState state();
bool isConnected() { return socket.state() == QAbstractSocket::ConnectedState; }
+ QString getNetwork() { return network; }
public slots:
// void setServerOptions();
- void connectToIrc(const QString &host, quint16 port = DEFAULT_PORT);
- void disconnectFromIrc();
+ void connectToIrc(QString net);
+ void disconnectFromIrc(QString net);
+ void userInput(QString net, QString buffer, QString msg);
void putRawLine(QString input);
void putCmd(QString cmd, QStringList params, QString prefix = 0);
- signals:
- //void outputLine(const QString & /*, Buffer *target = 0 */);
+ //void exitThread();
+ signals:
void recvRawServerMsg(QString);
- void recvLine(QString); // temp, should send a message to the GUI
+ void sendStatusMsg(QString);
+ void sendMessage(QString buffer, QString msg);
+ void disconnected();
private slots:
+ void run();
void socketHasData();
void socketError(QAbstractSocket::SocketError);
void socketConnected();
void defaultHandlerForServer(QString cmd, QString prefix, QStringList params);
private:
+ QString network;
QTcpSocket socket;
- QTextStream stream;
+ QHash<QString, Buffer*> buffers;
void handleServerMsg(QString rawMsg);
void handleUserMsg(QString usrMsg);
- //static inline void dispatchServerMsg(Message *msg) { msg->getServer()->handleServerMsg(msg); }
- //static inline void dispatchUserMsg(Message *msg) { msg->getServer()->handleUserMsg(msg); }
class ParseError : public Exception {
public:
};
};
-class Buffer {};
-
-
#endif