1 /* This file is part of Beifahrer.
3 * Copyright (C) 2010 Philipp Zabel
5 * Beifahrer is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Beifahrer is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Beifahrer. If not, see <http://www.gnu.org/licenses/>.
22 public class LiftListWindow : StackableWindow {
23 public const string GCONF_KEY_PRELOAD = "/apps/beifahrer/preload";
28 TreeViewColumn route_column;
33 public LiftListWindow (AdacMitfahrclub _adac) {
38 set_title ("Beifahrer");
40 gconf = GConf.Client.get_default ();
41 store = new ListStore (6, typeof (string), typeof (string), typeof (string), typeof (string), typeof (string), typeof (Lift));
43 tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, store);
44 Hildon.gtk_widget_set_theme_size (tree, SizeType.FINGER_HEIGHT);
46 tree.set_headers_visible (false);
47 tree.set_rules_hint (true);
49 // Tree selection object
50 var selection = tree.get_selection ();
51 selection.set_mode (SelectionMode.SINGLE);
53 // Source and destination column
54 route_column = new TreeViewColumn.with_attributes ("Route", new CellRendererText (), "text", 0);
55 route_column.set_reorderable (false);
56 route_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
57 route_column.set_expand (true);
58 tree.append_column (route_column);
60 // Date and time column
61 var datetime_column = new TreeViewColumn.with_attributes ("DateTime", new CellRendererText (), "text", 1);
62 datetime_column.set_reorderable (false);
63 datetime_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
64 datetime_column.set_expand (true);
65 tree.append_column (datetime_column);
68 var places_column = new TreeViewColumn.with_attributes ("Places", new CellRendererText (), "text", 2);
69 places_column.set_reorderable (false);
70 places_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
71 places_column.set_expand (true);
72 tree.append_column (places_column);
75 var price_column = new TreeViewColumn.with_attributes ("Price", new CellRendererText (), "text", 3);
76 price_column.set_reorderable (false);
77 price_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
78 price_column.set_expand (true);
79 tree.append_column (price_column);
81 // Smoker/Non-smoker column
82 var smoke_column = new TreeViewColumn.with_attributes ("Smoker", new CellRendererPixbuf (), "icon-name", 4);
83 smoke_column.set_reorderable (false);
84 smoke_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
85 smoke_column.set_expand (false);
86 tree.append_column (smoke_column);
88 var pannable = new PannableArea ();
91 no_lifts = new Label (_("No lifts"));
92 Hildon.helper_set_logical_font (no_lifts, "LargeSystemFont");
93 Hildon.helper_set_logical_color (no_lifts, RcFlags.FG, StateType.NORMAL, "SecondaryTextColor");
94 no_lifts.set_size_request (-1, 6 * 70);
95 no_lifts.set_alignment ((float) 0.5, (float) 0.42);
97 var vbox = new VBox (false, 0);
98 vbox.pack_start (pannable, true, true, 0);
99 vbox.pack_start (no_lifts, false, false, 0);
105 route_column.set_visible (!BeifahrerProgram.orientation.portrait);
107 tree.row_activated.connect (this.on_row_activated);
108 BeifahrerProgram.orientation.changed.connect (this.on_orientation_changed);
111 public async void find_lifts (string city_from, int radius_from, string city_to, int radius_to, Date date, int tolerance = 0) {
113 set_title ("%s - %s".printf (city_from, city_to));
114 Hildon.gtk_window_set_progress_indicator (this, 1);
116 var lift_list = yield adac.get_lift_list (city_from, radius_from, city_to, radius_to, date, tolerance);
117 foreach (Lift lift in lift_list) {
118 string icon_name = null;
119 if (LiftFlags.SMOKER in lift.flags)
120 icon_name = "beifahrer_smoker";
121 else if (LiftFlags.NON_SMOKER in lift.flags)
122 icon_name = "beifahrer_non_smoker";
123 string datetime = "%02d.%02d.%04d".printf (lift.time.day, lift.time.month, lift.time.year);
124 if (lift.time.hour >= 0)
125 datetime += ", %d:%02d".printf (lift.time.hour, lift.time.minute);
126 store.insert_with_values (out iter, -1, 0, lift.city_from + " - " + lift.city_to,
128 2, _("%d pl.").printf (lift.places),
132 // (LiftFlags.WOMEN_ONLY,ADAC_MEMBER in lift.flags)
134 if (lift_list.length () == 0)
137 bool preload = false;
139 preload = gconf.get_bool (GCONF_KEY_PRELOAD);
143 if (store.get_iter_first (out iter)) do {
145 store.@get (iter, 5, out lift2);
148 if (lift2.description == null)
149 yield adac.update_lift_details (lift2);
150 } while (store.iter_next (ref iter));
153 Hildon.gtk_window_set_progress_indicator (this, 0);
156 private void on_row_activated (TreeView tree, TreePath /*_*/path, TreeViewColumn column) {
157 TreeModel model = tree.model;
161 if (model.get_iter (out iter, path)) {
162 model.get (iter, 5, out lift);
164 var window = new LiftDetailWindow (adac, lift);
169 private void on_orientation_changed () {
170 route_column.set_visible (!BeifahrerProgram.orientation.portrait);