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"
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
;
44 static guint view_signals
[LAST_SIGNAL
] = { 0 };
46 G_DEFINE_TYPE (MMGtkApplicationView
, mm_gtk_application_view
, GTK_TYPE_TREE_VIEW
);
49 view_selection_changed_cb (GtkTreeSelection
*selection
,
50 MMGtkApplicationView
*view
)
57 gtk_tree_selection_get_selected (selection
, &model
, &iter
);
58 depth
= gtk_tree_store_iter_depth (GTK_TREE_STORE (model
),
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
,
67 type
= g_value_get_enum (&val
);
69 g_signal_emit (view
, view_signals
[MMTYPE_SELECTED
],
71 } else if (depth
== 1) {
74 /* we're selecting an application */
75 gtk_tree_model_get_value (model
, &iter
,
76 MM_GTK_APP_STORE_APP_COLUMN
,
78 app
= g_value_dup_object (&val
);
79 g_signal_emit (view
, view_signals
[APPLICATION_SELECTED
],
81 } else if (depth
== 2) {
84 /* we're selecting a category */
85 gtk_tree_model_get_value (model
, &iter
,
86 MM_GTK_APP_STORE_CAT_COLUMN
,
88 cat
= g_value_dup_object (&val
);
89 g_signal_emit (view
, view_signals
[CATEGORY_SELECTED
],
97 impl_constructor (GType type
, guint n_construct_properties
,
98 GObjectConstructParam
*construct_params
)
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
,
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",
118 "gicon", MM_GTK_APP_STORE_GICON_COLUMN
,
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",
125 "text", MM_GTK_APP_STORE_NAME_COLUMN
,
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);
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:
147 * @application: the application that was selected.
149 * Gets emitted when the user selects a #MMApplication inside the
153 view_signals
[APPLICATION_SELECTED
] =
154 g_signal_new ("application_selected",
155 G_OBJECT_CLASS_TYPE (oclass
),
157 G_STRUCT_OFFSET (MMGtkApplicationViewClass
, application_selected
),
159 g_cclosure_marshal_VOID__OBJECT
,
162 MM_TYPE_APPLICATION
);
165 * MMGtkApplicationView::category-selected:
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
),
176 G_STRUCT_OFFSET (MMGtkApplicationViewClass
, category_selected
),
178 g_cclosure_marshal_VOID__OBJECT
,
184 * MMGtkApplicationView::mmtype-selected:
186 * @mm_type: the #MMApplicationType that was selected.
188 * Gets emitted when the user selects a #MMApplicationType inside the
192 view_signals
[MMTYPE_SELECTED
] =
193 g_signal_new ("mmtype_selected",
194 G_OBJECT_CLASS_TYPE (oclass
),
196 G_STRUCT_OFFSET (MMGtkApplicationViewClass
, mmtype_selected
),
198 g_cclosure_marshal_VOID__ENUM
,
201 MM_TYPE_MAPPLICATION_TYPE
);
203 g_type_class_add_private (klass
, sizeof (MMGtkApplicationViewPrivate
));
207 mm_gtk_application_view_init (MMGtkApplicationView
*self
)
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
);