From 20b0033852d9d66553a62a6730a78385302d9831 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sun, 27 Jul 2008 21:41:10 +0200 Subject: [PATCH] Added a firdst draft of the tree view. Not working properly yet, still have to debug the code properly, will do it tomorrow. --- libmmanager-gtk/Makefile.am | 6 ++- libmmanager-gtk/mm-gtk-application-store.c | 37 +++++++------ libmmanager-gtk/mm-gtk-application-view.c | 87 ++++++++++++++++++++++++++++++ libmmanager-gtk/mm-gtk-application-view.h | 55 +++++++++++++++++++ libmmanager-gtk/mm-gtk.h | 1 + test/clients/Makefile.am | 12 +++++ 6 files changed, 179 insertions(+), 19 deletions(-) create mode 100644 libmmanager-gtk/mm-gtk-application-view.c create mode 100644 libmmanager-gtk/mm-gtk-application-view.h diff --git a/libmmanager-gtk/Makefile.am b/libmmanager-gtk/Makefile.am index 9cf3db8..7365a3a 100644 --- a/libmmanager-gtk/Makefile.am +++ b/libmmanager-gtk/Makefile.am @@ -16,10 +16,12 @@ libmmanager_gtk_la_includedir=$(includedir)/libmmanager-gtk libmmanager_gtk_la_include_HEADERS = \ mm-gtk.h \ - mm-gtk-application-store.h + mm-gtk-application-store.h \ + mm-gtk-application-view.h libmmanager_gtk_la_SOURCES = \ - mm-gtk-application-store.c + mm-gtk-application-store.c \ + mm-gtk-application-view.c pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libmmanager-gtk.pc diff --git a/libmmanager-gtk/mm-gtk-application-store.c b/libmmanager-gtk/mm-gtk-application-store.c index 9f29557..0dad186 100644 --- a/libmmanager-gtk/mm-gtk-application-store.c +++ b/libmmanager-gtk/mm-gtk-application-store.c @@ -24,15 +24,6 @@ #include #include -#define MM_GTK_APPLICATION_STORE_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_GTK_TYPE_APPLICATION_STORE,\ - MMGtkApplicationStorePrivate)) - -typedef struct _MMGtkApplicationStorePrivate MMGtkApplicationStorePrivate; - -struct _MMGtkApplicationStorePrivate { -}; - /* our parent's model iface */ static GtkTreeModelIface parent_iface = { 0, }; static void mm_gtk_application_store_tree_model_iface_init (GtkTreeModelIface *iface); @@ -54,8 +45,6 @@ mm_gtk_application_store_class_init (MMGtkApplicationStoreClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (klass, sizeof (MMGtkApplicationStorePrivate)); - object_class->finalize = mm_gtk_application_store_finalize; } @@ -69,8 +58,8 @@ populate_store (MMGtkApplicationStore *self) manager = mm_manager_get (); application_list = mm_manager_get_application_list (manager); for (l = application_list; l; l = l->next) { - gtk_tree_store_append (GTK_TREE_STORE (self), &iter, NULL); - gtk_tree_store_set (GTK_TREE_STORE (self), &iter, MM_GTK_APP_STORE_APP_COLUMN, l->data, -1); + gtk_list_store_append (GTK_LIST_STORE (self), &iter); + gtk_list_store_set (GTK_LIST_STORE (self), &iter, MM_GTK_APP_STORE_APP_COLUMN, l->data, -1); } } @@ -110,15 +99,29 @@ value_set_pixbuf_from_app (GValue *val, MMApplication *app) { GAppInfo *app_info; GIcon *icon; - GtkIconInfo *icon_info; + GtkIconInfo *icon_info = NULL; GdkPixbuf *pixbuf; GError *error = NULL; + g_debug ("get app info"); app_info = mm_application_get_app_info (app); + g_debug ("app info %p, get icon", app_info); icon = g_app_info_get_icon (app_info); - icon_info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), - icon, GTK_ICON_SIZE_MENU, 0); - pixbuf = gtk_icon_info_load_icon (icon_info, &error); + g_debug ("icon %p", icon); + if (icon && G_IS_ICON (icon)) { + icon_info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), + icon, GTK_ICON_SIZE_MENU, 0); + } + if (!icon_info) { + icon_info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (), + "application-default-icon", GTK_ICON_SIZE_MENU, 0); + } + if (!icon_info) { + g_warning ("MM-GTK: serious error!"); + return; + } + + pixbuf = gtk_icon_info_load_icon (icon_info, &error); if (!pixbuf) { g_warning ("MM-GTK: Unable to load the icon for the app %s: %s", diff --git a/libmmanager-gtk/mm-gtk-application-view.c b/libmmanager-gtk/mm-gtk-application-view.c new file mode 100644 index 0000000..1945def --- /dev/null +++ b/libmmanager-gtk/mm-gtk-application-view.c @@ -0,0 +1,87 @@ +/* MManager - a Desktop wide manager for multimedia applications. + * + * Copyright (C) 2008 Cosimo Cecchi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "mm-gtk-application-view.h" +#include "mm-gtk-application-store.h" +#include + +#define MM_GTK_APPLICATION_VIEW_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_GTK_TYPE_APPLICATION_VIEW, MMGtkApplicationViewDetails)) + +struct _MMGtkApplicationViewDetails { + MMGtkApplicationStore *store; +}; + +G_DEFINE_TYPE (MMGtkApplicationView, mm_gtk_application_view, GTK_TYPE_TREE_VIEW); + +static GObject * +impl_constructor (GType type, guint n_construct_properties, + GObjectConstructParam *construct_params) +{ + GObject *object; + MMGtkApplicationView *view; + MMGtkApplicationViewDetails *details; + GtkCellRenderer *renderer; + GtkTreeViewColumn *col; + + object = G_OBJECT_CLASS (mm_gtk_application_view_parent_class)->constructor (type, n_construct_properties, + construct_params); + view = MM_GTK_APPLICATION_VIEW (object); + details = MM_GTK_APPLICATION_VIEW_GET_PRIVATE (view); + + details->store = mm_gtk_application_store_new (); + gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (details->store)); + + renderer = gtk_cell_renderer_pixbuf_new (); + col = gtk_tree_view_column_new_with_attributes ("pixbuf", + renderer, + "pixbuf", MM_GTK_APP_STORE_PIXBUF_COLUMN, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), col); + + renderer = gtk_cell_renderer_text_new (); + col = gtk_tree_view_column_new_with_attributes ("app-name", + renderer, + "text", MM_GTK_APP_STORE_NAME_COLUMN, + NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (view), col); + + return object; +} + +static void +mm_gtk_application_view_class_init (MMGtkApplicationViewClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + oclass->constructor = impl_constructor; + + g_type_class_add_private (klass, sizeof (MMGtkApplicationViewDetails)); +} + +static void +mm_gtk_application_view_init (MMGtkApplicationView *self) +{ +} + +MMGtkApplicationView* +mm_gtk_application_view_new (void) +{ + return g_object_new (MM_GTK_TYPE_APPLICATION_VIEW, NULL); +} diff --git a/libmmanager-gtk/mm-gtk-application-view.h b/libmmanager-gtk/mm-gtk-application-view.h new file mode 100644 index 0000000..5b36796 --- /dev/null +++ b/libmmanager-gtk/mm-gtk-application-view.h @@ -0,0 +1,55 @@ +/* MManager - a Desktop wide manager for multimedia applications. + * + * Copyright (C) 2008 Cosimo Cecchi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __MM_GTK_APPLICATION_VIEW__ +#define __MM_GTK_APPLICATION_VIEW__ + +#include +#include + +#define MM_GTK_TYPE_APPLICATION_VIEW mm_gtk_application_view_get_type() +#define MM_GTK_APPLICATION_VIEW(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_GTK_TYPE_APPLICATION_VIEW, MMGtkApplicationView)) +#define MM_GTK_APPLICATION_VIEW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), MM_GTK_TYPE_APPLICATION_VIEW, MMGtkApplicationViewClass)) +#define MM_GTK_IS_APPLICATION_VIEW(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_GTK_TYPE_APPLICATION_VIEW)) +#define MM_GTK_IS_APPLICATION_VIEW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_GTK_TYPE_APPLICATION_VIEW)) +#define MM_GTK_APPLICATION_VIEW_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_GTK_TYPE_APPLICATION_VIEW, MMGtkApplicationViewClass)) + +typedef struct _MMGtkApplicationView MMGtkApplicationView; +typedef struct _MMGtkApplicationViewClass MMGtkApplicationViewClass; +typedef struct _MMGtkApplicationViewDetails MMGtkApplicationViewDetails; + +struct _MMGtkApplicationView { + GtkTreeView parent; + MMGtkApplicationViewDetails *details; +}; + +struct _MMGtkApplicationViewClass { + GtkTreeViewClass parent_class; +}; + +GType mm_gtk_application_view_get_type (void); +MMGtkApplicationView* mm_gtk_application_view_new (void); + +#endif /* __MM_GTK_APPLICATION_VIEW__ */ diff --git a/libmmanager-gtk/mm-gtk.h b/libmmanager-gtk/mm-gtk.h index 511df89..5bee303 100644 --- a/libmmanager-gtk/mm-gtk.h +++ b/libmmanager-gtk/mm-gtk.h @@ -22,5 +22,6 @@ #define __MM_GTK_H__ #include "mm-gtk-application-store.h" +#include "mm-gtk-application-view.h" #endif /* __MM_H__ */ diff --git a/test/clients/Makefile.am b/test/clients/Makefile.am index 2ed1ffd..59f2288 100644 --- a/test/clients/Makefile.am +++ b/test/clients/Makefile.am @@ -7,6 +7,7 @@ INCLUDES = \ -I. \ -I$(srcdir) \ -I$(top_srcdir)/src \ + -I$(top_srcdir)/libmmanager-gtk \ $(MMEDIAMANAGER_CFLAGS) LDADD = \ @@ -17,6 +18,7 @@ noinst_PROGRAMS = \ mm-test-dbus-client \ mm-test-dbus-register \ mm-test-dbus-spawn \ + mm-test-gtk \ mm-test-serialize mm_test_applications_SOURCES = \ @@ -47,6 +49,16 @@ mm_test_dbus_register_CFLAGS = \ mm_test_dbus_spawn_SOURCES = \ test-dbus-spawn.c +mm_test_gtk_SOURCES = \ + test-gtk.c + +mm_test_gtk_LDADD = \ + $(top_builddir)/libmmanager-gtk/libmmanager-gtk.la \ + $(GTK_LIBS) + +mm_test_gtk_CFLAGS = \ + $(GTK_CFLAGS) + mm_test_serialize_SOURCES = \ test-serialize.c -- 2.11.4.GIT