X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fqtui%2Fsettingspages%2Fnetworkssettingspage.cpp;h=a09a0fee416baca7dac27551e598d26e53285d70;hb=95bbc1d6fc62cd4e4dbafc513cbea4a274fa81ca;hp=5170826cf3306dd47e415c10e56ce932963a4240;hpb=6623fd2d46dadd0168e4e28d1db6944c26c2a773;p=quassel.git diff --git a/src/qtui/settingspages/networkssettingspage.cpp b/src/qtui/settingspages/networkssettingspage.cpp index 5170826c..a09a0fee 100644 --- a/src/qtui/settingspages/networkssettingspage.cpp +++ b/src/qtui/settingspages/networkssettingspage.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "networkssettingspage.h" @@ -36,8 +37,15 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) : SettingsPage(tr("G connectingIcon = QIcon(":/22x22/actions/gear"); disconnectedIcon = QIcon(":/22x22/actions/network-disconnect"); + foreach(int mib, QTextCodec::availableMibs()) { + QByteArray codec = QTextCodec::codecForMib(mib)->name(); + ui.sendEncoding->addItem(codec); + ui.recvEncoding->addItem(codec); + } + ui.sendEncoding->model()->sort(0); + ui.recvEncoding->model()->sort(0); currentId = 0; - setEnabled(false); // need a core connection! + setEnabled(Client::isConnected()); // need a core connection! setWidgetStates(); connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool))); connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkAdded(NetworkId))); @@ -46,6 +54,19 @@ NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) : SettingsPage(tr("G connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientIdentityRemoved(IdentityId))); connect(ui.identityList, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged())); + connect(ui.randomServer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.performEdit, SIGNAL(textChanged()), this, SLOT(widgetHasChanged())); + connect(ui.autoIdentify, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.autoIdentifyService, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.autoIdentifyPassword, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged())); + connect(ui.useDefaultEncodings, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.sendEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged())); + connect(ui.recvEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged())); + connect(ui.autoReconnect, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.reconnectInterval, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged())); + connect(ui.reconnectRetries, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged())); + connect(ui.unlimitedRetries, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + connect(ui.rejoinOnReconnect, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); //connect(ui., SIGNAL(), this, SLOT(widgetHasChanged())); //connect(ui., SIGNAL(), this, SLOT(widgetHasChanged())); @@ -178,7 +199,7 @@ void NetworksSettingsPage::setWidgetStates() { } void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) { - if(!item) item = networkItem(id); + if(!item && !(item = networkItem(id))) return; const Network *net = Client::network(id); if(!net || net->isInitialized()) item->setFlags(item->flags() | Qt::ItemIsEnabled); else item->setFlags(item->flags() & ~Qt::ItemIsEnabled); @@ -190,19 +211,31 @@ void NetworksSettingsPage::setItemState(NetworkId id, QListWidgetItem *item) { item->setIcon(disconnectedIcon); } if(net) { + bool select = false; // check if we already have another net of this name in the list, and replace it QList items = ui.networkList->findItems(net->networkName(), Qt::MatchExactly); if(items.count()) { foreach(QListWidgetItem *i, items) { NetworkId oldid = i->data(Qt::UserRole).value(); if(oldid > 0) continue; // only locally created nets should be replaced - if(oldid == currentId) item->setSelected(true); - delete ui.networkList->takeItem(ui.networkList->row(i)); + if(oldid == currentId) select = true; + int row = ui.networkList->row(i); + if(row >= 0) { + qDebug() << "ABOUT TO REMOVE: id=" << oldid << "from row" << row; + QListWidgetItem *olditem = ui.networkList->takeItem(row); + qDebug() << "Successfully removed item from list."; + if(!olditem) { + qWarning() << "NetworksSettingsPage::setItemState(): Why the heck don't we have an itempointer here?"; + Q_ASSERT(olditem); // abort non-gracefully, I need to figure out what's causing this + } + else delete olditem; + } networkInfos.remove(oldid); break; } } item->setText(net->networkName()); + if(select) item->setSelected(true); } } @@ -258,7 +291,7 @@ void NetworksSettingsPage::clientIdentityRemoved(IdentityId id) { if(currentId != 0) saveToNetworkInfo(networkInfos[currentId]); //ui.identityList->removeItem(ui.identityList->findData(id.toInt())); foreach(NetworkInfo info, networkInfos.values()) { - qDebug() << info.networkName << info.networkId << info.identity; + //qDebug() << info.networkName << info.networkId << info.identity; if(info.identity == id) { if(info.networkId == currentId) ui.identityList->setCurrentIndex(0); info.identity = 1; // set to default @@ -303,9 +336,9 @@ void NetworksSettingsPage::clientNetworkRemoved(NetworkId id) { if(id == currentId) displayNetwork(0); NetworkInfo info = networkInfos.take(id); QList items = ui.networkList->findItems(info.networkName, Qt::MatchExactly); - if(items.count()) { - Q_ASSERT(items[0]->data(Qt::UserRole).value() == id); - delete ui.networkList->takeItem(ui.networkList->row(items[0])); + foreach(QListWidgetItem *item, items) { + if(item->data(Qt::UserRole).value() == id) + delete ui.networkList->takeItem(ui.networkList->row(item)); } setWidgetStates(); widgetHasChanged(); @@ -358,6 +391,25 @@ void NetworksSettingsPage::displayNetwork(NetworkId id) { ui.serverList->addItem(QString("%1:%2").arg(v.toMap()["Host"].toString()).arg(v.toMap()["Port"].toUInt())); } setItemState(id); + ui.randomServer->setChecked(info.useRandomServer); + ui.performEdit->setPlainText(info.perform.join("\n")); + ui.autoIdentify->setChecked(info.useAutoIdentify); + ui.autoIdentifyService->setText(info.autoIdentifyService); + ui.autoIdentifyPassword->setText(info.autoIdentifyPassword); + if(info.codecForEncoding.isEmpty()) { + ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(Network::defaultCodecForEncoding())); + ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(Network::defaultCodecForDecoding())); + ui.useDefaultEncodings->setChecked(true); + } else { + ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(info.codecForEncoding)); + ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(info.codecForDecoding)); + ui.useDefaultEncodings->setChecked(false); + } + ui.autoReconnect->setChecked(info.useAutoReconnect); + ui.reconnectInterval->setValue(info.autoReconnectInterval); + ui.reconnectRetries->setValue(info.autoReconnectRetries); + ui.unlimitedRetries->setChecked(info.unlimitedReconnectRetries); + ui.rejoinOnReconnect->setChecked(info.rejoinChannels); } else { // just clear widgets ui.identityList->setCurrentIndex(-1); @@ -370,6 +422,23 @@ void NetworksSettingsPage::displayNetwork(NetworkId id) { void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo &info) { info.identity = ui.identityList->itemData(ui.identityList->currentIndex()).toInt(); + info.useRandomServer = ui.randomServer->isChecked(); + info.perform = ui.performEdit->toPlainText().split("\n"); + info.useAutoIdentify = ui.autoIdentify->isChecked(); + info.autoIdentifyService = ui.autoIdentifyService->text(); + info.autoIdentifyPassword = ui.autoIdentifyPassword->text(); + if(ui.useDefaultEncodings->isChecked()) { + info.codecForEncoding.clear(); + info.codecForDecoding.clear(); + } else { + info.codecForEncoding = ui.sendEncoding->currentText().toLatin1(); + info.codecForDecoding = ui.recvEncoding->currentText().toLatin1(); + } + info.useAutoReconnect = ui.autoReconnect->isChecked(); + info.autoReconnectInterval = ui.reconnectInterval->value(); + info.autoReconnectRetries = ui.reconnectRetries->value(); + info.unlimitedReconnectRetries = ui.unlimitedRetries->isChecked(); + info.rejoinChannels = ui.rejoinOnReconnect->isChecked(); } /*** Network list ***/ @@ -391,7 +460,7 @@ void NetworksSettingsPage::on_networkList_itemSelectionChanged() { void NetworksSettingsPage::on_addNetwork_clicked() { QStringList existing; for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text(); - NetworkEditDlgNew dlg(QString(), existing, this); + NetworkEditDlg dlg(QString(), existing, this); if(dlg.exec() == QDialog::Accepted) { NetworkId id; for(id = 1; id <= networkInfos.count(); id++) { @@ -403,6 +472,17 @@ void NetworksSettingsPage::on_addNetwork_clicked() { info.networkId = id; info.networkName = dlg.networkName(); info.identity = 1; + + // defaults + info.useRandomServer = false; + info.useAutoReconnect = true; + info.autoReconnectInterval = 60; + info.autoReconnectRetries = 20; + info.unlimitedReconnectRetries = false; + info.useAutoIdentify = false; + info.autoIdentifyService = "NickServ"; + info.rejoinChannels = true; + networkInfos[id] = info; QListWidgetItem *item = insertNetwork(info); ui.networkList->setCurrentItem(item); @@ -414,8 +494,7 @@ void NetworksSettingsPage::on_deleteNetwork_clicked() { if(ui.networkList->selectedItems().count()) { NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value(); int ret = QMessageBox::question(this, tr("Delete Network?"), - tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?" - "

NOTE: Backlog deletion hasn't actually been implemented yet.").arg(networkInfos[netid].networkName), + tr("Do you really want to delete the network \"%1\" and all related settings, including the backlog?").arg(networkInfos[netid].networkName), QMessageBox::Yes|QMessageBox::No, QMessageBox::No); if(ret == QMessageBox::Yes) { currentId = 0; @@ -433,7 +512,7 @@ void NetworksSettingsPage::on_renameNetwork_clicked() { QString old = ui.networkList->selectedItems()[0]->text(); QStringList existing; for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text(); - NetworkEditDlgNew dlg(old, existing, this); + NetworkEditDlg dlg(old, existing, this); if(dlg.exec() == QDialog::Accepted) { ui.networkList->selectedItems()[0]->setText(dlg.networkName()); NetworkId netid = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value(); @@ -459,7 +538,7 @@ void NetworksSettingsPage::on_serverList_itemSelectionChanged() { void NetworksSettingsPage::on_addServer_clicked() { if(currentId == 0) return; - ServerEditDlgNew dlg(QVariantMap(), this); + ServerEditDlg dlg(QVariantMap(), this); if(dlg.exec() == QDialog::Accepted) { networkInfos[currentId].serverList.append(dlg.serverData()); displayNetwork(currentId); @@ -472,7 +551,7 @@ void NetworksSettingsPage::on_addServer_clicked() { void NetworksSettingsPage::on_editServer_clicked() { if(currentId == 0) return; int cur = ui.serverList->currentRow(); - ServerEditDlgNew dlg(networkInfos[currentId].serverList[cur], this); + ServerEditDlg dlg(networkInfos[currentId].serverList[cur], this); if(dlg.exec() == QDialog::Accepted) { networkInfos[currentId].serverList[cur] = dlg.serverData(); displayNetwork(currentId); @@ -512,7 +591,7 @@ void NetworksSettingsPage::on_downServer_clicked() { * NetworkEditDlg *************************************************************************/ -NetworkEditDlgNew::NetworkEditDlgNew(const QString &old, const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) { +NetworkEditDlg::NetworkEditDlg(const QString &old, const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) { ui.setupUi(this); if(old.isEmpty()) { @@ -522,12 +601,12 @@ NetworkEditDlgNew::NetworkEditDlgNew(const QString &old, const QStringList &exis } else ui.networkEdit->setText(old); } -QString NetworkEditDlgNew::networkName() const { +QString NetworkEditDlg::networkName() const { return ui.networkEdit->text(); } -void NetworkEditDlgNew::on_networkEdit_textChanged(const QString &text) { +void NetworkEditDlg::on_networkEdit_textChanged(const QString &text) { ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text)); } @@ -536,7 +615,7 @@ void NetworkEditDlgNew::on_networkEdit_textChanged(const QString &text) { * ServerEditDlg *************************************************************************/ -ServerEditDlgNew::ServerEditDlgNew(const QVariant &_serverData, QWidget *parent) : QDialog(parent) { +ServerEditDlg::ServerEditDlg(const QVariant &_serverData, QWidget *parent) : QDialog(parent) { ui.setupUi(this); QVariantMap serverData = _serverData.toMap(); if(serverData.count()) { @@ -545,12 +624,12 @@ ServerEditDlgNew::ServerEditDlgNew(const QVariant &_serverData, QWidget *parent) ui.password->setText(serverData["Password"].toString()); ui.useSSL->setChecked(serverData["UseSSL"].toBool()); } else { - ui.port->setValue(Global::defaultPort); + ui.port->setValue(6667); } on_host_textChanged(); } -QVariant ServerEditDlgNew::serverData() const { +QVariant ServerEditDlg::serverData() const { QVariantMap _serverData; _serverData["Host"] = ui.host->text(); _serverData["Port"] = ui.port->value(); @@ -559,7 +638,7 @@ QVariant ServerEditDlgNew::serverData() const { return _serverData; } -void ServerEditDlgNew::on_host_textChanged() { +void ServerEditDlg::on_host_textChanged() { ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(ui.host->text().isEmpty()); }