static void gs_shell_overview_get_popular_rotating_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { LoadData *load_data = (LoadData *) user_data; GsShellOverview *self = load_data->self; GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self); GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object); GList *l; GsApp *app; gint i; GtkWidget *tile; g_autoptr(GError) error = NULL; g_autoptr(GsAppList) list = NULL; /* get popular apps */ list = gs_plugin_loader_get_category_apps_finish (plugin_loader, res, &error); if (list == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("failed to get recommended applications: %s", error->message); gtk_widget_hide (priv->popular_rotating_heading); gtk_widget_hide (priv->box_popular_rotating); goto out; } else if (g_list_length (list) < N_TILES) { g_warning ("hiding recommended applications: found only %d to show, need at least %d", g_list_length (list), N_TILES); gtk_widget_hide (priv->popular_rotating_heading); gtk_widget_hide (priv->box_popular_rotating); goto out; } gs_plugin_list_randomize (&list); gtk_widget_show (priv->popular_rotating_heading); gtk_widget_show (priv->box_popular_rotating); gs_container_remove_all (GTK_CONTAINER (priv->box_popular_rotating)); for (l = list, i = 0; l != NULL && i < N_TILES; l = l->next, i++) { app = GS_APP (l->data); tile = gs_popular_tile_new (app); g_signal_connect (tile, "clicked", G_CALLBACK (popular_tile_clicked), self); gtk_container_add (GTK_CONTAINER (priv->box_popular_rotating), tile); } priv->empty = FALSE; out: load_data_free (load_data); priv->loading_popular_rotating = FALSE; priv->refresh_count--; if (priv->refresh_count == 0) { priv->cache_valid = TRUE; g_signal_emit (self, signals[SIGNAL_REFRESHED], 0); } }
static void gs_plugin_loader_filename_to_app_finish_sync (GObject *source_object, GAsyncResult *res, gpointer user_data) { GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object); GsPluginLoaderHelper *helper = (GsPluginLoaderHelper *) user_data; helper->app = gs_plugin_loader_filename_to_app_finish (plugin_loader, res, helper->error); g_main_loop_quit (helper->loop); }
static void gs_page_app_shortcut_removed_cb (GObject *source, GAsyncResult *res, gpointer user_data) { GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source); g_autoptr(GError) error = NULL; if (!gs_plugin_loader_app_action_finish (plugin_loader, res, &error)) { g_warning ("failed to remove the shortcut to GsApp: %s", error->message); return; } }
static void gs_page_app_removed_cb (GObject *source, GAsyncResult *res, gpointer user_data) { g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data; GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source); GsPage *page = helper->page; GsPagePrivate *priv = gs_page_get_instance_private (page); gboolean ret; g_autoptr(GError) error = NULL; ret = gs_plugin_loader_app_action_finish (plugin_loader, res, &error); if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_CANCELLED)) { g_debug ("%s", error->message); return; } if (!ret) { /* try to authenticate then retry */ if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_AUTH_REQUIRED)) { g_autoptr(GError) error_local = NULL; GtkWidget *dialog; dialog = gs_auth_dialog_new (priv->plugin_loader, helper->app, gs_utils_get_error_value (error), &error_local); if (dialog == NULL) { g_warning ("%s", error_local->message); return; } gs_shell_modal_dialog_present (priv->shell, GTK_DIALOG (dialog)); g_signal_connect (dialog, "response", G_CALLBACK (gs_page_remove_authenticate_cb), g_steal_pointer (&helper)); return; } g_warning ("failed to remove: %s", error->message); return; } if (!gs_app_is_installed (helper->app) && GS_PAGE_GET_CLASS (page)->app_removed != NULL) { GS_PAGE_GET_CLASS (page)->app_removed (page, helper->app); } }
static void gs_shell_overview_get_featured_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GsShellOverview *self = GS_SHELL_OVERVIEW (user_data); GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self); GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object); GtkWidget *tile; GsApp *app; g_autoptr(GError) error = NULL; g_autoptr(GsAppList) list = NULL; list = gs_plugin_loader_get_featured_finish (plugin_loader, res, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) goto out; if (g_getenv ("GNOME_SOFTWARE_FEATURED") == NULL) { /* Don't show apps from the category that's currently featured as the category of the day */ gs_plugin_list_filter (&list, filter_category, priv->category_of_day); gs_plugin_list_randomize (&list); } gs_container_remove_all (GTK_CONTAINER (priv->bin_featured)); gtk_widget_set_visible (priv->featured_heading, list != NULL); if (list == NULL) { g_warning ("failed to get featured apps: %s", error ? error->message : "no apps to show"); goto out; } /* at the moment, we only care about the first app */ app = GS_APP (list->data); tile = gs_feature_tile_new (app); g_signal_connect (tile, "clicked", G_CALLBACK (feature_tile_clicked), self); gtk_container_add (GTK_CONTAINER (priv->bin_featured), tile); priv->empty = FALSE; out: priv->loading_featured = FALSE; priv->refresh_count--; if (priv->refresh_count == 0) { priv->cache_valid = TRUE; g_signal_emit (self, signals[SIGNAL_REFRESHED], 0); } }
/** * gs_shell_overview_get_popular_cb: **/ static void gs_shell_overview_get_popular_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GsShellOverview *self = GS_SHELL_OVERVIEW (user_data); GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self); GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object); GList *l; GsApp *app; gint i; GtkWidget *tile; g_autoptr(GError) error = NULL; g_autoptr(GsAppList) list = NULL; /* get popular apps */ list = gs_plugin_loader_get_popular_finish (plugin_loader, res, &error); gtk_widget_set_visible (priv->box_popular, list != NULL); gtk_widget_set_visible (priv->popular_heading, list != NULL); if (list == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("failed to get popular apps: %s", error->message); goto out; } /* Don't show apps from the category that's currently featured as the category of the day */ gs_plugin_list_filter (&list, filter_category, priv->category_of_day); gs_plugin_list_randomize (&list); gs_container_remove_all (GTK_CONTAINER (priv->box_popular)); for (l = list, i = 0; l != NULL && i < N_TILES; l = l->next, i++) { app = GS_APP (l->data); tile = gs_popular_tile_new (app); g_signal_connect (tile, "clicked", G_CALLBACK (popular_tile_clicked), self); gtk_container_add (GTK_CONTAINER (priv->box_popular), tile); } priv->empty = FALSE; out: priv->loading_popular = FALSE; priv->refresh_count--; if (priv->refresh_count == 0) { priv->cache_valid = TRUE; g_signal_emit (self, signals[SIGNAL_REFRESHED], 0); } }
/** * gs_shell_overview_get_categories_cb: **/ static void gs_shell_overview_get_categories_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GsShellOverview *self = GS_SHELL_OVERVIEW (user_data); GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self); GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object); GList *l; GsCategory *cat; GtkWidget *tile; gboolean has_category = FALSE; g_autoptr(GError) error = NULL; g_autoptr(GsAppList) list = NULL; list = gs_plugin_loader_get_categories_finish (plugin_loader, res, &error); if (list == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("failed to get categories: %s", error->message); goto out; } gs_container_remove_all (GTK_CONTAINER (priv->flowbox_categories)); for (l = list; l; l = l->next) { cat = GS_CATEGORY (l->data); if (gs_category_get_size (cat) == 0) continue; tile = gs_category_tile_new (cat); g_signal_connect (tile, "clicked", G_CALLBACK (category_tile_clicked), self); gtk_flow_box_insert (GTK_FLOW_BOX (priv->flowbox_categories), tile, -1); gtk_widget_set_can_focus (gtk_widget_get_parent (tile), FALSE); has_category = TRUE; } out: if (has_category) { priv->empty = FALSE; } gtk_widget_set_visible (priv->category_heading, has_category); priv->loading_categories = FALSE; priv->refresh_count--; if (priv->refresh_count == 0) { priv->cache_valid = TRUE; g_signal_emit (self, signals[SIGNAL_REFRESHED], 0); } }
static void gs_page_app_removed_cb (GObject *source, GAsyncResult *res, gpointer user_data) { g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data; GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source); GsPage *page = helper->page; gboolean ret; g_autoptr(GError) error = NULL; ret = gs_plugin_loader_job_action_finish (plugin_loader, res, &error); if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_CANCELLED)) { g_debug ("%s", error->message); return; } if (!ret) { /* try to authenticate then retry */ if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_AUTH_REQUIRED)) { gs_page_authenticate (page, helper->app, gs_utils_get_error_value (error), helper->cancellable, gs_page_remove_authenticate_cb, helper); g_steal_pointer (&helper); return; } g_warning ("failed to remove: %s", error->message); return; } if (!gs_app_is_installed (helper->app) && GS_PAGE_GET_CLASS (page)->app_removed != NULL) { GS_PAGE_GET_CLASS (page)->app_removed (page, helper->app); } }
static void gs_shell_loading_refresh_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object); GsShellLoading *self = GS_SHELL_LOADING (user_data); g_autoptr(GError) error = NULL; /* no longer care */ g_signal_handlers_disconnect_by_data (plugin_loader, self); /* not sure how to handle this */ if (!gs_plugin_loader_refresh_finish (plugin_loader, res, &error)) { g_warning ("failed to load metadata: %s", error->message); return; } /* UI is good to go */ g_signal_emit (self, signals[SIGNAL_REFRESHED], 0); }
/** * gs_shell_category_get_apps_cb: **/ static void gs_shell_category_get_apps_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { gint i = 0; GList *l; GList *list; GsApp *app; GtkWidget *tile; GsShellCategory *shell = GS_SHELL_CATEGORY (user_data); GsShellCategoryPrivate *priv = shell->priv; GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object); _cleanup_error_free_ GError *error = NULL; list = gs_plugin_loader_get_category_apps_finish (plugin_loader, res, &error); if (list == NULL) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("failed to get apps for category apps: %s", error->message); goto out; } gtk_grid_remove_column (GTK_GRID (priv->category_detail_grid), 1); gtk_grid_remove_column (GTK_GRID (priv->category_detail_grid), 0); for (l = list, i = 0; l != NULL; l = l->next, i++) { app = GS_APP (l->data); tile = gs_app_tile_new (app); g_signal_connect (tile, "clicked", G_CALLBACK (app_tile_clicked), shell); gtk_grid_attach (GTK_GRID (priv->category_detail_grid), tile, (i % 2), i / 2, 1, 1); } if (i == 1) gtk_grid_attach (GTK_GRID (priv->category_detail_grid), priv->col1_placeholder, 1, 0, 1, 1); out: gs_plugin_list_free (list); }
static void gs_page_app_purchased_cb (GObject *source, GAsyncResult *res, gpointer user_data) { g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data; GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source); GsPage *page = helper->page; GsPagePrivate *priv = gs_page_get_instance_private (page); gboolean ret; g_autoptr(GsPluginJob) plugin_job = NULL; g_autoptr(GError) error = NULL; ret = gs_plugin_loader_job_action_finish (plugin_loader, res, &error); if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_CANCELLED)) { g_debug ("%s", error->message); return; } if (!ret) { /* try to authenticate then retry */ if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_AUTH_REQUIRED)) { gs_page_authenticate (page, helper->app, gs_utils_get_error_value (error), helper->cancellable, gs_page_purchase_authenticate_cb, helper); g_steal_pointer (&helper); return; } else if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_PURCHASE_NOT_SETUP)) { const gchar *url; /* have we been given a link */ url = gs_utils_get_error_value (error); if (url != NULL) { g_autoptr(GError) error_local = NULL; g_debug ("showing link in: %s", error->message); if (!gtk_show_uri_on_window (GTK_WINDOW (gs_shell_get_window (priv->shell)), url, GDK_CURRENT_TIME, &error_local)) { g_warning ("failed to show URI %s: %s", url, error_local->message); } return; } } g_warning ("failed to purchase %s: %s", gs_app_get_id (helper->app), error->message); return; } if (gs_app_get_state (helper->app) != AS_APP_STATE_AVAILABLE) { g_warning ("no plugin purchased %s", gs_app_get_id (helper->app)); return; } /* now install */ plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL, "interactive", TRUE, "app", helper->app, NULL); gs_plugin_loader_job_process_async (priv->plugin_loader, plugin_job, helper->cancellable, gs_page_app_installed_cb, helper); g_steal_pointer (&helper); }
static void gs_page_app_installed_cb (GObject *source, GAsyncResult *res, gpointer user_data) { g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data; GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source); GsPage *page = helper->page; GsPagePrivate *priv = gs_page_get_instance_private (page); gboolean ret; g_autoptr(GError) error = NULL; ret = gs_plugin_loader_job_action_finish (plugin_loader, res, &error); if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_CANCELLED)) { g_debug ("%s", error->message); return; } if (!ret) { /* try to authenticate then retry */ if (g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_AUTH_REQUIRED)) { gs_page_authenticate (page, helper->app, gs_utils_get_error_value (error), helper->cancellable, gs_page_install_authenticate_cb, helper); g_steal_pointer (&helper); return; } g_warning ("failed to install %s: %s", gs_app_get_id (helper->app), error->message); return; } /* the single update needs system reboot, e.g. for firmware */ if (gs_app_has_quirk (helper->app, GS_APP_QUIRK_NEEDS_REBOOT)) { g_autoptr(GsAppList) list = gs_app_list_new (); gs_app_list_add (list, helper->app); gs_utils_reboot_notify (list); } /* only show this if the window is not active */ if (gs_app_is_installed (helper->app) && helper->action == GS_PLUGIN_ACTION_INSTALL && !gs_shell_is_active (priv->shell) && ((helper->interaction) & GS_SHELL_INTERACTION_NOTIFY) != 0) gs_app_notify_installed (helper->app); if (gs_app_is_installed (helper->app) && GS_PAGE_GET_CLASS (page)->app_installed != NULL) { GS_PAGE_GET_CLASS (page)->app_installed (page, helper->app); } }