Make SettingsPages a little bit clearer to use.
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 24 Jan 2008 00:29:44 +0000 (00:29 +0000)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 24 Jan 2008 00:29:44 +0000 (00:29 +0000)
12 files changed:
Quassel.kdevelop.filelist
dev-notes/obsolete/coreconnectdlgold.cpp [new file with mode: 0644]
dev-notes/obsolete/coreconnectdlgold.h [new file with mode: 0644]
src/qtui/settingspages/fontssettingspage.cpp
src/qtui/settingspages/identitiessettingspage.cpp
src/qtui/settingspages/networkeditdlgnew.ui [new file with mode: 0644]
src/qtui/settingspages/networkssettingspage.cpp
src/qtui/settingspages/networkssettingspage.h
src/qtui/settingspages/nickeditdlgnew.ui
src/qtui/settingspages/settingspages.pri
src/uisupport/settingspage.cpp
src/uisupport/settingspage.h

index 79bc51b..da5eff1 100644 (file)
@@ -185,11 +185,13 @@ src/qtui/settingspages/fontssettingspage.ui
 src/qtui/settingspages/identitiessettingspage.cpp
 src/qtui/settingspages/identitiessettingspage.h
 src/qtui/settingspages/identitiessettingspage.ui
 src/qtui/settingspages/identitiessettingspage.cpp
 src/qtui/settingspages/identitiessettingspage.h
 src/qtui/settingspages/identitiessettingspage.ui
+src/qtui/settingspages/networkeditdlgnew.ui
 src/qtui/settingspages/networkssettingspage.cpp
 src/qtui/settingspages/networkssettingspage.h
 src/qtui/settingspages/networkssettingspage.ui
 src/qtui/settingspages/nickeditdlgnew.ui
 src/qtui/settingspages/saveidentitiesdlg.ui
 src/qtui/settingspages/networkssettingspage.cpp
 src/qtui/settingspages/networkssettingspage.h
 src/qtui/settingspages/networkssettingspage.ui
 src/qtui/settingspages/nickeditdlgnew.ui
 src/qtui/settingspages/saveidentitiesdlg.ui
+src/qtui/settingspages/servereditdlgnew.ui
 src/qtui/settingspages/settingspages.pri
 src/qtui/topicwidget.cpp
 src/qtui/topicwidget.h
 src/qtui/settingspages/settingspages.pri
 src/qtui/topicwidget.cpp
 src/qtui/topicwidget.h
