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