[gnome-software] Get the featured applications from the plugin system
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Get the featured applications from the plugin system
- Date: Fri, 16 Aug 2013 13:56:27 +0000 (UTC)
commit 8e6a2d846d73181e377e55c39725de7c47f39c4b
Author: Richard Hughes <richard hughsie com>
Date: Fri Aug 16 14:55:01 2013 +0100
Get the featured applications from the plugin system
This ensures we have a correctly populated GsApp which we can query and remove/install.
data/featured-firefox.png | Bin 33865 -> 71392 bytes
src/gs-app.c | 24 +++++++
src/gs-app.h | 3 +
src/gs-main.c | 60 ++++++++++++-----
src/gs-plugin-loader.c | 102 +++++++++++++++++++++++++++-
src/gs-plugin-loader.h | 7 ++
src/gs-plugin.h | 4 +
src/plugins/Makefile.am | 6 ++
src/plugins/gs-plugin-hardcoded-featured.c | 79 +++++++++++++++++++++
9 files changed, 267 insertions(+), 18 deletions(-)
---
diff --git a/data/featured-firefox.png b/data/featured-firefox.png
index 0570a25..f32154b 100644
Binary files a/data/featured-firefox.png and b/data/featured-firefox.png differ
diff --git a/src/gs-app.c b/src/gs-app.c
index 4072765..3fdf1e7 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -41,6 +41,7 @@ struct GsAppPrivate
GsAppState state;
GHashTable *metadata;
GdkPixbuf *pixbuf;
+ GdkPixbuf *featured_pixbuf;
GPtrArray *related; /* of GsApp */
};
@@ -181,6 +182,27 @@ gs_app_set_pixbuf (GsApp *app, GdkPixbuf *pixbuf)
}
/**
+ * gs_app_get_featured_pixbuf:
+ */
+GdkPixbuf *
+gs_app_get_featured_pixbuf (GsApp *app)
+{
+ g_return_val_if_fail (GS_IS_APP (app), NULL);
+ return app->priv->featured_pixbuf;
+}
+
+/**
+ * gs_app_set_featured_pixbuf:
+ */
+void
+gs_app_set_featured_pixbuf (GsApp *app, GdkPixbuf *pixbuf)
+{
+ g_return_if_fail (GS_IS_APP (app));
+ g_return_if_fail (app->priv->featured_pixbuf == NULL);
+ app->priv->featured_pixbuf = g_object_ref (pixbuf);
+}
+
+/**
* gs_app_get_version:
*/
const gchar *
@@ -605,6 +627,8 @@ gs_app_finalize (GObject *object)
g_ptr_array_unref (priv->related);
if (priv->pixbuf != NULL)
g_object_unref (priv->pixbuf);
+ if (priv->featured_pixbuf != NULL)
+ g_object_unref (priv->featured_pixbuf);
G_OBJECT_CLASS (gs_app_parent_class)->finalize (object);
}
diff --git a/src/gs-app.h b/src/gs-app.h
index 8cf7a5c..b2ac207 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -103,6 +103,9 @@ void gs_app_set_screenshot (GsApp *app,
GdkPixbuf *gs_app_get_pixbuf (GsApp *app);
void gs_app_set_pixbuf (GsApp *app,
GdkPixbuf *pixbuf);
+GdkPixbuf *gs_app_get_featured_pixbuf (GsApp *app);
+void gs_app_set_featured_pixbuf (GsApp *app,
+ GdkPixbuf *pixbuf);
const gchar *gs_app_get_metadata_item (GsApp *app,
const gchar *key);
void gs_app_set_metadata (GsApp *app,
diff --git a/src/gs-main.c b/src/gs-main.c
index dab32fb..25b6745 100644
--- a/src/gs-main.c
+++ b/src/gs-main.c
@@ -1298,39 +1298,64 @@ gs_main_back_button_cb (GtkWidget *widget, GsMainPrivate *priv)
}
/**
- * gs_main_setup_featured:
+ * gs_main_get_featured_cb:
**/
static void
-gs_main_setup_featured (GsMainPrivate *priv)
+gs_main_get_featured_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GError *error = NULL;
GdkPixbuf *pixbuf;
+ GError *error = NULL;
+ GList *list;
+ GsApp *app;
+ GsMainPrivate *priv = (GsMainPrivate *) user_data;
+ GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
GtkImage *image;
- GtkWidget *button;
- GsApp *app;
+ GtkWidget *button;
+ GtkWidget *widget;
- /* 1 : TODO: generate these automatically */
- image = GTK_IMAGE (gtk_builder_get_object (priv->builder, "featured_image"));
- pixbuf = gdk_pixbuf_new_from_file_at_scale (DATADIR "/gnome-software/featured-firefox.png", -1, -1,
TRUE, &error);
- if (pixbuf == NULL) {
- g_warning ("failed to load featured tile: %s", error->message);
+ list = gs_plugin_loader_get_featured_finish (plugin_loader,
+ res,
+ &error);
+ if (list == NULL) {
+ g_warning ("failed to get featured apps: %s", error->message);
g_error_free (error);
goto out;
}
- gtk_image_set_from_pixbuf (image, pixbuf);
- g_object_unref (pixbuf);
- button = GTK_WIDGET (gtk_builder_get_object (priv->builder, "featured_button"));
- app = gs_app_new ("firefox");
- g_object_set_data_full (G_OBJECT (button), "app", app, g_object_unref);
- g_signal_connect (button, "clicked",
- G_CALLBACK (app_tile_clicked), priv);
+ /* at the moment, we only care about the first app */
+ app = GS_APP (list->data);
+ image = GTK_IMAGE (gtk_builder_get_object (priv->builder, "featured_image"));
+ pixbuf = gs_app_get_featured_pixbuf (app);
+ gtk_image_set_from_pixbuf (image, pixbuf);
+ button = GTK_WIDGET (gtk_builder_get_object (priv->builder, "featured_button"));
+ g_object_set_data_full (G_OBJECT (button), "app", app, g_object_unref);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (app_tile_clicked), priv);
+ /* focus back to the text extry */
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
+ gtk_widget_grab_focus (widget);
out:
+ g_list_free (list);
return;
}
/**
+ * gs_main_setup_featured:
+ **/
+static void
+gs_main_setup_featured (GsMainPrivate *priv)
+{
+ /* get popular apps */
+ gs_plugin_loader_get_featured_async (priv->plugin_loader,
+ priv->cancellable,
+ gs_main_get_featured_cb,
+ priv);
+}
+
+/**
* gs_main_utf8_filter_helper:
**/
static gboolean
@@ -1760,6 +1785,7 @@ main (int argc, char **argv)
}
/* FIXME: use GSettings key rather than hard-coding this */
+ gs_plugin_loader_set_enabled (priv->plugin_loader, "hardcoded-featured", TRUE);
gs_plugin_loader_set_enabled (priv->plugin_loader, "hardcoded-kind", TRUE);
gs_plugin_loader_set_enabled (priv->plugin_loader, "hardcoded-popular", TRUE);
gs_plugin_loader_set_enabled (priv->plugin_loader, "hardcoded-ratings", TRUE);
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 231b9b8..53ffb84 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -167,7 +167,7 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
g_set_error (error,
GS_PLUGIN_LOADER_ERROR,
GS_PLUGIN_LOADER_ERROR_FAILED,
- "no updates to show");
+ "no results to show");
goto out;
}
out:
@@ -639,6 +639,106 @@ gs_plugin_loader_get_popular_finish (GsPluginLoader *plugin_loader,
/******************************************************************************/
/**
+ * cd_plugin_loader_get_featured_thread_cb:
+ **/
+static void
+cd_plugin_loader_get_featured_thread_cb (GSimpleAsyncResult *res,
+ GObject *object,
+ GCancellable *cancellable)
+{
+ GError *error = NULL;
+ GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
+ GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) g_object_get_data (G_OBJECT
(cancellable), "state");
+
+ /* do things that would block */
+ state->list = gs_plugin_loader_run_results (plugin_loader,
+ "gs_plugin_add_featured",
+ cancellable,
+ &error);
+ if (state->list == NULL) {
+ cd_plugin_loader_get_all_state_finish (state, error);
+ g_error_free (error);
+ goto out;
+ }
+ state->list = gs_plugin_loader_remove_invalid (state->list);
+ if (state->list == NULL) {
+ g_set_error_literal (&error,
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_FAILED,
+ "no featured apps to show");
+ cd_plugin_loader_get_all_state_finish (state, error);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* success */
+ state->ret = TRUE;
+ cd_plugin_loader_get_all_state_finish (state, NULL);
+out:
+ return;
+}
+
+/**
+ * gs_plugin_loader_get_featured_async:
+ **/
+void
+gs_plugin_loader_get_featured_async (GsPluginLoader *plugin_loader,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GCancellable *tmp;
+ GsPluginLoaderAsyncState *state;
+
+ g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
+ /* save state */
+ state = g_slice_new0 (GsPluginLoaderAsyncState);
+ state->res = g_simple_async_result_new (G_OBJECT (plugin_loader),
+ callback,
+ user_data,
+ gs_plugin_loader_get_featured_async);
+ state->plugin_loader = g_object_ref (plugin_loader);
+ if (cancellable != NULL)
+ state->cancellable = g_object_ref (cancellable);
+
+ /* run in a thread */
+ tmp = g_cancellable_new ();
+ g_object_set_data (G_OBJECT (tmp), "state", state);
+ g_simple_async_result_run_in_thread (G_SIMPLE_ASYNC_RESULT (state->res),
+ cd_plugin_loader_get_featured_thread_cb,
+ 0,
+ (GCancellable *) tmp);
+ g_object_unref (tmp);
+}
+
+/**
+ * gs_plugin_loader_get_featured_finish:
+ **/
+GList *
+gs_plugin_loader_get_featured_finish (GsPluginLoader *plugin_loader,
+ GAsyncResult *res,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), NULL);
+ g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (res), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ /* failed */
+ simple = G_SIMPLE_ASYNC_RESULT (res);
+ if (g_simple_async_result_propagate_error (simple, error))
+ return NULL;
+
+ /* grab detail */
+ return g_list_copy (g_simple_async_result_get_op_res_gpointer (simple));
+}
+
+/******************************************************************************/
+
+/**
* gs_plugin_loader_search:
**/
GList *
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index b22cbbf..586f1e4 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -84,6 +84,13 @@ void gs_plugin_loader_get_popular_async (GsPluginLoader *plugin_loader,
GList *gs_plugin_loader_get_popular_finish (GsPluginLoader *plugin_loader,
GAsyncResult *res,
GError **error);
+void gs_plugin_loader_get_featured_async (GsPluginLoader *plugin_loader,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+GList *gs_plugin_loader_get_featured_finish (GsPluginLoader *plugin_loader,
+ GAsyncResult *res,
+ GError **error);
GList *gs_plugin_loader_search (GsPluginLoader *plugin_loader,
const gchar *value,
GCancellable *cancellable,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 4248e6b..cf1e45c 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -120,6 +120,10 @@ gboolean gs_plugin_add_popular (GsPlugin *plugin,
GList **list,
GCancellable *cancellable,
GError **error);
+gboolean gs_plugin_add_featured (GsPlugin *plugin,
+ GList **list,
+ GCancellable *cancellable,
+ GError **error);
gboolean gs_plugin_refine (GsPlugin *plugin,
GList *list,
GCancellable *cancellable,
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 781d9cb..3bb97f7 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -30,6 +30,7 @@ plugin_LTLIBRARIES = \
libgs_plugin_datadir_filename.la \
libgs_plugin_desktopdb.la \
libgs_plugin_dummy.la \
+ libgs_plugin_hardcoded-featured.la \
libgs_plugin_hardcoded-kind.la \
libgs_plugin_hardcoded-popular.la \
libgs_plugin_hardcoded-ratings.la \
@@ -52,6 +53,11 @@ libgs_plugin_hardcoded_popular_la_LIBADD = $(GS_PLUGIN_LIBS)
libgs_plugin_hardcoded_popular_la_LDFLAGS = -module -avoid-version
libgs_plugin_hardcoded_popular_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
+libgs_plugin_hardcoded_featured_la_SOURCES = gs-plugin-hardcoded-featured.c
+libgs_plugin_hardcoded_featured_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_hardcoded_featured_la_LDFLAGS = -module -avoid-version
+libgs_plugin_hardcoded_featured_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
+
libgs_plugin_hardcoded_ratings_la_SOURCES = gs-plugin-hardcoded-ratings.c
libgs_plugin_hardcoded_ratings_la_LIBADD = $(GS_PLUGIN_LIBS) $(SQLITE_LIBS)
libgs_plugin_hardcoded_ratings_la_LDFLAGS = -module -avoid-version
diff --git a/src/plugins/gs-plugin-hardcoded-featured.c b/src/plugins/gs-plugin-hardcoded-featured.c
new file mode 100644
index 0000000..1eb7814
--- /dev/null
+++ b/src/plugins/gs-plugin-hardcoded-featured.c
@@ -0,0 +1,79 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011-2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <gs-plugin.h>
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+ return "hardcoded-featured";
+}
+
+/**
+ * gs_plugin_get_priority:
+ */
+gdouble
+gs_plugin_get_priority (GsPlugin *plugin)
+{
+ return -100.0f;
+}
+
+/**
+ * gs_plugin_add_featured:
+ */
+gboolean
+gs_plugin_add_featured (GsPlugin *plugin,
+ GList **list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = TRUE;
+ gchar *path;
+ GdkPixbuf *pixbuf;
+ GsApp *app;
+ guint i;
+ const gchar *apps[] = {
+ "firefox",
+ NULL };
+
+ /* just add each one */
+ for (i = 0; apps[i] != NULL; i++) {
+ app = gs_app_new (apps[i]);
+ gs_plugin_add_app (list, app);
+ path = g_strdup_printf ("%s/gnome-software/featured-%s.png",
+ DATADIR, apps[i]);
+ pixbuf = gdk_pixbuf_new_from_file_at_scale (path, -1, -1, TRUE, error);
+ g_free (path);
+ if (pixbuf == NULL) {
+ ret = FALSE;
+ goto out;
+ }
+ gs_app_set_featured_pixbuf (app, pixbuf);
+ g_object_unref (pixbuf);
+ }
+out:
+ return ret;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]