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

« back to all changes in this revision

Viewing changes to src/common/network.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 Project                          *
 
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  *
20
20
#include "network.h"
21
21
 
22
22
#include <QDebug>
 
23
#include <QSettings>
23
24
#include <QTextCodec>
24
25
 
25
26
QTextCodec *Network::_defaultCodecForServer = 0;
26
27
QTextCodec *Network::_defaultCodecForEncoding = 0;
27
28
QTextCodec *Network::_defaultCodecForDecoding = 0;
 
29
QString Network::_networksIniPath = QString();
28
30
 
29
31
// ====================
30
32
//  Public:
396
398
  return string.toAscii();
397
399
}
398
400
 
 
401
/*** Handle networks.ini ***/
 
402
 
 
403
QStringList Network::presetNetworks(bool onlyDefault) {
 
404
  // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
 
405
  if(_networksIniPath.isNull()) {
 
406
    _networksIniPath = findDataFilePath("networks.ini");
 
407
    if(_networksIniPath.isNull()) {
 
408
      _networksIniPath = ""; // now we won't check again, as it's not null anymore
 
409
      return QStringList();
 
410
    }
 
411
  }
 
412
  if(!_networksIniPath.isEmpty()) {
 
413
    QSettings s(_networksIniPath, QSettings::IniFormat);
 
414
    QStringList networks = s.childGroups();
 
415
    if(!networks.isEmpty()) {
 
416
      // we sort the list case-insensitive
 
417
      QMap<QString, QString> sorted;
 
418
      foreach(QString net, networks) {
 
419
        if(onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
 
420
          continue;
 
421
        sorted[net.toLower()] = net;
 
422
      }
 
423
      return sorted.values();
 
424
    }
 
425
  }
 
426
  return QStringList();
 
427
}
 
428
 
 
429
QStringList Network::presetDefaultChannels(const QString &networkName) {
 
430
  if(_networksIniPath.isEmpty())  // be sure to have called presetNetworks() first, else this always fails
 
431
    return QStringList();
 
432
  QSettings s(_networksIniPath, QSettings::IniFormat);
 
433
  return s.value(QString("%1/DefaultChannels").arg(networkName)).toStringList();
 
434
}
 
435
 
 
436
NetworkInfo Network::networkInfoFromPreset(const QString &networkName) {
 
437
  NetworkInfo info;
 
438
  if(!_networksIniPath.isEmpty()) {
 
439
    info.networkName = networkName;
 
440
    QSettings s(_networksIniPath, QSettings::IniFormat);
 
441
    s.beginGroup(info.networkName);
 
442
    foreach(QString server, s.value("Servers").toStringList()) {
 
443
      bool ssl = false;
 
444
      QStringList splitserver = server.split(':', QString::SkipEmptyParts);
 
445
      if(splitserver.count() != 2) {
 
446
        qWarning() << "Invalid server entry in networks.conf:" << server;
 
447
        continue;
 
448
      }
 
449
      if(splitserver[1].at(0) == '+')
 
450
        ssl = true;
 
451
      uint port = splitserver[1].toUInt();
 
452
      if(!port) {
 
453
        qWarning() << "Invalid port entry in networks.conf:" << server;
 
454
        continue;
 
455
      }
 
456
      info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl);
 
457
    }
 
458
  }
 
459
  return info;
 
460
}
 
461
 
 
462
 
399
463
// ====================
400
464
//  Public Slots:
401
465
// ====================
661
725
 * NetworkInfo
662
726
 ************************************************************************/
663
727
 
 
728
NetworkInfo::NetworkInfo()
 
729
: networkId(0),
 
730
  identity(1),
 
731
  useRandomServer(false),
 
732
  useAutoIdentify(false),
 
733
  autoIdentifyService("NickServ"),
 
734
  useAutoReconnect(true),
 
735
  autoReconnectInterval(60),
 
736
  autoReconnectRetries(20),
 
737
  unlimitedReconnectRetries(false),
 
738
  rejoinChannels(true)
 
739
{
 
740
 
 
741
}
 
742
 
664
743
bool NetworkInfo::operator==(const NetworkInfo &other) const {
665
744
  if(networkId != other.networkId) return false;
666
745
  if(networkName != other.networkName) return false;