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

« back to all changes in this revision

Viewing changes to src/qtui/settingspages/networkssettingspage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2009-01-14 01:28:49 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090114012849-38celzez3y3wpai9
Tags: 0.4.0~git090113-0ubuntu1
* New upstream git snapshot
  - Use networks.ini to provide default network/channel
  - Provide presets for common IRC networks
* Add kubuntu_01_default_network_channel.patch to set Freenode, port
  8001, and #kubuntu as defaults
* Add build-dep on quilt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
 
2
 *   Copyright (C) 2005-09 by the Quassel Project                          *
3
3
 *   devel@quassel-irc.org                                                 *
4
4
 *                                                                         *
5
5
 *   This program is free software; you can redistribute it and/or modify  *
28
28
#include "iconloader.h"
29
29
#include "identity.h"
30
30
#include "network.h"
 
31
#include "settingspagedlg.h"
 
32
#include "util.h"
31
33
 
 
34
#include "settingspages/identitiessettingspage.h"
32
35
 
33
36
NetworksSettingsPage::NetworksSettingsPage(QWidget *parent) : SettingsPage(tr("General"), tr("Networks"), parent) {
34
37
  ui.setupUi(this);
42
45
  ui.editServer->setIcon(SmallIcon("configure"));
43
46
  ui.upServer->setIcon(SmallIcon("go-up"));
44
47
  ui.downServer->setIcon(SmallIcon("go-down"));
 
48
  ui.editIdentities->setIcon(SmallIcon("configure"));
45
49
 
46
50
  _ignoreWidgetChanges = false;
47
51
 
68
72
  connect(Client::instance(), SIGNAL(identityRemoved(IdentityId)), this, SLOT(clientIdentityRemoved(IdentityId)));
69
73
 
70
74
  connect(ui.identityList, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
71
 
  connect(ui.randomServer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
 
75
  //connect(ui.randomServer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
72
76
  connect(ui.performEdit, SIGNAL(textChanged()), this, SLOT(widgetHasChanged()));
73
77
  connect(ui.autoIdentify, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
74
78
  connect(ui.autoIdentifyService, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
75
79
  connect(ui.autoIdentifyPassword, SIGNAL(textEdited(const QString &)), this, SLOT(widgetHasChanged()));
76
 
  connect(ui.useDefaultEncodings, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
 
80
  connect(ui.useCustomEncodings, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
77
81
  connect(ui.sendEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
78
82
  connect(ui.recvEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
79
83
  connect(ui.serverEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
186
190
    ui.detailsBox->setEnabled(true);
187
191
    ui.renameNetwork->setEnabled(true);
188
192
    ui.deleteNetwork->setEnabled(true);
 
193
    /* button disabled for now
189
194
    ui.connectNow->setEnabled(net);
190
195
    //    && (Client::network(id)->connectionState() == Network::Initialized
191
196
    //    || Client::network(id)->connectionState() == Network::Disconnected));
200
205
    } else {
201
206
      ui.connectNow->setIcon(QIcon());
202
207
      ui.connectNow->setText(tr("Apply first!"));
203
 
    }
 
208
    } */
204
209
  } else {
205
210
    ui.renameNetwork->setEnabled(false);
206
211
    ui.deleteNetwork->setEnabled(false);
207
 
    ui.connectNow->setEnabled(false);
 
212
    //ui.connectNow->setEnabled(false);
208
213
    ui.detailsBox->setEnabled(false);
209
214
  }
210
215
  // network details
384
389
}
385
390
 
386
391
void NetworksSettingsPage::networkConnectionStateChanged(Network::ConnectionState state) {
 
392
  Q_UNUSED(state);
387
393
  const Network *net = qobject_cast<const Network *>(sender());
388
394
  if(!net) return;
 
395
  /*
389
396
  if(net->networkId() == currentId) {
390
397
    ui.connectNow->setEnabled(state == Network::Initialized || state == Network::Disconnected);
391
398
  }
 
399
  */
392
400
  setItemState(net->networkId());
393
401
  setWidgetStates();
394
402
}
429
437
    ui.identityList->setCurrentIndex(ui.identityList->findData(info.identity.toInt()));
430
438
    ui.serverList->clear();
431
439
    foreach(Network::Server server, info.serverList) {
432
 
      ui.serverList->addItem(QString("%1:%2").arg(server.host).arg(server.port));
 
440
      QListWidgetItem *item = new QListWidgetItem(QString("%1:%2").arg(server.host).arg(server.port));
 
441
      if(server.useSsl)
 
442
        item->setIcon(SmallIcon("document-encrypt"));
 
443
      ui.serverList->addItem(item);
433
444
    }
434
445
    //setItemState(id);
435
 
    ui.randomServer->setChecked(info.useRandomServer);
 
446
    //ui.randomServer->setChecked(info.useRandomServer);
436
447
    ui.performEdit->setPlainText(info.perform.join("\n"));
437
448
    ui.autoIdentify->setChecked(info.useAutoIdentify);
438
449
    ui.autoIdentifyService->setText(info.autoIdentifyService);
441
452
      ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(Network::defaultCodecForEncoding()));
442
453
      ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(Network::defaultCodecForDecoding()));
443
454
      ui.serverEncoding->setCurrentIndex(ui.serverEncoding->findText(Network::defaultCodecForServer()));
444
 
      ui.useDefaultEncodings->setChecked(true);
 
455
      ui.useCustomEncodings->setChecked(false);
445
456
    } else {
446
457
      ui.sendEncoding->setCurrentIndex(ui.sendEncoding->findText(info.codecForEncoding));
447
458
      ui.recvEncoding->setCurrentIndex(ui.recvEncoding->findText(info.codecForDecoding));
448
459
      ui.serverEncoding->setCurrentIndex(ui.serverEncoding->findText(info.codecForServer));
449
 
      ui.useDefaultEncodings->setChecked(false);
 
460
      ui.useCustomEncodings->setChecked(true);
450
461
    }
451
462
    ui.autoReconnect->setChecked(info.useAutoReconnect);
452
463
    ui.reconnectInterval->setValue(info.autoReconnectInterval);
468
479
 
469
480
void NetworksSettingsPage::saveToNetworkInfo(NetworkInfo &info) {
470
481
  info.identity = ui.identityList->itemData(ui.identityList->currentIndex()).toInt();
471
 
  info.useRandomServer = ui.randomServer->isChecked();
 
482
  //info.useRandomServer = ui.randomServer->isChecked();
472
483
  info.perform = ui.performEdit->toPlainText().split("\n");
473
484
  info.useAutoIdentify = ui.autoIdentify->isChecked();
474
485
  info.autoIdentifyService = ui.autoIdentifyService->text();
475
486
  info.autoIdentifyPassword = ui.autoIdentifyPassword->text();
476
 
  if(ui.useDefaultEncodings->isChecked()) {
 
487
  if(!ui.useCustomEncodings->isChecked()) {
477
488
    info.codecForEncoding.clear();
478
489
    info.codecForDecoding.clear();
479
490
    info.codecForServer.clear();
508
519
void NetworksSettingsPage::on_addNetwork_clicked() {
509
520
  QStringList existing;
510
521
  for(int i = 0; i < ui.networkList->count(); i++) existing << ui.networkList->item(i)->text();
511
 
  NetworkEditDlg dlg(QString(), existing, this);
 
522
  NetworkAddDlg dlg(existing, this);
512
523
  if(dlg.exec() == QDialog::Accepted) {
 
524
    NetworkInfo info = dlg.networkInfo();
 
525
    if(info.networkName.isEmpty())
 
526
      return;  // sanity check
 
527
 
513
528
    NetworkId id;
514
529
    for(id = 1; id <= networkInfos.count(); id++) {
515
530
      widgetHasChanged();
516
531
      if(!networkInfos.keys().contains(-id.toInt())) break;
517
532
    }
518
533
    id = -id.toInt();
519
 
    NetworkInfo info;
520
534
    info.networkId = id;
521
 
    info.networkName = dlg.networkName();
522
 
    info.identity = 1;
523
 
 
524
 
    // defaults
525
 
    info.useRandomServer = false;
526
 
    info.useAutoReconnect = true;
527
 
    info.autoReconnectInterval = 60;
528
 
    info.autoReconnectRetries = 20;
529
 
    info.unlimitedReconnectRetries = false;
530
 
    info.useAutoIdentify = false;
531
 
    info.autoIdentifyService = "NickServ";
532
 
    info.rejoinChannels = true;
533
 
 
534
535
    networkInfos[id] = info;
535
536
    QListWidgetItem *item = insertNetwork(info);
536
537
    ui.networkList->setCurrentItem(item);
569
570
  }
570
571
}
571
572
 
 
573
/*
572
574
void NetworksSettingsPage::on_connectNow_clicked() {
573
575
  if(!ui.networkList->selectedItems().count()) return;
574
576
  NetworkId id = ui.networkList->selectedItems()[0]->data(Qt::UserRole).value<NetworkId>();
577
579
  if(net->connectionState() == Network::Disconnected) net->requestConnect();
578
580
  else net->requestDisconnect();
579
581
}
 
582
*/
580
583
 
581
584
/*** Server list ***/
582
585
 
634
637
  widgetHasChanged();
635
638
}
636
639
 
 
640
void NetworksSettingsPage::on_editIdentities_clicked() {
 
641
  SettingsPageDlg dlg(new IdentitiesSettingsPage(this), this);
 
642
  dlg.exec();
 
643
}
 
644
 
 
645
/**************************************************************************
 
646
* NetworkAddDlg
 
647
*************************************************************************/
 
648
 
 
649
NetworkAddDlg::NetworkAddDlg(const QStringList &exist, QWidget *parent) : QDialog(parent), existing(exist) {
 
650
  ui.setupUi(this);
 
651
  ui.useSSL->setIcon(SmallIcon("document-encrypt"));
 
652
 
 
653
  // read preset networks
 
654
  QStringList networks = Network::presetNetworks();
 
655
  foreach(QString s, existing)
 
656
    networks.removeAll(s);
 
657
  if(networks.count())
 
658
    ui.presetList->addItems(networks);
 
659
  else {
 
660
    ui.useManual->setChecked(true);
 
661
    ui.usePreset->setEnabled(false);
 
662
  }
 
663
  connect(ui.networkName, SIGNAL(textChanged(const QString &)), SLOT(setButtonStates()));
 
664
  connect(ui.serverAddress, SIGNAL(textChanged(const QString &)), SLOT(setButtonStates()));
 
665
  setButtonStates();
 
666
}
 
667
 
 
668
NetworkInfo NetworkAddDlg::networkInfo() const {
 
669
  if(ui.useManual->isChecked()) {
 
670
    NetworkInfo info;
 
671
    info.networkName = ui.networkName->text().trimmed();
 
672
    info.serverList << Network::Server(ui.serverAddress->text().trimmed(), ui.port->value(), ui.serverPassword->text(), ui.useSSL->isChecked());
 
673
    return info;
 
674
  } else
 
675
    return Network::networkInfoFromPreset(ui.presetList->currentText());
 
676
}
 
677
 
 
678
void NetworkAddDlg::setButtonStates() {
 
679
  bool ok = false;
 
680
  if(ui.usePreset->isChecked() && ui.presetList->count())
 
681
    ok = true;
 
682
  else if(ui.useManual->isChecked()) {
 
683
    ok = !ui.networkName->text().trimmed().isEmpty() && !existing.contains(ui.networkName->text().trimmed())
 
684
      && !ui.serverAddress->text().isEmpty();
 
685
  }
 
686
  ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
 
687
}
 
688
 
637
689
/**************************************************************************
638
690
 * NetworkEditDlg
639
691
 *************************************************************************/
657
709
  ui.buttonBox->button(QDialogButtonBox::Ok)->setDisabled(text.isEmpty() || existing.contains(text.trimmed()));
658
710
}
659
711
 
660
 
 
661
712
/**************************************************************************
662
713
 * ServerEditDlg
663
714
 *************************************************************************/