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"
26 CoreConnectDlg::CoreConnectDlg(QWidget *parent) : QDialog(parent) {
28 ui.progressBar->hide();
31 connect(ui.hostName, SIGNAL(textChanged(QString)), this, SLOT(hostEditChanged(QString)));
32 connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(hostSelected()));
34 ui.hostName->setText(s.value("GUI/CoreHost", "localhost").toString());
35 ui.hostName->setSelection(0, ui.hostName->text().length());
36 ui.hostPort->setValue(s.value("GUI/CorePort", 4242).toInt());
37 ui.autoConnect->setChecked(s.value("GUI/CoreAutoConnect", true).toBool());
38 if(s.value("GUI/CoreAutoConnect").toBool()) {
43 void CoreConnectDlg::setStartState() {
44 ui.hostName->show(); ui.hostPort->show(); ui.hostLabel->show(); ui.portLabel->show();
45 ui.statusText->setText(tr("Connect to Quassel Core running on:"));
46 ui.buttonBox->button(QDialogButtonBox::Ok)->show();
47 ui.hostName->setEnabled(true); ui.hostPort->setEnabled(true);
48 ui.hostName->setSelection(0, ui.hostName->text().length());
51 void CoreConnectDlg::hostEditChanged(QString txt) {
52 ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(txt.length());
55 void CoreConnectDlg::hostSelected() {
56 ui.hostName->hide(); ui.hostPort->hide(); ui.hostLabel->hide(); ui.portLabel->hide();
57 ui.statusText->setText(tr("Connecting to %1:%2" ).arg(ui.hostName->text()).arg(ui.hostPort->value()));
58 ui.buttonBox->button(QDialogButtonBox::Ok)->hide();
59 connect(guiProxy, SIGNAL(coreConnected()), this, SLOT(coreConnected()));
60 connect(guiProxy, SIGNAL(coreConnectionError(QString)), this, SLOT(coreConnectionError(QString)));
61 guiProxy->connectToCore(ui.hostName->text(), ui.hostPort->value());
65 void CoreConnectDlg::coreConnected() {
66 ui.hostLabel->hide(); ui.hostName->hide(); ui.portLabel->hide(); ui.hostPort->hide();
67 ui.statusText->setText(tr("Synchronizing..."));
69 s.setValue("GUI/CoreHost", ui.hostName->text());
70 s.setValue("GUI/CorePort", ui.hostPort->value());
71 s.setValue("GUI/CoreAutoConnect", ui.autoConnect->isChecked());
72 connect(guiProxy, SIGNAL(recvPartialItem(quint32, quint32)), this, SLOT(updateProgressBar(quint32, quint32)));
73 connect(guiProxy, SIGNAL(csCoreState(QVariant)), this, SLOT(recvCoreState(QVariant)));
74 ui.progressBar->show();
76 initmsg["GUIProtocol"] = GUI_PROTOCOL;
77 guiProxy->send(GS_CLIENT_INIT, QVariant(initmsg));
80 void CoreConnectDlg::coreConnectionError(QString err) {
81 QMessageBox::warning(this, tr("Connection Error"), tr("<b>Could not connect to Quassel Core!</b><br>\n") + err, QMessageBox::Retry);
82 disconnect(guiProxy, 0, this, 0);
83 ui.autoConnect->setChecked(false);
87 void CoreConnectDlg::updateProgressBar(quint32 recv, quint32 avail) {
88 ui.progressBar->setMaximum(avail);
89 ui.progressBar->setValue(recv);
92 void CoreConnectDlg::recvCoreState(QVariant state) {
93 ui.progressBar->hide();
98 QVariant CoreConnectDlg::getCoreState() {