import SDK release
[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 static HildonNote *parent_class;
51
52 typedef struct _HildonFileHandlingNotePrivate
53     HildonFileHandlingNotePrivate;
54
55
56 static void
57 hildon_file_handling_note_class_init(HildonFileHandlingNoteClass * class);
58
59 static void hildon_file_handling_note_init(HildonFileHandlingNote *
60                                            dialog);
61
62 static void hildon_file_handling_note_finalize(GObject * obj_self);
63
64
65 struct _HildonFileHandlingNotePrivate {
66     guint note_type;
67 };
68
69
70 GType hildon_file_handling_note_get_type()
71 {
72     static GType dialog_type = 0;
73
74     if (!dialog_type) {
75         static const GTypeInfo dialog_info = {
76             sizeof(HildonFileHandlingNoteClass),
77             NULL,       /* base_init */
78             NULL,       /* base_finalize */
79             (GClassInitFunc) hildon_file_handling_note_class_init,
80             NULL,       /* class_finalize */
81             NULL,       /* class_data */
82             sizeof(HildonFileHandlingNote),
83             0,  /* n_preallocs */
84             (GInstanceInitFunc) hildon_file_handling_note_init
85         };
86
87         dialog_type = g_type_register_static(HILDON_TYPE_NOTE,
88                                              "HildonFileHandlingNote",
89                                              &dialog_info, 0);
90     }
91     return dialog_type;
92 }
93
94 static void
95 hildon_file_handling_note_class_init(HildonFileHandlingNoteClass * class)
96 {
97     GObjectClass *object_class = G_OBJECT_CLASS(class);
98
99     parent_class = g_type_class_peek_parent(class);
100     g_type_class_add_private(class, sizeof(HildonFileHandlingNotePrivate));
101     object_class->finalize = hildon_file_handling_note_finalize;
102 }
103
104 static void hildon_file_handling_note_init(HildonFileHandlingNote * dialog)
105 {
106     HildonFileHandlingNotePrivate *priv;
107
108     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(dialog);
109     priv->note_type = OPENING_TYPE;
110 }
111
112 static void hildon_file_handling_note_finalize(GObject * obj_self)
113 {
114     if (G_OBJECT_CLASS(parent_class)->finalize)
115         G_OBJECT_CLASS(parent_class)->finalize(obj_self);
116 }
117
118 /**
119  * hildon_file_handling_note_set_counter_and_name:
120  * @note: the #HildonFileHandlingNote widget
121  * @current: Current item
122  * @maximum: Maximum value for counter
123  * @name: Filename
124  *
125  * This function sets current counter value, maximum
126  * counter value and filename for dialog
127  */
128 void hildon_file_handling_note_set_counter_and_name(HildonFileHandlingNote
129                                                     * note, guint current,
130                                                     guint maximum,
131                                                     const gchar * name)
132 {
133     gchar str[255];
134     HildonNote *p_note = HILDON_NOTE(note);
135     HildonFileHandlingNotePrivate *priv;
136
137     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(note);
138
139     if (priv->note_type == MOVING_TYPE) {
140       if (maximum == 1)
141         {
142           g_snprintf(str, 255, _("sfil_nw_moving_file"), name);
143           hildon_note_set_button_text(p_note, _("sfil_bd_moving_file"));
144         } else {
145           g_snprintf(str, 255, _("docm_nw_moving_files"),
146                      current, maximum, name);
147           hildon_note_set_button_text(p_note, _("docm_bd_moving_files"));
148         }
149     } else if (priv->note_type == SAVING_TYPE) {
150       if (maximum == 1)
151         {
152           g_snprintf(str, 255, _("docm_nw_saving_file"), name);
153           hildon_note_set_button_text(p_note, _("docm_bd_saving_file"));
154         } else {
155           g_snprintf(str, 255, _("docm_nw_saving_files"),
156                    current, maximum, name);
157           hildon_note_set_button_text(p_note, _("docm_bd_saving_files"));
158         }
159     } else if (priv->note_type == OPENING_TYPE) {
160       if (maximum == 1)
161         {
162           g_snprintf(str, 255, _("docm_nw_opening_file"), name);
163           hildon_note_set_button_text(p_note, _("docm_bd_opening_file"));
164         } else {
165           g_snprintf(str, 255, _("docm_nw_opening_files"),
166                      current, maximum, name);
167           hildon_note_set_button_text(p_note, _("docm_bd_opening_files"));
168         }
169     } else if (priv->note_type == DELETING_TYPE) {
170       if (maximum == 1)
171         {
172           g_snprintf(str, 255, _("docm_nw_deleting_file"), name);
173           hildon_note_set_button_text(p_note, _("docm_bd_deleting_file"));
174         } else {
175           g_snprintf(str, 255, _("docm_nw_deleting_files"),
176                      current, maximum, name);
177           hildon_note_set_button_text(p_note, _("docm_bd_deleting_files"));
178         }
179     }
180
181     g_object_set(p_note, "description", str, NULL);
182 }
183
184 /**
185  * hildon_file_handling_note_set_name:
186  * @note: the @HildonFileHandlingNote widget
187  * @name: Filename
188  *
189  * This function sets filename for dialog
190  */
191 void hildon_file_handling_note_set_name(HildonFileHandlingNote * note,
192                                         const gchar * name)
193 {
194     gchar str[255];
195     HildonNote *p_note = HILDON_NOTE(note);
196     HildonFileHandlingNotePrivate *priv =
197         HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(note);
198
199     if (priv->note_type == MOVING_TYPE) {
200         g_snprintf(str, 255, _("sfil_nw_moving_file"), name);
201     } else if (priv->note_type == SAVING_TYPE) {
202         g_snprintf(str, 255, _("docm_nw_saving_file"), name);
203     } else if (priv->note_type == OPENING_TYPE) {
204         g_snprintf(str, 255, _("docm_nw_opening_file"), name);
205     } else if (priv->note_type == DELETING_TYPE) {
206         g_snprintf(str, 255, _("docm_nw_deleting_file"), name);
207     }
208
209     g_object_set(p_note, "description", str, NULL);
210 }
211
212 /**
213  * hildon_file_handling_note_set_fraction:
214  * @note: the @HildonFileHandlingNote widget
215  * @frac: value for progress bar
216
217  * This function sets fraction value for
218  * progress bar.
219  */
220 void hildon_file_handling_note_set_fraction(HildonFileHandlingNote * note,
221                                             gfloat frac)
222 {
223     GtkWidget *progbar;
224
225     g_object_get(note, "progressbar", &progbar, NULL);
226     gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progbar), frac);
227 }
228
229 /**
230  * hildon_file_handling_note_new_moving:
231  * @parent: parent GtkWindow 
232  *
233  * This function creates new dialog
234  * which is "moving" type.
235  *
236  * Return value: a new #HildonFileHandlingNote.
237  */
238 GtkWidget *hildon_file_handling_note_new_moving(GtkWindow * parent)
239 {
240     GtkWidget *progbar;
241     HildonFileHandlingNote *file_note;
242     HildonFileHandlingNotePrivate *priv;
243
244     progbar = gtk_progress_bar_new();
245
246     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
247                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
248                              "description", _("Moving..."),
249                              "progressbar", progbar, NULL);
250
251     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
252     priv->note_type = MOVING_TYPE;
253
254     if (parent != NULL)
255         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
256
257     return GTK_WIDGET(file_note);
258 }
259
260 /**
261  * hildon_file_handling_note_new_deleting:
262  * @parent: parent GtkWindow 
263  *
264  * This function creates new dialog
265  * which is "deleting" type.
266  *
267  * Return value: a new #HildonFileHandlingNote.
268  */
269 GtkWidget *hildon_file_handling_note_new_deleting(GtkWindow * parent)
270 {
271     GtkWidget *progbar;
272     HildonFileHandlingNote *file_note;
273     HildonFileHandlingNotePrivate *priv;
274
275     progbar = gtk_progress_bar_new();
276
277     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
278                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
279                              "description", _("Deleting..."),
280                              "progressbar", progbar, NULL);
281
282     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
283     priv->note_type = DELETING_TYPE;
284
285     if (parent != NULL)
286         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
287
288     return GTK_WIDGET(file_note);
289 }
290
291 /**
292  * hildon_file_handling_note_new_opening:
293  * @parent: parent GtkWindow 
294  *
295  * This function creates new dialog
296  * which is "opening" type
297  *
298  * Return value: a new #HildonFileHandlingNote.
299  */
300 GtkWidget *hildon_file_handling_note_new_opening(GtkWindow * parent)
301 {
302     GtkWidget *progbar;
303     HildonFileHandlingNote *file_note;
304     HildonFileHandlingNotePrivate *priv;
305
306     progbar = gtk_progress_bar_new();
307
308     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
309                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
310                              "description", _("Opening..."),
311                              "progressbar", progbar, NULL);
312
313     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
314     priv->note_type = OPENING_TYPE;
315
316     if (parent != NULL)
317         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
318
319     return GTK_WIDGET(file_note);
320 }
321
322 /**
323  * hildon_file_handling_note_new_saving:
324  * @parent: parent GtkWindow 
325  *
326  * This function creates new dialog
327  * which is "saving" type.
328  *
329  * Return value: a new #HildonFileHandlingNote.
330  */
331 GtkWidget *hildon_file_handling_note_new_saving(GtkWindow * parent)
332 {
333     GtkWidget *progbar;
334     HildonFileHandlingNote *file_note;
335     HildonFileHandlingNotePrivate *priv;
336
337     progbar = gtk_progress_bar_new();
338     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
339                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
340                              "description", _("Saving..."),
341                              "progressbar", progbar, NULL);
342
343     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
344     priv->note_type = SAVING_TYPE;
345
346     if (parent != NULL)
347         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
348
349     return GTK_WIDGET(file_note);
350 }