[gnome-software/wip/rancell/ubuntu-3-20-4: 3/51] Add a convenience function to check if an app is installed



commit da4ebacdf858029df5332c1f248950495f3a3a42
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Thu Aug 11 00:48:49 2016 +0200

    Add a convenience function to check if an app is installed
    
    This will avoid having to check three app states all the time.
    
    Signed-off-by: Richard Hughes <richard hughsie com>

 src/gs-app.c |   22 ++++++++++++++++++++++
 src/gs-app.h |    1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 4eb89d8..db4d960 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -1959,6 +1959,28 @@ gs_app_set_install_date (GsApp *app, guint64 install_date)
 }
 
 /**
+ * gs_app_is_installed:
+ * @app: a #GsApp
+ *
+ * Gets whether the app is installed or not.
+ *
+ * Returns: %TRUE if the app is installed, %FALSE otherwise.
+ **/
+gboolean
+gs_app_is_installed (GsApp *app)
+{
+       AsAppState state;
+
+       g_return_val_if_fail (GS_IS_APP (app), FALSE);
+
+       state = gs_app_get_state (app);
+
+       return (state == AS_APP_STATE_INSTALLED) ||
+              (state == AS_APP_STATE_UPDATABLE) ||
+              (state == AS_APP_STATE_UPDATABLE_LIVE);
+}
+
+/**
  * gs_app_get_categories:
  */
 GPtrArray *
diff --git a/src/gs-app.h b/src/gs-app.h
index d09dc1d..b8f9c35 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -246,6 +246,7 @@ GError              *gs_app_get_last_error          (GsApp          *app);
 void            gs_app_set_last_error          (GsApp          *app,
                                                 GError         *error);
 
+gboolean        gs_app_is_installed            (GsApp          *app);
 G_END_DECLS
 
 #endif /* __GS_APP_H */


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