]> git.sur5r.net Git - glabels/blob - glabels2/src/new-label-dialog.c
2009-09-01 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / new-label-dialog.c
1 /*
2  *  new-label-dialog.c
3  *  Copyright (C) 2006-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 #include <config.h>
22
23 #include "new-label-dialog.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtkbuilder.h>
27 #include <gtk/gtkdialog.h>
28 #include <gtk/gtkstock.h>
29
30 #include "hig.h"
31 #include "wdgt-media-select.h"
32 #include "wdgt-rotate-label.h"
33 #include "util.h"
34
35 #include "debug.h"
36
37
38 /*===========================================*/
39 /* Private data types                        */
40 /*===========================================*/
41
42 struct _glNewLabelDialogPrivate {
43
44         GtkBuilder *builder;
45
46         GtkWidget  *media_select;
47         GtkWidget  *rotate_label;
48
49 };
50
51
52 /*===========================================*/
53 /* Private globals                           */
54 /*===========================================*/
55
56
57 /*===========================================*/
58 /* Local function prototypes                 */
59 /*===========================================*/
60
61 static void       gl_new_label_dialog_finalize        (GObject               *object);
62
63 static void       gl_new_label_dialog_construct       (glNewLabelDialog      *dialog,
64                                                        GtkWindow             *win);
65
66 static void       template_changed_cb                 (glWdgtMediaSelect     *select,
67                                                        gpointer               data);
68
69
70 /*****************************************************************************/
71 /* Boilerplate object stuff.                                                 */
72 /*****************************************************************************/
73 G_DEFINE_TYPE (glNewLabelDialog, gl_new_label_dialog, GTK_TYPE_DIALOG);
74
75
76 static void
77 gl_new_label_dialog_class_init (glNewLabelDialogClass *class)
78 {
79         GObjectClass *object_class = G_OBJECT_CLASS (class);
80
81         gl_debug (DEBUG_FILE, "");
82         
83         gl_new_label_dialog_parent_class = g_type_class_peek_parent (class);
84
85         object_class->finalize = gl_new_label_dialog_finalize;          
86 }
87
88
89 static void
90 gl_new_label_dialog_init (glNewLabelDialog *dialog)
91 {
92         gl_debug (DEBUG_FILE, "START");
93
94         g_return_if_fail (GL_IS_NEW_LABEL_DIALOG (dialog));
95
96         dialog->priv = g_new0 (glNewLabelDialogPrivate, 1);
97
98         gtk_container_set_border_width (GTK_CONTAINER(dialog), GL_HIG_PAD2);
99
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,
104                                 NULL);
105         gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
106         gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
107
108         gl_debug (DEBUG_FILE, "END");
109 }
110
111
112 static void 
113 gl_new_label_dialog_finalize (GObject *object)
114 {
115         glNewLabelDialog* dialog = GL_NEW_LABEL_DIALOG (object);;
116         
117         gl_debug (DEBUG_FILE, "START");
118
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);
122
123         if (dialog->priv->builder)
124         {
125                 g_object_unref (dialog->priv->builder);
126         }
127         g_free (dialog->priv);
128
129         G_OBJECT_CLASS (gl_new_label_dialog_parent_class)->finalize (object);
130
131         gl_debug (DEBUG_FILE, "END");
132
133 }
134
135
136 /*****************************************************************************/
137 /* NEW object properties dialog.                                             */
138 /*****************************************************************************/
139 GtkWidget *
140 gl_new_label_dialog_new (GtkWindow    *win)
141 {
142         GtkWidget *dialog;
143
144         gl_debug (DEBUG_FILE, "");
145
146         dialog = GTK_WIDGET (g_object_new (GL_TYPE_NEW_LABEL_DIALOG, NULL));
147
148         gl_new_label_dialog_construct (GL_NEW_LABEL_DIALOG(dialog), win);
149
150         return dialog;
151 }
152
153
154 /*--------------------------------------------------------------------------*/
155 /* PRIVATE.  Construct dialog.                                              */
156 /*--------------------------------------------------------------------------*/
157 static void
158 gl_new_label_dialog_construct (glNewLabelDialog   *dialog,
159                                GtkWindow          *win)
160 {
161         GtkBuilder   *builder;
162         static gchar *object_ids[] = { "new_label_dialog_vbox", NULL };
163         GError       *error = NULL;
164         GtkWidget    *vbox, *media_select_vbox, *rotate_label_vbox;
165         gchar        *name;
166
167         gl_debug (DEBUG_FILE, "START");
168
169         gtk_window_set_transient_for (GTK_WINDOW (dialog), win);
170
171         builder = gtk_builder_new ();
172         gtk_builder_add_objects_from_file (builder,
173                                            GLABELS_BUILDER_DIR "new-label-dialog.builder",
174                                            object_ids,
175                                            &error);
176         if (error) {
177                 g_critical ("%s\n\ngLabels may not be installed correctly!", error->message);
178                 g_error_free (error);
179                 return;
180         }
181
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,
186                                      NULL);
187
188         gtk_box_pack_start (GTK_BOX( GTK_DIALOG (dialog)->vbox), vbox, FALSE, FALSE, 0);
189         dialog->priv->builder = builder;
190
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);
194
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);
198
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),
202                                                 name);
203
204         g_signal_connect (G_OBJECT (dialog->priv->media_select), "changed",
205                           G_CALLBACK (template_changed_cb), dialog);
206
207         gl_debug (DEBUG_FILE, "END");
208 }
209
210
211 /*---------------------------------------------------------------------------*/
212 /* PRIVATE.  New template changed callback.                                  */
213 /*---------------------------------------------------------------------------*/
214 static void
215 template_changed_cb (glWdgtMediaSelect *select,
216                      gpointer           data)
217 {
218         glNewLabelDialog  *dialog = GL_NEW_LABEL_DIALOG (data);
219         gchar             *name;
220
221         gl_debug (DEBUG_FILE, "START");
222
223         name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (select));
224
225         gl_wdgt_rotate_label_set_template_name (GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label),
226                                                 name);
227
228         gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
229                                            GTK_RESPONSE_OK,
230                                            (name != NULL));
231
232         g_free (name);
233
234         gl_debug (DEBUG_FILE, "END");
235 }
236
237
238 /*****************************************************************************/
239 /* Get template name.                                                        */
240 /*****************************************************************************/
241 gchar *
242 gl_new_label_dialog_get_template_name (glNewLabelDialog *dialog)
243 {
244         gchar *name;
245
246         name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select));
247
248         return name;
249 }
250
251
252 /*****************************************************************************/
253 /* Set template name.                                                        */
254 /*****************************************************************************/
255 void
256 gl_new_label_dialog_set_template_name (glNewLabelDialog *dialog,
257                                        gchar            *name)
258 {
259         gl_wdgt_media_select_set_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select), name);
260 }
261
262
263 /*****************************************************************************/
264 /* Get current filter parameters.                                            */
265 /*****************************************************************************/
266 void
267 gl_new_label_dialog_get_filter_parameters (glNewLabelDialog *dialog,
268                                            gchar           **page_size_id,
269                                            gchar           **category_id)
270 {
271         gl_wdgt_media_select_get_filter_parameters (
272                 GL_WDGT_MEDIA_SELECT (dialog->priv->media_select),
273                 page_size_id, category_id);
274 }
275
276
277 /*****************************************************************************/
278 /* Set current filter parameters.                                            */
279 /*****************************************************************************/
280 void
281 gl_new_label_dialog_set_filter_parameters (glNewLabelDialog *dialog,
282                                            const gchar      *page_size_id,
283                                            const gchar      *category_id)
284 {
285         gl_wdgt_media_select_set_filter_parameters (
286                 GL_WDGT_MEDIA_SELECT (dialog->priv->media_select),
287                 page_size_id, category_id);
288 }
289
290
291 /*****************************************************************************/
292 /* Get rotate state.                                                         */
293 /*****************************************************************************/
294 gboolean
295 gl_new_label_dialog_get_rotate_state (glNewLabelDialog *dialog)
296 {
297         return gl_wdgt_rotate_label_get_state (
298                 GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label));
299 }
300
301
302 /*****************************************************************************/
303 /* Set rotate state.                                                         */
304 /*****************************************************************************/
305 void
306 gl_new_label_dialog_set_rotate_state (glNewLabelDialog *dialog,
307                                       gboolean          state)
308 {
309         gl_wdgt_rotate_label_set_state (
310                 GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label), state);
311 }
312
313
314
315 /*
316  * Local Variables:       -- emacs
317  * mode: C                -- emacs
318  * c-basic-offset: 8      -- emacs
319  * tab-width: 8           -- emacs
320  * indent-tabs-mode: nil  -- emacs
321  * End:                   -- emacs
322  */