[vinagre] Move some utility code to where it is used



commit 1d5ab058ab7fdf400a47b8e16451e47d3f74955c
Author: David King <amigadave amigadave com>
Date:   Sun May 1 16:55:27 2011 +0200

    Move some utility code to where it is used

 vinagre/vinagre-commands.c |   14 ++++++++--
 vinagre/vinagre-fav.c      |   28 +++++++++++++++++++++-
 vinagre/vinagre-utils.c    |   55 +++++--------------------------------------
 vinagre/vinagre-utils.h    |    4 ---
 vinagre/vinagre-window.c   |   12 ++++++++-
 5 files changed, 56 insertions(+), 57 deletions(-)
---
diff --git a/vinagre/vinagre-commands.c b/vinagre/vinagre-commands.c
index fc676c2..278874d 100644
--- a/vinagre/vinagre-commands.c
+++ b/vinagre/vinagre-commands.c
@@ -42,6 +42,14 @@
 #include "vinagre-plugins-engine.h"
 #include "vinagre-plugin-dialog.h"
 
+static void _toggle_widget_visible (GtkWidget *widget)
+{
+    if (gtk_widget_get_visible (widget))
+        gtk_widget_hide (widget);
+    else
+        gtk_widget_show_all (widget);
+}
+
 void
 vinagre_cmd_direct_connect (VinagreConnection *conn,
 			    VinagreWindow     *window)
