[vinagre] Convert some utility functions to Vala



commit 4ae5dcb95008f31129939242dc172423e15f599a
Author: David King <amigadave amigadave com>
Date:   Sat May 7 20:36:23 2011 +0200

    Convert some utility functions to Vala
    
    Add config.vapi to take some defines from config.h. Add
    vinagre/vinagre-utils.vala to POTFILES.in. Ignore generated
    vinagre/vinagre-utils.c. Rearrange headers in Makefile variables so that
    no .h files are in SOURCES.

 .gitignore                                         |    2 +
 Makefile.am                                        |   70 ++++++----
 configure.ac                                       |    1 +
 plugins/rdp/vinagre-rdp-tab.c                      |    2 +-
 plugins/reverse-vnc/vinagre-reverse-vnc-listener.c |    2 +-
 plugins/spice/vinagre-spice-tab.c                  |    4 +-
 plugins/vnc/vinagre-vnc-tab.c                      |   12 +-
 po/POTFILES.in                                     |    3 +-
 po/POTFILES.skip                                   |    1 +
 vinagre/vapi/config.vapi                           |    7 +
 vinagre/vinagre-bookmarks-migration.c              |    2 +-
 vinagre/vinagre-bookmarks-ui.c                     |   10 +-
 vinagre/vinagre-commands.c                         |    6 +-
 vinagre/vinagre-connect.c                          |    2 +-
 vinagre/vinagre-fav.c                              |    4 +-
 vinagre/vinagre-notebook.c                         |    4 +-
 vinagre/vinagre-prefs.c                            |    2 +-
 vinagre/vinagre-ssh.c                              |    2 +-
 vinagre/vinagre-tab.c                              |    8 +-
 vinagre/vinagre-tube-handler.c                     |   12 +-
 vinagre/vinagre-util.c                             |  138 +-------------------
 vinagre/vinagre-util.h                             |    9 --
 vinagre/vinagre-utils.vala                         |   94 +++++++++++++
 vinagre/vinagre-window.c                           |    4 +-
 24 files changed, 188 insertions(+), 213 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 7448f38..771e1a1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 *~
+*vala.stamp
 Makefile
 Makefile.in
 /.deps
@@ -90,5 +91,6 @@ Makefile.in
 /vinagre/view/.deps
 /vinagre/view/.dirstamp
 /vinagre/view/.libs
+/vinagre/vinagre-utils.c
 /vinagre/vinagre
 /xmldocs.make
diff --git a/Makefile.am b/Makefile.am
index c4ecd39..0e5a7cf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,7 +3,7 @@ SUBDIRS = help po
 
 DISTCHECK_CONFIGURE_FLAGS = --disable-scrollkeeper
 
-AM_CPPFLAGS = \
+common_cppflags = \
 	-I$(top_builddir) \
 	-I$(top_builddir)/vinagre \
 	-I$(top_srcdir)/vinagre/view \
@@ -20,11 +20,19 @@ AM_CPPFLAGS = \
 	$(WARN_FLAGS) \
 	$(DISABLE_DEPRECATED_FLAGS)
 
+AM_CPPFLAGS = \
+	$(common_cppflags) \
+	-include config.h
+
+AM_VALAFLAGS = \
+	--vapidir vinagre/vapi \
+	--pkg config \
+	--pkg gtk+-3.0
+
 bin_PROGRAMS = vinagre/vinagre
 
 vinagre_vinagre_SOURCES = \
 	vinagre/vinagre-main.c \
-	vinagre/vinagre-options.h \
 	vinagre/vinagre-options.c
 
 vinagre_vinagre_LDADD = \
@@ -41,7 +49,11 @@ noinst_vinagreh_headers = \
 	vinagre/view/ovBox.h \
 	vinagre/vinagre-plugin-dialog.h \
 	vinagre/vinagre-window-private.h \
-	vinagre/pty_open.h
+	vinagre/pty_open.h \
+	vinagre/vinagre-options.h \
+	vinagre/vinagre-mdns.h \
+	vinagre/vinagre-tubes-manager.h \
+	vinagre/vinagre-tube-handler.h
 
 vinagreh_HEADERS = \
 	vinagre/vinagre-bookmarks-entry.h \
@@ -95,6 +107,7 @@ handwritten_sources = \
 	vinagre/vinagre-plugin-dialog.c \
 	vinagre/vinagre-prefs.c \
 	vinagre/vinagre-tab.c \
+	vinagre/vinagre-utils.vala \
 	vinagre/vinagre-util.c \
 	vinagre/vinagre-window.c \
 	vinagre/pty_open.c \
@@ -104,13 +117,10 @@ handwritten_sources = \
 	vinagre/vinagre-plugins-engine.c
 
 libvinagre_la_SOURCES = \
-	$(handwritten_sources) \
-	$(noinst_vinagreh_headers) \
-	$(vinagreh_HEADERS)
+	$(handwritten_sources)
 
 if VINAGRE_HAVE_AVAHI
 libvinagre_la_SOURCES += \
-	vinagre/vinagre-mdns.h \
 	vinagre/vinagre-mdns.c
 endif
 
@@ -122,9 +132,7 @@ libvinagre_la_LIBADD = $(VINAGRE_LIBS)
 if VINAGRE_HAVE_TELEPATHY_GLIB
 handwritten_sources += \
 	vinagre/vinagre-tubes-manager.c \
-	vinagre/vinagre-tubes-manager.h \
-	vinagre/vinagre-tube-handler.c \
-	vinagre/vinagre-tube-handler.h
+	vinagre/vinagre-tube-handler.c
 INTROSPECTION_GIR_INCLUDES += TelepathyGLib-0.12
 endif
 
