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

« back to all changes in this revision

Viewing changes to db-build/dbbuild.vala

  • Committer: Stephen Smally
  • Date: 2012-07-04 13:40:36 UTC
  • Revision ID: eco.stefi@fastwebnet.it-20120704134036-jzxry23ch4in5o80
Implemented packages list via Database, listing works and is fast!

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
class AppInstallPackage {
7
7
    public string[] directories { get; private set; }
8
8
    public string name { get; private set; }
9
 
    public string icon { get; private set; }
10
 
    public string summary { get; private set; }
 
9
    public string icon { get; set; }
 
10
    public string summary { get; set; }
11
11
    public string id { get; private set; }
12
12
    
13
13
    public AppInstallPackage (string[] directories, string name, string icon, string summary, string id) {
38
38
    private MenuDir[] menu_dirs;
39
39
    private Gee.HashMap<string, AppInstallPackage> packages;
40
40
    
41
 
    public void add_pkg (string id, Transaction trs) {
42
 
        AppInstallPackage app_pkg = packages[id];
 
41
    public void add_pkg (Package pk, Transaction trs) {
 
42
        AppInstallPackage app_pkg = packages[pk.get_name()];
43
43
        if (app_pkg == null) { return; }
 
44
        if (app_pkg.summary == "") {
 
45
                        app_pkg.summary = pk.get_summary();
 
46
                }
 
47
                if (app_pkg.icon == "") {
 
48
                        app_pkg.icon = "applications-other";
 
49
                }
44
50
        foreach (string dir in app_pkg.directories) {
45
 
                GLib.debug ("Inserting %s in %s\n", id, dir);
 
51
                GLib.debug ("Inserting %s in %s\n", app_pkg.id, dir);
46
52
                trs.execute_insert("INSERT INTO '%s' VALUES (:id, :name, :description, :icon);".printf (dir),
47
53
                                                           ":id", typeof (string), app_pkg.id,
48
54
                                                           ":name", typeof (string), app_pkg.name,
139
145
Client client;
140
146
DbBuilder dbbuilder;
141
147
Transaction trans;
142
 
string[] ids;
 
148
Package[] pkgs;
143
149
string db_filename = null;
144
150
 
145
151
void pkg_received (Package pkg) {
146
 
    ids += pkg.get_name ();
 
152
    pkgs += pkg;
147
153
}
148
154
 
149
155
const OptionEntry[] entries = {
154
160
// FIXME: Awful OOP code
155
161
 
156
162
int main (string[] args) {
157
 
    ids = {};
 
163
    pkgs = {};
158
164
    
159
165
    OptionContext context = new OptionContext ("Build a Lsc (Light Software Center) Database");
160
166
    context.add_main_entries (entries, null);
191
197
    
192
198
    stdout.printf ("Building database...\n");
193
199
    
194
 
    foreach (string id in ids) {
195
 
       dbbuilder.add_pkg (id, trans);
 
200
    foreach (Package pk in pkgs) {
 
201
       dbbuilder.add_pkg (pk, trans);
196
202
    }
197
203
    
198
204
    try {