qBittorrent
profile_p.h
Go to the documentation of this file.
1 /*
2  * Bittorrent Client using Qt and libtorrent.
3  * Copyright (C) 2016 Eugene Shalygin <eugene.shalygin@gmail.com>
4  * Copyright (C) 2012 Christophe Dumez
5  *
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.
10  *
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.
15  *
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.
19  *
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.
28  */
29 
30 #pragma once
31 
32 #include <QDir>
33 #include <QStandardPaths>
34 
35 #include "base/profile.h"
36 
37 namespace Private
38 {
39  class Profile
40  {
41  public:
42  virtual ~Profile() = default;
43 
44  virtual QString rootPath() const = 0;
45 
49  virtual QString basePath() const = 0;
50 
51  virtual QString cacheLocation() const = 0;
52  virtual QString configLocation() const = 0;
53  virtual QString dataLocation() const = 0;
54  virtual QString downloadLocation() const = 0;
55 
56  virtual SettingsPtr applicationSettings(const QString &name) const = 0;
57 
58  QString configurationName() const;
59 
63  QString profileName() const;
64 
65  protected:
66  explicit Profile(const QString &configurationName);
67 
68  QString configurationSuffix() const;
69 
70  private:
72  };
73 
75  class DefaultProfile final : public Profile
76  {
77  public:
78  explicit DefaultProfile(const QString &configurationName);
79 
80  QString rootPath() const override;
81  QString basePath() const override;
82  QString cacheLocation() const override;
83  QString configLocation() const override;
84  QString dataLocation() const override;
85  QString downloadLocation() const override;
86  SettingsPtr applicationSettings(const QString &name) const override;
87 
88  private:
95  QString locationWithConfigurationName(QStandardPaths::StandardLocation location) const;
96  };
97 
99  class CustomProfile final : public Profile
100  {
101  public:
102  CustomProfile(const QString &rootPath, const QString &configurationName);
103 
104  QString rootPath() const override;
105  QString basePath() const override;
106  QString cacheLocation() const override;
107  QString configLocation() const override;
108  QString dataLocation() const override;
109  QString downloadLocation() const override;
110  SettingsPtr applicationSettings(const QString &name) const override;
111 
112  private:
113  const QDir m_rootDir;
114  const QDir m_baseDir;
115  const QString m_cacheLocation;
116  const QString m_configLocation;
117  const QString m_dataLocation;
118  const QString m_downloadLocation;
119  };
120 
122  {
123  public:
124  virtual QString toPortablePath(const QString &path) const = 0;
125  virtual QString fromPortablePath(const QString &portablePath) const = 0;
126  virtual ~PathConverter() = default;
127  };
128 
129  class NoConvertConverter final : public PathConverter
130  {
131  public:
132  QString toPortablePath(const QString &path) const override;
133  QString fromPortablePath(const QString &portablePath) const override;
134  };
135 
136  class Converter final : public PathConverter
137  {
138  public:
139  explicit Converter(const QString &basePath);
140  QString toPortablePath(const QString &path) const override;
141  QString fromPortablePath(const QString &portablePath) const override;
142 
143  private:
144  QDir m_baseDir;
145  };
146 }
Converter(const QString &basePath)
Definition: profile_p.cpp:190
QString fromPortablePath(const QString &portablePath) const override
Definition: profile_p.cpp:214
QString toPortablePath(const QString &path) const override
Definition: profile_p.cpp:196
Custom tree: creates directories under the specified root directory.
Definition: profile_p.h:100
const QString m_downloadLocation
Definition: profile_p.h:118
const QDir m_baseDir
Definition: profile_p.h:114
const QString m_configLocation
Definition: profile_p.h:116
QString cacheLocation() const override
Definition: profile_p.cpp:148
SettingsPtr applicationSettings(const QString &name) const override
Definition: profile_p.cpp:168
QString dataLocation() const override
Definition: profile_p.cpp:158
QString rootPath() const override
Definition: profile_p.cpp:138
const QDir m_rootDir
Definition: profile_p.h:113
const QString m_dataLocation
Definition: profile_p.h:117
QString downloadLocation() const override
Definition: profile_p.cpp:163
QString configLocation() const override
Definition: profile_p.cpp:153
QString basePath() const override
The base path against to which portable (relative) paths are resolved.
Definition: profile_p.cpp:143
CustomProfile(const QString &rootPath, const QString &configurationName)
Definition: profile_p.cpp:127
const QString m_cacheLocation
Definition: profile_p.h:115
Default implementation. Takes paths from system.
Definition: profile_p.h:76
SettingsPtr applicationSettings(const QString &name) const override
Definition: profile_p.cpp:113
QString configLocation() const override
Definition: profile_p.cpp:74
QString downloadLocation() const override
Definition: profile_p.cpp:108
QString basePath() const override
The base path against to which portable (relative) paths are resolved.
Definition: profile_p.cpp:64
DefaultProfile(const QString &configurationName)
Definition: profile_p.cpp:54
QString locationWithConfigurationName(QStandardPaths::StandardLocation location) const
Standard path writable location for profile files.
Definition: profile_p.cpp:122
QString cacheLocation() const override
Definition: profile_p.cpp:69
QString dataLocation() const override
Definition: profile_p.cpp:84
QString rootPath() const override
Definition: profile_p.cpp:59
QString fromPortablePath(const QString &portablePath) const override
Definition: profile_p.cpp:180
QString toPortablePath(const QString &path) const override
Definition: profile_p.cpp:185
virtual ~PathConverter()=default
virtual QString toPortablePath(const QString &path) const =0
virtual QString fromPortablePath(const QString &portablePath) const =0
virtual SettingsPtr applicationSettings(const QString &name) const =0
virtual QString downloadLocation() const =0
QString profileName() const
QCoreApplication::applicationName() with optional configuration name appended.
Definition: profile_p.cpp:49
QString configurationName() const
Definition: profile_p.cpp:39
virtual QString rootPath() const =0
virtual QString dataLocation() const =0
virtual ~Profile()=default
virtual QString cacheLocation() const =0
Profile(const QString &configurationName)
Definition: profile_p.cpp:34
QString configurationSuffix() const
Definition: profile_p.cpp:44
QString m_configurationName
Definition: profile_p.h:71
virtual QString configLocation() const =0
virtual QString basePath() const =0
The base path against to which portable (relative) paths are resolved.
std::unique_ptr< QSettings > SettingsPtr
Definition: profile.h:44