1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
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) version 3. *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
23 #include "presetnetworks.h"
26 QString PresetNetworks::_networksIniPath = QString();
28 // ====================
30 // ====================
31 QStringList PresetNetworks::names(bool onlyDefault)
33 // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
34 if (_networksIniPath.isNull()) {
35 _networksIniPath = Quassel::findDataFilePath("networks.ini");
36 if (_networksIniPath.isNull()) {
37 _networksIniPath = ""; // now we won't check again, as it's not null anymore
41 if (!_networksIniPath.isEmpty()) {
42 QSettings s(_networksIniPath, QSettings::IniFormat);
43 QStringList networks = s.childGroups();
44 if (!networks.isEmpty()) {
45 // we sort the list case-insensitive
46 QMap<QString, QString> sorted;
47 foreach(QString net, networks) {
48 if (onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
50 sorted[net.toLower()] = net;
52 return sorted.values();
59 QStringList PresetNetworks::defaultChannels(const QString &networkName)
61 if (_networksIniPath.isEmpty()) // be sure to have called presetNetworks() first, else this always fails
63 QSettings s(_networksIniPath, QSettings::IniFormat);
64 return s.value(QString("%1/DefaultChannels").arg(networkName)).toStringList();
68 NetworkInfo PresetNetworks::networkInfo(const QString &networkName)
71 if (!_networksIniPath.isEmpty()) {
72 info.networkName = networkName;
73 QSettings s(_networksIniPath, QSettings::IniFormat);
74 s.beginGroup(info.networkName);
75 foreach(QString server, s.value("Servers").toStringList()) {
77 QStringList splitserver = server.split(':', QString::SkipEmptyParts);
78 if (splitserver.count() != 2) {
79 qWarning() << "Invalid server entry in networks.conf:" << server;
82 if (splitserver[1].at(0) == '+')
84 uint port = splitserver[1].toUInt();
86 qWarning() << "Invalid port entry in networks.conf:" << server;
89 // TODO Should networks.conf be modified to allow requiring SSL?
90 info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl, false);