1 /* Copyright (c) 2007, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
31 #include <glib/gstdio.h>
33 #include <string.h> /* for strlen */
34 #include <modest-runtime.h>
35 #include <libgnomevfs/gnome-vfs.h>
36 #include <tny-fs-stream.h>
37 #include <tny-camel-account.h>
38 #include <tny-status.h>
39 #include <tny-camel-transport-account.h>
40 #include <tny-camel-imap-store-account.h>
41 #include <tny-camel-pop-store-account.h>
43 #include <modest-defs.h>
44 #include "modest-utils.h"
45 #include "modest-platform.h"
46 #include <modest-account-protocol.h>
47 #include "modest-account-mgr-helpers.h"
48 #include "modest-text-utils.h"
49 #include <modest-local-folder-info.h>
50 #include "widgets/modest-header-view.h"
51 #include "widgets/modest-main-window.h"
52 #include "modest-widget-memory.h"
53 #include "widgets/modest-sort-criterium-view.h"
56 modest_utils_get_supported_secure_authentication_error_quark (void)
58 return g_quark_from_static_string("modest-utils-get-supported-secure-authentication-error-quark");
62 modest_utils_folder_writable (const gchar *filename)
64 g_return_val_if_fail (filename, FALSE);
69 if (g_strncasecmp (filename, "obex", 4) != 0) {
70 GnomeVFSFileInfo *folder_info;
72 GnomeVFSResult result;
74 folder = g_path_get_dirname (filename);
75 folder_info = gnome_vfs_file_info_new ();
76 result = gnome_vfs_get_file_info (folder, folder_info,
77 GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS);
80 if ((result != GNOME_VFS_OK) ||
81 (!((folder_info->permissions & GNOME_VFS_PERM_ACCESS_WRITABLE) ||
82 (folder_info->permissions & GNOME_VFS_PERM_USER_WRITE)))) {
84 gnome_vfs_file_info_unref (folder_info);
87 gnome_vfs_file_info_unref (folder_info);
93 modest_utils_file_exists (const gchar *filename)
95 GnomeVFSURI *uri = NULL;
96 gboolean result = FALSE;
98 g_return_val_if_fail (filename, FALSE);
100 uri = gnome_vfs_uri_new (filename);
102 result = gnome_vfs_uri_exists (uri);
103 gnome_vfs_uri_unref (uri);
109 modest_utils_create_temp_stream (const gchar *orig_name, const gchar *hash_base, gchar **path)
112 gchar *filepath = NULL;
116 /* hmmm... maybe we need a modest_text_utils_validate_file_name? */
117 g_return_val_if_fail (orig_name && strlen(orig_name) != 0, NULL);
119 if (strlen(orig_name) > 200) {
120 g_warning ("%s: filename too long ('%s')",
121 __FUNCTION__, orig_name);
125 if (g_strstr_len (orig_name, strlen(orig_name), "/") != NULL) {
126 g_warning ("%s: filename contains '/' character(s) (%s)",
127 __FUNCTION__, orig_name);
131 /* make a random subdir under /tmp or /var/tmp */
132 if (hash_base != NULL) {
133 hash_number = g_str_hash (hash_base);
135 hash_number = (guint) random ();
137 tmpdir = g_strdup_printf ("%s/%u", g_get_tmp_dir (), hash_number);
138 if ((g_access (tmpdir, R_OK) == -1) && (g_mkdir (tmpdir, 0755) == -1)) {
139 g_warning ("%s: failed to create dir '%s': %s",
140 __FUNCTION__, tmpdir, g_strerror(errno));
145 filepath = g_strconcat (tmpdir, "/", orig_name, NULL);
146 /* don't overwrite if it already exists, even if it is writable */
147 if (modest_utils_file_exists (filepath)) {
156 /* try to write the file there */
157 fd = g_open (filepath, O_CREAT|O_WRONLY|O_TRUNC, 0644);
159 g_warning ("%s: failed to create '%s': %s",
160 __FUNCTION__, filepath, g_strerror(errno));
172 return TNY_FS_STREAM (tny_fs_stream_new (fd));
182 } ModestGetSupportedAuthInfo;
184 static void on_camel_account_get_supported_secure_authentication_status (
185 GObject *self, TnyStatus *status, gpointer user_data)
187 /*ModestGetSupportedAuthInfo* info = (ModestGetSupportedAuthInfo*) user_data;*/
191 on_idle_secure_auth_finished (gpointer user_data)
193 ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
194 /* Operation has finished, close the dialog. Control continues after
195 * gtk_dialog_run in modest_utils_get_supported_secure_authentication_methods() */
197 /* This is a GDK lock because we are an idle callback and
198 * the code below is or does Gtk+ code */
200 gdk_threads_enter(); /* CHECKED */
201 gtk_dialog_response (GTK_DIALOG (info->dialog), GTK_RESPONSE_ACCEPT);
202 gdk_threads_leave(); /* CHECKED */
208 on_camel_account_get_supported_secure_authentication (TnyCamelAccount *self, gboolean cancelled,
209 TnyList *auth_types, GError *err, gpointer user_data)
211 ModestPairList *pairs;
213 ModestProtocolRegistry *protocol_registry;
214 ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
217 g_return_if_fail (user_data);
218 g_return_if_fail (TNY_IS_CAMEL_ACCOUNT(self));
219 g_return_if_fail (TNY_IS_LIST(auth_types));
221 info = (ModestGetSupportedAuthInfo *) user_data;
223 /* Free everything if the actual action was canceled */
226 g_debug ("%s: operation canceled\n", __FUNCTION__);
232 g_error_free (info->error);
235 info->error = g_error_copy (err);
240 g_debug ("%s: auth_types is NULL.\n", __FUNCTION__);
244 if (tny_list_get_length(auth_types) == 0) {
245 g_debug ("%s: auth_types is an empty TnyList.\n", __FUNCTION__);
249 protocol_registry = modest_runtime_get_protocol_registry ();
250 pairs = modest_protocol_registry_get_pair_list_by_tag (protocol_registry, MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS);
252 /* Get the enum value for the strings: */
254 iter = tny_list_create_iterator(auth_types);
255 while (!tny_iterator_is_done(iter)) {
257 const gchar *auth_name;
258 ModestProtocolType protocol_type;
260 pair = TNY_PAIR(tny_iterator_get_current(iter));
263 auth_name = tny_pair_get_name(pair);
264 g_object_unref (pair);
268 g_debug ("%s: auth_name=%s\n", __FUNCTION__, auth_name);
270 protocol_type = modest_protocol_get_type_id (modest_protocol_registry_get_protocol_by_name (protocol_registry,
271 MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS,
274 if (modest_protocol_registry_protocol_type_is_secure (protocol_registry, protocol_type))
275 result = g_list_prepend(result, GINT_TO_POINTER(protocol_type));
277 tny_iterator_next(iter);
279 g_object_unref (iter);
281 modest_pair_list_free (pairs);
282 info->result = result;
285 /* Close the dialog in a main thread */
286 g_idle_add(on_idle_secure_auth_finished, info);
290 on_secure_auth_cancel(GtkWidget* dialog, int response, gpointer user_data)
292 g_return_if_fail (GTK_IS_WIDGET(dialog));
294 if(response == GTK_RESPONSE_REJECT || response == GTK_RESPONSE_DELETE_EVENT) {
295 ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
296 g_return_if_fail(info);
297 /* This gives the ownership of the info to the worker thread. */
303 GtkProgressBar *progress;
304 gboolean not_finished;
308 keep_pulsing (gpointer user_data)
310 KeepPulsing *info = (KeepPulsing *) user_data;
312 gtk_progress_bar_pulse (info->progress);
314 if (!info->not_finished) {
315 g_object_unref (info->progress);
316 g_slice_free (KeepPulsing, info);
324 modest_utils_get_supported_secure_authentication_methods (ModestProtocolType protocol_type,
325 const gchar* hostname, gint port, const gchar* username, GtkWindow *parent_window, GError** error)
327 TnyAccount * tny_account = NULL;
328 ModestProtocolRegistry *protocol_registry;
329 ModestProtocol *protocol;
331 g_return_val_if_fail (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID, NULL);
333 protocol_registry = modest_runtime_get_protocol_registry ();
335 /* We need a connection to get the capabilities; */
336 if (!modest_platform_connect_and_wait (GTK_WINDOW (parent_window), NULL))
340 result = g_list_append (result, GINT_TO_POINTER (MODEST_PROTOCOL_AUTH_CRAMMD5));
343 /* Create a TnyCamelAccount so we can use
344 * tny_camel_account_get_supported_secure_authentication(): */
345 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
347 if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
348 tny_account = modest_account_protocol_create_account (MODEST_ACCOUNT_PROTOCOL (protocol));
352 g_printerr ("%s could not create tny account.", __FUNCTION__);
356 /* Set proto, so that the prepare_func() vfunc will work when we call
358 /* TODO: Why isn't this done in account_new()? */
359 tny_account_set_proto (tny_account,
360 modest_protocol_get_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type)));
362 tny_account_set_hostname (tny_account, hostname);
363 /* Required for POP, at least */
364 tny_account_set_user (tny_account, username);
367 tny_account_set_port (tny_account, port);
369 /* Set the session for the account, so we can use it: */
370 ModestTnyAccountStore *account_store = modest_runtime_get_account_store ();
371 TnySessionCamel *session =
372 modest_tny_account_store_get_session (TNY_ACCOUNT_STORE (account_store));
373 g_return_val_if_fail (session, NULL);
374 tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
377 /* Ask camel to ask the server, asynchronously: */
378 ModestGetSupportedAuthInfo *info = g_slice_new (ModestGetSupportedAuthInfo);
380 info->cancel = FALSE;
382 info->progress = gtk_progress_bar_new();
384 info->dialog = gtk_dialog_new_with_buttons(" ",
385 parent_window, GTK_DIALOG_MODAL,
386 _("mcen_bd_dialog_cancel"),
390 g_signal_connect(G_OBJECT(info->dialog), "response", G_CALLBACK(on_secure_auth_cancel), info);
392 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(info->dialog)->vbox),
393 gtk_label_new(_("emev_ni_checking_supported_auth_methods")));
394 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(info->dialog)->vbox), info->progress);
395 gtk_widget_show_all(info->dialog);
397 KeepPulsing *pi = g_slice_new (KeepPulsing);
398 pi->progress = (GtkProgressBar *) g_object_ref (info->progress);
399 pi->not_finished = TRUE;
401 /* Starts the pulsing of the progressbar */
402 g_timeout_add (500, keep_pulsing, pi);
404 tny_camel_account_get_supported_secure_authentication (
405 TNY_CAMEL_ACCOUNT (tny_account),
406 on_camel_account_get_supported_secure_authentication,
407 on_camel_account_get_supported_secure_authentication_status,
410 gtk_dialog_run (GTK_DIALOG (info->dialog));
412 pi->not_finished = FALSE;
413 /* pi is freed in the timeout itself to avoid a GCond here */
415 gtk_widget_destroy(info->dialog);
418 GList *result = info->result;
421 gchar * debug_url_string = tny_account_get_url_string (tny_account);
422 g_warning ("%s:\n error: %s\n account url: %s", __FUNCTION__, info->error->message,
424 g_free (debug_url_string);
426 g_propagate_error(error, info->error);
430 // Tell the caller that the operation was canceled so it can
433 modest_utils_get_supported_secure_authentication_error_quark(),
434 MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED,
435 "User has canceled query");
440 g_free (info->error);
442 g_list_free (info->result);
444 gtk_widget_destroy (info->dialog);
446 gtk_widget_destroy (info->progress);
447 g_slice_free (ModestGetSupportedAuthInfo, info);
453 modest_utils_show_dialog_and_forget (GtkWindow *parent_window,
456 g_return_if_fail (GTK_IS_WINDOW(parent_window));
457 g_return_if_fail (GTK_IS_DIALOG(dialog));
459 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window);
461 /* Destroy the dialog when it is closed: */
462 g_signal_connect_swapped (dialog,
464 G_CALLBACK (gtk_widget_destroy),
467 gtk_widget_show (GTK_WIDGET (dialog));
471 modest_utils_toggle_action_set_active_block_notify (GtkToggleAction *action, gboolean value)
473 GSList *proxies = NULL;
475 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
477 for (proxies = gtk_action_get_proxies (GTK_ACTION (action));
478 proxies != NULL; proxies = g_slist_next (proxies)) {
479 GtkWidget *widget = (GtkWidget *) proxies->data;
480 gtk_action_block_activate_from (GTK_ACTION (action), widget);
483 gtk_toggle_action_set_active (action, value);
485 for (proxies = gtk_action_get_proxies (GTK_ACTION (action));
486 proxies != NULL; proxies = g_slist_next (proxies)) {
487 GtkWidget *widget = (GtkWidget *) proxies->data;
488 gtk_action_unblock_activate_from (GTK_ACTION (action), widget);
495 modest_list_index (TnyList *list, GObject *object)
500 g_return_val_if_fail (TNY_IS_LIST(list), -1);
501 g_return_val_if_fail (G_IS_OBJECT(object), -1);
503 iter = tny_list_create_iterator (list);
504 while (!tny_iterator_is_done (iter)) {
505 GObject *current = tny_iterator_get_current (iter);
507 g_object_unref (current);
508 if (current == object)
511 tny_iterator_next (iter);
515 if (tny_iterator_is_done (iter))
517 g_object_unref (iter);
522 modest_utils_get_available_space (const gchar *maildir_path)
527 GnomeVFSFileSize size;
529 folder = modest_local_folder_info_get_maildir_path (maildir_path);
530 uri_string = gnome_vfs_get_uri_from_local_path (folder);
531 uri = gnome_vfs_uri_new (uri_string);
536 if (gnome_vfs_get_volume_free_space (uri, &size) != GNOME_VFS_OK)
538 gnome_vfs_uri_unref (uri);
543 return (guint64) size;
546 on_destroy_dialog (GtkDialog *dialog)
548 gtk_widget_destroy (GTK_WIDGET(dialog));
549 if (gtk_events_pending ())
550 gtk_main_iteration ();
554 checked_modest_sort_criterium_view_add_sort_key (ModestSortCriteriumView *view, const gchar* key, guint max)
558 g_return_val_if_fail (view && MODEST_IS_SORT_CRITERIUM_VIEW(view), 0);
559 g_return_val_if_fail (key, 0);
561 sort_key = modest_sort_criterium_view_add_sort_key (view, key);
562 if (sort_key < 0 || sort_key >= max) {
563 g_warning ("%s: out of range (%d) for %s", __FUNCTION__, sort_key, key);
566 return (guint)sort_key;
570 launch_sort_headers_dialog (GtkWindow *parent_window,
573 ModestHeaderView *header_view = NULL;
575 GtkSortType sort_type;
577 gint default_key = 0;
579 gboolean outgoing = FALSE;
580 gint current_sort_colid = -1;
581 GtkSortType current_sort_type;
582 gint attachments_sort_id;
583 gint priority_sort_id;
584 GtkTreeSortable *sortable;
586 /* Get header window */
587 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
588 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_window),
589 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
594 /* Add sorting keys */
595 cols = modest_header_view_get_columns (header_view);
598 #define SORT_ID_NUM 6
599 int sort_model_ids[SORT_ID_NUM];
600 int sort_ids[SORT_ID_NUM];
602 outgoing = (GPOINTER_TO_INT (g_object_get_data(G_OBJECT(cols->data), MODEST_HEADER_VIEW_COLUMN))==
603 MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT);
605 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_sender_recipient"),
608 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_TO_COLUMN;
609 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT;
611 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN;
612 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN;
615 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_date"),
618 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_TIME_T_COLUMN;
619 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_SENT_DATE;
621 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_DATE_RECEIVED_TIME_T_COLUMN;
622 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_RECEIVED_DATE;
624 default_key = sort_key;
626 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_subject"),
628 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_SUBJECT_COLUMN;
630 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT;
632 sort_ids[sort_key] = MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN;
634 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_attachment"),
636 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN;
637 sort_ids[sort_key] = TNY_HEADER_FLAG_ATTACHMENTS;
638 attachments_sort_id = sort_key;
640 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_size"),
642 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN;
643 sort_ids[sort_key] = 0;
645 sort_key = checked_modest_sort_criterium_view_add_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), _("mcen_li_sort_priority"),
647 sort_model_ids[sort_key] = TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN;
648 sort_ids[sort_key] = TNY_HEADER_FLAG_PRIORITY_MASK;
649 priority_sort_id = sort_key;
651 sortable = GTK_TREE_SORTABLE (gtk_tree_model_filter_get_model
652 (GTK_TREE_MODEL_FILTER (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)))));
654 if (!gtk_tree_sortable_get_sort_column_id (sortable,
655 ¤t_sort_colid, ¤t_sort_type)) {
656 modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), default_key);
657 modest_sort_criterium_view_set_sort_order (MODEST_SORT_CRITERIUM_VIEW (dialog), GTK_SORT_DESCENDING);
659 modest_sort_criterium_view_set_sort_order (MODEST_SORT_CRITERIUM_VIEW (dialog), current_sort_type);
660 if (current_sort_colid == TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN) {
661 gpointer flags_sort_type_pointer;
662 flags_sort_type_pointer = g_object_get_data (G_OBJECT (cols->data), MODEST_HEADER_VIEW_FLAG_SORT);
663 if (GPOINTER_TO_INT (flags_sort_type_pointer) == TNY_HEADER_FLAG_PRIORITY_MASK)
664 modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), priority_sort_id);
666 modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), attachments_sort_id);
668 gint current_sort_keyid = 0;
669 while (current_sort_keyid < SORT_ID_NUM) {
670 if (sort_model_ids[current_sort_keyid] == current_sort_colid)
673 current_sort_keyid++;
675 modest_sort_criterium_view_set_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog), current_sort_keyid);
679 result = gtk_dialog_run (GTK_DIALOG (dialog));
680 if (result == GTK_RESPONSE_OK) {
681 sort_key = modest_sort_criterium_view_get_sort_key (MODEST_SORT_CRITERIUM_VIEW (dialog));
682 if (sort_key < 0 || sort_key > SORT_ID_NUM -1) {
683 g_warning ("%s: out of range (%d)", __FUNCTION__, sort_key);
687 sort_type = modest_sort_criterium_view_get_sort_order (MODEST_SORT_CRITERIUM_VIEW (dialog));
688 if (sort_model_ids[sort_key] == TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN) {
689 g_object_set_data (G_OBJECT(cols->data), MODEST_HEADER_VIEW_FLAG_SORT,
690 GINT_TO_POINTER (sort_ids[sort_key]));
691 /* This is a hack to make it resort rows always when flag fields are
692 * selected. If we do not do this, changing sort field from priority to
693 * attachments does not work */
694 modest_header_view_sort_by_column_id (header_view, 0, sort_type);
696 gtk_tree_view_column_set_sort_column_id (GTK_TREE_VIEW_COLUMN (cols->data),
697 sort_model_ids[sort_key]);
700 modest_header_view_sort_by_column_id (header_view, sort_model_ids[sort_key], sort_type);
701 gtk_tree_sortable_sort_column_changed (sortable);
704 modest_widget_memory_save (modest_runtime_get_conf (),
705 G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY);
712 modest_utils_run_sort_dialog (GtkWindow *parent_window,
713 ModestSortDialogType type)
715 GtkWidget *dialog = NULL;
718 dialog = modest_platform_create_sort_dialog (parent_window);
721 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
722 GTK_WINDOW (dialog), parent_window);
726 case MODEST_SORT_HEADERS:
727 launch_sort_headers_dialog (parent_window,
733 on_destroy_dialog (GTK_DIALOG(dialog));
738 modest_images_cache_get_id (const gchar *account, const gchar *uri)
740 GnomeVFSURI *vfs_uri;
743 vfs_uri = gnome_vfs_uri_new (uri);
747 result = g_strdup_printf ("%s__%x", account, gnome_vfs_uri_hash (vfs_uri));
748 gnome_vfs_uri_unref (vfs_uri);
754 modest_utils_get_account_name_from_recipient (const gchar *from_header)
756 gchar *account_name = NULL;
757 ModestAccountMgr *mgr = NULL;
758 GSList *accounts = NULL, *node = NULL;
760 g_return_val_if_fail (from_header, NULL);
762 mgr = modest_runtime_get_account_mgr ();
763 accounts = modest_account_mgr_account_names (mgr, TRUE);
765 for (node = accounts; node != NULL; node = g_slist_next (node)) {
767 modest_account_mgr_get_from_string (mgr, node->data);
771 modest_text_utils_get_email_address (from);
772 gchar *from_header_email =
773 modest_text_utils_get_email_address (from_header);
775 if (from_email && from_header_email) {
776 if (!modest_text_utils_utf8_strcmp (from_header_email, from_email, TRUE)) {
777 account_name = g_strdup (node->data);
784 g_free (from_header_email);
788 g_slist_foreach (accounts, (GFunc) g_free, NULL);
789 g_slist_free (accounts);
795 modest_utils_on_entry_invalid_character (ModestValidatingEntry *self,
796 const gchar* character,
799 gchar *message = NULL;
800 const gchar *show_char = NULL;
803 show_char = character;
808 message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
809 modest_platform_information_banner (GTK_WIDGET (self), NULL, message);