projects/package-update-indicator

changeset 3:2fa34d6272c6

Add menu item to launch the preferences application
author Guido Berhoerster <guido+pui@berhoerster.name>
date Wed Jun 13 23:25:09 2018 +0200 (24 months ago)
parents 7172a0db97af
children 3d72ca76538d
files pui-application.c pui-menu.ui
line diff
     1.1 --- a/pui-application.c	Wed Jun 13 20:06:00 2018 +0200
     1.2 +++ b/pui-application.c	Wed Jun 13 23:25:09 2018 +0200
     1.3 @@ -21,6 +21,7 @@
     1.4   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     1.5   */
     1.6  
     1.7 +#include <gio/gdesktopappinfo.h>
     1.8  #include <glib/gi18n.h>
     1.9  #include <libappindicator/app-indicator.h>
    1.10  #include <stdlib.h>
    1.11 @@ -78,12 +79,15 @@
    1.12  
    1.13  static void	pui_application_show_about_dialog(GSimpleAction *, GVariant *,
    1.14      gpointer);
    1.15 +static void	pui_application_open_preferences(GSimpleAction *, GVariant *,
    1.16 +    gpointer);
    1.17  static void	pui_application_quit(GSimpleAction *, GVariant *, gpointer);
    1.18  static void	pui_application_install_updates(GSimpleAction *, GVariant *,
    1.19      gpointer);
    1.20  
    1.21  static const GActionEntry pui_application_actions[] = {
    1.22      { "about", pui_application_show_about_dialog },
    1.23 +    { "preferences", pui_application_open_preferences },
    1.24      { "quit", pui_application_quit },
    1.25      { "install-updates", pui_application_install_updates }
    1.26  };
    1.27 @@ -130,6 +134,28 @@
    1.28  }
    1.29  
    1.30  static void
    1.31 +pui_application_open_preferences(GSimpleAction *simple, GVariant *parameter,
    1.32 +    gpointer user_data)
    1.33 +{
    1.34 +	GDesktopAppInfo	*prefs_app_info;
    1.35 +	GError		*error = NULL;
    1.36 +
    1.37 +	prefs_app_info = g_desktop_app_info_new("org.guido-berhoerster.code."
    1.38 +	    "package-update-indicator.preferences.desktop");
    1.39 +	if (prefs_app_info == NULL) {
    1.40 +		g_warning("desktop file \"org.guido-berhoerster.code."
    1.41 +		    "package-update-indicator.preferences.desktop\" not found");
    1.42 +		return;
    1.43 +	}
    1.44 +
    1.45 +	if (!g_app_info_launch(G_APP_INFO(prefs_app_info), NULL, NULL,
    1.46 +	    &error)) {
    1.47 +		g_warning("failed to launch preferences: %s", error->message);
    1.48 +		g_error_free(error);
    1.49 +	}
    1.50 +}
    1.51 +
    1.52 +static void
    1.53  pui_application_quit(GSimpleAction *simple, GVariant *parameter,
    1.54      gpointer user_data)
    1.55  {
     2.1 --- a/pui-menu.ui	Wed Jun 13 20:06:00 2018 +0200
     2.2 +++ b/pui-menu.ui	Wed Jun 13 23:25:09 2018 +0200
     2.3 @@ -18,6 +18,15 @@
     2.4        <object class="GtkMenuItem">
     2.5          <property name="visible">True</property>
     2.6          <property name="can_focus">False</property>
     2.7 +        <property name="action_name">app.preferences</property>
     2.8 +        <property name="label" translatable="yes">_Preferences…</property>
     2.9 +        <property name="use_underline">True</property>
    2.10 +      </object>
    2.11 +    </child>
    2.12 +    <child>
    2.13 +      <object class="GtkMenuItem">
    2.14 +        <property name="visible">True</property>
    2.15 +        <property name="can_focus">False</property>
    2.16          <property name="action_name">app.about</property>
    2.17          <property name="label" translatable="yes">_About…</property>
    2.18          <property name="use_underline">True</property>