1 /***************************************************************************
2 * Copyright (C) 2005/06 by The Quassel Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include "coreconnectdlg.h"
23 #include "clientproxy.h"
27 CoreConnectDlg::CoreConnectDlg(QWidget *parent) : QDialog(parent) {
29 ui.progressBar->hide();
32 connect(ui.hostName, SIGNAL(textChanged(QString)), this, SLOT(hostEditChanged(QString)));
33 connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(hostSelected()));
35 ui.hostName->setText(s.value("GUI/CoreHost", "localhost").toString());
36 ui.hostName->setSelection(0, ui.hostName->text().length());
37 ui.hostPort->setValue(s.value("GUI/CorePort", 4242).toInt());
38 ui.autoConnect->setChecked(s.value("GUI/CoreAutoConnect", true).toBool());
39 if(s.value("GUI/CoreAutoConnect").toBool()) {
44 void CoreConnectDlg::setStartState() {
45 ui.hostName->show(); ui.hostPort->show(); ui.hostLabel->show(); ui.portLabel->show();
46 ui.statusText->setText(tr("Connect to Quassel Core running on:"));
47 ui.buttonBox->button(QDialogButtonBox::Ok)->show();
48 ui.hostName->setEnabled(true); ui.hostPort->setEnabled(true);
49 ui.hostName->setSelection(0, ui.hostName->text().length());
52 void CoreConnectDlg::hostEditChanged(QString txt) {
53 ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(txt.length());
56 void CoreConnectDlg::hostSelected() {
57 ui.hostName->hide(); ui.hostPort->hide(); ui.hostLabel->hide(); ui.portLabel->hide();
58 ui.statusText->setText(tr("Connecting to %1:%2" ).arg(ui.hostName->text()).arg(ui.hostPort->value()));
59 ui.buttonBox->button(QDialogButtonBox::Ok)->hide();
60 connect(ClientProxy::instance(), SIGNAL(coreConnected()), this, SLOT(coreConnected()));
61 connect(ClientProxy::instance(), SIGNAL(coreConnectionError(QString)), this, SLOT(coreConnectionError(QString)));
62 Client::instance()->connectToCore(ui.hostName->text(), ui.hostPort->value());
66 void CoreConnectDlg::coreConnected() {
67 ui.hostLabel->hide(); ui.hostName->hide(); ui.portLabel->hide(); ui.hostPort->hide();
68 ui.statusText->setText(tr("Synchronizing..."));
70 s.setValue("GUI/CoreHost", ui.hostName->text());
71 s.setValue("GUI/CorePort", ui.hostPort->value());
72 s.setValue("GUI/CoreAutoConnect", ui.autoConnect->isChecked());
73 connect(ClientProxy::instance(), SIGNAL(recvPartialItem(quint32, quint32)), this, SLOT(updateProgressBar(quint32, quint32)));
74 connect(ClientProxy::instance(), SIGNAL(csCoreState(QVariant)), this, SLOT(recvCoreState(QVariant)));
75 ui.progressBar->show();
77 initmsg["GUIProtocol"] = GUI_PROTOCOL;
78 // FIXME guiProxy->send(GS_CLIENT_INIT, QVariant(initmsg));
81 void CoreConnectDlg::coreConnectionError(QString err) {
82 QMessageBox::warning(this, tr("Connection Error"), tr("<b>Could not connect to Quassel Core!</b><br>\n") + err, QMessageBox::Retry);
83 disconnect(ClientProxy::instance(), 0, this, 0);
84 ui.autoConnect->setChecked(false);
88 void CoreConnectDlg::updateProgressBar(quint32 recv, quint32 avail) {
89 ui.progressBar->setMaximum(avail);
90 ui.progressBar->setValue(recv);
93 void CoreConnectDlg::recvCoreState(QVariant state) {
94 ui.progressBar->hide();
99 QVariant CoreConnectDlg::getCoreState() {