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 LiftDetailWindow : StackableWindow {
23 private const string BROWSER_SERVICE = "com.nokia.osso_browser";
24 private const string BROWSER_PATH = "/com/nokia/osso_browser";
25 private const string BROWSER_IF = "com.nokia.osso_browser";
27 private const string CALENDAR_SERVICE = "com.nokia.calendar";
28 private const string CALENDAR_PATH = "/com/nokia/calendar";
29 private const string CALENDAR_IF = "com.nokia.calendar";
33 OssoABook.Button button_route;
34 OssoABook.Button button_calendar;
36 OssoABook.Button button_phone;
37 OssoABook.Button button_sms;
41 public LiftDetailWindow (AdacMitfahrclub _adac, Lift _lift) {
45 update_lift_details ();
47 if (lift.description == null)
48 get_lift_details.begin ();
52 set_title ("Beifahrer");
54 var menu = new AppMenu ();
55 var add_contact = new Gtk.Button.with_label (_("New contact"));
57 menu.append (add_contact);
58 var goto_website = new Gtk.Button.with_label (_("Show website"));
60 menu.append (goto_website);
63 var pannable = new PannableArea ();
64 pannable.hscrollbar_policy = PolicyType.NEVER;
66 var vbox = new VBox (false, 0);
68 button_route = new OssoABook.Button (SizeType.FINGER_HEIGHT);
69 button_route.style = OssoABook.ButtonStyle.LABEL;
71 var table = new Table (5, 2, false);
73 button_calendar = new OssoABook.Button (SizeType.FINGER_HEIGHT);
74 button_calendar.set_icon_name ("general_calendar");
75 button_calendar.set_icon_visible (true);
76 button_calendar.style = OssoABook.ButtonStyle.LABEL;
77 button_calendar.title = _("Departure time");
79 label_driver = new Label (_("Driver:"));
80 label_driver.set_alignment (0.0f, 0.5f);
82 button_phone = new OssoABook.Button (SizeType.FINGER_HEIGHT);
83 button_phone.set_icon_name ("general_call");
84 button_phone.set_icon_visible (true);
85 button_phone.title = _("Phone");
87 button_sms = new OssoABook.Button (SizeType.FINGER_HEIGHT);
88 button_sms.set_icon_name ("general_sms");
89 button_sms.set_icon_visible (true);
90 button_sms.title = _("SMS");
92 image_smoke = new Image ();
94 label = new Label ("");
95 label.set_alignment (0.0f, 0.5f);
96 label.set_line_wrap (true);
98 table.attach (button_calendar, 1, 2, 0, 1, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
99 table.attach (label_driver, 0, 1, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
100 table.attach (button_phone, 1, 2, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
101 table.attach (button_sms, 1, 2, 2, 3, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
102 table.attach (image_smoke, 1, 2, 3, 4, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
103 table.attach (label, 0, 2, 4, 5, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
105 vbox.pack_start (button_route, true, true, 0);
106 vbox.pack_start (table, true, true, 0);
108 pannable.add_with_viewport (vbox);
112 add_contact.clicked.connect (on_add_contact_clicked);
113 goto_website.clicked.connect (on_goto_website_clicked);
114 button_phone.clicked.connect (on_button_phone_clicked);
115 button_sms.clicked.connect (on_button_sms_clicked);
118 private async void get_lift_details () {
119 Hildon.gtk_window_set_progress_indicator (this, 1);
120 yield adac.update_lift_details (lift);
121 Hildon.gtk_window_set_progress_indicator (this, 0);
123 update_lift_details ();
126 private void update_lift_details () {
127 button_route.title = _("From %s to %s").printf (lift.city_from, lift.city_to);
128 if (lift.city_via.length () > 0) {
129 string route = _("via ");
130 foreach (string via in lift.city_via)
132 button_route.value = route;
134 button_route.value = "";
137 button_calendar.value = "%s, %s".printf (lift.date, lift.time);
139 label_driver.set_text (_("Driver: ") + lift.name);
140 if (lift.cell != null) {
141 button_phone.title = _("Cell");
142 string cell_number = E.normalize_phone_number (lift.cell);
143 button_phone.value = cell_number;
144 button_sms.value = cell_number;
145 } else if (lift.phone != null) {
146 button_phone.title = _("Phone");
147 string phone_number = E.normalize_phone_number (lift.phone);
148 button_phone.value = phone_number;
149 button_sms.value = phone_number;
152 string lift_text = _("Free places: %d\n").printf (lift.places);
153 lift_text += (lift.price != null) ? _("Price: %s\n").printf (lift.price) : _("(no price given)\n");
154 if (LiftFlags.SMOKER in lift.flags) try {
155 var pixbuf = IconTheme.get_default ().load_icon ("beifahrer_smoker", 32, IconLookupFlags.NO_SVG);
156 image_smoke.pixbuf = pixbuf;
157 lift_text += _("smoker ");
159 } else if (LiftFlags.NON_SMOKER in lift.flags) try {
160 var pixbuf = IconTheme.get_default ().load_icon ("beifahrer_non_smoker", 32, IconLookupFlags.NO_SVG);
161 image_smoke.pixbuf = pixbuf;
162 lift_text += _("non-smoker ");
165 if (LiftFlags.ADAC_MEMBER in lift.flags)
166 lift_text += _("ADAC member ");
167 if (LiftFlags.WOMEN_ONLY in lift.flags)
168 lift_text += _("only women ");
169 lift_text += "\n\n" + lift.description;
171 if (lift.modified != null)
172 lift_text += _("\nLast changed: ") + lift.modified;
174 label.set_text (lift_text);
177 void on_button_phone_clicked () {
179 if (lift.cell != null)
180 uri += E.normalize_phone_number (lift.cell);
181 else if (lift.phone != null)
182 uri += E.normalize_phone_number (lift.phone);
184 var action = URIAction.get_default_action_by_uri (uri);
185 if (action != null) {
189 Banner.show_information (this, null, _("Couldn't call %s URI").printf (uri));
193 Banner.show_information (this, null, _("Error: %s").printf (e.message));
198 void on_button_sms_clicked () {
200 if (lift.cell != null)
201 uri += E.normalize_phone_number (lift.cell);
202 else if (lift.phone != null)
203 uri += E.normalize_phone_number (lift.phone);
205 var action = URIAction.get_default_action_by_uri (uri);
206 if (action != null) {
210 Banner.show_information (this, null, _("Couldn't open %s URI").printf (uri));
214 Banner.show_information (this, null, _("Error: %s").printf (e.message));
219 void on_add_contact_clicked () {
220 var contact = new OssoABook.Contact ();
221 var attr_fn = new E.VCardAttribute (null, E.EVC_FN);
222 contact.add_attribute_with_value ((owned) attr_fn, lift.name);
223 if (lift.cell != null) {
224 var attr_cell = new E.VCardAttribute (null, E.EVC_TEL);
225 var param = new E.VCardAttributeParam (E.EVC_TYPE);
226 attr_cell.add_param_with_value ((owned) param, "CELL");
227 contact.add_attribute_with_value ((owned) attr_cell, E.normalize_phone_number (lift.cell));
229 if (lift.phone != null) {
230 var attr_phone = new E.VCardAttribute (null, E.EVC_TEL);
231 var param = new E.VCardAttributeParam (E.EVC_TYPE);
232 attr_phone.add_param_with_value ((owned) param, "VOICE");
233 contact.add_attribute_with_value ((owned) attr_phone, E.normalize_phone_number (lift.phone));
235 var dialog = new OssoABook.TemporaryContactDialog.with_contact (this, contact);
239 void on_goto_website_clicked () {
240 var url = "http://mitfahrclub.adac.de" + lift.href;
243 var conn = DBus.Bus.get (DBus.BusType.SESSION);
245 dynamic DBus.Object browser = conn.get_object (BROWSER_SERVICE, BROWSER_PATH, BROWSER_IF);
246 browser.open_new_window (url, false);
248 stderr.printf ("Error: %s\n", e.message);
249 Banner.show_information (this, null, _("Failed to open browser."));