2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2016 Eugene Shalygin <eugene.shalygin@gmail.com>
4 * Copyright (C) 2012 Christophe Dumez
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
32 #include <QStandardPaths>
34 #include "base/path.h"
42 virtual ~Profile() = default;
44 virtual Path
rootPath() const = 0;
47 * @brief The base path against to which portable (relative) paths are resolved
49 virtual Path
basePath() const = 0;
51 virtual Path
cacheLocation() const = 0;
52 virtual Path
configLocation() const = 0;
53 virtual Path
dataLocation() const = 0;
54 virtual Path
downloadLocation() const = 0;
56 virtual SettingsPtr
applicationSettings(const QString
&name
) const = 0;
58 QString
configurationName() const;
61 * @brief QCoreApplication::applicationName() with optional configuration name appended
63 QString
profileName() const;
66 explicit Profile(const QString
&configurationName
);
68 QString
configurationSuffix() const;
71 QString m_configurationName
;
74 /// Default implementation. Takes paths from system
75 class DefaultProfile final
: public Profile
78 explicit DefaultProfile(const QString
&configurationName
);
80 Path
rootPath() const override
;
81 Path
basePath() const override
;
82 Path
cacheLocation() const override
;
83 Path
configLocation() const override
;
84 Path
dataLocation() const override
;
85 Path
downloadLocation() const override
;
86 SettingsPtr
applicationSettings(const QString
&name
) const override
;
90 * @brief Standard path writable location for profile files
92 * @param location location kind
93 * @return QStandardPaths::writableLocation(location) / configurationName()
95 Path
locationWithConfigurationName(QStandardPaths::StandardLocation location
) const;
98 /// Custom tree: creates directories under the specified root directory
99 class CustomProfile final
: public Profile
102 CustomProfile(const Path
&rootPath
, const QString
&configurationName
);
104 Path
rootPath() const override
;
105 Path
basePath() const override
;
106 Path
cacheLocation() const override
;
107 Path
configLocation() const override
;
108 Path
dataLocation() const override
;
109 Path
downloadLocation() const override
;
110 SettingsPtr
applicationSettings(const QString
&name
) const override
;
113 const Path m_rootPath
;
114 const Path m_basePath
;
115 const Path m_cacheLocation
;
116 const Path m_configLocation
;
117 const Path m_dataLocation
;
118 const Path m_downloadLocation
;
124 virtual Path
toPortablePath(const Path
&path
) const = 0;
125 virtual Path
fromPortablePath(const Path
&portablePath
) const = 0;
126 virtual ~PathConverter() = default;
129 class NoConvertConverter final
: public PathConverter
132 Path
toPortablePath(const Path
&path
) const override
;
133 Path
fromPortablePath(const Path
&portablePath
) const override
;
136 class Converter final
: public PathConverter
139 explicit Converter(const Path
&basePath
);
140 Path
toPortablePath(const Path
&path
) const override
;
141 Path
fromPortablePath(const Path
&portablePath
) const override
;