diff --git a/dev-notes/obsolete/coreconnectdlgold.cpp b/dev-notes/obsolete/coreconnectdlgold.cpp
new file mode 100644 (file)
index 0000000..643b0ff
--- /dev/null
@@ -0,0 +1,336 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   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) version 3.                                           *
+ *                                                                         *
+ *   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 <QtGui>
+#include "coreconnectdlg.h"
+#include "client.h"
+#include "clientsettings.h"
+#include "configwizard.h"
+#include "global.h"
+
+CoreConnectDlg::CoreConnectDlg(QWidget *parent, bool /*doAutoConnect*/) : QDialog(parent) {
+  ui.setupUi(this); //qDebug() << "new dlg";
+
+  setAttribute(Qt::WA_DeleteOnClose);
+
+  coreState = 0;
+  /* We show ui.internalCore in any case, because we might want to run as monolithic client anyway at another time
+  if(Global::runMode == Global::Monolithic) {
+    connect(ui.internalCore, SIGNAL(toggled(bool)), ui.hostEdit, SLOT(setDisabled(bool)));
+    connect(ui.internalCore, SIGNAL(toggled(bool)), ui.port, SLOT(setDisabled(bool)));
+    ui.internalCore->setChecked(true);
+  } else {
+    //ui.internalCore->hide();
+  }
+  */
+  connect(ui.newAccount, SIGNAL(clicked()), this, SLOT(createAccount()));
+  connect(ui.delAccount, SIGNAL(clicked()), this, SLOT(removeAccount()));
+  connect(ui.buttonBox1, SIGNAL(accepted()), this, SLOT(doConnect()));
+  connect(ui.hostEdit, SIGNAL(textChanged(const QString &)), this, SLOT(checkInputValid()));
+  connect(ui.userEdit, SIGNAL(textChanged(const QString &)), this, SLOT(checkInputValid()));
+  connect(ui.internalCore, SIGNAL(toggled(bool)), this, SLOT(checkInputValid()));
+  connect(ui.internalCore, SIGNAL(toggled(bool)), ui.hostEdit, SLOT(setDisabled(bool)));
+  connect(ui.internalCore, SIGNAL(toggled(bool)), ui.port, SLOT(setDisabled(bool)));
+  connect(ui.accountList, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(accountChanged(const QString &)));
+  connect(ui.autoConnect, SIGNAL(clicked(bool)), this, SLOT(autoConnectToggled(bool)));
+
+  connect(Client::instance(), SIGNAL(coreConnectionMsg(const QString &)), ui.connectionStatus, SLOT(setText(const QString &)));
+  connect(Client::instance(), SIGNAL(coreConnectionProgress(uint, uint)), this, SLOT(updateProgressBar(uint, uint)));
+  connect(Client::instance(), SIGNAL(coreConnectionError(QString)), this, SLOT(coreConnectionError(QString)));
+  connect(Client::instance(), SIGNAL(connected()), this, SLOT(coreConnected()));
+  
+  connect(Client::instance(), SIGNAL(showConfigWizard(const QVariantMap &)), this, SLOT(showConfigWizard(const QVariantMap &)));
+
+  AccountSettings s;
+  QString lastacc = s.lastAccount();
+  ui.accountList->addItems(s.knownAccounts());
+  if(!ui.accountList->count()) {
+    //if(doAutoConnect) reject();
+
+    setAccountEditEnabled(false);
+    QString newacc = QInputDialog::getText(this, tr("Create Account"), tr(
+                                           "In order to connect to a Quassel Core, you need to create an account.<br>"
+                                           "Please enter a name for this account now:"), QLineEdit::Normal, tr("Default"));
+    if(!newacc.isEmpty()) {
+      ui.accountList->addItem(newacc);
+      ui.hostEdit->setText("localhost");
+      ui.port->setValue(Global::defaultPort);
+      ui.internalCore->setChecked(false);
+      setAccountEditEnabled(true);
+    }
+    /*
+    // FIXME We create a default account here that just connects to the internal core
+    curacc = "Default";
+    ui.accountList->addItem("Default");
+    ui.internalCore->setChecked(true);
+    ui.userEdit->setText("Default");
+    ui.passwdEdit->setText("password");
+    ui.rememberPasswd->setChecked(true);
+    accountChanged(curacc);
+    ui.passwdEdit->setText("password");
+    ui.accountList->setCurrentIndex(0);
+    ui.autoConnect->setChecked(true);
+    autoConnectToggled(true);
+    */
+  } else {
+    if(!lastacc.isEmpty()) {
+      //if(doAutoConnect) { qDebug() << "auto";
+      //  AccountSettings s;
+      //  int idx = ui.accountList->findText(s.autoConnectAccount());
+      //  if(idx < 0) reject();
+      //  else {
+      //    ui.accountList->setCurrentIndex(idx);
+      //    doConnect();
+      //  }
+      //} else {
+        int idx = ui.accountList->findText(lastacc);
+        ui.accountList->setCurrentIndex(idx);
+      //}
+    }
+  }
+}
+
+CoreConnectDlg::~CoreConnectDlg() {
+  //qDebug() << "destroy";
+}
+
+void CoreConnectDlg::setAccountEditEnabled(bool en) {
+  ui.accountList->setEnabled(en);
+  ui.hostEdit->setEnabled(en && !ui.internalCore->isChecked());
+  ui.userEdit->setEnabled(en);
+  ui.passwdEdit->setEnabled(en);
+  ui.port->setEnabled(en && !ui.internalCore->isChecked());
+  ui.editAccount->setEnabled(en);
+  ui.delAccount->setEnabled(en);
+  ui.internalCore->setEnabled(en);
+  ui.rememberPasswd->setEnabled(en);
+  ui.autoConnect->setEnabled(en);
+  ui.buttonBox1->button(QDialogButtonBox::Ok)->setEnabled(en && checkInputValid());
+}
+
+void CoreConnectDlg::accountChanged(const QString &text) {
+  AccountSettings s;
+  if(!curacc.isEmpty()) {
+    QVariantMap oldAcc;
+    oldAcc["User"] = ui.userEdit->text();
+    oldAcc["Host"] = ui.hostEdit->text();
+    oldAcc["Port"] = ui.port->value();
+    oldAcc["InternalCore"] = ui.internalCore->isChecked();
+    if(ui.rememberPasswd->isChecked()) oldAcc["Password"] = ui.passwdEdit->text();
+    s.setValue(curacc, "AccountData", oldAcc);
+  }
+  ui.autoConnect->setChecked(false);
+  if(!text.isEmpty()) { // empty text: just save stuff
+    curacc = text;
+    s.setLastAccount(curacc);
+    QVariantMap newAcc = s.value(curacc, "AccountData").toMap();
+    ui.userEdit->setText(newAcc["User"].toString());
+    ui.hostEdit->setText(newAcc["Host"].toString());
+    ui.port->setValue(newAcc["Port"].toInt());
+    ui.internalCore->setChecked(newAcc["InternalCore"].toBool());
+    if(newAcc.contains("Password")) {
+      ui.passwdEdit->setText(newAcc["Password"].toString());
+      ui.rememberPasswd->setChecked(true);
+    } else ui.rememberPasswd->setChecked(false);
+    if(s.autoConnectAccount() == curacc) ui.autoConnect->setChecked(true);
+  }
+}
+
+void CoreConnectDlg::autoConnectToggled(bool autoConnect) {
+  AccountSettings s;
+  if(autoConnect) s.setAutoConnectAccount(curacc);
+  else s.setAutoConnectAccount("");
+}
+
+bool CoreConnectDlg::checkInputValid() {
+  bool res = (ui.internalCore->isChecked() || ui.hostEdit->text().count()) && ui.userEdit->text().count();
+  ui.buttonBox1->button(QDialogButtonBox::Ok)->setEnabled(res);
+  return res;
+}
+
+void CoreConnectDlg::createAccount() {
+  QString accname = QInputDialog::getText(this, tr("Create Account"), tr("Please enter a name for the new account:"));
+  if(accname.isEmpty()) return;
+  if(ui.accountList->findText(accname) >= 0) {
+    QMessageBox::warning(this, tr("Account name already exists!"), tr("An account named '%1' already exists, and account names must be unique!").arg(accname));
+    return;
+  }
+  QVariantMap defdata;
+  ui.accountList->addItem(accname);
+  ui.accountList->setCurrentIndex(ui.accountList->findText(accname));
+  setAccountEditEnabled(true);
+}
+
+void CoreConnectDlg::removeAccount() {
+  QString acc = ui.accountList->currentText();
+  int res = QMessageBox::warning(this, tr("Delete account?"), tr("Do you really want to delete the data for the account '%1'?<br>"
+                                                       "Note that this only affects your local account settings and will not remove "
+                                                       "any data from the core.").arg(acc),
+                             QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
+  if(res == QMessageBox::Yes) {
+    AccountSettings s;
+    s.removeAccount(acc);
+    curacc = "";
+    ui.accountList->removeItem(ui.accountList->findText(acc));
+    if(!ui.accountList->count()) setAccountEditEnabled(false);
+  }
+}
+
+bool CoreConnectDlg::willDoInternalAutoConnect() {
+  AccountSettings s;
+  if(Global::runMode != Global::Monolithic) return false;
+  if(ui.autoConnect->isChecked() && s.autoConnectAccount() == curacc && ui.internalCore->isChecked()) {
+    return true;
+  }
+  return false;
+}
+
+void CoreConnectDlg::doAutoConnect() {
+  AccountSettings s;
+  if(s.autoConnectAccount() == curacc) {
+    doConnect();
+  }
+}
+
+void CoreConnectDlg::doConnect() {
+  accountChanged(); // save current account info
+  QVariantMap conninfo;
+  ui.stackedWidget->setCurrentIndex(1);
+  if(ui.internalCore->isChecked()) {
+    // FIXME
+    coreConnectionError(tr("Can't connect to internal core at the moment [serious breakage due to switch to dynamic signals]. Please check back later."));
+    return;
+    if(Global::runMode != Global::Monolithic) {
+      coreConnectionError(tr("Can't connect to internal core, since we are running as a standalone GUI!"));
+      return;
+    }
+    ui.connectionGroupBox->setTitle(tr("Connecting to internal core"));
+    ui.connectionProgress->hide();
+  } else {
+    ui.connectionGroupBox->setTitle(tr("Connecting to %1").arg(ui.hostEdit->text()));
+    conninfo["Host"] = ui.hostEdit->text();
+    conninfo["Port"] = ui.port->value();
+  }
+  conninfo["User"] = ui.userEdit->text();
+  conninfo["Password"] = ui.passwdEdit->text();
+  ui.profileLabel->hide(); ui.guiProfile->hide();
+  ui.newGuiProfile->hide(); ui.alwaysUseProfile->hide();
+  ui.connectionProgress->show();
+  try {
+    Client::instance()->connectToCore(conninfo);
+  } catch(Exception e) {
+    QString msg;
+    //if(!e.msg().isEmpty()) msg = tr("<br>%1").arg(e.msg()); // FIXME throw more detailed (vulgo: any) error msg
+    coreConnectionError(tr("Invalid user or password. Pleasy try again.%1").arg(msg));
+    //QMessageBox::warning(this, tr("Unknown account"), tr("Invalid user or password. Pleasy try again.%1").arg(msg));
+    //cancelConnect();
+    return;
+  }
+}
+
+void CoreConnectDlg::cancelConnect() {
+  ui.stackedWidget->setCurrentIndex(0);
+}
+
+void CoreConnectDlg::setStartState() { /*
+  ui.hostName->show(); ui.hostPort->show(); ui.hostLabel->show(); ui.portLabel->show();
+  ui.statusText->setText(tr("Connect to Quassel Core running on:"));
+  ui.buttonBox->button(QDialogButtonBox::Ok)->show();
+  ui.hostName->setEnabled(true); ui.hostPort->setEnabled(true);
+  ui.hostName->setSelection(0, ui.hostName->text().length()); */
+  ui.stackedWidget->setCurrentIndex(0);
+}
+
+void CoreConnectDlg::hostEditChanged(QString /*txt*/) {
+  //ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(txt.length());
+}
+
+void CoreConnectDlg::hostSelected() { /*
+  ui.hostName->hide(); ui.hostPort->hide(); ui.hostLabel->hide(); ui.portLabel->hide();
+  ui.statusText->setText(tr("Connecting to %1:%2" ).arg(ui.hostName->text()).arg(ui.hostPort->value()));
+  ui.buttonBox->button(QDialogButtonBox::Ok)->hide();
+  connect(ClientProxy::instance(), SIGNAL(coreConnected()), this, SLOT(coreConnected()));
+  connect(ClientProxy::instance(), SIGNAL(coreConnectionError(QString)), this, SLOT(coreConnectionError(QString)));
+  Client::instance()->connectToCore(ui.hostName->text(), ui.hostPort->value());
+*/
+}
+
+void CoreConnectDlg::coreConnected() { /*
+  ui.hostLabel->hide(); ui.hostName->hide(); ui.portLabel->hide(); ui.hostPort->hide();
+  ui.statusText->setText(tr("Synchronizing..."));
+  QSettings s;
+  s.setValue("GUI/CoreHost", ui.hostName->text());
+  s.setValue("GUI/CorePort", ui.hostPort->value());
+  s.setValue("GUI/CoreAutoConnect", ui.autoConnect->isChecked());
+  connect(ClientProxy::instance(), SIGNAL(recvPartialItem(quint32, quint32)), this, SLOT(updateProgressBar(quint32, quint32)));
+  connect(ClientProxy::instance(), SIGNAL(csCoreState(QVariant)), this, SLOT(recvCoreState(QVariant)));
+  ui.progressBar->show();
+  QVariantMap initmsg;
+  initmsg["GUIProtocol"] = GUI_PROTOCOL;
+  // FIXME guiProxy->send(GS_CLIENT_INIT, QVariant(initmsg)); */
+  ui.connectionStatus->setText(tr("Connected to core."));
+  accept();
+}
+
+void CoreConnectDlg::coreConnectionError(QString err) {
+  ui.stackedWidget->setCurrentIndex(0);
+  show(); // just in case we started hidden
+  QMessageBox::warning(this, tr("Connection Error"), tr("<b>Could not connect to Quassel Core!</b><br>\n") + err, QMessageBox::Retry);
+  //disconnect(ClientProxy::instance(), 0, this, 0); FIXME?
+  //ui.autoConnect->setChecked(false);
+  setStartState();
+}
+
+void CoreConnectDlg::updateProgressBar(uint partial, uint total) {
+  ui.connectionProgress->setMaximum(total);
+  ui.connectionProgress->setValue(partial);
+  //qDebug() << "progress:" << partial << total;
+}
+
+void CoreConnectDlg::recvCoreState(QVariant state) {
+  //ui.progressBar->hide();
+  coreState = state;
+  accept();
+}
+
+QVariant CoreConnectDlg::getCoreState() {
+  return coreState;
+}
+
+void CoreConnectDlg::showConfigWizard(const QVariantMap &coredata) {
+  QStringList storageProviders = coredata["StorageProviders"].toStringList();
+  ConfigWizard *wizard = new ConfigWizard(storageProviders, this);
+  wizard->exec();
+  QVariantMap reply;
+  reply["GuiProtocol"] = GUI_PROTOCOL;
+  reply["HasSettings"] = true;
+  reply["User"] = wizard->field("adminuser.name").toString();
+  reply["Password"] = wizard->field("adminuser.password").toString();
+  QString sp = storageProviders.value(wizard->field("storage.provider").toInt());
+  reply["Type"] = sp;
+  if (sp.compare("Sqlite", Qt::CaseInsensitive)) {
+    reply["Host"] = wizard->field("storage.host").toString();
+    reply["Port"] = wizard->field("storage.port").toString();
+    reply["Database"] = wizard->field("storage.database").toString();
+    reply["User"] = wizard->field("storage.user").toString();
+    reply["Password"] = wizard->field("storage.password").toString();
+  }
+  Client::instance()->setCoreConfiguration(reply);
+}
diff --git a/dev-notes/obsolete/coreconnectdlgold.h b/dev-notes/obsolete/coreconnectdlgold.h
new file mode 100644 (file)
index 0000000..3b6f584
--- /dev/null
@@ -0,0 +1,69 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   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) version 3.                                           *
+ *                                                                         *
+ *   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 _CORECONNECTDLG_H
+#define _CORECONNECTDLG_H
+
+#include "ui_coreconnectdlg.h"
+
+class CoreConnectDlg: public QDialog {
+  Q_OBJECT
+
+  public:
+    CoreConnectDlg(QWidget *parent, bool doAutoConnect = false);
+    ~CoreConnectDlg();
+    QVariant getCoreState();
+
+    bool willDoInternalAutoConnect();
+    
+  public slots:
+    void doAutoConnect();
+
+  private slots:
+    void createAccount();
+    void removeAccount();
+    void accountChanged(const QString & = "");
+    void setAccountEditEnabled(bool);
+    void autoConnectToggled(bool);
+    bool checkInputValid();
+    void hostEditChanged(QString);
+    void hostSelected();
+    void doConnect();
+
+    void coreConnected();
+    void coreConnectionError(QString);
+    //void coreConnectionMsg(const QString &);
+    //void coreConnectionProgress(uint partial, uint total);
+    void updateProgressBar(uint partial, uint total);
+    void recvCoreState(QVariant);
+    
+    void showConfigWizard(const QVariantMap &coredata);
+
+  private:
+    Ui::CoreConnectDlg ui;
+    QVariant coreState;
+
+    void cancelConnect();
+    void setStartState();
+    QVariantMap accountData;
+    QString curacc;
+};
+
+#endif
index b82c72f..38c149c 100644 (file)
@@ -69,7 +69,7 @@ void FontsSettingsPage::defaults() {
 
 void FontsSettingsPage::load() {
   load(Settings::Custom);
 
 void FontsSettingsPage::load() {
   load(Settings::Custom);
-  changeState(false);
+  setChangedState(false);
 }
 
 void FontsSettingsPage::load(Settings::Mode mode) {
 }
 
 void FontsSettingsPage::load(Settings::Mode mode) {
@@ -92,7 +92,7 @@ void FontsSettingsPage::load(Settings::Mode mode) {
     ui.checkTimestamp->setChecked(false);
   }
 
     ui.checkTimestamp->setChecked(false);
   }
 
-  changeState(false);
+  setChangedState(false);
 }
 
 void FontsSettingsPage::save() {
 }
 
 void FontsSettingsPage::save() {
@@ -111,11 +111,11 @@ void FontsSettingsPage::save() {
   else timestampFormat.setFont(chatFormat.font());
   QtUi::style()->setFormat(UiStyle::Timestamp, timestampFormat, Settings::Custom);
 
   else timestampFormat.setFont(chatFormat.font());
   QtUi::style()->setFormat(UiStyle::Timestamp, timestampFormat, Settings::Custom);
 
-  changeState(false);
+  setChangedState(false);
 }
 
 void FontsSettingsPage::widgetHasChanged() {
 }
 
 void FontsSettingsPage::widgetHasChanged() {
-  if(!hasChanged()) changeState(true);
+  if(!hasChanged()) setChangedState(true);
 }
 
 void FontsSettingsPage::initLabel(QLabel *label, const QFont &font) {
 }
 
 void FontsSettingsPage::initLabel(QLabel *label, const QFont &font) {
index 1a2bfc1..5aa1712 100644 (file)
@@ -120,7 +120,7 @@ void IdentitiesSettingsPage::save() {
   }
   changedIdentities.clear();
   deletedIdentities.clear();
   }
   changedIdentities.clear();
   deletedIdentities.clear();
-  changeState(false);
+  setChangedState(false);
   setEnabled(true);
 }
 
   setEnabled(true);
 }
 
