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-filter-builder.h"
22 #include "mm-gtk-attribute-store.h"
23 #include "libmmanager/mm-attribute-manager.h"
24 #include "libmmanager/mm-attribute-base-manager.h"
27 #include <glib/gi18n.h>
29 G_DEFINE_TYPE (MMGtkFilterBuilder
, mm_gtk_filter_builder
, GTK_TYPE_VBOX
);
31 #define MM_GTK_FILTER_BUILDER_GET_PRIVATE(o) \
32 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_GTK_TYPE_FILTER_BUILDER, MMGtkFilterBuilderDetails))
34 struct _MMGtkFilterBuilderDetails
{
35 GtkListStore
*filter_store
;
36 MMGtkAttributeStore
*attribute_store
;
37 GtkWidget
*filter_view
;
39 GHashTable
*attr_managers
;
42 GtkWidget
*attr_combo
;
43 GtkWidget
*logic_combo
;
44 GtkWidget
*value_entry
;
47 static const char * logic_strs
[] = {
51 N_("greater or equal than"),
52 N_("less or equal than"),
56 mm_gtk_filter_builder_class_init (MMGtkFilterBuilderClass
*klass
)
58 g_type_class_add_private (klass
, sizeof (MMGtkFilterBuilderDetails
));
62 populate_logic_combo (GtkWidget
*combo
)
66 for (idx
= 0; idx
< G_N_ELEMENTS (logic_strs
); idx
++) {
67 gtk_combo_box_append_text (GTK_COMBO_BOX (combo
), logic_strs
[idx
]);
70 gtk_combo_box_set_active (GTK_COMBO_BOX (combo
), 0);
74 cat_combo_changed_cb (GtkComboBox
*combo
,
75 MMGtkFilterBuilder
*self
)
78 MMAttributeManager
*attr_manager
;
80 idx
= gtk_combo_box_get_active (combo
);
81 attr_manager
= g_hash_table_lookup (self
->details
->attr_managers
,
83 mm_gtk_attribute_store_set_from_attribute_manager (self
->details
->attribute_store
,
85 gtk_combo_box_set_model (GTK_COMBO_BOX (self
->details
->attr_combo
),
86 GTK_TREE_MODEL (self
->details
->attribute_store
));
87 gtk_combo_box_set_active (GTK_COMBO_BOX (self
->details
->attr_combo
), 0);
91 mm_gtk_filter_builder_init (MMGtkFilterBuilder
*self
)
93 MMGtkFilterBuilderDetails
*details
= self
->details
=
94 MM_GTK_FILTER_BUILDER_GET_PRIVATE (self
);
95 GtkWidget
*filter_view
;
96 GtkTreeViewColumn
*column
;
97 GtkCellRenderer
*renderer
;
101 details
->attribute_store
= mm_gtk_attribute_store_new ();
102 details
->attr_managers
= g_hash_table_new (g_int_hash
, g_int_equal
);
104 details
->filter_store
= gtk_list_store_new (3,
105 G_TYPE_STRING
, /* attribute name */
106 G_TYPE_STRING
, /* operator */
107 G_TYPE_STRING
); /* value */
108 filter_view
= gtk_tree_view_new_with_model (GTK_TREE_MODEL (details
->filter_store
));
109 renderer
= gtk_cell_renderer_text_new ();
110 column
= gtk_tree_view_column_new_with_attributes (_("Parameter"),
114 gtk_tree_view_append_column (GTK_TREE_VIEW (filter_view
), column
);
115 column
= gtk_tree_view_column_new_with_attributes (_("Logic"),
119 gtk_tree_view_append_column (GTK_TREE_VIEW (filter_view
), column
);
120 column
= gtk_tree_view_column_new_with_attributes (_("Value"),
124 gtk_tree_view_append_column (GTK_TREE_VIEW (filter_view
), column
);
125 details
->filter_view
= filter_view
;
126 gtk_box_pack_start (GTK_BOX (self
), GTK_WIDGET (filter_view
),
128 gtk_widget_show (filter_view
);
130 table
= gtk_table_new (3, 4, FALSE
);
131 w
= gtk_label_new_with_mnemonic (_("Attribute _category:"));
132 gtk_table_attach (GTK_TABLE (table
), w
,
135 details
->cat_combo
= gtk_combo_box_new_text ();
136 g_signal_connect (details
->cat_combo
, "changed",
137 G_CALLBACK (cat_combo_changed_cb
), self
);
138 gtk_table_attach (GTK_TABLE (table
), details
->cat_combo
,
141 w
= gtk_label_new_with_mnemonic (_("Attribute _name:"));
142 gtk_table_attach (GTK_TABLE (table
), w
,
145 details
->attr_combo
= gtk_combo_box_new ();
146 renderer
= gtk_cell_renderer_text_new ();
147 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (details
->attr_combo
),
149 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (details
->attr_combo
),
151 "text", MM_GTK_ATTR_STORE_NAME_COL
);
152 gtk_table_attach (GTK_TABLE (table
), details
->attr_combo
,
155 w
= gtk_label_new_with_mnemonic (_("_Logic:"));
156 gtk_table_attach (GTK_TABLE (table
), w
,
159 details
->logic_combo
= gtk_combo_box_new_text ();
160 gtk_table_attach (GTK_TABLE (table
), details
->logic_combo
,
163 w
= gtk_label_new_with_mnemonic (_("_Value:"));
164 gtk_table_attach (GTK_TABLE (table
), w
,
167 details
->value_entry
= gtk_entry_new ();
168 gtk_table_attach (GTK_TABLE (table
), details
->value_entry
,
171 w
= gtk_button_new_from_stock (GTK_STOCK_ADD
);
172 gtk_table_attach (GTK_TABLE (table
), w
,
175 gtk_box_pack_start (GTK_BOX (self
), table
,
177 gtk_widget_show_all (table
);
179 populate_logic_combo (details
->logic_combo
);
183 populate_from_category (MMGtkFilterBuilder
*self
, MMCategory
*cat
)
185 MMApplicationType type
;
186 MMAttributeManager
*attr_manager
;
189 /* TODO: we should take care in some way that applications may want to define
190 * a custom AttributeManager. The API here in libmmanager-gtk is already
191 * setup for that, but this needs an API addition in MMApplication.
194 g_return_if_fail (MM_GTK_IS_FILTER_BUILDER (self
));
195 g_return_if_fail (MM_IS_CATEGORY (cat
));
197 /* TODO: when I will create Photo, Video and Music attribute managers,
198 * here is the place for adding those custom attributes.
202 attr_manager
= mm_attribute_base_manager_get ();
203 mm_gtk_attribute_store_set_from_attribute_manager (self
->details
->attribute_store
,
205 gtk_combo_box_append_text (GTK_COMBO_BOX (self
->details
->cat_combo
),
206 _("Base attributes"));
207 g_hash_table_insert (self
->details
->attr_managers
, &key
, attr_manager
);
209 /* this should trigger population in the attr combo box */
210 gtk_combo_box_set_active (GTK_COMBO_BOX (self
->details
->cat_combo
), 0);
216 mm_gtk_filter_builder_new (MMCategory
*category
)
218 MMGtkFilterBuilder
*self
;
220 self
= MM_GTK_FILTER_BUILDER (g_object_new (MM_GTK_TYPE_FILTER_BUILDER
, NULL
));
221 populate_from_category (self
, category
);