* fix for NB#63391, where a notes-attachment would be opened in the browser instead
[modest] / src / maemo / modest-maemo-utils.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef DBUS_API_SUBJECT_TO_CHANGE
31 #define DBUS_API_SUBJECT_TO_CHANGE
32 #endif /*DBUS_API_SUBJECT_TO_CHANGE*/
33
34 #include <dbus/dbus.h>
35 #include <dbus/dbus-glib-lowlevel.h>
36 #include <glib.h>
37 #include <glib/gstdio.h>
38 #include <errno.h>
39 #include <modest-runtime.h>
40 #include <libgnomevfs/gnome-vfs.h>
41 #include <tny-fs-stream.h>
42 #include <tny-camel-account.h>
43 #include <tny-status.h>
44 #include <tny-camel-transport-account.h>
45 #include <tny-camel-imap-store-account.h>
46 #include <tny-camel-pop-store-account.h>
47 #include "modest-hildon-includes.h"
48
49 #include "modest-maemo-utils.h"
50 #include "modest-platform.h"
51
52 /*
53  * For getting and tracking the Bluetooth name
54  */
55 #define BTNAME_SERVICE                  "org.bluez"
56 #define BTNAME_REQUEST_IF               "org.bluez.Adapter"
57 #define BTNAME_SIGNAL_IF                "org.bluez.Adapter"
58 #define BTNAME_REQUEST_PATH             "/org/bluez/hci0"
59 #define BTNAME_SIGNAL_PATH              "/org/bluez/hci0"
60
61 #define BTNAME_REQ_GET                  "GetName"
62 #define BTNAME_SIG_CHANGED              "NameChanged"
63
64 #define BTNAME_MATCH_RULE "type='signal',interface='" BTNAME_SIGNAL_IF \
65                           "',member='" BTNAME_SIG_CHANGED "'"
66
67 GQuark modest_maemo_utils_get_supported_secure_authentication_error_quark (void)
68 {
69         return g_quark_from_static_string("modest-maemo-utils-get-supported-secure-authentication-error-quark");
70 }
71
72 GtkWidget*
73 modest_maemo_utils_menubar_to_menu (GtkUIManager *ui_manager)
74 {
75         GtkWidget *main_menu;
76         GtkWidget *menubar;
77         GList *iter;
78
79         g_return_val_if_fail (ui_manager, NULL);
80         
81         /* Create new main menu */
82         main_menu = gtk_menu_new();
83
84         /* Get the menubar from the UI manager */
85         menubar = gtk_ui_manager_get_widget (ui_manager, "/MenuBar");
86
87         iter = gtk_container_get_children (GTK_CONTAINER (menubar));
88         while (iter) {
89                 GtkWidget *menu;
90
91                 menu = GTK_WIDGET (iter->data);
92                 gtk_widget_reparent(menu, main_menu);
93
94                 iter = g_list_next (iter);
95         }
96         return main_menu;
97 }
98
99
100 static void
101 update_device_name_from_msg (DBusMessage *message)
102 {
103         DBusError error;
104         DBusMessageIter iter;
105
106         dbus_error_init (&error);
107
108         if (dbus_set_error_from_message (&error, message)) {
109                 g_printerr ("modest: failed to get bluetooth name: %s\n", error.message);
110                 dbus_error_free (&error);
111         } else {
112                 const gchar *device_name;
113                 if (!dbus_message_iter_init (message, &iter)) {
114                         g_printerr ("modest: message did not have argument\n");
115                         return;
116                 }
117                 dbus_message_iter_get_basic (&iter, &device_name);
118                 g_warning ("update device name: %s", device_name);
119                 modest_conf_set_string (modest_runtime_get_conf(),
120                                         MODEST_CONF_DEVICE_NAME, device_name,
121                                         NULL);
122         }
123 }
124
125
126 static void
127 on_device_name_received (DBusPendingCall *call, void *user_data)
128 {
129         DBusMessage *message;
130         
131         g_return_if_fail (dbus_pending_call_get_completed (call));
132         
133         message = dbus_pending_call_steal_reply (call);
134         if (!message) {
135                 g_printerr ("modest: no reply on device name query\n");
136                 return;
137         }
138
139         update_device_name_from_msg (message);
140         dbus_message_unref (message);
141 }
142
143
144 static DBusHandlerResult
145 handle_dbus_signal (DBusConnection *conn, DBusMessage *msg, gpointer data)
146 {
147         if (dbus_message_is_signal(msg, BTNAME_SIGNAL_IF, BTNAME_SIG_CHANGED))
148                 update_device_name_from_msg (msg);
149
150         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
151 }
152
153
154 static void
155 get_device_name_from_dbus ()
156 {
157         static DBusConnection *conn = NULL;
158         DBusMessage *request;
159         DBusError error;
160         DBusPendingCall *call = NULL;
161         
162         dbus_error_init (&error);
163         if (!conn) {
164                 conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
165                 if (!conn) {
166                         g_printerr ("modest: cannot get on the dbus: %s: %s\n",
167                                     error.name, error.message);
168                         dbus_error_free (&error);
169                         return;
170                 }
171         }
172         
173         request = dbus_message_new_method_call (BTNAME_SERVICE, BTNAME_REQUEST_PATH,
174                                                 BTNAME_REQUEST_IF, BTNAME_REQ_GET);
175         if (!request) {
176                 /* should we free the connection? */
177                 g_printerr ("modest: dbus_message_new_method_call failed\n");
178                 return;
179         }
180         dbus_message_set_auto_start (request, TRUE);
181         if (dbus_connection_send_with_reply (conn, request, &call, -1)) {
182                 dbus_pending_call_set_notify (call, on_device_name_received,
183                                               NULL, NULL);
184                 dbus_pending_call_unref (call);
185         }
186         dbus_message_unref (request);
187         
188         dbus_connection_setup_with_g_main (conn, NULL);
189         dbus_bus_add_match (conn, BTNAME_MATCH_RULE, &error);
190         if (dbus_error_is_set(&error)) {
191                 g_printerr ("modest: dbus_bus_add_match failed: %s\n", error.message);
192                 dbus_error_free (&error);
193         }
194
195         if (!dbus_connection_add_filter(conn, handle_dbus_signal, NULL, NULL))
196                 g_printerr ("modest: dbus_connection_add_filter failed\n");
197 }
198
199
200 void
201 modest_maemo_utils_get_device_name (void)
202 {
203         get_device_name_from_dbus ();
204 }
205
206 gboolean 
207 modest_maemo_utils_folder_writable (const gchar *filename)
208 {
209         g_return_val_if_fail (filename, FALSE);
210
211         if (!filename)
212                 return FALSE;
213         
214         if (g_strncasecmp (filename, "obex", 4) != 0) {
215                 GnomeVFSFileInfo folder_info;
216                 gchar *folder;
217                 folder = g_path_get_dirname (filename);
218                 gnome_vfs_get_file_info (folder, &folder_info,
219                                          GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS);
220                 g_free (folder);
221                 if (!((folder_info.permissions & GNOME_VFS_PERM_ACCESS_WRITABLE) ||
222                       (folder_info.permissions & GNOME_VFS_PERM_USER_WRITE))) {
223                         return FALSE;
224                 }
225         }
226         return TRUE;
227 }
228
229 gboolean 
230 modest_maemo_utils_file_exists (const gchar *filename)
231 {
232         GnomeVFSURI *uri = NULL;
233         gboolean result = FALSE;
234
235         uri = gnome_vfs_uri_new (filename);
236         if (uri) {
237                 result = gnome_vfs_uri_exists (uri);
238                 gnome_vfs_uri_unref (uri);
239         }
240         return result;
241 }
242
243 TnyFsStream *
244 modest_maemo_utils_create_temp_stream (const gchar *orig_name, gchar **path)
245 {
246         gint fd;
247         gchar *filepath = NULL;
248         gchar *tmpdir;
249
250         /* make a random subdir under /tmp or /var/tmp */
251         tmpdir = g_strdup_printf ("%s/%d", g_get_tmp_dir (), (guint)random());
252         if (g_mkdir (tmpdir, 0755) == -1) {
253                 g_warning ("%s: failed to create dir '%s': %s",
254                            __FUNCTION__, tmpdir, g_strerror(errno));
255                 g_free (tmpdir);
256                 return NULL;
257         }
258
259         /* try to write the file there */
260         filepath = g_strconcat (tmpdir, "/", orig_name, NULL);
261         fd = g_open (filepath, O_CREAT|O_WRONLY|O_TRUNC, 0644);
262         if (fd == -1) {
263                 g_warning ("%s: failed to create '%s': %s",
264                            __FUNCTION__, filepath, g_strerror(errno));
265                 g_free (tmpdir);
266                 g_free (filepath);
267                 return NULL;
268         }
269
270         g_free (tmpdir);
271
272         if (path)
273                 *path = filepath;
274
275         return TNY_FS_STREAM (tny_fs_stream_new (fd));
276 }
277
278 typedef struct 
279 {
280         gboolean cancel;
281         GList *result;
282         GtkWidget* dialog;
283         GtkWidget* progress;
284         GError* error;
285 } ModestGetSupportedAuthInfo;
286
287 static void on_camel_account_get_supported_secure_authentication_status (
288         GObject *self, TnyStatus *status, gpointer user_data)
289 {
290         /*ModestGetSupportedAuthInfo* info = (ModestGetSupportedAuthInfo*) user_data;*/
291 }
292
293 static gboolean
294 on_idle_secure_auth_finished (gpointer user_data)
295 {
296         ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
297         /* Operation has finished, close the dialog. Control continues after
298          * gtk_dialog_run in modest_maemo_utils_get_supported_secure_authentication_methods() */
299
300         /* This is a GDK lock because we are an idle callback and
301          * the code below is or does Gtk+ code */
302
303         gdk_threads_enter(); /* CHECKED */
304         gtk_dialog_response (GTK_DIALOG (info->dialog), GTK_RESPONSE_ACCEPT);
305         gdk_threads_leave(); /* CHECKED */
306
307         return FALSE;
308 }
309
310 static void
311 on_camel_account_get_supported_secure_authentication (
312   TnyCamelAccount *self, gboolean cancelled,
313   TnyList *auth_types, GError **err, 
314   gpointer user_data)
315 {
316                 
317         ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
318         g_return_if_fail (info);
319
320         /* Free everything if the actual action was canceled */
321         if (info->cancel)
322         {
323                 /* The operation was canceled and the ownership of the info given to us
324                  * so that we could still check the cancel flag. */
325                 g_slice_free (ModestGetSupportedAuthInfo, info);
326                 info = NULL;
327         }
328         else
329         {
330                 /* TODO: Why is this a pointer to a pointer? We are not supposed to
331                  * set it, are we? */
332                 if(err != NULL && *err != NULL)
333                 {
334                         if(info->error != NULL) g_error_free(info->error);
335                         info->error = g_error_copy(*err);
336                 }
337
338                 if (!auth_types) {
339                         printf ("DEBUG: %s: auth_types is NULL.\n", __FUNCTION__);
340                 }
341                 else
342                 {
343                         ModestPairList* pairs = modest_protocol_info_get_auth_protocol_pair_list ();
344   
345                         /* Get the enum value for the strings: */
346                         GList *result = NULL;
347                         TnyIterator* iter = tny_list_create_iterator(auth_types);
348                         while (!tny_iterator_is_done(iter)) {
349                                 TnyPair *pair = TNY_PAIR(tny_iterator_get_current(iter));
350                                 const gchar *auth_name = NULL;
351                                 if (pair) {
352                                         auth_name = tny_pair_get_name(pair);
353                                         g_object_unref (pair);
354                                         pair = NULL;
355                                 }
356
357                                 printf("DEBUG: %s: auth_name=%s\n", __FUNCTION__, auth_name);
358
359                                 ModestAuthProtocol proto = modest_protocol_info_get_auth_protocol (auth_name);
360                                 if(proto != MODEST_PROTOCOL_AUTH_NONE)
361                                                 result = g_list_prepend(result, GINT_TO_POINTER(proto));
362
363                                 tny_iterator_next(iter);
364                         }
365                         g_object_unref (iter);
366
367                         modest_pair_list_free (pairs);
368         
369                         info->result = result;
370                 }
371
372                 printf("DEBUG: finished\n");
373
374                 /* Close the dialog in a main thread */
375                 g_idle_add(on_idle_secure_auth_finished, info);
376         }
377 }
378
379 static void on_secure_auth_cancel(GtkWidget* dialog, int response, gpointer user_data)
380 {
381         if(response == GTK_RESPONSE_REJECT || response == GTK_RESPONSE_DELETE_EVENT)
382         {
383                 ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
384                 g_return_if_fail(info);
385                 /* This gives the ownership of the info to the worker thread. */
386                 info->result = NULL;
387                 info->cancel = TRUE;
388         }
389 }
390
391
392 typedef struct
393 {
394         GMainLoop* loop;
395 } UserData;
396
397 static UserData *user_data = NULL;
398
399 static void
400 on_account_online (TnyCamelAccount *account, GError *err)
401 {
402         printf ("DEBUGa1: %s\n", __FUNCTION__);
403         
404         if (err) {
405                 printf("DEBUG: %s: error=\n  %s\n", __FUNCTION__, err->message);        
406         }
407         
408         /* Allow the function that requested this callback to continue: */
409         /* TODO: Tinymail should really give us user_data with this callback. */
410         if (user_data && user_data->loop)
411                 g_main_loop_quit (user_data->loop);
412 }
413
414 GList*
415 modest_maemo_utils_get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto, 
416         const gchar* hostname, gint port, const gchar* username, GtkWindow *parent_window, GError** error)
417 {
418         g_return_val_if_fail (proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN, NULL);
419         
420         /* We need a connection to get the capabilities; */
421         if (!modest_platform_connect_and_wait (GTK_WINDOW (parent_window), NULL))
422                 return NULL;
423          
424         /*
425         result = g_list_append (result, GINT_TO_POINTER (MODEST_PROTOCOL_AUTH_CRAMMD5));
426         */
427         
428         /* Create a TnyCamelAccount so we can use 
429          * tny_camel_account_get_supported_secure_authentication(): */
430         TnyAccount * tny_account = NULL;
431         switch (proto) {
432         case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
433         case MODEST_PROTOCOL_TRANSPORT_SMTP:
434                 tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ()); break;
435         case MODEST_PROTOCOL_STORE_POP:
436                 tny_account = TNY_ACCOUNT(tny_camel_pop_store_account_new ()); break;
437         case MODEST_PROTOCOL_STORE_IMAP:
438                 tny_account = TNY_ACCOUNT(tny_camel_imap_store_account_new ()); break;
439         case MODEST_PROTOCOL_STORE_MAILDIR:
440         case MODEST_PROTOCOL_STORE_MBOX:
441                 tny_account = TNY_ACCOUNT(tny_camel_store_account_new()); break;
442         default:
443                 tny_account = NULL;
444         }
445
446         
447         if (!tny_account) {
448                 g_printerr ("%s could not create tny account.", __FUNCTION__);
449                 return NULL;
450         }
451         
452         /* Set proto, so that the prepare_func() vfunc will work when we call 
453          * set_session(): */
454          /* TODO: Why isn't this done in account_new()? */
455         tny_account_set_proto (tny_account,
456                                modest_protocol_info_get_transport_store_protocol_name(proto));
457
458         tny_account_set_hostname (tny_account, hostname);
459         /* Required for POP, at least */
460         tny_account_set_user (tny_account, username);
461                                
462         if(port > 0)
463                 tny_account_set_port (tny_account, port);
464                 
465         /* Set the session for the account, so we can use it: */
466         ModestTnyAccountStore *account_store = modest_runtime_get_account_store ();
467         TnySessionCamel *session = 
468                 modest_tny_account_store_get_session (TNY_ACCOUNT_STORE (account_store));
469         g_return_val_if_fail (session, NULL);
470         tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
471         
472         
473         /* This blocks on the result: */
474         /* TODO: Fix tinymail to take user_data for the callback instead of using one static instance: */
475         if (user_data)  {
476                 g_slice_free (UserData, user_data);
477                 user_data = NULL;
478         }
479         
480         user_data = g_slice_new0 (UserData);
481         user_data->loop = g_main_loop_new (NULL, FALSE /* not running */);
482
483         /* We get a warning if we don't do use tny_camel_account_set_online():
484          * GLIB CRITICAL ** camel-lite - camel_service_query_auth_types: assertion `service != NULL' failed.
485          */
486         tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (tny_account), TRUE, &on_account_online);
487         printf ("DEBUGa2: %s\n", __FUNCTION__);
488         
489         /* This main loop will run until the idle handler has stopped it: */
490         printf ("DEBUG: %s: before g_main_loop_run()\n", __FUNCTION__);
491         GDK_THREADS_LEAVE();
492         g_main_loop_run (user_data->loop);
493         GDK_THREADS_ENTER();
494         printf ("DEBUG: %s: after g_main_loop_run()\n", __FUNCTION__);
495         g_main_loop_unref (user_data->loop);
496         /* g_main_context_unref (context); */
497
498         g_slice_free (UserData, user_data);
499         user_data = NULL;
500         
501         
502         /* Ask camel to ask the server, asynchronously: */
503         ModestGetSupportedAuthInfo *info = g_slice_new (ModestGetSupportedAuthInfo);
504         info->result = NULL;
505         info->cancel = FALSE;
506         info->error = NULL;
507         info->progress = gtk_progress_bar_new();
508         /* TODO: Need logical_ID for the title: */
509         info->dialog = gtk_dialog_new_with_buttons(_("Authentication"),
510                                                    parent_window, GTK_DIALOG_MODAL,
511                                                    _("mcen_bd_dialog_cancel"),
512                                                    GTK_RESPONSE_REJECT,
513                                                    NULL);
514         //gtk_window_set_default_size(GTK_WINDOW(info->dialog), 300, 100);
515         
516         g_signal_connect(G_OBJECT(info->dialog), "response", G_CALLBACK(on_secure_auth_cancel), info);
517         
518         gtk_container_add(GTK_CONTAINER(GTK_DIALOG(info->dialog)->vbox),
519                           gtk_label_new("Checking for supported authentication types..."));
520         gtk_container_add(GTK_CONTAINER(GTK_DIALOG(info->dialog)->vbox), info->progress);
521         gtk_widget_show_all(info->dialog);
522         gtk_progress_bar_pulse(GTK_PROGRESS_BAR(info->progress));
523         
524         printf ("DEBUG: %s: STARTING.\n", __FUNCTION__);
525         tny_camel_account_get_supported_secure_authentication (
526                 TNY_CAMEL_ACCOUNT (tny_account),
527                 on_camel_account_get_supported_secure_authentication,
528                 on_camel_account_get_supported_secure_authentication_status,
529                 info);
530
531         gtk_dialog_run (GTK_DIALOG (info->dialog));
532         
533         gtk_widget_destroy(info->dialog);
534                 
535         GList *result = info->result;
536         if (!info->cancel)
537         {
538                 if(info->error != NULL)
539                         g_propagate_error(error, info->error);
540
541                 g_slice_free (ModestGetSupportedAuthInfo, info);
542                 info = NULL;
543         }
544         else
545         {
546                 // Tell the caller that the operation was canceled so it can
547                 // make a difference
548                 g_set_error(error,
549                             modest_maemo_utils_get_supported_secure_authentication_error_quark(),
550                             MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED,
551                             "User has canceled query");
552         }
553
554         return result;
555 }
556
557 void
558 modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser)
559 {
560         gchar *images_folder;
561         GtkFileFilter *file_filter;
562         GList *image_mimetypes_list;
563         GList *node;
564
565         g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
566
567         /* Set the default folder to images folder */
568         images_folder = g_build_filename (g_get_home_dir (), 
569                                           MODEST_MAEMO_UTILS_MYDOCS_FOLDER,
570                                           MODEST_MAEMO_UTILS_DEFAULT_IMAGE_FOLDER, NULL);
571         gtk_file_chooser_set_current_folder (chooser, images_folder);
572         g_free (images_folder);
573
574         /* Set the images mime filter */
575         file_filter = gtk_file_filter_new ();
576 #ifdef MODEST_HAVE_HILDON0_WIDGETS
577         image_mimetypes_list = osso_mime_get_mime_types_for_category (OSSO_MIME_CATEGORY_IMAGES);
578 #else
579         image_mimetypes_list = hildon_mime_get_mime_types_for_category (HILDON_MIME_CATEGORY_IMAGES);
580 #endif
581         for (node = image_mimetypes_list; node != NULL; node = g_list_next (node)) {
582                 gtk_file_filter_add_mime_type (file_filter, node->data);
583         }
584         gtk_file_chooser_set_filter (chooser, file_filter);
585 #ifdef MODEST_HAVE_HILDON0_WIDGETS
586         osso_mime_types_list_free (image_mimetypes_list);
587 #else
588         hildon_mime_types_list_free (image_mimetypes_list);
589 #endif
590
591 }
592
593 static void
594 on_response (GtkDialog *dialog, gint response, gpointer user_data)
595 {
596         /* Just destroy the dialog: */
597         gtk_widget_destroy (GTK_WIDGET (dialog));
598 }
599
600 void
601 modest_maemo_show_information_note_and_forget (GtkWindow *parent_window, const gchar* message)
602 {
603         GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, message));
604         
605         /* Destroy the dialog when it is closed: */
606         g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (on_response), NULL);
607         gtk_widget_show (GTK_WIDGET (dialog));
608 }
609
610 #if 0
611 static void
612 on_hide (GtkDialog *dialog, gpointer user_data)
613 {
614         /* Just destroy the dialog: */
615         gtk_widget_destroy (GTK_WIDGET (dialog));
616 }
617 #endif
618
619 #if 0 /* Not used now. */
620 /* user_data for the idle callback: */
621 typedef struct 
622 {
623         GtkWindow *parent_window;
624         gchar *message;
625 } ModestIdleNoteInfo;
626
627 static gboolean
628 on_idle_show_information(gpointer user_data)
629 {
630         ModestIdleNoteInfo *info = (ModestIdleNoteInfo*)user_data;
631         
632         modest_maemo_show_information_note_and_forget (info->parent_window, info->message);
633         
634         g_free (info->message);
635         g_slice_free (ModestIdleNoteInfo, info);
636         
637         return FALSE; /* Don't call this again. */
638 }
639
640 void modest_maemo_show_information_note_in_main_context_and_forget (GtkWindow *parent_window, const gchar* message)
641 {
642         ModestIdleNoteInfo *info = g_slice_new (ModestIdleNoteInfo);
643         info->parent_window = parent_window;
644         info->message = g_strdup (message);
645         
646         g_idle_add (on_idle_show_information, info);
647 }
648 #endif
649
650 void modest_maemo_show_dialog_and_forget (GtkWindow *parent_window, GtkDialog *dialog)
651 {
652         gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window);
653         
654         /* Destroy the dialog when it is closed: */
655         g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (on_response), NULL);
656         gtk_widget_show (GTK_WIDGET (dialog));
657 }
658
659
660
661 void
662 modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win, gboolean thumbable)
663 {
664         g_return_if_fail (GTK_IS_SCROLLED_WINDOW(win));
665 #ifdef MODEST_HAVE_HILDON1_WIDGETS              
666         hildon_helper_set_thumb_scrollbar (win, thumbable);
667 #endif /* MODEST_HAVE_HILDON1_WIDGETS */
668 }
669
670 void
671 modest_maemo_toggle_action_set_active_block_notify (GtkToggleAction *action, gboolean value)
672 {
673         GSList *proxies = NULL;
674
675         g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
676
677         for (proxies = gtk_action_get_proxies (GTK_ACTION (action));
678              proxies != NULL; proxies = g_slist_next (proxies)) {
679                 GtkWidget *widget = (GtkWidget *) proxies->data;
680                 gtk_action_block_activate_from (GTK_ACTION (action), widget);
681         }
682
683         gtk_toggle_action_set_active (action, value);
684
685         for (proxies = gtk_action_get_proxies (GTK_ACTION (action));
686              proxies != NULL; proxies = g_slist_next (proxies)) {
687                 GtkWidget *widget = (GtkWidget *) proxies->data;
688                 gtk_action_unblock_activate_from (GTK_ACTION (action), widget);
689         }
690
691 }