Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add donation row #545

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/icons/hicolor/scalable/actions/donation-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/exm-detail-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ template $ExmDetailView : Adw.NavigationPage {
}
}

Adw.ExpanderRow links_donations {
[prefix]
Gtk.Image {
icon-name: "donation-symbolic";
}

title: _("Donate");
}

Adw.ActionRow link_extensions {
[prefix]
Gtk.Image {
Expand Down
78 changes: 78 additions & 0 deletions src/exm-detail-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ struct _ExmDetailView

AdwActionRow *link_homepage;
gchar *uri_homepage;
AdwExpanderRow *links_donations;
gchar **uri_donations;
GList *donation_rows_list;
AdwActionRow *link_extensions;
gchar *uri_extensions;
int pk;
Expand Down Expand Up @@ -293,6 +296,69 @@ install_remote (GtkButton *button,
"(sb)", self->uuid, warn);
}

static void
delete_donation_rows (ExmDetailView *self)
{
GtkWidget *row;

for (GList *iter = self->donation_rows_list; iter != NULL; iter = g_list_next (iter)) {
row = GTK_WIDGET (iter->data);
adw_expander_row_remove (self->links_donations, row);
}

g_list_free (self->donation_rows_list);
self->donation_rows_list = NULL;
}

static void
new_donation_row (ExmDetailView *self,
int num_donation)
{
GtkWidget *row;
GtkWidget *external_link_icon;

row = adw_action_row_new ();

adw_preferences_row_set_title (ADW_PREFERENCES_ROW (row), self->uri_donations[num_donation]);
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), TRUE);

gtk_actionable_set_action_name (GTK_ACTIONABLE (row), "detail.open-donation");
gtk_actionable_set_action_target_value (GTK_ACTIONABLE (row), g_variant_new_int32 (num_donation));

external_link_icon = gtk_image_new_from_icon_name ("external-link-symbolic");
gtk_widget_add_css_class (external_link_icon, "dim-label");
adw_action_row_add_suffix (ADW_ACTION_ROW (row), external_link_icon);

adw_expander_row_add_row (self->links_donations, row);

self->donation_rows_list = g_list_append (self->donation_rows_list, row);
}

static void
update_donation_rows (ExmDetailView *self,
gchar **donation_urls)
{
gtk_widget_set_visible (GTK_WIDGET (self->links_donations), FALSE);
delete_donation_rows (self);

if (donation_urls == NULL || donation_urls[0] == NULL)
return;

self->uri_donations = g_new0 (gchar *, g_strv_length (donation_urls));

for (int i = 0; donation_urls[i] != NULL; i++)
{
self->uri_donations[i] = g_uri_resolve_relative (donation_urls[i],
"",
G_URI_FLAGS_NONE,
NULL);
new_donation_row (self, i);
}

adw_expander_row_set_expanded (self->links_donations, FALSE);
gtk_widget_set_visible (GTK_WIDGET (self->links_donations), TRUE);
}