@@ -243,7 +251,7 @@ vinagre_cmd_view_show_toolbar	(GtkAction     *action,
 {
   g_return_if_fail (VINAGRE_IS_WINDOW (window));
 
-  vinagre_utils_toggle_widget_visible (window->priv->toolbar);
+  _toggle_widget_visible (window->priv->toolbar);
 
   vinagre_cache_prefs_set_boolean ("window",
 				   "toolbar-visible",
@@ -256,7 +264,7 @@ vinagre_cmd_view_show_statusbar	(GtkAction     *action,
 {
   g_return_if_fail (VINAGRE_IS_WINDOW (window));
 
-  vinagre_utils_toggle_widget_visible (window->priv->statusbar);
+  _toggle_widget_visible (window->priv->statusbar);
 
   vinagre_cache_prefs_set_boolean ("window",
 				   "statusbar-visible",
@@ -269,7 +277,7 @@ vinagre_cmd_view_show_fav_panel	(GtkAction     *action,
 {
   g_return_if_fail (VINAGRE_IS_WINDOW (window));
 
-  vinagre_utils_toggle_widget_visible (window->priv->fav_panel);
+  _toggle_widget_visible (window->priv->fav_panel);
 
   vinagre_cache_prefs_set_boolean ("window",
 				   "side-panel-visible",
diff --git a/vinagre/vinagre-fav.c b/vinagre/vinagre-fav.c
index 80b88ec..b0ddb5d 100644
--- a/vinagre/vinagre-fav.c
+++ b/vinagre/vinagre-fav.c
@@ -844,6 +844,32 @@ vinagre_fav_hide (GtkButton *button, VinagreFav *fav)
   gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE);
 }
 
+static GtkWidget *
+_create_small_close_button ()
+{
+  GtkRcStyle *rcstyle;
+  GtkWidget *image;
+  GtkWidget *close_button;
+
+  close_button = gtk_button_new ();
+  gtk_button_set_relief (GTK_BUTTON (close_button),
+			 GTK_RELIEF_NONE);
+  /* don't allow focus on the close button */
+  gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
+
+  /* make it as small as possible */
+  rcstyle = gtk_rc_style_new ();
+  rcstyle->xthickness = rcstyle->ythickness = 0;
+  gtk_widget_modify_style (close_button, rcstyle);
+  g_object_unref (rcstyle),
+
+  image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
+				    GTK_ICON_SIZE_MENU);
+  gtk_container_add (GTK_CONTAINER (close_button), image);
+
+  return close_button;
+}
+
 static void
 vinagre_fav_create_title (VinagreFav *fav)
 {
@@ -863,7 +889,7 @@ vinagre_fav_create_title (VinagreFav *fav)
   gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
 
   /* setup small close button */
-  close_button = vinagre_utils_create_small_close_button ();
+  close_button = _create_small_close_button ();
   gtk_box_pack_start (GTK_BOX (box), close_button, FALSE, FALSE, 0);
   gtk_widget_set_tooltip_text (close_button, _("Hide panel"));
   g_signal_connect (close_button,
diff --git a/vinagre/vinagre-utils.c b/vinagre/vinagre-utils.c
index 2638dd9..80975a0 100644
--- a/vinagre/vinagre-utils.c
+++ b/vinagre/vinagre-utils.c
@@ -22,44 +22,10 @@
 #include <glib/gi18n.h>
 #include "vinagre-utils.h"
 
-#define VINAGRE_UI_FILE  "vinagre.ui"
-#define VINAGRE_UI_XML_FILE "vinagre-ui.xml"
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-/**
- * vinagre_utils_create_small_close_button:
- *
- * Return value: (transfer full):
- */
-GtkWidget *
-vinagre_utils_create_small_close_button ()
-{
-  GtkRcStyle *rcstyle;
-  GtkWidget *image;
-  GtkWidget *close_button;
-
-  close_button = gtk_button_new ();
-  gtk_button_set_relief (GTK_BUTTON (close_button),
-			 GTK_RELIEF_NONE);
-  /* don't allow focus on the close button */
-  gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
-
-  /* make it as small as possible */
-  rcstyle = gtk_rc_style_new ();
-  rcstyle->xthickness = rcstyle->ythickness = 0;
-  gtk_widget_modify_style (close_button, rcstyle);
-  g_object_unref (rcstyle),
-
-  image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
-				    GTK_ICON_SIZE_MENU);
-  gtk_container_add (GTK_CONTAINER (close_button), image);
-
-  return close_button;
-}
-
 void
 vinagre_utils_show_error (const gchar *title, const gchar *message, GtkWindow *parent)
 {
@@ -115,22 +81,15 @@ vinagre_utils_toggle_widget_visible (GtkWidget *widget)
     gtk_widget_show_all (widget);
 }
 
-const gchar *
-vinagre_utils_get_ui_filename (void)
+static const gchar *
+_get_ui_filename (void)
 {
-  if (g_file_test (VINAGRE_UI_FILE, G_FILE_TEST_EXISTS))
-    return VINAGRE_UI_FILE;
-  else
-    return VINAGRE_DATADIR "/" VINAGRE_UI_FILE;
-}
+    static const gchar ui_file[] = "vinagre.ui";
 
-const gchar *
-vinagre_utils_get_ui_xml_filename (void)
-{
-  if (g_file_test (VINAGRE_UI_XML_FILE, G_FILE_TEST_EXISTS))
-    return VINAGRE_UI_XML_FILE;
+  if (g_file_test (ui_file, G_FILE_TEST_EXISTS))
+    return ui_file;
   else
-    return VINAGRE_DATADIR "/" VINAGRE_UI_XML_FILE;
+    return g_build_filename (VINAGRE_DATADIR, ui_file, NULL);
 }
 
 /**
@@ -148,7 +107,7 @@ vinagre_utils_get_builder (const gchar *filename)
   if (filename)
     actual_filename = g_strdup (filename);
   else
-    actual_filename = g_strdup (vinagre_utils_get_ui_filename ());
+    actual_filename = g_strdup (_get_ui_filename ());
 
   xml = gtk_builder_new ();
   if (!gtk_builder_add_from_file (xml,
diff --git a/vinagre/vinagre-utils.h b/vinagre/vinagre-utils.h
index d964828..6fceb72 100644
--- a/vinagre/vinagre-utils.h
+++ b/vinagre/vinagre-utils.h
@@ -31,8 +31,6 @@
 
 enum { VINAGRE_ALL_WORKSPACES = 0xffffffff };
 
-GtkWidget	*vinagre_utils_create_small_close_button (void);
-
 void		vinagre_utils_show_error		(const gchar *title,
 							 const gchar *message,
 							 GtkWindow *parent);
@@ -43,8 +41,6 @@ void		vinagre_utils_show_many_errors		(const gchar *title,
 
 void		vinagre_utils_toggle_widget_visible	(GtkWidget *widget);
 
-const gchar	*vinagre_utils_get_ui_filename		(void);
-const gchar	*vinagre_utils_get_ui_xml_filename	(void);
 GtkBuilder	*vinagre_utils_get_builder		(const gchar *filename);
 
 gchar		*vinagre_utils_escape_underscores	(const gchar *text,
diff --git a/vinagre/vinagre-window.c b/vinagre/vinagre-window.c
index 0ee8119..15b1cc2 100644
--- a/vinagre/vinagre-window.c
+++ b/vinagre/vinagre-window.c
@@ -55,6 +55,16 @@
 
 G_DEFINE_TYPE(VinagreWindow, vinagre_window, GTK_TYPE_WINDOW)
 
+static const gchar * _get_ui_xml_filename (void)
+{
+    static const gchar ui_xml_file[] = "vinagre-ui.xml";
+
+    if (g_file_test (ui_xml_file, G_FILE_TEST_EXISTS))
+        return ui_xml_file;
+    else
+        return g_build_filename (VINAGRE_DATADIR, ui_xml_file, NULL);
+}
+
 static void
 vinagre_window_dispose (GObject *object)
 {
@@ -394,7 +404,7 @@ create_menu_bar_and_toolbar (VinagreWindow *window,
   window->priv->remote_initialized_action_group = action_group;
 
   /* now load the UI definition */
-  gtk_ui_manager_add_ui_from_file (manager, vinagre_utils_get_ui_xml_filename (), &error);
+  gtk_ui_manager_add_ui_from_file (manager, _get_ui_xml_filename (), &error);
   if (error != NULL)
     {
       g_critical (_("Could not merge UI XML file: %s"), error->message);



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