]> git.sur5r.net Git - glabels/blob - src/new-label-dialog.c
Imported Upstream version 2.2.8
[glabels] / src / new-label-dialog.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /*
4  *  (GLABELS) Label and Business Card Creation program for GNOME
5  *
6  *  new-label-dialog.c:  New label dialog module
7  *
8  *  Copyright (C) 2006  Jim Evins <evins@snaught.com>.
9  *
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.
14  *
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.
19  *
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
23  */
24 #include <config.h>
25
26 #include "new-label-dialog.h"
27
28 #include <glib/gi18n.h>
29 #include <glade/glade-xml.h>
30 #include <gtk/gtkdialog.h>
31 #include <gtk/gtkstock.h>
32
33 #include "hig.h"
34 #include "wdgt-media-select.h"
35 #include "wdgt-rotate-label.h"
36
37 #include "debug.h"
38
39 /*===========================================*/
40 /* Private data types                        */
41 /*===========================================*/
42
43 struct _glNewLabelDialogPrivate {
44
45         GtkWidget *media_select;
46         GtkWidget *rotate_label;
47
48 };
49
50
51 /*===========================================*/
52 /* Private globals                           */
53 /*===========================================*/
54
55 /*===========================================*/
56 /* Local function prototypes                 */
57 /*===========================================*/
58
59 static void       gl_new_label_dialog_finalize        (GObject               *object);
60
61 static void       gl_new_label_dialog_construct       (glNewLabelDialog      *dialog,
62                                                        GtkWindow             *win);
63
64 static void       template_changed_cb                 (glWdgtMediaSelect     *select,
65                                                        gpointer               data);
66
67
68 \f
69 /*****************************************************************************/
70 /* Boilerplate object stuff.                                                 */
71 /*****************************************************************************/
72 G_DEFINE_TYPE (glNewLabelDialog, gl_new_label_dialog, GTK_TYPE_DIALOG);
73
74 static void
75 gl_new_label_dialog_class_init (glNewLabelDialogClass *class)
76 {
77         GObjectClass *object_class = G_OBJECT_CLASS (class);
78
79         gl_debug (DEBUG_FILE, "");
80         
81         gl_new_label_dialog_parent_class = g_type_class_peek_parent (class);
82
83         object_class->finalize = gl_new_label_dialog_finalize;          
84 }
85
86 static void
87 gl_new_label_dialog_init (glNewLabelDialog *dialog)
88 {
89         gl_debug (DEBUG_FILE, "START");
90
91         g_return_if_fail (GL_IS_NEW_LABEL_DIALOG (dialog));
92
93         dialog->priv = g_new0 (glNewLabelDialogPrivate, 1);
94
95         gtk_container_set_border_width (GTK_CONTAINER(dialog), GL_HIG_PAD1);
96
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,
101                                 NULL);
102         gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
103         gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
104
105         gl_debug (DEBUG_FILE, "END");
106 }
107
108 static void 
109 gl_new_label_dialog_finalize (GObject *object)
110 {
111         glNewLabelDialog* dialog = GL_NEW_LABEL_DIALOG (object);;
112         
113         gl_debug (DEBUG_FILE, "START");
114
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);
118
119         g_free (dialog->priv);
120
121         G_OBJECT_CLASS (gl_new_label_dialog_parent_class)->finalize (object);
122
123         gl_debug (DEBUG_FILE, "END");
124
125 }
126
127 /*****************************************************************************/
128 /* NEW object properties dialog.                                             */
129 /*****************************************************************************/
130 GtkWidget *
131 gl_new_label_dialog_new (GtkWindow    *win)
132 {
133         GtkWidget *dialog;
134
135         gl_debug (DEBUG_FILE, "");
136
137         dialog = GTK_WIDGET (g_object_new (GL_TYPE_NEW_LABEL_DIALOG, NULL));
138
139         gl_new_label_dialog_construct (GL_NEW_LABEL_DIALOG(dialog), win);
140
141         return dialog;
142 }
143
144 /*--------------------------------------------------------------------------*/
145 /* PRIVATE.  Construct dialog.                                              */
146 /*--------------------------------------------------------------------------*/
147 static void
148 gl_new_label_dialog_construct (glNewLabelDialog   *dialog,
149                                GtkWindow          *win)
150 {
151         GladeXML  *gui;
152         GtkWidget *vbox, *media_select_vbox, *rotate_label_vbox;
153         gchar     *name;
154
155         gl_debug (DEBUG_FILE, "START");
156
157         gtk_window_set_transient_for (GTK_WINDOW (dialog), win);
158
159         gui = glade_xml_new (GLABELS_GLADE_DIR "new-label-dialog.glade",
160                              "new_label_dialog_vbox", NULL);
161
162         if (!gui) {
163                 g_critical ("Could not open new-label-dialog.glade. gLabels may not be installed correctly!");
164                 return;
165         }
166
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);
169
170         media_select_vbox = glade_xml_get_widget (gui, "media_select_vbox");
171         rotate_label_vbox = glade_xml_get_widget (gui, "rotate_label_vbox");
172
173         g_object_unref (gui);
174
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);
178
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);
182
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),
186                                                 name);
187
188         g_signal_connect (G_OBJECT (dialog->priv->media_select), "changed",
189                           G_CALLBACK (template_changed_cb), dialog);
190
191         gl_debug (DEBUG_FILE, "END");
192 }
193
194 /*---------------------------------------------------------------------------*/
195 /* PRIVATE.  New template changed callback.                                  */
196 /*---------------------------------------------------------------------------*/
197 static void
198 template_changed_cb (glWdgtMediaSelect *select,
199                      gpointer           data)
200 {
201         glNewLabelDialog  *dialog = GL_NEW_LABEL_DIALOG (data);
202         gchar             *name;
203
204         gl_debug (DEBUG_FILE, "START");
205
206         name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (select));
207
208         gl_wdgt_rotate_label_set_template_name (GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label),
209                                                 name);
210
211         gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
212                                            GTK_RESPONSE_OK,
213                                            (name != NULL));
214
215         g_free (name);
216
217         gl_debug (DEBUG_FILE, "END");
218 }
219
220 /*****************************************************************************/
221 /* Get template name.                                                        */
222 /*****************************************************************************/
223 gchar *
224 gl_new_label_dialog_get_template_name (glNewLabelDialog *dialog)
225 {
226         gchar *name;
227
228         name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select));
229
230         return name;
231 }
232
233 /*****************************************************************************/
234 /* Set template name.                                                        */
235 /*****************************************************************************/
236 void
237 gl_new_label_dialog_set_template_name (glNewLabelDialog *dialog,
238                                        gchar            *name)
239 {
240         gl_wdgt_media_select_set_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select), name);
241 }
242
243 /*****************************************************************************/
244 /* Get current filter parameters.                                            */
245 /*****************************************************************************/
246 void
247 gl_new_label_dialog_get_filter_parameters (glNewLabelDialog *dialog,
248                                            gchar           **page_size_id,
249                                            gchar           **category_id)
250 {
251         gl_wdgt_media_select_get_filter_parameters (
252                 GL_WDGT_MEDIA_SELECT (dialog->priv->media_select),
253                 page_size_id, category_id);
254 }
255
256 /*****************************************************************************/
257 /* Set current filter parameters.                                            */
258 /*****************************************************************************/
259 void
260 gl_new_label_dialog_set_filter_parameters (glNewLabelDialog *dialog,
261                                            const gchar      *page_size_id,
262                                            const gchar      *category_id)
263 {
264         gl_wdgt_media_select_set_filter_parameters (
265                 GL_WDGT_MEDIA_SELECT (dialog->priv->media_select),
266                 page_size_id, category_id);
267 }
268
269 /*****************************************************************************/
270 /* Get rotate state.                                                         */
271 /*****************************************************************************/
272 gboolean
273 gl_new_label_dialog_get_rotate_state (glNewLabelDialog *dialog)
274 {
275         return gl_wdgt_rotate_label_get_state (
276                 GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label));
277 }
278
279 /*****************************************************************************/
280 /* Set rotate state.                                                         */
281 /*****************************************************************************/
282 void
283 gl_new_label_dialog_set_rotate_state (glNewLabelDialog *dialog,
284                                       gboolean          state)
285 {
286         gl_wdgt_rotate_label_set_state (
287                 GL_WDGT_ROTATE_LABEL (dialog->priv->rotate_label), state);
288 }
289