Skip to content

Commit

Permalink
detail-view: Rewrite using unified data and property bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
mjakeman committed Mar 24, 2024
1 parent e6559dd commit c65d7a9
Show file tree
Hide file tree
Showing 4 changed files with 393 additions and 112 deletions.
9 changes: 8 additions & 1 deletion src/exm-detail-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ template $ExmDetailView : Adw.NavigationPage {
styles ["title-1"]
xalign: 0;
ellipsize: end;
label: bind template.data as <$ExmUnifiedData>.name;
}

Gtk.Label ext_author {
styles ["dim-label"]
label: "Author";
xalign: 0;
ellipsize: end;
label: bind template.data as <$ExmUnifiedData>.creator;
}
}

Expand Down Expand Up @@ -145,6 +146,8 @@ template $ExmDetailView : Adw.NavigationPage {
wrap: true;
wrap-mode: word_char;
selectable: true;

label: bind template.data as <$ExmUnifiedData>.description;
}
}

Expand Down Expand Up @@ -175,6 +178,8 @@ template $ExmDetailView : Adw.NavigationPage {
activatable: true;
action-name: "detail.open-homepage";

subtitle: bind template.data as <$ExmUnifiedData>.homepage;

[suffix]
Gtk.Image {
styles ["dim-label"]
Expand All @@ -192,6 +197,8 @@ template $ExmDetailView : Adw.NavigationPage {
activatable: true;
action-name: "detail.open-extensions";

subtitle: bind template.data as <$ExmUnifiedData>.link;

[suffix]
Gtk.Image {
styles ["dim-label"]
Expand Down
261 changes: 156 additions & 105 deletions src/exm-detail-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "exm-info-bar.h"
#include "exm-comment-tile.h"
#include "exm-comment-dialog.h"
#include "exm-unified-data.h"

#include "web/exm-data-provider.h"
#include "web/exm-image-resolver.h"
Expand All @@ -42,6 +43,8 @@ struct _ExmDetailView
{
AdwNavigationPage parent_instance;

ExmUnifiedData *data;

ExmManager *manager;
ExmDataProvider *provider;
ExmImageResolver *resolver;
Expand Down Expand Up @@ -86,6 +89,7 @@ enum {
PROP_0,
PROP_MANAGER,
PROP_SHELL_VERSION,
PROP_DATA,
N_PROPS
};

Expand Down Expand Up @@ -121,6 +125,9 @@ exm_detail_view_get_property (GObject *object,
case PROP_SHELL_VERSION:
g_value_set_string (value, self->shell_version);
break;
case PROP_DATA:
g_value_set_object (value, self->data);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
Expand All @@ -145,6 +152,9 @@ exm_detail_view_set_property (GObject *object,
case PROP_SHELL_VERSION:
self->shell_version = g_value_dup_string (value);
break;
case PROP_DATA:
self->data = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
Expand Down Expand Up @@ -293,10 +303,9 @@ install_remote (GtkButton *button,
"(sb)", self->uuid, warn);
}

static void
on_data_loaded (GObject *source,
GAsyncResult *result,
gpointer user_data)
/*static void
populate_with_data (ExmUnifiedData *data,
gpointer user_data)
{
ExmSearchResult *data;
GError *error = NULL;
Expand All @@ -307,132 +316,167 @@ on_data_loaded (GObject *source,
self = EXM_DETAIL_VIEW (user_data);
if ((data = exm_data_provider_get_finish (EXM_DATA_PROVIDER (source), result, &error)) != FALSE)
gint pk, downloads;
gboolean is_installed, is_supported;
gchar *uuid, *name, *creator, *icon_uri, *screenshot_uri, *link, *description, *url;
g_object_get (data,
"uuid", &uuid,
"name", &name,
"creator", &creator,
"icon", &icon_uri,
"screenshot", &screenshot_uri,
"link", &link,
"description", &description,
"shell_version_map", &version_map,
"pk", &pk,
"url", &url,
"downloads", &downloads,
NULL);
adw_window_title_set_title (self->title, name);
adw_window_title_set_subtitle (self->title, uuid);
adw_navigation_page_set_title (ADW_NAVIGATION_PAGE (self), name);
is_installed = exm_manager_is_installed_uuid (self->manager, uuid);
is_supported = exm_search_result_supports_shell_version (data, self->shell_version);
gtk_image_set_from_icon_name (self->ext_icon, "puzzle-piece-symbolic");
gtk_label_set_label (self->ext_title, name);
gtk_label_set_label (self->ext_author, creator);
gtk_label_set_label (self->ext_description, description);
exm_info_bar_set_downloads (self->ext_info_bar, downloads);
if (self->resolver_cancel)
{
g_cancellable_cancel (self->resolver_cancel);
g_clear_object (&self->resolver_cancel);
}
if (strcmp (icon_uri, "/static/images/plugin.png") != 0)
{
self->resolver_cancel = g_cancellable_new ();
queue_resolve_image (self, icon_uri, self->resolver_cancel, TRUE);
}
if (screenshot_uri != NULL)
{
self->resolver_cancel = g_cancellable_new ();
exm_screenshot_set_paintable (self->ext_screenshot, NULL);
exm_screenshot_reset (self->ext_screenshot);
gtk_widget_set_visible (GTK_WIDGET (self->ext_screenshot_container), TRUE);
gtk_widget_set_visible (GTK_WIDGET (self->ext_screenshot_popout_button), FALSE);
queue_resolve_image (self, screenshot_uri, self->resolver_cancel, FALSE);
}
else
{
gtk_widget_set_visible (GTK_WIDGET (self->ext_screenshot_container), FALSE);
}
install_state = is_installed
? EXM_INSTALL_BUTTON_STATE_INSTALLED
: (is_supported
? EXM_INSTALL_BUTTON_STATE_DEFAULT
: EXM_INSTALL_BUTTON_STATE_UNSUPPORTED);
g_object_set (self->ext_install, "state", install_state, NULL);
self->uri_homepage = g_uri_resolve_relative (url,
"",
G_URI_FLAGS_NONE,
NULL);
self->uri_extensions = g_uri_resolve_relative ("https://extensions.gnome.org/",
link,
G_URI_FLAGS_NONE,
NULL);
adw_action_row_set_subtitle (self->link_homepage, self->uri_homepage);
adw_action_row_set_subtitle (self->link_extensions, self->uri_extensions);
exm_info_bar_set_version (self->ext_info_bar, -1);
for (version_iter = version_map->map;
version_iter != NULL;
version_iter = version_iter->next)
{
gint pk, downloads;
gboolean is_installed, is_supported;
gchar *uuid, *name, *creator, *icon_uri, *screenshot_uri, *link, *description, *url;
g_object_get (data,
"uuid", &uuid,
"name", &name,
"creator", &creator,
"icon", &icon_uri,
"screenshot", &screenshot_uri,
"link", &link,
"description", &description,
"shell_version_map", &version_map,
"pk", &pk,
"url", &url,
"downloads", &downloads,
NULL);

adw_window_title_set_title (self->title, name);
adw_window_title_set_subtitle (self->title, uuid);
adw_navigation_page_set_title (ADW_NAVIGATION_PAGE (self), name);

is_installed = exm_manager_is_installed_uuid (self->manager, uuid);
is_supported = exm_search_result_supports_shell_version (data, self->shell_version);

gtk_image_set_from_icon_name (self->ext_icon, "puzzle-piece-symbolic");
gtk_label_set_label (self->ext_title, name);
gtk_label_set_label (self->ext_author, creator);
gtk_label_set_label (self->ext_description, description);
exm_info_bar_set_downloads (self->ext_info_bar, downloads);

if (self->resolver_cancel)
{
g_cancellable_cancel (self->resolver_cancel);
g_clear_object (&self->resolver_cancel);
}

if (strcmp (icon_uri, "/static/images/plugin.png") != 0)
{
self->resolver_cancel = g_cancellable_new ();

queue_resolve_image (self, icon_uri, self->resolver_cancel, TRUE);
}

if (screenshot_uri != NULL)
{
self->resolver_cancel = g_cancellable_new ();

exm_screenshot_set_paintable (self->ext_screenshot, NULL);
exm_screenshot_reset (self->ext_screenshot);

gtk_widget_set_visible (GTK_WIDGET (self->ext_screenshot_container), TRUE);
gtk_widget_set_visible (GTK_WIDGET (self->ext_screenshot_popout_button), FALSE);

queue_resolve_image (self, screenshot_uri, self->resolver_cancel, FALSE);
}
gchar *version;
MapEntry *entry;
entry = version_iter->data;
if (entry->shell_minor_version)
version = g_strdup_printf ("%s.%s", entry->shell_major_version, entry->shell_minor_version);
else
{
gtk_widget_set_visible (GTK_WIDGET (self->ext_screenshot_container), FALSE);
}
version = g_strdup_printf ("%s.0", entry->shell_major_version);
if (strcmp (version, self->shell_version) == 0 || strncmp(version, self->shell_version, strchr(version, '.') - version) == 0)
exm_info_bar_set_version (self->ext_info_bar, entry->extension_version);
install_state = is_installed
? EXM_INSTALL_BUTTON_STATE_INSTALLED
: (is_supported
? EXM_INSTALL_BUTTON_STATE_DEFAULT
: EXM_INSTALL_BUTTON_STATE_UNSUPPORTED);
g_free (version);
}
g_object_set (self->ext_install, "state", install_state, NULL);
self->pk = pk;
self->uri_homepage = g_uri_resolve_relative (url,
"",
G_URI_FLAGS_NONE,
NULL);
if (self->signal_id > 0)
g_signal_handler_disconnect (self->show_more_btn, self->signal_id);
self->uri_extensions = g_uri_resolve_relative ("https://extensions.gnome.org/",
link,
G_URI_FLAGS_NONE,
NULL);
self->signal_id = g_signal_connect (self->show_more_btn,
"clicked",
G_CALLBACK (show_more_comments),
self);
adw_action_row_set_subtitle (self->link_homepage, self->uri_homepage);
adw_action_row_set_subtitle (self->link_extensions, self->uri_extensions);
queue_resolve_comments (self, pk, self->resolver_cancel);
exm_info_bar_set_version (self->ext_info_bar, -1);
// Reset scroll position
gtk_adjustment_set_value (gtk_scrolled_window_get_vadjustment (self->scroll_area), 0);
for (version_iter = version_map->map;
version_iter != NULL;
version_iter = version_iter->next)
{
gchar *version;
MapEntry *entry;
gtk_stack_set_visible_child_name (self->stack, "page_detail");
}*/

entry = version_iter->data;
static void
on_data_loaded (GObject *source,
GAsyncResult *async_result,
gpointer user_data)
{
ExmUnifiedData *data;
ExmSearchResult *web_info;
ExmExtension *local_info;

if (entry->shell_minor_version)
version = g_strdup_printf ("%s.%s", entry->shell_major_version, entry->shell_minor_version);
else
version = g_strdup_printf ("%s.0", entry->shell_major_version);
GError *error = NULL;
ExmDetailView *self;

if (strcmp (version, self->shell_version) == 0 || strncmp(version, self->shell_version, strchr(version, '.') - version) == 0)
exm_info_bar_set_version (self->ext_info_bar, entry->extension_version);
g_return_if_fail (EXM_IS_DETAIL_VIEW (user_data));

g_free (version);
}
self = EXM_DETAIL_VIEW (user_data);

self->pk = pk;
data = exm_unified_data_new ();

if (self->signal_id > 0)
g_signal_handler_disconnect (self->show_more_btn, self->signal_id);
// Build Unified Data Representation
if ((local_info = exm_manager_get_by_uuid (self->manager, self->uuid)))
exm_unified_data_set_local_data (data, local_info);

self->signal_id = g_signal_connect (self->show_more_btn,
"clicked",
G_CALLBACK (show_more_comments),
self);
if ((web_info = exm_data_provider_get_finish (EXM_DATA_PROVIDER (source), async_result, &error)) != FALSE)
exm_unified_data_set_web_data (data, web_info);

queue_resolve_comments (self, pk, self->resolver_cancel);
// We need at least some data to proceed
if (!exm_unified_data_is_empty (data)) {
g_object_set (self, "data", data, NULL);

// Reset scroll position
// Reset scroll position
gtk_adjustment_set_value (gtk_scrolled_window_get_vadjustment (self->scroll_area), 0);

gtk_stack_set_visible_child_name (self->stack, "page_detail");

return;
}

adw_window_title_set_title (self->title, _("An Error Occurred"));
adw_window_title_set_subtitle (self->title, NULL);
gtk_stack_set_visible_child_name (self->stack, "page_error");
return;
}

void
Expand Down Expand Up @@ -564,6 +608,13 @@ exm_detail_view_class_init (ExmDetailViewClass *klass)
NULL,
G_PARAM_READWRITE);

properties [PROP_DATA]
= g_param_spec_object ("data",
"Data",
"Data",
EXM_TYPE_UNIFIED_DATA,
G_PARAM_READWRITE);

g_object_class_install_properties (object_class, N_PROPS, properties);

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
Expand Down
Loading

0 comments on commit c65d7a9

Please sign in to comment.