latest update
[hildon] / hildon-widgets / hildon-file-handling-note.c
1 /*
2  * This file is part of hildon-libs
3  *
4  * Copyright (C) 2005 Nokia Corporation.
5  *
6  * Contact: Luc Pionchon <luc.pionchon@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 #include "hildon-note.h"
26 #include "hildon-file-handling-note.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <gtk/gtk.h>
30 #include <libintl.h>
31 #include <glib.h>
32 #include <glib-object.h>
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 /* Note types */
39 #define MOVING_TYPE 0
40 #define DELETING_TYPE 1
41 #define OPENING_TYPE 2
42 #define SAVING_TYPE 3
43
44 #define _(String) dgettext(PACKAGE, String)
45
46 #define HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(obj)\
47         (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
48         HILDON_TYPE_FILE_HANDLING_NOTE, HildonFileHandlingNotePrivate));
49
50 typedef struct _HildonFileHandlingNotePrivate
51     HildonFileHandlingNotePrivate;
52
53 struct _HildonFileHandlingNotePrivate {
54     guint note_type;
55 };
56
57 #ifndef HILDON_DISABLE_DEPRECATED
58
59 static HildonNote *parent_class;
60
61
62 /* standard forbids empty source file, therefore the ifdef must be
63    placed here. */
64
65 static void
66 hildon_file_handling_note_class_init(HildonFileHandlingNoteClass * class);
67
68 static void hildon_file_handling_note_init(HildonFileHandlingNote *
69                                            dialog);
70
71 static void hildon_file_handling_note_finalize(GObject * obj_self);
72
73
74
75
76 GType hildon_file_handling_note_get_type()
77 {
78     static GType dialog_type = 0;
79
80     if (!dialog_type) {
81         static const GTypeInfo dialog_info = {
82             sizeof(HildonFileHandlingNoteClass),
83             NULL,       /* base_init */
84             NULL,       /* base_finalize */
85             (GClassInitFunc) hildon_file_handling_note_class_init,
86             NULL,       /* class_finalize */
87             NULL,       /* class_data */
88             sizeof(HildonFileHandlingNote),
89             0,  /* n_preallocs */
90             (GInstanceInitFunc) hildon_file_handling_note_init
91         };
92
93         dialog_type = g_type_register_static(HILDON_TYPE_NOTE,
94                                              "HildonFileHandlingNote",
95                                              &dialog_info, 0);
96     }
97     return dialog_type;
98 }
99
100 static void
101 hildon_file_handling_note_class_init(HildonFileHandlingNoteClass * class)
102 {
103     GObjectClass *object_class = G_OBJECT_CLASS(class);
104
105     parent_class = g_type_class_peek_parent(class);
106     g_type_class_add_private(class, sizeof(HildonFileHandlingNotePrivate));
107     object_class->finalize = hildon_file_handling_note_finalize;
108 }
109
110 static void hildon_file_handling_note_init(HildonFileHandlingNote * dialog)
111 {
112     HildonFileHandlingNotePrivate *priv;
113
114     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(dialog);
115     priv->note_type = OPENING_TYPE;
116 }
117
118 static void hildon_file_handling_note_finalize(GObject * obj_self)
119 {
120     if (G_OBJECT_CLASS(parent_class)->finalize)
121         G_OBJECT_CLASS(parent_class)->finalize(obj_self);
122 }
123
124 /**
125  * hildon_file_handling_note_set_counter_and_name:
126  * @note: the #HildonFileHandlingNote widget
127  * @current: Current item
128  * @maximum: Maximum value for counter
129  * @name: Filename
130  *
131  * This function sets current counter value, maximum
132  * counter value and filename for dialog 
133  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
134  */
135 void hildon_file_handling_note_set_counter_and_name(HildonFileHandlingNote
136                                                     * note, guint current,
137                                                     guint maximum,
138                                                     const gchar * name)
139 {
140     gchar str[255];
141     HildonNote *p_note = HILDON_NOTE(note);
142     HildonFileHandlingNotePrivate *priv;
143
144     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(note);
145
146     if (priv->note_type == MOVING_TYPE) {
147       if (maximum == 1)
148         {
149           g_snprintf(str, 255, _("sfil_nw_moving_file"), name);
150           hildon_note_set_button_text(p_note, _("sfil_bd_moving_file"));
151         } else {
152           g_snprintf(str, 255, _("docm_nw_moving_files"),
153                      current, maximum, name);
154           hildon_note_set_button_text(p_note, _("docm_bd_moving_files"));
155         }
156     } else if (priv->note_type == SAVING_TYPE) {
157       if (maximum == 1)
158         {
159           g_snprintf(str, 255, _("docm_nw_saving_file"), name);
160           hildon_note_set_button_text(p_note, _("docm_bd_saving_file"));
161         } else {
162           g_snprintf(str, 255, _("docm_nw_saving_files"),
163                    current, maximum, name);
164           hildon_note_set_button_text(p_note, _("docm_bd_saving_files"));
165         }
166     } else if (priv->note_type == OPENING_TYPE) {
167       if (maximum == 1)
168         {
169           g_snprintf(str, 255, _("docm_nw_opening_file"), name);
170           hildon_note_set_button_text(p_note, _("docm_bd_opening_file"));
171         } else {
172           g_snprintf(str, 255, _("docm_nw_opening_files"),
173                      current, maximum, name);
174           hildon_note_set_button_text(p_note, _("docm_bd_opening_files"));
175         }
176     } else if (priv->note_type == DELETING_TYPE) {
177       if (maximum == 1)
178         {
179           g_snprintf(str, 255, _("docm_nw_deleting_file"), name);
180           hildon_note_set_button_text(p_note, _("docm_bd_deleting_file"));
181         } else {
182           g_snprintf(str, 255, _("docm_nw_deleting_files"),
183                      current, maximum, name);
184           hildon_note_set_button_text(p_note, _("docm_bd_deleting_files"));
185         }
186     }
187
188     g_object_set(p_note, "description", str, NULL);
189 }
190
191 /**
192  * hildon_file_handling_note_set_name:
193  * @note: the @HildonFileHandlingNote widget
194  * @name: Filename
195  *
196  * This function sets filename for dialog
197  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
198  */
199 void hildon_file_handling_note_set_name(HildonFileHandlingNote * note,
200                                         const gchar * name)
201 {
202     gchar str[255];
203     HildonNote *p_note = HILDON_NOTE(note);
204     HildonFileHandlingNotePrivate *priv =
205         HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(note);
206
207     if (priv->note_type == MOVING_TYPE) {
208         g_snprintf(str, 255, _("sfil_nw_moving_file"), name);
209     } else if (priv->note_type == SAVING_TYPE) {
210         g_snprintf(str, 255, _("docm_nw_saving_file"), name);
211     } else if (priv->note_type == OPENING_TYPE) {
212         g_snprintf(str, 255, _("docm_nw_opening_file"), name);
213     } else if (priv->note_type == DELETING_TYPE) {
214         g_snprintf(str, 255, _("docm_nw_deleting_file"), name);
215     }
216
217     g_object_set(p_note, "description", str, NULL);
218 }
219
220 /**
221  * hildon_file_handling_note_set_fraction:
222  * @note: the @HildonFileHandlingNote widget
223  * @frac: value for progress bar
224
225  * This function sets fraction value for
226  * progress bar.
227  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
228  */
229 void hildon_file_handling_note_set_fraction(HildonFileHandlingNote * note,
230                                             gfloat frac)
231 {
232     GtkWidget *progbar;
233
234     g_object_get(note, "progressbar", &progbar, NULL);
235     gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progbar), frac);
236 }
237
238 /**
239  * hildon_file_handling_note_new_moving:
240  * @parent: parent GtkWindow 
241  *
242  * This function creates new dialog
243  * which is "moving" type.
244  *
245  * Return value: a new #HildonFileHandlingNote.
246  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
247  */
248 GtkWidget *hildon_file_handling_note_new_moving(GtkWindow * parent)
249 {
250     GtkWidget *progbar;
251     HildonFileHandlingNote *file_note;
252     HildonFileHandlingNotePrivate *priv;
253
254     progbar = gtk_progress_bar_new();
255
256     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
257                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
258                              "description", _("sfil_nw_moving_file"), 
259                              "progressbar", progbar, NULL);
260
261     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
262     priv->note_type = MOVING_TYPE;
263
264     if (parent != NULL)
265         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
266
267     return GTK_WIDGET(file_note);
268 }
269
270 /**
271  * hildon_file_handling_note_new_deleting:
272  * @parent: parent GtkWindow 
273  *
274  * This function creates new dialog
275  * which is "deleting" type.
276  *
277  * Return value: a new #HildonFileHandlingNote.
278  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
279  */
280 GtkWidget *hildon_file_handling_note_new_deleting(GtkWindow * parent)
281 {
282     GtkWidget *progbar;
283     HildonFileHandlingNote *file_note;
284     HildonFileHandlingNotePrivate *priv;
285
286     progbar = gtk_progress_bar_new();
287
288     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
289                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
290                              "description", _("docm_nw_deleting_file"),
291                              "progressbar", progbar, NULL);
292
293     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
294     priv->note_type = DELETING_TYPE;
295
296     if (parent != NULL)
297         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
298
299     return GTK_WIDGET(file_note);
300 }
301
302 /**
303  * hildon_file_handling_note_new_opening:
304  * @parent: parent GtkWindow 
305  *
306  * This function creates new dialog
307  * which is "opening" type
308  *
309  * Return value: a new #HildonFileHandlingNote.
310  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
311  */
312 GtkWidget *hildon_file_handling_note_new_opening(GtkWindow * parent)
313 {
314     GtkWidget *progbar;
315     HildonFileHandlingNote *file_note;
316     HildonFileHandlingNotePrivate *priv;
317
318     progbar = gtk_progress_bar_new();
319
320     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
321                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
322                              "description", _("docm_nw_opening_file"),
323                              "progressbar", progbar, NULL);
324
325     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
326     priv->note_type = OPENING_TYPE;
327
328     if (parent != NULL)
329         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
330
331     return GTK_WIDGET(file_note);
332 }
333
334 /**
335  * hildon_file_handling_note_new_saving:
336  * @parent: parent GtkWindow 
337  *
338  * This function creates new dialog
339  * which is "saving" type.
340  *
341  * Return value: a new #HildonFileHandlingNote.
342  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
343  */
344 GtkWidget *hildon_file_handling_note_new_saving(GtkWindow * parent)
345 {
346     GtkWidget *progbar;
347     HildonFileHandlingNote *file_note;
348     HildonFileHandlingNotePrivate *priv;
349
350     progbar = gtk_progress_bar_new();
351
352     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
353                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
354                              "description", _("docm_nw_saving_file"),
355                              "progressbar", progbar, NULL);
356
357     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
358     priv->note_type = SAVING_TYPE;
359
360     if (parent != NULL)
361         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
362
363     return GTK_WIDGET(file_note);
364 }
365
366 #endif /* HILDON_DISABLE_DEPRECATED */