]> spindle.queued.net Git - midori/commitdiff
Implement and optimize for portrait mode support for Fremantle
authorChristian Dywan <christian@twotoasts.de>
Fri, 27 Nov 2009 22:42:07 +0000 (23:42 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sun, 29 Nov 2009 13:09:28 +0000 (14:09 +0100)
Listen to accelerometer movement.
Hide tool items in portrait mode.
Omit Homepage and View Source from app menu.
Include Compact Add, View Source and Fullscreen in context menu.
Hide buttons in portrait mode in preferences.

katze/katze-preferences.c
midori/midori-app.c
midori/midori-browser.c
midori/midori-view.c

index f42f77d1afce950364ab03a036f66b9900727195..91006cb95fbbe40a85788b25ee359fd626c685e2 100644 (file)
@@ -66,6 +66,19 @@ katze_preferences_response_cb (KatzePreferences* preferences,
         gtk_widget_destroy (GTK_WIDGET (preferences));
 }
 
+#ifdef HAVE_HILDON_2_2
+static void
+katze_preferences_size_request_cb (KatzePreferences* preferences,
+                                   GtkRequisition*   requisition)
+{
+    GdkScreen* screen = gtk_widget_get_screen (GTK_WIDGET (preferences));
+    if (gdk_screen_get_height (screen) > gdk_screen_get_width (screen))
+        gtk_widget_hide (gtk_dialog_get_action_area (GTK_DIALOG (preferences)));
+    else
+        gtk_widget_show (gtk_dialog_get_action_area (GTK_DIALOG (preferences)));
+}
+#endif
+
 static void
 katze_preferences_init (KatzePreferences* preferences)
 {
@@ -94,9 +107,17 @@ katze_preferences_init (KatzePreferences* preferences)
         #endif
         NULL);
     #endif
+
     g_object_connect (preferences,
         "signal::response", katze_preferences_response_cb, NULL,
         NULL);
+
+    #ifdef HAVE_HILDON_2_2
+    katze_preferences_size_request_cb (preferences, NULL);
+    g_object_connect (preferences,
+        "signal::size-request", katze_preferences_size_request_cb, NULL,
+        NULL);
+    #endif
 }
 
 static void
@@ -168,7 +189,8 @@ katze_preferences_prepare (KatzePreferences* preferences)
     priv->sizegroup = NULL;
     priv->sizegroup2 = NULL;
 
-    g_signal_connect (priv->scrolled, "destroy", G_CALLBACK (gtk_widget_destroyed), &priv->scrolled);
+    g_signal_connect (priv->scrolled, "destroy",
+                      G_CALLBACK (gtk_widget_destroyed), &priv->scrolled);
     #else
     priv->notebook = gtk_notebook_new ();
     gtk_container_set_border_width (GTK_CONTAINER (priv->notebook), 6);
@@ -195,7 +217,8 @@ katze_preferences_prepare (KatzePreferences* preferences)
     priv->box = NULL;
     priv->hbox = NULL;
 
-    g_signal_connect (priv->notebook, "destroy", G_CALLBACK (gtk_widget_destroyed), &priv->notebook);
+    g_signal_connect (priv->notebook, "destroy",
+                      G_CALLBACK (gtk_widget_destroyed), &priv->notebook);
     #endif
 
     #if HAVE_OSX
@@ -206,8 +229,7 @@ katze_preferences_prepare (KatzePreferences* preferences)
     gtk_button_set_image (GTK_BUTTON (button), icon);
     g_signal_connect (button, "clicked",
         G_CALLBACK (katze_preferences_help_clicked_cb), preferences);
-    gtk_box_pack_end (GTK_BOX (hbox),
-        button, FALSE, FALSE, 4);
+    gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 4);
     gtk_box_pack_end (GTK_BOX (GTK_DIALOG (preferences)->action_area),
         hbox, FALSE, FALSE, 0);
     #endif
