From: Manuel Nickschas Date: Mon, 23 Nov 2009 08:52:28 +0000 (+0100) Subject: Resurrect CoreConnectDlg X-Git-Tag: 0.6-beta1~160 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=bf86381e85cd97ef04a9dc45c2b1a063035391fa Resurrect CoreConnectDlg This time it's just a thin wrapper around the settingspage, so it doesn't suck. --- diff --git a/src/client/coreconnection.cpp b/src/client/coreconnection.cpp index 9c8889c8..863f1bd8 100644 --- a/src/client/coreconnection.cpp +++ b/src/client/coreconnection.cpp @@ -239,6 +239,9 @@ void CoreConnection::reconnectToCore() { } bool CoreConnection::connectToCore(AccountId accId) { + if(isConnected()) + return false; + CoreAccountSettings s; if(!accId.isValid()) { diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index a4bda523..6e9626e9 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -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 index 00000000..10ee20f9 --- /dev/null +++ b/src/qtui/coreconnectdlg.cpp @@ -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 +#include + +#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 index 00000000..f7d29df6 --- /dev/null +++ b/src/qtui/coreconnectdlg.h @@ -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 + +#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 diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 6871ae01..522766b7 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -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(); diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index 966ee0ca..a42c3f8b 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -119,6 +119,7 @@ class MainWin void showAboutDlg(); void showChannelList(NetworkId netId = NetworkId()); void startInternalCore(); + void showCoreConnectionDlg(); void showCoreInfoDlg(); void showAwayLog(); void showSettingsDlg(); diff --git a/src/qtui/settingspages/coreaccountsettingspage.cpp b/src/qtui/settingspages/coreaccountsettingspage.cpp index 72ac2096..0cee7367 100644 --- a/src/qtui/settingspages/coreaccountsettingspage.cpp +++ b/src/qtui/settingspages/coreaccountsettingspage.cpp @@ -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(); +} + +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()); + else + editAccount(index); +} + void CoreAccountSettingsPage::setWidgetStates() { bool selected = ui.accountView->selectionModel()->selectedIndexes().count(); diff --git a/src/qtui/settingspages/coreaccountsettingspage.h b/src/qtui/settingspages/coreaccountsettingspage.h index e552a0b5..6948e85a 100644 --- a/src/qtui/settingspages/coreaccountsettingspage.h +++ b/src/qtui/settingspages/coreaccountsettingspage.h @@ -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();