[epiphany] Combine the Reload and Stop toolbar buttons into one



commit b1cd68562f3ceaf17a803f0f9161c28fdc5ba766
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Thu Dec 15 18:27:35 2011 +0200

    Combine the Reload and Stop toolbar buttons into one
    
    Add a combined action that toggles itself between the two states and
    instantiate it from the window. Replace the Reload and Stop buttons
    with the combined one in the default toolbar description.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=657655

 data/ui/epiphany-ui.xml                |    3 +-
 src/Makefile.am                        |    2 +
 src/ephy-combined-stop-reload-action.c |  162 ++++++++++++++++++++++++++++++++
 src/ephy-combined-stop-reload-action.h |   61 ++++++++++++
 src/ephy-window.c                      |   14 +++
 5 files changed, 240 insertions(+), 2 deletions(-)
---
diff --git a/data/ui/epiphany-ui.xml b/data/ui/epiphany-ui.xml
index ebce0c3..4737a47 100644
--- a/data/ui/epiphany-ui.xml
+++ b/data/ui/epiphany-ui.xml
@@ -174,8 +174,7 @@
         <toolbar name="DefaultToolbar">
                 <toolitem action="NavigationBack"/>
                 <toolitem action="NavigationForward"/>
-                <toolitem action="ViewStop"/>
-                <toolitem action="ViewReload"/>
+                <toolitem action="ViewCombinedStopReload"/>
                 <toolitem action="Location"/>
         </toolbar>
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 45b55d2..d71fd42 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,6 +15,7 @@ header_DATA = \
 
 NOINST_H_FILES = \
 	ephy-action-helper.h			\
+	ephy-combined-stop-reload-action.h	\
 	ephy-encoding-dialog.h			\
 	ephy-encoding-menu.h			\
 	ephy-find-toolbar.h			\
@@ -50,6 +51,7 @@ libephymain_la_SOURCES = \
 	ephy-action-helper.c			\
 	ephy-completion-model.c			\
 	ephy-completion-model.h			\
+	ephy-combined-stop-reload-action.c	\
 	ephy-encoding-dialog.c			\
 	ephy-encoding-menu.c			\
 	ephy-extension.c			\
