This repository was archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathqautostart.cpp
More file actions
128 lines (107 loc) · 2.8 KB
/
Copy pathqautostart.cpp
File metadata and controls
128 lines (107 loc) · 2.8 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "qautostart.h"
#include "qautostart_p.h"
#include <QDir>
#ifdef QT_GUI_LIB
#include <QGuiApplication>
#else
#include <QCoreApplication>
#endif
QAutoStart::QAutoStart(QObject *parent) :
QObject{parent},
d{new QAutoStartPrivate{this}}
{}
QString QAutoStart::startId() const
{
return d->startId;
}
QAutoStart::~QAutoStart() = default;
QString QAutoStart::program() const
{
return d->program;
}
QStringList QAutoStart::arguments() const
{
return d->arguments;
}
QAutoStart::PropertyHash QAutoStart::extraProperties() const
{
return d->extraProperties;
}
QVariant QAutoStart::extraProperty(PropertyKey key) const
{
return d->extraProperties.value(key);
}
bool QAutoStart::isAutoStartEnabled() const
{
return d->isAutoStartEnabled();
}
void QAutoStart::setStartId(QString startId)
{
if (d->startId == startId)
return;
d->startId = std::move(startId);
emit startIdChanged(d->startId);
}
void QAutoStart::setProgram(QString program)
{
if (d->program == program)
return;
d->program = std::move(program);
emit programChanged(d->program);
}
void QAutoStart::setArguments(QStringList arguments)
{
if (d->arguments == arguments)
return;
d->arguments = std::move(arguments);
emit argumentsChanged(d->arguments);
}
void QAutoStart::setExtraProperties(PropertyHash extraProperties)
{
if (d->extraProperties == extraProperties)
return;
d->extraProperties = std::move(extraProperties);
emit extraPropertiesChanged(d->extraProperties);
}
void QAutoStart::setExtraProperty(QAutoStart::PropertyKey key, const QVariant &value)
{
d->extraProperties.insert(key, value);
emit extraPropertiesChanged(d->extraProperties);
}
bool QAutoStart::setAutoStartEnabled(bool autoStartEnabled)
{
if(d->setAutoStartEnabled(autoStartEnabled)) {
emit autoStartEnabledChanged(autoStartEnabled);
return true;
} else
return false;
}
// ------------- PRIVATE IMPLEMENTATION -------------
QAutoStartPrivate::QAutoStartPrivate(QAutoStart *q_ptr) :
q_ptr{q_ptr},
startId{[](){
const auto domain = QCoreApplication::organizationDomain();
if(domain.isEmpty())
return QCoreApplication::applicationName();
else
return QStringLiteral("%1.%2").arg(domain, QCoreApplication::applicationName());
}()},
program{QCoreApplication::applicationFilePath()},
extraProperties{
#ifdef QT_GUI_LIB
{QAutoStart::DisplayName, QGuiApplication::applicationDisplayName()},
#else
{QAutoStart::DisplayName, QCoreApplication::applicationName()},
#endif
{QAutoStart::IconName, QCoreApplication::applicationName()}
}
{
extraProperties.insert(QAutoStart::Comment, extraProperties.value(QAutoStart::DisplayName));
}
QString QAutoStartPrivate::createCommand() const
{
QStringList command;
command.append(QDir::toNativeSeparators(program));
command.append(arguments);
return QStringLiteral("\"%1\"").arg(command.join(QStringLiteral("\" \"")));
}