From 17d9b78151bc366e65054a505e47aa5cc96a5153 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 29 Jul 2008 18:46:17 +0200 Subject: [PATCH] Complete signals in the application view. Rework icon code in the store and fix a bug in MMCategory. --- libmmanager-gtk/mm-gtk-application-store.c | 30 +++++++++++-- libmmanager-gtk/mm-gtk-application-view.c | 69 ++++++++++++++++++++++++++---- libmmanager-gtk/mm-gtk-application-view.h | 6 +++ src/mm-category.c | 2 +- 4 files changed, 94 insertions(+), 13 deletions(-) diff --git a/libmmanager-gtk/mm-gtk-application-store.c b/libmmanager-gtk/mm-gtk-application-store.c index 83a5c0f..77dd6d4 100644 --- a/libmmanager-gtk/mm-gtk-application-store.c +++ b/libmmanager-gtk/mm-gtk-application-store.c @@ -28,6 +28,7 @@ /* our parent's model iface */ static GtkTreeModelIface parent_iface = { 0, }; static void mm_gtk_application_store_tree_model_iface_init (GtkTreeModelIface *iface); +static void value_set_gicon_from_mm_type (GValue *val, MMApplicationType type); G_DEFINE_TYPE_EXTENDED (MMGtkApplicationStore, mm_gtk_application_store, GTK_TYPE_TREE_STORE, 0, @@ -162,11 +163,34 @@ impl_get_column_type (GtkTreeModel *self, gint column) } static void +value_set_gicon_from_cat (GValue *val, + MMCategory *cat) +{ + GIcon *icon; + + icon = mm_category_get_icon (cat); + if (!icon || !G_IS_ICON (icon)) { + /* fallback to a generic mimetype icon */ + + MMApplicationType type; + MMApplication *application; + + application = mm_category_get_application (cat); + g_object_get (application, "supported-type", &type, NULL); + value_set_gicon_from_mm_type (val, type); + g_object_unref (application); + } else { + g_value_take_object (val, icon); + } +} + +static void get_value_for_category (GtkTreeModel *self, GtkTreeIter *iter, gint column, GValue *value) { MMCategory *cat; GValue *obj; + GIcon *icon; obj = mm_gtk_application_store_get_object (MM_GTK_APPLICATION_STORE (self), iter, MM_GTK_APP_STORE_CAT_COLUMN); @@ -182,7 +206,7 @@ get_value_for_category (GtkTreeModel *self, GtkTreeIter *iter, g_value_take_object (value, mm_category_get_application (cat)); break; case MM_GTK_APP_STORE_GICON_COLUMN: - g_value_take_object (value, mm_category_get_icon (cat)); + value_set_gicon_from_cat (value, cat); break; case MM_GTK_APP_STORE_NAME_COLUMN: g_value_set_string (value, mm_category_get_name (cat)); @@ -280,8 +304,8 @@ value_set_name_from_mm_type (GValue *val, MMApplicationType type) { static const char *messages[] = { - N_("Music"), N_("Photos"), + N_("Music"), N_("Videos") }; @@ -309,7 +333,7 @@ value_set_gicon_from_mm_type (GValue *val, break; } - g_value_take_object (val, icon); + g_value_take_object (val, icon); } static void diff --git a/libmmanager-gtk/mm-gtk-application-view.c b/libmmanager-gtk/mm-gtk-application-view.c index d98c444..bb10751 100644 --- a/libmmanager-gtk/mm-gtk-application-view.c +++ b/libmmanager-gtk/mm-gtk-application-view.c @@ -22,6 +22,7 @@ #include "mm-gtk-application-store.h" #include +#include #include @@ -34,6 +35,8 @@ struct _MMGtkApplicationViewDetails { enum { APPLICATION_SELECTED, + CATEGORY_SELECTED, + MMTYPE_SELECTED, LAST_SIGNAL }; @@ -48,17 +51,45 @@ view_selection_changed_cb (GtkTreeSelection *selection, GtkTreeIter iter; GtkTreeModel *model; GValue val = { 0, }; - MMApplication *app; + int depth; gtk_tree_selection_get_selected (selection, &model, &iter); - gtk_tree_model_get_value (model, &iter, - MM_GTK_APP_STORE_APP_COLUMN, - &val); - app = MM_APPLICATION (g_value_dup_object (&val)); + depth = gtk_tree_store_iter_depth (GTK_TREE_STORE (model), + &iter); + if (depth == 0) { + MMApplicationType type; + + /* we're selecting an application type */ + gtk_tree_model_get_value (model, &iter, + MM_GTK_APP_STORE_TYPE_COLUMN, + &val); + type = g_value_get_enum (&val); + + g_signal_emit (view, view_signals[MMTYPE_SELECTED], + 0, type); + } else if (depth == 1) { + MMApplication *app; + + /* we're selecting an application */ + gtk_tree_model_get_value (model, &iter, + MM_GTK_APP_STORE_APP_COLUMN, + &val); + app = g_value_dup_object (&val); + g_signal_emit (view, view_signals[APPLICATION_SELECTED], + 0, app); + } else if (depth == 2) { + MMCategory *cat; + + /* we're selecting a category */ + gtk_tree_model_get_value (model, &iter, + MM_GTK_APP_STORE_CAT_COLUMN, + &val); + cat = g_value_dup_object (&val); + g_signal_emit (view, view_signals[CATEGORY_SELECTED], + 0, cat); + } + g_value_unset (&val); - - g_signal_emit (view, view_signals[APPLICATION_SELECTED], - 0, app); } static GObject * @@ -119,7 +150,27 @@ mm_gtk_application_view_class_init (MMGtkApplicationViewClass *klass) G_TYPE_NONE, 1, G_TYPE_POINTER); - + view_signals[CATEGORY_SELECTED] = + g_signal_new ("category_selected", + G_OBJECT_CLASS_TYPE (oclass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MMGtkApplicationViewClass, category_selected), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, + 1, + G_TYPE_POINTER); + view_signals[MMTYPE_SELECTED] = + g_signal_new ("mmtype_selected", + G_OBJECT_CLASS_TYPE (oclass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (MMGtkApplicationViewClass, mmtype_selected), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, + 1, + G_TYPE_POINTER); + g_type_class_add_private (klass, sizeof (MMGtkApplicationViewDetails)); } diff --git a/libmmanager-gtk/mm-gtk-application-view.h b/libmmanager-gtk/mm-gtk-application-view.h index 891adfe..26d278d 100644 --- a/libmmanager-gtk/mm-gtk-application-view.h +++ b/libmmanager-gtk/mm-gtk-application-view.h @@ -22,6 +22,8 @@ #define __MM_GTK_APPLICATION_VIEW__ #include +#include +#include #include #include @@ -52,6 +54,10 @@ struct _MMGtkApplicationViewClass { void (* application_selected) (MMGtkApplicationView *view, MMApplication *application); + void (* category_selected) (MMGtkApplicationView *view, + MMCategory *category); + void (* mmtype_selected) (MMGtkApplicationView *view, + MMApplicationType type); }; GType mm_gtk_application_view_get_type (void); diff --git a/src/mm-category.c b/src/mm-category.c index ac0b697..fb64289 100644 --- a/src/mm-category.c +++ b/src/mm-category.c @@ -95,7 +95,7 @@ mm_category_get_icon (MMCategory *c) g_return_val_if_fail (c != NULL, NULL); g_return_val_if_fail (MM_IS_CATEGORY (c), NULL); - return g_object_ref (c->details->icon); + return c->details->icon ? g_object_ref (c->details->icon) : NULL; } const char * -- 2.11.4.GIT