X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=gui%2Fserverlist.cpp;h=ab12919d730e6892343b5b3410a29f6180cfc469;hp=b194c6060456ead0ef75cee40994d4c6081adb9d;hb=26586e615ffe42bb2b1b307ed1324a6e3051f5da;hpb=a975272aca8f0deb25c395532b189141979304e5 diff --git a/gui/serverlist.cpp b/gui/serverlist.cpp index b194c606..ab12919d 100644 --- a/gui/serverlist.cpp +++ b/gui/serverlist.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005 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 * @@ -19,70 +19,79 @@ ***************************************************************************/ #include "serverlist.h" -#include "proxy.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 * this dialog, and that the dialog exists during the lifetime of the program. - * This data is also only used from within the GUI, which means it shouldn't be - * part of the global Quassel class (me thinks). */ ServerListDlg::ServerListDlg(QWidget *parent) : QDialog(parent) { ui.setupUi(this); QSettings settings; - settings.beginGroup("Network"); + 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::data("Identities", VarMap()).toMap().contains("Default")) editIdentities(true); + connect(this, SIGNAL(requestConnect(QStringList)), ClientProxy::instance(), SLOT(gsRequestConnect(QStringList))); + + // Autoconnect + QStringList list; + VarMap networks = Global::data("Networks").toMap(); + foreach(QString net, networks.keys()) { + if(networks[net].toMap()["AutoConnect"].toBool()) { + list << net; + } + } + if(!list.isEmpty()) emit requestConnect(list); +} + +ServerListDlg::~ServerListDlg() { + +} + +void ServerListDlg::updateNetworkTree() { + VarMap networks = Global::data("Networks").toMap(); + //QStringList headers; + //headers << "Network" << "Autoconnect"; + ui.networkTree->clear(); + //ui.networkTree->setHeaderLabels(headers); + ui.networkTree->setHeaderLabel("Networks"); QHash 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); } @@ -99,461 +108,276 @@ bool ServerListDlg::showOnStartup() { } void ServerListDlg::on_addButton_clicked() { - NetworkEditDlg dlg(this, VarMap(), identities); + NetworkEditDlg dlg(this, VarMap()); if(dlg.exec() == QDialog::Accepted) { - + VarMap networks = Global::data("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() { - //QSettings s; - //s.beginGroup("Identities"); - //identities = s.value("Network/Identities").toMap(); - identities = GuiProxy::loadIdentities(); - while(!identities.contains("Default")) { - identities = VarMap(); - editIdentities(); +void ServerListDlg::on_editButton_clicked() { + QString curnet = ui.networkTree->currentItem()->text(0); + VarMap networks = Global::data("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() { - //QSettings s; - //s.setValue("Network/Identities", identities); - GuiProxy::storeIdentities(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::data("Networks").toMap(); + QList 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 mapping = dlg.getNameMapping(); - // add mapping here + /* Should now all be handled within the dialog class. Global settings rulez0rs. */ + //identities = dlg.getIdentities(); + //QMap 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) { QSettings s; - s.setValue("Network/ShowServerListOnStartup", ui.showOnStartup->isChecked()); + s.setValue("GUI/ShowServerListOnStartup", ui.showOnStartup->isChecked()); +} + +void ServerListDlg::accept() { + QStringList nets; + QList list = ui.networkTree->selectedItems(); + foreach(QTreeWidgetItem *item, list) { + nets << item->text(0); + } + emit requestConnect(nets); + QDialog::accept(); } /***************************************************************************/ -NetworkEditDlg::NetworkEditDlg(QWidget *parent, VarMap _network, VarMap _identities) : QDialog(parent) { +NetworkEditDlg::NetworkEditDlg(QWidget *parent, VarMap _network) : QDialog(parent) { ui.setupUi(this); network = _network; - identities = _identities; + oldName = network["Name"].toString(); - ui.identityList->addItem(tr("Default Identity")); + connect(ui.serverList, SIGNAL(itemSelectionChanged()), this, SLOT(updateServerButtons())); + + VarMap identities = Global::data("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(); + foreach(QString net, nets.keys()) { + QString gr = nets[net].toMap()["Group"].toString(); + if(!groups.contains(gr) && !gr.isEmpty()) { + groups.append(gr); + } + } + 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(); + on_networkName_textChanged(ui.networkName->text()); + ui.networkName->setFocus(); } VarMap NetworkEditDlg::createDefaultNetwork() { VarMap net; - net["group"] = ""; + net["Name"] = QString(); + net["Group"] = QString(); + net["Identity"] = QString("Default"); return net; } -/***************************************************************************/ - -IdentitiesDlg::IdentitiesDlg(QWidget *parent, VarMap _identities) : QDialog(parent) { - ui.setupUi(this); - connect(ui.enableAutoAway, SIGNAL(stateChanged(int)), this, SLOT(autoAwayChecked())); - - identities = _identities; - foreach(QString name, identities.keys()) { - nameMapping[name] = name; - } - if(identities.size() == 0) { - VarMap id = createDefaultIdentity(); - id["IdName"] = "Default"; - identities["Default"] = id; +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); } - ui.identityList->addItem(tr("Default Identity")); - - foreach(QString id, identities.keys()) { - if(id != "Default") ui.identityList->addItem(id); + ui.performEdit->clear(); + ui.performEdit->setText( network["Perform"].toString() ); + updateServerButtons(); +} + +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 NetworkEditDlg::on_networkName_textChanged(QString text) { + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); +} + +void NetworkEditDlg::accept() { + QString reason = checkValidity(); + if(reason.isEmpty()) { + network["Name"] = ui.networkName->text(); + network["Description"] = ui.networkDesc->text(); + /*if(ui.networkGroup->currentText() == "") network["Group"] = ""; + else */ network["Group"] = ui.networkGroup->currentText(); + network["AutoConnect"] = ui.enableAutoConnect->isChecked(); + network["Perform"] = ui.performEdit->toPlainText(); + if(ui.identityList->currentIndex()) network["Identity"] = ui.identityList->currentText(); + else network["Identity"] = "Default"; + QDialog::accept(); + } else { + QMessageBox::warning(this, tr("Invalid Network Settings!"), + tr("Your network settings are invalid!
%1").arg(reason)); } - 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())); -} - -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); +QString NetworkEditDlg::checkValidity() { + QString r; + VarMap nets = Global::data("Networks").toMap(); + if(ui.networkName->text() != oldName && nets.keys().contains(ui.networkName->text())) { + r += tr(" Network name already exists."); } + if(network["Servers"].toList().isEmpty()) { + r += tr(" You need to enter at least one server for this network."); + } + return r; } -void IdentitiesDlg::nickSelectionChanged() { - int curidx = ui.nickList->currentRow(); - 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); +void NetworkEditDlg::on_addServer_clicked() { + ServerEditDlg 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(); + QList list = network["Servers"].toList(); + list.append(dlg.getServer()); + network["Servers"] = list; + updateWidgets(); } } -void IdentitiesDlg::editNick() { - NickEditDlg dlg(this, ui.nickList->currentItem()->text()); +void NetworkEditDlg::on_editServer_clicked() { + int idx = ui.serverList->currentRow(); + ServerEditDlg dlg(this, network["Servers"].toList()[idx].toMap()); if(dlg.exec() == QDialog::Accepted) { - ui.nickList->currentItem()->setText(dlg.getNick()); + QList list = network["Servers"].toList(); + list[idx] = dlg.getServer(); + network["Servers"] = list; + updateWidgets(); } } -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 NetworkEditDlg::on_deleteServer_clicked() { + int idx = ui.serverList->currentRow(); + QList 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 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)); - } +void NetworkEditDlg::on_upServer_clicked() { + int idx = ui.serverList->currentRow(); + QList list = network["Servers"].toList(); + list.swap(idx, idx-1); + network["Servers"] = list; + updateWidgets(); + ui.serverList->setCurrentRow(idx-1); } -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); - } - } - return reason; +void NetworkEditDlg::on_downServer_clicked() { + int idx = ui.serverList->currentRow(); + QList list = network["Servers"].toList(); + list.swap(idx, idx+1); + network["Servers"] = list; + updateWidgets(); + ui.serverList->setCurrentRow(idx+1); } -void IdentitiesDlg::editIdentities() { - updateIdentity(getCurIdentity()); - IdentitiesEditDlg dlg(this, identities, nameMapping, createDefaultIdentity()); +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) { - identities = dlg.getIdentities(); - nameMapping = dlg.getMapping(); + VarMap identities = Global::data("Identities").toMap(); ui.identityList->clear(); ui.identityList->addItem(tr("Default Identity")); - foreach(QString id, identities.keys()) { - if(id != "Default") ui.identityList->addItem(id); + foreach(QString i, identities.keys()) { + if(i != "Default") ui.identityList->addItem(i); } - lastIdentity = getCurIdentity(); - updateWidgets(); + QMap 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; } } -/******************************************************************************/ +/***************************************************************************/ -IdentitiesEditDlg::IdentitiesEditDlg(QWidget *parent, VarMap _identities, QMap _mapping, VarMap templ) - : QDialog(parent) { +ServerEditDlg::ServerEditDlg(QWidget *parent, VarMap server) { ui.setupUi(this); - identities = _identities; - mapping = _mapping; - identTemplate = templ; - - foreach(QString name, identities.keys()) { - if(name == "Default") continue; - ui.identList->addItem(name); - } - 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() { - int idx = ui.identList->currentRow(); - 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; - 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; - QListWidgetItem *item = new QListWidgetItem(dlg.getName(), ui.identList); - sortList(); - ui.identList->setCurrentItem(item); - selectionChanged(); - } -} -void IdentitiesEditDlg::renameIdentity() { - QList 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(); + 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(); } -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.okButton->setDisabled(text.isEmpty() || text == ""); +void ServerEditDlg::on_serverAddress_textChanged() { + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!ui.serverAddress->text().isEmpty()); } -QString NickEditDlg::getNick() { - return ui.lineEdit->text(); +VarMap ServerEditDlg::getServer() { + VarMap s; + s["Address"] = ui.serverAddress->text(); + s["Port"] = ui.serverPort->text(); + return s; } -/*******************************************************************************/ - -RenameIdentityDlg::RenameIdentityDlg(QWidget *parent, QList _reserved, QString name) : QDialog(parent) { - ui.setupUi(this); - reserved = _reserved; - //ui.NickEditDlg->setWindowTitle(tr("Edit Identity Name")); // why does this not work? - 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.okButton->setEnabled(0); return; } - ui.okButton->setDisabled(reserved.contains(text)); -} - -QString RenameIdentityDlg::getName() { - return ui.lineEdit->text(); -} +/***************************************************************************/