changeset 3:2fa34d6272c6

Add menu item to launch the preferences application
author Guido Berhoerster <guido+pui@berhoerster.name>
date Wed, 13 Jun 2018 23:25:09 +0200
parents 7172a0db97af
children 3d72ca76538d
files pui-application.c pui-menu.ui
diffstat 2 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pui-application.c	Wed Jun 13 20:06:00 2018 +0200
+++ b/pui-application.c	Wed Jun 13 23:25:09 2018 +0200
@@ -21,6 +21,7 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include <gio/gdesktopappinfo.h>
 #include <glib/gi18n.h>
 #include <libappindicator/app-indicator.h>
 #include <stdlib.h>
@@ -78,12 +79,15 @@
 
 static void	pui_application_show_about_dialog(GSimpleAction *, GVariant *,
     gpointer);
+static void	pui_application_open_preferences(GSimpleAction *, GVariant *,
+    gpointer);
 static void	pui_application_quit(GSimpleAction *, GVariant *, gpointer);
 static void	pui_application_install_updates(GSimpleAction *, GVariant *,
     gpointer);
 
 static const GActionEntry pui_application_actions[] = {
     { "about", pui_application_show_about_dialog },
+    { "preferences", pui_application_open_preferences },
     { "quit", pui_application_quit },
     { "install-updates", pui_application_install_updates }
 };
@@ -130,6 +134,28 @@
 }
 
 static void
+pui_application_open_preferences(GSimpleAction *simple, GVariant *parameter,
+    gpointer user_data)
+{
+	GDesktopAppInfo	*prefs_app_info;
+	GError		*error = NULL;
+
+	prefs_app_info = g_desktop_app_info_new("org.guido-berhoerster.code."
+	    "package-update-indicator.preferences.desktop");
+	if (prefs_app_info == NULL) {
+		g_warning("desktop file \"org.guido-berhoerster.code."
+		    "package-update-indicator.preferences.desktop\" not found");
+		return;
+	}
+
+	if (!g_app_info_launch(G_APP_INFO(prefs_app_info), NULL, NULL,
+	    &error)) {
+		g_warning("failed to launch preferences: %s", error->message);
+		g_error_free(error);
+	}
+}
+
+static void
 pui_application_quit(GSimpleAction *simple, GVariant *parameter,
     gpointer user_data)
 {
--- a/pui-menu.ui	Wed Jun 13 20:06:00 2018 +0200
+++ b/pui-menu.ui	Wed Jun 13 23:25:09 2018 +0200
@@ -18,6 +18,15 @@
       <object class="GtkMenuItem">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="action_name">app.preferences</property>
+        <property name="label" translatable="yes">_Preferences…</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <property name="action_name">app.about</property>
         <property name="label" translatable="yes">_About…</property>
         <property name="use_underline">True</property>