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 "profile_p.h"
34 Profile
*Profile::m_instance
= nullptr;
36 Profile::Profile(const QString
&rootProfilePath
, const QString
&configurationName
, const bool convertPathsToProfileRelative
)
38 if (rootProfilePath
.isEmpty())
39 m_profileImpl
= std::make_unique
<Private::DefaultProfile
>(configurationName
);
41 m_profileImpl
= std::make_unique
<Private::CustomProfile
>(rootProfilePath
, configurationName
);
43 ensureDirectoryExists(SpecialFolder::Cache
);
44 ensureDirectoryExists(SpecialFolder::Config
);
45 ensureDirectoryExists(SpecialFolder::Data
);
47 if (convertPathsToProfileRelative
)
48 m_pathConverterImpl
= std::make_unique
<Private::Converter
>(m_profileImpl
->basePath());
50 m_pathConverterImpl
= std::make_unique
<Private::NoConvertConverter
>();
53 void Profile::initInstance(const QString
&rootProfilePath
, const QString
&configurationName
,
54 const bool convertPathsToProfileRelative
)
58 m_instance
= new Profile(rootProfilePath
, configurationName
, convertPathsToProfileRelative
);
61 void Profile::freeInstance()
67 const Profile
*Profile::instance()
72 QString
Profile::location(const SpecialFolder folder
) const
77 case SpecialFolder::Cache
:
78 result
= m_profileImpl
->cacheLocation();
80 case SpecialFolder::Config
:
81 result
= m_profileImpl
->configLocation();
83 case SpecialFolder::Data
:
84 result
= m_profileImpl
->dataLocation();
86 case SpecialFolder::Downloads
:
87 result
= m_profileImpl
->downloadLocation();
91 if (!result
.endsWith(QLatin1Char('/')))
92 result
+= QLatin1Char('/');
96 QString
Profile::rootPath() const
98 return m_profileImpl
->rootPath();
101 QString
Profile::configurationName() const
103 return m_profileImpl
->configurationName();
106 QString
Profile::profileName() const
108 return m_profileImpl
->profileName();
111 SettingsPtr
Profile::applicationSettings(const QString
&name
) const
113 return m_profileImpl
->applicationSettings(name
);
116 void Profile::ensureDirectoryExists(const SpecialFolder folder
) const
118 const QString locationPath
= location(folder
);
119 if (!locationPath
.isEmpty() && !QDir().mkpath(locationPath
))
120 qFatal("Could not create required directory '%s'", qUtf8Printable(locationPath
));
123 QString
Profile::toPortablePath(const QString
&absolutePath
) const
125 return m_pathConverterImpl
->toPortablePath(absolutePath
);
128 QString
Profile::fromPortablePath(const QString
&portablePath
) const
130 return m_pathConverterImpl
->fromPortablePath(portablePath
);
133 QString
specialFolderLocation(const SpecialFolder folder
)
135 return Profile::instance()->location(folder
);