From 0a83046c78acea94d80fe2aea239a220445410ab Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 21 Mar 2010 01:14:35 -0400 Subject: [PATCH] Yet another new "New Label Dialog" Re-designed the "New label dialog" again. This time as a "wizard" or GtkAssistant. This is an attempt to keep the easy navigation of the 2.2.x dialog, to keep the added meta data and preview of the latest incarnation, and to maintain a compact dialog that should work on fairly small displays such on netbooks (probably not hand-helds still). --- data/builder/Makefile.am | 1 + data/builder/media-select.builder | 229 +++++++ data/builder/new-label-dialog.builder | 628 +++++++++++-------- po/POTFILES.in | 10 +- src/Makefile.am | 10 +- src/file.c | 115 ++-- src/media-combo-menu-item.c | 178 ------ src/media-combo-menu-item.h | 75 --- src/media-combo-menu.c | 332 ---------- src/media-combo-menu.h | 83 --- src/media-combo.c | 345 ----------- src/media-combo.h | 84 --- src/media-select.c | 847 ++++++++++++++++++++++++++ src/media-select.h | 87 +++ src/new-label-dialog.c | 275 ++++++--- src/new-label-dialog.h | 6 +- src/rotate-label-button.c | 261 -------- src/rotate-label-button.h | 83 --- 18 files changed, 1779 insertions(+), 1870 deletions(-) create mode 100644 data/builder/media-select.builder delete mode 100644 src/media-combo-menu-item.c delete mode 100644 src/media-combo-menu-item.h delete mode 100644 src/media-combo-menu.c delete mode 100644 src/media-combo-menu.h delete mode 100644 src/media-combo.c delete mode 100644 src/media-combo.h create mode 100644 src/media-select.c create mode 100644 src/media-select.h delete mode 100644 src/rotate-label-button.c delete mode 100644 src/rotate-label-button.h diff --git a/data/builder/Makefile.am b/data/builder/Makefile.am index 4b48a699..1c8744d6 100644 --- a/data/builder/Makefile.am +++ b/data/builder/Makefile.am @@ -5,6 +5,7 @@ builderdir = $(datadir)/$(GLABELS_BRANCH)/builder/ builder_DATA = \ property-bar.builder \ print-op-dialog-custom-widget.builder \ + media-select.builder \ new-label-dialog.builder \ merge-properties-dialog.builder \ template-designer.builder \ diff --git a/data/builder/media-select.builder b/data/builder/media-select.builder new file mode 100644 index 00000000..9cb814fa --- /dev/null +++ b/data/builder/media-select.builder @@ -0,0 +1,229 @@ + + + + + + True + window1 + + + True + + + True + 0 + + + 320 + True + 6 + vertical + + + True + vertical + + + + + + False + False + 0 + + + + + True + True + automatic + automatic + in + + + True + False + + + + + 1 + + + + + + + True + Recent templates + + + False + + + + + True + 6 + vertical + + + True + 12 + + + True + 6 + + + True + Brand: + + + False + False + 0 + + + + + True + False + + + False + 1 + + + + + False + False + 0 + + + + + True + 6 + + + True + Page size: + + + False + False + 0 + + + + + True + False + + + False + 1 + + + + + False + 1 + + + + + True + 6 + + + True + Category: + + + False + False + 0 + + + + + True + False + + + False + 1 + + + + + False + 2 + + + + + False + 6 + 0 + + + + + True + vertical + + + + + + False + False + 1 + + + + + True + True + automatic + automatic + in + + + True + False + + + + + 2 + + + + + 1 + + + + + True + Search all templates + + + 1 + False + + + + + 0 + + + + + + diff --git a/data/builder/new-label-dialog.builder b/data/builder/new-label-dialog.builder index e5914100..9f3f5d07 100644 --- a/data/builder/new-label-dialog.builder +++ b/data/builder/new-label-dialog.builder @@ -9,356 +9,474 @@ 6 18 - + True - vertical - 6 + True - + True - 0 - none + 6 + vertical + 12 + + + True + 0 + Choose label or card product from hundreds of predefined templates. You may also +define your own templates. + + + False + False + 0 + + + + + True + + + + + + False + False + 1 + + + + + + + True + page 1 + + + False + + + + + True + 6 + vertical + 12 + + + True + 0 + Select orientation of label content. + + + False + False + 0 + + - + True - 12 + True - + True - 2 - 2 - 12 - 6 + vertical + 12 - + True - 0 - Template: + + + - GTK_FILL + False + False + 0 - + True - + + Normal + True + True + False + True + True + + + False + 0 + - 1 - 2 + False + False + 1 + + + False + False + 0 + + + + + True + vertical + 12 - + True - 0 - 0 - Orientation: + + + - 1 - 2 - GTK_FILL + False + False + 0 - + True - + + Rotated + True + True + False + True + normal_radio + + + False + 0 + - 1 - 2 - 1 - 2 - GTK_FILL + False + False + 1 + + False + False + 1 + - - - - True - <b>Select media</b> - True - + + False + 1 + - False - False - 0 + 1 - - - - - - 0 - - - - - True - True - - - True - 3 - vertical - - - - - - + True - Preview + page 2 + 1 False - + True - 9 + 6 vertical + 12 - + True - 7 - 2 - 12 - 6 - - - True - 0 - Description: - - - 2 - 3 - GTK_FILL - - - - - True - 0 - Page size: - - - 3 - 4 - GTK_FILL - - - - - True - 0 - Label size: - - - 4 - 5 - GTK_FILL - - - - - True - 0 - Layout: - - - 5 - 6 - GTK_FILL - - - - - True - 0 - 0 - Similar products: - - - 6 - 7 - GTK_FILL - - - - - True - 0 - - - 1 - 2 - 2 - 3 - - - - - True - 0 - - - 1 - 2 - 3 - 4 - - - - - True - 0 - - - 1 - 2 - 4 - 5 - - - - - True - 0 - - - 1 - 2 - 5 - 6 - - - - - True - 0 - - - 1 - 2 - - - - - True - 0 - Part #: - - - 1 - 2 - GTK_FILL - - + 0 + Please review and confirm your selection. + + + False + False + 0 + + + + + True + 24 - + True - 0 + vertical + + + True + vertical + + + + + + False + False + 0 + + - 1 - 2 - 1 - 2 + False + False + 0 - - 77 + True - True - never - automatic - in + 7 + 2 + 12 + 6 + + + True + 0 + Description: + + + 2 + 3 + GTK_FILL + + + + + + True + 0 + Page size: + + + 3 + 4 + GTK_FILL + + + + + + True + 0 + Label size: + + + 4 + 5 + GTK_FILL + + + - + True - queue - none + 0 + Layout: + + + 5 + 6 + GTK_FILL + + + + + + True + 0 + 0 + Similar products: + + + 6 + 7 + GTK_FILL + GTK_FILL + + + + + True + 0 + + + 1 + 2 + 2 + 3 + + + + + + True + 0 + + + 1 + 2 + 3 + 4 + + + + + + True + 0 + + + 1 + 2 + 4 + 5 + + + + + + True + 0 + + + 1 + 2 + 5 + 6 + + + + + + True + 0 + + + 1 + 2 + + + + + + True + 0 + Part #: + + + 1 + 2 + GTK_FILL + + + + + + True + 0 + + + 1 + 2 + 1 + 2 + + + + + + 77 + True + True + never + automatic - + True - 0 - 0 - 1 + queue + etched-in + + + True + 0 + 0 + 1 2 3 4 + + + + 1 + 2 + 6 + 7 + + + + + True + 0 + Vendor: + + + GTK_FILL + + - 1 - 2 - 6 - 7 - - - - - - True - 0 - Vendor: - - - GTK_FILL + 1 - False - False - 0 + 1 - 1 + 2 - + True - Information + page 3 - 1 + 2 False - - - - - - - 1 + 0 diff --git a/po/POTFILES.in b/po/POTFILES.in index 1c35ca9a..24ce7cda 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -81,12 +81,8 @@ src/label-text.c src/label-text.h #src/marshal.c #src/marshal.h -src/media-combo.c -src/media-combo.h -src/media-combo-menu.c -src/media-combo-menu.h -src/media-combo-menu-item.c -src/media-combo-menu-item.h +src/media-select.c +src/media-select.h src/merge.c src/merge.h src/merge-evolution.c @@ -141,8 +137,6 @@ src/message-bar.c src/message-bar.h src/recent.c src/recent.h -src/rotate-label-button.c -src/rotate-label-button.h src/stock.c src/stock.h src/str-util.c diff --git a/src/Makefile.am b/src/Makefile.am index 49e6e0ef..9c9f5f15 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -162,12 +162,8 @@ glabels_3_SOURCES = \ mini-preview-pixbuf.h \ mini-preview-pixbuf-cache.c \ mini-preview-pixbuf-cache.h \ - media-combo.c \ - media-combo.h \ - media-combo-menu.c \ - media-combo-menu.h \ - media-combo-menu-item.c \ - media-combo-menu-item.h \ + media-select.c \ + media-select.h \ message-bar.c \ message-bar.h \ template-history.c \ @@ -178,8 +174,6 @@ glabels_3_SOURCES = \ mini-preview.h \ mini-label-preview.c \ mini-label-preview.h \ - rotate-label-button.c \ - rotate-label-button.h \ wdgt-chain-button.c \ wdgt-chain-button.h \ field-button.c \ diff --git a/src/file.c b/src/file.c index ca04e5fd..2b490535 100644 --- a/src/file.c +++ b/src/file.c @@ -54,12 +54,10 @@ static gchar *save_path = NULL; /*===========================================*/ /* Local function prototypes. */ /*===========================================*/ -static void new_response (GtkDialog *dialog, - gint response, +static void new_complete (GtkDialog *dialog, gpointer user_data); -static void properties_response (GtkDialog *dialog, - gint response, +static void properties_complete (GtkDialog *dialog, gpointer user_data); static void open_response (GtkDialog *chooser, @@ -87,8 +85,7 @@ gl_file_new (glWindow *window) g_object_set_data (G_OBJECT (dialog), "parent_window", window); - g_signal_connect (G_OBJECT(dialog), "response", - G_CALLBACK (new_response), dialog); + g_signal_connect (G_OBJECT(dialog), "complete", G_CALLBACK (new_complete), dialog); if (page_size != NULL) { gl_new_label_dialog_set_filter_parameters (GL_NEW_LABEL_DIALOG (dialog), @@ -112,8 +109,7 @@ gl_file_new (glWindow *window) /* PRIVATE. New "ok" button callback. */ /*---------------------------------------------------------------------------*/ static void -new_response (GtkDialog *dialog, - gint response, +new_complete (GtkDialog *dialog, gpointer user_data) { lglTemplate *template; @@ -123,48 +119,38 @@ new_response (GtkDialog *dialog, gl_debug (DEBUG_FILE, "START"); - switch (response) { - - case GTK_RESPONSE_OK: + gl_new_label_dialog_get_filter_parameters (GL_NEW_LABEL_DIALOG (dialog), + &page_size, + &category); - gl_new_label_dialog_get_filter_parameters (GL_NEW_LABEL_DIALOG (dialog), - &page_size, - &category); + if (sheet_name != NULL) + { + g_free (sheet_name); + } - if (sheet_name != NULL) - g_free (sheet_name); - sheet_name = - gl_new_label_dialog_get_template_name (GL_NEW_LABEL_DIALOG (dialog)); + sheet_name = gl_new_label_dialog_get_template_name (GL_NEW_LABEL_DIALOG (dialog)); - rotate_flag = - gl_new_label_dialog_get_rotate_state (GL_NEW_LABEL_DIALOG (dialog)); + rotate_flag = gl_new_label_dialog_get_rotate_state (GL_NEW_LABEL_DIALOG (dialog)); - template = lgl_db_lookup_template_from_name (sheet_name); + template = lgl_db_lookup_template_from_name (sheet_name); - label = GL_LABEL(gl_label_new ()); - gl_label_set_template (label, template, FALSE); - gl_label_set_rotate_flag (label, rotate_flag, FALSE); + label = GL_LABEL(gl_label_new ()); + gl_label_set_template (label, template, FALSE); + gl_label_set_rotate_flag (label, rotate_flag, FALSE); - lgl_template_free (template); + lgl_template_free (template); - window = - GL_WINDOW (g_object_get_data (G_OBJECT (dialog), - "parent_window")); - if ( gl_window_is_empty (window) ) { - gl_window_set_label (window, label); - } else { - new_window = gl_window_new_from_label (label); - gtk_widget_show_all (new_window); - } + window = GL_WINDOW (g_object_get_data (G_OBJECT (dialog), "parent_window")); + if ( gl_window_is_empty (window) ) + { + gl_window_set_label (window, label); + } + else + { + new_window = gl_window_new_from_label (label); + gtk_widget_show_all (new_window); + } - break; - - default: - break; - } - - gtk_widget_destroy (GTK_WIDGET (dialog)); - gl_debug (DEBUG_FILE, "END"); } @@ -191,8 +177,7 @@ gl_file_properties (glLabel *label, g_object_set_data (G_OBJECT (dialog), "label", label); - g_signal_connect (G_OBJECT(dialog), "response", - G_CALLBACK (properties_response), dialog); + g_signal_connect (G_OBJECT(dialog), "complete", G_CALLBACK (properties_complete), dialog); template = gl_label_get_template (label); rotate_flag = gl_label_get_rotate_flag (label); @@ -221,45 +206,33 @@ gl_file_properties (glLabel *label, /* PRIVATE. Properties "ok" button callback. */ /*---------------------------------------------------------------------------*/ static void -properties_response (GtkDialog *dialog, - gint response, - gpointer user_data) +properties_complete (GtkDialog *dialog, + gpointer user_data) { lglTemplate *template; glLabel *label; gl_debug (DEBUG_FILE, "START"); - switch (response) { - - case GTK_RESPONSE_OK: - - gl_new_label_dialog_get_filter_parameters (GL_NEW_LABEL_DIALOG (dialog), - &page_size, - &category); + gl_new_label_dialog_get_filter_parameters (GL_NEW_LABEL_DIALOG (dialog), + &page_size, + &category); - if (sheet_name != NULL) - g_free (sheet_name); - sheet_name = - gl_new_label_dialog_get_template_name (GL_NEW_LABEL_DIALOG (dialog)); - - rotate_flag = - gl_new_label_dialog_get_rotate_state (GL_NEW_LABEL_DIALOG (dialog)); - - template = lgl_db_lookup_template_from_name (sheet_name); + if (sheet_name != NULL) + { + g_free (sheet_name); + } - label = GL_LABEL(g_object_get_data (G_OBJECT (dialog), "label")); + sheet_name = gl_new_label_dialog_get_template_name (GL_NEW_LABEL_DIALOG (dialog)); - gl_label_set_template (label, template, TRUE); - gl_label_set_rotate_flag (label, rotate_flag, TRUE); + rotate_flag = gl_new_label_dialog_get_rotate_state (GL_NEW_LABEL_DIALOG (dialog)); - break; + template = lgl_db_lookup_template_from_name (sheet_name); - default: - break; - } + label = GL_LABEL(g_object_get_data (G_OBJECT (dialog), "label")); - gtk_widget_destroy (GTK_WIDGET (dialog)); + gl_label_set_template (label, template, TRUE); + gl_label_set_rotate_flag (label, rotate_flag, TRUE); gl_debug (DEBUG_FILE, "END"); } diff --git a/src/media-combo-menu-item.c b/src/media-combo-menu-item.c deleted file mode 100644 index 0c3225fc..00000000 --- a/src/media-combo-menu-item.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * media-combo-menu-item.c - * Copyright (C) 2010 Jim Evins . - * - * This file is part of gLabels. - * - * gLabels is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * gLabels is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gLabels. If not, see . - */ - -#include - -#include "media-combo-menu-item.h" - -#include -#include - -#include -#include "mini-preview-pixbuf-cache.h" -#include "prefs.h" -#include "str-util.h" -#include "marshal.h" - - - -/*===========================================*/ -/* Private macros and constants. */ -/*===========================================*/ - - -/*===========================================*/ -/* Private types */ -/*===========================================*/ - -struct _glMediaComboMenuItemPrivate { - - gchar *name; - -}; - - -/*===========================================*/ -/* Private globals */ -/*===========================================*/ - - -/*===========================================*/ -/* Local function prototypes */ -/*===========================================*/ - -static void gl_media_combo_menu_item_finalize (GObject *object); - - -/****************************************************************************/ -/* Boilerplate Object stuff. */ -/****************************************************************************/ -G_DEFINE_TYPE (glMediaComboMenuItem, gl_media_combo_menu_item, GTK_TYPE_MENU_ITEM); - - -/*****************************************************************************/ -/* Class Init Function. */ -/*****************************************************************************/ -static void -gl_media_combo_menu_item_class_init (glMediaComboMenuItemClass *class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (class); - - gl_media_combo_menu_item_parent_class = g_type_class_peek_parent (class); - - gobject_class->finalize = gl_media_combo_menu_item_finalize; -} - - -/*****************************************************************************/ -/* Object Instance Init Function. */ -/*****************************************************************************/ -static void -gl_media_combo_menu_item_init (glMediaComboMenuItem *this) -{ - this->priv = g_new0 (glMediaComboMenuItemPrivate, 1); -} - - -/*****************************************************************************/ -/* Finalize Method. */ -/*****************************************************************************/ -static void -gl_media_combo_menu_item_finalize (GObject *object) -{ - glMediaComboMenuItem *this = GL_MEDIA_COMBO_MENU_ITEM (object); - - g_return_if_fail (object != NULL); - g_return_if_fail (GL_IS_MEDIA_COMBO_MENU_ITEM (object)); - - g_free (this->priv->name); - g_free (this->priv); - - G_OBJECT_CLASS (gl_media_combo_menu_item_parent_class)->finalize (object); -} - - -/*****************************************************************************/ -/** New Object Generator. */ -/*****************************************************************************/ -GtkWidget * -gl_media_combo_menu_item_new (gchar *name) -{ - glMediaComboMenuItem *this; - GtkWidget *hbox; - GtkWidget *preview; - GtkWidget *label; - GdkPixbuf *pixbuf; - lglTemplate *template; - lglTemplateFrame *frame; - gchar *size_string; - gchar *layout_string; - gchar *label_markup; - - this = g_object_new (GL_TYPE_MEDIA_COMBO_MENU_ITEM, NULL); - - this->priv->name = g_strdup (name); - - hbox = gtk_hbox_new (FALSE, 6); - gtk_container_add (GTK_CONTAINER (this), hbox); - - pixbuf = gl_mini_preview_pixbuf_cache_get_pixbuf (name); - preview = gtk_image_new_from_pixbuf (pixbuf); - gtk_box_pack_start (GTK_BOX (hbox), preview, FALSE, FALSE, 0); - g_object_unref (G_OBJECT (pixbuf)); - - template = lgl_db_lookup_template_from_name (name); - frame = (lglTemplateFrame *)template->frames->data; - size_string = lgl_template_frame_get_size_description (frame, gl_prefs_model_get_units (gl_prefs)); - layout_string = lgl_template_frame_get_layout_description (frame); - label_markup = g_strdup_printf ("%s: %s\n%s\n%s", - name, template->description, size_string, layout_string); - g_free (size_string); - g_free (layout_string); - lgl_template_free (template); - - label = gtk_label_new (NULL); - gtk_label_set_markup (GTK_LABEL (label), label_markup); - g_free (label_markup); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - - return GTK_WIDGET (this); -} - - -/*****************************************************************************/ -/* Get family. */ -/*****************************************************************************/ -gchar * -gl_media_combo_menu_item_get_name (glMediaComboMenuItem *this) -{ - return g_strdup (this->priv->name); -} - - - -/* - * Local Variables: -- emacs - * mode: C -- emacs - * c-basic-offset: 8 -- emacs - * tab-width: 8 -- emacs - * indent-tabs-mode: nil -- emacs - * End: -- emacs - */ diff --git a/src/media-combo-menu-item.h b/src/media-combo-menu-item.h deleted file mode 100644 index 4aa6ad42..00000000 --- a/src/media-combo-menu-item.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * media-combo-menu-item.h - * Copyright (C) 2010 Jim Evins . - * - * This file is part of gLabels. - * - * gLabels is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * gLabels is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gLabels. If not, see . - */ - -#ifndef __MEDIA_COMBO_MENU_ITEM_H__ -#define __MEDIA_COMBO_MENU_ITEM_H__ - - -#include - - -G_BEGIN_DECLS - -#define GL_TYPE_MEDIA_COMBO_MENU_ITEM (gl_media_combo_menu_item_get_type ()) -#define GL_MEDIA_COMBO_MENU_ITEM(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), GL_TYPE_MEDIA_COMBO_MENU_ITEM, glMediaComboMenuItem )) -#define GL_MEDIA_COMBO_MENU_ITEM_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_MEDIA_COMBO_MENU_ITEM, glMediaComboMenuItemClass)) -#define GL_IS_MEDIA_COMBO_MENU_ITEM(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_MEDIA_COMBO_MENU_ITEM)) -#define GL_IS_MEDIA_COMBO_MENU_ITEM_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_MEDIA_COMBO_MENU_ITEM)) - -typedef struct _glMediaComboMenuItem glMediaComboMenuItem; -typedef struct _glMediaComboMenuItemPrivate glMediaComboMenuItemPrivate; -typedef struct _glMediaComboMenuItemClass glMediaComboMenuItemClass; - -struct _glMediaComboMenuItem { - GtkMenuItem parent_widget; - - glMediaComboMenuItemPrivate *priv; -}; - -struct _glMediaComboMenuItemClass { - GtkMenuItemClass parent_class; -}; - - -GType gl_media_combo_menu_item_get_type (void) G_GNUC_CONST; - -GtkWidget *gl_media_combo_menu_item_new (gchar *name); - -gchar *gl_media_combo_menu_item_get_name (glMediaComboMenuItem *this); - - -G_END_DECLS - -#endif /* __MEDIA_COMBO_MENU_ITEM_H__ */ - - - -/* - * Local Variables: -- emacs - * mode: C -- emacs - * c-basic-offset: 8 -- emacs - * tab-width: 8 -- emacs - * indent-tabs-mode: nil -- emacs - * End: -- emacs - */ diff --git a/src/media-combo-menu.c b/src/media-combo-menu.c deleted file mode 100644 index 4f117d50..00000000 --- a/src/media-combo-menu.c +++ /dev/null @@ -1,332 +0,0 @@ -/* - * media-combo-menu.c - * Copyright (C) 2010 Jim Evins . - * - * This file is part of gLabels. - * - * gLabels is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * gLabels is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gLabels. If not, see . - */ - -#include - -#include "media-combo-menu.h" - -#include -#include - -#include -#include "media-combo-menu-item.h" -#include "template-history.h" -#include "marshal.h" - - -/*===========================================*/ -/* Private macros and constants. */ -/*===========================================*/ - - -/*===========================================*/ -/* Private types */ -/*===========================================*/ - -struct _glMediaComboMenuPrivate { - - gchar *media; - - GtkWidget *recent_menu_item; - GtkWidget *recent_sub_menu; - -}; - -enum { - MEDIA_CHANGED, - LAST_SIGNAL -}; - - -/*===========================================*/ -/* Private globals */ -/*===========================================*/ - -static guint signals[LAST_SIGNAL] = {0}; - - -/*===========================================*/ -/* Local function prototypes */ -/*===========================================*/ - -static void gl_media_combo_menu_finalize (GObject *object); - -static void menu_item_activate_cb (glMediaComboMenuItem *item, - glMediaComboMenu *this); - -static GtkWidget *new_brand_sub_menu (glMediaComboMenu *this, - const gchar *paper_id, - const GList *brand_list); - -static GtkWidget *new_part_sub_menu (glMediaComboMenu *this, - const GList *part_list); - -static void media_history_changed_cb (glMediaComboMenu *this); - - - -/****************************************************************************/ -/* Boilerplate Object stuff. */ -/****************************************************************************/ -G_DEFINE_TYPE (glMediaComboMenu, gl_media_combo_menu, GTK_TYPE_MENU); - - -/*****************************************************************************/ -/* Class Init Function. */ -/*****************************************************************************/ -static void -gl_media_combo_menu_class_init (glMediaComboMenuClass *class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (class); - - gl_media_combo_menu_parent_class = g_type_class_peek_parent (class); - - gobject_class->finalize = gl_media_combo_menu_finalize; - - signals[MEDIA_CHANGED] = - g_signal_new ("media_changed", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (glMediaComboMenuClass, media_changed), - NULL, NULL, - gl_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - - -/*****************************************************************************/ -/* Object Instance Init Function. */ -/*****************************************************************************/ -static void -gl_media_combo_menu_init (glMediaComboMenu *this) -{ - GtkWidget *menu_item; - GtkWidget *sub_menu; - const GList *list; - GList *paper_id_list, *p_id; - gchar *paper_id, *paper_name; - GList *brand_list; - - this->priv = g_new0 (glMediaComboMenuPrivate, 1); - - - menu_item = gtk_menu_item_new_with_label (_("Recent templates")); - gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item); - - list = gl_template_history_model_get_name_list (gl_template_history); - sub_menu = new_part_sub_menu (this, list); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu); - gtk_widget_set_sensitive (menu_item, list != NULL); - - this->priv->recent_menu_item = menu_item; - this->priv->recent_sub_menu = sub_menu; - - menu_item = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item); - - paper_id_list = lgl_db_get_paper_id_list (); - - for ( p_id = paper_id_list; p_id; p_id = p_id->next ) - { - paper_id = p_id->data; - paper_name = lgl_db_lookup_paper_name_from_id (paper_id); - - brand_list = lgl_db_get_brand_list (paper_id, NULL); - if ( brand_list ) - { - menu_item = gtk_menu_item_new_with_label (paper_name); - gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item); - - sub_menu = new_brand_sub_menu (this, paper_id, brand_list); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu); - } - lgl_db_free_brand_list ( brand_list ); - } - - lgl_db_free_paper_id_list (paper_id_list); - - g_signal_connect_swapped (gl_template_history, "changed", - G_CALLBACK (media_history_changed_cb), this); - -} - - -/*****************************************************************************/ -/* Finalize Method. */ -/*****************************************************************************/ -static void -gl_media_combo_menu_finalize (GObject *object) -{ - glMediaComboMenu *this = GL_MEDIA_COMBO_MENU (object); - - g_return_if_fail (object != NULL); - g_return_if_fail (GL_IS_MEDIA_COMBO_MENU (object)); - - g_free (this->priv); - - G_OBJECT_CLASS (gl_media_combo_menu_parent_class)->finalize (object); -} - - -/*****************************************************************************/ -/** New Object Generator. */ -/*****************************************************************************/ -GtkWidget * -gl_media_combo_menu_new (void) -{ - glMediaComboMenu *this; - - this = g_object_new (gl_media_combo_menu_get_type (), NULL); - - return GTK_WIDGET (this); -} - - -/*****************************************************************************/ -/* menu_item activate callback. */ -/*****************************************************************************/ -static void menu_item_activate_cb (glMediaComboMenuItem *item, - glMediaComboMenu *this) -{ - this->priv->media = gl_media_combo_menu_item_get_name (item); - - g_signal_emit (this, signals[MEDIA_CHANGED], 0); - - gtk_widget_hide (GTK_WIDGET (this)); -} - - -/*****************************************************************************/ -/* Get media name. */ -/*****************************************************************************/ -gchar * -gl_media_combo_menu_get_name (glMediaComboMenu *this) -{ - return g_strdup (this->priv->media); -} - - -/*****************************************************************************/ -/* Create a new brand sub menu from media list. */ -/*****************************************************************************/ -static GtkWidget * -new_brand_sub_menu (glMediaComboMenu *this, - const gchar *paper_id, - const GList *brand_list) -{ - GtkWidget *menu; - GtkWidget *menu_item; - GtkWidget *sub_menu; - GList *p_brand; - gchar *brand; - GList *part_list; - - menu = gtk_menu_new (); - - for ( p_brand = (GList *)brand_list; p_brand; p_brand = p_brand->next ) - { - brand = p_brand->data; - - part_list = lgl_db_get_template_name_list_all (brand, paper_id, NULL); - if ( part_list ) - { - menu_item = gtk_menu_item_new_with_label (brand); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); - - sub_menu = new_part_sub_menu (this, part_list); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu); - } - lgl_db_free_brand_list ( part_list ); - } - - gtk_widget_show (menu); - - return menu; -} - - -/*****************************************************************************/ -/* Create a new part sub menu from part list. */ -/*****************************************************************************/ -static GtkWidget * -new_part_sub_menu (glMediaComboMenu *this, - const GList *part_list) -{ - GtkWidget *menu; - GtkWidget *menu_item; - GList *p; - - menu = gtk_menu_new (); - - for ( p = (GList *)part_list; p != NULL; p = p->next ) - { - menu_item = gl_media_combo_menu_item_new (p->data); - gtk_widget_show_all (menu_item); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); - g_signal_connect (menu_item, "activate", - G_CALLBACK (menu_item_activate_cb), this); - } - - gtk_widget_show (menu); - return menu; -} - - -/*****************************************************************************/ -/* Media history changed callback. */ -/*****************************************************************************/ -static void -media_history_changed_cb (glMediaComboMenu *this) -{ - GList *list; - - /* - * Remove old sub menu - */ - gtk_menu_item_set_submenu (GTK_MENU_ITEM (this->priv->recent_menu_item), - NULL); - - /* - * Build new sub menu - */ - list = gl_template_history_model_get_name_list (gl_template_history); - this->priv->recent_sub_menu = new_part_sub_menu (this, list); - - /* - * Attach to top-level menu item - */ - gtk_menu_item_set_submenu (GTK_MENU_ITEM (this->priv->recent_menu_item), - this->priv->recent_sub_menu); - gtk_widget_set_sensitive (this->priv->recent_menu_item, list != NULL); - - gl_template_history_model_free_name_list (list); -} - - - - -/* - * Local Variables: -- emacs - * mode: C -- emacs - * c-basic-offset: 8 -- emacs - * tab-width: 8 -- emacs - * indent-tabs-mode: nil -- emacs - * End: -- emacs - */ diff --git a/src/media-combo-menu.h b/src/media-combo-menu.h deleted file mode 100644 index 5c83e587..00000000 --- a/src/media-combo-menu.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * media-combo-menu.h - * Copyright (C) 2010 Jim Evins . - * - * This file is part of gLabels. - * - * gLabels is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * gLabels is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gLabels. If not, see . - */ - -#ifndef __MEDIA_COMBO_MENU_H__ -#define __MEDIA_COMBO_MENU_H__ - -#include - - -G_BEGIN_DECLS - -#define GL_TYPE_MEDIA_COMBO_MENU (gl_media_combo_menu_get_type ()) -#define GL_MEDIA_COMBO_MENU(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), GL_TYPE_MEDIA_COMBO_MENU, glMediaComboMenu )) -#define GL_MEDIA_COMBO_MENU_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_MEDIA_COMBO_MENU, glMediaComboMenuClass)) -#define GL_IS_MEDIA_COMBO_MENU(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_MEDIA_COMBO_MENU)) -#define GL_IS_MEDIA_COMBO_MENU_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_MEDIA_COMBO_MENU)) - -typedef struct _glMediaComboMenu glMediaComboMenu; -typedef struct _glMediaComboMenuPrivate glMediaComboMenuPrivate; -typedef struct _glMediaComboMenuClass glMediaComboMenuClass; - -struct _glMediaComboMenu { - GtkMenu parent_widget; - - glMediaComboMenuPrivate *priv; -}; - -struct _glMediaComboMenuClass { - GtkMenuClass parent_class; - - /* - * Signals - */ - void (*media_changed) (glMediaComboMenu *object, - gpointer user_data); - -}; - - -GType gl_media_combo_menu_get_type (void) G_GNUC_CONST; - -GtkWidget *gl_media_combo_menu_new (void); - -gchar *gl_media_combo_menu_get_name (glMediaComboMenu *this); - - -G_END_DECLS - - -#endif /* __MEDIA_COMBO_MENU_H__ */ - - - -/* - * Local Variables: -- emacs - * mode: C -- emacs - * c-basic-offset: 8 -- emacs - * tab-width: 8 -- emacs - * indent-tabs-mode: nil -- emacs - * End: -- emacs - */ - diff --git a/src/media-combo.c b/src/media-combo.c deleted file mode 100644 index 6c7104e8..00000000 --- a/src/media-combo.c +++ /dev/null @@ -1,345 +0,0 @@ -/* - * media-combo.c - * Copyright (C) 2010 Jim Evins . - * - * This file is part of gLabels. - * - * gLabels is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * gLabels is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gLabels. If not, see . - */ - -#include - -#include "media-combo.h" - -#include -#include - -#include "media-combo-menu.h" -#include "marshal.h" - - - -/*========================================================*/ -/* Private types. */ -/*========================================================*/ - -/** GL_MEDIA_COMBO Private fields */ -struct _glMediaComboPrivate { - - gchar *name; - - GtkWidget *label; - - GtkWidget *menu; -}; - -enum { - CHANGED, - LAST_SIGNAL -}; - - -/*========================================================*/ -/* Private globals. */ -/*========================================================*/ - -static guint signals[LAST_SIGNAL] = {0}; - - -/*========================================================*/ -/* Private function prototypes. */ -/*========================================================*/ - -static void gl_media_combo_finalize (GObject *object); - -static gboolean -button_press_event_cb (GtkWidget *widget, - GdkEventButton *event, - glMediaCombo *this); - -static void -menu_media_changed_cb (glMediaComboMenu *menu, - glMediaCombo *this); - -static void -menu_selection_done_cb (GtkMenuShell *object, - glMediaCombo *this); - - -/*****************************************************************************/ -/* Object infrastructure. */ -/*****************************************************************************/ -G_DEFINE_TYPE (glMediaCombo, gl_media_combo, GTK_TYPE_TOGGLE_BUTTON); - - -/*****************************************************************************/ -/* Class Init Function. */ -/*****************************************************************************/ -static void -gl_media_combo_class_init (glMediaComboClass *class) -{ - GObjectClass *gobject_class = (GObjectClass *) class; - - gl_media_combo_parent_class = g_type_class_peek_parent (class); - - gobject_class->finalize = gl_media_combo_finalize; - - signals[CHANGED] = - g_signal_new ("changed", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (glMediaComboClass, changed), - NULL, NULL, - gl_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - - -/*****************************************************************************/ -/* Object Instance Init Function. */ -/*****************************************************************************/ -static void -gl_media_combo_init (glMediaCombo *this) -{ - GtkWidget *hbox; - GtkWidget *arrow; - - this->priv = g_new0 (glMediaComboPrivate, 1); - - hbox = gtk_hbox_new (FALSE, 3); - gtk_container_add (GTK_CONTAINER (this), hbox); - - this->priv->label = gtk_label_new (""); - gtk_misc_set_alignment (GTK_MISC (this->priv->label), 0.0, 0.5); - gtk_widget_set_size_request (this->priv->label, 180, -1); - gtk_box_pack_start (GTK_BOX (hbox), this->priv->label, TRUE, TRUE, 0); - - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN); - gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0); - - g_signal_connect (this, "button_press_event", - G_CALLBACK(button_press_event_cb), this); -} - - -/*****************************************************************************/ -/* Finalize Method. */ -/*****************************************************************************/ -static void -gl_media_combo_finalize (GObject *object) -{ - glMediaCombo *this; - - g_return_if_fail (object && IS_GL_MEDIA_COMBO (object)); - this = GL_MEDIA_COMBO (object); - - g_free (this->priv->name); - g_object_ref_sink (this->priv->menu); - g_free (this->priv); - - G_OBJECT_CLASS (gl_media_combo_parent_class)->finalize (object); -} - - -/*****************************************************************************/ -/** New Object Generator. */ -/*****************************************************************************/ -GtkWidget * -gl_media_combo_new (void) -{ - glMediaCombo *this; - - this = g_object_new (TYPE_GL_MEDIA_COMBO, NULL); - - this->priv->menu = gl_media_combo_menu_new (); - - gtk_widget_show_all (this->priv->menu); - - g_signal_connect (this->priv->menu, "media_changed", - G_CALLBACK (menu_media_changed_cb), this); - g_signal_connect (this->priv->menu, "selection_done", - G_CALLBACK (menu_selection_done_cb), this); - - return GTK_WIDGET (this); -} - - -/*****************************************************************************/ -/* Set media name. */ -/*****************************************************************************/ -void -gl_media_combo_set_name (glMediaCombo *this, - const gchar *name) -{ - - g_free (this->priv->name); - this->priv->name = g_strdup (name); - - gtk_label_set_text (GTK_LABEL (this->priv->label), this->priv->name); -} - - -/*****************************************************************************/ -/* Get media name. */ -/*****************************************************************************/ -gchar * -gl_media_combo_get_name (glMediaCombo *this) -{ - return g_strdup (this->priv->name); -} - - -/*****************************************************************************/ -/* Menu positioning function. */ -/*****************************************************************************/ -static void -menu_position_function (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - glMediaCombo *this) -{ - GdkScreen *screen; - gint w_screen, h_screen; - GdkWindow *window; - gint x_window, y_window; - GtkAllocation allocation; - gint x_this, y_this, h_this; - GtkRequisition menu_requisition; - gint h_menu, w_menu; - - /* - * Screen size - */ - screen = gtk_widget_get_screen (GTK_WIDGET (this)); - w_screen = gdk_screen_get_width (screen); - h_screen = gdk_screen_get_height (screen); - - /* - * Absolute position of "this" window on screen. - */ - window = gtk_widget_get_window (GTK_WIDGET (this)); - gdk_window_get_origin (window, &x_window, &y_window); - - /* - * Position and size of "this" inside window - */ - gtk_widget_get_allocation (GTK_WIDGET (this), &allocation); - x_this = allocation.x; - y_this = allocation.y; - h_this = allocation.height; - - /* - * Size of menu. - */ - gtk_widget_size_request (this->priv->menu, &menu_requisition); - h_menu = menu_requisition.height; - w_menu = menu_requisition.width; - - /* - * Default position anchored to lower left corner of "this". - */ - *x = x_window + x_this; - *y = y_window + y_this + h_this; - - /* - * Adjust vertical position if menu if extends past bottom of screen. - */ - if ( (*y + h_menu) > h_screen ) - { - *y = y_window + y_this - h_menu; - - if ( *y < 0 ) - { - *y = h_screen - h_menu; - } - } - - /* - * Adjust horizontal position if menu if extends past edge of screen. - */ - if ( (*x + w_menu) > w_screen ) - { - *x = w_screen - w_menu; - } - - - *push_in = TRUE; -} - - -/*****************************************************************************/ -/* Button "button_press_event" callback. */ -/*****************************************************************************/ -static gboolean -button_press_event_cb (GtkWidget *widget, - GdkEventButton *event, - glMediaCombo *this) -{ - switch (event->button) - { - - case 1: - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this), TRUE); - - gtk_menu_popup (GTK_MENU (this->priv->menu), - NULL, NULL, - (GtkMenuPositionFunc)menu_position_function, this, - event->button, event->time); - break; - - default: - break; - - } - - return FALSE; -} - - -/*****************************************************************************/ -/* Menu "media changed" callback. */ -/*****************************************************************************/ -static void -menu_media_changed_cb (glMediaComboMenu *menu, - glMediaCombo *this) -{ - this->priv->name = gl_media_combo_menu_get_name (menu); - - gtk_label_set_text (GTK_LABEL (this->priv->label), this->priv->name); - - g_signal_emit (this, signals[CHANGED], 0); -} - - -/*****************************************************************************/ -/* Menu "selection done" callback. */ -/*****************************************************************************/ -static void -menu_selection_done_cb (GtkMenuShell *object, - glMediaCombo *this) -{ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this), FALSE); -} - - - -/* - * Local Variables: -- emacs - * mode: C -- emacs - * c-basic-offset: 8 -- emacs - * tab-width: 8 -- emacs - * indent-tabs-mode: nil -- emacs - * End: -- emacs - */ diff --git a/src/media-combo.h b/src/media-combo.h deleted file mode 100644 index c413d14b..00000000 --- a/src/media-combo.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * media-combo.h - * Copyright (C) 2009 Jim Evins . - * - * This file is part of gLabels. - * - * gLabels is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * gLabels is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gLabels. If not, see . - */ - -#ifndef __GL_MEDIA_COMBO_H__ -#define __GL_MEDIA_COMBO_H__ - - -#include - - -G_BEGIN_DECLS - -#define TYPE_GL_MEDIA_COMBO (gl_media_combo_get_type ()) -#define GL_MEDIA_COMBO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GL_MEDIA_COMBO, glMediaCombo)) -#define GL_MEDIA_COMBO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GL_MEDIA_COMBO, glMediaComboClass)) -#define IS_GL_MEDIA_COMBO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GL_MEDIA_COMBO)) -#define IS_GL_MEDIA_COMBO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GL_MEDIA_COMBO)) -#define GL_MEDIA_COMBO_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), TYPE_GL_MEDIA_COMBO, glMediaComboClass)) - - -typedef struct _glMediaCombo glMediaCombo; -typedef struct _glMediaComboPrivate glMediaComboPrivate; -typedef struct _glMediaComboClass glMediaComboClass; - - -struct _glMediaCombo { - GtkToggleButton parent; - - glMediaComboPrivate *priv; -}; - -struct _glMediaComboClass { - GtkToggleButtonClass parent_class; - - /* - * Signals - */ - void (*changed) (glMediaCombo *object, - gpointer user_data); - -}; - - -GType gl_media_combo_get_type (void) G_GNUC_CONST; - -GtkWidget *gl_media_combo_new (void); - -void gl_media_combo_set_name (glMediaCombo *this, - const gchar *name); - -gchar *gl_media_combo_get_name (glMediaCombo *this); - - -G_END_DECLS - -#endif /* __GL_COLOR_COMBO_H__ */ - - - -/* - * Local Variables: -- emacs - * mode: C -- emacs - * c-basic-offset: 8 -- emacs - * tab-width: 8 -- emacs - * indent-tabs-mode: nil -- emacs - * End: -- emacs - */ diff --git a/src/media-select.c b/src/media-select.c new file mode 100644 index 00000000..ae7860ab --- /dev/null +++ b/src/media-select.c @@ -0,0 +1,847 @@ +/* + * media-select.c + * Copyright (C) 2001-2009 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels. If not, see . + */ + +#include + +#include "media-select.h" + +#include +#include +#include + +#include +#include "mini-preview-pixbuf-cache.h" +#include "prefs.h" +#include "message-bar.h" +#include "template-history.h" +#include "str-util.h" +#include "combo-util.h" +#include "builder-util.h" +#include "color.h" +#include "marshal.h" + +#include "debug.h" + + +#define HISTORY_SIZE 5 + +/*===========================================*/ +/* Private types */ +/*===========================================*/ + +enum { + NAME_COLUMN, + PREVIEW_COLUMN, + PREVIEW_COLUMN_STOCK, + PREVIEW_COLUMN_STOCK_SIZE, + DESCRIPTION_COLUMN, + N_COLUMNS +}; + +struct _glMediaSelectPrivate { + + GtkBuilder *builder; + + GtkWidget *notebook; + guint current_page_num; + + gint recent_page_num; + GtkWidget *recent_tab_vbox; + GtkWidget *recent_info_vbox; + GtkWidget *recent_info_bar; + GtkWidget *recent_treeview; + GtkListStore *recent_store; + + gint search_all_page_num; + GtkWidget *search_all_tab_vbox; + GtkWidget *search_all_info_vbox; + GtkWidget *search_all_info_bar; + GtkWidget *brand_combo; + GtkWidget *page_size_combo; + GtkWidget *category_combo; + GtkWidget *search_all_treeview; + GtkListStore *search_all_store; + + /* Prevent recursion */ + gboolean stop_signals; +}; + +enum { + CHANGED, + LAST_SIGNAL +}; + + +/*===========================================*/ +/* Private globals */ +/*===========================================*/ + +static gint media_select_signals[LAST_SIGNAL] = { 0 }; + + +/*===========================================*/ +/* Local function prototypes */ +/*===========================================*/ + +static void gl_media_select_finalize (GObject *object); + +static void gl_media_select_construct (glMediaSelect *this); + +static void filter_changed_cb (GtkComboBox *combo, + gpointer user_data); + +static void selection_changed_cb (GtkTreeSelection *selection, + gpointer user_data); + +static void page_changed_cb (GtkNotebook *notebook, + GtkNotebookPage *page, + guint page_num, + gpointer user_data); + +static void load_recent_list (glMediaSelect *this, + GtkListStore *store, + GtkTreeSelection *selection, + GList *list); + +static void load_search_all_list (glMediaSelect *this, + GtkListStore *store, + GtkTreeSelection *selection, + GList *list); + + +/****************************************************************************/ +/* Boilerplate Object stuff. */ +/****************************************************************************/ +G_DEFINE_TYPE (glMediaSelect, gl_media_select, GTK_TYPE_VBOX); + + +static void +gl_media_select_class_init (glMediaSelectClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + gl_media_select_parent_class = g_type_class_peek_parent (class); + + object_class->finalize = gl_media_select_finalize; + + media_select_signals[CHANGED] = + g_signal_new ("changed", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glMediaSelectClass, changed), + NULL, NULL, + gl_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + +static void +gl_media_select_init (glMediaSelect *this) +{ + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + this->priv = g_new0 (glMediaSelectPrivate, 1); + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + +static void +gl_media_select_finalize (GObject *object) +{ + glMediaSelect *this = GL_MEDIA_SELECT (object); + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + g_return_if_fail (object != NULL); + g_return_if_fail (GL_IS_MEDIA_SELECT (object)); + + if (this->priv->builder) + { + g_object_unref (this->priv->builder); + } + g_object_unref (this->priv->recent_store); + g_object_unref (this->priv->search_all_store); + g_free (this->priv); + + G_OBJECT_CLASS (gl_media_select_parent_class)->finalize (object); + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + +GtkWidget * +gl_media_select_new (void) +{ + glMediaSelect *this; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + this = g_object_new (gl_media_select_get_type (), NULL); + + gl_media_select_construct (this); + + gl_debug (DEBUG_MEDIA_SELECT, "END"); + + return GTK_WIDGET (this); +} + + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Construct composite widget. */ +/*--------------------------------------------------------------------------*/ +static void +gl_media_select_construct (glMediaSelect *this) +{ + gchar *builder_filename; + GtkBuilder *builder; + static gchar *object_ids[] = { "media_select_hbox", NULL }; + GError *error = NULL; + GtkWidget *hbox; + GList *recent_list = NULL; + GList *brands = NULL; + GList *page_sizes = NULL; + GList *categories = NULL; + GList *search_all_names = NULL; + const gchar *page_size_id; + gchar *page_size_name; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + GtkTreeSelection *recent_selection; + GtkTreeSelection *search_all_selection; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + g_return_if_fail (GL_IS_MEDIA_SELECT (this)); + g_return_if_fail (this->priv != NULL); + + builder = gtk_builder_new (); + builder_filename = g_build_filename (GLABELS_DATA_DIR, "builder", "media-select.builder", NULL); + gtk_builder_add_objects_from_file (builder, builder_filename, object_ids, &error); + g_free (builder_filename); + if (error) { + g_critical ("%s\n\ngLabels may not be installed correctly!", error->message); + g_error_free (error); + return; + } + + gl_builder_util_get_widgets (builder, + "media_select_hbox", &hbox, + "notebook", &this->priv->notebook, + "recent_tab_vbox", &this->priv->recent_tab_vbox, + "recent_info_vbox", &this->priv->recent_info_vbox, + "recent_treeview", &this->priv->recent_treeview, + "search_all_tab_vbox", &this->priv->search_all_tab_vbox, + "brand_combo", &this->priv->brand_combo, + "page_size_combo", &this->priv->page_size_combo, + "category_combo", &this->priv->category_combo, + "search_all_info_vbox", &this->priv->search_all_info_vbox, + "search_all_treeview", &this->priv->search_all_treeview, + NULL); + + gtk_container_add (GTK_CONTAINER (this), hbox); + this->priv->builder = builder; + + this->priv->recent_page_num = + gtk_notebook_page_num (GTK_NOTEBOOK (this->priv->notebook), + this->priv->recent_tab_vbox); + this->priv->search_all_page_num = + gtk_notebook_page_num (GTK_NOTEBOOK (this->priv->notebook), + this->priv->search_all_tab_vbox); + + gtk_widget_show_all (GTK_WIDGET (this)); + + /* Recent templates treeview */ + 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); + gtk_tree_view_set_model (GTK_TREE_VIEW (this->priv->recent_treeview), + GTK_TREE_MODEL (this->priv->recent_store)); + renderer = gtk_cell_renderer_pixbuf_new (); + column = gtk_tree_view_column_new_with_attributes ("", renderer, + "pixbuf", PREVIEW_COLUMN, + "stock-id", PREVIEW_COLUMN_STOCK, + "stock-size", PREVIEW_COLUMN_STOCK_SIZE, + NULL); + gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); + gtk_tree_view_append_column (GTK_TREE_VIEW (this->priv->recent_treeview), column); + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("", renderer, + "markup", DESCRIPTION_COLUMN, + NULL); + gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); + gtk_tree_view_append_column (GTK_TREE_VIEW (this->priv->recent_treeview), column); + recent_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->recent_treeview)); + recent_list = gl_template_history_model_get_name_list (gl_template_history); + load_recent_list (this, this->priv->recent_store, recent_selection, recent_list); + + page_size_id = gl_prefs_model_get_default_page_size (gl_prefs); + page_size_name = lgl_db_lookup_paper_name_from_id (page_size_id); + + /* Brand selection control */ + gl_combo_util_add_text_model (GTK_COMBO_BOX (this->priv->brand_combo)); + brands = lgl_db_get_brand_list (NULL, NULL); + brands = g_list_prepend (brands, g_strdup (_("Any"))); + gl_combo_util_set_strings (GTK_COMBO_BOX (this->priv->brand_combo), brands); + lgl_db_free_brand_list (brands); + gl_combo_util_set_active_text (GTK_COMBO_BOX (this->priv->brand_combo), + _("Any")); + + /* Page size selection control */ + gl_combo_util_add_text_model (GTK_COMBO_BOX (this->priv->page_size_combo)); + page_sizes = lgl_db_get_paper_name_list (); + page_sizes = g_list_prepend (page_sizes, g_strdup (_("Any"))); + gl_combo_util_set_strings (GTK_COMBO_BOX (this->priv->page_size_combo), page_sizes); + lgl_db_free_paper_name_list (page_sizes); + gl_combo_util_set_active_text (GTK_COMBO_BOX (this->priv->page_size_combo), + page_size_name); + + /* Category selection control */ + gl_combo_util_add_text_model (GTK_COMBO_BOX (this->priv->category_combo)); + categories = lgl_db_get_category_name_list (); + categories = g_list_prepend (categories, g_strdup (_("Any"))); + gl_combo_util_set_strings (GTK_COMBO_BOX (this->priv->category_combo), categories); + gl_combo_util_set_active_text (GTK_COMBO_BOX (this->priv->category_combo), + _("Any")); + lgl_db_free_category_name_list (categories); + + /* Search all treeview */ + 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); + gtk_tree_view_set_model (GTK_TREE_VIEW (this->priv->search_all_treeview), + GTK_TREE_MODEL (this->priv->search_all_store)); + renderer = gtk_cell_renderer_pixbuf_new (); + column = gtk_tree_view_column_new_with_attributes ("", renderer, + "pixbuf", PREVIEW_COLUMN, + "stock-id", PREVIEW_COLUMN_STOCK, + "stock-size", PREVIEW_COLUMN_STOCK_SIZE, + NULL); + gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); + gtk_tree_view_append_column (GTK_TREE_VIEW (this->priv->search_all_treeview), column); + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("", renderer, + "markup", DESCRIPTION_COLUMN, + NULL); + gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); + gtk_tree_view_append_column (GTK_TREE_VIEW (this->priv->search_all_treeview), column); + search_all_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->search_all_treeview)); + search_all_names = lgl_db_get_template_name_list_all (NULL, page_size_id, NULL); + load_search_all_list (this, this->priv->search_all_store, search_all_selection, search_all_names); + lgl_db_free_template_name_list (search_all_names); + + /* Connect signals to controls */ + g_signal_connect (G_OBJECT (this->priv->brand_combo), "changed", + G_CALLBACK (filter_changed_cb), + this); + g_signal_connect (G_OBJECT (this->priv->page_size_combo), "changed", + G_CALLBACK (filter_changed_cb), + this); + g_signal_connect (G_OBJECT (this->priv->category_combo), "changed", + G_CALLBACK (filter_changed_cb), + this); + g_signal_connect (G_OBJECT (recent_selection), "changed", + G_CALLBACK (selection_changed_cb), + this); + g_signal_connect (G_OBJECT (search_all_selection), "changed", + G_CALLBACK (selection_changed_cb), + this); + g_signal_connect (G_OBJECT (this->priv->notebook), "switch-page", + G_CALLBACK (page_changed_cb), + this); + + g_free (page_size_name); + + if ( recent_list ) + { + gtk_notebook_set_current_page (GTK_NOTEBOOK (this->priv->notebook), + this->priv->recent_page_num); + } + else + { + gtk_notebook_set_current_page (GTK_NOTEBOOK (this->priv->notebook), + this->priv->search_all_page_num); + } + gl_template_history_model_free_name_list (recent_list); + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. modify widget due to change in selection */ +/*--------------------------------------------------------------------------*/ +static void +filter_changed_cb (GtkComboBox *combo, + gpointer user_data) +{ + glMediaSelect *this = GL_MEDIA_SELECT (user_data); + gchar *brand; + gchar *page_size_name, *page_size_id; + gchar *category_name, *category_id; + GList *search_all_names; + GtkTreeSelection *selection; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + + this->priv->stop_signals = TRUE; + + /* Update template selections for new filter settings */ + brand = gtk_combo_box_get_active_text (GTK_COMBO_BOX (this->priv->brand_combo)); + page_size_name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (this->priv->page_size_combo)); + category_name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (this->priv->category_combo)); + if ( brand && strlen(brand) && + page_size_name && strlen(page_size_name) && + category_name && strlen(category_name) ) + { + gl_debug (DEBUG_MEDIA_SELECT, "brand = \"%s\"", brand); + gl_debug (DEBUG_MEDIA_SELECT, "page_size_name = \"%s\"", page_size_name); + gl_debug (DEBUG_MEDIA_SELECT, "category_name = \"%s\"", category_name); + if (!g_utf8_collate (brand, _("Any"))) + { + g_free (brand); + brand = NULL; + } + page_size_id = lgl_db_lookup_paper_id_from_name (page_size_name); + category_id = lgl_db_lookup_category_id_from_name (category_name); + gl_debug (DEBUG_MEDIA_SELECT, "page_size_id = \"%s\"", page_size_id); + gl_debug (DEBUG_MEDIA_SELECT, "category_id = \"%s\"", category_id); + search_all_names = lgl_db_get_template_name_list_all (brand, page_size_id, category_id); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->search_all_treeview)); + load_search_all_list (this, this->priv->search_all_store, selection, search_all_names); + lgl_db_free_template_name_list (search_all_names); + g_free (page_size_id); + g_free (category_id); + + /* Emit our "changed" signal */ + g_signal_emit (G_OBJECT (user_data), + media_select_signals[CHANGED], 0); + } + g_free (brand); + g_free (page_size_name); + g_free (category_name); + + + this->priv->stop_signals = FALSE; + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. modify widget due to change in selection */ +/*--------------------------------------------------------------------------*/ +static void +selection_changed_cb (GtkTreeSelection *selection, + gpointer user_data) +{ + glMediaSelect *this = GL_MEDIA_SELECT (user_data); + + if (this->priv->stop_signals) return; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + /* Emit our "changed" signal */ + g_signal_emit (G_OBJECT (user_data), + media_select_signals[CHANGED], 0); + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. modify widget due to change in selection */ +/*--------------------------------------------------------------------------*/ +static void +page_changed_cb (GtkNotebook *notebook, + GtkNotebookPage *page, + guint page_num, + gpointer user_data) +{ + glMediaSelect *this = GL_MEDIA_SELECT (user_data); + + if (this->priv->stop_signals) return; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + /* + * Store new current page, because this signal is emitted before the actual page change. + */ + this->priv->current_page_num = page_num; + + /* Emit our "changed" signal */ + g_signal_emit (G_OBJECT (user_data), + media_select_signals[CHANGED], 0); + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + +/****************************************************************************/ +/* query selected label template name. */ +/****************************************************************************/ +gchar * +gl_media_select_get_name (glMediaSelect *this) +{ + gint page_num; + GtkTreeSelection *selection; + GtkTreeIter iter; + GtkTreeModel *model; + gchar *name; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + page_num = this->priv->current_page_num; + if (page_num == this->priv->recent_page_num) + { + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->recent_treeview)); + } + else if (page_num == this->priv->search_all_page_num) + { + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->search_all_treeview)); + } + else + { + g_print ("notebook page = %d\n", page_num); + g_assert_not_reached (); + } + + if (gtk_tree_selection_get_mode (selection) == GTK_SELECTION_NONE) + { + name = NULL; + } + else + { + gtk_tree_selection_get_selected (selection, &model, &iter); + gtk_tree_model_get (model, &iter, NAME_COLUMN, &name, -1); + } + + gl_debug (DEBUG_MEDIA_SELECT, "END"); + return name; +} + + +/****************************************************************************/ +/* set selected label template name. */ +/****************************************************************************/ +void +gl_media_select_set_name (glMediaSelect *this, + gchar *name) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + GtkTreePath *path; + gchar *name_i; + gboolean flag; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (this->priv->search_all_treeview)); + g_return_if_fail (GTK_IS_TREE_SELECTION (selection)); + + model = GTK_TREE_MODEL (this->priv->search_all_store); + + for ( flag = gtk_tree_model_get_iter_first (model, &iter); + flag; + flag = gtk_tree_model_iter_next(model, &iter) ) + { + gtk_tree_model_get (model, &iter, NAME_COLUMN, &name_i, -1); + if (strcasecmp(name, name_i) == 0) + { + gtk_tree_selection_select_iter (selection, &iter); + path = gtk_tree_model_get_path (model, &iter); + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (this->priv->search_all_treeview), + path, + NULL, + TRUE, 0.5, 0.0); + gtk_tree_path_free (path); + break; + } + } + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + +/****************************************************************************/ +/* query current filter parameters. */ +/****************************************************************************/ +void +gl_media_select_get_filter_parameters (glMediaSelect *this, + gchar **page_size_id, + gchar **category_id) +{ + gchar *page_size_name, *category_name; + + gl_debug (DEBUG_MEDIA_SELECT, ""); + + g_free (*page_size_id); + g_free (*category_id); + + page_size_name = + gtk_combo_box_get_active_text (GTK_COMBO_BOX (this->priv->page_size_combo)); + + *page_size_id = lgl_db_lookup_paper_id_from_name (page_size_name); + + category_name = + gtk_combo_box_get_active_text (GTK_COMBO_BOX (this->priv->category_combo)); + + *category_id = lgl_db_lookup_category_id_from_name (category_name); + + g_free (page_size_name); + g_free (category_name); +} + + +/****************************************************************************/ +/* set filter parameters. */ +/****************************************************************************/ +void +gl_media_select_set_filter_parameters (glMediaSelect *this, + const gchar *page_size_id, + const gchar *category_id) +{ + gchar *page_size_name; + gchar *category_name; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + page_size_name = lgl_db_lookup_paper_name_from_id (page_size_id); + if (page_size_name == NULL) + { + page_size_name = g_strdup (_("Any")); + } + + gl_combo_util_set_active_text (GTK_COMBO_BOX (this->priv->page_size_combo), + page_size_name); + + category_name = lgl_db_lookup_category_name_from_id (category_id); + if (category_name == NULL) + { + category_name = g_strdup (_("Any")); + } + + gl_combo_util_set_active_text (GTK_COMBO_BOX (this->priv->category_combo), + category_name); + g_free (page_size_name); + g_free (category_name); + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Load list store from template name list. */ +/*--------------------------------------------------------------------------*/ +static void +load_recent_list (glMediaSelect *this, + GtkListStore *store, + GtkTreeSelection *selection, + GList *list) +{ + GList *p; + GtkTreeIter iter; + lglUnits units; + lglTemplate *template; + lglTemplateFrame *frame; + GdkPixbuf *pixbuf; + gchar *size; + gchar *layout; + gchar *description; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + gtk_list_store_clear (store); + + + if ( this->priv->recent_info_bar ) + { + gtk_container_remove (GTK_CONTAINER (this->priv->recent_info_vbox), + this->priv->recent_info_bar); + this->priv->recent_info_bar = NULL; + } + + if (list) + { + + units = gl_prefs_model_get_units (gl_prefs); + + for ( p=list; p!=NULL; p=p->next ) + { + + gl_debug (DEBUG_MEDIA_SELECT, "p->data = \"%s\"", p->data); + + template = lgl_db_lookup_template_from_name (p->data); + frame = (lglTemplateFrame *)template->frames->data; + pixbuf = gl_mini_preview_pixbuf_cache_get_pixbuf (p->data); + + size = lgl_template_frame_get_size_description (frame, units); + layout = lgl_template_frame_get_layout_description (frame); + description = g_strdup_printf ("%s: %s\n%s\n%s", + (gchar *)p->data, + template->description, + size, + layout); + g_free (size); + g_free (layout); + + lgl_template_free (template); + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + NAME_COLUMN, p->data, + PREVIEW_COLUMN, pixbuf, + DESCRIPTION_COLUMN, description, + -1); + + g_object_unref (G_OBJECT (pixbuf)); + g_free (description); + } + + gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); + gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); + gtk_tree_selection_select_iter (selection, &iter); + + } + else + { + this->priv->recent_info_bar = gl_message_bar_new (GTK_MESSAGE_INFO, + GTK_BUTTONS_NONE, + "%s", _("No recent templates found.")); + gl_message_bar_format_secondary_text (GL_MESSAGE_BAR (this->priv->recent_info_bar), + "%s", _("Try selecting a template from the \"Search all templates\" page.")); + + gtk_box_pack_start (GTK_BOX (this->priv->recent_info_vbox), + this->priv->recent_info_bar, + FALSE, FALSE, 0); + gtk_widget_show_all (this->priv->recent_info_bar); + + gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE); + + } + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Load list store from template name list. */ +/*--------------------------------------------------------------------------*/ +static void +load_search_all_list (glMediaSelect *this, + GtkListStore *store, + GtkTreeSelection *selection, + GList *list) +{ + GList *p; + GtkTreeIter iter; + lglUnits units; + lglTemplate *template; + lglTemplateFrame *frame; + GdkPixbuf *pixbuf; + gchar *size; + gchar *layout; + gchar *description; + + gl_debug (DEBUG_MEDIA_SELECT, "START"); + + gtk_list_store_clear (store); + + if ( this->priv->search_all_info_bar ) + { + gtk_container_remove (GTK_CONTAINER (this->priv->search_all_info_vbox), + this->priv->search_all_info_bar); + this->priv->search_all_info_bar = NULL; + } + + if (list) + { + + units = gl_prefs_model_get_units (gl_prefs); + + for ( p=list; p!=NULL; p=p->next ) + { + + gl_debug (DEBUG_MEDIA_SELECT, "p->data = \"%s\"", p->data); + + template = lgl_db_lookup_template_from_name (p->data); + frame = (lglTemplateFrame *)template->frames->data; + pixbuf = gl_mini_preview_pixbuf_cache_get_pixbuf (p->data); + + size = lgl_template_frame_get_size_description (frame, units); + layout = lgl_template_frame_get_layout_description (frame); + description = g_strdup_printf ("%s: %s\n%s\n%s", + (gchar *)p->data, + template->description, + size, + layout); + g_free (size); + g_free (layout); + + lgl_template_free (template); + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + NAME_COLUMN, p->data, + PREVIEW_COLUMN, pixbuf, + DESCRIPTION_COLUMN, description, + -1); + + g_object_unref (G_OBJECT (pixbuf)); + g_free (description); + } + + gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); + gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); + gtk_tree_selection_select_iter (selection, &iter); + + } + else + { + this->priv->search_all_info_bar = gl_message_bar_new (GTK_MESSAGE_INFO, + GTK_BUTTONS_NONE, + "%s", _("No match.")); + gl_message_bar_format_secondary_text (GL_MESSAGE_BAR (this->priv->search_all_info_bar), + "%s", _("Try selecting a different brand, page size or category.")); + + gtk_box_pack_start (GTK_BOX (this->priv->search_all_info_vbox), + this->priv->search_all_info_bar, + FALSE, FALSE, 0); + gtk_widget_show_all (this->priv->search_all_info_bar); + + gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE); + + } + + gl_debug (DEBUG_MEDIA_SELECT, "END"); +} + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/src/media-select.h b/src/media-select.h new file mode 100644 index 00000000..603eeb81 --- /dev/null +++ b/src/media-select.h @@ -0,0 +1,87 @@ +/* + * media-select.h + * Copyright (C) 2001-2009 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels. If not, see . + */ + +#ifndef __MEDIA_SELECT_H__ +#define __MEDIA_SELECT_H__ + +#include + + +G_BEGIN_DECLS + +#define GL_TYPE_MEDIA_SELECT (gl_media_select_get_type ()) +#define GL_MEDIA_SELECT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), GL_TYPE_MEDIA_SELECT, glMediaSelect )) +#define GL_MEDIA_SELECT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_MEDIA_SELECT, glMediaSelectClass)) +#define GL_IS_MEDIA_SELECT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_MEDIA_SELECT)) +#define GL_IS_MEDIA_SELECT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_MEDIA_SELECT)) + +typedef struct _glMediaSelect glMediaSelect; +typedef struct _glMediaSelectClass glMediaSelectClass; + +typedef struct _glMediaSelectPrivate glMediaSelectPrivate; + +struct _glMediaSelect { + GtkVBox parent_widget; + + glMediaSelectPrivate *priv; +}; + +struct _glMediaSelectClass { + GtkVBoxClass parent_class; + + void (*changed) (glMediaSelect *media_select, gpointer user_data); +}; + + +GType gl_media_select_get_type (void) G_GNUC_CONST; + +GtkWidget *gl_media_select_new (void); + +gchar *gl_media_select_get_name (glMediaSelect *this); + +void gl_media_select_set_name (glMediaSelect *this, + gchar *name); + +void gl_media_select_get_filter_parameters (glMediaSelect *this, + gchar **page_size_id, + gchar **category_id); + +void gl_media_select_set_filter_parameters (glMediaSelect *this, + const gchar *page_size_id, + const gchar *category_id); + +G_END_DECLS + +#endif + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/src/new-label-dialog.c b/src/new-label-dialog.c index 46621483..b6a92596 100644 --- a/src/new-label-dialog.c +++ b/src/new-label-dialog.c @@ -25,19 +25,21 @@ #include #include -#include "hig.h" +#include "marshal.h" #include "builder-util.h" #include "prefs.h" -#include "template-history.h" +#include "media-select.h" +#include "mini-label-preview.h" #include "mini-preview.h" -#include "media-combo.h" -#include "rotate-label-button.h" #include "debug.h" -#define MINI_PREVIEW_MIN_HEIGHT 300 -#define MINI_PREVIEW_MIN_WIDTH 256 +#define LABEL_PREVIEW_WIDTH 96 +#define LABEL_PREVIEW_HEIGHT 96 + +#define MINI_PREVIEW_MIN_WIDTH 300 +#define MINI_PREVIEW_MIN_HEIGHT 360 /*===========================================*/ @@ -48,10 +50,21 @@ struct _glNewLabelDialogPrivate { GtkBuilder *builder; - GtkWidget *preview_vbox; + GtkWidget *template_page_vbox; GtkWidget *combo_hbox; - GtkWidget *rotate_hbox; + GtkWidget *combo; + GtkWidget *rotate_page_vbox; + GtkWidget *normal_radio; + GtkWidget *rotated_radio; + GtkWidget *normal_preview_hbox; + GtkWidget *rotated_preview_hbox; + GtkWidget *normal_preview; + GtkWidget *rotated_preview; + + GtkWidget *confirm_page_vbox; + GtkWidget *preview_vbox; + GtkWidget *preview; GtkWidget *desc_label; GtkWidget *page_size_label; GtkWidget *label_size_label; @@ -59,10 +72,18 @@ struct _glNewLabelDialogPrivate { GtkWidget *vendor_label; GtkWidget *part_label; GtkWidget *similar_label; +}; - GtkWidget *preview; - GtkWidget *combo; - GtkWidget *rotate_button; +/* Page numbers for traversing GtkAssistant */ +enum { + TEMPLATE_PAGE_NUM = 0, + ROTATE_PAGE_NUM, + CONFIRM_PAGE_NUM +}; + +enum { + COMPLETE, + LAST_SIGNAL }; @@ -70,6 +91,8 @@ struct _glNewLabelDialogPrivate { /* Private globals */ /*===========================================*/ +static gint signals[LAST_SIGNAL] = { 0 }; + /*===========================================*/ /* Local function prototypes */ @@ -77,6 +100,13 @@ struct _glNewLabelDialogPrivate { static void gl_new_label_dialog_finalize (GObject *object); +static void cancel_cb (glNewLabelDialog *this); +static void apply_cb (glNewLabelDialog *this); +static void close_cb (glNewLabelDialog *this); + +static gint forward_page_function (gint current_page, + glNewLabelDialog *this); + static void combo_changed_cb (glNewLabelDialog *this); static void rotate_toggled_cb (glNewLabelDialog *this); @@ -89,7 +119,7 @@ static void set_info (glNewLabelDialog *this, /*****************************************************************************/ /* Boilerplate object stuff. */ /*****************************************************************************/ -G_DEFINE_TYPE (glNewLabelDialog, gl_new_label_dialog, GTK_TYPE_DIALOG); +G_DEFINE_TYPE (glNewLabelDialog, gl_new_label_dialog, GTK_TYPE_ASSISTANT); /*****************************************************************************/ @@ -105,6 +135,16 @@ gl_new_label_dialog_class_init (glNewLabelDialogClass *class) gl_new_label_dialog_parent_class = g_type_class_peek_parent (class); object_class->finalize = gl_new_label_dialog_finalize; + + signals[COMPLETE] = + g_signal_new ("complete", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glNewLabelDialogClass, complete), + NULL, NULL, + gl_marshal_VOID__VOID, + G_TYPE_NONE, 0); + } @@ -115,12 +155,16 @@ static void gl_new_label_dialog_init (glNewLabelDialog *this) { GtkWidget *vbox; + gchar *logo_filename; + GdkPixbuf *logo; GtkBuilder *builder; gchar *builder_filename; - static gchar *object_ids[] = { "new_label_dialog_hbox", NULL }; + static gchar *object_ids[] = { "template_page_vbox", + "rotate_page_vbox", + "confirm_page_vbox", + NULL }; GError *error = NULL; GtkWidget *new_label_dialog_hbox; - gchar *name; gl_debug (DEBUG_FILE, "START"); @@ -128,19 +172,9 @@ gl_new_label_dialog_init (glNewLabelDialog *this) this->priv = g_new0 (glNewLabelDialogPrivate, 1); - gtk_container_set_border_width (GTK_CONTAINER (this), GL_HIG_PAD1); - - gtk_dialog_set_has_separator (GTK_DIALOG (this), FALSE); - gtk_dialog_add_buttons (GTK_DIALOG (this), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - gtk_dialog_set_default_response (GTK_DIALOG (this), GTK_RESPONSE_OK); - gtk_window_set_destroy_with_parent (GTK_WINDOW (this), TRUE); - gtk_window_set_modal (GTK_WINDOW (this), TRUE); - - vbox = gtk_dialog_get_content_area (GTK_DIALOG (this)); - + logo_filename = g_build_filename (GLABELS_ICON_DIR, GLABELS_ICON, NULL); + logo = gdk_pixbuf_new_from_file (logo_filename, NULL); + g_free (logo_filename); builder = gtk_builder_new (); builder_filename = g_build_filename (GLABELS_DATA_DIR, "builder", "new-label-dialog.builder", NULL); @@ -153,10 +187,15 @@ gl_new_label_dialog_init (glNewLabelDialog *this) } gl_builder_util_get_widgets (builder, - "new_label_dialog_hbox", &new_label_dialog_hbox, - "preview_vbox", &this->priv->preview_vbox, + "template_page_vbox", &this->priv->template_page_vbox, "combo_hbox", &this->priv->combo_hbox, - "rotate_hbox", &this->priv->rotate_hbox, + "rotate_page_vbox", &this->priv->rotate_page_vbox, + "normal_radio", &this->priv->normal_radio, + "rotated_radio", &this->priv->rotated_radio, + "normal_preview_hbox", &this->priv->normal_preview_hbox, + "rotated_preview_hbox", &this->priv->rotated_preview_hbox, + "confirm_page_vbox", &this->priv->confirm_page_vbox, + "preview_vbox", &this->priv->preview_vbox, "desc_label", &this->priv->desc_label, "page_size_label", &this->priv->page_size_label, "label_size_label", &this->priv->label_size_label, @@ -166,29 +205,47 @@ gl_new_label_dialog_init (glNewLabelDialog *this) "similar_label", &this->priv->similar_label, NULL); - gtk_container_add (GTK_CONTAINER (vbox), new_label_dialog_hbox); this->priv->builder = builder; + gtk_assistant_append_page (GTK_ASSISTANT (this), this->priv->template_page_vbox); + gtk_assistant_set_page_title (GTK_ASSISTANT (this), this->priv->template_page_vbox, _("Select Product")); + gtk_assistant_set_page_header_image (GTK_ASSISTANT (this), this->priv->template_page_vbox, logo); + gtk_assistant_set_page_type (GTK_ASSISTANT (this), this->priv->template_page_vbox, GTK_ASSISTANT_PAGE_INTRO); + + this->priv->combo = gl_media_select_new (); + gtk_container_add (GTK_CONTAINER (this->priv->combo_hbox), this->priv->combo); + + gtk_assistant_append_page (GTK_ASSISTANT (this), this->priv->rotate_page_vbox); + gtk_assistant_set_page_title (GTK_ASSISTANT (this), this->priv->rotate_page_vbox, _("Choose Orientation")); + gtk_assistant_set_page_header_image (GTK_ASSISTANT (this), this->priv->rotate_page_vbox, logo); + gtk_assistant_set_page_complete (GTK_ASSISTANT (this), this->priv->rotate_page_vbox, TRUE); + + this->priv->normal_preview = gl_mini_label_preview_new (LABEL_PREVIEW_WIDTH, LABEL_PREVIEW_HEIGHT); + gtk_container_add (GTK_CONTAINER (this->priv->normal_preview_hbox), this->priv->normal_preview); + this->priv->rotated_preview = gl_mini_label_preview_new (LABEL_PREVIEW_WIDTH, LABEL_PREVIEW_HEIGHT); + gtk_container_add (GTK_CONTAINER (this->priv->rotated_preview_hbox), this->priv->rotated_preview); + + gtk_assistant_append_page (GTK_ASSISTANT (this), this->priv->confirm_page_vbox); + gtk_assistant_set_page_title (GTK_ASSISTANT (this), this->priv->confirm_page_vbox, _("Review")); + gtk_assistant_set_page_header_image (GTK_ASSISTANT (this), this->priv->confirm_page_vbox, logo); + gtk_assistant_set_page_type (GTK_ASSISTANT (this), this->priv->confirm_page_vbox, GTK_ASSISTANT_PAGE_CONFIRM); + gtk_assistant_set_page_complete (GTK_ASSISTANT (this), this->priv->confirm_page_vbox, TRUE); + this->priv->preview = gl_mini_preview_new (MINI_PREVIEW_MIN_HEIGHT, MINI_PREVIEW_MIN_WIDTH); gl_mini_preview_set_draw_arrow (GL_MINI_PREVIEW (this->priv->preview), TRUE); gl_mini_preview_set_rotate (GL_MINI_PREVIEW (this->priv->preview), FALSE); gtk_container_add (GTK_CONTAINER (this->priv->preview_vbox), this->priv->preview); - this->priv->combo = gl_media_combo_new (); - gtk_container_add (GTK_CONTAINER (this->priv->combo_hbox), this->priv->combo); + gtk_assistant_set_forward_page_func (GTK_ASSISTANT (this), (GtkAssistantPageFunc)forward_page_function, this, NULL); - this->priv->rotate_button = gl_rotate_label_button_new (); - gtk_container_add (GTK_CONTAINER (this->priv->rotate_hbox), this->priv->rotate_button); + g_signal_connect_swapped (G_OBJECT(this), "cancel", G_CALLBACK(cancel_cb), this); + g_signal_connect_swapped (G_OBJECT(this), "apply", G_CALLBACK(apply_cb), this); + g_signal_connect_swapped (G_OBJECT(this), "close", G_CALLBACK(close_cb), this); - g_signal_connect_swapped (G_OBJECT (this->priv->combo), "changed", - G_CALLBACK (combo_changed_cb), this); - g_signal_connect_swapped (G_OBJECT (this->priv->rotate_button), "changed", - G_CALLBACK (rotate_toggled_cb), this); + g_signal_connect_swapped (G_OBJECT (this->priv->combo), "changed", G_CALLBACK (combo_changed_cb), this); + g_signal_connect_swapped (G_OBJECT (this->priv->normal_radio), "toggled", G_CALLBACK (rotate_toggled_cb), this); + g_signal_connect_swapped (G_OBJECT (this->priv->rotated_radio), "toggled", G_CALLBACK (rotate_toggled_cb), this); - name = get_default_name (); - gl_media_combo_set_name (GL_MEDIA_COMBO (this->priv->combo), name); - gl_rotate_label_button_set_template_name (GL_ROTATE_LABEL_BUTTON (this->priv->rotate_button), name); - g_free (name); combo_changed_cb (this); gl_debug (DEBUG_FILE, "END"); @@ -237,6 +294,84 @@ gl_new_label_dialog_new (GtkWindow *win) } +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Handle non-linear forward traversal. */ +/*--------------------------------------------------------------------------*/ +static gint +forward_page_function (gint current_page, + glNewLabelDialog *this) +{ + gchar *name; + lglTemplate *template; + const lglTemplateFrame *frame; + gdouble w, h; + + switch (current_page) + { + case TEMPLATE_PAGE_NUM: + name = gl_media_select_get_name (GL_MEDIA_SELECT (this->priv->combo)); + if ( name != NULL ) + { + template = lgl_db_lookup_template_from_name (name); + frame = (lglTemplateFrame *)template->frames->data; + lgl_template_frame_get_size (frame, &w, &h); + + if ( w == h ) + { + /* Skip rotate page for square and circular labels. */ + return CONFIRM_PAGE_NUM; + } + } + return ROTATE_PAGE_NUM; + + case ROTATE_PAGE_NUM: + return CONFIRM_PAGE_NUM; + + case CONFIRM_PAGE_NUM: + default: + return -1; + } + + return -1; +} + + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. cancel callback. */ +/*--------------------------------------------------------------------------*/ +static void +cancel_cb (glNewLabelDialog *this) +{ + + gtk_widget_destroy (GTK_WIDGET(this)); + +} + + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. apply callback */ +/*--------------------------------------------------------------------------*/ +static void +apply_cb (glNewLabelDialog *this) +{ + + g_signal_emit (G_OBJECT (this), signals[COMPLETE], 0); + +} + + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. close callback */ +/*--------------------------------------------------------------------------*/ +static void +close_cb (glNewLabelDialog *this) +{ + + gtk_widget_destroy (GTK_WIDGET(this)); + +} + + /*---------------------------------------------------------------------------*/ /* PRIVATE. Template changed callback. */ /*---------------------------------------------------------------------------*/ @@ -247,12 +382,17 @@ combo_changed_cb (glNewLabelDialog *this) gl_debug (DEBUG_FILE, "START"); - name = gl_media_combo_get_name (GL_MEDIA_COMBO (this->priv->combo)); + name = gl_media_select_get_name (GL_MEDIA_SELECT (this->priv->combo)); + + gl_mini_label_preview_set_by_name (GL_MINI_LABEL_PREVIEW (this->priv->normal_preview), name, FALSE); + gl_mini_label_preview_set_by_name (GL_MINI_LABEL_PREVIEW (this->priv->rotated_preview), name, TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->normal_radio), TRUE); gl_mini_preview_set_by_name (GL_MINI_PREVIEW (this->priv->preview), name); - gl_rotate_label_button_set_template_name (GL_ROTATE_LABEL_BUTTON (this->priv->rotate_button), name); set_info (this, name); + gtk_assistant_set_page_complete (GTK_ASSISTANT (this), this->priv->template_page_vbox, (name != NULL)); + g_free (name); gl_debug (DEBUG_FILE, "END"); @@ -269,48 +409,13 @@ rotate_toggled_cb (glNewLabelDialog *this) gl_debug (DEBUG_FILE, "START"); - state = gl_rotate_label_button_get_state (GL_ROTATE_LABEL_BUTTON (this->priv->rotate_button)); + state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (this->priv->rotated_radio)); gl_mini_preview_set_rotate (GL_MINI_PREVIEW (this->priv->preview), state); gl_debug (DEBUG_FILE, "END"); } -/*---------------------------------------------------------------------------*/ -/* PRIVATE. Get default template name. */ -/*---------------------------------------------------------------------------*/ -static gchar * -get_default_name (void) -{ - gchar *name = NULL; - GList *list; - - list = gl_template_history_model_get_name_list (gl_template_history); - - if ( list ) - { - name = g_strdup (list->data); - gl_template_history_model_free_name_list (list); - } - else - { - gchar *page_size; - - page_size = gl_prefs_model_get_default_page_size (gl_prefs); - list = lgl_db_get_template_name_list_all (NULL, page_size, NULL); - g_free (page_size); - - if ( list ) - { - name = g_strdup (list->data); - lgl_db_free_template_name_list (list); - } - } - - return name; -} - - /*---------------------------------------------------------------------------*/ /* PRIVATE. Set information labels. */ /*---------------------------------------------------------------------------*/ @@ -406,7 +511,7 @@ gl_new_label_dialog_get_template_name (glNewLabelDialog *this) { gchar *name; - name = gl_media_combo_get_name (GL_MEDIA_COMBO (this->priv->combo)); + name = gl_media_select_get_name (GL_MEDIA_SELECT (this->priv->combo)); return name; } @@ -420,7 +525,7 @@ gl_new_label_dialog_set_template_name (glNewLabelDialog *this, gchar *name) { gl_mini_preview_set_by_name (GL_MINI_PREVIEW (this->priv->preview), name); - gl_media_combo_set_name (GL_MEDIA_COMBO (this->priv->combo), name); + gl_media_select_set_name (GL_MEDIA_SELECT (this->priv->combo), name); set_info (this, name); } @@ -453,7 +558,7 @@ gl_new_label_dialog_set_filter_parameters (glNewLabelDialog *this, gboolean gl_new_label_dialog_get_rotate_state (glNewLabelDialog *this) { - return gl_rotate_label_button_get_state (GL_ROTATE_LABEL_BUTTON (this->priv->rotate_button)); + return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (this->priv->rotated_radio)); } @@ -464,7 +569,7 @@ void gl_new_label_dialog_set_rotate_state (glNewLabelDialog *this, gboolean state) { - gl_rotate_label_button_set_state (GL_ROTATE_LABEL_BUTTON (this->priv->rotate_button), state); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->rotated_radio), state); gl_mini_preview_set_rotate (GL_MINI_PREVIEW (this->priv->preview), state); } diff --git a/src/new-label-dialog.h b/src/new-label-dialog.h index 2029a9fc..ccfd27fd 100644 --- a/src/new-label-dialog.h +++ b/src/new-label-dialog.h @@ -45,7 +45,7 @@ typedef struct _glNewLabelDialogPrivate glNewLabelDialogPrivate; struct _glNewLabelDialog { - GtkDialog parent_instance; + GtkAssistant parent_instance; glNewLabelDialogPrivate *priv; @@ -53,7 +53,9 @@ struct _glNewLabelDialog struct _glNewLabelDialogClass { - GtkDialogClass parent_class; + GtkAssistantClass parent_class; + + void (*complete) (glNewLabelDialog *this, gpointer user_data); }; diff --git a/src/rotate-label-button.c b/src/rotate-label-button.c deleted file mode 100644 index cf65db06..00000000 --- a/src/rotate-label-button.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * rotate-label-button.c - * Copyright (C) 2001-2009 Jim Evins . - * - * This file is part of gLabels. - * - * gLabels is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * gLabels is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gLabels. If not, see . - */ - -#include - -#include "rotate-label-button.h" - -#include -#include -#include - -#include -#include "mini-label-preview.h" -#include "hig.h" -#include "marshal.h" - -#include "debug.h" - - -/*========================================================*/ -/* Private macros and constants. */ -/*========================================================*/ - -#define SIZE 48 - - -/*===========================================*/ -/* Private types */ -/*===========================================*/ - -struct _glRotateLabelButtonPrivate { - - GtkWidget *no_rotate_radio; - GtkWidget *rotate_radio; - GtkWidget *no_rotate_preview; - GtkWidget *rotate_preview; -}; - -enum { - CHANGED, - LAST_SIGNAL -}; - - -/*===========================================*/ -/* Private globals */ -/*===========================================*/ - -static gint rotate_label_button_signals[LAST_SIGNAL] = { 0 }; - - -/*===========================================*/ -/* Local function prototypes */ -/*===========================================*/ - -static void gl_rotate_label_button_finalize (GObject *object); - -static void toggled_cb (GtkToggleButton *toggle, - gpointer user_data); - - -/****************************************************************************/ -/* Boilerplate Object stuff. */ -/****************************************************************************/ -G_DEFINE_TYPE (glRotateLabelButton, gl_rotate_label_button, GTK_TYPE_HBOX); - - -static void -gl_rotate_label_button_class_init (glRotateLabelButtonClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - gl_rotate_label_button_parent_class = g_type_class_peek_parent (class); - - object_class->finalize = gl_rotate_label_button_finalize; - - rotate_label_button_signals[CHANGED] = - g_signal_new ("changed", - G_OBJECT_CLASS_TYPE(object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (glRotateLabelButtonClass, changed), - NULL, NULL, - gl_marshal_VOID__VOID, - G_TYPE_NONE, 0); - -} - - -static void -gl_rotate_label_button_init (glRotateLabelButton *this) -{ - GtkWidget *vbox; - GtkWidget *label; - - this->priv = g_new0 (glRotateLabelButtonPrivate, 1); - - gtk_box_set_spacing (GTK_BOX (this), GL_HIG_PAD2); - - this->priv->no_rotate_radio = gtk_radio_button_new (NULL); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (this->priv->no_rotate_radio), - FALSE); - vbox = gtk_vbox_new (FALSE, 1); - this->priv->no_rotate_preview = gl_mini_label_preview_new (SIZE, SIZE); - gtk_box_pack_start (GTK_BOX (vbox), this->priv->no_rotate_preview, FALSE, FALSE, 0); - label = gtk_label_new (_("Normal")); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (this->priv->no_rotate_radio), vbox); - - - this->priv->rotate_radio = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (this->priv->no_rotate_radio)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (this->priv->rotate_radio), - FALSE); - vbox = gtk_vbox_new (FALSE, 1); - this->priv->rotate_preview = gl_mini_label_preview_new (SIZE, SIZE); - gtk_box_pack_start (GTK_BOX (vbox), this->priv->rotate_preview, FALSE, FALSE, 0); - label = gtk_label_new (_("Rotated")); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (this->priv->rotate_radio), vbox); - - gtk_box_pack_start (GTK_BOX (this), this->priv->no_rotate_radio, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (this), this->priv->rotate_radio, FALSE, FALSE, 0); - - /* Connect signals to controls */ - g_signal_connect (G_OBJECT (this->priv->no_rotate_radio), - "toggled", - G_CALLBACK (toggled_cb), this); - g_signal_connect (G_OBJECT (this->priv->rotate_radio), - "toggled", - G_CALLBACK (toggled_cb), this); -} - - -static void -gl_rotate_label_button_finalize (GObject *object) -{ - glRotateLabelButton *this = GL_ROTATE_LABEL_BUTTON (object); - - g_return_if_fail (object != NULL); - g_return_if_fail (GL_IS_ROTATE_LABEL_BUTTON (object)); - - g_free (this->priv); - - G_OBJECT_CLASS (gl_rotate_label_button_parent_class)->finalize (object); -} - - -GtkWidget * -gl_rotate_label_button_new (void) -{ - glRotateLabelButton *this; - - this = g_object_new (gl_rotate_label_button_get_type (), NULL); - - return GTK_WIDGET (this); -} - - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. modify widget due to change of check button */ -/*--------------------------------------------------------------------------*/ -static void -toggled_cb (GtkToggleButton *toggle, - gpointer user_data) -{ - - /* Emit our "changed" signal */ - g_signal_emit (G_OBJECT (user_data), - rotate_label_button_signals[CHANGED], 0); - -} - - -/****************************************************************************/ -/* query state of widget. */ -/****************************************************************************/ -gboolean -gl_rotate_label_button_get_state (glRotateLabelButton *this) -{ - return - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON - (this->priv->rotate_radio)); -} - -/****************************************************************************/ -/* set state of widget. */ -/****************************************************************************/ -void -gl_rotate_label_button_set_state (glRotateLabelButton *this, - gboolean state) -{ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON - (this->priv->rotate_radio), state); -} - -/****************************************************************************/ -/* set template for widget. */ -/****************************************************************************/ -void -gl_rotate_label_button_set_template_name (glRotateLabelButton *this, - gchar *name) -{ - lglTemplate *template; - const lglTemplateFrame *frame; - gdouble raw_w, raw_h; - - if (name == NULL) - { - gtk_widget_set_sensitive (this->priv->no_rotate_radio, FALSE); - gtk_widget_set_sensitive (this->priv->rotate_radio, FALSE); - } - else - { - template = lgl_db_lookup_template_from_name (name); - frame = (lglTemplateFrame *)template->frames->data; - - gl_mini_label_preview_set_by_name (GL_MINI_LABEL_PREVIEW (this->priv->no_rotate_preview), - name, FALSE); - gl_mini_label_preview_set_by_name (GL_MINI_LABEL_PREVIEW (this->priv->rotate_preview), - name, TRUE); - - lgl_template_frame_get_size (frame, &raw_w, &raw_h); - gtk_widget_set_sensitive (this->priv->no_rotate_radio, - (raw_w != raw_h)); - gtk_widget_set_sensitive (this->priv->rotate_radio, - (raw_w != raw_h)); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON - (this->priv->no_rotate_radio), TRUE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON - (this->priv->rotate_radio), FALSE); - } - -} - - - -/* - * Local Variables: -- emacs - * mode: C -- emacs - * c-basic-offset: 8 -- emacs - * tab-width: 8 -- emacs - * indent-tabs-mode: nil -- emacs - * End: -- emacs - */ diff --git a/src/rotate-label-button.h b/src/rotate-label-button.h deleted file mode 100644 index 049d80e8..00000000 --- a/src/rotate-label-button.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * rotate-label-button.h - * Copyright (C) 2001-2009 Jim Evins . - * - * This file is part of gLabels. - * - * gLabels is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * gLabels is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with gLabels. If not, see . - */ - -#ifndef __ROTATE_LABEL_BUTTON_H__ -#define __ROTATE_LABEL_BUTTON_H__ - -#include - -G_BEGIN_DECLS - -#define GL_TYPE_ROTATE_LABEL_BUTTON (gl_rotate_label_button_get_type ()) -#define GL_ROTATE_LABEL_BUTTON(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), GL_TYPE_ROTATE_LABEL_BUTTON, glRotateLabelButton )) -#define GL_ROTATE_LABEL_BUTTON_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_ROTATE_LABEL_BUTTON, glRotateLabelButtonClass)) -#define GL_IS_ROTATE_LABEL_BUTTON(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_ROTATE_LABEL_BUTTON)) -#define GL_IS_ROTATE_LABEL_BUTTON_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_ROTATE_LABEL_BUTTON)) - - -typedef struct _glRotateLabelButton glRotateLabelButton; -typedef struct _glRotateLabelButtonClass glRotateLabelButtonClass; - -typedef struct _glRotateLabelButtonPrivate glRotateLabelButtonPrivate; - -struct _glRotateLabelButton { - GtkHBox parent_widget; - - glRotateLabelButtonPrivate *priv; -}; - -struct _glRotateLabelButtonClass { - GtkHBoxClass parent_class; - - void (*changed) (glRotateLabelButton *rotate_label_button, - gpointer user_data); -}; - - -GType gl_rotate_label_button_get_type (void) G_GNUC_CONST; - -GtkWidget *gl_rotate_label_button_new (void); - -gboolean gl_rotate_label_button_get_state (glRotateLabelButton *rotate_label); - -void gl_rotate_label_button_set_state (glRotateLabelButton *rotate_label, - gboolean state); - -void gl_rotate_label_button_set_template_name (glRotateLabelButton *rotate_label, - gchar *name); - -G_END_DECLS - -#endif - - - -/* - * Local Variables: -- emacs - * mode: C -- emacs - * c-basic-offset: 8 -- emacs - * tab-width: 8 -- emacs - * indent-tabs-mode: nil -- emacs - * End: -- emacs - */ -- 2.39.5