static void
on_data_loaded (GObject *source,
GAsyncResult *result,
Expand All @@ -312,6 +378,7 @@ on_data_loaded (GObject *source,
gint pk, downloads;
gboolean is_installed, is_supported;
gchar *uuid, *name, *creator, *icon_uri, *screenshot_uri, *link, *description, *url;
gchar **donation_urls;
g_object_get (data,
"uuid", &uuid,
"name", &name,
Expand All @@ -324,6 +391,7 @@ on_data_loaded (GObject *source,
"pk", &pk,
"url", &url,
"downloads", &downloads,
"donation_urls", &donation_urls,
NULL);

adw_window_title_set_title (self->title, name);
Expand Down Expand Up @@ -382,6 +450,8 @@ on_data_loaded (GObject *source,
G_URI_FLAGS_NONE,
NULL);

update_donation_rows (self, donation_urls);

self->uri_extensions = g_uri_resolve_relative ("https://extensions.gnome.org/",
link,
G_URI_FLAGS_NONE,
Expand Down Expand Up @@ -481,6 +551,12 @@ open_link (ExmDetailView *self,
uri = gtk_uri_launcher_new (self->uri_extensions);
else if (strcmp (action_name, "detail.open-homepage") == 0)
uri = gtk_uri_launcher_new (self->uri_homepage);
else if (strcmp (action_name, "detail.open-donation") == 0)
{
guint val;
g_variant_get (param, "i", &val);
uri = gtk_uri_launcher_new (self->uri_donations[val]);
}
else
g_critical ("open_link() invalid action: %s", action_name);

Expand Down Expand Up @@ -585,6 +661,7 @@ exm_detail_view_class_init (ExmDetailViewClass *klass)
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, ext_screenshot_popout_button);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, ext_info_bar);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, link_homepage);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, links_donations);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, link_extensions);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, scroll_area);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, comment_box);
Expand All @@ -597,6 +674,7 @@ exm_detail_view_class_init (ExmDetailViewClass *klass)

gtk_widget_class_install_action (widget_class, "detail.open-extensions", NULL, (GtkWidgetActionActivateFunc) open_link);
gtk_widget_class_install_action (widget_class, "detail.open-homepage", NULL, (GtkWidgetActionActivateFunc) open_link);
gtk_widget_class_install_action (widget_class, "detail.open-donation", "i", (GtkWidgetActionActivateFunc) open_link);
}

static void
Expand Down
1 change: 1 addition & 0 deletions src/exm.gresource.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<gresource prefix="/com/mattjakeman/ExtensionManager/icons/scalable/actions">
<file preprocess="xml-stripblanks" alias="clock-alt-symbolic.svg">../data/icons/hicolor/scalable/actions/clock-alt-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="dialog-error-symbolic.svg">../data/icons/hicolor/scalable/actions/dialog-error-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="donation-symbolic.svg">../data/icons/hicolor/scalable/actions/donation-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="external-link-symbolic.svg">../data/icons/hicolor/scalable/actions/external-link-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="globe-symbolic.svg">../data/icons/hicolor/scalable/actions/globe-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="go-next-symbolic.svg">../data/icons/hicolor/scalable/actions/go-next-symbolic.svg</file>
Expand Down
15 changes: 15 additions & 0 deletions src/web/model/exm-search-result.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct _ExmSearchResult
gchar *icon;
gchar *screenshot;
gchar *url;
gchar **donation_urls;
gchar *link;
gchar *description;
int pk;
Expand All @@ -35,6 +36,7 @@ enum {
PROP_ICON,
PROP_SCREENSHOT,
PROP_URL,
PROP_DONATION_URLS,
PROP_LINK,
PROP_DESCRIPTION,
PROP_PK,
Expand Down Expand Up @@ -89,6 +91,9 @@ exm_search_result_get_property (GObject *object,
case PROP_URL:
g_value_set_string (value, self->url);
break;
case PROP_DONATION_URLS:
g_value_set_boxed (value, self->donation_urls);
break;
case PROP_LINK:
g_value_set_string (value, self->link);
break;
Expand Down Expand Up @@ -139,6 +144,9 @@ exm_search_result_set_property (GObject *object,
case PROP_URL:
self->url = g_value_dup_string (value);
break;
case PROP_DONATION_URLS:
self->donation_urls = g_value_dup_boxed (value);
break;
case PROP_LINK:
self->link = g_value_dup_string (value);
break;
Expand Down Expand Up @@ -257,6 +265,13 @@ exm_search_result_class_init (ExmSearchResultClass *klass)
NULL,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY);

properties[PROP_DONATION_URLS] =
g_param_spec_boxed ("donation_urls",
"Donation URLs",
"Donation URLs",
G_TYPE_STRV,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY);

properties [PROP_LINK] =
g_param_spec_string ("link",
"Link",
Expand Down