[empathy] Factor out empathy_launch_program()



commit 55c0b12101a314d838aa0ba5c6a6d741063c540f
Author: Emilio Pozuelo Monfort <emilio pozuelo collabora co uk>
Date:   Wed Aug 3 11:27:00 2011 +0100

    Factor out empathy_launch_program()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=655884

 libempathy-gtk/empathy-ui-utils.c |   52 +++++++++++++++++++++++
 libempathy-gtk/empathy-ui-utils.h |    4 ++
 src/empathy-accounts-dialog.c     |   54 ++++--------------------
 src/empathy-call-window.c         |   83 +------------------------------------
 src/empathy-main-window.c         |   37 +----------------
 5 files changed, 67 insertions(+), 163 deletions(-)
---
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 322f836..8ad7dfb 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -2114,3 +2114,55 @@ empathy_create_dtmf_dialpad (GObject *self,
 
   return box;
 }
+
+void
+empathy_launch_program (const gchar *dir,
+    const gchar *name,
+    const gchar *args)
+{
+  GdkDisplay *display;
+  GError *error = NULL;
+  gchar *path, *cmd;
+  GAppInfo *app_info;
+  GdkAppLaunchContext *context = NULL;
+
+  /* Try to run from source directory if possible */
+  path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
+      name, NULL);
+
+  if (!g_file_test (path, G_FILE_TEST_EXISTS))
+    {
+      g_free (path);
+      path = g_build_filename (dir, name, NULL);
+    }
+
+  if (args != NULL)
+    cmd = g_strconcat (path, " ", args, NULL);
+  else
+    cmd = g_strdup (path);
+
+  app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
+  if (app_info == NULL)
+    {
+      DEBUG ("Failed to create app info: %s", error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  display = gdk_display_get_default ();
+  context = gdk_display_get_app_launch_context (display);
+
+  if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
+      &error))
+    {
+      g_warning ("Failed to launch %s: %s", name, error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+out:
+  tp_clear_object (&app_info);
+  tp_clear_object (&context);
+  g_free (path);
+  g_free (cmd);
+}
diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h
index 1bfaf24..b65206b 100644
--- a/libempathy-gtk/empathy-ui-utils.h
+++ b/libempathy-gtk/empathy-ui-utils.h
@@ -159,6 +159,10 @@ gboolean empathy_individual_match_string (
     const gchar *text,
     GPtrArray *words);
 
+void empathy_launch_program (const gchar *dir,
+    const gchar *name,
+    const gchar *args);
+
 G_END_DECLS
 
 #endif /*  __EMPATHY_UI_UTILS_H__ */
diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c
index 75b7481..0eeec82 100644
--- a/src/empathy-accounts-dialog.c
+++ b/src/empathy-accounts-dialog.c
@@ -2517,68 +2517,30 @@ empathy_accounts_dialog_show_application (GdkScreen *screen,
     gboolean if_needed,
     gboolean hidden)
 {
-  GError *error = NULL;
-  GdkDisplay *display;
-  GString *cmd;
-  gchar *path;
-  GAppInfo *app_info;
-  GdkAppLaunchContext *context = NULL;
+  GString *args;
 
-  g_return_if_fail (GDK_IS_SCREEN (screen));
   g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
 
-  /* Try to run from source directory if possible */
-  path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
-      "empathy-accounts", NULL);
-
-  if (!g_file_test (path, G_FILE_TEST_EXISTS))
-    {
-      g_free (path);
-      path = g_build_filename (BIN_DIR, "empathy-accounts", NULL);
-    }
-
-  cmd = g_string_new (path);
-  g_free (path);
+  args = g_string_new (NULL);
 
   if (selected_account != NULL)
-    {
-      g_string_append_printf (cmd, " --select-account=%s",
-          tp_account_get_path_suffix (selected_account));
-    }
+    g_string_append_printf (args, " --select-account=%s",
+        tp_account_get_path_suffix (selected_account));
 
   if (if_needed)
-    g_string_append_printf (cmd, " --if-needed");
+    g_string_append_printf (args, " --if-needed");
 
   if (hidden)
-    g_string_append_printf (cmd, " --hidden");
+    g_string_append_printf (args, " --hidden");
 
   DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
     if_needed, hidden,
     selected_account == NULL ? "<none selected>" :
       tp_proxy_get_object_path (TP_PROXY (selected_account)));
 
