[gnome-panel] menu: add gp_menu_launch_app_info



commit 8171e20707c60f340be36cbf297e385ee4c38e95
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Jan 22 18:09:20 2018 +0200

    menu: add gp_menu_launch_app_info

 modules/menu/Makefile.am     |    2 +
 modules/menu/gp-menu-utils.c |   68 ++++++++++++++++++++++++++++++++++++++++++
 modules/menu/gp-menu-utils.h |   29 ++++++++++++++++++
 modules/menu/gp-menu.c       |   43 +-------------------------
 po/POTFILES.in               |    2 +-
 5 files changed, 102 insertions(+), 42 deletions(-)
---
diff --git a/modules/menu/Makefile.am b/modules/menu/Makefile.am
index d4daabf..c5822cd 100644
--- a/modules/menu/Makefile.am
+++ b/modules/menu/Makefile.am
@@ -27,6 +27,8 @@ menu_la_SOURCES = \
        gp-menu-bar.c \
        gp-menu-bar.h \
        gp-menu-module.c \
+       gp-menu-utils.c \
+       gp-menu-utils.h \
        gp-menu.c \
        gp-menu.h \
        gp-user-menu-applet.c \
diff --git a/modules/menu/gp-menu-utils.c b/modules/menu/gp-menu-utils.c
new file mode 100644
index 0000000..2395976
--- /dev/null
+++ b/modules/menu/gp-menu-utils.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2018 Alberts Muktupāvels
+ *
+ * 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 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/>.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
+
+#include "gp-menu-utils.h"
+
+static void
+pid_cb (GDesktopAppInfo *info,
+        GPid             pid,
+        gpointer         user_data)
+{
+  g_child_watch_add (pid, (GChildWatchFunc) g_spawn_close_pid, NULL);
+}
+
+void
+gp_menu_launch_app_info (GDesktopAppInfo *app_info)
+{
+  GSpawnFlags flags;
+  GError *error;
+  gboolean ret;
+
+  flags = G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD;
+  error = NULL;
+
+  ret = g_desktop_app_info_launch_uris_as_manager (app_info, NULL, NULL,
+                                                   flags, NULL, NULL,
+                                                   pid_cb, NULL,
+                                                   &error);
+
+  if (ret == FALSE)
+    {
+      const gchar *display_name;
+      GtkWidget *dialog;
+
+      display_name = g_app_info_get_display_name (G_APP_INFO (app_info));
+      dialog = gtk_message_dialog_new (NULL, 0,
+                                       GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+                                       _("Could not launch '%s'"),
+                                       display_name);
+
+      if (error != NULL)
+        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                                  "%s", error->message);
+
+      g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+      gtk_window_present (GTK_WINDOW (dialog));
+    }
+
+  g_clear_error (&error);
+}
diff --git a/modules/menu/gp-menu-utils.h b/modules/menu/gp-menu-utils.h
new file mode 100644
index 0000000..4c612bd
--- /dev/null
+++ b/modules/menu/gp-menu-utils.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2018 Alberts Muktupāvels
+ *
+ * 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 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/>.
+ */
+
+#ifndef GP_MENU_UTILS_H
+#define GP_MENU_UTILS_H
+
+#include <gio/gdesktopappinfo.h>
+
+G_BEGIN_DECLS
+
+void gp_menu_launch_app_info (GDesktopAppInfo *app_info);
+
+G_END_DECLS
+
+#endif
diff --git a/modules/menu/gp-menu.c b/modules/menu/gp-menu.c
index c8702b0..6677170 100644
--- a/modules/menu/gp-menu.c
+++ b/modules/menu/gp-menu.c
@@ -17,11 +17,11 @@
 
 #include "config.h"
 
-#include <glib/gi18n-lib.h>
 #include <gio/gdesktopappinfo.h>
 #include <gmenu-tree.h>
 #include <libgnome-panel/gp-image-menu-item.h>
 
+#include "gp-menu-utils.h"
 #include "gp-menu.h"
 
 struct _GpMenu
@@ -55,49 +55,10 @@ static void directory_to_menu_items (GMenuTreeDirectory *directory,
                                      GpMenu             *menu);
 
 static void
-pid_cb (GDesktopAppInfo *info,
-        GPid             pid,
-        gpointer         user_data)
-{
-  g_child_watch_add (pid, (GChildWatchFunc) g_spawn_close_pid, NULL);
-}
-
-static void
 activate_cb (GtkWidget       *item,
              GDesktopAppInfo *info)
 {
-  GSpawnFlags flags;
-  GError *error;
-  gboolean ret;
-
-  flags = G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD;
-  error = NULL;
-
-  ret = g_desktop_app_info_launch_uris_as_manager (info, NULL, NULL,
-                                                   flags, NULL, NULL,
-                                                   pid_cb, NULL,
-                                                   &error);
-
-  if (ret == FALSE)
-    {
-      const gchar *display_name;
-      GtkWidget *dialog;
-
-      display_name = g_app_info_get_display_name (G_APP_INFO (info));
-      dialog = gtk_message_dialog_new (NULL, 0,
-                                       GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
-                                       _("Could not launch '%s'"),
-                                       display_name);
-
-      if (error != NULL)
-        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                  "%s", error->message);
-
-      g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
-      gtk_window_present (GTK_WINDOW (dialog));
-    }
-
-  g_clear_error (&error);
+  gp_menu_launch_app_info (info);
 }
 
 static void
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f5f063c..35a7f6c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -61,7 +61,7 @@ modules/fish/fish-menu.ui
 modules/fish/fish.ui
 modules/menu/gp-menu-bar-applet.c
 modules/menu/gp-menu-module.c
-modules/menu/gp-menu.c
+modules/menu/gp-menu-utils.c
 modules/notification-area/na-applet.c
 modules/notification-area/na-module.c
 modules/notification-area/na-tray-manager.c


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