3 * Copyright (C) 2001-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "media-select.h"
25 #include <glib/gi18n.h>
29 #include <libglabels.h>
30 #include "mini-preview-pixbuf-cache.h"
32 #include "message-bar.h"
33 #include "template-history.h"
34 #include "template-designer.h"
36 #include "combo-util.h"
37 #include "builder-util.h"
44 #define HISTORY_SIZE 5
46 /*===========================================*/
48 /*===========================================*/
54 PREVIEW_COLUMN_STOCK_SIZE,
59 struct _glMediaSelectPrivate {
66 guint current_page_num;
69 GtkWidget *recent_tab_vbox;
70 GtkWidget *recent_info_vbox;
71 GtkWidget *recent_info_bar;
72 GtkWidget *recent_treeview;
73 GtkListStore *recent_store;
75 gint search_all_page_num;
76 GtkWidget *search_all_tab_vbox;
77 GtkWidget *search_all_info_vbox;
78 GtkWidget *search_all_info_bar;
79 GtkWidget *brand_combo_hbox;
80 GtkWidget *brand_combo;
81 GtkWidget *page_size_combo_hbox;
82 GtkWidget *page_size_combo;
83 GtkWidget *category_combo_hbox;
84 GtkWidget *category_combo;
85 GtkWidget *search_all_treeview;
86 GtkListStore *search_all_store;
89 GtkWidget *custom_tab_vbox;
90 GtkWidget *custom_info_vbox;
91 GtkWidget *custom_info_bar;
92 GtkWidget *custom_treeview;
93 GtkListStore *custom_store;
94 GtkWidget *custom_add_button;
95 GtkWidget *custom_edit_button;
96 GtkWidget *custom_delete_button;
98 /* Prevent recursion */
99 gboolean stop_signals;
108 /*===========================================*/
109 /* Private globals */
110 /*===========================================*/
112 static gint signals[LAST_SIGNAL] = { 0 };
115 /*===========================================*/
116 /* Local function prototypes */
117 /*===========================================*/
119 static void gl_media_select_finalize (GObject *object);
121 static void gl_media_select_construct (glMediaSelect *this);
123 static void filter_changed_cb (glMediaSelect *this);
125 static void selection_changed_cb (GtkTreeSelection *selection,
128 static void custom_add_clicked_cb (GtkButton *button,
131 static void custom_edit_clicked_cb (GtkButton *button,
134 static void custom_delete_clicked_cb (GtkButton *button,
137 static void page_changed_cb (GtkNotebook *notebook,
142 static void db_changed_cb (glMediaSelect *this);
144 static void load_recent_list (glMediaSelect *this,
146 GtkTreeSelection *selection,
149 static void load_custom_list (glMediaSelect *this,
151 GtkTreeSelection *selection,
154 static void load_search_all_list (glMediaSelect *this,
156 GtkTreeSelection *selection,
160 /****************************************************************************/
161 /* Boilerplate Object stuff. */
162 /****************************************************************************/
163 G_DEFINE_TYPE (glMediaSelect, gl_media_select, GTK_TYPE_VBOX)
167 gl_media_select_class_init (glMediaSelectClass *class)
169 GObjectClass *object_class = G_OBJECT_CLASS (class);
171 gl_debug (DEBUG_MEDIA_SELECT, "START");
173 gl_media_select_parent_class = g_type_class_peek_parent (class);
175 object_class->finalize = gl_media_select_finalize;
178 g_signal_new ("changed",
179 G_OBJECT_CLASS_TYPE(object_class),
181 G_STRUCT_OFFSET (glMediaSelectClass, changed),
183 gl_marshal_VOID__VOID,
186 gl_debug (DEBUG_MEDIA_SELECT, "END");
191 gl_media_select_init (glMediaSelect *this)
193 gl_debug (DEBUG_MEDIA_SELECT, "START");
195 this->priv = g_new0 (glMediaSelectPrivate, 1);
197 gl_debug (DEBUG_MEDIA_SELECT, "END");
202 gl_media_select_finalize (GObject *object)
204 glMediaSelect *this = GL_MEDIA_SELECT (object);
206 gl_debug (DEBUG_MEDIA_SELECT, "START");
208 g_return_if_fail (object != NULL);
209 g_return_if_fail (GL_IS_MEDIA_SELECT (object));
211 if (this->priv->db_notify_id)
213 lgl_db_notify_remove (this->priv->db_notify_id);
216 if (this->priv->builder)
218 g_object_unref (this->priv->builder);
220 g_object_unref (this->priv->recent_store);
221 g_object_unref (this->priv->search_all_store);
224 G_OBJECT_CLASS (gl_media_select_parent_class)->finalize (object);
226 gl_debug (DEBUG_MEDIA_SELECT, "END");
231 gl_media_select_new (void)
235 gl_debug (DEBUG_MEDIA_SELECT, "START");
237 this = g_object_new (gl_media_select_get_type (), NULL);
239 gl_media_select_construct (this);
241 gl_debug (DEBUG_MEDIA_SELECT, "END");
243 return GTK_WIDGET (this);
247 /*--------------------------------------------------------------------------*/
248 /* PRIVATE. Construct composite widget. */
249 /*--------------------------------------------------------------------------*/
251 gl_media_select_construct (glMediaSelect *this)
253 gchar *builder_filename;
255 static gchar *object_ids[] = { "media_select_hbox",
256 "custom_buttons_sizegroup",
258 GError *error = NULL;
260 GList *recent_list = NULL;
261 GList *brands = NULL;
262 GList *page_sizes = NULL;
263 GList *categories = NULL;
264 GList *search_all_names = NULL;
265 const gchar *page_size_id;
266 gchar *page_size_name;
267 GList *custom_list = NULL;
268 GtkCellRenderer *renderer;
269 GtkTreeViewColumn *column;
270 GtkTreeSelection *recent_selection;
271 GtkTreeSelection *search_all_selection;
272 GtkTreeSelection *custom_selection;
274 gl_debug (DEBUG_MEDIA_SELECT, "START");
276 g_return_if_fail (GL_IS_MEDIA_SELECT (this));
277 g_return_if_fail (this->priv != NULL);
279 builder = gtk_builder_new ();
280 builder_filename = g_build_filename (GLABELS_DATA_DIR, "ui", "media-select.ui", NULL);
281 gtk_builder_add_objects_from_file (builder, builder_filename, object_ids, &error);
282 g_free (builder_filename);
284 g_critical ("%s\n\ngLabels may not be installed correctly!", error->message);
285 g_error_free (error);
289 gl_builder_util_get_widgets (builder,
290 "media_select_hbox", &hbox,
291 "notebook", &this->priv->notebook,
292 "recent_tab_vbox", &this->priv->recent_tab_vbox,
293 "recent_info_vbox", &this->priv->recent_info_vbox,
294 "recent_treeview", &this->priv->recent_treeview,
295 "search_all_tab_vbox", &this->priv->search_all_tab_vbox,
296 "brand_combo_hbox", &this->priv->brand_combo_hbox,
297 "page_size_combo_hbox", &this->priv->page_size_combo_hbox,
298 "category_combo_hbox", &this->priv->category_combo_hbox,
299 "search_all_info_vbox", &this->priv->search_all_info_vbox,
300 "search_all_treeview", &this->priv->search_all_treeview,
301 "custom_tab_vbox", &this->priv->custom_tab_vbox,
302 "custom_info_vbox", &this->priv->custom_info_vbox,
303 "custom_treeview", &this->priv->custom_treeview,
304 "custom_add_button", &this->priv->custom_add_button,
305 "custom_edit_button", &this->priv->custom_edit_button,
306 "custom_delete_button", &this->priv->custom_delete_button,
309 gtk_container_add (GTK_CONTAINER (this), hbox);
310 this->priv->builder = builder;
312 this->priv->recent_page_num =
313 gtk_notebook_page_num (GTK_NOTEBOOK (this->priv->notebook),
314 this->priv->recent_tab_vbox);
315 this->priv->search_all_page_num =
316 gtk_notebook_page_num (GTK_NOTEBOOK (this->priv->notebook),
317 this->priv->search_all_tab_vbox);
318 this->priv->custom_page_num =
319 gtk_notebook_page_num (GTK_NOTEBOOK (this->priv->notebook),
320 this->priv->custom_tab_vbox);
322 this->priv->brand_combo = gtk_combo_box_text_new ();
323 gtk_box_pack_start (GTK_BOX (this->priv->brand_combo_hbox), this->priv->brand_combo, FALSE, FALSE, 0);
324 this->priv->page_size_combo = gtk_combo_box_text_new ();
325 gtk_box_pack_start (GTK_BOX (this->priv->page_size_combo_hbox), this->priv->page_size_combo, FALSE, FALSE, 0);
326 this->priv->category_combo = gtk_combo_box_text_new ();
327 gtk_box_pack_start (GTK_BOX (this->priv->category_combo_hbox), this->priv->category_combo, FALSE, FALSE, 0);
329 gtk_widget_show_all (GTK_WIDGET (this));
331 /* Recent templates treeview */
332 this->priv->recent_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING);
333 gtk_tree_view_set_model (GTK_TREE_VIEW (this->priv->recent_treeview),
334 GTK_TREE_MODEL (this->priv->recent_store));
335 renderer = gtk_cell_renderer_pixbuf_new ();
336 column = gtk_tree_view_column_new_with_attributes ("", renderer,
337 "pixbuf", PREVIEW_COLUMN,
338 "stock-id", PREVIEW_COLUMN_STOCK,
339 "stock-size", PREVIEW_COLUMN_STOCK_SIZE,
341 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
342 gtk_tree_view_append_column (GTK_TREE_VIEW (this->priv->recent_treeview), column);
343 renderer = gtk_cell_renderer_text_new ();
344 column = gtk_tree_view_column_new_with_attributes ("", renderer,
345 "markup", DESCRIPTION_COLUMN,
347 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
348 gtk_tree_view_append_column (GTK_TREE_VIEW (this->priv->recent_treeview), column);
349 recent_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->recent_treeview));
350 recent_list = gl_template_history_model_get_name_list (gl_template_history);
351 load_recent_list (this, this->priv->recent_store, recent_selection, recent_list);
353 page_size_id = gl_prefs_model_get_default_page_size (gl_prefs);
354 page_size_name = lgl_db_lookup_paper_name_from_id (page_size_id);
356 /* Brand selection control */
357 brands = lgl_db_get_brand_list (NULL, NULL);
358 brands = g_list_prepend (brands, g_strdup (C_("Brand", "Any")));
359 gl_combo_util_set_strings (GTK_COMBO_BOX_TEXT (this->priv->brand_combo), brands);
360 lgl_db_free_brand_list (brands);
361 gl_combo_util_set_active_text (GTK_COMBO_BOX (this->priv->brand_combo), C_("Brand", "Any"));
363 /* Page size selection control */
364 page_sizes = lgl_db_get_paper_name_list ();
365 page_sizes = g_list_prepend (page_sizes, g_strdup (C_("Page size", "Any")));
366 gl_combo_util_set_strings (GTK_COMBO_BOX_TEXT (this->priv->page_size_combo), page_sizes);
367 lgl_db_free_paper_name_list (page_sizes);
368 gl_combo_util_set_active_text (GTK_COMBO_BOX (this->priv->page_size_combo), page_size_name);
370 /* Category selection control */
371 categories = lgl_db_get_category_name_list ();
372 categories = g_list_prepend (categories, g_strdup (C_("Category", "Any")));
373 gl_combo_util_set_strings (GTK_COMBO_BOX_TEXT (this->priv->category_combo), categories);
374 lgl_db_free_category_name_list (categories);
375 gl_combo_util_set_active_text (GTK_COMBO_BOX (this->priv->category_combo), C_("Category", "Any"));
377 /* Search all treeview */
378 this->priv->search_all_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING);
379 gtk_tree_view_set_model (GTK_TREE_VIEW (this->priv->search_all_treeview),
380 GTK_TREE_MODEL (this->priv->search_all_store));
381 renderer = gtk_cell_renderer_pixbuf_new ();
382 column = gtk_tree_view_column_new_with_attributes ("", renderer,
383 "pixbuf", PREVIEW_COLUMN,
384 "stock-id", PREVIEW_COLUMN_STOCK,
385 "stock-size", PREVIEW_COLUMN_STOCK_SIZE,
387 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
388 gtk_tree_view_append_column (GTK_TREE_VIEW (this->priv->search_all_treeview), column);
389 renderer = gtk_cell_renderer_text_new ();
390 column = gtk_tree_view_column_new_with_attributes ("", renderer,
391 "markup", DESCRIPTION_COLUMN,
393 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
394 gtk_tree_view_append_column (GTK_TREE_VIEW (this->priv->search_all_treeview), column);
395 search_all_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->search_all_treeview));
396 search_all_names = lgl_db_get_template_name_list_all (NULL, page_size_id, NULL);
397 load_search_all_list (this, this->priv->search_all_store, search_all_selection, search_all_names);
398 lgl_db_free_template_name_list (search_all_names);
400 /* Custom templates treeview */
401 this->priv->custom_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING);
402 gtk_tree_view_set_model (GTK_TREE_VIEW (this->priv->custom_treeview),
403 GTK_TREE_MODEL (this->priv->custom_store));
404 renderer = gtk_cell_renderer_pixbuf_new ();
405 column = gtk_tree_view_column_new_with_attributes ("", renderer,
406 "pixbuf", PREVIEW_COLUMN,
407 "stock-id", PREVIEW_COLUMN_STOCK,
408 "stock-size", PREVIEW_COLUMN_STOCK_SIZE,
410 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
411 gtk_tree_view_append_column (GTK_TREE_VIEW (this->priv->custom_treeview), column);
412 renderer = gtk_cell_renderer_text_new ();
413 column = gtk_tree_view_column_new_with_attributes ("", renderer,
414 "markup", DESCRIPTION_COLUMN,
416 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
417 gtk_tree_view_append_column (GTK_TREE_VIEW (this->priv->custom_treeview), column);
418 custom_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->custom_treeview));
419 custom_list = lgl_db_get_template_name_list_all (NULL, NULL, "user-defined");
420 load_custom_list (this, this->priv->custom_store, custom_selection, custom_list);
421 lgl_db_free_template_name_list (custom_list);
423 page_size_id = gl_prefs_model_get_default_page_size (gl_prefs);
424 page_size_name = lgl_db_lookup_paper_name_from_id (page_size_id);
426 /* Connect signals to controls */
427 g_signal_connect_swapped (G_OBJECT (this->priv->brand_combo), "changed",
428 G_CALLBACK (filter_changed_cb),
430 g_signal_connect_swapped (G_OBJECT (this->priv->page_size_combo), "changed",
431 G_CALLBACK (filter_changed_cb),
433 g_signal_connect_swapped (G_OBJECT (this->priv->category_combo), "changed",
434 G_CALLBACK (filter_changed_cb),
436 g_signal_connect (G_OBJECT (recent_selection), "changed",
437 G_CALLBACK (selection_changed_cb),
439 g_signal_connect (G_OBJECT (search_all_selection), "changed",
440 G_CALLBACK (selection_changed_cb),
442 g_signal_connect (G_OBJECT (custom_selection), "changed",
443 G_CALLBACK (selection_changed_cb),
445 g_signal_connect (G_OBJECT (this->priv->custom_add_button), "clicked",
446 G_CALLBACK (custom_add_clicked_cb),
448 g_signal_connect (G_OBJECT (this->priv->custom_edit_button), "clicked",
449 G_CALLBACK (custom_edit_clicked_cb),
451 g_signal_connect (G_OBJECT (this->priv->custom_delete_button), "clicked",
452 G_CALLBACK (custom_delete_clicked_cb),
454 g_signal_connect (G_OBJECT (this->priv->notebook), "switch-page",
455 G_CALLBACK (page_changed_cb),
458 g_free (page_size_name);
462 gtk_notebook_set_current_page (GTK_NOTEBOOK (this->priv->notebook),
463 this->priv->recent_page_num);
467 gtk_notebook_set_current_page (GTK_NOTEBOOK (this->priv->notebook),
468 this->priv->search_all_page_num);
470 gl_template_history_model_free_name_list (recent_list);
472 this->priv->db_notify_id = lgl_db_notify_add ((lglDbNotifyFunc)db_changed_cb, this);
474 gl_debug (DEBUG_MEDIA_SELECT, "END");
478 /*--------------------------------------------------------------------------*/
479 /* PRIVATE. modify widget due to change in selection */
480 /*--------------------------------------------------------------------------*/
482 filter_changed_cb (glMediaSelect *this)
485 gchar *page_size_name, *page_size_id;
486 gchar *category_name, *category_id;
487 GList *search_all_names;
488 GtkTreeSelection *selection;
490 gl_debug (DEBUG_MEDIA_SELECT, "START");
493 this->priv->stop_signals = TRUE;
495 /* Update template selections for new filter settings */
496 brand = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (this->priv->brand_combo));
497 page_size_name = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (this->priv->page_size_combo));
498 category_name = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (this->priv->category_combo));
499 if ( brand && strlen(brand) &&
500 page_size_name && strlen(page_size_name) &&
501 category_name && strlen(category_name) )
503 gl_debug (DEBUG_MEDIA_SELECT, "brand = \"%s\"", brand);
504 gl_debug (DEBUG_MEDIA_SELECT, "page_size_name = \"%s\"", page_size_name);
505 gl_debug (DEBUG_MEDIA_SELECT, "category_name = \"%s\"", category_name);
506 if (!g_utf8_collate (brand, C_("Brand", "Any")))
511 page_size_id = lgl_db_lookup_paper_id_from_name (page_size_name);
512 category_id = lgl_db_lookup_category_id_from_name (category_name);
513 gl_debug (DEBUG_MEDIA_SELECT, "page_size_id = \"%s\"", page_size_id);
514 gl_debug (DEBUG_MEDIA_SELECT, "category_id = \"%s\"", category_id);
515 search_all_names = lgl_db_get_template_name_list_all (brand, page_size_id, category_id);
516 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->search_all_treeview));
517 load_search_all_list (this, this->priv->search_all_store, selection, search_all_names);
518 lgl_db_free_template_name_list (search_all_names);
519 g_free (page_size_id);
520 g_free (category_id);
522 /* Emit our "changed" signal */
523 g_signal_emit (G_OBJECT (this), signals[CHANGED], 0);
526 g_free (page_size_name);
527 g_free (category_name);
530 this->priv->stop_signals = FALSE;
532 gl_debug (DEBUG_MEDIA_SELECT, "END");
536 /*--------------------------------------------------------------------------*/
537 /* PRIVATE. modify widget due to change in selection */
538 /*--------------------------------------------------------------------------*/
540 selection_changed_cb (GtkTreeSelection *selection,
543 glMediaSelect *this = GL_MEDIA_SELECT (user_data);
544 GtkTreeSelection *custom_selection;
546 if (this->priv->stop_signals) return;
548 gl_debug (DEBUG_MEDIA_SELECT, "START");
550 custom_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->custom_treeview));
551 gtk_widget_set_sensitive (GTK_WIDGET (this->priv->custom_edit_button),
552 gtk_tree_selection_get_mode (custom_selection) != GTK_SELECTION_NONE );
553 gtk_widget_set_sensitive (GTK_WIDGET (this->priv->custom_delete_button),
554 gtk_tree_selection_get_mode (custom_selection) != GTK_SELECTION_NONE );
556 /* Emit our "changed" signal */
557 g_signal_emit (G_OBJECT (user_data), signals[CHANGED], 0);
559 gl_debug (DEBUG_MEDIA_SELECT, "END");
563 /*--------------------------------------------------------------------------*/
564 /* PRIVATE. Custom add button clicked callback. */
565 /*--------------------------------------------------------------------------*/
567 custom_add_clicked_cb (GtkButton *button,
570 glMediaSelect *this = GL_MEDIA_SELECT (user_data);
574 window = gtk_widget_get_toplevel (GTK_WIDGET (this));
576 dialog = gl_template_designer_new (GTK_WINDOW (window));
578 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
579 gtk_widget_show (dialog);
583 /*--------------------------------------------------------------------------*/
584 /* PRIVATE. Custom edit button clicked callback. */
585 /*--------------------------------------------------------------------------*/
587 custom_edit_clicked_cb (GtkButton *button,
590 glMediaSelect *this = GL_MEDIA_SELECT (user_data);
591 GtkTreeSelection *selection;
598 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->custom_treeview));
600 if (!gtk_tree_selection_get_mode (selection) == GTK_SELECTION_NONE)
602 gtk_tree_selection_get_selected (selection, &model, &iter);
603 gtk_tree_model_get (model, &iter, NAME_COLUMN, &name, -1);
605 window = gtk_widget_get_toplevel (GTK_WIDGET (this));
607 dialog = gl_template_designer_new (GTK_WINDOW (window));
608 gl_template_designer_set_from_name (GL_TEMPLATE_DESIGNER (dialog), name);
610 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
611 gtk_widget_show (dialog);
618 /*--------------------------------------------------------------------------*/
619 /* PRIVATE. Custom delete button clicked callback. */
620 /*--------------------------------------------------------------------------*/
622 custom_delete_clicked_cb (GtkButton *button,
625 glMediaSelect *this = GL_MEDIA_SELECT (user_data);
626 GtkTreeSelection *selection;
634 this->priv->stop_signals = TRUE;
636 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->custom_treeview));
638 if (!gtk_tree_selection_get_mode (selection) == GTK_SELECTION_NONE)
640 gtk_tree_selection_get_selected (selection, &model, &iter);
641 gtk_tree_model_get (model, &iter, NAME_COLUMN, &name, -1);
643 window = gtk_widget_get_toplevel (GTK_WIDGET (this));
644 dialog = gtk_message_dialog_new (GTK_WINDOW (window),
645 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
646 GTK_MESSAGE_QUESTION,
648 _("Delete template \"%s\"?"), name);
649 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
650 _("This action will permanently delete this template."));
652 ret = gtk_dialog_run (GTK_DIALOG (dialog));
653 gtk_widget_destroy (dialog);
655 if ( ret == GTK_RESPONSE_YES )
657 lgl_db_delete_template_by_name (name);
658 gl_mini_preview_pixbuf_cache_delete_by_name (name);
664 this->priv->stop_signals = FALSE;
668 /*--------------------------------------------------------------------------*/
669 /* PRIVATE. modify widget due to change in selection */
670 /*--------------------------------------------------------------------------*/
672 page_changed_cb (GtkNotebook *notebook,
677 glMediaSelect *this = GL_MEDIA_SELECT (user_data);
679 if (this->priv->stop_signals) return;
681 gl_debug (DEBUG_MEDIA_SELECT, "START");
684 * Store new current page, because this signal is emitted before the actual page change.
686 this->priv->current_page_num = page_num;
688 /* Emit our "changed" signal */
689 g_signal_emit (G_OBJECT (user_data), signals[CHANGED], 0);
691 gl_debug (DEBUG_MEDIA_SELECT, "END");
695 /*--------------------------------------------------------------------------*/
696 /* PRIVATE. DB changed notification callback. */
697 /*--------------------------------------------------------------------------*/
699 db_changed_cb (glMediaSelect *this)
702 gchar *page_size_name, *page_size_id;
703 gchar *category_name, *category_id;
704 GtkTreeSelection *selection;
707 this->priv->stop_signals = TRUE;
709 /* Update recent page. */
710 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->recent_treeview));
711 list = gl_template_history_model_get_name_list (gl_template_history);
712 load_recent_list (this, this->priv->recent_store, selection, list);
713 lgl_db_free_template_name_list (list);
715 /* Update search all page. */
716 brand = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (this->priv->brand_combo));
717 page_size_name = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (this->priv->page_size_combo));
718 category_name = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (this->priv->category_combo));
719 if ( brand && strlen(brand) &&
720 page_size_name && strlen(page_size_name) &&
721 category_name && strlen(category_name) )
723 if (!g_utf8_collate (brand, C_("Brand", "Any")))
728 page_size_id = lgl_db_lookup_paper_id_from_name (page_size_name);
729 category_id = lgl_db_lookup_category_id_from_name (category_name);
730 list = lgl_db_get_template_name_list_all (brand, page_size_id, category_id);
731 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->search_all_treeview));
732 load_search_all_list (this, this->priv->search_all_store, selection, list);
733 lgl_db_free_template_name_list (list);
734 g_free (page_size_id);
735 g_free (category_id);
738 g_free (page_size_name);
739 g_free (category_name);
741 /* Update custom page. */
742 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->custom_treeview));
743 list = lgl_db_get_template_name_list_all (NULL, NULL, "user-defined");
744 load_custom_list (this, this->priv->custom_store, selection, list);
745 lgl_db_free_template_name_list (list);
747 this->priv->stop_signals = FALSE;
749 /* Emit our "changed" signal */
750 g_signal_emit (G_OBJECT (this), signals[CHANGED], 0);
752 filter_changed_cb (this);
756 /****************************************************************************/
757 /* query selected label template name. */
758 /****************************************************************************/
760 gl_media_select_get_name (glMediaSelect *this)
763 GtkTreeSelection *selection;
768 gl_debug (DEBUG_MEDIA_SELECT, "START");
770 page_num = this->priv->current_page_num;
771 if (page_num == this->priv->recent_page_num)
773 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->recent_treeview));
775 else if (page_num == this->priv->search_all_page_num)
777 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->search_all_treeview));
779 else if (page_num == this->priv->custom_page_num)
781 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->custom_treeview));
785 g_print ("notebook page = %d\n", page_num);
786 g_assert_not_reached ();
789 if (gtk_tree_selection_get_mode (selection) == GTK_SELECTION_NONE)
795 gtk_tree_selection_get_selected (selection, &model, &iter);
796 gtk_tree_model_get (model, &iter, NAME_COLUMN, &name, -1);
799 gl_debug (DEBUG_MEDIA_SELECT, "END");
804 /****************************************************************************/
805 /* set selected label template name. */
806 /****************************************************************************/
808 gl_media_select_set_name (glMediaSelect *this,
811 GtkTreeSelection *selection;
818 gl_debug (DEBUG_MEDIA_SELECT, "START");
820 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->search_all_treeview));
821 g_return_if_fail (GTK_IS_TREE_SELECTION (selection));
823 model = GTK_TREE_MODEL (this->priv->search_all_store);
825 for ( flag = gtk_tree_model_get_iter_first (model, &iter);
827 flag = gtk_tree_model_iter_next(model, &iter) )
829 gtk_tree_model_get (model, &iter, NAME_COLUMN, &name_i, -1);
830 if (lgl_str_utf8_casecmp(name, name_i) == 0)
832 gtk_tree_selection_select_iter (selection, &iter);
833 path = gtk_tree_model_get_path (model, &iter);
834 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (this->priv->search_all_treeview),
838 gtk_tree_path_free (path);
843 gl_debug (DEBUG_MEDIA_SELECT, "END");
847 /****************************************************************************/
848 /* query current filter parameters. */
849 /****************************************************************************/
851 gl_media_select_get_filter_parameters (glMediaSelect *this,
852 gchar **page_size_id,
855 gchar *page_size_name, *category_name;
857 gl_debug (DEBUG_MEDIA_SELECT, "");
859 g_free (*page_size_id);
860 g_free (*category_id);
863 gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (this->priv->page_size_combo));
865 *page_size_id = lgl_db_lookup_paper_id_from_name (page_size_name);
868 gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (this->priv->category_combo));
870 *category_id = lgl_db_lookup_category_id_from_name (category_name);
872 g_free (page_size_name);
873 g_free (category_name);
877 /****************************************************************************/
878 /* set filter parameters. */
879 /****************************************************************************/
881 gl_media_select_set_filter_parameters (glMediaSelect *this,
882 const gchar *page_size_id,
883 const gchar *category_id)
885 gchar *page_size_name;
886 gchar *category_name;
888 gl_debug (DEBUG_MEDIA_SELECT, "START");
890 page_size_name = lgl_db_lookup_paper_name_from_id (page_size_id);
891 if (page_size_name == NULL)
893 page_size_name = g_strdup (C_("Page size", "Any"));
896 gl_combo_util_set_active_text (GTK_COMBO_BOX (this->priv->page_size_combo),
899 category_name = lgl_db_lookup_category_name_from_id (category_id);
900 if (category_name == NULL)
902 category_name = g_strdup (C_("Category", "Any"));
905 gl_combo_util_set_active_text (GTK_COMBO_BOX (this->priv->category_combo),
907 g_free (page_size_name);
908 g_free (category_name);
910 gl_debug (DEBUG_MEDIA_SELECT, "END");
914 /*--------------------------------------------------------------------------*/
915 /* PRIVATE. Load list store from template name list. */
916 /*--------------------------------------------------------------------------*/
918 load_recent_list (glMediaSelect *this,
920 GtkTreeSelection *selection,
926 lglTemplate *template;
927 lglTemplateFrame *frame;
933 gl_debug (DEBUG_MEDIA_SELECT, "START");
935 gtk_list_store_clear (store);
938 if ( this->priv->recent_info_bar )
940 gtk_container_remove (GTK_CONTAINER (this->priv->recent_info_vbox),
941 this->priv->recent_info_bar);
942 this->priv->recent_info_bar = NULL;
948 units = gl_prefs_model_get_units (gl_prefs);
950 for ( p=list; p!=NULL; p=p->next )
953 gl_debug (DEBUG_MEDIA_SELECT, "p->data = \"%s\"", p->data);
955 template = lgl_db_lookup_template_from_name (p->data);
956 frame = (lglTemplateFrame *)template->frames->data;
957 pixbuf = gl_mini_preview_pixbuf_cache_get_pixbuf (p->data);
959 size = lgl_template_frame_get_size_description (frame, units);
960 layout = lgl_template_frame_get_layout_description (frame);
961 description = g_strdup_printf ("<b>%s: %s</b>\n%s\n%s",
963 template->description,
969 lgl_template_free (template);
971 gtk_list_store_append (store, &iter);
972 gtk_list_store_set (store, &iter,
973 NAME_COLUMN, p->data,
974 PREVIEW_COLUMN, pixbuf,
975 DESCRIPTION_COLUMN, description,
978 g_object_unref (G_OBJECT (pixbuf));
979 g_free (description);
982 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
983 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
984 gtk_tree_selection_select_iter (selection, &iter);
989 this->priv->recent_info_bar = gl_message_bar_new (GTK_MESSAGE_INFO, GTK_BUTTONS_NONE,
990 "%s", _("No recent templates found."));
991 gl_message_bar_format_secondary_text (GL_MESSAGE_BAR (this->priv->recent_info_bar),
992 "%s", _("Try selecting a template in the \"Search all\" tab."));
994 gtk_box_pack_start (GTK_BOX (this->priv->recent_info_vbox),
995 this->priv->recent_info_bar,
997 gtk_widget_show_all (this->priv->recent_info_bar);
999 gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
1003 gl_debug (DEBUG_MEDIA_SELECT, "END");
1007 /*--------------------------------------------------------------------------*/
1008 /* PRIVATE. Load list store from template name list. */
1009 /*--------------------------------------------------------------------------*/
1011 load_search_all_list (glMediaSelect *this,
1012 GtkListStore *store,
1013 GtkTreeSelection *selection,
1019 lglTemplate *template;
1020 lglTemplateFrame *frame;
1026 gl_debug (DEBUG_MEDIA_SELECT, "START");
1028 gtk_list_store_clear (store);
1030 if ( this->priv->search_all_info_bar )
1032 gtk_container_remove (GTK_CONTAINER (this->priv->search_all_info_vbox),
1033 this->priv->search_all_info_bar);
1034 this->priv->search_all_info_bar = NULL;
1040 units = gl_prefs_model_get_units (gl_prefs);
1042 for ( p=list; p!=NULL; p=p->next )
1045 gl_debug (DEBUG_MEDIA_SELECT, "p->data = \"%s\"", p->data);
1047 template = lgl_db_lookup_template_from_name (p->data);
1048 frame = (lglTemplateFrame *)template->frames->data;
1049 pixbuf = gl_mini_preview_pixbuf_cache_get_pixbuf (p->data);
1051 size = lgl_template_frame_get_size_description (frame, units);
1052 layout = lgl_template_frame_get_layout_description (frame);
1053 description = g_strdup_printf ("<b>%s: %s</b>\n%s\n%s",
1055 template->description,
1061 lgl_template_free (template);
1063 gtk_list_store_append (store, &iter);
1064 gtk_list_store_set (store, &iter,
1065 NAME_COLUMN, p->data,
1066 PREVIEW_COLUMN, pixbuf,
1067 DESCRIPTION_COLUMN, description,
1070 g_object_unref (G_OBJECT (pixbuf));
1071 g_free (description);
1074 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
1075 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
1076 gtk_tree_selection_select_iter (selection, &iter);
1081 /* Translators: "No match" means that for the given template search criteria, there
1082 * were no matches found. */
1083 this->priv->search_all_info_bar = gl_message_bar_new (GTK_MESSAGE_INFO, GTK_BUTTONS_NONE, "%s", _("No match."));
1084 gl_message_bar_format_secondary_text (GL_MESSAGE_BAR (this->priv->search_all_info_bar),
1085 "%s", _("Try selecting a different brand, page size or category."));
1087 gtk_box_pack_start (GTK_BOX (this->priv->search_all_info_vbox),
1088 this->priv->search_all_info_bar,
1090 gtk_widget_show_all (this->priv->search_all_info_bar);
1092 gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
1096 gl_debug (DEBUG_MEDIA_SELECT, "END");
1100 /*--------------------------------------------------------------------------*/
1101 /* PRIVATE. Load list store from template name list. */
1102 /*--------------------------------------------------------------------------*/
1104 load_custom_list (glMediaSelect *this,
1105 GtkListStore *store,
1106 GtkTreeSelection *selection,
1112 lglTemplate *template;
1113 lglTemplateFrame *frame;
1119 gl_debug (DEBUG_MEDIA_SELECT, "START");
1121 gtk_list_store_clear (store);
1124 if ( this->priv->custom_info_bar )
1126 gtk_container_remove (GTK_CONTAINER (this->priv->custom_info_vbox),
1127 this->priv->custom_info_bar);
1128 this->priv->custom_info_bar = NULL;
1134 units = gl_prefs_model_get_units (gl_prefs);
1136 for ( p=list; p!=NULL; p=p->next )
1139 gl_debug (DEBUG_MEDIA_SELECT, "p->data = \"%s\"", p->data);
1141 template = lgl_db_lookup_template_from_name (p->data);
1142 frame = (lglTemplateFrame *)template->frames->data;
1143 pixbuf = gl_mini_preview_pixbuf_cache_get_pixbuf (p->data);
1145 size = lgl_template_frame_get_size_description (frame, units);
1146 layout = lgl_template_frame_get_layout_description (frame);
1147 description = g_strdup_printf ("<b>%s: %s</b>\n%s\n%s",
1149 template->description,
1155 lgl_template_free (template);
1157 gtk_list_store_append (store, &iter);
1158 gtk_list_store_set (store, &iter,
1159 NAME_COLUMN, p->data,
1160 PREVIEW_COLUMN, pixbuf,
1161 DESCRIPTION_COLUMN, description,
1164 g_object_unref (G_OBJECT (pixbuf));
1165 g_free (description);
1168 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
1169 gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
1170 gtk_tree_selection_select_iter (selection, &iter);
1172 gtk_widget_set_sensitive (GTK_WIDGET (this->priv->custom_edit_button), TRUE);
1173 gtk_widget_set_sensitive (GTK_WIDGET (this->priv->custom_delete_button), TRUE);
1177 this->priv->custom_info_bar = gl_message_bar_new (GTK_MESSAGE_INFO,
1179 "%s", _("No custom templates found."));
1180 gl_message_bar_format_secondary_text (GL_MESSAGE_BAR (this->priv->custom_info_bar),
1181 "%s", _("You may create new templates or try searching for pre-defined templates in the \"Search all\" tab."));
1183 gtk_box_pack_start (GTK_BOX (this->priv->custom_info_vbox),
1184 this->priv->custom_info_bar,
1186 gtk_widget_show_all (this->priv->custom_info_bar);
1188 gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);
1190 gtk_widget_set_sensitive (GTK_WIDGET (this->priv->custom_edit_button), FALSE);
1191 gtk_widget_set_sensitive (GTK_WIDGET (this->priv->custom_delete_button), FALSE);
1194 gl_debug (DEBUG_MEDIA_SELECT, "END");
1200 * Local Variables: -- emacs
1202 * c-basic-offset: 8 -- emacs
1203 * tab-width: 8 -- emacs
1204 * indent-tabs-mode: nil -- emacs