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.
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.
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.
22
namespace Lsc.Backend {
23
public class LscApp : Object {
24
public LscCategory parent_category { get; private set; }
25
public string id { get; private set; }
26
public string name { get; private set; }
27
public string comment { get; private set; }
28
public string description { get; private set; }
29
public string icon { get; private set; }
30
public string[] dependencies { get; private set; }
32
public LscApp (LscCategory parent, Statement stmt) {
33
parent_category = parent;
34
id = stmt.column_value(1).to_text();
35
name = stmt.column_value(0).to_text();
36
comment = stmt.column_value(3).to_text();
37
icon = stmt.column_value(4).to_text();
38
description = stmt.column_value(5).to_text();
39
dependencies = stmt.column_value(6).to_text().split(";");
43
public class LscCategory : Object {
44
public string id { get; private set; }
45
public bool showboth { get; private set; }
46
public string name { get; private set; }
47
public string comment { get; private set; }
48
public string icon { get; private set; }
50
public LscCategory (Statement stmt) {
51
id = stmt.column_value(0).to_text();
52
showboth = bool.parse(stmt.column_value(2).to_text().down());
53
name = stmt.column_value(3).to_text();
54
comment = stmt.column_value(4).to_text();
55
icon = stmt.column_value(5).to_text();
59
public class LscDatabase : Object {
60
public HashMap<string, LscCategory> current_categories { get; private set; }
61
public HashMap<LscCategory, HashMap<string, LscApp>> current_apps { get; private set; }
62
private HashMap<string, LscApp> tmp_apps;
64
private Statement get_categories_stmt;
65
private Statement get_apps_stmt;
66
private string STMT_GET_CATEGORIES = "SELECT * FROM tables";
68
public void fill_categories () {
69
current_categories.clear();
70
while (get_categories_stmt.step() == Sqlite.ROW) {
71
LscCategory category = new LscCategory(get_categories_stmt);
72
current_categories[category.id] = category;
76
public LscApp get_app (string category_id, string app_id) {
77
return current_apps[current_categories[category_id]][app_id];
80
public void fill_category (string category_id) {
82
LscCategory cat = current_categories[category_id];
84
string STMT_GET_FROM_CAT = "SELECT * FROM "+cat.id;
85
db.prepare_v2(STMT_GET_FROM_CAT, STMT_GET_FROM_CAT.length, out get_apps_stmt);
86
tmp_apps = new HashMap<string, LscApp>();
88
while (get_apps_stmt.step() == Sqlite.ROW) {
89
LscApp app = new LscApp(cat, get_apps_stmt);
90
tmp_apps[app.id] = app;
93
current_apps[cat] = tmp_apps;
96
public LscDatabase (string path) {
97
current_categories = new HashMap<string, LscCategory>();
98
current_apps = new HashMap<LscCategory, HashMap<string, LscApp>>();
100
if (Database.open_v2(path, out db) != Sqlite.OK) {
101
stdout.printf("Error opening %s\n", path);
104
db.prepare_v2(STMT_GET_CATEGORIES, STMT_GET_CATEGORIES.length, out get_categories_stmt);