@@ -136,7 +144,7 @@ if VINAGRE_HAVE_INTROSPECTION
 INTROSPECTION_GIRS = Vinagre-3.0.gir
 
 Vinagre-3.0.gir: libvinagre.la
-INTROSPECTION_SCANNER_ARGS = $(AM_CPPFLAGS) $(VINAGRE_CFLAGS) -I$(top_srcdir) --warn-all
+INTROSPECTION_SCANNER_ARGS = $(common_cppflags) $(VINAGRE_CFLAGS) -I$(top_srcdir) --warn-all
 Vinagre_3_0_gir_LIBS = libvinagre.la
 Vinagre_3_0_gir_FILES = $(vinagreh_HEADERS) $(filter-out pty_open.h vinagre-plugin-dialog.h, $(noinst_vinagreh_headers)) $(handwritten_sources)
 Vinagre_3_0_gir_INCLUDES = $(INTROSPECTION_GIR_INCLUDES)
@@ -155,16 +163,33 @@ endif
 
 plugindir = $(VINAGRE_PLUGINS_LIBS_DIR)
 
+noinst_plugin_headers = \
+	plugins/rdp/vinagre-rdp-plugin.h \
+	plugins/rdp/vinagre-rdp-connection.h \
+	plugins/rdp/vinagre-rdp-tab.h \
+	plugins/spice/vinagre-spice-plugin.h \
+	plugins/spice/vinagre-spice-connection.h \
+	plugins/spice/vinagre-spice-tab.h \
+	plugins/spice/vinagre-spice-tunnel.h \
+	plugins/ssh/vinagre-ssh-plugin.h \
+	plugins/ssh/vinagre-ssh-connection.h \
+	plugins/ssh/vinagre-ssh-tab.h \
+	plugins/reverse-vnc/if/ifaddrs.h \
+	plugins/reverse-vnc/vinagre-reverse-vnc-plugin.h \
+	plugins/reverse-vnc/vinagre-reverse-vnc-listener.h \
+	plugins/reverse-vnc/vinagre-reverse-vnc-listener-dialog.h \
+	plugins/vnc/vinagre-vnc-plugin.h \
+	plugins/vnc/vinagre-vnc-connection.h \
+	plugins/vnc/vinagre-vnc-tab.h \
+	plugins/vnc/vinagre-vnc-tunnel.h
+
 if VINAGRE_ENABLE_RDP
 rdp_plugin = librdp.la
 rdp_plugin_in = plugins/rdp/rdp.plugin.desktop.in
 
 librdp_la_SOURCES = \
-	plugins/rdp/vinagre-rdp-plugin.h \
 	plugins/rdp/vinagre-rdp-plugin.c \
-	plugins/rdp/vinagre-rdp-connection.h \
 	plugins/rdp/vinagre-rdp-connection.c \
-	plugins/rdp/vinagre-rdp-tab.h \
 	plugins/rdp/vinagre-rdp-tab.c
 
 librdp_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
@@ -181,13 +206,9 @@ libspice_la_CPPFLAGS = \
 	-I$(top_srcdir)/plugins/spice
 
 libspice_la_SOURCES = \
-	plugins/spice/vinagre-spice-plugin.h \
 	plugins/spice/vinagre-spice-plugin.c \
-	plugins/spice/vinagre-spice-connection.h \
 	plugins/spice/vinagre-spice-connection.c \
-	plugins/spice/vinagre-spice-tab.h \
 	plugins/spice/vinagre-spice-tab.c \
-	plugins/spice/vinagre-spice-tunnel.h \
 	plugins/spice/vinagre-spice-tunnel.c
 
 libspice_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
@@ -199,11 +220,8 @@ ssh_plugin = libssh.la
 ssh_plugin_in = plugins/ssh/ssh.plugin.desktop.in
 
 libssh_la_SOURCES = \
-	plugins/ssh/vinagre-ssh-plugin.h \
 	plugins/ssh/vinagre-ssh-plugin.c \
-	plugins/ssh/vinagre-ssh-connection.h \
 	plugins/ssh/vinagre-ssh-connection.c \
-	plugins/ssh/vinagre-ssh-tab.h \
 	plugins/ssh/vinagre-ssh-tab.c
 
 libssh_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
@@ -219,7 +237,6 @@ plugin_LTLIBRARIES = \
 
 if VINAGRE_HAVE_SELF_IFADDRS
 ifaddrs_sources = \
-	plugins/reverse-vnc/if/ifaddrs.h \
 	plugins/reverse-vnc/if/getifaddrs.c
 endif
 
@@ -229,11 +246,8 @@ libreversevnc_la_CPPFLAGS = \
 	-DVINAGRE_REVERSE_VNC_DATADIR=\"$(reversevncuidir)\"
 
 libreversevnc_la_SOURCES = \
-	plugins/reverse-vnc/vinagre-reverse-vnc-plugin.h \
 	plugins/reverse-vnc/vinagre-reverse-vnc-plugin.c \
-	plugins/reverse-vnc/vinagre-reverse-vnc-listener.h \
 	plugins/reverse-vnc/vinagre-reverse-vnc-listener.c \
-	plugins/reverse-vnc/vinagre-reverse-vnc-listener-dialog.h \
 	plugins/reverse-vnc/vinagre-reverse-vnc-listener-dialog.c \
 	$(ifaddrs_sources)
 
@@ -249,13 +263,9 @@ libvnc_la_CPPFLAGS = \
 	-I$(top_srcdir)
 
 libvnc_la_SOURCES = \
-	plugins/vnc/vinagre-vnc-plugin.h \
 	plugins/vnc/vinagre-vnc-plugin.c \
-	plugins/vnc/vinagre-vnc-connection.h \
 	plugins/vnc/vinagre-vnc-connection.c \
-	plugins/vnc/vinagre-vnc-tab.h \
 	plugins/vnc/vinagre-vnc-tab.c \