diff --git a/src/ephy-combined-stop-reload-action.c b/src/ephy-combined-stop-reload-action.c
new file mode 100644
index 0000000..73a638f
--- /dev/null
+++ b/src/ephy-combined-stop-reload-action.c
@@ -0,0 +1,162 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=2 sts=2 et: */
+/*
+ *  Copyright  2011 Igalia S.L.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include "ephy-combined-stop-reload-action.h"
+#include "ephy-window.h"
+#include "window-commands.h"
+
+#include <glib/gi18n.h>
+
+
+G_DEFINE_TYPE (EphyCombinedStopReloadAction, ephy_combined_stop_reload_action, GTK_TYPE_ACTION)
+
+#define COMBINED_STOP_RELOAD_ACTION_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION, EphyCombinedStopReloadActionPrivate))
+
+struct _EphyCombinedStopReloadActionPrivate
+{
+  gboolean loading;
+  EphyWindow *window;
+  gulong action_handler_id;
+};
+
+GtkActionEntry combined_stop_reload_action_entries [] = {
+  { NULL, GTK_STOCK_STOP, N_("Stop"), NULL,
+    N_("Stop current data transfer"),
+    G_CALLBACK (window_cmd_view_stop) },
+  { NULL, GTK_STOCK_REFRESH, N_("_Reload"), NULL,
+    N_("Display the latest content of the current page"),
+    G_CALLBACK (window_cmd_view_reload) }
+};
+
+typedef enum {
+  EPHY_COMBINED_STOP_RELOAD_ACTION_STOP,
+  EPHY_COMBINED_STOP_RELOAD_ACTION_REFRESH
+} EphyCombinedStopReloadActionEnum;
+
+enum {
+  PROP_0,
+  PROP_LOADING,
+  PROP_WINDOW
+};
+
+void
+ephy_combined_stop_reload_action_set_loading (EphyCombinedStopReloadAction *action,
+                                              gboolean loading)
+{
+  EphyCombinedStopReloadActionEnum action_enum;
+
+  if (action->priv->loading == loading)
+    return;
+
+  action_enum = loading ?
+    EPHY_COMBINED_STOP_RELOAD_ACTION_STOP : EPHY_COMBINED_STOP_RELOAD_ACTION_REFRESH;
+
+  g_object_set (action,
+                "label", combined_stop_reload_action_entries[action_enum].label,
+                "stock-id", combined_stop_reload_action_entries[action_enum].stock_id,
+                "tooltip", combined_stop_reload_action_entries[action_enum].tooltip,
+                NULL);
+
+  if (action->priv->action_handler_id)
+    g_signal_handler_disconnect (action, action->priv->action_handler_id);
+
+  action->priv->action_handler_id = g_signal_connect (action, "activate",
+                                                      combined_stop_reload_action_entries[action_enum].callback,
+                                                      action->priv->window);
+
+  action->priv->loading = loading;
+}
+
+static void
+ephy_combined_stop_reload_action_get_property (GObject    *object,
+                                               guint       property_id,
+                                               GValue     *value,
+                                               GParamSpec *pspec)
+{
+  EphyCombinedStopReloadAction *action = EPHY_COMBINED_STOP_RELOAD_ACTION (object);
+
+  switch (property_id)
+    {
+    case PROP_LOADING:
+      g_value_set_boolean (value, action->priv->loading);
+      break;
+    case PROP_WINDOW:
+      g_value_set_object (value, action->priv->window);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+ephy_combined_stop_reload_action_set_property (GObject      *object,
+                                               guint         property_id,
+                                               const GValue *value,
+                                               GParamSpec   *pspec)
+{
+  EphyCombinedStopReloadAction *action = EPHY_COMBINED_STOP_RELOAD_ACTION (object);
+
+  switch (property_id)
+  {
+  case PROP_LOADING:
+    ephy_combined_stop_reload_action_set_loading (action,
+                                      g_value_get_boolean (value));
+    break;
+  case PROP_WINDOW:
+    action->priv->window = EPHY_WINDOW (g_value_get_object (value));
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+
+static void
+ephy_combined_stop_reload_action_class_init (EphyCombinedStopReloadActionClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (EphyCombinedStopReloadActionPrivate));
+
+  object_class->get_property = ephy_combined_stop_reload_action_get_property;
+  object_class->set_property = ephy_combined_stop_reload_action_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_LOADING,
+                                   g_param_spec_boolean ("loading", NULL, NULL,
+                                                         FALSE,
+                                                         G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+  g_object_class_install_property (object_class,
+                                   PROP_WINDOW,
+                                   g_param_spec_object ("window", NULL, NULL,
+                                                        EPHY_TYPE_WINDOW,
+                                                        G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+}
+
+static void
+ephy_combined_stop_reload_action_init (EphyCombinedStopReloadAction *self)
+{
+  self->priv = COMBINED_STOP_RELOAD_ACTION_PRIVATE (self);
+}
diff --git a/src/ephy-combined-stop-reload-action.h b/src/ephy-combined-stop-reload-action.h
new file mode 100644
index 0000000..680f3fe
--- /dev/null
+++ b/src/ephy-combined-stop-reload-action.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=2 sts=2 et: */
+/*
+ *  Copyright  2011 Igalia S.L.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef _EPHY_COMBINED_STOP_RELOAD_ACTION_H
+#define _EPHY_COMBINED_STOP_RELOAD_ACTION_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION            (ephy_combined_stop_reload_action_get_type())
+#define EPHY_COMBINED_STOP_RELOAD_ACTION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION, EphyCombinedStopReloadAction))
+#define EPHY_COMBINED_STOP_RELOAD_ACTION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION, EphyCombinedStopReloadActionClass))
+#define EPHY_IS_COMBINED_STOP_RELOAD_ACTION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION))
+#define EPHY_IS_COMBINED_STOP_RELOAD_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION))
+#define EPHY_COMBINED_STOP_RELOAD_ACTION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION, EphyCombinedStopReloadActionClass))
+
+typedef struct _EphyCombinedStopReloadAction EphyCombinedStopReloadAction;
+typedef struct _EphyCombinedStopReloadActionClass EphyCombinedStopReloadActionClass;
+typedef struct _EphyCombinedStopReloadActionPrivate EphyCombinedStopReloadActionPrivate;
+
+struct _EphyCombinedStopReloadAction
+{
+  GtkAction parent;
+
+  /*< private >*/
+  EphyCombinedStopReloadActionPrivate *priv;
+};
+
+struct _EphyCombinedStopReloadActionClass
+{
+  GtkActionClass parent_class;
+};
+
+GType ephy_combined_stop_reload_action_get_type (void) G_GNUC_CONST;
+
+void ephy_combined_stop_reload_action_set_loading (EphyCombinedStopReloadAction *action,
+				       gboolean loading);
+
+G_END_DECLS
+
+#endif /* _EPHY_COMBINED_STOP_RELOAD_ACTION_H */
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 8b63429..7fc4f38 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -25,6 +25,7 @@
 
 #include "ephy-action-helper.h"
 #include "ephy-bookmarks-ui.h"
+#include "ephy-combined-stop-reload-action.h"
 #include "ephy-debug.h"
 #include "ephy-download-widget.h"
 #include "ephy-download.h"
@@ -1726,6 +1727,14 @@ setup_ui_manager (EphyWindow *window)
 	gtk_action_group_add_action_with_accel (action_group, action, "<control>N");
 	g_object_unref (action);
 
+	action = g_object_new (EPHY_TYPE_COMBINED_STOP_RELOAD_ACTION,
+			       "name", "ViewCombinedStopReload",
+			       "loading", FALSE,
+			       "window", window,
+			       NULL);
+	gtk_action_group_add_action (action_group, action);
+	g_object_unref (action);
+
 	gtk_ui_manager_insert_action_group (manager, action_group, 0);
 	window->priv->toolbar_action_group = action_group;
 	g_object_unref (action_group);
@@ -2089,6 +2098,11 @@ sync_tab_load_status (EphyWebView *view,
 	ephy_action_change_sensitivity_flags (action, SENS_FLAG_LOADING, loading);
 	action = gtk_action_group_get_action (action_group, "FilePrint");
 	ephy_action_change_sensitivity_flags (action, SENS_FLAG_LOADING, loading);
+
+	action = gtk_action_group_get_action (priv->toolbar_action_group,
+					      "ViewCombinedStopReload");
+	ephy_combined_stop_reload_action_set_loading (EPHY_COMBINED_STOP_RELOAD_ACTION (action),
+						      loading);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]