2
by Stephen Smally
Worked a lot! |
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.
|
|
6 |
//
|
|
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.
|
|
11 |
//
|
|
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.
|
|
16 |
//
|
|
17 |
||
18 |
using Gtk; |
|
19 |
using Lsc.Backend; |
|
20 |
using Lsc.Widgets; |
|
21 |
||
22 |
namespace Lsc { |
|
23 |
// Elements which should be accessible to every void or class
|
|
24 |
public enum PageType { |
|
25 |
HOMEPAGE, |
|
26 |
APPSVIEW, |
|
27 |
APPSINFO; |
|
28 |
||
29 |
public string to_string () { |
|
30 |
switch (this) { |
|
31 |
case HOMEPAGE: |
|
32 |
return "Home Page"; |
|
33 |
case APPSVIEW: |
|
34 |
return "Apps View"; |
|
35 |
case APPSINFO: |
|
36 |
return "Apps Info"; |
|
37 |
default: |
|
38 |
assert_not_reached(); |
|
39 |
}
|
|
40 |
}
|
|
41 |
||
42 |
public PageType[] get_all () { |
|
43 |
return { HOMEPAGE, APPSVIEW, APPSINFO }; |
|
44 |
}
|
|
45 |
}
|
|
46 |
||
47 |
// Apps Manager which handle the PackageKit connection
|
|
48 |
public AppsManager apps_manager; |
|
49 |
||
50 |
public class Frontend : Window { |
|
51 |
// Widgets
|
|
52 |
public Box main_box; |
|
53 |
public MainToolbar toolbar; |
|
54 |
public PagesView pages_view; |
|
55 |
public ProgressInfo progress_info; |
|
56 |
||
3
by Stephen Smally
Implemented dynamic category view |
57 |
private int _width = 0; |
58 |
||
2
by Stephen Smally
Worked a lot! |
59 |
public void load_packages (string filters) { |
60 |
pages_view.set_current_page(PageType.APPSVIEW); |
|
61 |
pages_view.apps_view.apps_tree.clear(); |
|
62 |
apps_manager.get_pkgs(filters); |
|
63 |
}
|
|
64 |
||
65 |
public void update_back_button (Notebook nb, Widget pg, uint page_n) { |
|
3
by Stephen Smally
Implemented dynamic category view |
66 |
stdout.printf("Page: %s\n", ((PageType) page_n).to_string()); |
2
by Stephen Smally
Worked a lot! |
67 |
switch ((PageType) page_n) { |
3
by Stephen Smally
Implemented dynamic category view |
68 |
case PageType.HOMEPAGE: |
69 |
toolbar.searchbar.set_sensitive(true); |
|
70 |
toolbar.label.margin_left = 5; |
|
71 |
toolbar.back.set_visible(false); |
|
72 |
break; |
|
73 |
||
74 |
case PageType.APPSINFO: |
|
75 |
toolbar.searchbar.set_sensitive(false); |
|
76 |
toolbar.label.margin_left = 0; |
|
77 |
toolbar.back.set_visible(true); |
|
78 |
break; |
|
79 |
||
80 |
default: |
|
81 |
toolbar.searchbar.set_sensitive(true); |
|
82 |
toolbar.label.margin_left = 0; |
|
83 |
toolbar.back.set_visible(true); |
|
84 |
break; |
|
2
by Stephen Smally
Worked a lot! |
85 |
}
|
86 |
}
|
|
87 |
||
88 |
public void connect_signals () { |
|
89 |
apps_manager.app_added.connect(pages_view.apps_view.apps_tree.append_app); |
|
90 |
apps_manager.loading_started.connect(progress_info.load_undefined); |
|
91 |
apps_manager.loading_finished.connect(progress_info.clear); |
|
92 |
apps_manager.category_added.connect(pages_view.home_page.categories_view.add_category); |
|
93 |
apps_manager.details_received.connect(pages_view.apps_info.set_details); |
|
94 |
pages_view.switch_page.connect(update_back_button); |
|
3
by Stephen Smally
Implemented dynamic category view |
95 |
pages_view.switch_page.connect(toolbar.update_label); |
96 |
}
|
|
97 |
||
98 |
public void on_size_allocate (Allocation alloc) { |
|
99 |
if (_width != get_allocated_width() && get_allocated_width()/150 != pages_view.home_page.categories_view.columns) { |
|
100 |
stdout.printf("Allocating main window to width: %d, need to rework columns\n", get_allocated_width()); |
|
101 |
int size = get_allocated_width(); |
|
102 |
if (size < 150 ) { |
|
103 |
size = 150; |
|
104 |
}
|
|
105 |
pages_view.home_page.categories_view.columns = size/150; |
|
106 |
||
107 |
_width = get_allocated_width(); |
|
108 |
}
|
|
109 |
}
|
|
110 |
||
111 |
public Frontend () { |
|
2
by Stephen Smally
Worked a lot! |
112 |
apps_manager = new AppsManager(); |
113 |
||
114 |
destroy.connect(Gtk.main_quit); |
|
3
by Stephen Smally
Implemented dynamic category view |
115 |
|
2
by Stephen Smally
Worked a lot! |
116 |
window_position = WindowPosition.CENTER; |
117 |
title = "Light Software Center"; |
|
118 |
set_default_size(600, 400); |
|
3
by Stephen Smally
Implemented dynamic category view |
119 |
set_has_resize_grip(true); |
2
by Stephen Smally
Worked a lot! |
120 |
|
121 |
main_box = new Box(Orientation.VERTICAL, 0); |
|
122 |
||
123 |
toolbar = new MainToolbar(); |
|
124 |
main_box.pack_start(toolbar, false, false, 0); |
|
125 |
||
126 |
progress_info = new ProgressInfo(); |
|
127 |
main_box.pack_start(progress_info, false, false, 0); |
|
128 |
||
129 |
pages_view = new PagesView(); |
|
130 |
||
131 |
main_box.pack_start(pages_view, true, true, 0); |
|
132 |
||
133 |
add(main_box); |
|
134 |
show_all(); |
|
135 |
||
136 |
connect_signals(); |
|
137 |
||
138 |
apps_manager.get_categories(); |
|
3
by Stephen Smally
Implemented dynamic category view |
139 |
size_allocate.connect(on_size_allocate); |
2
by Stephen Smally
Worked a lot! |
140 |
|
141 |
progress_info.set_visible(false); |
|
3
by Stephen Smally
Implemented dynamic category view |
142 |
pages_view.apps_info.reviews_box.set_visible(false); |
143 |
||
144 |
pages_view.set_page(PageType.HOMEPAGE); |
|
145 |
||
146 |
set_focus(null); |
|
2
by Stephen Smally
Worked a lot! |
147 |
}
|
148 |
}
|
|
149 |
}
|
|
150 |
||
151 |
int main (string[] args) { |
|
152 |
Gtk.init(ref args); |
|
153 |
new Lsc.Frontend(); |
|
154 |
Gtk.main(); |
|
155 |
return 0; |
|
156 |
}
|