~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-04 12:59:13 UTC
  • Revision ID: eco.stefi@fastwebnet.it-20120304125913-bk1iutifwoeoyo0i
Worked a lot!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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);
 
25
        public signal void category_added (string category, string name);
 
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
        
 
35
        public void get_pkgs (string filters) {
 
36
            Bitfield filter;
 
37
            filter = filter_bitfield_from_string(filters);
 
38
            loading_started("Loading packages");
 
39
            client.get_packages_async(filter, null, (pkg) => {
 
40
                if (pkg.package != null) {
 
41
                    app_added(pkg.package);
 
42
                }
 
43
                while (Gtk.events_pending())
 
44
                    Gtk.main_iteration();
 
45
            }, () => {
 
46
                loading_finished();
 
47
            });
 
48
        }
 
49
        
 
50
        public void search_for_packages (string filters, string name) {
 
51
            Bitfield filter;
 
52
            filter = filter_bitfield_from_string(filters);
 
53
            loading_started("Loading packages");
 
54
            client.search_names_async(filter, {name}, null, (pkg) => {
 
55
                if (pkg.package != null) {
 
56
                    app_added(pkg.package);
 
57
                }
 
58
                while (Gtk.events_pending())
 
59
                    Gtk.main_iteration();
 
60
            }, () => {
 
61
                loading_finished();
 
62
            });
 
63
        }
 
64
        
 
65
        public void get_details (string pkg_id) {
 
66
            client.get_details_async({pkg_id},
 
67
            null,
 
68
            () => {},
 
69
            (obj, res) => {
 
70
                Results contains = client.generic_finish(res);
 
71
                details_received(get_package_from_id(pkg_id), contains.get_details_array()[0]);
 
72
            });
 
73
        }
 
74
        
 
75
        public Package get_package_from_id (string pkg_id) {
 
76
            Results res = client.resolve(filter_bitfield_from_string(""),
 
77
            {pkg_id},
 
78
            null,
 
79
            null);
 
80
            return res.get_package_array()[0];
 
81
        }
 
82
        
 
83
        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");
 
88
        }
 
89
        
 
90
        public AppsManager () {
 
91
            client = new Client();
 
92
            control = new Control();
 
93
            transaction = new Cancellable();
 
94
        }
 
95
    }
 
96
}