Resurrect CoreConnectDlg
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 23 Nov 2009 08:52:28 +0000 (09:52 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 28 Nov 2009 23:39:41 +0000 (00:39 +0100)
This time it's just a thin wrapper around the settingspage, so it doesn't suck.

src/client/coreconnection.cpp
src/qtui/CMakeLists.txt
src/qtui/coreconnectdlg.cpp [new file with mode: 0644]
src/qtui/coreconnectdlg.h [new file with mode: 0644]
src/qtui/mainwin.cpp
src/qtui/mainwin.h
src/qtui/settingspages/coreaccountsettingspage.cpp
src/qtui/settingspages/coreaccountsettingspage.h

index 9c8889c..863f1bd 100644 (file)
@@ -239,6 +239,9 @@ void CoreConnection::reconnectToCore() {
 }
 
 bool CoreConnection::connectToCore(AccountId accId) {
+  if(isConnected())
+    return false;
+
   CoreAccountSettings s;
 
   if(!accId.isValid()) {
index a4bda52..6e9626e 100644 (file)
@@ -28,6 +28,7 @@ set(SOURCES
     chatviewsettings.cpp
     columnhandleitem.cpp
     coreconfigwizard.cpp
+    coreconnectdlg.cpp
     coreconnectionstatuswidget.cpp
     coreinfodlg.cpp
     debugbufferviewoverlay.cpp
@@ -73,6 +74,7 @@ set(MOC_HDRS
     chatviewsearchcontroller.h
     columnhandleitem.h
     coreconfigwizard.h
+    coreconnectdlg.h
     coreconnectionstatuswidget.h
     coreinfodlg.h
     debugbufferviewoverlay.h
diff --git a/src/qtui/coreconnectdlg.cpp b/src/qtui/coreconnectdlg.cpp
new file mode 100644 (file)
index 0000000..10ee20f
--- /dev/null
@@ -0,0 +1,62 @@
+/***************************************************************************
+ *   Copyright (C) 2009 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 <QDialogButtonBox>
+#include <QVBoxLayout>
+
+#include "coreconnectdlg.h"
+
+#include "iconloader.h"
+#include "clientsettings.h"
+#include "coreaccountsettingspage.h"
+
+CoreConnectDlg::CoreConnectDlg(QWidget *parent) : QDialog(parent) {
+  _settingsPage = new CoreAccountSettingsPage(this);
+  _settingsPage->setStandAlone(true);
+  _settingsPage->load();
+
+  CoreAccountSettings s;
+  AccountId lastAccount = s.lastAccount();
+  if(lastAccount.isValid())
+    _settingsPage->setSelectedAccount(lastAccount);
+
+  setWindowTitle(tr("Connect to Core"));
+  setWindowIcon(SmallIcon("network-disconnect"));
+
+  QVBoxLayout *layout = new QVBoxLayout(this);
+  layout->addWidget(_settingsPage);
+
+  QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
+  buttonBox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
+  layout->addWidget(buttonBox);
+
+  connect(_settingsPage, SIGNAL(connectToCore(AccountId)), SLOT(accept()));
+  connect(buttonBox, SIGNAL(accepted()), SLOT(accept()));
+  connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
+}
+
+AccountId CoreConnectDlg::selectedAccount() const {
+  return _settingsPage->selectedAccount();
+}
+
+void CoreConnectDlg::accept() {
+  _settingsPage->save();
+  QDialog::accept();
+}
diff --git a/src/qtui/coreconnectdlg.h b/src/qtui/coreconnectdlg.h
new file mode 100644 (file)
index 0000000..f7d29df
--- /dev/null
@@ -0,0 +1,43 @@
+/***************************************************************************
+ *   Copyright (C) 2009 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 <QDialog>
+
+#include "coreaccount.h"
+
+class CoreAccountSettingsPage;
+
+class CoreConnectDlg : public QDialog {
+  Q_OBJECT
+
+public:
+  CoreConnectDlg(QWidget *parent = 0);
+  AccountId selectedAccount() const;
+
+  void accept();
+
+private:
+  CoreAccountSettingsPage *_settingsPage;
+};
+
+#endif
index 6871ae0..522766b 100644 (file)
@@ -55,6 +55,7 @@
 #include "clientbufferviewconfig.h"
 #include "clientbufferviewmanager.h"
 #include "clientignorelistmanager.h"
+#include "coreconnectdlg.h"
 #include "coreconnection.h"
 #include "coreconnectionstatuswidget.h"
 #include "coreinfodlg.h"
@@ -212,12 +213,11 @@ void MainWin::init() {
   // restore locked state of docks
   QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
 
-  if(Quassel::runMode() != Quassel::Monolithic) {
-    //showCoreConnectionDlg(true); // autoconnect if appropriate
-  } else {
-    startInternalCore();
+  CoreConnection *conn = Client::coreConnection();
+  if(!conn->connectToCore()) {
+    // No autoconnect selected (or no accounts)
+    showCoreConnectionDlg();
   }
-  Client::coreConnection()->start();
 }
 
 MainWin::~MainWin() {
@@ -831,6 +831,15 @@ void MainWin::startInternalCore() {
 
 }
 
+void MainWin::showCoreConnectionDlg() {
+  CoreConnectDlg dlg(this);
+  if(dlg.exec() == QDialog::Accepted) {
+    AccountId accId = dlg.selectedAccount();
+    if(accId.isValid())
+      Client::coreConnection()->connectToCore(accId);
+  }
+}
+
 void MainWin::showChannelList(NetworkId netId) {
   ChannelListDlg *channelListDlg = new ChannelListDlg();
 
index 966ee0c..a42c3f8 100644 (file)
@@ -119,6 +119,7 @@ class MainWin
     void showAboutDlg();
     void showChannelList(NetworkId netId = NetworkId());
     void startInternalCore();
+    void showCoreConnectionDlg();
     void showCoreInfoDlg();
     void showAwayLog();
     void showSettingsDlg();
index 72ac209..0cee736 100644 (file)
@@ -28,7 +28,8 @@
 CoreAccountSettingsPage::CoreAccountSettingsPage(QWidget *parent)
 : SettingsPage(tr("Misc"), tr("Core Accounts"), parent),
 _lastAccountId(0),
-_lastAutoConnectId(0)
+_lastAutoConnectId(0),
+_standalone(false)
 {
   ui.setupUi(this);
   initAutoWidgets();
@@ -47,6 +48,10 @@ _lastAutoConnectId(0)
   setWidgetStates();
 }
 
+void CoreAccountSettingsPage::setStandAlone(bool standalone) {
+  _standalone = standalone;
+}
+
 void CoreAccountSettingsPage::load() {
   _model->update(Client::coreAccountModel());
 
@@ -112,6 +117,19 @@ void CoreAccountSettingsPage::rowsInserted(const QModelIndex &index, int start,
   _lastAccountId = _lastAutoConnectId = 0;
 }
 
+AccountId CoreAccountSettingsPage::selectedAccount() const {
+  QModelIndex index = ui.accountView->currentIndex();
+  if(!index.isValid())
+    return 0;
+  return index.data(CoreAccountModel::AccountIdRole).value<AccountId>();
+}
+
+void CoreAccountSettingsPage::setSelectedAccount(AccountId accId) {
+  QModelIndex index = model()->accountIndex(accId);
+  if(index.isValid())
+    ui.accountView->setCurrentIndex(index);
+}
+
 void CoreAccountSettingsPage::on_addAccountButton_clicked() {
   CoreAccountEditDlg dlg(CoreAccount(), this);
   if(dlg.exec() == QDialog::Accepted) {
@@ -126,7 +144,14 @@ void CoreAccountSettingsPage::on_editAccountButton_clicked() {
   if(!idx.isValid())
     return;
 
-  CoreAccountEditDlg dlg(_model->account(idx), this);
+  editAccount(idx);
+}
+
+void CoreAccountSettingsPage::editAccount(const QModelIndex &index) {
+  if(!index.isValid())
+    return;
+
+  CoreAccountEditDlg dlg(_model->account(index), this);
   if(dlg.exec() == QDialog::Accepted) {
     AccountId id = _model->createOrUpdateAccount(dlg.account());
     ui.accountView->setCurrentIndex(model()->accountIndex(id));
@@ -144,6 +169,16 @@ void CoreAccountSettingsPage::on_deleteAccountButton_clicked() {
   }
 }
 
+void CoreAccountSettingsPage::on_accountView_doubleClicked(const QModelIndex &index) {
+  if(!index.isValid())
+    return;
+
+  if(isStandAlone())
+    emit connectToCore(index.data(CoreAccountModel::AccountIdRole).value<AccountId>());
+  else
+    editAccount(index);
+}
+
 void CoreAccountSettingsPage::setWidgetStates() {
   bool selected = ui.accountView->selectionModel()->selectedIndexes().count();
 
index e552a0b..6948e85 100644 (file)
@@ -36,16 +36,26 @@ class CoreAccountSettingsPage : public SettingsPage {
   public:
     CoreAccountSettingsPage(QWidget *parent = 0);
 
-    virtual inline bool hasDefaults() const { return false; }
+    inline bool hasDefaults() const { return false; }
+    inline bool isStandAlone() const { return _standalone; }
+
+    AccountId selectedAccount() const;
 
   public slots:
     void save();
     void load();
 
+    void setSelectedAccount(AccountId accId);
+    void setStandAlone(bool);
+
+signals:
+    void connectToCore(AccountId accId);
+
   private slots:
     void on_addAccountButton_clicked();
     void on_editAccountButton_clicked();
     void on_deleteAccountButton_clicked();
+    void on_accountView_doubleClicked(const QModelIndex &index);
 
     void setWidgetStates();
 
@@ -59,10 +69,13 @@ class CoreAccountSettingsPage : public SettingsPage {
     inline CoreAccountModel *model() const { return _model; }
 
     AccountId _lastAccountId, _lastAutoConnectId;
+    bool _standalone;
 
     virtual QVariant loadAutoWidgetValue(const QString &widgetName);
     virtual void saveAutoWidgetValue(const QString &widgetName, const QVariant &value);
 
+    void editAccount(const QModelIndex &);
+
     void widgetHasChanged();
     bool testHasChanged();