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

« back to all changes in this revision

Viewing changes to src/Backend/AppsManager.vala

  • Committer: Stephen Smally
  • Date: 2012-05-16 15:04:53 UTC
  • Revision ID: eco.stefi@fastwebent.it-20120516150453-ldidynmwbc1qfq41
Working on

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  Stephen Smally © 2012
 
1
//  Copyright © 2012 Stephen Smally
2
2
//      This program is free software; you can redistribute it and/or modify
3
3
//      it under the terms of the GNU General Public License as published by
4
4
//      the Free Software Foundation; either version 2 of the License, or
15
15
//      MA 02110-1301, USA.
16
16
//      
17
17
 
18
 
 
19
18
using Pk;
20
19
 
21
20
namespace Lsc.Backend {
 
21
    public enum LoadingType {
 
22
        PACKAGES, // Loaded packages
 
23
        CATEGORIES, // Loaded categories
 
24
        OTHER; // Installed or so
 
25
    }
 
26
    
22
27
    public class AppsManager : Object {
23
28
        // Signals
24
29
        public signal void app_added (Package app);
25
30
        public signal void category_added (string category, string group);
26
31
        public signal void loading_started (string text);
27
 
        public signal void loading_finished ();
 
32
        public signal void loading_finished (LoadingType load);
28
33
        public signal void details_received (Package pkg, Details details);
29
34
        
30
35
        // PackageKit stuffs
38
43
        public void get_pkgs_cb (Progress progress, ProgressType type) {
39
44
        }
40
45
        
41
 
        public void ready () {
42
 
            loading_finished();
43
 
        }
44
 
        
45
46
        public void get_pkgs (string filters) {
46
47
            Bitfield filter;
47
48
            filter = filter_bitfield_from_string(filters);
49
50
            client.get_packages_async(filter, null, (progress, type) => {
50
51
                if (type == ProgressType.PACKAGE_ID && progress.package != null) {
51
52
                    stdout.printf("%s, %s\n", progress.package.get_name(), progress.package.get_arch());
52
 
                    app_added(progress.package);
 
53
                    //app_added(progress.package);
53
54
                    while (Gtk.events_pending())
54
55
                        Gtk.main_iteration();
55
56
                }
56
 
            }, () => {ready();});
 
57
            }, () => {
 
58
                loading_finished(LoadingType.PACKAGES);
 
59
            });
57
60
        }
58
61
        
59
62
        public void search_for_packages (string filters, string name) {
67
70
                while (Gtk.events_pending())
68
71
                    Gtk.main_iteration();
69
72
            }, () => {
70
 
                loading_finished();
 
73
                loading_finished(LoadingType.PACKAGES);
71
74
            });
72
75
        }
73
76
        
90
93
        }
91
94
        
92
95
        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
96
        }
141
97
        
142
98
        public void get_categories () {
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
 
            }*/
 
99
            /* Need a wrapper for /usr/share/app-install/desktop/applications.menu*/
148
100
            
149
101
            category_added("applications-accessories", "Accessories");
150
102
            category_added("applications-internet", "Internet");
152
104
            category_added("applications-multimedia", "Multimedia");
153
105
            category_added("applications-development", "Development");
154
106
            category_added("category-show-all", "All");
 
107
            
 
108
            loading_finished(LoadingType.CATEGORIES);
155
109
        }
156
110
        
157
111
        public void get_screenshot (string pkg_name) {