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



commit aec5292c0b7c1a61d0fad5ec6bbe469da300c702
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 13210c9..7f0ae24 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -633,11 +633,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 49a3f5c..9e19204 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -1438,12 +1438,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 1de320a..a991c85 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -317,12 +317,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;
@@ -920,12 +919,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 374c1c0..629c631 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -78,8 +78,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]