[gnome-software/wip/rancell/paid] Start adding the concept of currency
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/rancell/paid] Start adding the concept of currency
- Date: Tue, 23 Feb 2016 01:55:25 +0000 (UTC)
commit 19fa9df7707a07b3f12401973e2aebadea9b09cf
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Feb 23 14:55:05 2016 +1300
Start adding the concept of currency
src/gs-app.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++
src/gs-app.h | 6 +++
src/gs-shell-details.c | 8 ++++-
src/gs-utils.c | 26 +++++++++++++++
src/gs-utils.h | 3 ++
5 files changed, 122 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 22026a4..e7ad648 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -82,6 +82,8 @@ struct _GsApp
gchar *update_details;
AsUrgencyKind update_urgency;
gchar *management_plugin;
+ guint price;
+ gchar *currency;
gint rating;
GArray *review_ratings;
GPtrArray *reviews; /* of GsReview */
@@ -112,6 +114,8 @@ enum {
PROP_VERSION,
PROP_SUMMARY,
PROP_DESCRIPTION,
+ PROP_PRICE,
+ PROP_CURRENCY,
PROP_RATING,
PROP_KIND,
PROP_STATE,
@@ -290,6 +294,11 @@ gs_app_to_string (GsApp *app)
g_string_append_printf (str, "\torigin:\t%s\n", app->origin);
if (app->origin_ui != NULL && app->origin_ui[0] != '\0')
g_string_append_printf (str, "\torigin-ui:\t%s\n", app->origin_ui);
+ if (app->price > 0) {
+ g_string_append_printf (str, "\tprice:\t%u\n", app->price);
+ if (app->currency != NULL)
+ g_string_append_printf (str, "\tcurrency:\t%s\n", app->currency);
+ }
if (app->rating != -1)
g_string_append_printf (str, "\trating:\t%i\n", app->rating);
if (app->review_ratings != NULL) {
@@ -1669,6 +1678,48 @@ gs_app_set_management_plugin (GsApp *app, const gchar *management_plugin)
}
/**
+ * gs_app_get_price:
+ */
+guint
+gs_app_get_price (GsApp *app)
+{
+ g_return_val_if_fail (GS_IS_APP (app), 0);
+ return app->price;
+}
+
+/**
+ * gs_app_set_price:
+ */
+void
+gs_app_set_price (GsApp *app, guint price)
+{
+ g_return_if_fail (GS_IS_APP (app));
+ app->price = price;
+ gs_app_queue_notify (app, "price");
+}
+
+/**
+ * gs_app_get_currency:
+ */
+const gchar *
+gs_app_get_currency (GsApp *app)
+{
+ g_return_val_if_fail (GS_IS_APP (app), NULL);
+ return app->currency;
+}
+
+/**
+ * gs_app_set_currency:
+ */
+void
+gs_app_set_currency (GsApp *app, const gchar *currency)
+{
+ g_return_if_fail (GS_IS_APP (app));
+ app->currency = currency;
+ gs_app_queue_notify (app, "currency");
+}
+
+/**
* gs_app_get_rating:
*/
gint
@@ -2216,6 +2267,12 @@ 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_PRICE:
+ g_value_set_uint (value, app->price);
+ break;
+ case PROP_CURRENCY:
+ g_value_set_string (value, app->currency);
+ break;
case PROP_RATING:
g_value_set_int (value, app->rating);
break;
@@ -2267,6 +2324,12 @@ 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_PRICE:
+ gs_app_set_price (app, g_value_get_uint (value));
+ break;
+ case PROP_CURRENCY:
+ gs_app_set_currency (app, g_value_get_string (value));
+ break;
case PROP_RATING:
gs_app_set_rating (app, g_value_get_int (value));
break;
@@ -2337,6 +2400,7 @@ gs_app_finalize (GObject *object)
g_free (app->update_version_ui);
g_free (app->update_details);
g_free (app->management_plugin);
+ g_free (app->currency);
g_hash_table_unref (app->metadata);
g_hash_table_unref (app->addons_hash);
g_hash_table_unref (app->related_hash);
@@ -2399,6 +2463,22 @@ gs_app_class_init (GsAppClass *klass)
g_object_class_install_property (object_class, PROP_DESCRIPTION, pspec);
/**
+ * GsApp:price:
+ */
+ pspec = g_param_spec_uint ("rating", NULL, NULL,
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+ g_object_class_install_property (object_class, PROP_RATING, pspec);
+
+ /**
+ * GsApp:currency:
+ */
+ pspec = g_param_spec_string ("currency", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+ g_object_class_install_property (object_class, PROP_RATING, pspec);
+
+ /**
* GsApp:rating:
*/
pspec = g_param_spec_int ("rating", NULL, NULL,
diff --git a/src/gs-app.h b/src/gs-app.h
index 97d9c9f..a0bf5a6 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -199,6 +199,12 @@ const gchar *gs_app_get_metadata_item (GsApp *app,
void gs_app_set_metadata (GsApp *app,
const gchar *key,
const gchar *value);
+guint gs_app_get_price (GsApp *app);
+void gs_app_set_price (GsApp *app,
+ guint price);
+const gchar *gs_app_get_currency (GsApp *app);
+void gs_app_set_currency (GsApp *app,
+ const gchar *currency);
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 22b6140..2a9141a 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -192,7 +192,13 @@ gs_shell_details_switch_to (GsShellDetails *self)
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"));
+ if (gs_app_get_price (self->app) > 0) {
+ g_autofree gchar *price = NULL;
+ price = gs_format_price (gs_app_get_currency (self->app), gs_app_get_price
(self->app));
+ gtk_button_set_label (GTK_BUTTON (self->button_install), price);
+ } else {
+ 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);
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 5709f9f..df5c6de 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -501,4 +501,30 @@ gs_utils_get_user_hash (GError **error)
return g_compute_checksum_for_string (G_CHECKSUM_SHA1, salted, -1);
}
+gchar *
+gs_format_price (const gchar *currency, guint price)
+{
+ if (strcmp (currency, "AUD") == 0) {
+ return g_strdup_printf (_("A$%u"), price);
+ } else if (strcmp (currency, "CAD") == 0) {
+ return g_strdup_printf (_("C$%u"), price);
+ } else if (strcmp (currency, "CNY") == 0) {
+ return g_strdup_printf (_("CN¥%u"), price);
+ } else if (strcmp (currency, "EUR") == 0) {
+ return g_strdup_printf (_("€%u"), price);
+ } else if (strcmp (currency, "GBP") == 0) {
+ return g_strdup_printf (_("£%u"), price);
+ } else if (strcmp (currency, "JPY") == 0) {
+ return g_strdup_printf (_("¥%u"), price);
+ } else if (strcmp (currency, "NZD") == 0) {
+ return g_strdup_printf (_("NZ$%u"), price);
+ } else if (strcmp (currency, "RUB") == 0) {
+ return g_strdup_printf (_("₽%u"), price);
+ } else if (strcmp (currency, "USD") == 0) {
+ return g_strdup_printf (_("US$%u"), price);
+ } else {
+ return g_strdup_printf (_("%s %u"), currency, price);
+ }
+}
+
/* vim: set noexpandtab: */
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 54df901..9d9bcef 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -64,6 +64,9 @@ gchar *gs_utils_get_cachedir (const gchar *kind,
GError **error);
gchar *gs_utils_get_user_hash (GError **error);
+gchar *gs_format_price (const gchar *currency,
+ guint price);
+
G_END_DECLS
#endif /* __GS_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]