1 /***************************************************************************
2 * Copyright (C) 2005-2019 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 ***************************************************************************/
21 #include "presetnetworks.h"
27 QString PresetNetworks::_networksIniPath = QString();
29 // ====================
31 // ====================
32 QStringList PresetNetworks::names(bool onlyDefault)
34 // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
35 if (_networksIniPath.isNull()) {
36 _networksIniPath = Quassel::findDataFilePath("networks.ini");
37 if (_networksIniPath.isNull()) {
38 _networksIniPath = ""; // now we won't check again, as it's not null anymore
42 if (!_networksIniPath.isEmpty()) {
43 QSettings s(_networksIniPath, QSettings::IniFormat);
44 QStringList networks = s.childGroups();
45 if (!networks.isEmpty()) {
46 // we sort the list case-insensitive
47 QMap<QString, QString> sorted;
48 foreach (QString net, networks) {
49 if (onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
51 sorted[net.toLower()] = net;
53 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();
67 NetworkInfo PresetNetworks::networkInfo(const QString& networkName)
70 if (!_networksIniPath.isEmpty()) {
71 info.networkName = networkName;
72 QSettings s(_networksIniPath, QSettings::IniFormat);
73 s.beginGroup(info.networkName);
74 foreach (QString server, s.value("Servers").toStringList()) {
76 QStringList splitserver = server.split(':', QString::SkipEmptyParts);
77 if (splitserver.count() != 2) {
78 qWarning() << "Invalid server entry in networks.conf:" << server;
81 if (splitserver[1].at(0) == '+')
83 uint port = splitserver[1].toUInt();
85 qWarning() << "Invalid port entry in networks.conf:" << server;
88 // TODO Should networks.conf be modified to allow requiring SSL?
89 info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl, false);