Still working on the authentification stuff. Technically, now even in the monolithic...
[quassel.git] / src / qtgui / coreconnectdlg.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005/06 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include <QtGui>
22 #include "coreconnectdlg.h"
23 #include "clientproxy.h"
24 #include "global.h"
25 #include "client.h"
26
27 CoreConnectDlg::CoreConnectDlg(QWidget *parent) : QDialog(parent) {
28   ui.setupUi(this);
29   ui.progressBar->hide();
30   coreState = 0;
31   QSettings s;
32   /*
33   connect(ui.hostName, SIGNAL(textChanged(QString)), this, SLOT(hostEditChanged(QString)));
34   connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(hostSelected()));
35
36   ui.hostName->setText(s.value("GUI/CoreHost", "localhost").toString());
37   ui.hostName->setSelection(0, ui.hostName->text().length());
38   ui.hostPort->setValue(s.value("GUI/CorePort", 4242).toInt());
39   ui.autoConnect->setChecked(s.value("GUI/CoreAutoConnect", true).toBool());
40   if(s.value("GUI/CoreAutoConnect").toBool()) {
41     hostSelected();
42   }
43   */
44 }
45
46 void CoreConnectDlg::setStartState() { /*
47   ui.hostName->show(); ui.hostPort->show(); ui.hostLabel->show(); ui.portLabel->show();
48   ui.statusText->setText(tr("Connect to Quassel Core running on:"));
49   ui.buttonBox->button(QDialogButtonBox::Ok)->show();
50   ui.hostName->setEnabled(true); ui.hostPort->setEnabled(true);
51   ui.hostName->setSelection(0, ui.hostName->text().length()); */
52 }
53
54 void CoreConnectDlg::hostEditChanged(QString txt) {
55   ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(txt.length());
56 }
57
58 void CoreConnectDlg::hostSelected() { /*
59   ui.hostName->hide(); ui.hostPort->hide(); ui.hostLabel->hide(); ui.portLabel->hide();
60   ui.statusText->setText(tr("Connecting to %1:%2" ).arg(ui.hostName->text()).arg(ui.hostPort->value()));
61   ui.buttonBox->button(QDialogButtonBox::Ok)->hide();
62   connect(ClientProxy::instance(), SIGNAL(coreConnected()), this, SLOT(coreConnected()));
63   connect(ClientProxy::instance(), SIGNAL(coreConnectionError(QString)), this, SLOT(coreConnectionError(QString)));
64   Client::instance()->connectToCore(ui.hostName->text(), ui.hostPort->value());
65 */
66 }
67
68 void CoreConnectDlg::coreConnected() { /*
69   ui.hostLabel->hide(); ui.hostName->hide(); ui.portLabel->hide(); ui.hostPort->hide();
70   ui.statusText->setText(tr("Synchronizing..."));
71   QSettings s;
72   s.setValue("GUI/CoreHost", ui.hostName->text());
73   s.setValue("GUI/CorePort", ui.hostPort->value());
74   s.setValue("GUI/CoreAutoConnect", ui.autoConnect->isChecked());
75   connect(ClientProxy::instance(), SIGNAL(recvPartialItem(quint32, quint32)), this, SLOT(updateProgressBar(quint32, quint32)));
76   connect(ClientProxy::instance(), SIGNAL(csCoreState(QVariant)), this, SLOT(recvCoreState(QVariant)));
77   ui.progressBar->show();
78   VarMap initmsg;
79   initmsg["GUIProtocol"] = GUI_PROTOCOL;
80   // FIXME guiProxy->send(GS_CLIENT_INIT, QVariant(initmsg)); */
81 }
82
83 void CoreConnectDlg::coreConnectionError(QString err) {
84   QMessageBox::warning(this, tr("Connection Error"), tr("<b>Could not connect to Quassel Core!</b><br>\n") + err, QMessageBox::Retry);
85   disconnect(ClientProxy::instance(), 0, this, 0);
86   ui.autoConnect->setChecked(false);
87   setStartState();
88 }
89
90 void CoreConnectDlg::updateProgressBar(quint32 recv, quint32 avail) {
91   ui.progressBar->setMaximum(avail);
92   ui.progressBar->setValue(recv);
93 }
94
95 void CoreConnectDlg::recvCoreState(QVariant state) {
96   ui.progressBar->hide();
97   coreState = state;
98   accept();
99 }
100
101 QVariant CoreConnectDlg::getCoreState() {
102   return coreState;
103 }