@@ -19,107 +19,16 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
1919
2020#include " group.hpp"
2121
22+ #include " ../../group.hpp"
2223#include " dbus.hpp"
2324
2425#include < libdnf5/common/sack/query_cmp.hpp>
2526#include < libdnf5/comps/group/group.hpp>
2627#include < libdnf5/comps/group/query.hpp>
2728#include < sdbus-c++/sdbus-c++.h>
2829
29- #include < iostream>
3030#include < string>
3131
32- enum class GroupAttribute {
33- groupid,
34- name,
35- description,
36- // TODO(mblaha): translated name / translated description
37- order,
38- order_int,
39- langonly,
40- uservisible,
41- is_default,
42- packages,
43- installed,
44- repos,
45- };
46-
47- // map string group attribute name to actual attribute
48- const std::map<std::string, GroupAttribute> group_attributes{
49- {" groupid" , GroupAttribute::groupid},
50- {" name" , GroupAttribute::name},
51- {" description" , GroupAttribute::description},
52- {" order" , GroupAttribute::order},
53- {" order_int" , GroupAttribute::order_int},
54- {" langonly" , GroupAttribute::langonly},
55- {" uservisible" , GroupAttribute::uservisible},
56- {" default" , GroupAttribute::is_default},
57- {" packages" , GroupAttribute::packages},
58- {" installed" , GroupAttribute::installed},
59- {" repos" , GroupAttribute::repos},
60- };
61-
62- dnfdaemon::KeyValueMap group_to_map (libdnf5::comps::Group & libdnf_group, const std::vector<std::string> & attributes) {
63- dnfdaemon::KeyValueMap dbus_group;
64- // add group id by default
65- dbus_group.emplace (std::make_pair (" groupid" , libdnf_group.get_groupid ()));
66- // attributes required by client
67- for (auto & attr : attributes) {
68- auto it = group_attributes.find (attr);
69- if (it == group_attributes.end ()) {
70- throw std::runtime_error (fmt::format (" Group attribute '{}' not supported" , attr));
71- }
72- switch (it->second ) {
73- case GroupAttribute::groupid:
74- // groupid is always included
75- break ;
76- case GroupAttribute::name:
77- dbus_group.emplace (attr, libdnf_group.get_name ());
78- break ;
79- case GroupAttribute::description:
80- dbus_group.emplace (attr, libdnf_group.get_description ());
81- break ;
82- case GroupAttribute::order:
83- dbus_group.emplace (attr, libdnf_group.get_order ());
84- break ;
85- case GroupAttribute::order_int:
86- dbus_group.emplace (attr, libdnf_group.get_order_int ());
87- break ;
88- case GroupAttribute::langonly:
89- dbus_group.emplace (attr, libdnf_group.get_langonly ());
90- break ;
91- case GroupAttribute::uservisible:
92- dbus_group.emplace (attr, libdnf_group.get_uservisible ());
93- break ;
94- case GroupAttribute::is_default:
95- dbus_group.emplace (attr, libdnf_group.get_default ());
96- break ;
97- case GroupAttribute::installed:
98- dbus_group.emplace (attr, libdnf_group.get_installed ());
99- break ;
100- case GroupAttribute::repos: {
101- auto repos_set = libdnf_group.get_repos ();
102- std::vector<std::string> repos (repos_set.begin (), repos_set.end ());
103- dbus_group.emplace (attr, repos);
104- break ;
105- }
106- case GroupAttribute::packages: {
107- dnfdaemon::KeyValueMapList packages;
108- for (auto pkg : libdnf_group.get_packages ()) {
109- dnfdaemon::KeyValueMap package;
110- package.emplace (" name" , pkg.get_name ());
111- package.emplace (" type" , static_cast <int >(pkg.get_type ()));
112- package.emplace (" condition" , pkg.get_condition ());
113- packages.push_back (std::move (package));
114- }
115- dbus_group.emplace (attr, packages);
116- break ;
117- }
118- }
119- }
120- return dbus_group;
121- }
122-
12332
12433void Group::dbus_register () {
12534 auto dbus_object = session.get_dbus_object ();
0 commit comments