[gnome-software/wip/hughsie/reviews-donation] Show a donation section in the review dialog
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/reviews-donation] Show a donation section in the review dialog
- Date: Tue, 16 Jul 2019 19:21:15 +0000 (UTC)
commit 2cd3c064cfaa4753bc05cbc09be2faee6cd869bf
Author: Richard Hughes <richard hughsie com>
Date: Sat Aug 5 14:16:24 2017 +0100
Show a donation section in the review dialog
Additionally, allow admins to disable the donation functionality using a key in
GSettings.
data/org.gnome.software.gschema.xml | 4 ++
src/gs-details-page.c | 6 ++-
src/gs-review-dialog.c | 51 ++++++++++++++++++++++--
src/gs-review-dialog.h | 6 ++-
src/gs-review-dialog.ui | 78 +++++++++++++++++++++++++++++++++++++
5 files changed, 138 insertions(+), 7 deletions(-)
---
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index 97780e0d..a5d12472 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -118,6 +118,10 @@
<default>true</default>
<summary>Show the prompt to install nonfree software repositories</summary>
</key>
+ <key name="show-donation-ui" type="b">
+ <default>true</default>
+ <summary>Show links for donatation to upstream projects</summary>
+ </key>
<key name="installed-page-show-size" type="b">
<default>true</default>
<summary>Show the installed size for apps in the list of installed applications</summary>
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index b80a4438..3bfcddcc 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1082,8 +1082,10 @@ gs_details_page_refresh_all (GsDetailsPage *self)
} else {
gtk_widget_set_visible (self->button_details_website, FALSE);
}
+
tmp = gs_app_get_url (self->app, AS_URL_KIND_DONATION);
- if (tmp != NULL && tmp[0] != '\0') {
+ if (tmp != NULL && tmp[0] != '\0' &&
+ g_settings_get_boolean (self->settings, "show-donation-ui")) {
gtk_widget_set_visible (self->button_donate, TRUE);
show_support_box = TRUE;
} else {
@@ -2204,7 +2206,7 @@ gs_details_page_write_review_cb (GtkButton *button,
GsDetailsPage *self)
{
GtkWidget *dialog;
- dialog = gs_review_dialog_new ();
+ dialog = gs_review_dialog_new (self->shell, self->app);
g_signal_connect (dialog, "response",
G_CALLBACK (gs_details_page_review_response_cb), self);
gs_shell_modal_dialog_present (self->shell, GTK_DIALOG (dialog));
diff --git a/src/gs-review-dialog.c b/src/gs-review-dialog.c
index 424ced5f..0037fcb5 100644
--- a/src/gs-review-dialog.c
+++ b/src/gs-review-dialog.c
@@ -26,11 +26,15 @@
struct _GsReviewDialog
{
GtkDialog parent_instance;
+ GsShell *shell;
+ GsApp *app;
GtkWidget *star;
GtkWidget *label_rating_desc;
GtkWidget *summary_entry;
GtkWidget *post_button;
+ GtkWidget *box_donation;
+ GtkWidget *button_donation;
GtkWidget *text_view;
guint timer_id;
};
@@ -102,6 +106,17 @@ gs_review_dialog_update_review_comment (GsReviewDialog *dialog)
gtk_label_set_label (GTK_LABEL (dialog->label_rating_desc), msg);
}
+static void
+gs_review_dialog_update_donation (GsReviewDialog *dialog)
+{
+ gint pc = gs_star_widget_get_rating (GS_STAR_WIDGET (dialog->star));
+ g_autoptr(GSettings) settings = g_settings_new ("org.gnome.software");
+ gtk_widget_set_visible (dialog->box_donation,
+ gs_app_get_url (dialog->app, AS_URL_KIND_DONATION) != NULL &&
+ g_settings_get_boolean (settings, "show-donation-ui"));
+ gtk_widget_set_sensitive (dialog->button_donation, pc == 0 || pc > 40);
+}
+
static void
gs_review_dialog_changed_cb (GsReviewDialog *dialog)
{
@@ -145,6 +160,9 @@ gs_review_dialog_changed_cb (GsReviewDialog *dialog)
/* can the user submit this? */
gtk_widget_set_sensitive (dialog->post_button, all_okay);
+
+ /* ony show the review section if the user posted a positive review */
+ gs_review_dialog_update_donation (dialog);
}
static gboolean
@@ -156,6 +174,18 @@ gs_review_dialog_timeout_cb (gpointer user_data)
return FALSE;
}
+static void
+gs_review_dialog_donate_clicked_cb (GtkWidget *widget, GsReviewDialog *dialog)
+{
+ gs_shell_show_uri (dialog->shell, gs_app_get_url (dialog->app, AS_URL_KIND_DONATION));
+}
+
+static void
+gs_review_dialog_show_cb (GtkWidget *widget, GsReviewDialog *dialog)
+{
+ gs_review_dialog_update_donation (dialog);
+}
+
static void
gs_review_dialog_init (GsReviewDialog *dialog)
{
@@ -194,12 +224,19 @@ gs_review_dialog_init (GsReviewDialog *dialog)
gtk_widget_set_sensitive (dialog->post_button, FALSE);
+ /* donation button */
+ g_signal_connect (dialog->button_donation, "clicked",
+ G_CALLBACK (gs_review_dialog_donate_clicked_cb), dialog);
+ g_signal_connect (dialog, "show",
+ G_CALLBACK (gs_review_dialog_show_cb), dialog);
}
static void
gs_review_row_dispose (GObject *object)
{
GsReviewDialog *dialog = GS_REVIEW_DIALOG (object);
+ g_clear_object (&dialog->app);
+ g_clear_object (&dialog->shell);
if (dialog->timer_id > 0) {
g_source_remove (dialog->timer_id);
dialog->timer_id = 0;
@@ -222,12 +259,18 @@ gs_review_dialog_class_init (GsReviewDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, GsReviewDialog, summary_entry);
gtk_widget_class_bind_template_child (widget_class, GsReviewDialog, text_view);
gtk_widget_class_bind_template_child (widget_class, GsReviewDialog, post_button);
+ gtk_widget_class_bind_template_child (widget_class, GsReviewDialog, button_donation);
+ gtk_widget_class_bind_template_child (widget_class, GsReviewDialog, box_donation);
}
GtkWidget *
-gs_review_dialog_new (void)
+gs_review_dialog_new (GsShell *shell, GsApp *app)
{
- return GTK_WIDGET (g_object_new (GS_TYPE_REVIEW_DIALOG,
- "use-header-bar", TRUE,
- NULL));
+ GsReviewDialog *self;
+ self = g_object_new (GS_TYPE_REVIEW_DIALOG,
+ "use-header-bar", TRUE,
+ NULL);
+ self->app = g_object_ref (app);
+ self->shell = g_object_ref (shell);
+ return GTK_WIDGET (self);
}
diff --git a/src/gs-review-dialog.h b/src/gs-review-dialog.h
index 2ab610fc..ea8ec4f7 100644
--- a/src/gs-review-dialog.h
+++ b/src/gs-review-dialog.h
@@ -9,13 +9,17 @@
#include <gtk/gtk.h>
+#include "gs-app.h"
+#include "gs-shell.h"
+
G_BEGIN_DECLS
#define GS_TYPE_REVIEW_DIALOG (gs_review_dialog_get_type ())
G_DECLARE_FINAL_TYPE (GsReviewDialog, gs_review_dialog, GS, REVIEW_DIALOG, GtkDialog)
-GtkWidget *gs_review_dialog_new (void);
+GtkWidget *gs_review_dialog_new (GsShell *shell,
+ GsApp *app);
gint gs_review_dialog_get_rating (GsReviewDialog *dialog);
void gs_review_dialog_set_rating (GsReviewDialog *dialog,
gint rating);
diff --git a/src/gs-review-dialog.ui b/src/gs-review-dialog.ui
index c737c677..e2204b44 100644
--- a/src/gs-review-dialog.ui
+++ b/src/gs-review-dialog.ui
@@ -194,6 +194,84 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkBox" id="box_donation">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label_donation_title">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes" context="app review" comments="Translators:
Section where we ask the user for a donation.">Donation</property>
+ <property name="xalign">0</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_donation">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Donating to the project means the developers
can concentrate on writing code, and have access to what they need to make the project better. If you
appreciate what the developers do then please do consider donating as many contributors are
volunteers.</property>
+ <property name="wrap">True</property>
+ <property name="xalign">0</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_donation_tax">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Please also note that not all donations are
tax deductible, so it's best to check with the upstream project if this is a consideration to you.</property>
+ <property name="wrap">True</property>
+ <property name="xalign">0</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_donation">
+ <property name="use_underline">True</property>
+ <property name="label" translatable="yes">_Donate and feel awesome</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="halign">center</property>
+ <property name="valign">start</property>
+ <property name="visible">True</property>
+ <property name="margin_top">18</property>
+ </object>
+ <packing>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]