~ubuntu-branches/ubuntu/jaunty/quassel/jaunty-backports

« back to all changes in this revision

Viewing changes to src/qtui/coreconnectdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2008-11-17 15:22:46 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20081117152246-3lwlpnr4r08910kv
Tags: 0.3.1-0ubuntu1
* New upstream release (LP: #271403)
* Drop all patches originated from upstream (quassel_*)
* Compile with non-builtin quassel icons
  + Introduce new quassel-data package
  + quassel and quassel-client depend on quassel-data
  + Don't manually enforce icon installation for desktop files in debian/rules
  + Add quassel_01_fix_iconloader.patch
* Drop perl build dependency, I have no clue why it was added in the first
  place. Neither changelog nor Bazaar knows, and since quassel compiles just
  fine without it, removing it should be save.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "coreconnectdlg.h"
26
26
 
 
27
#include "client.h"
27
28
#include "clientsettings.h"
28
29
#include "clientsyncer.h"
29
30
#include "coreconfigwizard.h"
 
31
#include "iconloader.h"
 
32
#include "quassel.h"
30
33
 
31
34
CoreConnectDlg::CoreConnectDlg(bool autoconnect, QWidget *parent)
32
 
  : QDialog(parent)
 
35
  : QDialog(parent),
 
36
    _internalAccountId(0)
33
37
{
34
38
  ui.setupUi(this);
 
39
  ui.editAccount->setIcon(SmallIcon("document-properties"));
 
40
  ui.addAccount->setIcon(SmallIcon("list-add"));
 
41
  ui.deleteAccount->setIcon(SmallIcon("list-remove"));
 
42
  ui.connectIcon->setPixmap(BarIcon("network-disconnect"));
 
43
  ui.secureConnection->setPixmap(SmallIcon("document-encrypt"));
 
44
 
 
45
  if(Quassel::runMode() != Quassel::Monolithic) {
 
46
    ui.useInternalCore->hide();
 
47
  }
35
48
 
36
49
  // make it look more native under Mac OS X:
37
50
  setWindowFlags(Qt::Sheet);
38
51
 
39
52
  clientSyncer = new ClientSyncer(this);
 
53
  connect(this, SIGNAL(newClientSyncer(ClientSyncer *)), Client::instance(), SIGNAL(newClientSyncer(ClientSyncer *)));
 
54
  emit newClientSyncer(clientSyncer); // announce the new client syncer via the client.
 
55
 
40
56
  wizard = 0;
41
57
 
42
58
  doingAutoConnect = false;
50
66
  foreach(AccountId id, s.knownAccounts()) {
51
67
    if(!id.isValid()) continue;
52
68
    QVariantMap data = s.retrieveAccountData(id);
 
69
    if(data.contains("InternalAccount") && data["InternalAccount"].toBool()) {
 
70
      _internalAccountId = id;
 
71
      continue;
 
72
    }
53
73
    data["AccountId"] = QVariant::fromValue<AccountId>(id);
54
74
    accounts[id] = data;
55
75
    QListWidgetItem *item = new QListWidgetItem(data["AccountName"].toString(), ui.accountList);
135
155
  for(int i = 0; i < ui.accountList->count(); i++) existing << ui.accountList->item(i)->text();
136
156
  CoreAccountEditDlg dlg(0, QVariantMap(), existing, this);
137
157
  if(dlg.exec() == QDialog::Accepted) {
138
 
    // find free ID
139
 
    AccountId id = accounts.count() + 1;
140
 
    for(AccountId i = 1; i <= accounts.count(); i++) {
141
 
      if(!accounts.keys().contains(i)) {
142
 
        id = i;
143
 
        break;
144
 
      }
145
 
    }
 
158
    AccountId id = findFreeAccountId();
146
159
    QVariantMap data = dlg.accountData();
147
160
    data["AccountId"] = QVariant::fromValue<AccountId>(id);
148
161
    accounts[id] = data;
205
218
  connectToCore();
206
219
}
207
220
 
 
221
void CoreConnectDlg::on_useInternalCore_clicked() {
 
222
  if(!_internalAccountId.isValid()) {
 
223
    _internalAccountId = findFreeAccountId();
 
224
    QVariantMap data;
 
225
    data["InternalAccount"] = true;
 
226
    CoreAccountSettings accountSettings;
 
227
    accountSettings.storeAccountData(_internalAccountId, data);
 
228
  }
 
229
  clientSyncer->useInternalCore(_internalAccountId);
 
230
  startSync();
 
231
}
 
232
 
208
233
/*****************************************************
209
234
 * Connecting to the Core
210
235
 ****************************************************/
213
238
 
214
239
void CoreConnectDlg::connectToCore() {
215
240
  ui.secureConnection->hide();
216
 
  ui.connectIcon->setPixmap(QPixmap::fromImage(QImage(":/22x22/actions/network-disconnect")));
 
241
  ui.connectIcon->setPixmap(BarIcon("network-disconnect"));
217
242
  ui.connectLabel->setText(tr("Connect to %1").arg(accountData["Host"].toString()));
218
243
  ui.coreInfoLabel->setText("");
219
244
  ui.loginStack->setCurrentWidget(ui.loginEmptyPage);
229
254
void CoreConnectDlg::initPhaseError(const QString &error) {
230
255
  doingAutoConnect = false;
231
256
  ui.secureConnection->hide();
232
 
  ui.connectIcon->setPixmap(QPixmap::fromImage(QImage(":/22x22/status/dialog-error")));
 
257
  ui.connectIcon->setPixmap(BarIcon("dialog-error"));
233
258
  //ui.connectLabel->setBrush(QBrush("red"));
234
259
  ui.connectLabel->setText(tr("<div style=color:red;>Connection to %1 failed!</div>").arg(accountData["Host"].toString()));
235
260
  ui.coreInfoLabel->setText(error);
275
300
 *********************************************************/
276
301
 
277
302
void CoreConnectDlg::startLogin() {
278
 
  ui.connectIcon->setPixmap(QPixmap::fromImage(QImage(":/22x22/actions/network-connect")));
 
303
  ui.connectIcon->setPixmap(BarIcon("network-connect"));
279
304
  ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
280
305
  //ui.loginStack->setMinimumSize(ui.loginStack->sizeHint()); ui.loginStack->updateGeometry();
281
306
  ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
336
361
  if(wizard) {
337
362
    wizard->reject();
338
363
  }
 
364
  ui.connectIcon->setPixmap(BarIcon("dialog-error"));
339
365
  ui.loginStack->setCurrentWidget(ui.loginCredentialsPage);
340
366
  ui.loginGroup->setTitle(tr("Login"));
341
367
  ui.user->setEnabled(true);
429
455
  }
430
456
}
431
457
 
 
458
AccountId CoreConnectDlg::findFreeAccountId() {
 
459
  for(AccountId i = 1;; i++) {
 
460
    if(!accounts.contains(i) && i != _internalAccountId)
 
461
      return i;
 
462
  }
 
463
}
 
464
 
432
465
/*****************************************************************************************
433
466
 * CoreAccountEditDlg
434
467
 *****************************************************************************************/
436
469
  : QDialog(parent)
437
470
{
438
471
  ui.setupUi(this);
 
472
  ui.useSsl->setIcon(SmallIcon("document-encrypt"));
 
473
 
439
474
  existing = _existing;
440
475
  if(id.isValid()) {
 
476
    account = acct;
 
477
 
441
478
    existing.removeAll(acct["AccountName"].toString());
442
479
    ui.host->setText(acct["Host"].toString());
443
480
    ui.port->setValue(acct["Port"].toUInt());
444
 
    ui.useInternal->setChecked(acct["UseInternal"].toBool());
445
481
    ui.accountName->setText(acct["AccountName"].toString());
446
 
#ifndef QT_NO_OPENSSL
 
482
#ifdef HAVE_SSL
447
483
    ui.useSsl->setChecked(acct["useSsl"].toBool());
448
484
#else
449
485
    ui.useSsl->setChecked(false);
457
493
    ui.proxyPassword->setText(acct["proxyPassword"].toString());
458
494
  } else {
459
495
    setWindowTitle(tr("Add Core Account"));
460
 
#ifdef QT_NO_OPENSSL
 
496
#ifndef HAVE_SSL
461
497
    ui.useSsl->setChecked(false);
462
498
    ui.useSsl->setEnabled(false);
463
499
#endif
464
500
  }
465
 
 
466
 
#ifndef BUILD_MONO
467
 
  // if we don't have a mono build we hide the option to use the internal connection and force the setting to use remote host
468
 
  ui.useInternal->setChecked(false);
469
 
  ui.useInternal->hide();
470
 
  ui.useRemote->hide();
471
 
  ui.labelUseBuiltinCore->hide();
472
 
#endif
473
501
}
474
502
 
475
503
QVariantMap CoreAccountEditDlg::accountData() {
476
504
  account["AccountName"] = ui.accountName->text().trimmed();
477
505
  account["Host"] = ui.host->text().trimmed();
478
506
  account["Port"] = ui.port->value();
479
 
  account["UseInternal"] = ui.useInternal->isChecked();
480
507
  account["useSsl"] = ui.useSsl->isChecked();
481
508
  account["useProxy"] = ui.useProxy->isChecked();
482
509
  account["proxyHost"] = ui.proxyHost->text().trimmed();
488
515
}
489
516
 
490
517
void CoreAccountEditDlg::setWidgetStates() {
491
 
  bool ok = !ui.accountName->text().trimmed().isEmpty() && !existing.contains(ui.accountName->text()) && (ui.useInternal->isChecked() || !ui.host->text().isEmpty());
 
518
  bool ok = !ui.accountName->text().trimmed().isEmpty() && !existing.contains(ui.accountName->text()) && !ui.host->text().isEmpty();
492
519
  ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
493
520
}
494
521
 
501
528
  Q_UNUSED(text);
502
529
  setWidgetStates();
503
530
}
504
 
 
505
 
void CoreAccountEditDlg::on_useRemote_toggled(bool state) {
506
 
  Q_UNUSED(state);
507
 
  setWidgetStates();
508
 
}