1/****************************************************************************
2**
3** Copyright (C) 2006-2007 Ralf Habacker. All rights reserved.
4**
5** This file is part of the KDE installer for windows
6**
7** This library is free software; you can redistribute it and/or
8** modify it under the terms of the GNU Library General Public
9** License version 2 as published by the Free Software Foundation.
10**
11** This library is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14** Library General Public License for more details.
15**
16** You should have received a copy of the GNU Library General Public License
17** along with this library; see the file COPYING.LIB. If not, write to
18** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19** Boston, MA 02110-1301, USA.
20**
21****************************************************************************/
22
23#ifndef SETTINGS_H
24#define SETTINGS_H
25
26#include "misc.h"
27#include "typehelper.h"
28#include "proxysettings.h"
29
30#include <QDir>
31#include <QObject>
32#include <QSettings>
33#include <QStringList>
34#include <QUrl>
35
36/**
37 holds global options, which are stored in a local user specific config file
38*/
39class Settings : public QObject
40{
41 Q_OBJECT
42public:
43 Settings();
44 ~Settings();
45
46 // Place where the packages should be installed to
47 QString installDir() const;
48 void setInstallDir(const QString &dir, bool persistent=true);
49
50 // Place where the packages should be downloaded to
51 QString downloadDir() const;
52 void setDownloadDir(const QString &dir, bool persistent=true);
53
54 // download mirror base url
55 QString mirror() const;
56 void setMirror(const QString &mirror);
57
58 // url of last used mirror url
59 QUrl mirrorWithReleasePath() const { return m_settings->value("MirrorWithReleasePath", "").toString(); }
60 void setMirrorWithReleasePath(const QUrl &url) { m_settings->setValue("MirrorWithReleasePath", url.toString()); sync(); }
61
62 // additional download mirrors
63 QStringList localMirrors() const;
64 void addLocalMirror(const QString &locMirror);
65 void setLocalMirrors(const QStringList& locMirrors);
66
67 // show title page
68 bool showTitlePage() const;
69 void setShowTitlePage(bool bShow);
70
71 bool isSkipBasicSettings() const { return m_settings->value("SkipBasicSettings", false).toBool(); }
72 void setSkipBasicSettings(bool mode) { m_settings->setValue("SkipBasicSettings", mode); sync(); }
73
74 // create start menu entries fomr .desktop files
75 bool createStartMenuEntries();
76 void setCreateStartMenuEntries(bool bCreate);
77
78 // true on first run
79 bool isFirstRun() const { return m_settingsMain->value("FirstRun", true).toBool(); }
80 void setFirstRun(bool bFirstRun) { m_settingsMain->setValue("FirstRun", bFirstRun); sync(); }
81
82 // package Manager mode
83 bool isPackageManagerMode() const { return m_settings->value("PackageManagerMode", m_settingsMain->value("PackageManagerMode",false).toBool()).toBool(); }
84 void setPackageManagerMode(bool mode) { m_settings->setValue("PackageManagerMode", mode); sync(); }
85
86 // property of the packagerManagerMode
87 const bool isDeveloperInstallMode() { return false; }
88 void setDeveloperInstallMode() { }
89
90 /// specify the source mode of proxy settings
91 ProxySettings::ProxyMode proxyMode() const { return (ProxySettings::ProxyMode)m_settingsMain->value("proxyMode",0).toInt(); }
92 void setProxyMode(ProxySettings::ProxyMode mode) { m_settingsMain->setValue("proxyMode", mode); }
93
94 /// return proxy settings
95 bool proxy(ProxySettings &proxy)
96 {
97 proxy.hostname = proxyHost();
98 proxy.port = proxyPort();
99 proxy.user = proxyUser();
100 proxy.password = proxyPassword();
101 return true;
102 }
103
104 /// save proxy settings
105 void setProxy(const ProxySettings &proxy)
106 {
107 m_settingsMain->setValue("proxyHost",proxy.hostname);
108 m_settingsMain->setValue("proxyPort",proxy.port);
109 m_settingsMain->setValue("proxyUser",proxy.user);
110 m_settingsMain->setValue("proxyPassword",proxy.password);
111 sync();
112 }
113
114 bool installDetails() const { return m_settings->value("installDetails", false).toBool(); }
115 void setInstallDetails(bool state) { m_settings->setValue("installDetails", state); sync(); }
116
117 bool autoNextStep() const { return m_settingsMain->value("autoNextStep", true).toBool(); }
118 void setAutoNextStep(bool state) { m_settingsMain->setValue("autoNextStep", state); sync(); }
119
120 bool installDebugPackages() const { return m_settings->value("installDebugPackages", false).toBool(); }
121 void setInstallDebugPackages(bool state) { m_settings->setValue("installDebugPackages", state); sync(); }
122
123 CompilerTypes::Type compilerType() const { return (CompilerTypes::Type) (m_settings->value("compilerType",m_settingsMain->value("compilerType",0).toInt()).toInt()); }
124 void setCompilerType(CompilerTypes::Type type);
125
126 QString logFile(const QString &baseName="kdewin-installer") { return downloadDir() + QDir::separator() + baseName + ".log"; }
127
128 // QSettings compatible interface
129 void beginGroup(const QString &prefix) { m_settings->beginGroup(prefix); }
130 void endGroup() { m_settings->endGroup(); }
131 QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const { return m_settings->value(key,defaultValue); }
132 void setValue(const QString &key, const QVariant &value) { m_settings->setValue(key,value); }
133 // sync database
134 void sync();
135
136 // static methods
137 static Settings &instance();
138 static bool hasDebug(const QString area="");
139
140Q_SIGNALS:
141 void installDirChanged(const QString &newDir);
142 void downloadDirChanged(const QString &newDir);
143 void settingsChanged();
144 void compilerTypeChanged();
145
146protected:
147 QString proxyHost() const { return m_settingsMain->value("proxyHost").toString(); }
148 int proxyPort() const { return m_settingsMain->value("proxyPort").toInt(); }
149 QString proxyUser() const { return m_settingsMain->value("proxyUser").toString(); }
150 QString proxyPassword() const { return m_settingsMain->value("proxyPassword").toString(); }
151
152private:
153 // stored in user profile
154 QSettings *m_settingsMain;
155 // stored in installroot
156 QSettings *m_settings;
157
158 QString m_installDir;
159 QString m_downloadDir;
160
161 QString debug(void) { return m_settings->value("debug", "").toString(); }
162 friend QDebug operator<<(QDebug, Settings &);
163};
164
165
166#include <QDebug>
167
168inline QDebug operator<<(QDebug out, ProxySettings &c)
169{
170 out << "host:" << c.hostname << "port:" << c.port
171 << "user:" << c.user << "password:" << (c.password.isEmpty() ? "<empty>" : "****");
172 return out;
173}
174
175
176#endif
177