[gnome-software/wip/ubuntu-master: 102/107] Construct the "Software Sources" menu item dynamically



commit 0671f2db0648e5ad4b8ee970d55eb58db9c229af
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 264443e..79c4483 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -769,9 +769,30 @@ gs_application_setup_search_provider (GsApplication *app)
 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]