[gnome-software/wip/ubuntu-3-22: 10/24] Construct the "Software Sources" menu item dynamically



commit b5b3c8e41af4f9454ec3ca9519f603303f39051a
Author: Iain Lane <iain orangesquash org uk>
Date:   Mon Jan 23 16:22:09 2017 +0000

    Construct the "Software Sources" menu item dynamically
    
    If we have software-properties-gtk, we'll launch that. In that case,
    call the menu item "Software & Updates", since that more accurately
    reflects what it does.

 src/gs-application.c |   21 +++++++++++++++++++++
 src/gs-menus.ui      |    8 +-------
 2 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 7f0ae24..8d170b8 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -760,9 +760,30 @@ gs_application_settings_changed_cb (GApplication *self,
 static void
 gs_application_startup (GApplication *application)
 {
+       g_autofree gchar *software_properties = NULL;
+       const gchar *label = NULL;
+       g_autoptr(GMenu) menu = NULL;
+       g_autoptr(GMenu) new = NULL;
+
        GSettings *settings;
        G_APPLICATION_CLASS (gs_application_parent_class)->startup (application);
 
+       /* This follows the behaviour in src/gs-shell.c; when we have s-p-gtk,
+        * we will launch it. It provides a UI to manage update behaviour too.
+        */
+       software_properties = g_find_program_in_path ("software-properties-gtk");
+
+       if (!software_properties)
+               label = _("Software Sources");
+       else
+               label = _("Software & Updates");
+
+       menu =  gtk_application_get_menu_by_id (GTK_APPLICATION (application),
+                                               "app-menu");
+       new = g_menu_new ();
+       g_menu_append (new, label, "app.sources");
+       g_menu_prepend_section (menu, NULL, G_MENU_MODEL (new));
+
        g_action_map_add_action_entries (G_ACTION_MAP (application),
                                         actions, G_N_ELEMENTS (actions),
                                         application);
diff --git a/src/gs-menus.ui b/src/gs-menus.ui
index af7f63b..59e0b1e 100644
--- a/src/gs-menus.ui
+++ b/src/gs-menus.ui
@@ -2,13 +2,7 @@
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
   <menu id="app-menu">
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">_Software Sources</attribute>
-        <attribute name="action">app.sources</attribute>
-        <attribute name="hidden-when">action-disabled</attribute>
-      </item>
-    </section>
+    <!-- "Software Sources" entry inserted here in code, see src/gs-application.c -->
     <section>
       <item>
         <attribute name="label" translatable="yes">_About</attribute>


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