passwordmanager/quickgui/applicationpaths.h

42 lines
885 B
C
Raw Normal View History

2015-04-22 19:30:09 +02:00
#ifndef APPLICATIONPATHS_H
#define APPLICATIONPATHS_H
#include <QDir>
#include <QStandardPaths>
#include <QStringList>
namespace QtGui {
2017-05-01 03:26:04 +02:00
class ApplicationPaths {
2015-04-22 19:30:09 +02:00
public:
static QString settingsPath();
static QString dowloadedFilesPath();
2017-05-01 03:26:04 +02:00
2015-04-22 19:30:09 +02:00
protected:
static QString path(QStandardPaths::StandardLocation location);
};
inline QString ApplicationPaths::settingsPath()
{
return path(QStandardPaths::DataLocation);
}
inline QString ApplicationPaths::dowloadedFilesPath()
{
return path(QStandardPaths::CacheLocation);
}
inline QString ApplicationPaths::path(QStandardPaths::StandardLocation location)
{
QString path = QStandardPaths::standardLocations(location).value(0);
QDir dir(path);
2017-05-01 03:26:04 +02:00
if (!dir.exists())
2015-04-22 19:30:09 +02:00
dir.mkpath(path);
2017-05-01 03:26:04 +02:00
if (!path.isEmpty() && !path.endsWith("/"))
2015-04-22 19:30:09 +02:00
path += "/";
return path;
}
}
#endif // APPLICATIONPATHS_H