~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-03-18 10:38:53 UTC
  • Revision ID: eco.stefi@fastwebnet.it-20120318103853-v7wg1qfuifjkc3gc
Implemented dynamic category view

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    public class AppsManager : Object {
23
23
        // Signals
24
24
        public signal void app_added (Package app);
25
 
        public signal void category_added (string category, string name);
 
25
        public signal void category_added (string category, string group);
26
26
        public signal void loading_started (string text);
27
27
        public signal void loading_finished ();
28
28
        public signal void details_received (Package pkg, Details details);
32
32
        private Control control;
33
33
        private Cancellable transaction;
34
34
        
 
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
        
35
45
        public void get_pkgs (string filters) {
36
46
            Bitfield filter;
37
47
            filter = filter_bitfield_from_string(filters);
38
48
            loading_started("Loading packages");
39
 
            client.get_packages_async(filter, null, (pkg) => {
40
 
                if (pkg.package != null) {
41
 
                    app_added(pkg.package);
 
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();
42
55
                }
43
 
                while (Gtk.events_pending())
44
 
                    Gtk.main_iteration();
45
 
            }, () => {
46
 
                loading_finished();
47
 
            });
 
56
            }, () => {ready();});
48
57
        }
49
58
        
50
59
        public void search_for_packages (string filters, string name) {
80
89
            return res.get_package_array()[0];
81
90
        }
82
91
        
 
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
        
83
142
        public void get_categories () {
84
 
            category_added("gtk-yes", "Utilities");
85
 
            category_added("gtk-yes", "Internet");
86
 
            category_added("gtk-yes", "System");
87
 
            category_added("gtk-yes", "Accessibility");
 
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");
88
155
        }
89
156
        
 
157
        public void get_screenshot (string pkg_name) {
 
158
            
 
159
        } 
 
160
        
90
161
        public AppsManager () {
91
162
            client = new Client();
92
163
            control = new Control();
93
164
            transaction = new Cancellable();
 
165
            fill_icon_table();
94
166
        }
95
167
    }
96
168
}