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
106
107
108
109
110
|
// Copyright © 2012 Stephen Smally
// 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 PackageKit;
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 string stock_image;
public void append_app (LscApp app) {
/*if (app.get_info() == Info.INSTALLED) {
stock_image = Stock.YES;
} else {
stock_image = null;
}*/
model.append(out iter);
model.set(iter, 0, app.icon, 1, app.name+"\n"+app.summary, 2, stock_image, 3, app.id);
}
public void clear () {
model.clear();
}
public void on_cursor_changed (TreeView widget) {
get_cursor(out path, null);
if (path != null) {
string val;
model.get_iter(out iter, path);
model.get(iter, 3, out val);
selected_row(val);
}
}
public AppsTree () {
model = new ListStore(4,
typeof(string), // Icon name
typeof(string), // Name and description
typeof(string), // Installed (Gtk.Stock)
typeof(string) // Package ID
);
set_model(model);
CellRendererPixbuf icon_cell = new CellRendererPixbuf();
icon_cell.stock_size = IconSize.DND;
CellRendererText text = new CellRendererText();
text.ellipsize = Pango.EllipsizeMode.END;
insert_column_with_attributes(-1, "Icon", icon_cell, "icon-name", 0);
insert_column_with_attributes(-1, "Inst", new CellRendererPixbuf(), "stock-id", 2);
insert_column_with_attributes(-1, "Name", text, "text", 1);
get_column(2).set_sort_column_id(1);
get_column(2).set_expand(true);
get_column(2).clicked();
get_column(1).set_sort_column_id(2);
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);
}
}
}
|