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
|
// Copyright Contributors to the DNF5 project.
// Copyright Contributors to the libdnf project.
// SPDX-License-Identifier: GPL-2.0-or-later
//
// 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);
#ifndef SDBUS_CPP_VERSION_2
session_manager_proxy->finishRegistration();
#endif
// 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"] = sdbus::Variant(config);
if (!releasever.get_value().empty()) {
cfg["releasever"] = sdbus::Variant(releasever.get_value());
}
if (!releasever_major.get_value().empty()) {
cfg["releasever_major"] = sdbus::Variant(releasever_major.get_value());
}
if (!releasever_minor.get_value().empty()) {
cfg["releasever_minor"] = sdbus::Variant(releasever_minor.get_value());
}
cfg["locale"] = sdbus::Variant(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);
#ifndef SDBUS_CPP_VERSION_2
session_proxy->finishRegistration();
#endif
}
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
|