Almost there to pass distcheck.
[mmediamanager.git] / libmmanager-gtk / mm-gtk-application-view.c
blob05fdcc49492d0d21aadf974205101a6f749fd784
1 /* MManager - a Desktop wide manager for multimedia applications.
3 * Copyright (C) 2008 Cosimo Cecchi <cosimoc@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include "mm-gtk-application-view.h"
22 #include "mm-gtk-application-store.h"
24 #include "libmmanager/mm-application.h"
25 #include "libmmanager/mm-category.h"
26 #include "libmmanager/mm-type-builtins.h"
28 #include <gtk/gtk.h>
30 #define MM_GTK_APPLICATION_VIEW_GET_PRIVATE(o) \
31 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_GTK_TYPE_APPLICATION_VIEW, MMGtkApplicationViewPrivate))
33 struct _MMGtkApplicationViewPrivate {
34 MMGtkApplicationStore *store;
37 enum {
38 APPLICATION_SELECTED,
39 CATEGORY_SELECTED,
40 MMTYPE_SELECTED,
41 LAST_SIGNAL
44 static guint view_signals[LAST_SIGNAL] = { 0 };
46 G_DEFINE_TYPE (MMGtkApplicationView, mm_gtk_application_view, GTK_TYPE_TREE_VIEW);
48 static void
49 view_selection_changed_cb (GtkTreeSelection *selection,
50 MMGtkApplicationView *view)
52 GtkTreeIter iter;
53 GtkTreeModel *model;
54 GValue val = { 0, };
55 int depth;
57 gtk_tree_selection_get_selected (selection, &model, &iter);
58 depth = gtk_tree_store_iter_depth (GTK_TREE_STORE (model),
59 &iter);
60 if (depth == 0) {
61 MMApplicationType type;
63 /* we're selecting an application type */
64 gtk_tree_model_get_value (model, &iter,
65 MM_GTK_APP_STORE_TYPE_COLUMN,
66 &val);
67 type = g_value_get_enum (&val);
69 g_signal_emit (view, view_signals[MMTYPE_SELECTED],
70 0, type);
71 } else if (depth == 1) {
72 MMApplication *app;
74 /* we're selecting an application */
75 gtk_tree_model_get_value (model, &iter,
76 MM_GTK_APP_STORE_APP_COLUMN,
77 &val);
78 app = g_value_dup_object (&val);
79 g_signal_emit (view, view_signals[APPLICATION_SELECTED],
80 0, app);
81 } else if (depth == 2) {
82 MMCategory *cat;
84 /* we're selecting a category */
85 gtk_tree_model_get_value (model, &iter,
86 MM_GTK_APP_STORE_CAT_COLUMN,
87 &val);
88 cat = g_value_dup_object (&val);
89 g_signal_emit (view, view_signals[CATEGORY_SELECTED],
90 0, cat);
93 g_value_unset (&val);
96 static GObject *
97 impl_constructor (GType type, guint n_construct_properties,
98 GObjectConstructParam *construct_params)
100 GObject *object;
101 MMGtkApplicationView *view;
102 MMGtkApplicationViewPrivate *details;
103 GtkCellRenderer *renderer;
104 GtkTreeViewColumn *col;
105 GtkTreeSelection *selection;
107 object = G_OBJECT_CLASS (mm_gtk_application_view_parent_class)->constructor (type, n_construct_properties,
108 construct_params);
109 view = MM_GTK_APPLICATION_VIEW (object);
110 details = MM_GTK_APPLICATION_VIEW_GET_PRIVATE (view);
112 details->store = mm_gtk_application_store_new ();
113 gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (details->store));
115 renderer = gtk_cell_renderer_pixbuf_new ();
116 col = gtk_tree_view_column_new_with_attributes ("gicon",
117 renderer,
118 "gicon", MM_GTK_APP_STORE_GICON_COLUMN,
119 NULL);
120 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
122 renderer = gtk_cell_renderer_text_new ();
123 col = gtk_tree_view_column_new_with_attributes ("app-name",
124 renderer,
125 "text", MM_GTK_APP_STORE_NAME_COLUMN,
126 NULL);
127 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
129 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
130 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
131 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
132 g_signal_connect_object (selection, "changed",
133 G_CALLBACK (view_selection_changed_cb), view, 0);
135 return object;
138 static void
139 mm_gtk_application_view_class_init (MMGtkApplicationViewClass *klass)
141 GObjectClass *oclass = G_OBJECT_CLASS (klass);
142 oclass->constructor = impl_constructor;
145 * MMGtkApplicationView::application-selected:
146 * @view: the view.
147 * @application: the application that was selected.
149 * Gets emitted when the user selects a #MMApplication inside the
150 * treeview.
153 view_signals[APPLICATION_SELECTED] =
154 g_signal_new ("application_selected",
155 G_OBJECT_CLASS_TYPE (oclass),
156 G_SIGNAL_RUN_LAST,
157 G_STRUCT_OFFSET (MMGtkApplicationViewClass, application_selected),
158 NULL, NULL,
159 g_cclosure_marshal_VOID__OBJECT,
160 G_TYPE_NONE,
162 MM_TYPE_APPLICATION);
165 * MMGtkApplicationView::category-selected:
166 * @view: the view.
167 * @category: the category that was selected.
169 * Gets emitted when the user selects a #MMCategory inside the treeview.
172 view_signals[CATEGORY_SELECTED] =
173 g_signal_new ("category_selected",
174 G_OBJECT_CLASS_TYPE (oclass),
175 G_SIGNAL_RUN_LAST,
176 G_STRUCT_OFFSET (MMGtkApplicationViewClass, category_selected),
177 NULL, NULL,
178 g_cclosure_marshal_VOID__OBJECT,
179 G_TYPE_NONE,
181 MM_TYPE_CATEGORY);
184 * MMGtkApplicationView::mmtype-selected:
185 * @view: the view.
186 * @mm_type: the #MMApplicationType that was selected.
188 * Gets emitted when the user selects a #MMApplicationType inside the
189 * treeview.
192 view_signals[MMTYPE_SELECTED] =
193 g_signal_new ("mmtype_selected",
194 G_OBJECT_CLASS_TYPE (oclass),
195 G_SIGNAL_RUN_LAST,
196 G_STRUCT_OFFSET (MMGtkApplicationViewClass, mmtype_selected),
197 NULL, NULL,
198 g_cclosure_marshal_VOID__ENUM,
199 G_TYPE_NONE,
201 MM_TYPE_MAPPLICATION_TYPE);
203 g_type_class_add_private (klass, sizeof (MMGtkApplicationViewPrivate));
206 static void
207 mm_gtk_application_view_init (MMGtkApplicationView *self)
209 /* do nothing */
212 /* public methods */
215 * mm_gtk_application_view_new:
217 * Builds a #GtkTreeView containing all the information about
218 * #MMApplication and #MMCategory objects registered in the library.
220 * Return value: an already filled ready-to-use #MMGtkApplicationView.
223 MMGtkApplicationView*
224 mm_gtk_application_view_new (void)
226 return g_object_new (MM_GTK_TYPE_APPLICATION_VIEW, NULL);