Debian packaging: 0.0.4-1
[beifahrer] / src / beifahrer.vala
1 /* This file is part of Beifahrer.
2  *
3  * Copyright (C) 2010 Philipp Zabel
4  *
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.
9  *
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.
14  *
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/>.
17  */
18
19 using Hildon;
20
21 public class BeifahrerProgram : Hildon.Program {
22         private const string BEIFAHRER_SERVICE = "org.maemo.beifahrer";
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";
26
27         QueryWindow window;
28         public static Orientation orientation;
29
30         construct {
31                 Environment.set_application_name ("Beifahrer");
32
33                 window = new QueryWindow ();
34                 window.destroy.connect (Gtk.main_quit);
35
36                 orientation = new Orientation ();
37                 orientation.changed.connect (on_orientation_changed);
38
39                 add_window (window);
40         }
41
42         private void on_orientation_changed () {
43                 if (orientation.portrait) {
44                         Hildon.gtk_window_set_portrait_flags (window, PortraitFlags.REQUEST);
45                 } else {
46                         Hildon.gtk_window_set_portrait_flags (window, PortraitFlags.SUPPORT);
47                 }
48         }
49
50         public static void open_browser (Gtk.Window window, string url) {
51                 try {
52                         var conn = DBus.Bus.get (DBus.BusType.SESSION);
53
54                         dynamic DBus.Object browser = conn.get_object (BROWSER_SERVICE, BROWSER_PATH, BROWSER_IF);
55                         browser.open_new_window (url, false);
56                 } catch (Error e) {
57                         Banner.show_information (window, null, _("Failed to open browser."));
58                 }
59         }
60
61         static int main (string[] args) {
62                 Gtk.init (ref args);
63
64                 Intl.setlocale (LocaleCategory.ALL, "");
65                 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
66                 Intl.textdomain (Config.GETTEXT_PACKAGE);
67
68                 var osso_context = new Osso.Context (BEIFAHRER_SERVICE, Config.VERSION, true, null);
69                 if (osso_context == null) {
70                         return Osso.Status.ERROR;
71                 }
72
73                 var app = new BeifahrerProgram ();
74
75                 Gtk.main ();
76
77                 return 0;
78         }
79 }
80