@@ -136,12 +136,12 @@ void IdentitiesSettingsPage::load() {
   foreach(IdentityId id, Client::identityIds()) {
     clientIdentityCreated(id);
   }
   foreach(IdentityId id, Client::identityIds()) {
     clientIdentityCreated(id);
   }
-  changeState(false);
+  setChangedState(false);
 }
 
 void IdentitiesSettingsPage::widgetHasChanged() {
   bool changed = testHasChanged();
 }
 
 void IdentitiesSettingsPage::widgetHasChanged() {
   bool changed = testHasChanged();
-  if(changed != hasChanged()) changeState(changed);
+  if(changed != hasChanged()) setChangedState(changed);
 }
 
 bool IdentitiesSettingsPage::testHasChanged() {
 }
 
 bool IdentitiesSettingsPage::testHasChanged() {
diff --git a/src/qtui/settingspages/networkeditdlgnew.ui b/src/qtui/settingspages/networkeditdlgnew.ui
new file mode 100644 (file)
index 0000000..c072133
--- /dev/null
@@ -0,0 +1,90 @@
+<ui version="4.0" >
+ <class>NetworkEditDlgNew</class>
+ <widget class="QDialog" name="NetworkEditDlgNew" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>254</width>
+    <height>93</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" >
+   <item>
+    <layout class="QVBoxLayout" >
+     <item>
+      <widget class="QLabel" name="label" >
+       <property name="text" >
+        <string>Please enter a network name:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLineEdit" name="networkEdit" />
+     </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>
+     <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>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>NetworkEditDlgNew</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>NetworkEditDlgNew</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>
index 2c18255..c2dd3fb 100644 (file)
@@ -61,7 +61,7 @@ void NetworksSettingsPage::load() {
     clientNetworkAdded(netid);
   }
   ui.networkList->setCurrentRow(0);
     clientNetworkAdded(netid);
   }
   ui.networkList->setCurrentRow(0);
