forked from rpm-software-management/dnf5
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.cpp
87 lines (68 loc) · 2.85 KB
/
context.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
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/
#include "context.hpp"
#include "commands/command.hpp"
#include <dnf5daemon-server/dbus.hpp>
#include <dnf5daemon-server/utils.hpp>
#include <libdnf5/rpm/package_set.hpp>
#include <locale.h>
#include <sdbus-c++/sdbus-c++.h>
#include <filesystem>
#include <iostream>
#include <string>
namespace dnfdaemon::client {
void Context::init_session(sdbus::IConnection & connection) {
// open dnf5daemon-server session
auto cfg = static_cast<DaemonCommand *>(get_selected_command())->session_config();
auto session_manager_proxy = sdbus::createProxy(connection, dnfdaemon::DBUS_NAME, dnfdaemon::DBUS_OBJECT_PATH);
session_manager_proxy->finishRegistration();
// set up the install root end setopts
std::map<std::string, std::string> empty_options{};
auto config = key_value_map_get<std::map<std::string, std::string>>(cfg, "config", empty_options);
std::filesystem::path ir{installroot.get_value()};
config["installroot"] = ir.string();
for (auto & opt : setopts) {
config[opt.first] = opt.second;
}
cfg["config"] = config;
if (!releasever.get_value().empty()) {
cfg["releasever"] = releasever.get_value();
}
cfg["locale"] = setlocale(LC_MESSAGES, nullptr);
session_manager_proxy->callMethod("open_session")
.onInterface(dnfdaemon::INTERFACE_SESSION_MANAGER)
.withArguments(cfg)
.storeResultsTo(session_object_path);
session_proxy = sdbus::createProxy(connection, dnfdaemon::DBUS_NAME, session_object_path);
// register progress bars callbacks
download_cb = std::make_unique<DownloadCB>(*this);
transaction_cb = std::make_unique<TransactionCB>(*this);
session_proxy->finishRegistration();
}
void Context::on_repositories_ready(const bool & result) {
if (result) {
repositories_status = dnfdaemon::RepoStatus::READY;
} else {
repositories_status = dnfdaemon::RepoStatus::ERROR;
}
}
void Context::reset_download_cb() {
if (download_cb) {
download_cb->reset_progress_bar();
download_cb->set_number_widget_visible(true);
download_cb->set_show_total_bar_limit(0);
}
}
} // namespace dnfdaemon::client