X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fmainpage.cpp;h=373e7076acdfa3b30d80a0956068177d57e7af5d;hb=8fe8accd73abf77ab21d2d1c1346d2bc5c4de2ff;hp=a0e5f1178b4543fa8f1076b8b308e69d64a3e3f1;hpb=66e6d26b38fb6e4528654e6525d205e9e9ca3243;p=quassel.git diff --git a/src/qtui/mainpage.cpp b/src/qtui/mainpage.cpp index a0e5f117..373e7076 100644 --- a/src/qtui/mainpage.cpp +++ b/src/qtui/mainpage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2016 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -37,15 +37,30 @@ MainPage::MainPage(QWidget *parent) : QWidget(parent) layout->addWidget(label); if (Quassel::runMode() != Quassel::Monolithic) { - QPushButton *connectButton = new QPushButton(QIcon::fromTheme("network-connect"), tr("Connect to Core...")); - connect(connectButton, &QPushButton::clicked, [this](){ - CoreConnectDlg dlg(this); - if (dlg.exec() == QDialog::Accepted) { - AccountId accId = dlg.selectedAccount(); - if (accId.isValid()) - Client::coreConnection()->connectToCore(accId); - } - }); - layout->addWidget(connectButton); + _connectButton = new QPushButton(QIcon::fromTheme("network-connect"), tr("Connect to Core...")); + _connectButton->setEnabled(Client::coreConnection()->state() == CoreConnection::Disconnected); + + connect(Client::coreConnection(), SIGNAL(stateChanged(CoreConnection::ConnectionState)), this, SLOT(coreConnectionStateChanged())); + connect(_connectButton, SIGNAL(clicked(bool)), this, SLOT(showCoreConnectionDlg())); + layout->addWidget(_connectButton); + } +} + +void MainPage::showCoreConnectionDlg() +{ + CoreConnectDlg dlg(this); + if (dlg.exec() == QDialog::Accepted) { + AccountId accId = dlg.selectedAccount(); + if (accId.isValid()) + Client::coreConnection()->connectToCore(accId); + } +} + +void MainPage::coreConnectionStateChanged() +{ + if (Client::coreConnection()->state() == CoreConnection::Disconnected) { + _connectButton->setEnabled(true); + } else { + _connectButton->setDisabled(true); } }