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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
// Stephen Smally © 2012
// This program 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.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//
using Pk;
namespace Lsc.Backend {
public class AppsManager : Object {
// Signals
public signal void app_added (Package app);
public signal void category_added (string category, string group);
public signal void loading_started (string text);
public signal void loading_finished ();
public signal void details_received (Package pkg, Details details);
// PackageKit stuffs
private Client client;
private Control control;
private Cancellable transaction;
// Vars
public string[] icon_table;
public void get_pkgs_cb (Progress progress, ProgressType type) {
}
public void ready () {
loading_finished();
}
public void get_pkgs (string filters) {
Bitfield filter;
filter = filter_bitfield_from_string(filters);
loading_started("Loading packages");
client.get_packages_async(filter, null, (progress, type) => {
if (type == ProgressType.PACKAGE_ID && progress.package != null) {
stdout.printf("%s, %s\n", progress.package.get_name(), progress.package.get_arch());
app_added(progress.package);
while (Gtk.events_pending())
Gtk.main_iteration();
}
}, () => {ready();});
}
public void search_for_packages (string filters, string name) {
Bitfield filter;
filter = filter_bitfield_from_string(filters);
loading_started("Loading packages");
client.search_names_async(filter, {name}, null, (pkg) => {
if (pkg.package != null) {
app_added(pkg.package);
}
while (Gtk.events_pending())
Gtk.main_iteration();
}, () => {
loading_finished();
});
}
public void get_details (string pkg_id) {
client.get_details_async({pkg_id},
null,
() => {},
(obj, res) => {
Results contains = client.generic_finish(res);
details_received(get_package_from_id(pkg_id), contains.get_details_array()[0]);
});
}
public Package get_package_from_id (string pkg_id) {
Results res = client.resolve(filter_bitfield_from_string(""),
{pkg_id},
null,
null);
return res.get_package_array()[0];
}
private void fill_icon_table () {
icon_table = {
string.joinv("|", {group_enum_to_string(Group.UNKNOWN),"help-browser"}), /* fall though value */
string.joinv("|", {group_enum_to_string(Group.ACCESSIBILITY), "preferences-desktop-accessibility"}),
string.joinv("|", {group_enum_to_string(Group.ACCESSORIES), "applications-accessories"}),
string.joinv("|", {group_enum_to_string(Group.ADMIN_TOOLS), "system-lock-screen"}),
string.joinv("|", {group_enum_to_string(Group.COLLECTIONS), "pk-collection-installed"}),
string.joinv("|", {group_enum_to_string(Group.COMMUNICATION), "folder-remote"}),
string.joinv("|", {group_enum_to_string(Group.DESKTOP_GNOME), "pk-desktop-gnome"}),
string.joinv("|", {group_enum_to_string(Group.DESKTOP_KDE), "pk-desktop-kde"}),
string.joinv("|", {group_enum_to_string(Group.DESKTOP_OTHER), "user-desktop"}),
string.joinv("|", {group_enum_to_string(Group.DESKTOP_XFCE), "pk-desktop-xfce"}),
string.joinv("|", {group_enum_to_string(Group.DOCUMENTATION), "x-office-address-book"}),
string.joinv("|", {group_enum_to_string(Group.EDUCATION), "utilities-system-monitor"}),
string.joinv("|", {group_enum_to_string(Group.ELECTRONICS), "video-display"}),
string.joinv("|", {group_enum_to_string(Group.FONTS), "preferences-desktop-font"}),
string.joinv("|", {group_enum_to_string(Group.GAMES), "applications-games"}),
string.joinv("|", {group_enum_to_string(Group.GRAPHICS), "applications-graphics"}),
string.joinv("|", {group_enum_to_string(Group.INTERNET), "applications-internet"}),
string.joinv("|", {group_enum_to_string(Group.LEGACY), "media-floppy"}),
string.joinv("|", {group_enum_to_string(Group.LOCALIZATION), "preferences-desktop-locale"}),
string.joinv("|", {group_enum_to_string(Group.MAPS), "applications-multimedia"}),
string.joinv("|", {group_enum_to_string(Group.MULTIMEDIA), "applications-multimedia"}),
string.joinv("|", {group_enum_to_string(Group.NETWORK), "network-wired"}),
string.joinv("|", {group_enum_to_string(Group.OFFICE), "applications-office"}),
string.joinv("|", {group_enum_to_string(Group.OTHER), "applications-other"}),
string.joinv("|", {group_enum_to_string(Group.POWER_MANAGEMENT), "battery"}),
string.joinv("|", {group_enum_to_string(Group.PROGRAMMING), "applications-development"}),
string.joinv("|", {group_enum_to_string(Group.PUBLISHING), "accessories-dictionary"}),
string.joinv("|", {group_enum_to_string(Group.REPOS), "system-file-manager"}),
string.joinv("|", {group_enum_to_string(Group.SCIENCE), "application-certificate"}),
string.joinv("|", {group_enum_to_string(Group.SECURITY), "network-wireless-encrypted"}),
string.joinv("|", {group_enum_to_string(Group.SERVERS), "network-server"}),
string.joinv("|", {group_enum_to_string(Group.SYSTEM), "applications-system"}),
string.joinv("|", {group_enum_to_string(Group.VIRTUALIZATION), "computer"}),
string.joinv("|", {group_enum_to_string(Group.VENDOR), "application-certificate"}),
string.joinv("|", {group_enum_to_string(Group.NEWEST), "dialog-information"})
};
}
private string group_to_icon_name(string group) {
foreach (string couple in icon_table) {
if (couple.split("|")[0] == group) {
return couple.split("|")[1];
}
}
return "";
}
public void get_categories () {
/*
for (int i = 0; i < Group.LAST; i++) {
if (i != Group.COLLECTIONS && i != Group.NEWEST)
category_added(group_to_icon_name(group_enum_to_string((Group)i)), group_enum_to_string((Group)i));
}*/
category_added("applications-accessories", "Accessories");
category_added("applications-internet", "Internet");
category_added("applications-office", "Office");
category_added("applications-multimedia", "Multimedia");
category_added("applications-development", "Development");
category_added("category-show-all", "All");
}
public void get_screenshot (string pkg_name) {
}
public AppsManager () {
client = new Client();
control = new Control();
transaction = new Cancellable();
fill_icon_table();
}
}
}
|