]> git.sur5r.net Git - glabels/blob - src/new-label-dialog.c
Use accessor functions instead direct access
[glabels] / 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/gtk.h>
27
28 #include "hig.h"
29 #include "wdgt-media-select.h"
30 #include "rotate-label-button.h"
31
32 #include "debug.h"
33
34
35 /*===========================================*/
36 /* Private data types                        */
37 /*===========================================*/
38
39 struct _glNewLabelDialogPrivate {
40
41         GtkWidget  *media_select;
42         GtkWidget  *rotate_label;
43
44 };
45
46
47 /*===========================================*/
48 /* Private globals                           */
49 /*===========================================*/
50
51
52 /*===========================================*/
53 /* Local function prototypes                 */
54 /*===========================================*/
55
56 static void       gl_new_label_dialog_finalize        (GObject               *object);
57
58 static void       template_changed_cb                 (glWdgtMediaSelect     *select,
59                                                        gpointer               data);
60
61
62 /*****************************************************************************/
63 /* Boilerplate object stuff.                                                 */
64 /*****************************************************************************/
65 G_DEFINE_TYPE (glNewLabelDialog, gl_new_label_dialog, GTK_TYPE_DIALOG);
66
67
68 /*****************************************************************************/
69 /* Class Init Function.                                                      */
70 /*****************************************************************************/
71 static void
72 gl_new_label_dialog_class_init (glNewLabelDialogClass *class)
73 {
74         GObjectClass *object_class = G_OBJECT_CLASS (class);
75
76         gl_debug (DEBUG_FILE, "");
77         
78         gl_new_label_dialog_parent_class = g_type_class_peek_parent (class);
79
80         object_class->finalize = gl_new_label_dialog_finalize;          
81 }
82
83
84 /*****************************************************************************/
85 /* Object Instance Init Function.                                            */
86 /*****************************************************************************/
87 static void
88 gl_new_label_dialog_init (glNewLabelDialog *dialog)
89 {
90         GtkWidget    *vbox;
91         GtkWidget    *label;
92         GtkWidget    *frame;
93         gchar        *name;
94
95         gl_debug (DEBUG_FILE, "START");
96
97         g_return_if_fail (GL_IS_NEW_LABEL_DIALOG (dialog));
98
99         dialog->priv = g_new0 (glNewLabelDialogPrivate, 1);
100
101         gtk_container_set_border_width (GTK_CONTAINER (dialog), GL_HIG_PAD1);
102
103         gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
104         gtk_dialog_add_buttons (GTK_DIALOG (dialog),
105                                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
106                                 GTK_STOCK_OK, GTK_RESPONSE_OK,
107                                 NULL);
108         gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
109         gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
110         gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
111
112         vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
113
114         label = gtk_label_new (_("<b>Media type</b>"));
115         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
116         frame = gtk_frame_new ("");
117         gtk_frame_set_label_widget (GTK_FRAME (frame), label);
118         gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
119         gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, GL_HIG_PAD1);
120
121         dialog->priv->media_select = gl_wdgt_media_select_new ();
122         gtk_container_add (GTK_CONTAINER (frame), dialog->priv->media_select);
123
124         label = gtk_label_new (_("<b>Label orientation</b>"));
125         gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
126         frame = gtk_frame_new ("");
127         gtk_frame_set_label_widget (GTK_FRAME (frame), label);
128         gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
129         gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
130
131         dialog->priv->rotate_label = gl_rotate_label_button_new ();
132         gtk_container_add (GTK_CONTAINER (frame), dialog->priv->rotate_label);
133
134         /* Sync template name from media select with rotate widget. */
135         name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select));
136         gl_rotate_label_button_set_template_name (GL_ROTATE_LABEL_BUTTON (dialog->priv->rotate_label),
137                                                   name);
138
139         g_signal_connect (G_OBJECT (dialog->priv->media_select), "changed",
140                           G_CALLBACK (template_changed_cb), dialog);
141
142         gl_debug (DEBUG_FILE, "END");
143 }
144
145
146 /*****************************************************************************/
147 /* Finalize Function.                                                        */
148 /*****************************************************************************/
149 static void 
150 gl_new_label_dialog_finalize (GObject *object)
151 {
152         glNewLabelDialog* dialog = GL_NEW_LABEL_DIALOG (object);;
153         
154         gl_debug (DEBUG_FILE, "START");
155
156         g_return_if_fail (object != NULL);
157         g_return_if_fail (GL_IS_NEW_LABEL_DIALOG (dialog));
158         g_return_if_fail (dialog->priv != NULL);
159
160         g_free (dialog->priv);
161
162         G_OBJECT_CLASS (gl_new_label_dialog_parent_class)->finalize (object);
163
164         gl_debug (DEBUG_FILE, "END");
165
166 }
167
168
169 /*****************************************************************************/
170 /* NEW object properties dialog.                                             */
171 /*****************************************************************************/
172 GtkWidget *
173 gl_new_label_dialog_new (GtkWindow    *win)
174 {
175         GtkWidget *dialog;
176
177         gl_debug (DEBUG_FILE, "");
178
179         dialog = GTK_WIDGET (g_object_new (GL_TYPE_NEW_LABEL_DIALOG, NULL));
180
181         gtk_window_set_transient_for (GTK_WINDOW (dialog), win);
182
183         return dialog;
184 }
185
186
187 /*---------------------------------------------------------------------------*/
188 /* PRIVATE.  New template changed callback.                                  */
189 /*---------------------------------------------------------------------------*/
190 static void
191 template_changed_cb (glWdgtMediaSelect *select,
192                      gpointer           data)
193 {
194         glNewLabelDialog  *dialog = GL_NEW_LABEL_DIALOG (data);
195         gchar             *name;
196
197         gl_debug (DEBUG_FILE, "START");
198
199         name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (select));
200
201         gl_rotate_label_button_set_template_name (GL_ROTATE_LABEL_BUTTON (dialog->priv->rotate_label),
202                                                   name);
203
204         gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
205                                            GTK_RESPONSE_OK,
206                                            (name != NULL));
207
208         g_free (name);
209
210         gl_debug (DEBUG_FILE, "END");
211 }
212
213
214 /*****************************************************************************/
215 /* Get template name.                                                        */
216 /*****************************************************************************/
217 gchar *
218 gl_new_label_dialog_get_template_name (glNewLabelDialog *dialog)
219 {
220         gchar *name;
221
222         name = gl_wdgt_media_select_get_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select));
223
224         return name;
225 }
226
227
228 /*****************************************************************************/
229 /* Set template name.                                                        */
230 /*****************************************************************************/
231 void
232 gl_new_label_dialog_set_template_name (glNewLabelDialog *dialog,
233                                        gchar            *name)
234 {
235         gl_wdgt_media_select_set_name (GL_WDGT_MEDIA_SELECT (dialog->priv->media_select), name);
236 }
237
238
239 /*****************************************************************************/
240 /* Get current filter parameters.                                            */
241 /*****************************************************************************/
242 void
243 gl_new_label_dialog_get_filter_parameters (glNewLabelDialog *dialog,
244                                            gchar           **page_size_id,
245                                            gchar           **category_id)
246 {
247         gl_wdgt_media_select_get_filter_parameters (
248                 GL_WDGT_MEDIA_SELECT (dialog->priv->media_select),
249                 page_size_id, category_id);
250 }
251
252
253 /*****************************************************************************/
254 /* Set current filter parameters.                                            */
255 /*****************************************************************************/
256 void
257 gl_new_label_dialog_set_filter_parameters (glNewLabelDialog *dialog,
258                                            const gchar      *page_size_id,
259                                            const gchar      *category_id)
260 {
261         gl_wdgt_media_select_set_filter_parameters (
262                 GL_WDGT_MEDIA_SELECT (dialog->priv->media_select),
263                 page_size_id, category_id);
264 }
265
266
267 /*****************************************************************************/
268 /* Get rotate state.                                                         */
269 /*****************************************************************************/
270 gboolean
271 gl_new_label_dialog_get_rotate_state (glNewLabelDialog *dialog)
272 {
273         return gl_rotate_label_button_get_state (
274                 GL_ROTATE_LABEL_BUTTON (dialog->priv->rotate_label));
275 }
276
277
278 /*****************************************************************************/
279 /* Set rotate state.                                                         */
280 /*****************************************************************************/
281 void
282 gl_new_label_dialog_set_rotate_state (glNewLabelDialog *dialog,
283                                       gboolean          state)
284 {
285         gl_rotate_label_button_set_state (
286                 GL_ROTATE_LABEL_BUTTON (dialog->priv->rotate_label), state);
287 }
288
289
290
291 /*
292  * Local Variables:       -- emacs
293  * mode: C                -- emacs
294  * c-basic-offset: 8      -- emacs
295  * tab-width: 8           -- emacs
296  * indent-tabs-mode: nil  -- emacs
297  * End:                   -- emacs
298  */