-  app_info = g_app_info_create_from_commandline (cmd->str, NULL, 0, &error);
-  if (app_info == NULL)
-    {
-      DEBUG ("Failed to create app info: %s", error->message);
-      g_error_free (error);
-      goto out;
-    }
-
-  display = gdk_screen_get_display (screen);
-  context = gdk_display_get_app_launch_context (display);
-
-  if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
-        &error))
-    {
-      g_warning ("Failed to open accounts dialog: %s", error->message);
-      g_error_free (error);
-    }
+  empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
 
-out:
-  tp_clear_object (&app_info);
-  tp_clear_object (&context);
-  g_string_free (cmd, TRUE);
+  g_string_free (args, TRUE);
 }
 
 gboolean
diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c
index b3272bd..212431f 100644
--- a/src/empathy-call-window.c
+++ b/src/empathy-call-window.c
@@ -734,48 +734,7 @@ static void
 empathy_call_window_settings_cb (GtkAction *action,
     EmpathyCallWindow *self)
 {
-  GdkDisplay *display;
-  GError *error = NULL;
-  gchar *path, *cmd;
-  GAppInfo *app_info;
-  GdkAppLaunchContext *context = NULL;
-
-  /* Try to run from source directory if possible */
-  path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
-      "empathy", NULL);
-
-  if (!g_file_test (path, G_FILE_TEST_EXISTS))
-    {
-      g_free (path);
-      path = g_build_filename (BIN_DIR, "empathy", NULL);
-    }
-
-  cmd = g_strconcat (path, " -p", NULL);
-
-  app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
-  if (app_info == NULL)
-    {
-      DEBUG ("Failed to create app info: %s", error->message);
-      g_error_free (error);
-      goto out;
-    }
-
-  display = gdk_display_get_default ();
-  context = gdk_display_get_app_launch_context (display);
-
-  if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
-      &error))
-    {
-      g_warning ("Failed to open debug window: %s", error->message);
-      g_error_free (error);
-      goto out;
-    }
-
-out:
-  tp_clear_object (&app_info);
-  tp_clear_object (&context);
-  g_free (path);
-  g_free (cmd);
+  empathy_launch_program (BIN_DIR, "empathy", "-p");
 }
 
 static void
@@ -789,45 +748,7 @@ static void
 empathy_call_window_debug_cb (GtkAction *action,
     EmpathyCallWindow *self)
 {
-  GdkDisplay *display;
-  GError *error = NULL;
-  gchar *path;
-  GAppInfo *app_info;
-  GdkAppLaunchContext *context = NULL;
-
-  /* Try to run from source directory if possible */
-  path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
-      "empathy-debugger", NULL);
-
-  if (!g_file_test (path, G_FILE_TEST_EXISTS))
-    {
-      g_free (path);
-      path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
-    }
-
-  app_info = g_app_info_create_from_commandline (path, NULL, 0, &error);
-  if (app_info == NULL)
-    {
-      DEBUG ("Failed to create app info: %s", error->message);
-      g_error_free (error);
-      goto out;
-    }
-
-  display = gdk_display_get_default ();
-  context = gdk_display_get_app_launch_context (display);
-
-  if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
-      &error))
-    {
-      g_warning ("Failed to open debug window: %s", error->message);
-      g_error_free (error);
-      goto out;
-    }
-
-out:
-  tp_clear_object (&app_info);
-  tp_clear_object (&context);
-  g_free (path);
+  empathy_launch_program (BIN_DIR, "empathy-debugger", NULL);
 }
 
 static void
diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c
index 4aa720a..cbe44d6 100644
--- a/src/empathy-main-window.c
+++ b/src/empathy-main-window.c
@@ -1909,42 +1909,7 @@ static void
 main_window_help_debug_cb (GtkAction         *action,
 			   EmpathyMainWindow *window)
 {
-	GdkDisplay *display;
-	GError *error = NULL;
-	gchar *path;
-	GAppInfo *app_info;
-	GdkAppLaunchContext *context = NULL;
-
-	/* Try to run from source directory if possible */
-	path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
-			"empathy-debugger", NULL);
-
-	if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
-		g_free (path);
-		path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
-	}
-
-	app_info = g_app_info_create_from_commandline (path, NULL, 0, &error);
-	if (app_info == NULL) {
-		DEBUG ("Failed to create app info: %s", error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	display = gdk_display_get_default ();
-	context = gdk_display_get_app_launch_context (display);
-
-	if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
-		&error)) {
-		g_warning ("Failed to open debug window: %s", error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-out:
-	tp_clear_object (&app_info);
-	tp_clear_object (&context);
-	g_free (path);
+	empathy_launch_program (BIN_DIR, "empathy-debugger", NULL);
 }
 
 static void



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