-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdudisksjob.cpp
139 lines (111 loc) · 3.16 KB
/
dudisksjob.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
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
129
130
131
132
133
134
135
136
137
138
139
// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "dudisksjob.h"
#include "udisks2_interface.h"
#include <QDBusConnection>
class DUDisksJobPrivate
{
DUDisksJobPrivate(DUDisksJob *)
{
}
DUDisksJob *q_ptr;
OrgFreedesktopUDisks2JobInterface *dbusif;
Q_DECLARE_PUBLIC(DUDisksJob)
};
DUDisksJob::~DUDisksJob()
{
}
QString DUDisksJob::path() const
{
Q_D(const DUDisksJob);
return d->dbusif->path();
}
QStringList DUDisksJob::objects() const
{
Q_D(const DUDisksJob);
QStringList ret;
for (auto &o : d->dbusif->objects()) {
ret.push_back(o.path());
}
return ret;
}
bool DUDisksJob::cancelable() const
{
Q_D(const DUDisksJob);
return d->dbusif->cancelable();
}
bool DUDisksJob::progressValid() const
{
Q_D(const DUDisksJob);
return d->dbusif->progressValid();
}
double DUDisksJob::progress() const
{
Q_D(const DUDisksJob);
return d->dbusif->progress();
}
QString DUDisksJob::operation() const
{
Q_D(const DUDisksJob);
return d->dbusif->operation();
}
quint32 DUDisksJob::startedByUid() const
{
Q_D(const DUDisksJob);
return d->dbusif->startedByUID();
}
quint64 DUDisksJob::bytes() const
{
Q_D(const DUDisksJob);
return d->dbusif->bytes();
}
quint64 DUDisksJob::expectedEndTime() const
{
Q_D(const DUDisksJob);
return d->dbusif->expectedEndTime();
}
quint64 DUDisksJob::rate() const
{
Q_D(const DUDisksJob);
return d->dbusif->rate();
}
quint64 DUDisksJob::startTime() const
{
Q_D(const DUDisksJob);
return d->dbusif->startTime();
}
void DUDisksJob::cancel(const QVariantMap &options)
{
Q_D(DUDisksJob);
d->dbusif->Cancel(options).waitForFinished();
}
DUDisksJob::DUDisksJob(QString path, QObject *parent)
: QObject(parent)
, d_ptr(new DUDisksJobPrivate(this))
{
Q_D(DUDisksJob);
d->dbusif = new OrgFreedesktopUDisks2JobInterface(UDISKS2_SERVICE, path, QDBusConnection::systemBus());
QDBusConnection::systemBus().connect(UDISKS2_SERVICE, d->dbusif->path(), "org.freedesktop.DBus.Properties",
"PropertiesChanged", this, SLOT(onPropertiesChanged(const QString &, const QVariantMap &)));
connect(d->dbusif, &OrgFreedesktopUDisks2JobInterface::Completed, this, &DUDisksJob::completed);
}
void DUDisksJob::onPropertiesChanged(const QString &interface, const QVariantMap &changed_properties)
{
Q_UNUSED(interface)
auto begin = changed_properties.begin();
for (; begin != changed_properties.constEnd(); ++begin) {
QString property_name = begin.key();
int pindex = this->metaObject()->indexOfProperty(property_name.toLatin1().constData());
if (pindex < 0) {
property_name[0] = property_name.at(0).toLower();
pindex = this->metaObject()->indexOfProperty(property_name.toLatin1().constData());
}
if (pindex < 0)
continue;
const QMetaProperty &mp = this->metaObject()->property(pindex);
if (!mp.hasNotifySignal())
continue;
mp.notifySignal().invoke(this, QGenericArgument(begin.value().typeName(), begin.value().constData()));
}
}