2006-09-12 Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
[hildon] / hildon-widgets / hildon-file-handling-note.c
1 /*
2  * This file is part of hildon-libs
3  *
4  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@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; version 2.1 of
11  * the License or 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 /**
26  * SECTION:hildon-file-handling-note
27  * @short_description: Displaying the notification when a move 
28  * operation is in progress. 
29  * @see_also: #HildonFileHandlingNote
30  * 
31  * This is the notification displayed when a move operation is in
32  * progress.  The notification uses a progress bar to indicate the
33  * progress of the operation. For operation containing multiple items, a
34  * separe progress bar is shown for each item. The notification has a
35  * single button, which allows users to stop the move operation.
36  */
37
38 #include "hildon-note.h"
39 #include "hildon-file-handling-note.h"
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <gtk/gtk.h>
43 #include <libintl.h>
44 #include <glib.h>
45 #include <glib-object.h>
46
47 #ifdef HAVE_CONFIG_H
48 #include <config.h>
49 #endif
50
51 /* Note types */
52 #define MOVING_TYPE 0
53 #define DELETING_TYPE 1
54 #define OPENING_TYPE 2
55 #define SAVING_TYPE 3
56
57 /*#define _(String) dgettext(PACKAGE, String)*/
58 #define _(String) dgettext("hildon-fm", String) /* FIXME: this file should be moved to hildon-fm */
59
60 #define HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(obj)\
61         (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
62         HILDON_TYPE_FILE_HANDLING_NOTE, HildonFileHandlingNotePrivate));
63
64 typedef struct _HildonFileHandlingNotePrivate
65     HildonFileHandlingNotePrivate;
66
67 struct _HildonFileHandlingNotePrivate {
68     guint note_type;
69 };
70
71
72 static HildonNote *parent_class;
73
74
75 /* standard forbids empty source file, therefore the ifdef must be
76    placed here. */
77
78 static void
79 hildon_file_handling_note_class_init(HildonFileHandlingNoteClass * class);
80
81 static void hildon_file_handling_note_init(HildonFileHandlingNote *
82                                            dialog);
83
84 static void hildon_file_handling_note_finalize(GObject * obj_self);
85
86
87
88
89 GType hildon_file_handling_note_get_type()
90 {
91     static GType dialog_type = 0;
92
93     if (!dialog_type) {
94         static const GTypeInfo dialog_info = {
95             sizeof(HildonFileHandlingNoteClass),
96             NULL,       /* base_init */
97             NULL,       /* base_finalize */
98             (GClassInitFunc) hildon_file_handling_note_class_init,
99             NULL,       /* class_finalize */
100             NULL,       /* class_data */
101             sizeof(HildonFileHandlingNote),
102             0,  /* n_preallocs */
103             (GInstanceInitFunc) hildon_file_handling_note_init
104         };
105
106         dialog_type = g_type_register_static(HILDON_TYPE_NOTE,
107                                              "HildonFileHandlingNote",
108                                              &dialog_info, 0);
109     }
110     return dialog_type;
111 }
112
113 static void
114 hildon_file_handling_note_class_init(HildonFileHandlingNoteClass * class)
115 {
116     GObjectClass *object_class = G_OBJECT_CLASS(class);
117
118     parent_class = g_type_class_peek_parent(class);
119     g_type_class_add_private(class, sizeof(HildonFileHandlingNotePrivate));
120     object_class->finalize = hildon_file_handling_note_finalize;
121 }
122
123 static void hildon_file_handling_note_init(HildonFileHandlingNote * dialog)
124 {
125     HildonFileHandlingNotePrivate *priv;
126
127     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(dialog);
128     priv->note_type = OPENING_TYPE;
129 }
130
131 static void hildon_file_handling_note_finalize(GObject * obj_self)
132 {
133     if (G_OBJECT_CLASS(parent_class)->finalize)
134         G_OBJECT_CLASS(parent_class)->finalize(obj_self);
135 }
136
137 /**
138  * hildon_file_handling_note_set_counter_and_name:
139  * @note: the #HildonFileHandlingNote widget
140  * @current: progress, current item being processed
141  * @maximum: maximum value for counter (number of items)
142  * @name: filename
143  *
144  * This function sets current counter value, maximum
145  * counter value and filename for dialog 
146  *
147  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
148  */
149 void hildon_file_handling_note_set_counter_and_name(HildonFileHandlingNote
150                                                     * note, guint current,
151                                                     guint maximum,
152                                                     const gchar * name)
153 {
154     gchar str[255];
155     HildonNote *p_note = HILDON_NOTE(note);
156     HildonFileHandlingNotePrivate *priv;
157
158     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(note);
159
160     if (priv->note_type == MOVING_TYPE) {
161       if (maximum == 1)
162         {
163           g_snprintf(str, 255, _("sfil_nw_moving_file"), name);
164           hildon_note_set_button_text(p_note, _("sfil_bd_moving_file"));
165         } else {
166           g_snprintf(str, 255, _("docm_nw_moving_files"),
167                      current, maximum, name);
168           hildon_note_set_button_text(p_note, _("docm_bd_moving_files"));
169         }
170     } else if (priv->note_type == SAVING_TYPE) {
171       if (maximum == 1)
172         {
173           g_snprintf(str, 255, _("docm_nw_saving_file"), name);
174           hildon_note_set_button_text(p_note, _("docm_bd_saving_file"));
175         } else {
176           g_snprintf(str, 255, _("docm_nw_saving_files"),
177                    current, maximum, name);
178           hildon_note_set_button_text(p_note, _("docm_bd_saving_files"));
179         }
180     } else if (priv->note_type == OPENING_TYPE) {
181       if (maximum == 1)
182         {
183           g_snprintf(str, 255, _("docm_nw_opening_file"), name);
184           hildon_note_set_button_text(p_note, _("docm_bd_opening_file"));
185         } else {
186           g_snprintf(str, 255, _("docm_nw_opening_files"),
187                      current, maximum, name);
188           hildon_note_set_button_text(p_note, _("docm_bd_opening_files"));
189         }
190     } else if (priv->note_type == DELETING_TYPE) {
191       if (maximum == 1)
192         {
193           g_snprintf(str, 255, _("docm_nw_deleting_file"), name);
194           hildon_note_set_button_text(p_note, _("docm_bd_deleting_file"));
195         } else {
196           g_snprintf(str, 255, _("docm_nw_deleting_files"),
197                      current, maximum, name);
198           hildon_note_set_button_text(p_note, _("docm_bd_deleting_files"));
199         }
200     }
201
202     g_object_set(p_note, "description", str, NULL);
203 }
204
205 /**
206  * hildon_file_handling_note_set_name:
207  * @note: the @HildonFileHandlingNote widget
208  * @name: filename
209  *
210  * This function sets the filename for dialog
211  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
212  */
213 void hildon_file_handling_note_set_name(HildonFileHandlingNote * note,
214                                         const gchar * name)
215 {
216     gchar str[255];
217     HildonNote *p_note = HILDON_NOTE(note);
218     HildonFileHandlingNotePrivate *priv =
219         HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(note);
220
221     if (priv->note_type == MOVING_TYPE) {
222         g_snprintf(str, 255, _("sfil_nw_moving_file"), name);
223     } else if (priv->note_type == SAVING_TYPE) {
224         g_snprintf(str, 255, _("docm_nw_saving_file"), name);
225     } else if (priv->note_type == OPENING_TYPE) {
226         g_snprintf(str, 255, _("docm_nw_opening_file"), name);
227     } else if (priv->note_type == DELETING_TYPE) {
228         g_snprintf(str, 255, _("docm_nw_deleting_file"), name);
229     }
230
231     g_object_set(p_note, "description", str, NULL);
232 }
233
234 /**
235  * hildon_file_handling_note_set_fraction:
236  * @note: the @HildonFileHandlingNote widget
237  * @frac: value for progress bar
238
239  * This function sets fraction value for
240  * progress bar.
241  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
242  */
243 void hildon_file_handling_note_set_fraction(HildonFileHandlingNote * note,
244                                             gfloat frac)
245 {
246     GtkWidget *progbar;
247
248     g_object_get(note, "progressbar", &progbar, NULL);
249     gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progbar), frac);
250 }
251
252 /**
253  * hildon_file_handling_note_new_moving:
254  * @parent: parent GtkWindow 
255  *
256  * This function creates new dialog
257  * which is "moving" type.
258  *
259  * Returns: a new #HildonFileHandlingNote
260  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
261  */
262 GtkWidget *hildon_file_handling_note_new_moving(GtkWindow * parent)
263 {
264     GtkWidget *progbar;
265     HildonFileHandlingNote *file_note;
266     HildonFileHandlingNotePrivate *priv;
267
268     progbar = gtk_progress_bar_new();
269
270     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
271                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
272                              "description", _("sfil_nw_moving_file"), 
273                              "progressbar", progbar, NULL);
274
275     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
276     priv->note_type = MOVING_TYPE;
277
278     if (parent != NULL)
279         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
280
281     return GTK_WIDGET(file_note);
282 }
283
284 /**
285  * hildon_file_handling_note_new_deleting:
286  * @parent: parent GtkWindow 
287  *
288  * This function creates new dialog
289  * which is "deleting" type.
290  *
291  * Returns: a new #HildonFileHandlingNote
292  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
293  */
294 GtkWidget *hildon_file_handling_note_new_deleting(GtkWindow * parent)
295 {
296     GtkWidget *progbar;
297     HildonFileHandlingNote *file_note;
298     HildonFileHandlingNotePrivate *priv;
299
300     progbar = gtk_progress_bar_new();
301
302     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
303                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
304                              "description", _("docm_nw_deleting_file"),
305                              "progressbar", progbar, NULL);
306
307     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
308     priv->note_type = DELETING_TYPE;
309
310     if (parent != NULL)
311         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
312
313     return GTK_WIDGET(file_note);
314 }
315
316 /**
317  * hildon_file_handling_note_new_opening:
318  * @parent: parent GtkWindow 
319  *
320  * This function creates new dialog
321  * which is "opening" type
322  *
323  * Returns: a new #HildonFileHandlingNote
324  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
325  */
326 GtkWidget *hildon_file_handling_note_new_opening(GtkWindow * parent)
327 {
328     GtkWidget *progbar;
329     HildonFileHandlingNote *file_note;
330     HildonFileHandlingNotePrivate *priv;
331
332     progbar = gtk_progress_bar_new();
333
334     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
335                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
336                              "description", _("docm_nw_opening_file"),
337                              "progressbar", progbar, NULL);
338
339     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
340     priv->note_type = OPENING_TYPE;
341
342     if (parent != NULL)
343         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
344
345     return GTK_WIDGET(file_note);
346 }
347
348 /**
349  * hildon_file_handling_note_new_saving:
350  * @parent: parent GtkWindow 
351  *
352  * This function creates new dialog
353  * which is "saving" type.
354  *
355  * Returns: a new #HildonFileHandlingNote
356  * DEPRECATED: use hildon-note instead of hildon-file-handling-note.
357  */
358 GtkWidget *hildon_file_handling_note_new_saving(GtkWindow * parent)
359 {
360     GtkWidget *progbar;
361     HildonFileHandlingNote *file_note;
362     HildonFileHandlingNotePrivate *priv;
363
364     progbar = gtk_progress_bar_new();
365
366     file_note = g_object_new(HILDON_TYPE_FILE_HANDLING_NOTE,
367                              "note_type", HILDON_NOTE_PROGRESSBAR_TYPE,
368                              "description", _("docm_nw_saving_file"),
369                              "progressbar", progbar, NULL);
370
371     priv = HILDON_FILE_HANDLING_NOTE_GET_PRIVATE(file_note);
372     priv->note_type = SAVING_TYPE;
373
374     if (parent != NULL)
375         gtk_window_set_transient_for(GTK_WINDOW(file_note), parent);
376
377     return GTK_WIDGET(file_note);
378 }
379