3 * Copyright (C) 2006-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "new-label-dialog.h"
25 #include <glib/gi18n.h>
26 #include <gtk/gtkbuilder.h>
27 #include <gtk/gtkdialog.h>
28 #include <gtk/gtkstock.h>
31 #include "wdgt-media-select.h"
32 #include "wdgt-rotate-label.h"
38 /*===========================================*/
39 /* Private data types */
40 /*===========================================*/
42 struct _glNewLabelDialogPrivate {
46 GtkWidget *media_select;
47 GtkWidget *rotate_label;
52 /*===========================================*/
54 /*===========================================*/
57 /*===========================================*/
58 /* Local function prototypes */
59 /*===========================================*/
61 static void gl_new_label_dialog_finalize (GObject *object);
63 static void gl_new_label_dialog_construct (glNewLabelDialog *dialog,
66 static void template_changed_cb (glWdgtMediaSelect *select,
70 /*****************************************************************************/
71 /* Boilerplate object stuff. */
72 /*****************************************************************************/
73 G_DEFINE_TYPE (glNewLabelDialog, gl_new_label_dialog, GTK_TYPE_DIALOG);
77 gl_new_label_dialog_class_init (glNewLabelDialogClass *class)
79 GObjectClass *object_class = G_OBJECT_CLASS (class);
81 gl_debug (DEBUG_FILE, "");
83 gl_new_label_dialog_parent_class = g_type_class_peek_parent (class);
85 object_class->finalize = gl_new_label_dialog_finalize;
90 gl_new_label_dialog_init (glNewLabelDialog *dialog)
92 gl_debug (DEBUG_FILE, "START");
94 g_return_if_fail (GL_IS_NEW_LABEL_DIALOG (dialog));
96 dialog->priv = g_new0 (glNewLabelDialogPrivate, 1);
98 gtk_container_set_border_width (GTK_CONTAINER(dialog), GL_HIG_PAD2);
100 gtk_dialog_set_has_separator (GTK_DIALOG(dialog), FALSE);
101 gtk_dialog_add_buttons (GTK_DIALOG(dialog),
102 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
103 GTK_STOCK_OK, GTK_RESPONSE_OK,
105 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
106 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
108 gl_debug (DEBUG_FILE, "END");
113 gl_new_label_dialog_finalize (GObject *object)
115 glNewLabelDialog* dialog = GL_NEW_LABEL_DIALOG (object);;
117 gl_debug (DEBUG_FILE, "START");
119 g_return_if_fail (object != NULL);
120 g_return_if_fail (GL_IS_NEW_LABEL_DIALOG (dialog));
121 g_return_if_fail (dialog->priv != NULL);
123 if (dialog->priv->builder)
125 g_object_unref (dialog->priv->builder);
127 g_free (dialog->priv);
129 G_OBJECT_CLASS (gl_new_label_dialog_parent_class)->finalize (object);
131 gl_debug (DEBUG_FILE, "END");
136 /*****************************************************************************/
137 /* NEW object properties dialog. */
138 /*****************************************************************************/
140 gl_new_label_dialog_new (GtkWindow *win)
144 gl_debug (DEBUG_FILE, "");
146 dialog = GTK_WIDGET (g_object_new (GL_TYPE_NEW_LABEL_DIALOG, NULL));
148 gl_new_label_dialog_construct (GL_NEW_LABEL_DIALOG(dialog), win);
154 /*--------------------------------------------------------------------------*/
155 /* PRIVATE. Construct dialog. */
156 /*--------------------------------------------------------------------------*/
158 gl_new_label_dialog_construct (glNewLabelDialog *dialog,
162 static gchar *object_ids[] = { "new_label_dialog_vbox", NULL };
163 GError *error = NULL;
164 GtkWidget *vbox, *media_select_vbox, *rotate_label_vbox;
167 gl_debug (DEBUG_FILE, "START");
169 gtk_window_set_transient_for (GTK_WINDOW (dialog), win);
171 builder = gtk_builder_new ();
172 gtk_builder_add_objects_from_file (builder,
173 GLABELS_BUILDER_DIR "new-label-dialog.builder",
177 g_critical ("%s\n\ngLabels may not be installed correctly!", error->message);
178 g_error_free (error);
182 gl_util_get_builder_widgets (builder,
183 "new_label_dialog_vbox", &vbox,
184 "media_select_vbox", &media_select_vbox,
185 "rotate_label_vbox", &rotate_label_vbox,
188 gtk_box_pack_start (GTK_BOX( GTK_DIALOG (dialog)->vbox), vbox, FALSE, FALSE, 0);
189 dialog->priv->builder = builder;
191 dialog->priv->media_select = gl_wdgt_media_select_new ();
192 gtk_box_pack_start (GTK_BOX (media_select_vbox),
193 dialog->priv->media_select, FALSE, FALSE, 0);
195 dialog->priv->rotate_label = gl_wdgt_rotate_label_new ();
196 gtk_box_pack_start (GTK_BOX (rotate_label_vbox),
197 dialog->priv->rotate_label, FALSE, FALSE, 0);
199 /* Sync template name from media select with rotate widget. */
200 name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select));
201 gl_wdgt_rotate_label_set_template_name (GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label),
204 g_signal_connect (G_OBJECT (dialog->priv->media_select), "changed",
205 G_CALLBACK (template_changed_cb), dialog);
207 gl_debug (DEBUG_FILE, "END");
211 /*---------------------------------------------------------------------------*/
212 /* PRIVATE. New template changed callback. */
213 /*---------------------------------------------------------------------------*/
215 template_changed_cb (glWdgtMediaSelect *select,
218 glNewLabelDialog *dialog = GL_NEW_LABEL_DIALOG (data);
221 gl_debug (DEBUG_FILE, "START");
223 name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (select));
225 gl_wdgt_rotate_label_set_template_name (GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label),
228 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
234 gl_debug (DEBUG_FILE, "END");
238 /*****************************************************************************/
239 /* Get template name. */
240 /*****************************************************************************/
242 gl_new_label_dialog_get_template_name (glNewLabelDialog *dialog)
246 name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select));
252 /*****************************************************************************/
253 /* Set template name. */
254 /*****************************************************************************/
256 gl_new_label_dialog_set_template_name (glNewLabelDialog *dialog,
259 gl_wdgt_media_select_set_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select), name);
263 /*****************************************************************************/
264 /* Get current filter parameters. */
265 /*****************************************************************************/
267 gl_new_label_dialog_get_filter_parameters (glNewLabelDialog *dialog,
268 gchar **page_size_id,
271 gl_wdgt_media_select_get_filter_parameters (
272 GL_WDGT_MEDIA_SELECT (dialog->priv->media_select),
273 page_size_id, category_id);
277 /*****************************************************************************/
278 /* Set current filter parameters. */
279 /*****************************************************************************/
281 gl_new_label_dialog_set_filter_parameters (glNewLabelDialog *dialog,
282 const gchar *page_size_id,
283 const gchar *category_id)
285 gl_wdgt_media_select_set_filter_parameters (
286 GL_WDGT_MEDIA_SELECT (dialog->priv->media_select),
287 page_size_id, category_id);
291 /*****************************************************************************/
292 /* Get rotate state. */
293 /*****************************************************************************/
295 gl_new_label_dialog_get_rotate_state (glNewLabelDialog *dialog)
297 return gl_wdgt_rotate_label_get_state (
298 GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label));
302 /*****************************************************************************/
303 /* Set rotate state. */
304 /*****************************************************************************/
306 gl_new_label_dialog_set_rotate_state (glNewLabelDialog *dialog,
309 gl_wdgt_rotate_label_set_state (
310 GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label), state);
316 * Local Variables: -- emacs
318 * c-basic-offset: 8 -- emacs
319 * tab-width: 8 -- emacs
320 * indent-tabs-mode: nil -- emacs