2525#include "exm-info-bar.h"
2626#include "exm-comment-tile.h"
2727#include "exm-comment-dialog.h"
28+ #include "exm-unified-data.h"
2829
2930#include "web/exm-data-provider.h"
3031#include "web/exm-image-resolver.h"
@@ -75,6 +76,7 @@ struct _ExmDetailView
7576
7677 AdwActionRow * link_homepage ;
7778 gchar * uri_homepage ;
79+
7880 AdwActionRow * link_extensions ;
7981 gchar * uri_extensions ;
8082 int pk ;
@@ -256,7 +258,7 @@ queue_resolve_comments (ExmDetailView *self,
256258 GCancellable * cancellable )
257259{
258260 gtk_stack_set_visible_child_name (self -> comment_stack , "page_spinner" );
259- exm_comment_provider_get_comments_async (self -> comment_provider , pk , false , cancellable ,
261+ exm_comment_provider_get_comments_async (self -> comment_provider , pk , FALSE , cancellable ,
260262 (GAsyncReadyCallback ) on_get_comments ,
261263 self );
262264}
@@ -292,106 +294,117 @@ install_remote (GtkButton *button,
292294 "(sb)" , self -> uuid , warn );
293295}
294296
297+ static ExmInstallButtonState
298+ get_install_state (ExmUnifiedData * data ,
299+ ExmDetailView * self )
300+ {
301+ const char * uuid = exm_unified_data_get_uuid (data );
302+ gboolean is_installed = exm_manager_is_installed_uuid (self -> manager , uuid );
303+
304+ if (is_installed )
305+ return EXM_INSTALL_BUTTON_STATE_INSTALLED ;
306+
307+ ExmShellVersionMap * version_map ;
308+ version_map = exm_unified_data_get_shell_version_map (data );
309+
310+ g_return_val_if_fail (version_map != NULL , EXM_INSTALL_BUTTON_STATE_UNSUPPORTED );
311+
312+ return exm_shell_version_map_supports (version_map , self -> shell_version )
313+ ? EXM_INSTALL_BUTTON_STATE_DEFAULT
314+ : EXM_INSTALL_BUTTON_STATE_UNSUPPORTED ;
315+ }
316+
295317static void
296- on_data_loaded (GObject * source ,
297- GAsyncResult * result ,
298- gpointer user_data )
318+ populate_with_data (ExmUnifiedData * data ,
319+ ExmDetailView * self )
299320{
300- ExmSearchResult * data ;
301- GError * error = NULL ;
302- ExmDetailView * self ;
303321 ExmInstallButtonState install_state ;
304- GtkWidget * child ;
305- GList * version_iter ;
306- ExmShellVersionMap * version_map ;
307- gchar * uri ;
308322
309- self = EXM_DETAIL_VIEW (user_data );
323+ const char * name = exm_unified_data_get_name (data );
324+ adw_window_title_set_title (self -> title , name );
325+ gtk_label_set_label (self -> ext_title , name );
310326
311- if ((data = exm_data_provider_get_finish (EXM_DATA_PROVIDER (source ), result , & error )) != FALSE)
312- {
313- gint pk , downloads ;
314- gboolean is_installed , is_supported ;
315- gchar * uuid , * name , * creator , * icon_uri , * screenshot_uri , * link , * description , * url ;
316- g_object_get (data ,
317- "uuid" , & uuid ,
318- "name" , & name ,
319- "creator" , & creator ,
320- "icon" , & icon_uri ,
321- "screenshot" , & screenshot_uri ,
322- "link" , & link ,
323- "description" , & description ,
324- "shell_version_map" , & version_map ,
325- "pk" , & pk ,
326- "url" , & url ,
327- "downloads" , & downloads ,
328- NULL );
329-
330- adw_window_title_set_title (self -> title , name );
331- adw_window_title_set_subtitle (self -> title , uuid );
332-
333- is_installed = exm_manager_is_installed_uuid (self -> manager , uuid );
334- is_supported = exm_search_result_supports_shell_version (data , self -> shell_version );
335-
336- gtk_image_set_from_icon_name (self -> ext_icon , "puzzle-piece-symbolic" );
337- gtk_label_set_label (self -> ext_title , name );
338- gtk_label_set_label (self -> ext_author , creator );
339- gtk_label_set_label (self -> ext_description , description );
340- exm_info_bar_set_downloads (self -> ext_info_bar , downloads );
341-
342- if (self -> resolver_cancel )
343- {
344- g_cancellable_cancel (self -> resolver_cancel );
345- g_clear_object (& self -> resolver_cancel );
346- }
327+ const char * uuid = exm_unified_data_get_uuid (data );
328+ adw_window_title_set_subtitle (self -> title , uuid );
347329
348- if (strcmp (icon_uri , "/static/images/plugin.png" ) != 0 )
349- {
350- self -> resolver_cancel = g_cancellable_new ();
330+ const char * creator = exm_unified_data_get_creator (data );
331+ gtk_label_set_label (self -> ext_author , creator );
351332
352- queue_resolve_image ( self , icon_uri , self -> resolver_cancel , TRUE );
353- }
333+ const char * description = exm_unified_data_get_description ( data );
334+ gtk_label_set_label ( self -> ext_description , description );
354335
355- if (screenshot_uri != NULL )
356- {
357- self -> resolver_cancel = g_cancellable_new ();
336+ if (self -> resolver_cancel )
337+ {
338+ g_cancellable_cancel (self -> resolver_cancel );
339+ g_clear_object (& self -> resolver_cancel );
340+ }
358341
359- exm_screenshot_set_paintable (self -> ext_screenshot , NULL );
360- exm_zoom_picture_set_paintable (self -> overlay_screenshot , NULL );
361- exm_screenshot_reset (self -> ext_screenshot );
342+ char * screenshot_uri ;
343+ if (exm_unified_data_get_screenshot_uri (data , & screenshot_uri ) && screenshot_uri != NULL )
344+ {
345+ self -> resolver_cancel = g_cancellable_new ();
362346
363- gtk_widget_set_visible (GTK_WIDGET (self -> ext_screenshot_container ), TRUE);
364- gtk_widget_set_visible (GTK_WIDGET (self -> ext_screenshot_popout_button ), FALSE);
347+ exm_screenshot_set_paintable (self -> ext_screenshot , NULL );
348+ exm_zoom_picture_set_paintable (self -> overlay_screenshot , NULL );
349+ exm_screenshot_reset (self -> ext_screenshot );
365350
366- queue_resolve_image (self , screenshot_uri , self -> resolver_cancel , FALSE);
367- }
368- else
369- {
370- gtk_widget_set_visible (GTK_WIDGET (self -> ext_screenshot_container ), FALSE);
371- }
351+ gtk_widget_set_visible (GTK_WIDGET (self -> ext_screenshot_container ), TRUE);
352+ gtk_widget_set_visible (GTK_WIDGET (self -> ext_screenshot_popout_button ), FALSE);
372353
373- install_state = is_installed
374- ? EXM_INSTALL_BUTTON_STATE_INSTALLED
375- : (is_supported
376- ? EXM_INSTALL_BUTTON_STATE_DEFAULT
377- : EXM_INSTALL_BUTTON_STATE_UNSUPPORTED );
354+ queue_resolve_image (self , screenshot_uri , self -> resolver_cancel , false);
378355
379- g_object_set (self -> ext_install , "state" , install_state , NULL );
356+ g_free (screenshot_uri );
357+ }
358+ else
359+ {
360+ gtk_widget_set_visible (GTK_WIDGET (self -> ext_screenshot_container ), FALSE);
361+ }
380362
381- self -> uri_homepage = g_uri_resolve_relative (url ,
382- "" ,
383- G_URI_FLAGS_NONE ,
384- NULL );
363+ install_state = get_install_state (data , self );
364+ g_object_set (self -> ext_install , "state" , install_state , NULL );
385365
366+ char * link ;
367+ if (exm_unified_data_get_link (data , & link ))
368+ {
386369 self -> uri_extensions = g_uri_resolve_relative ("https://extensions.gnome.org/" ,
387370 link ,
388371 G_URI_FLAGS_NONE ,
389372 NULL );
390373
391- adw_action_row_set_subtitle (self -> link_homepage , self -> uri_homepage );
392374 adw_action_row_set_subtitle (self -> link_extensions , self -> uri_extensions );
375+ gtk_widget_set_visible (GTK_WIDGET (self -> link_extensions ), TRUE);
376+ }
377+ else
378+ {
379+ gtk_widget_set_visible (GTK_WIDGET (self -> link_extensions ), FALSE);
380+ }
393381
394- exm_info_bar_set_version (self -> ext_info_bar , -1 );
382+ char * homepage ;
383+ if (exm_unified_data_get_homepage (data , & homepage ))
384+ {
385+ self -> uri_homepage = g_uri_resolve_relative (homepage ,
386+ "" ,
387+ G_URI_FLAGS_NONE ,
388+ NULL );
389+
390+ adw_action_row_set_subtitle (self -> link_homepage , self -> uri_homepage );
391+ gtk_widget_set_visible (GTK_WIDGET (self -> link_homepage ), TRUE);
392+ }
393+ else
394+ {
395+ gtk_widget_set_visible (GTK_WIDGET (self -> link_homepage ), FALSE);
396+ }
397+
398+ // Clear Flowbox
399+ // GtkWidget *child;
400+ // while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->supported_versions))))
401+ // gtk_flow_box_remove (self->supported_versions, child);
402+
403+ ExmShellVersionMap * version_map = exm_unified_data_get_shell_version_map (data );
404+
405+ if (version_map )
406+ {
407+ GList * version_iter ;
395408
396409 for (version_iter = version_map -> map ;
397410 version_iter != NULL ;
@@ -412,30 +425,68 @@ on_data_loaded (GObject *source,
412425
413426 g_free (version );
414427 }
428+ }
415429
416- self -> pk = pk ;
417-
418- if (self -> signal_id > 0 )
419- g_signal_handler_disconnect (self -> show_more_btn , self -> signal_id );
430+ if (self -> signal_id > 0 )
431+ g_signal_handler_disconnect (self -> show_more_btn , self -> signal_id );
420432
433+ int pk ;
434+ if (exm_unified_data_get_pk (data , & pk ))
435+ {
436+ self -> pk = pk ;
421437 self -> signal_id = g_signal_connect (self -> show_more_btn ,
422- "clicked" ,
423- G_CALLBACK (show_more_comments ),
424- self );
438+ "clicked" ,
439+ G_CALLBACK (show_more_comments ),
440+ self );
425441
426442 queue_resolve_comments (self , pk , self -> resolver_cancel );
443+ }
444+ else
445+ {
446+ gtk_stack_set_visible_child_name (self -> comment_stack , "page_empty" );
447+ }
448+
449+ // Reset scroll position
450+ gtk_adjustment_set_value (gtk_scrolled_window_get_vadjustment (self -> scroll_area ), 0 );
451+
452+ gtk_stack_set_visible_child_name (self -> stack , "page_detail" );
453+ }
454+
455+ static void
456+ on_data_loaded (GObject * source ,
457+ GAsyncResult * async_result ,
458+ gpointer user_data )
459+ {
460+ ExmUnifiedData * data ;
461+ ExmSearchResult * web_info ;
462+ ExmExtension * local_info ;
463+
464+ GError * error = NULL ;
465+ ExmDetailView * self ;
466+
467+ g_return_if_fail (EXM_IS_DETAIL_VIEW (user_data ));
468+
469+ self = EXM_DETAIL_VIEW (user_data );
470+
471+ data = exm_unified_data_new ();
427472
428- // Reset scroll position
429- gtk_adjustment_set_value (gtk_scrolled_window_get_vadjustment (self -> scroll_area ), 0 );
473+ // Build Unified Data Representation
474+ if ((local_info = exm_manager_get_by_uuid (self -> manager , self -> uuid )))
475+ exm_unified_data_set_local_data (data , local_info );
430476
431- gtk_stack_set_visible_child_name (self -> stack , "page_detail" );
477+ if ((web_info = exm_data_provider_get_finish (EXM_DATA_PROVIDER (source ), async_result , & error )) != FALSE)
478+ exm_unified_data_set_web_data (data , web_info );
432479
480+ // We need at least some data to proceed
481+ if (!exm_unified_data_is_empty (data )) {
482+ populate_with_data (data , self );
433483 return ;
434484 }
435485
436486 adw_window_title_set_title (self -> title , _ ("An Error Occurred" ));
437487 adw_window_title_set_subtitle (self -> title , NULL );
438488 gtk_stack_set_visible_child_name (self -> stack , "page_error" );
489+ return ;
439490}
440491
441492void
@@ -594,8 +645,8 @@ exm_detail_view_class_init (ExmDetailViewClass *klass)
594645 gtk_widget_class_bind_template_child (widget_class , ExmDetailView , comment_box );
595646 gtk_widget_class_bind_template_child (widget_class , ExmDetailView , comment_stack );
596647 gtk_widget_class_bind_template_child (widget_class , ExmDetailView , show_more_btn );
597- gtk_widget_class_bind_template_child (widget_class , ExmDetailView , image_overlay );
598- gtk_widget_class_bind_template_child (widget_class , ExmDetailView , overlay_screenshot );
648+ gtk_widget_class_bind_template_child (widget_class , ExmDetailView , image_overlay );
649+ gtk_widget_class_bind_template_child (widget_class , ExmDetailView , overlay_screenshot );
599650
600651 gtk_widget_class_install_action (widget_class , "detail.open-extensions" , NULL , open_link );
601652 gtk_widget_class_install_action (widget_class , "detail.open-homepage" , NULL , open_link );
0 commit comments