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;
40 public LiftDetailWindow (AdacMitfahrclub _adac, Lift _lift) {
44 update_lift_details ();
48 set_title ("Beifahrer");
50 var menu = new AppMenu ();
51 var add_contact = new Gtk.Button.with_label (_("New contact"));
53 menu.append (add_contact);
54 var goto_website = new Gtk.Button.with_label (_("Show website"));
56 menu.append (goto_website);
59 var pannable = new PannableArea ();
60 pannable.hscrollbar_policy = PolicyType.NEVER;
62 var vbox = new VBox (false, 0);
64 button_route = new OssoABook.Button (SizeType.FINGER_HEIGHT);
65 button_route.style = OssoABook.ButtonStyle.LABEL;
67 var table = new Table (2, 4, false);
69 button_calendar = new OssoABook.Button (SizeType.FINGER_HEIGHT);
70 button_calendar.set_icon_name ("general_calendar");
71 button_calendar.set_icon_visible (true);
72 button_calendar.style = OssoABook.ButtonStyle.LABEL;
73 button_calendar.title = _("Departure time");
75 label_driver = new Label (_("Driver:"));
76 label_driver.set_alignment (0.0f, 0.5f);
78 button_phone = new OssoABook.Button (SizeType.FINGER_HEIGHT);
79 button_phone.set_icon_name ("general_call");
80 button_phone.set_icon_visible (true);
81 button_phone.title = _("Phone");
83 image_smoke = new Image ();
85 label = new Label ("");
86 label.set_alignment (0.0f, 0.5f);
87 label.set_line_wrap (true);
89 table.attach (button_calendar, 1, 2, 0, 1, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
90 table.attach (label_driver, 0, 1, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
91 table.attach (button_phone, 1, 2, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
92 table.attach (image_smoke, 1, 2, 2, 3, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
93 table.attach (label, 0, 2, 3, 4, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
95 vbox.pack_start (button_route, true, true, 0);
96 vbox.pack_start (table, true, true, 0);
98 pannable.add_with_viewport (vbox);
102 add_contact.clicked.connect (on_add_contact_clicked);
103 goto_website.clicked.connect (on_goto_website_clicked);
104 button_phone.clicked.connect (on_button_phone_clicked);
107 public void update_lift_details () {
108 button_route.title = _("From %s to %s").printf (lift.city_from, lift.city_to);
109 if (lift.city_via.length () > 0) {
110 string route = _("via ");
111 foreach (string via in lift.city_via)
113 button_route.value = route;
115 button_route.value = "";
118 button_calendar.value = "%s, %s".printf (lift.date, lift.time);
120 label_driver.set_text (_("Driver: ") + lift.name);
121 if (lift.cell != null) {
122 button_phone.title = _("Cell");
123 button_phone.value = E.normalize_phone_number (lift.cell);
124 } else if (lift.phone != null) {
125 button_phone.title = _("Phone");
126 button_phone.value = E.normalize_phone_number (lift.phone);
129 string lift_text = _("Free places: %d\n").printf (lift.places);
130 lift_text += (lift.price != null) ? _("Price: %s\n").printf (lift.price) : _("(no price given)\n");
131 if (LiftFlags.SMOKER in lift.flags) try {
132 var pixbuf = IconTheme.get_default ().load_icon ("beifahrer_smoker", 32, IconLookupFlags.NO_SVG);
133 image_smoke.pixbuf = pixbuf;
134 lift_text += _("smoker ");
136 } else if (LiftFlags.NON_SMOKER in lift.flags) try {
137 var pixbuf = IconTheme.get_default ().load_icon ("beifahrer_non_smoker", 32, IconLookupFlags.NO_SVG);
138 image_smoke.pixbuf = pixbuf;
139 lift_text += _("non-smoker ");
142 if (LiftFlags.ADAC_MEMBER in lift.flags)
143 lift_text += _("ADAC member ");
144 if (LiftFlags.WOMEN_ONLY in lift.flags)
145 lift_text += _("only women ");
146 lift_text += "\n\n" + lift.description;
148 if (lift.modified != null)
149 lift_text += _("\nLast changed: ") + lift.modified;
151 label.set_text (lift_text);
154 void on_button_phone_clicked () {
156 if (lift.cell != null)
157 uri += E.normalize_phone_number (lift.cell);
158 else if (lift.phone != null)
159 uri += E.normalize_phone_number (lift.phone);
161 var action = URIAction.get_default_action_by_uri (uri);
162 if (action != null) {
166 Banner.show_information (this, null, _("Couldn't call %s URI").printf (uri));
170 Banner.show_information (this, null, _("Error: %s").printf (e.message));
175 void on_add_contact_clicked () {
176 var contact = new OssoABook.Contact ();
177 var attr_fn = new E.VCardAttribute (null, E.EVC_FN);
178 contact.add_attribute_with_value ((owned) attr_fn, lift.name);
179 if (lift.cell != null) {
180 var attr_cell = new E.VCardAttribute (null, E.EVC_TEL);
181 var param = new E.VCardAttributeParam (E.EVC_TYPE);
182 attr_cell.add_param_with_value ((owned) param, "CELL");
183 contact.add_attribute_with_value ((owned) attr_cell, E.normalize_phone_number (lift.cell));
185 if (lift.phone != null) {
186 var attr_phone = new E.VCardAttribute (null, E.EVC_TEL);
187 var param = new E.VCardAttributeParam (E.EVC_TYPE);
188 attr_phone.add_param_with_value ((owned) param, "VOICE");
189 contact.add_attribute_with_value ((owned) attr_phone, E.normalize_phone_number (lift.phone));
191 var dialog = new OssoABook.TemporaryContactDialog.with_contact (this, contact);
195 void on_goto_website_clicked () {
196 var url = "http://mitfahrclub.adac.de" + lift.href;
199 var conn = DBus.Bus.get (DBus.BusType.SESSION);
201 dynamic DBus.Object browser = conn.get_object (BROWSER_SERVICE, BROWSER_PATH, BROWSER_IF);
202 browser.open_new_window (url, false);
204 stderr.printf ("Error: %s\n", e.message);
205 Banner.show_information (this, null, _("Failed to open browser."));