-	plugins/vnc/vinagre-vnc-tunnel.h \
 	plugins/vnc/vinagre-vnc-tunnel.c
 
 libvnc_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
@@ -387,6 +397,8 @@ dist-changelog:
 	else rm -f .ChangeLog.tmp; exit 1; fi
 
 dist_noinst_DATA = \
+	$(noinst_vinagreh_headers) \
+	$(noinst_plugin_headers) \
 	ChangeLog.pre-git \
 	data/vinagre.pc.in \
 	data/vinagre-mime.xml.in \
diff --git a/configure.ac b/configure.ac
index 2d97fa3..03cfa2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,6 +11,7 @@ AM_SILENT_RULES([yes])
 # Checks for programs.
 AC_PROG_CC
 AM_PROG_CC_C_O
+AM_PROG_VALAC([0.12.0])
 
 GNOME_COMPILE_WARNINGS([maximum])
 GNOME_MAINTAINER_MODE_DEFINES
diff --git a/plugins/rdp/vinagre-rdp-tab.c b/plugins/rdp/vinagre-rdp-tab.c
index 6ef3961..bd8b84b 100644
--- a/plugins/rdp/vinagre-rdp-tab.c
+++ b/plugins/rdp/vinagre-rdp-tab.c
@@ -121,7 +121,7 @@ delay_connect (GObject *object)
 		      &rdp_tab->priv->pid,
 		      &error))
     {
-      vinagre_utils_show_error (_("Error while executing rdesktop"),
+      vinagre_utils_show_error_dialog (_("Error while executing rdesktop"),
 				error ? error->message : _("Unknown error"),
 				GTK_WINDOW (vinagre_tab_get_window (tab)));
       vinagre_tab_remove_from_notebook (tab);
diff --git a/plugins/reverse-vnc/vinagre-reverse-vnc-listener.c b/plugins/reverse-vnc/vinagre-reverse-vnc-listener.c
index 8176e9c..f7ed9cc 100644
--- a/plugins/reverse-vnc/vinagre-reverse-vnc-listener.c
+++ b/plugins/reverse-vnc/vinagre-reverse-vnc-listener.c
@@ -209,7 +209,7 @@ vinagre_reverse_vnc_listener_start (VinagreReverseVncListener *listener)
     }
   if (port > 5600)
     {
-      vinagre_utils_show_error (_("Error activating reverse connections"),
+      vinagre_utils_show_error_dialog (_("Error activating reverse connections"),
 				_("The program could not find any available TCP ports starting at 5500. Is there any other running program consuming all your TCP ports?"),
 				GTK_WINDOW (listener->priv->window));
       g_object_unref (priv->service);
diff --git a/plugins/spice/vinagre-spice-tab.c b/plugins/spice/vinagre-spice-tab.c
index 570ce6c..bb45f33 100644
--- a/plugins/spice/vinagre-spice-tab.c
+++ b/plugins/spice/vinagre-spice-tab.c
@@ -249,7 +249,7 @@ open_spice (VinagreSpiceTab *spice_tab)
 	if (!vinagre_spice_tunnel_create (window, &host, &port_str, ssh_tunnel_host, &error))
 	  {
 	    success = FALSE;
-	    vinagre_utils_show_error (_("Error creating the SSH tunnel"),
+	    vinagre_utils_show_error_dialog (_("Error creating the SSH tunnel"),
 				      error ? error->message : _("Unknown reason"),
 				      window);
 	    goto out;
@@ -261,7 +261,7 @@ open_spice (VinagreSpiceTab *spice_tab)
     }
 
   if (!success)
-    vinagre_utils_show_error (_("Error connecting to host."),
+    vinagre_utils_show_error_dialog (_("Error connecting to host."),
 			      error ? error->message : _("Unknown reason"),
 			      window);
 
diff --git a/plugins/vnc/vinagre-vnc-tab.c b/plugins/vnc/vinagre-vnc-tab.c
index bf4522e..62ff9fb 100644
--- a/plugins/vnc/vinagre-vnc-tab.c
+++ b/plugins/vnc/vinagre-vnc-tab.c
@@ -293,7 +293,7 @@ open_vnc (VinagreVncTab *vnc_tab)
 	if (!vinagre_vnc_tunnel_create (window, &host, &port_str, ssh_tunnel_host, &error))
 	  {
 	    success = FALSE;
-	    vinagre_utils_show_error (_("Error creating the SSH tunnel"),
+	    vinagre_utils_show_error_dialog (_("Error creating the SSH tunnel"),
 				      error ? error->message : _("Unknown reason"),
 				      window);
 	    goto out;
@@ -304,7 +304,7 @@ open_vnc (VinagreVncTab *vnc_tab)
   if (success)
     gtk_widget_grab_focus (GTK_WIDGET (vnc));
   else
-    vinagre_utils_show_error (_("Error connecting to host."),
+    vinagre_utils_show_error_dialog (_("Error connecting to host."),
 			      error ? error->message : _("Unknown reason"),
 			      window);
 
@@ -353,7 +353,7 @@ vnc_auth_unsupported_cb (VncDisplay *vnc, guint auth_type, VinagreVncTab *vnc_ta
 		   emphasis,
 		   auth_type);
 
-  vinagre_utils_show_error (_("Authentication unsupported"),
+  vinagre_utils_show_error_dialog (_("Authentication unsupported"),
 			    message->str,
 			    GTK_WINDOW (vinagre_tab_get_window (tab)));
   g_string_free (message, TRUE);
@@ -521,7 +521,7 @@ vnc_authentication_cb (VncDisplay *vnc, GValueArray *credList, VinagreVncTab *vn
 	  else
 	    {
 	      vinagre_tab_remove_from_notebook (tab);
-	      vinagre_utils_show_error (_("Authentication error"),
+	      vinagre_utils_show_error_dialog (_("Authentication error"),
 					_("A username is required in order to access this remote desktop."),
 					window);
 	      goto out;
@@ -538,7 +538,7 @@ vnc_authentication_cb (VncDisplay *vnc, GValueArray *credList, VinagreVncTab *vn
 	  else
 	    {
 	      vinagre_tab_remove_from_notebook (tab);
-	      vinagre_utils_show_error (_("Authentication error"),
+	      vinagre_utils_show_error_dialog (_("Authentication error"),
 					_("A password is required in order to access this remote desktop."),
 					window);
 	      goto out;
@@ -910,7 +910,7 @@ vinagre_vnc_tab_set_scaling (VinagreVncTab *tab, gboolean active) {
   vnc_display_set_force_size (VNC_DISPLAY(tab->priv->vnc), !active);
   if (!vnc_display_set_scaling (VNC_DISPLAY (tab->priv->vnc), active))
     {
-      vinagre_utils_show_error (NULL, _("Scaling is not supported on this installation.\n\nRead the README file (shipped with Vinagre) in order to know how to enable this feature."),
+      vinagre_utils_show_error_dialog (NULL, _("Scaling is not supported on this installation.\n\nRead the README file (shipped with Vinagre) in order to know how to enable this feature."),
 				GTK_WINDOW (vinagre_tab_get_window (VINAGRE_TAB (tab))));
       return FALSE;
     }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e1d21e7..4bd9c21 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -48,5 +48,6 @@ vinagre/vinagre-ssh.c
 vinagre/vinagre-tab.c
 vinagre/vinagre-tube-handler.c
 vinagre/vinagre-ui.h
-vinagre/vinagre-utils.c
+vinagre/vinagre-util.c
+vinagre/vinagre-utils.vala
 vinagre/vinagre-window.c
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 708b5c5..7963552 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -4,3 +4,4 @@ data/vinagre-mime.xml.in
 data/vinagre.schemas.in
 plugins/dummy/dummy.vinagre-plugin.desktop.in
 plugins/dummy/vinagre-dummy-plugin.c
+vinagre/vinagre-utils.c
diff --git a/vinagre/vapi/config.vapi b/vinagre/vapi/config.vapi
new file mode 100644
index 0000000..eea4517
--- /dev/null
+++ b/vinagre/vapi/config.vapi
@@ -0,0 +1,7 @@
+[CCode (cprefix="", lower_case_cprefix = "", cheader_filename = "config.h")]
+namespace Vinagre.Config
+{
+    public const string PACKAGE_TARNAME;
+    public const string PACKAGE_URL;
+    public const string PACKAGE_VERSION;
+} // namespace Vinagre.Config
diff --git a/vinagre/vinagre-bookmarks-migration.c b/vinagre/vinagre-bookmarks-migration.c
index a6650ba..518454c 100644
--- a/vinagre/vinagre-bookmarks-migration.c
+++ b/vinagre/vinagre-bookmarks-migration.c
@@ -212,7 +212,7 @@ vinagre_bookmarks_migration_migrate (const gchar *filename)
   GSList   *entries;
 
   error  = NULL;
-  if (!vinagre_utils_create_dir (filename, &error))
+  if (!vinagre_utils_create_dir_for_file (filename, &error))
     {
       g_warning (_("Error while migrating bookmarks: %s"), error?error->message:_("Failed to create the directory"));
       if (error)
diff --git a/vinagre/vinagre-bookmarks-ui.c b/vinagre/vinagre-bookmarks-ui.c
index 31e66b8..8e3fa3d 100644
--- a/vinagre/vinagre-bookmarks-ui.c
+++ b/vinagre/vinagre-bookmarks-ui.c
@@ -75,7 +75,7 @@ show_dialog_folder (VinagreBookmarks      *book,
       name = gtk_entry_get_text (GTK_ENTRY (name_entry));
       if (strlen (name) < 1)
         {
-	  vinagre_utils_show_error (NULL, _("Invalid name for this folder"), GTK_WINDOW (dialog));
+	  vinagre_utils_show_error_dialog (NULL, _("Invalid name for this folder"), GTK_WINDOW (dialog));
 	  gtk_widget_grab_focus (name_entry);
 	  continue;
 	}
@@ -86,7 +86,7 @@ show_dialog_folder (VinagreBookmarks      *book,
       if (existing_entry && existing_entry != entry)
 	{
 	  gchar *str = g_strdup_printf (_("The name \"%s\" is already used in this folder. Please use a different name."), name);
-	  vinagre_utils_show_error (_("Invalid name for this item"),
+	  vinagre_utils_show_error_dialog (_("Invalid name for this item"),
 				    str,
 				    GTK_WINDOW (dialog));
 	  g_free (str);
@@ -187,7 +187,7 @@ show_dialog_conn (VinagreBookmarks      *book,
       name = gtk_entry_get_text (GTK_ENTRY (name_entry));
       if (strlen (name) < 1)
         {
-	  vinagre_utils_show_error (NULL, _("Invalid name for this item"), GTK_WINDOW (dialog));
+	  vinagre_utils_show_error_dialog (NULL, _("Invalid name for this item"), GTK_WINDOW (dialog));
 	  gtk_widget_grab_focus (name_entry);
 	  continue;
 	}
@@ -198,7 +198,7 @@ show_dialog_conn (VinagreBookmarks      *book,
       if (existing_entry && existing_entry != entry)
 	{
 	  str = g_strdup_printf (_("The name \"%s\" is already used in this folder. Please use a different name."), name);
-	  vinagre_utils_show_error (_("Invalid name for this item"),
+	  vinagre_utils_show_error_dialog (_("Invalid name for this item"),
 				    str,
 				    GTK_WINDOW (dialog));
 	  g_free (str);
@@ -213,7 +213,7 @@ show_dialog_conn (VinagreBookmarks      *book,
 					    &port,
 					    &error_str))
         {
-	  vinagre_utils_show_error (NULL, error_str, GTK_WINDOW (dialog));
+	  vinagre_utils_show_error_dialog (NULL, error_str, GTK_WINDOW (dialog));
 	  g_free (error_str);
 	  gtk_widget_grab_focus (host_entry);
 	  continue;
diff --git a/vinagre/vinagre-commands.c b/vinagre/vinagre-commands.c
index d01556f..8c4cd82 100644
--- a/vinagre/vinagre-commands.c
+++ b/vinagre/vinagre-commands.c
@@ -151,7 +151,7 @@ vinagre_cmd_remote_open (GtkAction     *action,
 
   if (i == 0)
     {
-      vinagre_utils_show_error (_("There are no supported files"),
+      vinagre_utils_show_error_dialog (_("There are no supported files"),
 				_("None of the active plugins support this action. Activate some plugins and try again."),
 				GTK_WINDOW (window));
       goto finalize;
@@ -350,14 +350,14 @@ void
 vinagre_cmd_help_contents (GtkAction     *action,
 			   VinagreWindow *window)
 {
-  vinagre_utils_help_contents (GTK_WINDOW (window), NULL);
+  vinagre_utils_show_help (GTK_WINDOW (window), NULL);
 }
 
 void
 vinagre_cmd_help_about (GtkAction     *action,
 			VinagreWindow *window)
 {
-  vinagre_utils_help_about (GTK_WINDOW (window));
+  vinagre_utils_show_help_about (GTK_WINDOW (window));
 }
 
 /* vim: set ts=8: */
diff --git a/vinagre/vinagre-connect.c b/vinagre/vinagre-connect.c
index 20e2d65..5b1f413 100644
--- a/vinagre/vinagre-connect.c
+++ b/vinagre/vinagre-connect.c
@@ -489,7 +489,7 @@ vinagre_connect (VinagreWindow *window)
 	}
       else
 	{
-	  vinagre_utils_show_error (NULL, error_msg ? error_msg : _("Unknown error"),
+	  vinagre_utils_show_error_dialog (NULL, error_msg ? error_msg : _("Unknown error"),
 				    GTK_WINDOW (window));
 	}
 
diff --git a/vinagre/vinagre-fav.c b/vinagre/vinagre-fav.c
index 33aaea3..06b7664 100644
--- a/vinagre/vinagre-fav.c
+++ b/vinagre/vinagre-fav.c
@@ -758,7 +758,7 @@ drag_data_received_handl (GtkWidget *widget,
       info = g_strsplit (_sdata, "||", 2);
       if (g_strv_length (info) != 2)
 	{
-	  vinagre_utils_show_error (_("Invalid operation"),
+	  vinagre_utils_show_error_dialog (_("Invalid operation"),
 				    _("Data received from drag&drop operation is invalid."),
 				    GTK_WINDOW (fav->priv->window));
 	  return;
@@ -768,7 +768,7 @@ drag_data_received_handl (GtkWidget *widget,
       if (!conn)
 	{
 	  g_strfreev (info);
-	  vinagre_utils_show_error (NULL,
+	  vinagre_utils_show_error_dialog (NULL,
 				    error ? error : _("Unknown error"),
 				    GTK_WINDOW (fav->priv->window));
 	  g_free (error);
diff --git a/vinagre/vinagre-notebook.c b/vinagre/vinagre-notebook.c
index 883f2c8..00026f8 100644
--- a/vinagre/vinagre-notebook.c
+++ b/vinagre/vinagre-notebook.c
@@ -461,7 +461,7 @@ tab_disconnected_cb (VinagreTab *tab, VinagreNotebook *nb)
   /* Translators: %s is a host name or IP address. */
   message = g_strdup_printf (_("Connection to host %s was closed."),
 			     emphasis);
-  vinagre_utils_show_error (_("Connection closed"), message, GTK_WINDOW (nb->priv->window));
+  vinagre_utils_show_error_dialog (_("Connection closed"), message, GTK_WINDOW (nb->priv->window));
   g_free (message);
   g_free (name);
   g_free (emphasis);
@@ -486,7 +486,7 @@ tab_auth_failed_cb (VinagreTab *tab, const gchar *msg, VinagreNotebook *nb)
   	g_string_append_printf (message, " (%s)", msg);
   g_string_append_c (message, '.');
 
-  vinagre_utils_show_error (_("Authentication failed"), message->str, GTK_WINDOW (nb->priv->window));
+  vinagre_utils_show_error_dialog (_("Authentication failed"), message->str, GTK_WINDOW (nb->priv->window));
   g_string_free (message, TRUE);
   g_free (name);
   g_free (emphasis);
diff --git a/vinagre/vinagre-prefs.c b/vinagre/vinagre-prefs.c
index 5366e8a..45b8d01 100644
--- a/vinagre/vinagre-prefs.c
+++ b/vinagre/vinagre-prefs.c
@@ -212,7 +212,7 @@ vinagre_prefs_dialog_response (GtkDialog *d, gint response_id, VinagrePrefsDialo
 {
   if (response_id > 0)
     {
-      vinagre_utils_help_contents (dialog->parent, "preferences");
+      vinagre_utils_show_help (dialog->parent, "preferences");
       return;
     }
 
diff --git a/vinagre/vinagre-ssh.c b/vinagre/vinagre-ssh.c
index 7a95985..ce6d2f7 100644
--- a/vinagre/vinagre-ssh.c
+++ b/vinagre/vinagre-ssh.c
@@ -559,7 +559,7 @@ handle_login (GtkWindow *parent,
                 &keyring_item_id);
 
       if (result != GNOME_KEYRING_RESULT_OK)
-        vinagre_utils_show_error (_("Error saving the credentials on the keyring."),
+        vinagre_utils_show_error_dialog (_("Error saving the credentials on the keyring."),
 				  gnome_keyring_result_to_message (result),
 				  parent);
 
diff --git a/vinagre/vinagre-tab.c b/vinagre/vinagre-tab.c
index 4836b35..3f0feb4 100644
--- a/vinagre/vinagre-tab.c
+++ b/vinagre/vinagre-tab.c
@@ -533,7 +533,7 @@ vinagre_tab_add_recent_used (VinagreTab *tab)
   data->is_private = FALSE;
 
   if (!gtk_recent_manager_add_full (manager, uri, data))
-    vinagre_utils_show_error (NULL,
+    vinagre_utils_show_error_dialog (NULL,
 			      _("Error saving recent connection."),
 			      GTK_WINDOW (tab->priv->window));
 
@@ -803,7 +803,7 @@ vinagre_tab_save_credentials_in_keyring (VinagreTab *tab)
                 &tab->priv->keyring_item_id);
 
   if (result != GNOME_KEYRING_RESULT_OK)
-    vinagre_utils_show_error (_("Error saving the credentials on the keyring."),
+    vinagre_utils_show_error_dialog (_("Error saving the credentials on the keyring."),
 			      gnome_keyring_result_to_message (result),
 			      GTK_WINDOW (tab->priv->window));
 
@@ -891,7 +891,7 @@ vinagre_tab_take_screenshot (VinagreTab *tab)
   pix = VINAGRE_TAB_GET_CLASS (tab)->impl_get_screenshot (tab);
   if (!pix)
     {
-      vinagre_utils_show_error (NULL,
+      vinagre_utils_show_error_dialog (NULL,
 				_("Could not get a screenshot of the connection."),
 				GTK_WINDOW (tab->priv->window));
       return;
@@ -960,7 +960,7 @@ vinagre_tab_take_screenshot (VinagreTab *tab)
 
       if (!gdk_pixbuf_save (pix, filename, name, &error, NULL))
 	{
-	  vinagre_utils_show_error (_("Error saving screenshot"),
+	  vinagre_utils_show_error_dialog (_("Error saving screenshot"),
 				    error->message,
 				    GTK_WINDOW (tab->priv->window));
 	  g_error_free (error);
diff --git a/vinagre/vinagre-tube-handler.c b/vinagre/vinagre-tube-handler.c
index dbeb048..ec32c93 100644
--- a/vinagre/vinagre-tube-handler.c
+++ b/vinagre/vinagre-tube-handler.c
@@ -230,7 +230,7 @@ vinagre_tube_handler_call_service_cb (TpProxy *channel,
       error_msg = g_strdup_printf
           (_("Impossible to get service property: %s"),
           error->message);
-      vinagre_utils_show_error (NULL, (const gchar *) error_msg,
+      vinagre_utils_show_error_dialog (NULL, (const gchar *) error_msg,
           GTK_WINDOW (priv->window));
       g_free (priv->hostname);
       g_free (error_msg);
@@ -253,7 +253,7 @@ vinagre_tube_handler_call_service_cb (TpProxy *channel,
     {
       error_msg = g_strdup_printf
           (_("The protocol %s is not supported."), service_s);
-      vinagre_utils_show_error (NULL, (const gchar *) error_msg,
+      vinagre_utils_show_error_dialog (NULL, (const gchar *) error_msg,
           GTK_WINDOW (priv->window));
       g_free (priv->hostname);
       g_free (error_msg);
@@ -286,7 +286,7 @@ vinagre_tube_handler_call_service_cb (TpProxy *channel,
     {
       error_msg = g_strdup_printf
           (_("Impossible to create the connection: %s"), error_conn_msg);
-      vinagre_utils_show_error (NULL, (const gchar *) error_msg,
+      vinagre_utils_show_error_dialog (NULL, (const gchar *) error_msg,
           GTK_WINDOW (priv->window));
       g_signal_handler_disconnect (G_OBJECT (priv->channel),
         priv->signal_invalidated_id);
@@ -326,7 +326,7 @@ vinagre_tube_handler_accept_stream_tube_cb (TpChannel *channel,
       error_msg = g_strdup_printf
           (_("Impossible to accept the stream tube: %s"),
           error->message);
-      vinagre_utils_show_error (NULL, (const gchar *) error_msg,
+      vinagre_utils_show_error_dialog (NULL, (const gchar *) error_msg,
           GTK_WINDOW (priv->window));
       g_free (error_msg);
       g_signal_emit (G_OBJECT (self), signals[DISCONNECTED], 0);
@@ -464,7 +464,7 @@ vinagre_tube_handler_factory_handle_cb (TpConnection *connection,
       /* Translators: this is an error message when we fail to get the name of an empathy/telepathy buddy. %s will be replaced by the actual error message. */
       error_msg = g_strdup_printf (_("Impossible to get the contact name: %s"),
                                    error->message);
-      vinagre_utils_show_error (NULL,
+      vinagre_utils_show_error_dialog (NULL,
                                 (const gchar *) error_msg,
                                 GTK_WINDOW (priv->window));
       g_free (error_msg);
@@ -501,7 +501,7 @@ vinagre_tube_handler_factory_handle_cb (TpConnection *connection,
               error_msg = g_strdup_printf
                   (_("Impossible to get the avatar: %s"),
                   error_failed->message);
-              vinagre_utils_show_error (NULL, (const gchar *) error_msg,
+              vinagre_utils_show_error_dialog (NULL, (const gchar *) error_msg,
                   GTK_WINDOW (priv->window));
               g_free (error_msg);
               image = gtk_image_new_from_icon_name ("stock_person",
diff --git a/vinagre/vinagre-util.c b/vinagre/vinagre-util.c
index a5d854b..e998b40 100644
--- a/vinagre/vinagre-util.c
+++ b/vinagre/vinagre-util.c
@@ -27,37 +27,6 @@
 #endif
 
 void
-vinagre_utils_show_error (const gchar *title, const gchar *message, GtkWindow *parent)
-{
-  GtkWidget *d;
-  gchar     *t;
-
-  if (title)
-    t = g_strdup (title);
-  else
-    t = g_strdup (_("An error has occurred:"));
-
-  d = gtk_message_dialog_new (parent,
-			      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-			      GTK_MESSAGE_ERROR,
-			      GTK_BUTTONS_CLOSE,
-			      "%s",
-			      t);
-  g_free (t);
-
-  if (message)
-    gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (d),
-					      "%s",
-					      message);
-
-  g_signal_connect_swapped (d,
-			    "response",
-			    G_CALLBACK (gtk_widget_destroy),
-			    d);
-  gtk_widget_show_all (GTK_WIDGET(d));
-}
-
-void
 vinagre_utils_show_many_errors (const gchar *title, GSList *items, GtkWindow *parent)
 {
   GString *msg;
@@ -68,7 +37,7 @@ vinagre_utils_show_many_errors (const gchar *title, GSList *items, GtkWindow *pa
   for (l = items; l; l = l->next)
     g_string_append_printf (msg, "%s\n", (gchar *)l->data);
 
-  vinagre_utils_show_error (title, msg->str, parent);
+  vinagre_utils_show_error_dialog (title, msg->str, parent);
   g_string_free (msg, TRUE);
 }
 
@@ -123,7 +92,7 @@ vinagre_utils_get_builder (const gchar *filename)
 
       g_string_append_printf (str, "\n\n%s\n\n", error->message);
       g_string_append (str, _("Please check your installation."));
-      vinagre_utils_show_error (_("Error loading UI file"), str->str, NULL);
+      vinagre_utils_show_error_dialog (_("Error loading UI file"), str->str, NULL);
       g_error_free (error);
       g_string_free (str, TRUE);
       g_object_unref (xml);
@@ -176,88 +145,6 @@ vinagre_utils_escape_underscores (const gchar* text,
 	return g_string_free (str, FALSE);
 }
 
-void
-vinagre_utils_help_contents (GtkWindow *window, const gchar *section)
-{
-  GError    *error;
-  GdkScreen *screen;
-  gchar     *uri;
-
-  screen = GTK_IS_WINDOW (window) ? gtk_window_get_screen (GTK_WINDOW (window)) : NULL;
-  error = NULL;
-  if (section)
-    uri = g_strdup_printf ("ghelp:vinagre?%s", section);
-  else
-    uri = g_strdup ("ghelp:vinagre");
-
-  gtk_show_uri (screen,
-		uri,
-		GDK_CURRENT_TIME,
-		&error);
-
-  g_free (uri);
-  if (error != NULL)
-    {
-      vinagre_utils_show_error (NULL, error->message, GTK_IS_WINDOW (window) ? window : NULL);
-      g_error_free (error);
-    }
-}
-
-void
-vinagre_utils_help_about (GtkWindow *window)
-{
-  static const gchar * const authors[] = {
-	"David King <amigadave amigadave com>",
-	"Jonh Wendell <jwendell gnome org>",
-	NULL
-  };
-
-  static const gchar * const artists[] = {
-	"Vinicius Depizzol <vdepizzol gmail com>",
-	NULL
-  };
-
-  static const gchar copyright[] = \
-    "Copyright \xc2\xa9 2007-2011 Jonh Wendell\n" \
-    "Copyright \xc2\xa9 2011 David King";
-
-  static const gchar comments[] = \
-	N_("Vinagre is a remote desktop viewer for the GNOME Desktop");
-
-  static const char *license[] = {
-	N_("Vinagre 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 of the License, or "
-	   "(at your option) any later version."),
-	N_("Vinagre 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."),
-	N_("You should have received a copy of the GNU General Public License "
-	   "along with this program. If not, see <http://www.gnu.org/licenses/>.")
-  };
-
-  gchar *license_trans;
-
-  license_trans = g_strjoin ("\n\n", _(license[0]), _(license[1]),
-				     _(license[2]), NULL);
-
-  gtk_show_about_dialog (GTK_IS_WINDOW (window)?window:NULL,
-			 "authors", authors,
-			 "artists", artists,
-			 "comments", _(comments),
-			 "copyright", copyright,
-			 "license", license_trans,
-			 "wrap-license", TRUE,
-			 "logo-icon-name", "vinagre",
-			 "translator-credits", _("translator-credits"),
-			 "version", PACKAGE_VERSION,
-			 "website", PACKAGE_URL,
-			 "website-label", _("Vinagre Website"),
-			 NULL);
-  g_free (license_trans);
-}
-
 gboolean
 vinagre_utils_parse_boolean (const gchar* value)
 {
@@ -444,25 +331,4 @@ vinagre_utils_ask_credential (GtkWindow *parent,
   return result == -5;
 }
 
-gboolean
-vinagre_utils_create_dir (const gchar *filename, GError **error)
-{
-  GFile    *file, *parent;
-  gboolean result;
-  gchar    *path;
-
-  file   = g_file_new_for_path (filename);
-  parent = g_file_get_parent (file);
-  path   = g_file_get_path (parent);
-  result = TRUE;
-
-  if (!g_file_test (path, G_FILE_TEST_EXISTS))
-    result = g_file_make_directory_with_parents (parent, NULL, error);
-
-  g_object_unref (file);
-  g_object_unref (parent);
-  g_free (path);
-  return result;
-}
-
 /* vim: set ts=8: */
diff --git a/vinagre/vinagre-util.h b/vinagre/vinagre-util.h
index 6fceb72..6c72b9b 100644
--- a/vinagre/vinagre-util.h
+++ b/vinagre/vinagre-util.h
@@ -31,10 +31,6 @@
 
 enum { VINAGRE_ALL_WORKSPACES = 0xffffffff };
 
-void		vinagre_utils_show_error		(const gchar *title,
-							 const gchar *message,
-							 GtkWindow *parent);
-
 void		vinagre_utils_show_many_errors		(const gchar *title,
 							 GSList *items,
 							 GtkWindow *parent);
@@ -46,9 +42,6 @@ GtkBuilder	*vinagre_utils_get_builder		(const gchar *filename);
 gchar		*vinagre_utils_escape_underscores	(const gchar *text,
 							 gssize      length);
 
-void		vinagre_utils_help_contents		(GtkWindow *window, const gchar *section);
-void		vinagre_utils_help_about		(GtkWindow *window);
-
 gboolean	vinagre_utils_parse_boolean		(const gchar* value);
 
 gboolean	vinagre_utils_ask_question		(GtkWindow  *parent,
@@ -66,7 +59,5 @@ gboolean	vinagre_utils_ask_credential		(GtkWindow *parent,
 							 gchar **password,
 							 gboolean *save_in_keyring);
 
-gboolean	vinagre_utils_create_dir		(const gchar *filename, GError **error);
-
 #endif  /* __VINAGRE_UTILS_H__  */
 /* vim: set ts=8: */
diff --git a/vinagre/vinagre-utils.vala b/vinagre/vinagre-utils.vala
new file mode 100644
index 0000000..852a0f8
--- /dev/null
+++ b/vinagre/vinagre-utils.vala
@@ -0,0 +1,94 @@
+/*  Vinagre - GNOME Remote Desktop viewer
+ *
+ *  Copyright (C) 2011  David King <amigadave amigadave com>
+ *
+ *  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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Vinagre.Utils {
+
+static void show_error_dialog(string? title, string? message, Gtk.Window parent)
+{
+    if(title != null)
+        title = _("An error occurred");
+
+    var dialog = new Gtk.MessageDialog(parent,
+        Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
+        Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "%s", title);
+
+    if(message != null)
+        dialog.format_secondary_markup("%s", message);
+
+    dialog.response.connect((d, response) => { dialog.destroy(); });
+    dialog.show_all();
+}
+
+static bool create_dir_for_file(string filename) throws GLib.Error
+{
+    var file = GLib.File.new_for_path(filename);
+    var parent = file.get_parent();
+    var parent_path = parent.get_path();
+
+    if(!GLib.FileUtils.test(parent_path, GLib.FileTest.EXISTS))
+        return parent.make_directory_with_parents();
+    else
+        return true;
+}
+
+static void show_help(Gtk.Window window, string? page)
+{
+    string uri;
+    if(page != null)
+        uri = "ghelp:" + Vinagre.Config.PACKAGE_TARNAME + "?" + page;
+    else
+        uri = "ghelp:" + Vinagre.Config.PACKAGE_TARNAME;
+
+    try
+    {
+        Gtk.show_uri(window.get_screen(), uri, Gdk.CURRENT_TIME);
+    }
+    catch(GLib.Error error)
+    {
+        show_error_dialog(_("Error showing help"), error.message, window);
+    }
+}
+
+// TODO: Move this into the GtkBuilder file.
+static void show_help_about(Gtk.Window parent)
+{
+    string[] authors = { "David King <amigadave amigadave com>",
+        "Jonh Wendell <jwendell gnome org>" };
+
+    string[] artists = { "Vinicius Depizzol <vdepizzol gmail com>" };
+
+    const string copyright = "Copyright \xc2\xa9 2007-2011 Jonh Wendell\nCopyright \xc2\xa9 2011 David King";
+
+    const string comments = N_("Vinagre is a remote desktop viewer for the GNOME Desktop");
+
+    const string license = """Vinagre 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 of the License, or (at your option) any later version.
+
+Vinagre 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, see <http://www.gnu.org/licenses/>.""";
+
+    Gtk.show_about_dialog(parent, "authors", authors, "artists", artists,
+        "comments", _(comments), "copyright", copyright, "license", license,
+        "wrap-license", true, "logo-icon-name", Vinagre.Config.PACKAGE_TARNAME,
+        "translator-credits", _("translator-credits"),
+        "version", Vinagre.Config.PACKAGE_VERSION,
+        "website", Vinagre.Config.PACKAGE_URL,
+        "website-label", _("Vinagre Website"));
+}
+
+} // namespace Vinagre.Utils
diff --git a/vinagre/vinagre-window.c b/vinagre/vinagre-window.c
index 0a4d1e0..0264a7a 100644
--- a/vinagre/vinagre-window.c
+++ b/vinagre/vinagre-window.c
@@ -285,7 +285,7 @@ activate_recent_cb (GtkRecentChooser *action, VinagreWindow *window)
       g_object_unref (conn);
     }
   else
-    vinagre_utils_show_error (NULL, error ? error : _("Unknown error"), GTK_WINDOW (window));
+    vinagre_utils_show_error_dialog (NULL, error ? error : _("Unknown error"), GTK_WINDOW (window));
 
   g_free (error);
   g_free (uri);
@@ -740,7 +740,7 @@ vinagre_window_check_first_run (VinagreWindow *window)
       gtk_dialog_run (GTK_DIALOG (dialog));
       gtk_widget_destroy (dialog);
 
-      if (vinagre_utils_create_dir (filename, &error))
+      if (vinagre_utils_create_dir_for_file (filename, &error))
         {
           int fd = g_creat (filename, 0644);
           if (fd < 0)



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