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
;
40 GtkWidget
*attr_combo
;
41 GtkWidget
*logic_combo
;
42 GtkWidget
*value_entry
;
45 static const char * logic_strs
[] = {
49 N_("greater or equal than"),
50 N_("less or equal than"),
54 mm_gtk_filter_builder_class_init (MMGtkFilterBuilderClass
*klass
)
56 g_type_class_add_private (klass
, sizeof (MMGtkFilterBuilderDetails
));
60 populate_logic_combo (GtkWidget
*combo
)
64 for (idx
= 0; idx
< G_N_ELEMENTS (logic_strs
); idx
++) {
65 gtk_combo_box_append_text (GTK_COMBO_BOX (combo
), logic_strs
[idx
]);
68 gtk_combo_box_set_active (GTK_COMBO_BOX (combo
), 0);
72 cat_combo_changed_cb (GtkComboBox
*combo
,
73 MMGtkFilterBuilder
*self
)
79 mm_gtk_filter_builder_init (MMGtkFilterBuilder
*self
)
81 MMGtkFilterBuilderDetails
*details
= self
->details
=
82 MM_GTK_FILTER_BUILDER_GET_PRIVATE (self
);
83 GtkWidget
*filter_view
;
84 GtkTreeViewColumn
*column
;
85 GtkCellRenderer
*renderer
;
89 details
->attribute_store
= mm_gtk_attribute_store_new ();
90 details
->filter_store
= gtk_list_store_new (3,
91 G_TYPE_STRING
, /* attribute name */
92 G_TYPE_STRING
, /* operator */
93 G_TYPE_STRING
); /* value */
94 filter_view
= gtk_tree_view_new_with_model (GTK_TREE_MODEL (details
->filter_store
));
95 renderer
= gtk_cell_renderer_text_new ();
96 column
= gtk_tree_view_column_new_with_attributes (_("Parameter"),
100 gtk_tree_view_append_column (GTK_TREE_VIEW (filter_view
), column
);
101 column
= gtk_tree_view_column_new_with_attributes (_("Logic"),
105 gtk_tree_view_append_column (GTK_TREE_VIEW (filter_view
), column
);
106 column
= gtk_tree_view_column_new_with_attributes (_("Value"),
110 gtk_tree_view_append_column (GTK_TREE_VIEW (filter_view
), column
);
111 details
->filter_view
= filter_view
;
112 gtk_box_pack_start (GTK_BOX (self
), GTK_WIDGET (filter_view
),
114 gtk_widget_show (filter_view
);
116 table
= gtk_table_new (3, 4, FALSE
);
117 w
= gtk_label_new_with_mnemonic (_("Attribute _category:"));
118 gtk_table_attach (GTK_TABLE (table
), w
,
121 details
->cat_combo
= gtk_combo_box_new_text ();
122 g_signal_connect (details
->cat_combo
, "changed",
123 G_CALLBACK (cat_combo_changed_cb
), self
);
124 gtk_table_attach (GTK_TABLE (table
), details
->cat_combo
,
127 w
= gtk_label_new_with_mnemonic (_("Attribute _name:"));
128 gtk_table_attach (GTK_TABLE (table
), w
,
131 details
->attr_combo
= gtk_combo_box_new ();
132 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (details
->attr_combo
),
134 "text", MM_GTK_ATTR_STORE_NAME_COL
);
135 gtk_table_attach (GTK_TABLE (table
), details
->attr_combo
,
138 w
= gtk_label_new_with_mnemonic (_("_Logic:"));
139 gtk_table_attach (GTK_TABLE (table
), w
,
142 details
->logic_combo
= gtk_combo_box_new_text ();
143 gtk_table_attach (GTK_TABLE (table
), details
->logic_combo
,
146 w
= gtk_label_new_with_mnemonic (_("_Value:"));
147 gtk_table_attach (GTK_TABLE (table
), w
,
150 details
->value_entry
= gtk_entry_new ();
151 gtk_table_attach (GTK_TABLE (table
), details
->value_entry
,
154 w
= gtk_button_new_from_stock (GTK_STOCK_ADD
);
155 gtk_table_attach (GTK_TABLE (table
), w
,
158 gtk_box_pack_start (GTK_BOX (self
), table
,
160 gtk_widget_show_all (table
);
162 populate_logic_combo (details
->logic_combo
);
166 populate_cat_combo (MMGtkFilterBuilder
*self
, MMApplicationType type
)
168 /* TODO: update this when we support more attr managers */
169 gtk_combo_box_append_text (GTK_COMBO_BOX (self
->details
->cat_combo
),
170 _("Base attributes"));
171 /* this should trigger population in the attr combo box */
172 gtk_combo_box_set_active (GTK_COMBO_BOX (self
->details
->cat_combo
), 0);
176 populate_from_category (MMGtkFilterBuilder
*self
, MMCategory
*cat
)
179 MMApplicationType type
;
180 MMAttributeManager
*attr_manager
;
182 /* TODO: we should take care in some way that applications may want to define
183 * a custom AttributeManager. The API here in libmmanager-gtk is already
184 * setup for that, but this needs an API addition in MMApplication.
187 g_return_if_fail (MM_GTK_IS_FILTER_BUILDER (self
));
188 g_return_if_fail (MM_IS_CATEGORY (cat
));
190 app
= mm_category_get_application (cat
);
191 g_object_get (app
, "supported-type", &type
, NULL
);
193 attr_manager
= mm_attribute_base_manager_get ();
194 /* TODO: when I will create Photo, Video and Music attribute managers,
195 * here is the place for adding those custom attributes.
197 mm_gtk_attribute_store_add_from_attribute_manager (self
->details
->attribute_store
,
199 g_object_unref (app
);
201 populate_cat_combo (self
, type
);
207 mm_gtk_filter_builder_new (MMCategory
*category
)
209 MMGtkFilterBuilder
*self
;
211 self
= MM_GTK_FILTER_BUILDER (g_object_new (MM_GTK_TYPE_FILTER_BUILDER
, NULL
));
212 populate_from_category (self
, category
);