]> spindle.queued.net Git - midori/commitdiff
Initial Granite.Widgets.DynamicNotebook support
authorLucas Baudin <xapantu@gmail.com>
Wed, 14 Mar 2012 20:33:16 +0000 (21:33 +0100)
committerChristian Dywan <christian@twotoasts.de>
Wed, 14 Mar 2012 20:48:37 +0000 (21:48 +0100)
The always-show-tabbar is ineffective if we have Granite
and 'Add Tab' won't appear in the toobar.

Modified patched.

midori/midori-browser.c
midori/midori-preferences.c
midori/midori-view.c
midori/midori-websettings.c

index 09c096db111c7d38f20e8e9d844743e8bd112f3e..c9acb8fcdac8b83f031c0604084c275ec5f0c62e 100644 (file)
 #include <gdk/gdkkeysyms.h>
 #include <string.h>
 
+#ifdef HAVE_GRANITE
+    #include <granite.h>
+#endif
+
 #include <config.h>
 #ifdef HAVE_UNISTD_H
     #include <unistd.h>
@@ -247,6 +251,10 @@ static gboolean
 _toggle_tabbar_smartly (MidoriBrowser* browser,
                         gboolean       ignore_fullscreen)
 {
+#ifdef HAVE_GRANITE
+    gboolean has_tabs = !(midori_browser_is_fullscreen (browser) || ignore_fullscreen);
+    /* FIXME: Toggle tabbar visibility */
+#else
     gboolean has_tabs =
         gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), 1) != NULL;
     gboolean show_tabs =
@@ -257,6 +265,7 @@ _toggle_tabbar_smartly (MidoriBrowser* browser,
 
     gtk_notebook_set_show_tabs (GTK_NOTEBOOK (browser->notebook), show_tabs);
     gtk_notebook_set_show_border (GTK_NOTEBOOK (browser->notebook), show_tabs);
+#endif
     return has_tabs;
 }
 
@@ -612,9 +621,13 @@ midori_view_notify_minimized_cb (GtkWidget*     widget,
 {
     if (katze_object_get_boolean (widget, "minimized"))
     {
+        #ifdef HAVE_GRANITE
+        /* FIXME */
+        #else
         GtkNotebook* notebook = GTK_NOTEBOOK (browser->notebook);
         GtkWidget* label = gtk_notebook_get_tab_label (notebook, widget);
         gtk_widget_set_size_request (label, -1, -1);
+        #endif
     }
     else
         midori_browser_notebook_size_allocate_cb (NULL, NULL, browser);
@@ -1512,6 +1525,7 @@ midori_browser_tab_destroy_cb (GtkWidget*     widget,
     return FALSE;
 }
 
+#ifndef HAVE_GRANITE
 static void
 midori_browser_notebook_resize (MidoriBrowser* browser,
                                 GdkRectangle*  allocation)
@@ -1555,33 +1569,33 @@ midori_browser_notebook_resize (MidoriBrowser* browser,
             gtk_widget_set_size_request (label, new_size, -1);
     }
 }
+#endif
 
 static void
 midori_browser_notebook_size_allocate_cb (GtkWidget*     widget,
                                           GdkRectangle*  allocation,
                                           MidoriBrowser* browser)
 {
+    #ifndef HAVE_GRANITE
     if (!gtk_notebook_get_show_tabs (GTK_NOTEBOOK (browser->notebook)))
         return;
 
     midori_browser_notebook_resize (browser, allocation);
+    #endif
 }
 
 static void
 _midori_browser_add_tab (MidoriBrowser* browser,
                          GtkWidget*     view)
 {
-    GtkNotebook* notebook = GTK_NOTEBOOK (browser->notebook);
+    GtkWidget* notebook = browser->notebook;
+#ifndef HAVE_GRANITE
     GtkWidget* tab_label;
+#endif
     KatzeItem* item;
     guint n;
 
     gtk_widget_set_can_focus (view, TRUE);
-    tab_label = midori_view_get_proxy_tab_label (MIDORI_VIEW (view));
-    /* Don't resize empty bin, which is used for thumbnail tabs */
-    if (GTK_IS_BIN (tab_label) && gtk_bin_get_child (GTK_BIN (tab_label))
-     && !katze_object_get_boolean (view, "minimized"))
-        gtk_widget_set_size_request (tab_label, browser->last_tab_size, -1);
     item = midori_view_get_proxy_item (MIDORI_VIEW (view));
     katze_array_add_item (browser->proxy_array, item);
 
@@ -1634,12 +1648,23 @@ _midori_browser_add_tab (MidoriBrowser* browser,
     }
     else
         n = -1;
-    gtk_notebook_insert_page (notebook, view, tab_label, n);
+#ifdef HAVE_GRANITE
+    /* FIXME: Move to desired position */
+    granite_widgets_dynamic_notebook_append_page (
+        GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (notebook),
+        view, midori_view_get_display_title (MIDORI_VIEW (view)), "text-plain");
+#else
+    tab_label = midori_view_get_proxy_tab_label (MIDORI_VIEW (view));
+    /* Don't resize empty bin, which is used for thumbnail tabs */
+    if (GTK_IS_BIN (tab_label) && gtk_bin_get_child (GTK_BIN (tab_label))
+     && !katze_object_get_boolean (view, "minimized"))
+        gtk_widget_set_size_request (tab_label, browser->last_tab_size, -1);
+    gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), view, tab_label, n);
+    gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), view, TRUE);
+    gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), view, TRUE);
+#endif
     katze_item_set_meta_integer (item, "append", -1);
 
