[gnome-software] shell: Use new GsApp API to handle local files



commit 5fcf4144a16cea8aac3cf80c4a76b54e0b2dba80
Author: Kalev Lember <klember redhat com>
Date:   Mon Jan 16 11:15:58 2017 +0100

    shell: Use new GsApp API to handle local files
    
    Instead of abusing the (kind == GENERIC) test, use the new
    gs_app_set/get_local_file() API. Apps without appdata, such as extra
    packages that we show through the org.freedesktop.PackageKit session
    service can also legitimately be of the GENERIC kind and as such we
    can't use it to test if it's a local file.

 src/gs-application.c   |    4 +++-
 src/gs-shell-details.c |    5 +----
 src/gs-shell-details.h |    4 ++--
 src/gs-shell.c         |   14 ++++++--------
 src/gs-shell.h         |    4 ++--
 5 files changed, 14 insertions(+), 17 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 7d167c0..e07d08b 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -602,11 +602,13 @@ filename_activated (GSimpleAction *action,
 {
        GsApplication *app = GS_APPLICATION (data);
        const gchar *filename;
+       g_autoptr(GFile) file = NULL;
 
        gs_application_initialize_ui (app);
 
        g_variant_get (parameter, "(&s)", &filename);
-       gs_shell_show_filename (app->shell, filename);
+       file = g_file_new_for_path (filename);
+       gs_shell_show_local_file (app->shell, file);
 }
 
 static void
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 9e67376..e827a7a 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -1495,12 +1495,9 @@ gs_shell_details_file_to_app_cb (GObject *source,
 }
 
 void
-gs_shell_details_set_filename (GsShellDetails *self, const gchar *filename)
+gs_shell_details_set_local_file (GsShellDetails *self, GFile *file)
 {
-       g_autoptr(GFile) file = NULL;
-
        gs_shell_details_set_state (self, GS_SHELL_DETAILS_STATE_LOADING);
-       file = g_file_new_for_path (filename);
        gs_plugin_loader_file_to_app_async (self->plugin_loader,
                                            file,
                                            GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON |
diff --git a/src/gs-shell-details.h b/src/gs-shell-details.h
index 5b2bb77..45da1d5 100644
--- a/src/gs-shell-details.h
+++ b/src/gs-shell-details.h
@@ -39,8 +39,8 @@ G_DECLARE_FINAL_TYPE (GsShellDetails, gs_shell_details, GS, SHELL_DETAILS, GsPag
 GsShellDetails *gs_shell_details_new           (void);
 void            gs_shell_details_set_app       (GsShellDetails         *self,
                                                 GsApp                  *app);
-void            gs_shell_details_set_filename  (GsShellDetails         *self,
-                                                const gchar            *filename);
+void            gs_shell_details_set_local_file(GsShellDetails         *self,
+                                                GFile                  *file);
 GsApp          *gs_shell_details_get_app       (GsShellDetails         *self);
 void            gs_shell_details_setup         (GsShellDetails         *self,
                                                 GsShell                *shell,
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 39abb3d..9cd17e3 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -340,12 +340,11 @@ gs_shell_change_mode (GsShell *shell,
                break;
        case GS_SHELL_MODE_DETAILS:
                app = GS_APP (data);
-               if (gs_app_get_kind (app) != AS_APP_KIND_GENERIC ||
-                   gs_app_get_source_default (app) == NULL) {
-                       gs_shell_details_set_app (priv->shell_details, data);
+               if (gs_app_get_local_file (app) != NULL) {
+                       gs_shell_details_set_local_file (priv->shell_details,
+                                                        gs_app_get_local_file (app));
                } else {
-                       const gchar *tmp = gs_app_get_source_default (app);
-                       gs_shell_details_set_filename (priv->shell_details, tmp);
+                       gs_shell_details_set_app (priv->shell_details, data);
                }
                new_page = GS_PAGE (priv->shell_details);
                break;
@@ -1853,12 +1852,11 @@ gs_shell_show_search (GsShell *shell, const gchar *search)
 }
 
 void
-gs_shell_show_filename (GsShell *shell, const gchar *filename)
+gs_shell_show_local_file (GsShell *shell, GFile *file)
 {
        g_autoptr(GsApp) app = gs_app_new (NULL);
        save_back_entry (shell);
-       gs_app_set_kind (app, AS_APP_KIND_GENERIC);
-       gs_app_add_source (app, filename);
+       gs_app_set_local_file (app, file);
        gs_shell_change_mode (shell, GS_SHELL_MODE_DETAILS,
                              (gpointer) app, TRUE);
        gs_shell_activate (shell);
diff --git a/src/gs-shell.h b/src/gs-shell.h
index 1341584..4a1ed8e 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -91,8 +91,8 @@ void           gs_shell_show_category         (GsShell        *shell,
                                                 GsCategory     *category);
 void            gs_shell_show_search           (GsShell        *shell,
                                                 const gchar    *search);
-void            gs_shell_show_filename         (GsShell        *shell,
-                                                const gchar    *filename);
+void            gs_shell_show_local_file       (GsShell        *shell,
+                                                GFile          *file);
 void            gs_shell_show_search_result    (GsShell        *shell,
                                                 const gchar    *id,
                                                 const gchar    *search);


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