No longer honours following status in JSON, instead relies solely on following list.
[larjonas-pumpa.git] / src / pumpasettings.cpp
blob3d7b52b014250146942018409514093238889d6b
1 /*
2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #include <QFile>
22 #include "pumpasettings.h"
23 #include "pumpa_defines.h"
24 #include "util.h"
26 PumpaSettings* PumpaSettings::s_settings = NULL;
28 //------------------------------------------------------------------------------
30 PumpaSettings::PumpaSettings(QString filename, QObject* parent) :
31 QObject(parent) {
32 if (filename.isEmpty())
33 m_s = new QSettings(CLIENT_NAME, CLIENT_NAME, this);
34 else
35 m_s = new QSettings(filename, QSettings::IniFormat, this);
37 m_firstStart = !QFile(m_s->fileName()).exists();
39 QFile::setPermissions(m_s->fileName(),
40 QFile::ReadOwner | QFile::WriteOwner);
43 //------------------------------------------------------------------------------
45 PumpaSettings* PumpaSettings::getSettings(bool create, QString filename,
46 QObject* parent) {
47 if (s_settings == NULL && create)
48 s_settings = new PumpaSettings(filename, parent);
50 return s_settings;
53 //------------------------------------------------------------------------------
55 QVariant PumpaSettings::getValue(QString name, QVariant defaultValue,
56 QString group) const {
57 m_s->beginGroup(group);
58 QVariant v = m_s->value(name, defaultValue);
59 m_s->endGroup();
60 return v;
63 //------------------------------------------------------------------------------
65 QString PumpaSettings::siteUrl() const {
66 return siteUrlFixer(getValue("site_url", "", "Account").toString());
69 //------------------------------------------------------------------------------
71 int PumpaSettings::reloadTime() const {
72 int reloadTime = getValue("reload_time", 1, "General").toInt();
73 if (reloadTime < 1)
74 reloadTime = 1;
75 return reloadTime;
78 //------------------------------------------------------------------------------
80 int PumpaSettings::highlightFeeds() const {
81 return getValue("highlight_feeds", 0, "General").toInt();
84 //------------------------------------------------------------------------------
86 int PumpaSettings::popupFeeds() const {
87 return getValue("popup_feeds", 0, "General").toInt();
90 //------------------------------------------------------------------------------
91 // Setters
92 //------------------------------------------------------------------------------
94 void PumpaSettings::setValue(QString name, QVariant value, QString group) {
95 m_s->beginGroup(group);
96 m_s->setValue(name, value);
97 m_s->endGroup();
100 //------------------------------------------------------------------------------
102 void PumpaSettings::useTrayIcon(bool b) {
103 bool old = useTrayIcon();
104 setValue("use_tray_icon", b);
105 if (old != b)
106 emit trayIconChanged();