-    gtk_notebook_set_tab_reorderable (notebook, view, TRUE);
-    gtk_notebook_set_tab_detachable (notebook, view, TRUE);
-
     /* We want the tab to be removed if the widget is destroyed */
     g_signal_connect (view, "destroy",
         G_CALLBACK (midori_browser_tab_destroy_cb), browser);
@@ -2037,7 +2062,11 @@ midori_browser_class_init (MidoriBrowserClass* class)
                                      "notebook",
                                      "Notebook",
                                      "The notebook containing the views",
+                                     #ifdef HAVE_GRANITE
+                                     GRANITE_WIDGETS_TYPE_DYNAMIC_NOTEBOOK,
+                                     #else
                                      GTK_TYPE_NOTEBOOK,
+                                     #endif
                                      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
     g_object_class_install_property (gobject_class,
@@ -3433,8 +3462,12 @@ _action_fullscreen_activate (GtkAction*     action,
         gtk_widget_hide (browser->bookmarkbar);
         gtk_widget_hide (browser->navigationbar);
         gtk_widget_hide (browser->statusbar);
+        #ifndef HAVE_GRANITE
+        /* FIXME hide tabs */
+        #else
         gtk_notebook_set_show_tabs (GTK_NOTEBOOK (browser->notebook), FALSE);
         gtk_notebook_set_show_border (GTK_NOTEBOOK (browser->notebook), FALSE);
+        #endif
 
         gtk_window_fullscreen (GTK_WINDOW (browser));
     }
@@ -4555,7 +4588,12 @@ _action_inspect_page_activate (GtkAction*     action,
 static gint
 midori_browser_get_n_pages (MidoriBrowser* browser)
 {
+    #ifdef HAVE_GRANITE
+    return granite_widgets_dynamic_notebook_get_n_pages (
+        GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook));
+    #else
     return gtk_notebook_get_n_pages (GTK_NOTEBOOK (browser->notebook));
+    #endif
 }
 
 static void
@@ -4569,8 +4607,12 @@ _action_tab_move_backward_activate (GtkAction*     action,
         new_pos = cur_pos - 1;
     else
         new_pos = midori_browser_get_n_pages (browser) - 1;
+    #ifdef HAVE_GRANITE
+    /* FIXME */
+    #else
     gtk_notebook_reorder_child (GTK_NOTEBOOK (browser->notebook), widget, new_pos);
     g_signal_emit (browser, signals[MOVE_TAB], 0, browser->notebook, cur_pos, new_pos);
+    #endif
 }
 
 static void
@@ -4961,6 +5003,20 @@ midori_browser_notebook_switch_page_after_cb (GtkWidget*       notebook,
     _midori_browser_update_progress (browser, view);
 }
 
+#ifdef HAVE_GRANITE
+static void
+midori_browser_notebook_new_tab_created_cb (GtkWidget*         notebook,
+                                            GraniteWidgetsTab* tab,
+                                            MidoriBrowser*     browser)
+{
+    /* FIXME Pack view into tab: How? */
+    KatzeItem* item = katze_item_new ();
+    GtkWidget* view = midori_view_new_with_item (item, browser->settings);
+    gint n = midori_browser_add_tab (browser, view);
+    midori_browser_set_current_page (browser, n);
+}
+#endif
+
 static void
 midori_browser_notebook_page_reordered_cb (GtkNotebook*   notebook,
                                            MidoriView*    view,
@@ -4972,6 +5028,15 @@ midori_browser_notebook_page_reordered_cb (GtkNotebook*   notebook,
     g_object_notify (G_OBJECT (browser), "tab");
 }
 
+static void
+midori_browser_notebook_page_removed_cb (GtkWidget*     notebook,
+                                         GtkWidget*     view,
+                                         guint          page_num,
+                                         MidoriBrowser* browser)
+{
+    _midori_browser_remove_tab (browser, view);
+}
+
 static gboolean
 midori_browser_notebook_reorder_tab_cb (GtkNotebook*     notebook,
                                         GtkDirectionType arg1,
@@ -6159,7 +6224,13 @@ midori_browser_init (MidoriBrowser* browser)
     vpaned = gtk_vpaned_new ();
     gtk_paned_pack2 (GTK_PANED (hpaned), vpaned, TRUE, FALSE);
     gtk_widget_show (vpaned);
+    #ifdef HAVE_GRANITE
+    /* FIXME: granite: should return GtkWidget* like GTK+ */
+    browser->notebook = (GtkWidget*)granite_widgets_dynamic_notebook_new ();
+    #else
     browser->notebook = gtk_notebook_new ();
+    gtk_notebook_set_scrollable (GTK_NOTEBOOK (browser->notebook), TRUE);
+    #endif
     #if !GTK_CHECK_VERSION (3, 0, 0)
     {
     /* Remove the inner border between scrollbars and the window border */
@@ -6169,7 +6240,6 @@ midori_browser_init (MidoriBrowser* browser)
     g_object_unref (rcstyle);
     }
     #endif
-    gtk_notebook_set_scrollable (GTK_NOTEBOOK (browser->notebook), TRUE);
     gtk_paned_pack1 (GTK_PANED (vpaned), browser->notebook, FALSE, FALSE);
     g_signal_connect (browser->notebook, "switch-page",
                       G_CALLBACK (midori_browser_notebook_switch_page_cb),
@@ -6177,9 +6247,17 @@ midori_browser_init (MidoriBrowser* browser)
     g_signal_connect_after (browser->notebook, "switch-page",
                             G_CALLBACK (midori_browser_notebook_switch_page_after_cb),
                             browser);
+    #ifdef HAVE_GRANITE
+    g_signal_connect (browser->notebook, "new-tab-created",
+                      G_CALLBACK (midori_browser_notebook_new_tab_created_cb),
+                      browser);
+    #endif
     g_signal_connect (browser->notebook, "page-reordered",
                       G_CALLBACK (midori_browser_notebook_page_reordered_cb),
                       browser);
+    g_signal_connect (browser->notebook, "page-removed",
+                      G_CALLBACK (midori_browser_notebook_page_removed_cb),
+                      browser);
     g_signal_connect (browser->notebook, "size-allocate",
                       G_CALLBACK (midori_browser_notebook_size_allocate_cb),
                       browser);
@@ -6440,6 +6518,11 @@ _midori_browser_set_toolbar_items (MidoriBrowser* browser,
             }
             else if (token_current != token_dontcare && token_last == token_dontcare)
                 continue;
+            #ifdef HAVE_GRANITE
+            /* A "new tab" button is already part of the notebook */
+            else if (!strcmp (gtk_action_get_name (action), "TabNew"))
+                continue;
+            #endif
             else
                 toolitem = gtk_action_create_tool_item (action);
 
@@ -7061,9 +7144,15 @@ midori_browser_page_num (MidoriBrowser* browser,
     g_return_val_if_fail (MIDORI_IS_BROWSER (browser), -1);
     g_return_val_if_fail (MIDORI_IS_VIEW (view), -1);
 
+#ifdef HAVE_GRANITE
+    return granite_widgets_dynamic_notebook_page_num (
+        GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), view);
+#else
     return gtk_notebook_page_num (GTK_NOTEBOOK (browser->notebook), view);
+#endif
 }
 
+
 /**
  * midori_browser_remove_tab:
  * @browser: a #MidoriBrowser
@@ -7311,7 +7400,12 @@ midori_browser_set_current_page (MidoriBrowser* browser,
     view = midori_browser_get_nth_tab (browser, n);
     g_return_if_fail (view != NULL);
 
+    #ifdef HAVE_GRANITE
+    granite_widgets_dynamic_notebook_set_current_page (
+        GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), n);
+    #else
     gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), n);
+    #endif
     if (midori_view_is_blank (MIDORI_VIEW (view)))
         midori_browser_activate_action (browser, "Location");
     else
@@ -7338,7 +7432,12 @@ midori_browser_get_current_page (MidoriBrowser* browser)
 {
     g_return_val_if_fail (MIDORI_IS_BROWSER (browser), -1);
 
+    #ifdef HAVE_GRANITE
+    return granite_widgets_dynamic_notebook_get_current_page (
+        GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook));
+    #else
     return gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
+    #endif
 }
 
 /**
@@ -7358,9 +7457,19 @@ GtkWidget*
 midori_browser_get_nth_tab (MidoriBrowser* browser,
                             gint           page)
 {
+#ifdef HAVE_GRANITE
+    GraniteWidgetsTab* tab;
+
+    g_return_val_if_fail (MIDORI_IS_BROWSER (browser), NULL);
+
+    tab = granite_widgets_dynamic_notebook_get_nth_page (
+        GRANITE_WIDGETS_DYNAMIC_NOTEBOOK (browser->notebook), page);
+    return tab != NULL ? tab->widget : NULL;
+#else
     g_return_val_if_fail (MIDORI_IS_BROWSER (browser), NULL);
 
     return gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), page);
+#endif
 }
 
 /**
@@ -7408,7 +7517,7 @@ midori_browser_get_current_tab (MidoriBrowser* browser)
 
     g_return_val_if_fail (MIDORI_IS_BROWSER (browser), NULL);
 
-    n = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
+    n = midori_browser_get_current_page (browser);
     if (n >= 0)
         return midori_browser_get_nth_tab (browser, n);
     else
index 3ec6bdffe6c2329dd52edcd1f090a1b4be15a521..be60c466b6be8a3388ad17e3a200c60b79ea372e 100644 (file)
@@ -429,11 +429,13 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
     button = katze_property_proxy (settings, "open-new-pages-in", NULL);
     SPANNED_ADD (button);
     #if !HAVE_HILDON
-    button = katze_property_proxy (settings, "always-show-tabbar", NULL);
-    INDENTED_ADD (button);
     button = katze_property_proxy (settings, "close-buttons-on-tabs", NULL);
+    INDENTED_ADD (button);
+    #ifndef HAVE_GRANITE
+    button = katze_property_proxy (settings, "always-show-tabbar", NULL);
     SPANNED_ADD (button);
     #endif
+    #endif
     button = katze_property_proxy (settings, "open-tabs-next-to-current", NULL);
     INDENTED_ADD (button);
     button = katze_property_proxy (settings, "open-tabs-in-the-background", NULL);
index a16deca32585a32b3be05e68b624f302ec66471f..ab4f34761d136e38f72343a88231ffe520e0f0c3 100644 (file)
 
 #include "marshal.h"
 
+#ifdef HAVE_GRANITE
+#include <granite.h>
+#endif
+
 #include <string.h>
 #include <stdlib.h>
 #include <glib/gi18n.h>
@@ -595,10 +599,29 @@ midori_view_class_init (MidoriViewClass* class)
                                      flags));
 }
 
+#ifdef HAVE_GRANITE
+static GraniteWidgetsTab*
+midori_view_get_tab (MidoriView* view)
+{
+    GraniteWidgetsDynamicNotebook* notebook;
+    GraniteWidgetsTab* tab = NULL;
+
+    notebook = (GraniteWidgetsDynamicNotebook*)gtk_widget_get_parent ((GtkWidget*)view);
+    if (notebook != NULL)
+        tab = granite_widgets_dynamic_notebook_get_nth_page (notebook,
+            granite_widgets_dynamic_notebook_page_num (notebook, (GtkWidget*)view));
+
+    return tab;
+}
+#endif
+
 static void
 midori_view_set_title (MidoriView* view, const gchar* title)
 {
     const gchar* display_title;
+    #ifdef HAVE_GRANITE
+    GraniteWidgetsTab* tab;
+    #endif
 
     if (!title)
         title = view->uri;
@@ -632,6 +655,12 @@ midori_view_set_title (MidoriView* view, const gchar* title)
     #endif
 
     display_title = midori_view_get_display_title (view);
+    #ifdef HAVE_GRANITE
+    /* FIXME: granite: GraniteWidgetsTab.text should be a property */
+    tab = midori_view_get_tab (view);
+    if (tab != NULL)
+        katze_assign (tab->text, g_strdup (display_title));
+    #endif
     if (view->tab_label)
     {
         /* If the title starts with the presumed name of the website, we
@@ -667,6 +696,11 @@ midori_view_apply_icon (MidoriView*  view,
                         GdkPixbuf*   icon,
                         const gchar* icon_name)
 {
+    #ifdef HAVE_GRANITE
+    GraniteWidgetsTab* tab = midori_view_get_tab (view);
+    g_object_set (tab, "pixbuf", icon, NULL);
+    #endif
+
     katze_item_set_icon (view->item, icon_name);
     /* katze_item_get_image knows about this pixbuf */
     g_object_set_data_full (G_OBJECT (view->item), "pixbuf", g_object_ref (icon),
@@ -898,6 +932,10 @@ midori_view_update_load_status (MidoriView*      view,
     view->load_status = load_status;
     g_object_notify (G_OBJECT (view), "load-status");
 
+    #ifdef HAVE_GRANITE
+    g_object_set (midori_view_get_tab (view),
+                  "loading", view->load_status != MIDORI_LOAD_FINISHED, NULL);
+    #endif
     if (view->tab_icon)
         katze_throbber_set_animated (KATZE_THROBBER (view->tab_icon),
             view->load_status != MIDORI_LOAD_FINISHED);
index 6257650eea633b7ae63e20e681b2413e15635aae..e7a5b8285c70758eadb9f30620fc45d98fe0c776 100644 (file)
@@ -656,8 +656,14 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
                                      "always-show-tabbar",
                                      _("Always Show Tabbar"),
                                      _("Always show the tabbar"),
+        #ifdef HAVE_GRANITE
+                                     TRUE,
+                                     G_PARAM_READABLE
+        #else
                                      FALSE,
-                                     flags));
+                                     flags
+        #endif
+                                     ));
 
     g_object_class_install_property (gobject_class,
                                      PROP_CLOSE_BUTTONS_ON_TABS,