-
Notifications
You must be signed in to change notification settings - Fork 1
/
cpputils.cpp
72 lines (56 loc) · 1.78 KB
/
cpputils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "cpputils.h"
#include <QClipboard>
#include <QGuiApplication>
Q_LOGGING_CATEGORY(CppSingletone, "CppUtils")
CppUtils::CppUtils(QObject *parent) : QObject(parent)
{ }
CppUtils::~CppUtils()
{ }
void CppUtils::copyToClipboard(const QString& text) const
{
qCDebug(CppSingletone) << text;
QGuiApplication::clipboard()->setText(text);
}
QString CppUtils::prependWithDownloadsPath(const QString &fileName) const
{
static QString dirName;
if (dirName.isEmpty())
{
// dirName = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QStringLiteral("/AMeditation");
dirName = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); // + QStringLiteral("/AMeditation");
qCDebug(CppSingletone) << "Directory for downloads:" << dirName;
}
if (!QDir(dirName).exists() && !QDir().mkpath(dirName))
{
qCCritical(CppSingletone) << "Can't create directory for downloads:" << dirName;
return fileName;
}
return QDir::cleanPath(dirName + QDir::separator() + fileName);
}
bool CppUtils::openUrlExternally(const QString &url) const
{
return QDesktopServices::openUrl(QUrl(url));
}
bool CppUtils::removeFile(const QString &fileName) const
{
QFileInfo fi(fileName);
if (!fi.exists())
{
qCWarning(CppSingletone) << "Local file doesn't exist:" << fileName;
return false;
}
return QFile::remove(fileName);
}
bool CppUtils::isFileExists(const QString &fileName) const
{
QFileInfo fi(fileName);
bool exists = fi.exists();
qCDebug(CppSingletone) << "isFileExists:" << exists << fileName;
return exists;
}
QObject *CppUtils::cppUtilsSingletoneProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new CppUtils();
}