X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtgui%2Fcoreconnectdlg.cpp;fp=src%2Fqtgui%2Fcoreconnectdlg.cpp;h=c0ca4808899ce1b8fe41ae165d3ab7010c016e75;hp=0000000000000000000000000000000000000000;hb=077d44f36d2f5c730283ef6be839aea7dd073d56;hpb=f0a6776fc5102ff6a7fe1469917fe231e4cd3a8a diff --git a/src/qtgui/coreconnectdlg.cpp b/src/qtgui/coreconnectdlg.cpp new file mode 100644 index 00000000..c0ca4808 --- /dev/null +++ b/src/qtgui/coreconnectdlg.cpp @@ -0,0 +1,101 @@ +/*************************************************************************** + * Copyright (C) 2005/06 by The Quassel Team * + * 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) any later version. * + * * + * 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 "coreconnectdlg.h" +#include "guiproxy.h" +#include "global.h" +#include "gui.h" + +CoreConnectDlg::CoreConnectDlg(QWidget *parent) : QDialog(parent) { + ui.setupUi(this); + ui.progressBar->hide(); + coreState = 0; + QSettings s; + connect(ui.hostName, SIGNAL(textChanged(QString)), this, SLOT(hostEditChanged(QString))); + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(hostSelected())); + + ui.hostName->setText(s.value("GUI/CoreHost", "localhost").toString()); + ui.hostName->setSelection(0, ui.hostName->text().length()); + ui.hostPort->setValue(s.value("GUI/CorePort", 4242).toInt()); + ui.autoConnect->setChecked(s.value("GUI/CoreAutoConnect", true).toBool()); + if(s.value("GUI/CoreAutoConnect").toBool()) { + hostSelected(); + } +} + +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()); +} + +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(); + VarMap initmsg; + initmsg["GUIProtocol"] = GUI_PROTOCOL; + // FIXME guiProxy->send(GS_CLIENT_INIT, QVariant(initmsg)); +} + +void CoreConnectDlg::coreConnectionError(QString err) { + QMessageBox::warning(this, tr("Connection Error"), tr("Could not connect to Quassel Core!
\n") + err, QMessageBox::Retry); + disconnect(ClientProxy::instance(), 0, this, 0); + ui.autoConnect->setChecked(false); + setStartState(); +} + +void CoreConnectDlg::updateProgressBar(quint32 recv, quint32 avail) { + ui.progressBar->setMaximum(avail); + ui.progressBar->setValue(recv); +} + +void CoreConnectDlg::recvCoreState(QVariant state) { + ui.progressBar->hide(); + coreState = state; + accept(); +} + +QVariant CoreConnectDlg::getCoreState() { + return coreState; +}