From 2cd3c064cfaa4753bc05cbc09be2faee6cd869bf Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Sat, 5 Aug 2017 14:16:24 +0100 Subject: [PATCH] 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 97780e0d3..a5d124729 100644 --- a/data/org.gnome.software.gschema.xml +++ b/data/org.gnome.software.gschema.xml @@ -118,6 +118,10 @@ true Show the prompt to install nonfree software repositories + + true + Show links for donatation to upstream projects + true Show the installed size for apps in the list of installed applications diff --git a/src/gs-details-page.c b/src/gs-details-page.c index b80a44386..3bfcddcc6 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 424ced5f9..0037fcb5d 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 2ab610fc5..ea8ec4f71 100644 --- a/src/gs-review-dialog.h +++ b/src/gs-review-dialog.h @@ -9,13 +9,17 @@ #include +#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 c737c6770..e2204b445 100644 --- a/src/gs-review-dialog.ui +++ b/src/gs-review-dialog.ui @@ -194,6 +194,84 @@ + + + True + False + vertical + 6 + + + True + False + Donation + 0 + + + + + + False + False + 0 + + + + + True + False + 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. + True + 0 + + + + False + False + 1 + + + + + True + False + 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. + True + 0 + + + + False + False + 2 + + + + + True + _Donate and feel awesome + True + True + center + start + True + 18 + + + 3 + + + + + False + False + 3 + + -- GitLab