1/*
2 * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15#ifndef CONFIGFILE_H
16#define CONFIGFILE_H
17
18#include "owncloudlib.h"
19#include <memory>
20#include <QSharedPointer>
21#include <QSettings>
22#include <QString>
23#include <QVariant>
24#include <chrono>
25
26class QWidget;
27class QHeaderView;
28class ExcludedFiles;
29
30namespace OCC {
31
32class AbstractCredentials;
33
34/**
35 * @brief The ConfigFile class
36 * @ingroup libsync
37 */
38class OWNCLOUDSYNC_EXPORT ConfigFile
39{
40public:
41 ConfigFile();
42
43 enum Scope { UserScope,
44 SystemScope };
45
46 QString configPath() const;
47 QString configFile() const;
48 QString excludeFile(Scope scope) const;
49 static QString excludeFileFromSystem(); // doesn't access config dir
50
51 /**
52 * Creates a backup of the file
53 *
54 * Returns the path of the new backup.
55 */
56 QString backup() const;
57
58 bool exists();
59
60 QString defaultConnection() const;
61
62 // the certs do not depend on a connection.
63 QByteArray caCerts();
64 void setCaCerts(const QByteArray &);
65
66 bool passwordStorageAllowed(const QString &connection = QString());
67
68 // max count of lines in the log window
69 int maxLogLines() const;
70 void setMaxLogLines(int);
71
72 /* Server poll interval in milliseconds */
73 std::chrono::milliseconds remotePollInterval(const QString &connection = QString()) const;
74 /* Set poll interval. Value in milliseconds has to be larger than 5000 */
75 void setRemotePollInterval(std::chrono::milliseconds interval, const QString &connection = QString());
76
77 /* Interval to check for new notifications */
78 std::chrono::milliseconds notificationRefreshInterval(const QString &connection = QString()) const;
79
80 /* Force sync interval, in milliseconds */
81 std::chrono::milliseconds forceSyncInterval(const QString &connection = QString()) const;
82
83 /**
84 * Interval in milliseconds within which full local discovery is required
85 *
86 * Use -1 to disable regular full local discoveries.
87 */
88 std::chrono::milliseconds fullLocalDiscoveryInterval() const;
89
90 bool monoIcons() const;
91 void setMonoIcons(bool);
92
93 bool promptDeleteFiles() const;
94 void setPromptDeleteFiles(bool promptDeleteFiles);
95
96 bool crashReporter() const;
97 void setCrashReporter(bool enabled);
98
99 bool automaticLogDir() const;
100 void setAutomaticLogDir(bool enabled);
101
102 // Whether experimental UI options should be shown
103 bool showExperimentalOptions() const;
104
105 // proxy settings
106 void setProxyType(int proxyType,
107 const QString &host = QString(),
108 int port = 0, bool needsAuth = false,
109 const QString &user = QString(),
110 const QString &pass = QString());
111
112 int proxyType() const;
113 QString proxyHostName() const;
114 int proxyPort() const;
115 bool proxyNeedsAuth() const;
116 QString proxyUser() const;
117 QString proxyPassword() const;
118
119 /** 0: no limit, 1: manual, >0: automatic */
120 int useUploadLimit() const;
121 int useDownloadLimit() const;
122 void setUseUploadLimit(int);
123 void setUseDownloadLimit(int);
124 /** in kbyte/s */
125 int uploadLimit() const;
126 int downloadLimit() const;
127 void setUploadLimit(int kbytes);
128 void setDownloadLimit(int kbytes);
129 /** [checked, size in MB] **/
130 QPair<bool, quint64> newBigFolderSizeLimit() const;
131 void setNewBigFolderSizeLimit(bool isChecked, quint64 mbytes);
132 bool confirmExternalStorage() const;
133 void setConfirmExternalStorage(bool);
134
135 /** If we should move the files deleted on the server in the trash */
136 bool moveToTrash() const;
137 void setMoveToTrash(bool);
138
139 static bool setConfDir(const QString &value);
140
141 bool optionalDesktopNotifications() const;
142 void setOptionalDesktopNotifications(bool show);
143
144 bool showInExplorerNavigationPane() const;
145 void setShowInExplorerNavigationPane(bool show);
146
147 int timeout() const;
148 quint64 chunkSize() const;
149 quint64 maxChunkSize() const;
150 quint64 minChunkSize() const;
151 std::chrono::milliseconds targetChunkUploadDuration() const;
152
153 void saveGeometry(QWidget *w);
154 void restoreGeometry(QWidget *w);
155
156 // how often the check about new versions runs
157 std::chrono::milliseconds updateCheckInterval(const QString &connection = QString()) const;
158
159 bool skipUpdateCheck(const QString &connection = QString()) const;
160 void setSkipUpdateCheck(bool, const QString &);
161
162 QString updateChannel() const;
163 void setUpdateChannel(const QString &channel);
164
165 void saveGeometryHeader(QHeaderView *header);
166 void restoreGeometryHeader(QHeaderView *header);
167
168 QString certificatePath() const;
169 void setCertificatePath(const QString &cPath);
170 QString certificatePasswd() const;
171 void setCertificatePasswd(const QString &cPasswd);
172
173 /** The client version that last used this settings file.
174 Updated by configVersionMigration() at client startup. */
175 QString clientVersionString() const;
176 void setClientVersionString(const QString &version);
177
178 /** Returns a new settings pre-set in a specific group. The Settings will be created
179 with the given parent. If no parent is specified, the caller must destroy the settings */
180 static std::unique_ptr<QSettings> settingsWithGroup(const QString &group, QObject *parent = 0);
181
182 /// Add the system and user exclude file path to the ExcludedFiles instance.
183 static void setupDefaultExcludeFilePaths(ExcludedFiles &excludedFiles);
184
185protected:
186 QVariant getPolicySetting(const QString &policy, const QVariant &defaultValue = QVariant()) const;
187 void storeData(const QString &group, const QString &key, const QVariant &value);
188 QVariant retrieveData(const QString &group, const QString &key) const;
189 void removeData(const QString &group, const QString &key);
190 bool dataExists(const QString &group, const QString &key) const;
191
192private:
193 QVariant getValue(const QString &param, const QString &group = QString(),
194 const QVariant &defaultValue = QVariant()) const;
195 void setValue(const QString &key, const QVariant &value);
196
197private:
198 typedef QSharedPointer<AbstractCredentials> SharedCreds;
199
200 static bool _askedUser;
201 static QString _oCVersion;
202 static QString _confDir;
203};
204}
205#endif // CONFIGFILE_H
206