Add "My offers" window and offer edit dialog
authorPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 24 Jun 2010 16:41:59 +0000 (18:41 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 24 Jun 2010 16:41:59 +0000 (18:41 +0200)
Makefile.am
src/my-offers-window.vala [new file with mode: 0644]
src/offer-edit-dialog.vala [new file with mode: 0644]
src/query-window.vala

index 837f782..5bb0c5e 100644 (file)
@@ -36,6 +36,8 @@ beifahrer_SOURCES = \
        src/lift-list-window.c \
        src/lift-detail-window.c \
        src/my-info-window.c \
+       src/my-offers-window.c \
+       src/offer-edit-dialog.c \
        src/settings-dialog.c
 
 beifahrer_VALASOURCES = \
@@ -47,6 +49,8 @@ beifahrer_VALASOURCES = \
        src/lift-list-window.vala \
        src/lift-detail-window.vala \
        src/my-info-window.vala \
+       src/my-offers-window.vala \
+       src/offer-edit-dialog.vala \
        src/settings-dialog.vala
 
 src/beifahrer.c: ${beifahrer_VALASOURCES}
diff --git a/src/my-offers-window.vala b/src/my-offers-window.vala
new file mode 100644 (file)
index 0000000..3432b87
--- /dev/null
@@ -0,0 +1,169 @@
+/* This file is part of Beifahrer.
+ *
+ * Copyright (C) 2010 Philipp Zabel
+ *
+ * Beifahrer 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Beifahrer 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 Beifahrer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+using Hildon;
+
+public class MyOffersWindow : StackableWindow {
+       AdacMitfahrclub adac;
+       ListStore store;
+       Alignment alignment;
+       TreeView tree;
+       TreeViewColumn route_column;
+       Label no_offers;
+       bool preload = false;
+
+       public MyOffersWindow (AdacMitfahrclub _adac) {
+               adac = _adac;
+       }
+
+       construct {
+               set_title ("My offers");
+
+               var menu = new AppMenu ();
+               var goto_website = new Gtk.Button.with_label (_("Show website"));
+               goto_website.show ();
+               menu.append (goto_website);
+               set_main_menu (menu);
+
+               store = new ListStore (4, typeof (string), typeof (string), typeof (string), typeof (Lift));
+
+               alignment = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
+               alignment.top_padding = MARGIN_HALF;
+               alignment.left_padding = MARGIN_DOUBLE;
+               alignment.right_padding = MARGIN_DOUBLE;
+
+               tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, store);
+               Hildon.gtk_widget_set_theme_size (tree, SizeType.FINGER_HEIGHT);
+
+               tree.set_headers_visible (false);
+               tree.set_rules_hint (true);
+
+               // Tree selection object
+               var selection = tree.get_selection ();
+               selection.set_mode (SelectionMode.SINGLE);
+
+               // Source and destination column
+               route_column = new TreeViewColumn.with_attributes ("Route", new CellRendererText (), "markup", 0);
+               route_column.set_reorderable (false);
+               route_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
+               route_column.set_expand (true);
+               tree.append_column (route_column);
+
+               // Date and time column
+               var datetime_column = new TreeViewColumn.with_attributes ("DateTime", new CellRendererText (), "text", 1);
+               datetime_column.set_reorderable (false);
+               datetime_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
+               datetime_column.set_expand (true);
+               tree.append_column (datetime_column);
+
+               // Active column
+               var renderer = new CellRendererText ();
+               Pango.AttrList attr_list = new Pango.AttrList ();
+               var style = Gtk.rc_get_style_by_paths (Gtk.Settings.get_default (), "SmallSystemFont", null, typeof (void));
+               if (style != null) {
+                       var attr_font_desc = new Pango.AttrFontDesc (style.font_desc.copy ());
+                       attr_list.insert ((owned) attr_font_desc);
+               }
+               Gdk.Color color;
+               this.ensure_style ();
+               if (this.style.lookup_color ("ActiveTextColor", out color)) {
+                       Pango.Attribute attr_color = Pango.attr_foreground_new (color.red, color.green, color.blue);
+                       attr_list.insert ((owned) attr_color);
+               }
+               renderer.attributes = attr_list;
+               var active_column = new TreeViewColumn.with_attributes ("Active", renderer, "text", 2);
+               active_column.set_reorderable (false);
+               active_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
+               active_column.set_expand (false);
+               tree.append_column (active_column);
+
+               var pannable = new PannableArea ();
+               pannable.add (tree);
+
+               no_offers = new Label (_("No offers"));
+               Hildon.helper_set_logical_font (no_offers, "LargeSystemFont");
+               Hildon.helper_set_logical_color (no_offers, RcFlags.FG, StateType.NORMAL, "SecondaryTextColor");
+               no_offers.set_size_request (-1, 6 * 70);
+               no_offers.set_alignment ((float) 0.5, (float) 0.42);
+
+               var vbox = new VBox (false, 0);
+               vbox.pack_start (pannable, true, true, 0);
+               vbox.pack_start (no_offers, false, false, 0);
+
+               alignment.add (vbox);
+               add (alignment);
+
+               alignment.show_all ();
+               no_offers.hide ();
+               route_column.set_visible (!BeifahrerProgram.orientation.portrait);
+
+               tree.row_activated.connect (this.on_row_activated);
+               Gdk.Screen.get_default ().size_changed.connect (this.on_orientation_changed);
+               goto_website.clicked.connect (on_goto_website_clicked);
+       }
+
+       public async void get_my_offers () {
+               TreeIter iter;
+               Hildon.gtk_window_set_progress_indicator (this, 1);
+               bool logged_in = yield adac.login_async ();
+               if (!logged_in) {
+                       Banner.show_information (this, null, "Login failed.");
+                       return;
+               }
+
+               var lift_list = yield adac.get_my_offers ();
+               foreach (Lift lift in lift_list) {
+                       string datetime = "%02d.%02d.%04d".printf (lift.time.day, lift.time.month, lift.time.year);
+                       if (lift.time.hour >= 0)
+                               datetime += ", %d:%02d".printf (lift.time.hour, lift.time.minute);
+                       store.insert_with_values (out iter, -1, 0, lift.city_from + " - " + lift.city_to,
+                                                               1, datetime,
+                                                               2, (LiftFlags.ACTIVE in lift.flags) ? _("Active") : _("Inactive"),
+                                                               3, lift);
+               }
+
+               if (lift_list.length () > 6)
+                       alignment.right_padding = MARGIN_DEFAULT;
+               if (lift_list.length () == 0)
+                       no_offers.show ();
+
+               Hildon.gtk_window_set_progress_indicator (this, 0);
+       }
+
+       void on_goto_website_clicked () {
+               BeifahrerProgram.open_browser (this, adac.get_my_offers_url ());
+       }
+
+       private void on_row_activated (TreeView tree, TreePath path, TreeViewColumn column) {
+               TreeModel model = tree.model;
+               TreeIter iter;
+               Lift lift;
+
+               if (model.get_iter (out iter, path)) {
+                       model.get (iter, 3, out lift);
+
+                       var dialog = new OfferEditDialog (this, adac, lift);
+                       dialog.show ();
+               }
+       }
+
+       private void on_orientation_changed (Gdk.Screen screen) {
+       //      route_column.set_visible (!BeifahrerProgram.orientation.portrait);
+       }
+}
diff --git a/src/offer-edit-dialog.vala b/src/offer-edit-dialog.vala
new file mode 100644 (file)
index 0000000..fb1f5ec
--- /dev/null
@@ -0,0 +1,104 @@
+/* This file is part of Beifahrer.
+ *
+ * Copyright (C) 2010 Philipp Zabel
+ *
+ * Beifahrer 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Beifahrer 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 Beifahrer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+using Hildon;
+
+public class OfferEditDialog : Gtk.Dialog {
+       TimeButton time_button;
+       DateButton date_button;
+       CityButton departure_button;
+       CityButton arrival_button;
+       Hildon.TextView comment_entry;
+       Hildon.CheckButton cell;
+       Hildon.CheckButton phone;
+       Hildon.CheckButton email;
+
+       public OfferEditDialog (Gtk.Window window, AdacMitfahrclub adac, Lift lift) {
+               set_title (_("Edit offer"));
+               set_transient_for (window);
+
+               var vbox = (VBox) get_content_area ();
+               vbox.set_size_request (-1, 5*70);
+               var pannable = new PannableArea ();
+               vbox.pack_start (pannable, true, true, 0);
+               vbox = new Gtk.VBox (false, 0);
+               pannable.add_with_viewport (vbox);
+
+               var title_size = new SizeGroup (SizeGroupMode.HORIZONTAL);
+
+               time_button = new Hildon.TimeButton (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
+               time_button.add_title_size_group (title_size);
+               time_button.set_alignment (0.0f, 0.5f, 0.5f, 0.5f);
+               time_button.set_time (lift.time.hour, lift.time.minute);
+               date_button = new Hildon.DateButton (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
+               date_button.add_title_size_group (title_size);
+               date_button.set_alignment (0.0f, 0.5f, 0.5f, 0.5f);
+               date_button.set_date (lift.time.year, lift.time.month - DateMonth.JANUARY, lift.time.day);
+               departure_button = new CityButton (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL, adac.get_city_list (), false);
+               departure_button.set_title (_("Departure"));
+               departure_button.set_value (_("Please select"));
+               departure_button.add_title_size_group (title_size);
+               departure_button.set_alignment (0.0f, 0.5f, 0.5f, 0.5f);
+               departure_button.set_city (lift.city_from);
+               arrival_button = new CityButton (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL, adac.get_city_list (), false);
+               arrival_button.set_title (_("Arrival"));
+               arrival_button.set_value (_("Please select"));
+               arrival_button.add_title_size_group (title_size);
+               arrival_button.set_alignment (0.0f, 0.5f, 0.5f, 0.5f);
+               arrival_button.set_city (lift.city_to);
+
+               var comment_hbox = new Gtk.HBox (false, Hildon.MARGIN_DOUBLE);
+               var comment_label = new Label (_("Comment"));
+               comment_label.set_alignment (0.0f, 0.5f);
+               title_size.add_widget (comment_label);
+               comment_entry = new Hildon.TextView (); // 1000 chars
+               comment_entry.set_wrap_mode (Gtk.WrapMode.WORD_CHAR);
+               cell = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
+               cell.set_label (_("Show cell number"));
+               phone = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
+               phone.set_label (_("Show phone number"));
+               email = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
+               email.set_label (_("Show E-mail address"));
+
+               comment_hbox.pack_start (comment_label, false, false, 0);
+               comment_hbox.pack_start (comment_entry, true, true, 0);
+
+               vbox.pack_start (time_button, true, true, 0);
+               vbox.pack_start (date_button, true, true, 0);
+               vbox.pack_start (departure_button, true, true, 0);
+               vbox.pack_start (arrival_button, true, true, 0);
+               vbox.pack_start (comment_hbox, true, false, 0);
+               vbox.pack_start (cell, true, true, 0);
+               vbox.pack_start (phone, true, true, 0);
+               vbox.pack_start (email, true, true, 0);
+               pannable.show_all ();
+
+               add_button (_("Save"), ResponseType.APPLY);
+
+               response.connect (on_response);
+       }
+
+       void on_response (int response_id) {
+               if (response_id == ResponseType.APPLY) try {
+                       //x
+                       this.destroy ();
+               } catch (Error e) {
+               }
+       }
+}
index 60a43b9..85c73f1 100644 (file)
@@ -40,8 +40,10 @@ public class QueryWindow : StackableWindow {
 
                var menu = new AppMenu ();
                var my_info = new Gtk.Button.with_label (_("My information"));
+               var my_offers = new Gtk.Button.with_label (_("My offers"));
                var settings = new Gtk.Button.with_label (_("Settings"));
                menu.append (my_info);
+               menu.append (my_offers);
                menu.append (settings);
                menu.show_all ();
                set_main_menu (menu);
@@ -117,6 +119,7 @@ public class QueryWindow : StackableWindow {
                switch_button.clicked.connect (on_switch_button_clicked);
                search_button.clicked.connect (on_search_button_clicked);
                my_info.clicked.connect (on_my_info_clicked);
+               my_offers.clicked.connect (on_my_offers_clicked);
                settings.clicked.connect (on_settings_clicked);
 
                show_all ();
@@ -245,6 +248,12 @@ public class QueryWindow : StackableWindow {
                window.show ();
        }
 
+       void on_my_offers_clicked () {
+               var window = new MyOffersWindow (adac);
+               window.show ();
+               window.get_my_offers.begin ();
+       }
+
        void on_settings_clicked () {
                var dialog = new SettingsDialog (this);
                dialog.response.connect (on_settings_response);