forked from linuxdeepin/dde-application-wizard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkutils.cpp
112 lines (84 loc) · 3.75 KB
/
pkutils.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
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "pkutils.h"
// PackageKit-Qt
#include <Daemon>
#include <QCoroSignal>
#include <qcoroasyncgenerator.h>
#include <stdexcept>
#include <transaction.h>
#include <tuple>
QCoro::Task<PKUtils::PkPackages> PKUtils::searchFiles(const QString &search, PackageKit::Transaction::Filters filters)
{
PackageKit::Transaction * tx = PackageKit::Daemon::searchFiles(search, filters);
PkPackages results;
QObject::connect(tx, &PackageKit::Transaction::package, [&results](PackageKit::Transaction::Info info, const QString &packageID, const QString &summary){
results.append(std::make_tuple(info, packageID, summary));
});
const auto [status, runtime] = co_await qCoro(tx, &PackageKit::Transaction::finished);
qDebug() << "searchFiles Coro" << status << runtime;
co_return results;
}
QCoro::Task<PKUtils::PkPackages> PKUtils::searchNames(const QString & search, PackageKit::Transaction::Filters filters)
{
PackageKit::Transaction * tx = PackageKit::Daemon::searchNames(search, filters);
PkPackages results;
QObject::connect(tx, &PackageKit::Transaction::package, [&results](PackageKit::Transaction::Info info, const QString &packageID, const QString &summary){
results.append(std::make_tuple(info, packageID, summary));
});
const auto [status, runtime] = co_await qCoro(tx, &PackageKit::Transaction::finished);
qDebug() << "searchNames Coro" << status << runtime;
co_return results;
}
QCoro::Task<PKUtils::PkPackages> PKUtils::resolve(const QString & packageName, PackageKit::Transaction::Filters filters)
{
PackageKit::Transaction * tx = PackageKit::Daemon::resolve(packageName);
PkPackages results;
QObject::connect(tx, &PackageKit::Transaction::package, [&results](PackageKit::Transaction::Info info, const QString &packageID, const QString &summary){
results.append(std::make_tuple(info, packageID, summary));
qDebug() << packageID;
});
const auto [status, runtime] = co_await qCoro(tx, &PackageKit::Transaction::finished);
qDebug() << "resolve Coro" << status << runtime;
co_return results;
}
QCoro::Task<void> PKUtils::installPackage(const PkPackage & package)
{
QString pkgId;
std::tie(std::ignore, pkgId, std::ignore) = package;
co_await installPackage(pkgId);
co_return;
}
QCoro::Task<void> PKUtils::installPackage(const QString & packageId)
{
PackageKit::Transaction * tx = PackageKit::Daemon::installPackage(packageId);
PackageKit::Transaction::Error _error;
QString _details;
QObject::connect(tx, &PackageKit::Transaction::errorCode, [&_error, &_details](PackageKit::Transaction::Error error, const QString &details){
_error = error;
_details = details;
});
const auto [status, runtime] = co_await qCoro(tx, &PackageKit::Transaction::finished);
qDebug() << "installPackage Coro" << status << runtime;
if (status != PackageKit::Transaction::ExitSuccess) {
throw PkError(_error, _details);
}
co_return;
}
QCoro::Task<void> PKUtils::removePackage(const QString &packageId)
{
PackageKit::Transaction * tx = PackageKit::Daemon::removePackage(packageId);
PackageKit::Transaction::Error _error;
QString _details;
QObject::connect(tx, &PackageKit::Transaction::errorCode, [&_error, &_details](PackageKit::Transaction::Error error, const QString &details){
_error = error;
_details = details;
});
const auto [status, runtime] = co_await qCoro(tx, &PackageKit::Transaction::finished);
qDebug() << "removePackage Coro" << status << runtime;
if (status != PackageKit::Transaction::ExitSuccess) {
throw PkError(_error, _details);
}
co_return;
}