From: Manuel Nickschas Date: Mon, 12 Jan 2009 00:51:22 +0000 (+0100) Subject: Introduce presets for adding networks X-Git-Tag: 0.4.0~233 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=eb5efce4b040e37a4d8fbabae37c63528b253744 Introduce presets for adding networks We now allow providing a networks.ini that contains a predefined list of networks/servers. When adding a network, one can choose a preset from that list to have server properties filled in automatically. This should make it much easier for users to add networks. For adding a custom network, we allow entering the most important data right in the dialog, to avoid useless clicks. --- diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 4513ca1e..8d835423 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -7,5 +7,6 @@ if(WANT_MONO) endif(WANT_MONO) if(WANT_MONO OR WANT_QTCLIENT) - install(FILES quassel.notifyrc DESTINATION ${DATA_INSTALL_DIR}/quassel) + install(FILES quassel.notifyrc networks.ini + DESTINATION ${DATA_INSTALL_DIR}/quassel) endif(WANT_MONO OR WANT_QTCLIENT) diff --git a/data/networks.ini b/data/networks.ini new file mode 100644 index 00000000..57861d33 --- /dev/null +++ b/data/networks.ini @@ -0,0 +1,7 @@ +[Freenode] +Default=Yes +DefaultChannels=#kubuntu,#quassel +Servers=irc.freenode.net:6667,chat.freenode.net:6667,kornbluth.freenode.net:6668 + +[Quakenet] +Servers=irc.quakenet.net:6667 diff --git a/src/qtui/settingspages/networkadddlg.ui b/src/qtui/settingspages/networkadddlg.ui new file mode 100644 index 00000000..0c63f078 --- /dev/null +++ b/src/qtui/settingspages/networkadddlg.ui @@ -0,0 +1,238 @@ + + NetworkAddDlg + + + + 0 + 0 + 421 + 275 + + + + Add Network + + + + + + + + Use preset: + + + true + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Manually specify network settings + + + + + + + false + + + Manual Settings + + + + + + + + Network name: + + + + + + + + + + Server address: + + + + + + + + + + Port: + + + + + + + 0 + + + 65535 + + + 6667 + + + + + + + Server password: + + + + + + + QLineEdit::Password + + + + + + + + + Use secure connection + + + + + + + + + + Qt::Vertical + + + + 20 + 31 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + NetworkAddDlg + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + NetworkAddDlg + reject() + + + 316 + 260 + + + 286 + 274 + + + + + usePreset + toggled(bool) + presetList + setEnabled(bool) + + + 53 + 18 + + + 132 + 17 + + + + + useManual + toggled(bool) + groupBox + setEnabled(bool) + + + 46 + 47 + + + 59 + 84 + + + + + useManual + clicked() + networkName + setFocus() + + + 26 + 45 + + + 153 + 113 + + + + + diff --git a/src/qtui/settingspages/networkssettingspage.cpp b/src/qtui/settingspages/networkssettingspage.cpp index 713cfa1a..c2785a0e 100644 --- a/src/qtui/settingspages/networkssettingspage.cpp +++ b/src/qtui/settingspages/networkssettingspage.cpp @@ -28,7 +28,7 @@ #include "iconloader.h" #include "identity.h" #include "network.h" - +#include "util.h" NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) : SettingsPage(tr("General"), tr("Networks"), parent) { ui.setupUi(this); @@ -508,7 +508,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(); - NetworkEditDlg dlg(QString(), existing, this); + NetworkAddDlg dlg(existing, this); if(dlg.exec() == QDialog::Accepted) { NetworkId id; for(id = 1; id <= networkInfos.count(); id++) { @@ -516,9 +516,11 @@ void NetworksSettingsPage::on_addNetwork_clicked() { if(!networkInfos.keys().contains(-id.toInt())) break; } id = -id.toInt(); - NetworkInfo info; + + NetworkInfo info = dlg.networkInfo(); + if(info.networkName.isEmpty()) + return; // sanity check info.networkId = id; - info.networkName = dlg.networkName(); info.identity = 1; // defaults @@ -634,6 +636,76 @@ void NetworksSettingsPage::on_downServer_clicked() { widgetHasChanged(); } +/************************************************************************** +* NetworkAddDlg +*************************************************************************/ + +NetworkAddDlg::NetworkAddDlg(const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) { + ui.setupUi(this); + ui.useSSL->setIcon(SmallIcon("document-encrypt")); + + // read preset networks + networksFilePath = findDataFilePath("networks.ini"); + if(!networksFilePath.isEmpty()) { + QSettings s(networksFilePath, QSettings::IniFormat); + QStringList networks = s.childGroups(); + foreach(QString s, existing) + networks.removeAll(s); + if(!networks.isEmpty()) + networks.sort(); + ui.presetList->addItems(networks); + } + if(!ui.presetList->count()) { + ui.useManual->setChecked(true); + ui.usePreset->setEnabled(false); + } + connect(ui.networkName, SIGNAL(textChanged(const QString &)), SLOT(setButtonStates())); + connect(ui.serverAddress, SIGNAL(textChanged(const QString &)), SLOT(setButtonStates())); + setButtonStates(); +} + +NetworkInfo NetworkAddDlg::networkInfo() const { + NetworkInfo info; + + if(ui.useManual->isChecked()) { + info.networkName = ui.networkName->text().trimmed(); + info.serverList << Network::Server(ui.serverAddress->text().trimmed(), ui.port->value(), ui.serverPassword->text(), ui.useSSL->isChecked()); + } else { + info.networkName = ui.presetList->currentText(); + QSettings s(networksFilePath, QSettings::IniFormat); + s.beginGroup(info.networkName); + foreach(QString server, s.value("Servers").toStringList()) { + bool ssl = false; + QStringList splitserver = server.split(':', QString::SkipEmptyParts); + if(splitserver.count() != 2) { + qWarning() << "Invalid server entry in networks.conf:" << server; + continue; + } + if(splitserver[1].at(0) == '+') + ssl = true; + uint port = splitserver[1].toUInt(); + if(!port) { + qWarning() << "Invalid port entry in networks.conf:" << server; + continue; + } + info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl); + } + } + + return info; +} + +void NetworkAddDlg::setButtonStates() { + bool ok = false; + if(ui.usePreset->isChecked() && ui.presetList->count()) + ok = true; + else if(ui.useManual->isChecked()) { + ok = !ui.networkName->text().trimmed().isEmpty() && !existing.contains(ui.networkName->text().trimmed()) + && !ui.serverAddress->text().isEmpty(); + } + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok); +} + /************************************************************************** * NetworkEditDlg *************************************************************************/ @@ -657,7 +729,6 @@ void NetworkEditDlg::on_networkEdit_textChanged(const QString &text) { ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text.trimmed())); } - /************************************************************************** * ServerEditDlg *************************************************************************/ diff --git a/src/qtui/settingspages/networkssettingspage.h b/src/qtui/settingspages/networkssettingspage.h index ef9b0dbe..624ca9a3 100644 --- a/src/qtui/settingspages/networkssettingspage.h +++ b/src/qtui/settingspages/networkssettingspage.h @@ -27,6 +27,7 @@ #include "settingspage.h" #include "ui_networkssettingspage.h" +#include "ui_networkadddlg.h" #include "ui_networkeditdlg.h" #include "ui_servereditdlg.h" #include "ui_saveidentitiesdlg.h" @@ -92,6 +93,26 @@ class NetworksSettingsPage : public SettingsPage { void saveToNetworkInfo(NetworkInfo &); }; + +class NetworkAddDlg : public QDialog { + Q_OBJECT + + public: + NetworkAddDlg(const QStringList &existing = QStringList(), QWidget *parent = 0); + + NetworkInfo networkInfo() const; + + private slots: + void setButtonStates(); + + private: + Ui::NetworkAddDlg ui; + + QString networksFilePath; + QStringList existing; +}; + + class NetworkEditDlg : public QDialog { Q_OBJECT @@ -110,7 +131,6 @@ class NetworkEditDlg : public QDialog { }; - class ServerEditDlg : public QDialog { Q_OBJECT diff --git a/src/qtui/settingspages/settingspages.inc b/src/qtui/settingspages/settingspages.inc index fd9819f7..533d6cb4 100644 --- a/src/qtui/settingspages/settingspages.inc +++ b/src/qtui/settingspages/settingspages.inc @@ -6,4 +6,4 @@ set(SETTINGSPAGES aliases appearance backlog bufferview color chatmonitor fonts # Specify additional files (e.g. for subdialogs) here! set(SP_SOURCES aliasesmodel.cpp notificationssettingspage.cpp) set(SP_HEADERS aliasesmodel.h notificationssettingspage.h previewbufferview.h) -set(SP_FORMS buffervieweditdlg.ui createidentitydlg.ui saveidentitiesdlg.ui networkeditdlg.ui nickeditdlg.ui servereditdlg.ui) +set(SP_FORMS buffervieweditdlg.ui createidentitydlg.ui saveidentitiesdlg.ui networkadddlg.ui networkeditdlg.ui nickeditdlg.ui servereditdlg.ui)