[gnome-software/wip/rancell/paid] Use an app state instead of a flag for unpurchased apps
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/rancell/paid] Use an app state instead of a flag for unpurchased apps
- Date: Fri, 6 May 2016 04:08:58 +0000 (UTC)
commit 275d8795758323347c8885081acc9c3ba5519918
Author: Robert Ancell <robert ancell canonical com>
Date: Fri May 6 16:08:06 2016 +1200
Use an app state instead of a flag for unpurchased apps
configure.ac | 2 +-
src/gs-app-row.c | 16 +++++++++++-----
src/gs-app.c | 44 +++++++-------------------------------------
src/gs-app.h | 3 ---
src/gs-shell-details.c | 27 +++++++++++++++++----------
5 files changed, 36 insertions(+), 56 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 113b47d..32e7fd5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,7 +61,7 @@ dnl ---------------------------------------------------------------------------
dnl - Check library dependencies
dnl ---------------------------------------------------------------------------
PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.18.2 gio-unix-2.0 gtkspell3-3.0)
-PKG_CHECK_MODULES(APPSTREAM, appstream-glib >= 0.5.14)
+PKG_CHECK_MODULES(APPSTREAM, appstream-glib >= 0.5.15)
PKG_CHECK_MODULES(GDK_PIXBUF, gdk-pixbuf-2.0 >= 2.31.5)
PKG_CHECK_MODULES(JSON_GLIB, json-glib-1.0 >= 1.1.1)
PKG_CHECK_MODULES(SQLITE, sqlite3)
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index 9d5354f..53091df 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -278,21 +278,27 @@ gs_app_row_refresh (GsAppRow *app_row)
* that has been queued for installation */
gtk_label_set_label (GTK_LABEL (priv->label), _("Pending"));
break;
- case AS_APP_STATE_AVAILABLE:
- case AS_APP_STATE_AVAILABLE_LOCAL:
+ case AS_APP_STATE_PURCHASABLE:
gtk_widget_set_visible (priv->button, TRUE);
prices = gs_app_get_prices (priv->app);
- if (!gs_app_get_owned (priv->app) && prices->len > 0) {
+ if (prices->len > 0) {
GsPrice *price = g_ptr_array_index (prices, 0);
g_autofree gchar *text = NULL;
text = gs_price_to_string (price);
gtk_button_set_label (GTK_BUTTON (priv->button), text);
} else {
/* TRANSLATORS: this is a button next to the search results that
- * allows the application to be easily installed */
- gtk_button_set_label (GTK_BUTTON (priv->button), _("Install"));
+ * allows the application to be easily bought */
+ gtk_button_set_label (GTK_BUTTON (priv->button), _("Buy"));
}
break;
+ case AS_APP_STATE_AVAILABLE:
+ case AS_APP_STATE_AVAILABLE_LOCAL:
+ gtk_widget_set_visible (priv->button, TRUE);
+ /* TRANSLATORS: this is a button next to the search results that
+ * allows the application to be easily installed */
+ gtk_button_set_label (GTK_BUTTON (priv->button), _("Install"));
+ break;
case AS_APP_STATE_UPDATABLE_LIVE:
gtk_widget_set_visible (priv->button, TRUE);
if (priv->show_update) {
diff --git a/src/gs-app.c b/src/gs-app.c
index 40d1e96..8e7923a 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -87,7 +87,6 @@ struct _GsApp
gchar *management_plugin;
guint match_value;
GPtrArray *prices; /* of GsPrice */
- gboolean owned;
gint rating;
GArray *review_ratings;
GPtrArray *reviews; /* of GsReview */
@@ -120,7 +119,6 @@ enum {
PROP_VERSION,
PROP_SUMMARY,
PROP_DESCRIPTION,
- PROP_OWNED,
PROP_RATING,
PROP_KIND,
PROP_STATE,
@@ -511,6 +509,7 @@ gs_app_set_state_internal (GsApp *app, AsAppState state)
/* unknown has to go into one of the stable states */
if (state == AS_APP_STATE_INSTALLED ||
state == AS_APP_STATE_QUEUED_FOR_INSTALL ||
+ state == AS_APP_STATE_PURCHASABLE ||
state == AS_APP_STATE_AVAILABLE ||
state == AS_APP_STATE_AVAILABLE_LOCAL ||
state == AS_APP_STATE_UPDATABLE ||
@@ -530,6 +529,12 @@ gs_app_set_state_internal (GsApp *app, AsAppState state)
state == AS_APP_STATE_AVAILABLE)
state_change_ok = TRUE;
break;
+ case AS_APP_STATE_PURCHASABLE:
+ /* purchasable has to go into an available state */
+ if (state == AS_APP_STATE_UNKNOWN ||
+ state == AS_APP_STATE_AVAILABLE)
+ state_change_ok = TRUE;
+ break;
case AS_APP_STATE_AVAILABLE:
/* available has to go into an action state */
if (state == AS_APP_STATE_UNKNOWN ||
@@ -1782,27 +1787,6 @@ gs_app_add_price (GsApp *app, gdouble amount, const gchar *currency)
}
/**
- * gs_app_get_owned:
- */
-gboolean
-gs_app_get_owned (GsApp *app)
-{
- g_return_val_if_fail (GS_IS_APP (app), FALSE);
- return app->owned;
-}
-
-/**
- * gs_app_set_owned:
- */
-void
-gs_app_set_owned (GsApp *app, gboolean owned)
-{
- g_return_if_fail (GS_IS_APP (app));
- app->owned = owned;
- gs_app_queue_notify (app, "owned");
-}
-
-/**
* gs_app_get_rating:
*/
gint
@@ -2400,9 +2384,6 @@ gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *
case PROP_DESCRIPTION:
g_value_set_string (value, app->description);
break;
- case PROP_OWNED:
- g_value_set_boolean (value, app->owned);
- break;
case PROP_RATING:
g_value_set_int (value, app->rating);
break;
@@ -2457,9 +2438,6 @@ gs_app_set_property (GObject *object, guint prop_id, const GValue *value, GParam
GS_APP_QUALITY_UNKNOWN,
g_value_get_string (value));
break;
- case PROP_OWNED:
- gs_app_set_owned (app, g_value_get_boolean (value));
- break;
case PROP_RATING:
gs_app_set_rating (app, g_value_get_int (value));
break;
@@ -2602,14 +2580,6 @@ gs_app_class_init (GsAppClass *klass)
g_object_class_install_property (object_class, PROP_DESCRIPTION, pspec);
/**
- * GsApp:owned:
- */
- pspec = g_param_spec_boolean ("owned", NULL, NULL,
- FALSE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
- g_object_class_install_property (object_class, PROP_OWNED, pspec);
-
- /**
* GsApp:rating:
*/
pspec = g_param_spec_int ("rating", NULL, NULL,
diff --git a/src/gs-app.h b/src/gs-app.h
index cd40600..20c9836 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -200,9 +200,6 @@ GPtrArray *gs_app_get_prices (GsApp *app);
void gs_app_add_price (GsApp *app,
gdouble amount,
const gchar *currency);
-gboolean gs_app_get_owned (GsApp *app);
-void gs_app_set_owned (GsApp *app,
- gboolean owned);
gint gs_app_get_rating (GsApp *app);
void gs_app_set_rating (GsApp *app,
gint rating);
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 4a8b328..0aa9094 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -249,23 +249,31 @@ gs_shell_details_switch_to (GsPage *page, gboolean scroll_up)
/* install button */
switch (state) {
- case AS_APP_STATE_AVAILABLE:
- case AS_APP_STATE_AVAILABLE_LOCAL:
+ case AS_APP_STATE_PURCHASABLE:
gtk_widget_set_visible (self->button_install, TRUE);
gtk_widget_set_sensitive (self->button_install, TRUE);
gtk_style_context_add_class (gtk_widget_get_style_context (self->button_install),
"suggested-action");
- /* TRANSLATORS: button text in the header when an application
- * can be installed */
prices = gs_app_get_prices (self->app);
- if (!gs_app_get_owned (self->app) && prices->len > 0) {
+ if (prices->len > 0) {
GsPrice *price = g_ptr_array_index (prices, 0);
g_autofree gchar *text = NULL;
text = gs_price_to_string (price);
gtk_button_set_label (GTK_BUTTON (self->button_install), text);
} else {
- gtk_button_set_label (GTK_BUTTON (self->button_install), _("_Install"));
+ /* TRANSLATORS: button text in the header when an application
+ * can be purchased */
+ gtk_button_set_label (GTK_BUTTON (self->button_install), _("_Buy"));
}
break;
+ case AS_APP_STATE_AVAILABLE:
+ case AS_APP_STATE_AVAILABLE_LOCAL:
+ gtk_widget_set_visible (self->button_install, TRUE);
+ gtk_widget_set_sensitive (self->button_install, TRUE);
+ gtk_style_context_add_class (gtk_widget_get_style_context (self->button_install),
"suggested-action");
+ /* TRANSLATORS: button text in the header when an application
+ * can be installed */
+ gtk_button_set_label (GTK_BUTTON (self->button_install), _("_Install"));
+ break;
case AS_APP_STATE_QUEUED_FOR_INSTALL:
gtk_widget_set_visible (self->button_install, FALSE);
break;
@@ -370,6 +378,7 @@ gs_shell_details_switch_to (GsPage *page, gboolean scroll_up)
gtk_style_context_remove_class (gtk_widget_get_style_context (self->button_remove),
"destructive-action");
gtk_button_set_label (GTK_BUTTON (self->button_remove), _("_Cancel"));
break;
+ case AS_APP_STATE_PURCHASABLE:
case AS_APP_STATE_AVAILABLE_LOCAL:
case AS_APP_STATE_AVAILABLE:
case AS_APP_STATE_INSTALLING:
@@ -402,6 +411,7 @@ gs_shell_details_switch_to (GsPage *page, gboolean scroll_up)
switch (state) {
case AS_APP_STATE_UNKNOWN:
case AS_APP_STATE_INSTALLED:
+ case AS_APP_STATE_PURCHASABLE:
case AS_APP_STATE_AVAILABLE:
case AS_APP_STATE_QUEUED_FOR_INSTALL:
case AS_APP_STATE_UPDATABLE:
@@ -1316,9 +1326,6 @@ gs_shell_details_file_to_app_cb (GObject *source,
g_signal_connect_object (self->app, "notify::license",
G_CALLBACK (gs_shell_details_notify_state_changed_cb),
self, 0);
- g_signal_connect_object (self->app, "notify::owned",
- G_CALLBACK (gs_shell_details_notify_state_changed_cb),
- self, 0);
g_signal_connect_object (self->app, "notify::progress",
G_CALLBACK (gs_shell_details_progress_changed_cb),
self, 0);
@@ -1458,7 +1465,7 @@ gs_shell_details_app_install_button_cb (GtkWidget *widget, GsShellDetails *self)
GList *l;
g_autoptr(GList) addons = NULL;
- if (gs_app_get_prices (self->app)->len > 0 && !gs_app_get_owned (self->app)) {
+ if (gs_app_get_state (self->app) == AS_APP_STATE_PURCHASABLE) {
gs_page_purchase_app (GS_PAGE (self), self->app);
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]