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 MyOffersWindow : StackableWindow {
27 TreeViewColumn route_column;
31 public MyOffersWindow (AdacMitfahrclub _adac) {
36 set_title ("My offers");
38 var menu = new AppMenu ();
39 var goto_website = new Gtk.Button.with_label (_("Show website"));
41 menu.append (goto_website);
44 store = new ListStore (4, typeof (string), typeof (string), typeof (string), typeof (Lift));
46 alignment = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
47 alignment.top_padding = MARGIN_HALF;
48 alignment.left_padding = MARGIN_DOUBLE;
49 alignment.right_padding = MARGIN_DOUBLE;
51 tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, store);
52 Hildon.gtk_widget_set_theme_size (tree, SizeType.FINGER_HEIGHT);
54 tree.set_headers_visible (false);
55 tree.set_rules_hint (true);
57 // Tree selection object
58 var selection = tree.get_selection ();
59 selection.set_mode (SelectionMode.SINGLE);
61 // Source and destination column
62 route_column = new TreeViewColumn.with_attributes ("Route", new CellRendererText (), "markup", 0);
63 route_column.set_reorderable (false);
64 route_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
65 route_column.set_expand (true);
66 tree.append_column (route_column);
68 // Date and time column
69 var datetime_column = new TreeViewColumn.with_attributes ("DateTime", new CellRendererText (), "text", 1);
70 datetime_column.set_reorderable (false);
71 datetime_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
72 datetime_column.set_expand (true);
73 tree.append_column (datetime_column);
76 var renderer = new CellRendererText ();
77 Pango.AttrList attr_list = new Pango.AttrList ();
78 var style = Gtk.rc_get_style_by_paths (Gtk.Settings.get_default (), "SmallSystemFont", null, typeof (void));
80 var attr_font_desc = new Pango.AttrFontDesc (style.font_desc.copy ());
81 attr_list.insert ((owned) attr_font_desc);
85 if (this.style.lookup_color ("ActiveTextColor", out color)) {
86 Pango.Attribute attr_color = Pango.attr_foreground_new (color.red, color.green, color.blue);
87 attr_list.insert ((owned) attr_color);
89 renderer.attributes = attr_list;
90 var active_column = new TreeViewColumn.with_attributes ("Active", renderer, "text", 2);
91 active_column.set_reorderable (false);
92 active_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
93 active_column.set_expand (false);
94 tree.append_column (active_column);
96 var pannable = new PannableArea ();
99 no_offers = new Label (_("No offers"));
100 Hildon.helper_set_logical_font (no_offers, "LargeSystemFont");
101 Hildon.helper_set_logical_color (no_offers, RcFlags.FG, StateType.NORMAL, "SecondaryTextColor");
102 no_offers.set_size_request (-1, 6 * 70);
103 no_offers.set_alignment ((float) 0.5, (float) 0.42);
105 var vbox = new VBox (false, 0);
106 vbox.pack_start (pannable, true, true, 0);
107 vbox.pack_start (no_offers, false, false, 0);
109 alignment.add (vbox);
112 alignment.show_all ();
114 route_column.set_visible (!BeifahrerProgram.orientation.portrait);
116 tree.row_activated.connect (this.on_row_activated);
117 Gdk.Screen.get_default ().size_changed.connect (this.on_orientation_changed);
118 goto_website.clicked.connect (on_goto_website_clicked);
121 public async void get_my_offers () {
123 Hildon.gtk_window_set_progress_indicator (this, 1);
124 bool logged_in = yield adac.login_async ();
126 Banner.show_information (this, null, "Login failed.");
130 var lift_list = yield adac.get_my_offers ();
131 foreach (Lift lift in lift_list) {
132 string datetime = "%02d.%02d.%04d".printf (lift.time.day, lift.time.month, lift.time.year);
133 if (lift.time.hour >= 0)
134 datetime += ", %d:%02d".printf (lift.time.hour, lift.time.minute);
135 store.insert_with_values (out iter, -1, 0, lift.city_from + " - " + lift.city_to,
137 2, (LiftFlags.ACTIVE in lift.flags) ? _("Active") : _("Inactive"),
141 if (lift_list.length () > 6)
142 alignment.right_padding = MARGIN_DEFAULT;
143 if (lift_list.length () == 0)
146 Hildon.gtk_window_set_progress_indicator (this, 0);
149 void on_goto_website_clicked () {
150 BeifahrerProgram.open_browser (this, adac.get_my_offers_url ());
153 private void on_row_activated (TreeView tree, TreePath path, TreeViewColumn column) {
154 TreeModel model = tree.model;
158 if (model.get_iter (out iter, path)) {
159 model.get (iter, 3, out lift);
161 var dialog = new OfferEditDialog (this, adac, lift);
166 private void on_orientation_changed (Gdk.Screen screen) {
167 // route_column.set_visible (!BeifahrerProgram.orientation.portrait);