-  changeState(false);
+  setChangedState(false);
 }
 
 void NetworksSettingsPage::reset() {
 }
 
 void NetworksSettingsPage::reset() {
@@ -82,7 +82,7 @@ void NetworksSettingsPage::reset() {
 
 void NetworksSettingsPage::widgetHasChanged() {
   bool changed = testHasChanged();
 
 void NetworksSettingsPage::widgetHasChanged() {
   bool changed = testHasChanged();
-  if(changed != hasChanged()) changeState(changed);
+  if(changed != hasChanged()) setChangedState(changed);
 }
 
 bool NetworksSettingsPage::testHasChanged() {
 }
 
 bool NetworksSettingsPage::testHasChanged() {
@@ -245,9 +245,42 @@ void NetworksSettingsPage::on_networkList_itemSelectionChanged() {
   setWidgetStates();
 }
 
   setWidgetStates();
 }
 
+void NetworksSettingsPage::on_addNetwork_clicked() {
 
 
 
 
 
 
+}
+
+/**************************************************************************
+ * NetworkEditDlg
+ *************************************************************************/
+
+NetworkEditDlgNew::NetworkEditDlgNew(const QString &old, const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) {
+  ui.setupUi(this);
+
+  if(old.isEmpty()) {
+    // new network
+    setWindowTitle(tr("Add Network"));
+    on_networkEdit_textChanged(""); // disable ok button
+  } else ui.networkEdit->setText(old);
+}
+
+QString NetworkEditDlgNew::networkName() const {
+  return ui.networkEdit->text();
+
+}
+
+void NetworkEditDlgNew::on_networkEdit_textChanged(const QString &text) {
+  ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text));
+}
+
+
+/**************************************************************************
+ * ServerEditDlg
+ *************************************************************************/
+
+//ServerEditDlg::
+
 
 
 
 
 
 
index f58d900..00c4532 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "settingspage.h"
 #include "ui_networkssettingspage.h"
 
 #include "settingspage.h"
 #include "ui_networkssettingspage.h"
+#include "ui_networkeditdlgnew.h"
 
 #include "network.h"
 #include "types.h"
 
 #include "network.h"
 #include "types.h"
@@ -56,6 +57,7 @@ class NetworksSettingsPage : public SettingsPage {
     void clientIdentityUpdated();
 
     void on_networkList_itemSelectionChanged();
     void clientIdentityUpdated();
 
     void on_networkList_itemSelectionChanged();
+    void on_addNetwork_clicked();
 
   private:
     Ui::NetworksSettingsPage ui;
 
   private:
     Ui::NetworksSettingsPage ui;
@@ -69,7 +71,39 @@ class NetworksSettingsPage : public SettingsPage {
     bool testHasChanged();
     void insertNetwork(NetworkId);
     QListWidgetItem *networkItem(NetworkId) const;
     bool testHasChanged();
     void insertNetwork(NetworkId);
     QListWidgetItem *networkItem(NetworkId) const;
+};
+
+class NetworkEditDlgNew : public QDialog {
+  Q_OBJECT
+
+  public:
+    NetworkEditDlgNew(const QString &old, const QStringList &existing = QStringList(), QWidget *parent = 0);
+
+    QString networkName() const;
+
+  private slots:
+    void on_networkEdit_textChanged(const QString &);
+
+  private:
+    Ui::NetworkEditDlgNew ui;
+
+    QStringList existing;
+};
+
+
 
 
+class ServerEditDlgNew : public QDialog {
+  Q_OBJECT
+
+  public:
+    ServerEditDlgNew(const QVariantMap &serverData = QVariantMap(), QWidget *parent = 0);
+
+    QVariantMap serverData() const;
+
+  private:
+    QVariantMap _serverData;
 };
 
 };
 
+
+
 #endif
 #endif
index c1b3be4..0ab92c9 100644 (file)
@@ -5,7 +5,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>285</width>
+    <width>262</width>
     <height>93</height>
    </rect>
   </property>
     <height>93</height>
    </rect>
   </property>
        </property>
       </widget>
      </item>
        </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>
      <item>
       <widget class="QDialogButtonBox" name="buttonBox" >
        <property name="orientation" >
      <item>
       <widget class="QDialogButtonBox" name="buttonBox" >
        <property name="orientation" >
      </item>
     </layout>
    </item>
      </item>
     </layout>
    </item>
-   <item>
-    <spacer>
-     <property name="orientation" >
-      <enum>Qt::Vertical</enum>
-     </property>
-     <property name="sizeHint" >
-      <size>
-       <width>277</width>
-       <height>16</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
   </layout>
  </widget>
  <resources/>
   </layout>
  </widget>
  <resources/>
index 7b14b4b..8164574 100644 (file)
@@ -5,4 +5,4 @@ SETTINGSPAGES = fonts identities networks
 # Specify additional files (e.g. for subdialogs) here!
 SP_SRCS =
 SP_HDRS =
 # Specify additional files (e.g. for subdialogs) here!
 SP_SRCS =
 SP_HDRS =
-SP_FRMS = createidentitydlg.ui saveidentitiesdlg.ui nickeditdlgnew.ui servereditdlgnew.ui
+SP_FRMS = createidentitydlg.ui saveidentitiesdlg.ui networkeditdlgnew.ui nickeditdlgnew.ui servereditdlgnew.ui
index 37ac416..7808a74 100644 (file)
@@ -51,10 +51,10 @@ bool SettingsPage::aboutToSave() {
 }
 
 void SettingsPage::changed() {
 }
 
 void SettingsPage::changed() {
-  changeState(true);
+  setChangedState(true);
 }
 
 }
 
