1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * new-label-dialog.c: New label dialog module
8 * Copyright (C) 2006 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "new-label-dialog.h"
28 #include <glib/gi18n.h>
29 #include <glade/glade-xml.h>
30 #include <gtk/gtkdialog.h>
31 #include <gtk/gtkstock.h>
34 #include "wdgt-media-select.h"
35 #include "wdgt-rotate-label.h"
39 /*===========================================*/
40 /* Private data types */
41 /*===========================================*/
43 struct _glNewLabelDialogPrivate {
45 GtkWidget *media_select;
46 GtkWidget *rotate_label;
51 /*===========================================*/
53 /*===========================================*/
55 /*===========================================*/
56 /* Local function prototypes */
57 /*===========================================*/
59 static void gl_new_label_dialog_finalize (GObject *object);
61 static void gl_new_label_dialog_construct (glNewLabelDialog *dialog,
64 static void template_changed_cb (glWdgtMediaSelect *select,
69 /*****************************************************************************/
70 /* Boilerplate object stuff. */
71 /*****************************************************************************/
72 G_DEFINE_TYPE (glNewLabelDialog, gl_new_label_dialog, GTK_TYPE_DIALOG);
75 gl_new_label_dialog_class_init (glNewLabelDialogClass *class)
77 GObjectClass *object_class = G_OBJECT_CLASS (class);
79 gl_debug (DEBUG_FILE, "");
81 gl_new_label_dialog_parent_class = g_type_class_peek_parent (class);
83 object_class->finalize = gl_new_label_dialog_finalize;
87 gl_new_label_dialog_init (glNewLabelDialog *dialog)
89 gl_debug (DEBUG_FILE, "START");
91 g_return_if_fail (GL_IS_NEW_LABEL_DIALOG (dialog));
93 dialog->priv = g_new0 (glNewLabelDialogPrivate, 1);
95 gtk_container_set_border_width (GTK_CONTAINER(dialog), GL_HIG_PAD1);
97 gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
98 gtk_dialog_add_buttons (GTK_DIALOG(dialog),
99 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
100 GTK_STOCK_OK, GTK_RESPONSE_OK,
102 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
103 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
105 gl_debug (DEBUG_FILE, "END");
109 gl_new_label_dialog_finalize (GObject *object)
111 glNewLabelDialog* dialog = GL_NEW_LABEL_DIALOG (object);;
113 gl_debug (DEBUG_FILE, "START");
115 g_return_if_fail (object != NULL);
116 g_return_if_fail (GL_IS_NEW_LABEL_DIALOG (dialog));
117 g_return_if_fail (dialog->priv != NULL);
119 g_free (dialog->priv);
121 G_OBJECT_CLASS (gl_new_label_dialog_parent_class)->finalize (object);
123 gl_debug (DEBUG_FILE, "END");
127 /*****************************************************************************/
128 /* NEW object properties dialog. */
129 /*****************************************************************************/
131 gl_new_label_dialog_new (GtkWindow *win)
135 gl_debug (DEBUG_FILE, "");
137 dialog = GTK_WIDGET (g_object_new (GL_TYPE_NEW_LABEL_DIALOG, NULL));
139 gl_new_label_dialog_construct (GL_NEW_LABEL_DIALOG(dialog), win);
144 /*--------------------------------------------------------------------------*/
145 /* PRIVATE. Construct dialog. */
146 /*--------------------------------------------------------------------------*/
148 gl_new_label_dialog_construct (glNewLabelDialog *dialog,
152 GtkWidget *vbox, *media_select_vbox, *rotate_label_vbox;
155 gl_debug (DEBUG_FILE, "START");
157 gtk_window_set_transient_for (GTK_WINDOW (dialog), win);
159 gui = glade_xml_new (GLABELS_GLADE_DIR "new-label-dialog.glade",
160 "new_label_dialog_vbox", NULL);
163 g_critical ("Could not open new-label-dialog.glade. gLabels may not be installed correctly!");
167 vbox = glade_xml_get_widget (gui, "new_label_dialog_vbox");
168 gtk_box_pack_start (GTK_BOX( GTK_DIALOG (dialog)->vbox), vbox, FALSE, FALSE, 0);
170 media_select_vbox = glade_xml_get_widget (gui, "media_select_vbox");
171 rotate_label_vbox = glade_xml_get_widget (gui, "rotate_label_vbox");
173 g_object_unref (gui);
175 dialog->priv->media_select = gl_wdgt_media_select_new ();
176 gtk_box_pack_start (GTK_BOX (media_select_vbox),
177 dialog->priv->media_select, FALSE, FALSE, 0);
179 dialog->priv->rotate_label = gl_wdgt_rotate_label_new ();
180 gtk_box_pack_start (GTK_BOX (rotate_label_vbox),
181 dialog->priv->rotate_label, FALSE, FALSE, 0);
183 /* Sync template name from media select with rotate widget. */
184 name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select));
185 gl_wdgt_rotate_label_set_template_name (GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label),
188 g_signal_connect (G_OBJECT (dialog->priv->media_select), "changed",
189 G_CALLBACK (template_changed_cb), dialog);
191 gl_debug (DEBUG_FILE, "END");
194 /*---------------------------------------------------------------------------*/
195 /* PRIVATE. New template changed callback. */
196 /*---------------------------------------------------------------------------*/
198 template_changed_cb (glWdgtMediaSelect *select,
201 glNewLabelDialog *dialog = GL_NEW_LABEL_DIALOG (data);
204 gl_debug (DEBUG_FILE, "START");
206 name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (select));
208 gl_wdgt_rotate_label_set_template_name (GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label),
211 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
217 gl_debug (DEBUG_FILE, "END");
220 /*****************************************************************************/
221 /* Get template name. */
222 /*****************************************************************************/
224 gl_new_label_dialog_get_template_name (glNewLabelDialog *dialog)
228 name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select));
233 /*****************************************************************************/
234 /* Set template name. */
235 /*****************************************************************************/
237 gl_new_label_dialog_set_template_name (glNewLabelDialog *dialog,
240 gl_wdgt_media_select_set_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select), name);
243 /*****************************************************************************/
244 /* Get current filter parameters. */
245 /*****************************************************************************/
247 gl_new_label_dialog_get_filter_parameters (glNewLabelDialog *dialog,
248 gchar **page_size_id,
251 gl_wdgt_media_select_get_filter_parameters (
252 GL_WDGT_MEDIA_SELECT (dialog->priv->media_select),
253 page_size_id, category_id);
256 /*****************************************************************************/
257 /* Set current filter parameters. */
258 /*****************************************************************************/
260 gl_new_label_dialog_set_filter_parameters (glNewLabelDialog *dialog,
261 const gchar *page_size_id,
262 const gchar *category_id)
264 gl_wdgt_media_select_set_filter_parameters (
265 GL_WDGT_MEDIA_SELECT (dialog->priv->media_select),
266 page_size_id, category_id);
269 /*****************************************************************************/
270 /* Get rotate state. */
271 /*****************************************************************************/
273 gl_new_label_dialog_get_rotate_state (glNewLabelDialog *dialog)
275 return gl_wdgt_rotate_label_get_state (
276 GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label));
279 /*****************************************************************************/
280 /* Set rotate state. */
281 /*****************************************************************************/
283 gl_new_label_dialog_set_rotate_state (glNewLabelDialog *dialog,
286 gl_wdgt_rotate_label_set_state (
287 GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label), state);