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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
// 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 Lsc.Backend;
using Lsc.Widgets;
namespace Lsc {
// Elements which should be accessible to every void or class
public enum PageType {
HOMEPAGE,
APPSVIEW,
APPSINFO;
public string to_string () {
switch (this) {
case HOMEPAGE:
return "Home Page";
case APPSVIEW:
return "Apps View";
case APPSINFO:
return "Apps Info";
default:
assert_not_reached();
}
}
public PageType[] get_all () {
return { HOMEPAGE, APPSVIEW, APPSINFO };
}
}
// Apps Manager which handle the PackageKit connection
public AppsManager apps_manager;
public class Frontend : Window {
// Widgets
public Box main_box;
public MainToolbar toolbar;
public PagesView pages_view;
public ProgressInfo progress_info;
private int _width = 0;
public void load_packages (string filters) {
pages_view.set_current_page(PageType.APPSVIEW);
pages_view.apps_view.apps_tree.clear();
apps_manager.get_pkgs(filters);
}
public void update_back_button (Notebook nb, Widget pg, uint page_n) {
stdout.printf("Page: %s\n", ((PageType) page_n).to_string());
switch ((PageType) page_n) {
case PageType.HOMEPAGE:
toolbar.searchbar.set_sensitive(true);
toolbar.label.margin_left = 5;
toolbar.back.set_visible(false);
break;
case PageType.APPSINFO:
toolbar.searchbar.set_sensitive(false);
toolbar.label.margin_left = 0;
toolbar.back.set_visible(true);
break;
default:
toolbar.searchbar.set_sensitive(true);
toolbar.label.margin_left = 0;
toolbar.back.set_visible(true);
break;
}
}
public void connect_signals () {
apps_manager.app_added.connect(pages_view.apps_view.apps_tree.append_app);
apps_manager.loading_started.connect(progress_info.load_undefined);
apps_manager.loading_finished.connect(progress_info.clear);
apps_manager.category_added.connect(pages_view.home_page.categories_view.add_category);
apps_manager.details_received.connect(pages_view.apps_info.set_details);
pages_view.switch_page.connect(update_back_button);
pages_view.switch_page.connect(toolbar.update_label);
}
public void on_size_allocate (Allocation alloc) {
if (_width != get_allocated_width() && get_allocated_width()/150 != pages_view.home_page.categories_view.columns) {
stdout.printf("Allocating main window to width: %d, need to rework columns\n", get_allocated_width());
int size = get_allocated_width();
if (size < 150 ) {
size = 150;
}
pages_view.home_page.categories_view.columns = size/150;
_width = get_allocated_width();
}
}
public Frontend () {
apps_manager = new AppsManager();
destroy.connect(Gtk.main_quit);
window_position = WindowPosition.CENTER;
title = "Light Software Center";
set_default_size(600, 400);
set_has_resize_grip(true);
main_box = new Box(Orientation.VERTICAL, 0);
toolbar = new MainToolbar();
main_box.pack_start(toolbar, false, false, 0);
progress_info = new ProgressInfo();
main_box.pack_start(progress_info, false, false, 0);
pages_view = new PagesView();
main_box.pack_start(pages_view, true, true, 0);
add(main_box);
show_all();
connect_signals();
apps_manager.get_categories();
size_allocate.connect(on_size_allocate);
progress_info.set_visible(false);
pages_view.apps_info.reviews_box.set_visible(false);
pages_view.set_page(PageType.HOMEPAGE);
set_focus(null);
}
}
}
int main (string[] args) {
Gtk.init(ref args);
new Lsc.Frontend();
Gtk.main();
return 0;
}
|