-void SettingsPage::changeState(bool hasChanged) {
+void SettingsPage::setChangedState(bool hasChanged) {
   if(hasChanged != _changed) {
     _changed = hasChanged;
     emit changed(hasChanged);
   if(hasChanged != _changed) {
     _changed = hasChanged;
     emit changed(hasChanged);
index 247efb1..f58cb37 100644 (file)
 #include <QWidget>
 
 //! A SettingsPage is a page in the settings dialog.
 #include <QWidget>
 
 //! A SettingsPage is a page in the settings dialog.
+/** The SettingsDlg provides suitable standard buttons, such as Ok, Apply, Cancel, Restore Defaults and Reset.
+ *  Some pages might also be used in standalone dialogs or other containers. A SettingsPage provides suitable
+ *  slots and signals to allow interaction with the container.
+ */
 class SettingsPage : public QWidget {
   Q_OBJECT
 
   public:
     SettingsPage(const QString &category, const QString &name, QWidget *parent = 0);
     virtual ~SettingsPage() {};
 class SettingsPage : public QWidget {
   Q_OBJECT
 
   public:
     SettingsPage(const QString &category, const QString &name, QWidget *parent = 0);
     virtual ~SettingsPage() {};
+
+    //! The category of this settings page.
     virtual QString category() const;
     virtual QString category() const;
+
+    //! The title of this settings page.
     virtual QString title() const;
     virtual QString title() const;
+
+    //! Derived classes need to define this and return true if they have default settings.
+    /** If this method returns true, the "Restore Defaults" button in the SettingsDlg is
+     *  enabled. You also need to provide an implementation of defaults() then.
+     *
+     * The default implementation returns false.
+     */
     virtual bool hasDefaults() const;
 
     virtual bool hasDefaults() const;
 
+    //! Check if there are changes in the page, compared to the state saved in permanent storage.
     bool hasChanged() const;
 
     //! Called immediately before save() is called.
     bool hasChanged() const;
 
     //! Called immediately before save() is called.
@@ -43,17 +59,24 @@ class SettingsPage : public QWidget {
     virtual bool aboutToSave();
 
   public slots:
     virtual bool aboutToSave();
 
   public slots:
+    //! Save settings to permanent storage.
     virtual void save() = 0;
     virtual void save() = 0;
+
+    //! Load settings from permanent storage, overriding any changes the user might have made in the dialog.
     virtual void load() = 0;
     virtual void load() = 0;
+
+    //! Restore defaults, overriding any changes the user might have made in the dialog.
+    /** The default implementation does nothing.
+     */
     virtual void defaults();
 
   protected slots:
     virtual void defaults();
 
   protected slots:
-    //! Calling this slot is equivalent to calling changeState(true).
+    //! Calling this slot is equivalent to calling setChangedState(true).
     void changed();
 
   protected:
     //! This should be called whenever the widget state changes from unchanged to change or the other way round.
     void changed();
 
   protected:
     //! This should be called whenever the widget state changes from unchanged to change or the other way round.
-    void changeState(bool hasChanged = true);
+    void setChangedState(bool hasChanged = true);
 
   signals:
     //! Emitted whenever the widget state changes.
 
   signals:
     //! Emitted whenever the widget state changes.