~lubuntu-software-center-team/lubuntu-software-center/vala-port

2 by Stephen Smally
Worked a lot!
1
//  Stephen Smally © 2012
2
//      This program is free software; you can redistribute it and/or modify
3
//      it under the terms of the GNU General Public License as published by
4
//      the Free Software Foundation; either version 2 of the License, or
5
//      (at your option) any later version.
6
//      
7
//      This program is distributed in the hope that it will be useful,
8
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
9
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
//      GNU General Public License for more details.
11
//      
12
//      You should have received a copy of the GNU General Public License
13
//      along with this program; if not, write to the Free Software
14
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15
//      MA 02110-1301, USA.
16
//      
17
18
19
using Pk;
20
21
namespace Lsc.Backend {
22
    public class AppsManager : Object {
23
        // Signals
24
        public signal void app_added (Package app);
3 by Stephen Smally
Implemented dynamic category view
25
        public signal void category_added (string category, string group);
2 by Stephen Smally
Worked a lot!
26
        public signal void loading_started (string text);
27
        public signal void loading_finished ();
28
        public signal void details_received (Package pkg, Details details);
29
        
30
        // PackageKit stuffs
31
        private Client client;
32
        private Control control;
33
        private Cancellable transaction;
34
        
3 by Stephen Smally
Implemented dynamic category view
35
        // Vars
36
        public string[] icon_table;
37
        
38
        public void get_pkgs_cb (Progress progress, ProgressType type) {
39
        }
40
        
41
        public void ready () {
42
            loading_finished();
43
        }
44
        
2 by Stephen Smally
Worked a lot!
45
        public void get_pkgs (string filters) {
46
            Bitfield filter;
47
            filter = filter_bitfield_from_string(filters);
48
            loading_started("Loading packages");
3 by Stephen Smally
Implemented dynamic category view
49
            client.get_packages_async(filter, null, (progress, type) => {
50
                if (type == ProgressType.PACKAGE_ID && progress.package != null) {
51
                    stdout.printf("%s, %s\n", progress.package.get_name(), progress.package.get_arch());
52
                    app_added(progress.package);
53
                    while (Gtk.events_pending())
54
                        Gtk.main_iteration();
2 by Stephen Smally
Worked a lot!
55
                }
3 by Stephen Smally
Implemented dynamic category view
56
            }, () => {ready();});
2 by Stephen Smally
Worked a lot!
57
        }
58
        
59
        public void search_for_packages (string filters, string name) {
60
            Bitfield filter;
61
            filter = filter_bitfield_from_string(filters);
62
            loading_started("Loading packages");
63
            client.search_names_async(filter, {name}, null, (pkg) => {
64
                if (pkg.package != null) {
65
                    app_added(pkg.package);
66
                }
67
                while (Gtk.events_pending())
68
                    Gtk.main_iteration();
69
            }, () => {
70
                loading_finished();
71
            });
72
        }
73
        
74
        public void get_details (string pkg_id) {
75
            client.get_details_async({pkg_id},
76
            null,
77
            () => {},
78
            (obj, res) => {
79
                Results contains = client.generic_finish(res);
80
                details_received(get_package_from_id(pkg_id), contains.get_details_array()[0]);
81
            });
82
        }
83
        
84
        public Package get_package_from_id (string pkg_id) {
85
            Results res = client.resolve(filter_bitfield_from_string(""),
86
            {pkg_id},
87
            null,
88
            null);
89
            return res.get_package_array()[0];
90
        }
91
        
3 by Stephen Smally
Implemented dynamic category view
92
        private void fill_icon_table () {
93
            icon_table = {
94
                string.joinv("|", {group_enum_to_string(Group.UNKNOWN),"help-browser"}),	/* fall though value */
95
                string.joinv("|", {group_enum_to_string(Group.ACCESSIBILITY), "preferences-desktop-accessibility"}),
96
                string.joinv("|", {group_enum_to_string(Group.ACCESSORIES), "applications-accessories"}),
97
                string.joinv("|", {group_enum_to_string(Group.ADMIN_TOOLS), "system-lock-screen"}),
98
                string.joinv("|", {group_enum_to_string(Group.COLLECTIONS),	"pk-collection-installed"}),
99
                string.joinv("|", {group_enum_to_string(Group.COMMUNICATION), "folder-remote"}),
100
                string.joinv("|", {group_enum_to_string(Group.DESKTOP_GNOME), "pk-desktop-gnome"}),
101
                string.joinv("|", {group_enum_to_string(Group.DESKTOP_KDE), "pk-desktop-kde"}),
102
                string.joinv("|", {group_enum_to_string(Group.DESKTOP_OTHER), "user-desktop"}),
103
                string.joinv("|", {group_enum_to_string(Group.DESKTOP_XFCE), "pk-desktop-xfce"}),
104
                string.joinv("|", {group_enum_to_string(Group.DOCUMENTATION), "x-office-address-book"}),
105
                string.joinv("|", {group_enum_to_string(Group.EDUCATION), "utilities-system-monitor"}),
106
                string.joinv("|", {group_enum_to_string(Group.ELECTRONICS), "video-display"}),
107
                string.joinv("|", {group_enum_to_string(Group.FONTS), "preferences-desktop-font"}),
108
                string.joinv("|", {group_enum_to_string(Group.GAMES), "applications-games"}),
109
                string.joinv("|", {group_enum_to_string(Group.GRAPHICS), "applications-graphics"}),
110
                string.joinv("|", {group_enum_to_string(Group.INTERNET), "applications-internet"}),
111
                string.joinv("|", {group_enum_to_string(Group.LEGACY), "media-floppy"}),
112
                string.joinv("|", {group_enum_to_string(Group.LOCALIZATION), "preferences-desktop-locale"}),
113
                string.joinv("|", {group_enum_to_string(Group.MAPS), "applications-multimedia"}),
114
                string.joinv("|", {group_enum_to_string(Group.MULTIMEDIA), "applications-multimedia"}),
115
                string.joinv("|", {group_enum_to_string(Group.NETWORK), "network-wired"}),
116
                string.joinv("|", {group_enum_to_string(Group.OFFICE), "applications-office"}),
117
                string.joinv("|", {group_enum_to_string(Group.OTHER), "applications-other"}),
118
                string.joinv("|", {group_enum_to_string(Group.POWER_MANAGEMENT), "battery"}),
119
                string.joinv("|", {group_enum_to_string(Group.PROGRAMMING), "applications-development"}),
120
                string.joinv("|", {group_enum_to_string(Group.PUBLISHING), "accessories-dictionary"}),
121
                string.joinv("|", {group_enum_to_string(Group.REPOS), "system-file-manager"}),
122
                string.joinv("|", {group_enum_to_string(Group.SCIENCE), "application-certificate"}),
123
                string.joinv("|", {group_enum_to_string(Group.SECURITY), "network-wireless-encrypted"}),
124
                string.joinv("|", {group_enum_to_string(Group.SERVERS), "network-server"}),
125
                string.joinv("|", {group_enum_to_string(Group.SYSTEM), "applications-system"}),
126
                string.joinv("|", {group_enum_to_string(Group.VIRTUALIZATION), "computer"}),
127
                string.joinv("|", {group_enum_to_string(Group.VENDOR), "application-certificate"}),
128
                string.joinv("|", {group_enum_to_string(Group.NEWEST), "dialog-information"})
129
            };
130
        }
131
        
132
        private string group_to_icon_name(string group) {
133
            foreach (string couple in icon_table) {
134
                if (couple.split("|")[0] == group) {
135
                return couple.split("|")[1];
136
                }
137
            }
138
            
139
            return "";
140
        }
141
        
2 by Stephen Smally
Worked a lot!
142
        public void get_categories () {
3 by Stephen Smally
Implemented dynamic category view
143
            /*
144
            for (int i = 0; i < Group.LAST; i++) {
145
                if (i != Group.COLLECTIONS && i != Group.NEWEST)
146
                    category_added(group_to_icon_name(group_enum_to_string((Group)i)), group_enum_to_string((Group)i));
147
            }*/
148
            
149
            category_added("applications-accessories", "Accessories");
150
            category_added("applications-internet", "Internet");
151
            category_added("applications-office", "Office");
152
            category_added("applications-multimedia", "Multimedia");
153
            category_added("applications-development", "Development");
154
            category_added("category-show-all", "All");
2 by Stephen Smally
Worked a lot!
155
        }
156
        
3 by Stephen Smally
Implemented dynamic category view
157
        public void get_screenshot (string pkg_name) {
158
            
159
        } 
160
        
2 by Stephen Smally
Worked a lot!
161
        public AppsManager () {
162
            client = new Client();
163
            control = new Control();
164
            transaction = new Cancellable();
3 by Stephen Smally
Implemented dynamic category view
165
            fill_icon_table();
2 by Stephen Smally
Worked a lot!
166
        }
167
    }
168
}