index 434e346906c93737fa9f62e72db7bc0cab0ba766..cb756e1e9eeabf3a0fcb2ea67d1d0bce3eb10a0a 100644 (file)
 
 #if HAVE_HILDON
     #include <libosso.h>
+    #ifdef HAVE_HILDON_2_2
+        #include <dbus/dbus.h>
+        #include <mce/mode-names.h>
+        #include <mce/dbus-names.h>
+    #endif
     typedef osso_context_t* MidoriAppInstance;
     #define MidoriAppInstanceNull NULL
 #elif HAVE_UNIQUE
@@ -642,6 +647,12 @@ midori_app_create_instance (MidoriApp*   app,
         osso_deinitialize (instance);
         return NULL;
     }
+
+    #ifdef HAVE_HILDON_2_2
+    if (OSSO_OK == osso_rpc_run_system (instance, MCE_SERVICE, MCE_REQUEST_PATH,
+        MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ, NULL, DBUS_TYPE_INVALID))
+        /* Accelerometer enabled */;
+    #endif
     #else
     GdkDisplay* display;
     gchar* display_name;
index 588ca5704445c4bf39ef953dc8dee796844f77e1..25d064ad689ec5995f1c051698bbe4e778da4163 100644 (file)
     #include <unistd.h>
 #endif
 
+#ifdef HAVE_HILDON_2_2
+    #include <dbus/dbus.h>
+    #include <mce/mode-names.h>
+    #include <mce/dbus-names.h>
+    #define MCE_SIGNAL_MATCH "type='signal'," \
+        "sender='"    MCE_SERVICE     "',"    \
+        "path='"      MCE_SIGNAL_PATH "',"    \
+        "interface='" MCE_SIGNAL_IF   "'"
+#endif
+
 struct _MidoriBrowser
 {
     #if HAVE_HILDON
@@ -3029,8 +3039,6 @@ _action_compact_menu_populate_popup (GtkAction*     action,
       { "Open" },
       #if HAVE_HILDON
       { "Find" },
-      { "Homepage" },
-      { "SourceView" },
       #else
       { "Print" },
       { "About" },
@@ -3057,12 +3065,7 @@ _action_compact_menu_populate_popup (GtkAction*     action,
 
     for (i = 0; i < G_N_ELEMENTS (actions); i++)
     {
-        #if HAVE_HILDON
-        #if HILDON_CHECK_VERSION (2, 2, 0)
-        #define HAVE_APP_MENU 1
-        #endif
-        #endif
-        #ifdef HAVE_APP_MENU
+        #ifdef HAVE_HILDON_2_2
         GtkAction* _action;
         gchar* label;
         GtkWidget* button;
@@ -5474,6 +5477,58 @@ midori_browser_ui_manager_disconnect_proxy_cb (GtkUIManager*  ui_manager,
     }
 }
 
+#ifdef HAVE_HILDON_2_2
+static void
+midori_browser_set_portrait_mode (MidoriBrowser* browser,
+                                  gboolean       portrait)
+{
+    if (portrait)
+        hildon_gtk_window_set_portrait_flags (GTK_WINDOW (browser),
+                                              HILDON_PORTRAIT_MODE_REQUEST);
+    else
+        hildon_gtk_window_set_portrait_flags (GTK_WINDOW (browser),
+                                              ~HILDON_PORTRAIT_MODE_REQUEST);
+    _action_set_visible (browser, "Bookmarks", !portrait);
+    _action_set_visible (browser, "CompactAdd", !portrait);
+    _action_set_visible (browser, "Back", !portrait);
+    _action_set_visible (browser, "SourceView", !portrait);
+    _action_set_visible (browser, "Fullscreen", !portrait);
+}
+
+static DBusHandlerResult
+midori_browser_mce_filter_cb (DBusConnection* connection,
+                              DBusMessage*    message,
+                              gpointer        data)
+{
+    if (dbus_message_is_signal (message, MCE_SIGNAL_IF, MCE_DEVICE_ORIENTATION_SIG))
+    {
+        DBusError error;
+        char *rotation, *stand, *face;
+        int x, y, z;
+
+        dbus_error_init (&error);
+        if (dbus_message_get_args (message,
+                                   &error,
+                                   DBUS_TYPE_STRING, &rotation,
+                                   DBUS_TYPE_STRING, &stand,
+                                   DBUS_TYPE_STRING, &face,
+                                   DBUS_TYPE_INT32,  &x,
+                                   DBUS_TYPE_INT32,  &y,
+                                   DBUS_TYPE_INT32,  &z, DBUS_TYPE_INVALID))
+        {
+            gboolean portrait = !strcmp (rotation, MCE_ORIENTATION_PORTRAIT);
+            midori_browser_set_portrait_mode (MIDORI_BROWSER (data), portrait);
+        }
+        else
+        {
+            g_warning ("%s: %s\n", error.name, error.message);
+            dbus_error_free (&error);
+        }
+    }
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+#endif
+
 static void
 midori_browser_init (MidoriBrowser* browser)
 {
@@ -5792,6 +5847,18 @@ midori_browser_init (MidoriBrowser* browser)
     gtk_box_pack_start (GTK_BOX (vbox), browser->navigationbar, FALSE, FALSE, 0);
     #endif
 
+    #ifdef HAVE_HILDON_2_2
+    DBusConnection* system_bus = dbus_bus_get (DBUS_BUS_SYSTEM, NULL);
+    if (system_bus)
+    {
+        dbus_bus_add_match (system_bus, MCE_SIGNAL_MATCH, NULL);
+        dbus_connection_add_filter (system_bus,
+            midori_browser_mce_filter_cb, browser, NULL);
+        hildon_gtk_window_set_portrait_flags (GTK_WINDOW (browser),
+                                              HILDON_PORTRAIT_MODE_SUPPORT);
+    }
+    #endif
+
     /* Bookmarkbar */
     browser->bookmarkbar = gtk_toolbar_new ();
     gtk_widget_set_name (browser->bookmarkbar, "MidoriBookmarkbar");
index e41d19f38e92dc8085d86f0e45df495c0262b9f5..d4a89e3ddbffef0970691cccd61f3a0e4590a7f2 100644 (file)
@@ -1977,12 +1977,14 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
             gtk_menu_shell_append (menu_shell, menuitem);
         }
 
+        #if !HAVE_HILDON
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "ZoomIn"));
         gtk_menu_shell_append (menu_shell, menuitem);
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "ZoomOut"));
         gtk_menu_shell_append (menu_shell, menuitem);
