1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
// Stephen Smally © 2012
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//
using Gtk;
using Pk;
using Lsc.Backend;
namespace Lsc.Widgets {
public class AppsTree : TreeView {
// Signals
public signal void selected_row (string pkg);
// Vars
private ListStore model;
private TreeIter iter;
private TreePath path;
private Value value;
private string stock_image;
public void append_app (Package app) {
if (app.get_info() == Info.INSTALLED) {
stock_image = Stock.YES;
} else {
stock_image = null;
}
model.append(out iter);
model.set(iter, 0, "deb", 1, IconSize.DND, 2, app.get_name()+"\n"+app.get_summary(), 3, stock_image, 4, app.get_id());
}
public void clear () {
model.clear();
}
public void on_cursor_changed (TreeView widget) {
get_cursor(out path, null);
if (path != null) {
model.get_iter(out iter, path);
model.get_value(iter, 4, out value);
selected_row(value.get_string());
}
}
public AppsTree () {
model = new ListStore(5,
typeof(string), // Icon name
typeof(int), // Icon size
typeof(string), // Name and description
typeof(string), // Installed (Gtk.Stock)
typeof(string) // Package ID
);
set_model(model);
insert_column_with_attributes(-1, "Icon", new CellRendererPixbuf(), "icon-name", 0, "stock-size", 1);
insert_column_with_attributes(-1, "Inst", new CellRendererPixbuf(), "stock-id", 3);
insert_column_with_attributes(-1, "Name", new CellRendererText(), "text", 2);
get_column(2).set_sort_column_id(2);
get_column(2).set_expand(true);
get_column(2).clicked();
get_column(1).set_sort_column_id(3);
cursor_changed.connect(on_cursor_changed);
headers_visible = false;
}
}
public class AppsView : Box {
// Widgets
public AppsTree apps_tree;
public InfoMessage info_message;
public AppsView () {
orientation = Orientation.VERTICAL;
apps_tree = new AppsTree();
info_message = new InfoMessage();
ScrolledWindow apps_tree_scroll = new ScrolledWindow(null, null);
apps_tree_scroll.set_policy(PolicyType.NEVER, PolicyType.AUTOMATIC);
apps_tree_scroll.add(apps_tree);
apps_tree.selected_row.connect(info_message.update);
pack_start(apps_tree_scroll, true, true, 0);
pack_start(info_message, false, false, 0);
}
}
}
|