[gnome-software] Add an app menu



commit 77ae6ec3b4ee3a7e5d0f8f9f7209e3ec96f6e46f
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 23 16:24:38 2013 -0400

    Add an app menu
    
    For now, we just have About and Quit, more will come later.

 configure.ac                     |    2 +-
 src/Makefile.am                  |    3 +-
 src/app-menu.ui                  |   18 ++++++++
 src/gnome-software.gresource.xml |    3 +-
 src/gs-main.c                    |   80 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 103 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4318efe..496581c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
 # Copyright (C) 2010-2012 Richard Hughes <richard hughsie com>
 AC_PREREQ(2.63)
 
-AC_INIT([gnome-software],[3.5.1],[http://bugzilla.gnome.org/enter_bug.cgi?product=gnome-software])
+AC_INIT([gnome-software],[0.1],[http://bugzilla.gnome.org/enter_bug.cgi?product=gnome-software])
 AC_CONFIG_SRCDIR(src)
 AM_INIT_AUTOMAKE([1.11 no-dist-gzip dist-xz tar-ustar])
 AC_CONFIG_HEADERS([config.h])
diff --git a/src/Makefile.am b/src/Makefile.am
index 8ef2c91..9398aaf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,7 +21,8 @@ desktop_in_files =                                    \
 desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 
 UI_FILES =                                             \
-       gnome-software.ui
+       gnome-software.ui                               \
+       app-menu.ui
 
 bin_PROGRAMS =                                         \
        gnome-software
diff --git a/src/app-menu.ui b/src/app-menu.ui
new file mode 100644
index 0000000..7011906
--- /dev/null
+++ b/src/app-menu.ui
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <menu id="appmenu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_About</attribute>
+        <attribute name="action">app.about</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Quit</attribute>
+        <attribute name="action">app.quit</attribute>
+        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
+
diff --git a/src/gnome-software.gresource.xml b/src/gnome-software.gresource.xml
index 1ac9a1d..7c14b5b 100644
--- a/src/gnome-software.gresource.xml
+++ b/src/gnome-software.gresource.xml
@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
  <gresource prefix="/org/gnome/software">
-  <file compressed="true">gnome-software.ui</file>
+  <file preprocess="xml-stripblanks">gnome-software.ui</file>
+  <file preprocess="xml-stripblanks">app-menu.ui</file>
   <file>gtk-style.css</file>
  </gresource>
 </gresources>
diff --git a/src/gs-main.c b/src/gs-main.c
index a95a3d8..630af2b 100644
--- a/src/gs-main.c
+++ b/src/gs-main.c
@@ -361,6 +361,74 @@ gs_main_app_widget_button_clicked_cb (GsAppWidget *app_widget, GsMainPrivate *pr
 }
 #endif
 
+static void
+about_activated (GSimpleAction *action,
+                 GVariant      *parameter,
+                 gpointer       app)
+{
+        const gchar *authors[] = {
+                "Richard Hughes",
+                "Matthias Clasen",
+                NULL
+        };
+        const gchar *designers[] = {
+                "William Jon McCann",
+                "Allan Day",
+                "Ryan Lerch",
+                NULL
+        };
+        GtkIconTheme *icon_theme;
+        GdkPixbuf *logo;
+        GtkWidget *dialog;
+        GList *windows;
+        GtkWindow *parent = NULL;
+
+        windows = gtk_application_get_windows (GTK_APPLICATION (app));
+        if (windows)
+                parent = windows->data;
+
+        icon_theme = gtk_icon_theme_get_default ();
+        logo = gtk_icon_theme_load_icon (icon_theme, "system-software-install", 256, 0, NULL);
+
+        dialog = gtk_about_dialog_new ();
+
+        if (parent) {
+                gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+                gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+                gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
+        }
+
+        gtk_window_set_title (GTK_WINDOW (dialog), _("About GNOME Software"));
+        gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG (dialog), _("GNOME Software"));
+        gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (dialog), VERSION);
+        gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG (dialog), _("A nice way to manage the software on 
your system."));
+        gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG (dialog), logo);
+        gtk_about_dialog_set_license_type (GTK_ABOUT_DIALOG (dialog), GTK_LICENSE_GPL_2_0);
+        gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (dialog), authors);
+        gtk_about_dialog_add_credit_section (GTK_ABOUT_DIALOG (dialog), _("Design by"), designers);
+        gtk_about_dialog_set_translator_credits (GTK_ABOUT_DIALOG (dialog), _("translator-credits"));
+
+        g_signal_connect (dialog, "response",
+                          G_CALLBACK (gtk_widget_destroy), NULL);
+
+        gtk_window_present (GTK_WINDOW (dialog));
+
+        g_object_unref (logo);
+}
+
+static void
+quit_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       app)
+{
+        g_application_quit (G_APPLICATION (app));
+}
+
+static GActionEntry actions[] = {
+        { "about", about_activated, NULL, NULL, NULL },
+        { "quit", quit_activated, NULL, NULL, NULL }
+};
+
 /**
  * gs_main_startup_cb:
  **/
@@ -371,6 +439,17 @@ gs_main_startup_cb (GApplication *application, GsMainPrivate *priv)
        GError *error = NULL;
        gboolean ret;
        GtkWindow *window;
+        GtkBuilder *builder;
+        GMenuModel *app_menu;
+
+        /* set up the app menu */
+        g_action_map_add_action_entries (G_ACTION_MAP (application),
+                                         actions, G_N_ELEMENTS (actions),
+                                         application);
+        builder = gtk_builder_new_from_resource ("/org/gnome/software/app-menu.ui");
+        app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
+        gtk_application_set_app_menu (GTK_APPLICATION (application), app_menu);
+        g_object_unref (builder);
 
        /* get CSS */
        if (priv->provider == NULL) {
@@ -421,6 +500,7 @@ gs_main_activate_cb (GApplication *application, GsMainPrivate *priv)
        gs_shell_activate (priv->shell);
 }
 
+
 /**
  * main:
  **/


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