+        #endif
 
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "Encoding"));
@@ -2012,7 +2014,15 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
             }
         }
 
-        #if !HAVE_HILDON
+        #if HAVE_HILDON
+        gtk_menu_shell_append (menu_shell, gtk_separator_menu_item_new ());
+        menuitem = sokoke_action_create_popup_menu_item (
+                gtk_action_group_get_action (actions, "CompactAdd"));
+        gtk_menu_shell_append (menu_shell, menuitem);
+        menuitem = sokoke_action_create_popup_menu_item (
+                gtk_action_group_get_action (actions, "Fullscreen"));
+        gtk_menu_shell_append (menu_shell, menuitem);
+        #else
         gtk_menu_shell_append (menu_shell, gtk_separator_menu_item_new ());
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "BookmarkAdd"));
@@ -2033,7 +2043,6 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "SaveAs"));
         gtk_menu_shell_append (menu_shell, menuitem);
-        #if !HAVE_HILDON
         /* Currently views that don't support source, don't support
            saving either. If that changes, we need to think of something. */
         if (!midori_view_can_view_source (view))
@@ -2041,7 +2050,6 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
         menuitem = sokoke_action_create_popup_menu_item (
                 gtk_action_group_get_action (actions, "SourceView"));
         gtk_menu_shell_append (menu_shell, menuitem);
-        #endif
     }
 
     gtk_widget_show_all (menu);