X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fgtk%2Fmodest-platform.c;h=848ceecf8d6165dd90a33586eee78296c62f8d02;hb=0322239e8fd08ce70d12c09b6c2328e20e665c8c;hp=b82bf74e9504b70322639a954aa89855f930e741;hpb=7db85dbe0a847a94f4686ad299a36a9d55747230;p=modest diff --git a/src/gtk/modest-platform.c b/src/gtk/modest-platform.c index b82bf74..848ceec 100644 --- a/src/gtk/modest-platform.c +++ b/src/gtk/modest-platform.c @@ -62,8 +62,11 @@ #include #include #include +#include +#include #include - +#include "widgets/modest-toolkit-utils.h" +#include #define HILDON_OSSO_URI_ACTION "uri-action" #define URI_ACTION_COPY "copy:" @@ -75,12 +78,6 @@ #define FOLDER_PICKER_CURRENT_FOLDER "current-folder" #define FOLDER_PICKER_ORIGINAL_ACCOUNT "original-account" -static gboolean ca_con_opened = FALSE; - - -static void modest_platform_play_email_tone (void); - - static void on_modest_conf_update_interval_changed (ModestConf* self, const gchar *key, @@ -102,6 +99,7 @@ on_modest_conf_update_interval_changed (ModestConf* self, static gboolean check_required_files (void) { +#if 0 FILE *mcc_file = modest_utils_open_mcc_mapping_file (); if (!mcc_file) { @@ -116,7 +114,7 @@ check_required_files (void) g_printerr ("modest: cannot find providers data\n"); return FALSE; } - +#endif return TRUE; } @@ -178,11 +176,40 @@ gchar* modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type, gchar **effective_mime_type) { + gchar *icon_name = NULL; + gchar *content_type; + GIcon *icon; + gchar **icon_names, **cursor; + + if (!mime_type || g_ascii_strcasecmp (mime_type, "application/octet-stream") == 0) + content_type = g_content_type_guess (name, NULL, 0, NULL); + else { + content_type = g_content_type_from_mime_type (mime_type); + } - g_warning ("Not implemented %s", __FUNCTION__); + if (!content_type) { + content_type = g_content_type_from_mime_type ("application/octet-stream"); + } + icon = g_content_type_get_icon (content_type); + if (!G_THEMED_ICON (icon)) + return NULL; + + g_object_get (G_OBJECT (icon), "names", &icon_names, NULL); + + for (cursor = icon_names; cursor; ++cursor) { + if (!g_ascii_strcasecmp (*cursor, "gnome-mime-message") || + !g_ascii_strcasecmp (*cursor, "gnome-mime-message-rfc822")) { + icon_name = g_strdup ("stock_message-display"); + break; + } else if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default(), *cursor)) { + icon_name = g_strdup (*cursor); + break; + } + } + g_strfreev (icon_names); + + return icon_name; - return NULL; - } @@ -190,18 +217,56 @@ modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type, gboolean modest_platform_activate_uri (const gchar *uri) { - g_warning ("Not implemented %s", __FUNCTION__); + GAppLaunchContext *al_context; + gboolean retval; - return FALSE; + al_context = gdk_app_launch_context_new (); + retval = g_app_info_launch_default_for_uri (uri, al_context, NULL); + g_object_unref (al_context); + + return retval; } gboolean modest_platform_activate_file (const gchar *path, const gchar *mime_type) { - g_warning ("Not implemented %s", __FUNCTION__); + gchar *content_type; + gboolean retval; + GAppInfo *app_info; + GList *list; + GFile *file; + GAppLaunchContext *al_context; - return FALSE; + content_type = g_content_type_from_mime_type (mime_type); + if (!content_type) + return FALSE; + + app_info = g_app_info_get_default_for_type (content_type, FALSE); + g_free (content_type); + if (!app_info) { + content_type = g_content_type_guess (path, NULL, 0, NULL); + if (!content_type) + return FALSE; + + app_info = g_app_info_get_default_for_type (content_type, FALSE); + g_free (content_type); + + if (!app_info) + return FALSE; + + } + + file = g_file_new_for_path (path); + list = g_list_prepend (NULL, file); + al_context = gdk_app_launch_context_new (); + retval = g_app_info_launch (app_info, list, al_context, NULL); + g_object_unref (al_context); + + g_list_free (list); + g_object_unref (file); + + return retval; } gboolean @@ -216,9 +281,11 @@ modest_platform_show_uri_popup (const gchar *uri) GdkPixbuf* modest_platform_get_icon (const gchar *name, guint icon_size) { - g_warning ("Not implemented %s", __FUNCTION__); - - return NULL; + return gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + name, + icon_size, + 0, + NULL); } const gchar* @@ -244,7 +311,7 @@ entry_insert_text (GtkEditable *editable, /* Show WID-INF036 */ if (chars_length >= 20) { modest_platform_information_banner (gtk_widget_get_parent (GTK_WIDGET (data)), NULL, - _CS("ckdg_ib_maximum_characters_reached")); + _CS_MAXIMUM_CHARACTERS_REACHED); } else { if (modest_text_utils_is_forbidden_char (*text, FOLDER_NAME_FORBIDDEN_CHARS)) { /* Show an error */ @@ -252,7 +319,7 @@ entry_insert_text (GtkEditable *editable, tmp = g_strndup (folder_name_forbidden_chars, FOLDER_NAME_FORBIDDEN_CHARS_LENGTH); - msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp); + msg = g_strdup_printf (_CS_ILLEGAL_CHARACTERS_ENTERED, tmp); modest_platform_information_banner (gtk_widget_get_parent (GTK_WIDGET (data)), NULL, msg); g_free (msg); @@ -260,7 +327,7 @@ entry_insert_text (GtkEditable *editable, } else { if (length >= 20) { modest_platform_information_banner (gtk_widget_get_parent (GTK_WIDGET (data)), NULL, - _CS("ckdg_ib_maximum_characters_reached")); + _CS_MAXIMUM_CHARACTERS_REACHED); } /* Write the text in the entry if it's valid */ g_signal_handlers_block_by_func (editable, @@ -291,7 +358,7 @@ entry_changed (GtkEditable *editable, if (g_utf8_strlen (chars,-1) >= 20) { modest_platform_information_banner (gtk_widget_get_parent (GTK_WIDGET (user_data)), NULL, - _CS("ckdg_ib_maximum_characters_reached")); + _CS_MAXIMUM_CHARACTERS_REACHED); } gtk_widget_set_sensitive (ok_button, modest_text_utils_validate_folder_name(chars)); @@ -343,7 +410,7 @@ on_response (GtkDialog *dialog, if (exists) { /* Show an error */ modest_platform_information_banner (gtk_widget_get_parent (GTK_WIDGET (dialog)), - NULL, _CS("ckdg_ib_folder_already_exists")); + NULL, _CS_FOLDER_ALREADY_EXISTS); /* Select the text */ gtk_entry_select_region (GTK_ENTRY (entry), 0, -1); gtk_widget_grab_focus (entry); @@ -380,7 +447,7 @@ folder_chooser_dialog_run (ModestFolderView *original, scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ()); folder_view = modest_platform_create_folder_view (NULL); - gtk_window_set_title (GTK_WINDOW (userdata.dialog), _FM("ckdg_ti_change_folder")); + gtk_window_set_title (GTK_WINDOW (userdata.dialog), _FM_CHANGE_FOLDER); modest_folder_view_copy_model (MODEST_FOLDER_VIEW (original), MODEST_FOLDER_VIEW (folder_view)); @@ -553,7 +620,7 @@ static gchar * get_next_folder_name (const gchar *suggested_name, TnyFolderStore *suggested_folder) { - const gchar *default_name = _FM("ckdg_va_new_folder_name_stub"); + const gchar *default_name = _FM_NEW_FOLDER_NAME_STUB; unsigned int i; gchar *real_suggested_name; @@ -568,7 +635,7 @@ get_next_folder_name (const gchar *suggested_name, real_suggested_name = g_strdup (default_name); else real_suggested_name = g_strdup_printf ("%s(%d)", - _FM("ckdg_va_new_folder_name_stub"), + _FM_NEW_FOLDER_NAME_STUB, i); exists = modest_tny_folder_has_subfolder_with_name (suggested_folder, real_suggested_name, @@ -701,7 +768,7 @@ modest_platform_run_folder_common_dialog (GtkWindow *parent_window, dialog = gtk_dialog_new_with_buttons (dialog_title, parent_window, GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT, - _FM("ckdg_bd_new_folder_dialog_ok"), + _FM_NEW_FOLDER_DIALOG_OK, GTK_RESPONSE_ACCEPT, NULL); @@ -722,16 +789,16 @@ modest_platform_run_folder_common_dialog (GtkWindow *parent_window, if (suggested_name) gtk_entry_set_text (GTK_ENTRY (entry), suggested_name); else - gtk_entry_set_text (GTK_ENTRY (entry), _FM("ckdg_va_new_folder_name_stub")); + gtk_entry_set_text (GTK_ENTRY (entry), _FM_NEW_FOLDER_NAME_STUB); gtk_entry_set_width_chars (GTK_ENTRY (entry), MAX (g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (entry)), -1), - g_utf8_strlen (_FM("ckdg_va_new_folder_name_stub"), -1))); + g_utf8_strlen (_FM_NEW_FOLDER_NAME_STUB, -1))); gtk_entry_select_region (GTK_ENTRY (entry), 0, -1); } if (show_parent) { - label_location = gtk_label_new (_FM("ckdg_fi_new_folder_location")); + label_location = gtk_label_new (_FM_NEW_FOLDER_LOCATION); gtk_misc_set_alignment (GTK_MISC (label_location), 0.0, 0.5); gtk_size_group_add_widget (sizegroup, label_location); @@ -859,8 +926,8 @@ modest_platform_run_new_folder_dialog (GtkWindow *parent_window, result = modest_platform_run_folder_common_dialog (parent_window, suggested_folder, - _HL("ckdg_ti_new_folder"), - _FM("ckdg_fi_new_folder_name"), + _HL_TITLE_NEW_FOLDER, + _FM_NEW_FOLDER_NAME, real_suggested_name, TRUE, TRUE, @@ -876,17 +943,17 @@ modest_platform_run_new_folder_dialog (GtkWindow *parent_window, } gint -modest_platform_run_rename_folder_dialog (GtkWindow *parent_window, +modest_platform_run_rename_folder_dialog (ModestWindow *parent_window, TnyFolderStore *parent_folder, const gchar *suggested_name, gchar **folder_name) { g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent_folder), GTK_RESPONSE_REJECT); - return modest_platform_run_folder_common_dialog (parent_window, + return modest_platform_run_folder_common_dialog (gtk_widget_get_toplevel (GTK_WIDGET (parent_window)), parent_folder, - _HL("ckdg_ti_rename_folder"), - _HL("ckdg_fi_rename_name"), + _HL_TITLE_RENAME_FOLDER, + _HL_RENAME_NAME, suggested_name, TRUE, FALSE, @@ -997,57 +1064,10 @@ typedef struct _ConnectAndWaitData { } ConnectAndWaitData; -static void -quit_wait_loop (TnyAccount *account, - ConnectAndWaitData *data) -{ - /* Set the has_callback to TRUE (means that the callback was - executed and wake up every code waiting for cond to be - TRUE */ - g_mutex_lock (data->mutex); - data->has_callback = TRUE; - if (data->wait_loop) - g_main_loop_quit (data->wait_loop); - g_mutex_unlock (data->mutex); -} - -static void -on_connection_status_changed (TnyAccount *account, - TnyConnectionStatus status, - gpointer user_data) -{ - TnyConnectionStatus conn_status; - ConnectAndWaitData *data; - - /* Ignore if reconnecting or disconnected */ - conn_status = tny_account_get_connection_status (account); - if (conn_status == TNY_CONNECTION_STATUS_RECONNECTING || - conn_status == TNY_CONNECTION_STATUS_DISCONNECTED) - return; - - /* Remove the handler */ - data = (ConnectAndWaitData *) user_data; - g_signal_handler_disconnect (account, data->handler); - - /* Quit from wait loop */ - quit_wait_loop (account, (ConnectAndWaitData *) user_data); -} - -static void -on_tny_camel_account_set_online_cb (TnyCamelAccount *account, - gboolean canceled, - GError *err, - gpointer user_data) -{ - /* Quit from wait loop */ - quit_wait_loop (TNY_ACCOUNT (account), (ConnectAndWaitData *) user_data); -} - gboolean modest_platform_connect_and_wait (GtkWindow *parent_window, TnyAccount *account) { - ConnectAndWaitData *data = NULL; gboolean device_online; TnyDevice *device; TnyConnectionStatus conn_status; @@ -1150,7 +1170,7 @@ modest_platform_remove_new_mail_notifications (gboolean only_visuals) GtkWidget * modest_platform_get_global_settings_dialog () { - return NULL; + return modest_default_global_settings_dialog_new (); } void @@ -1203,6 +1223,12 @@ modest_platform_information_banner (GtkWidget *parent, const gchar *icon_name, const gchar *text) { + GtkWidget *banner; + + banner = modest_shell_banner_new (parent); + modest_shell_banner_set_icon (MODEST_SHELL_BANNER (banner), icon_name); + modest_shell_banner_set_text (MODEST_SHELL_BANNER (banner), text); + return; } @@ -1211,7 +1237,7 @@ modest_platform_system_banner (GtkWidget *parent, const gchar *icon_name, const gchar *text) { - return; + modest_platform_information_banner (parent, icon_name, text); } void @@ -1220,6 +1246,12 @@ modest_platform_information_banner_with_timeout (GtkWidget *parent, const gchar *text, gint timeout) { + GtkWidget *banner; + + banner = modest_shell_banner_new_with_timeout (parent, timeout); + modest_shell_banner_set_icon (MODEST_SHELL_BANNER (banner), icon_name); + modest_shell_banner_set_text (MODEST_SHELL_BANNER (banner), text); + return; } @@ -1228,7 +1260,13 @@ modest_platform_animation_banner (GtkWidget *parent, const gchar *animation_name, const gchar *text) { - return; + GtkWidget *banner; + + banner = modest_shell_banner_new_with_timeout (parent, 0); + modest_shell_banner_set_animation (MODEST_SHELL_BANNER (banner), animation_name); + modest_shell_banner_set_text (MODEST_SHELL_BANNER (banner), text); + + return banner; } typedef struct @@ -1342,16 +1380,13 @@ on_cert_dialog_response (GtkDialog *dialog, gint response_id, const gchar* cert { /* GTK_RESPONSE_HELP means we need to show the certificate */ if (response_id == GTK_RESPONSE_APPLY) { - GtkWidget *note; gchar *msg; /* Do not close the dialog */ g_signal_stop_emission_by_name (dialog, "response"); msg = g_strdup_printf (_("mcen_ni_view_unknown_certificate"), cert); - note = modest_platform_information_banner (NULL, NULL, msg); - gtk_dialog_run (GTK_DIALOG(note)); - gtk_widget_destroy (note); + modest_platform_run_information_dialog (NULL, msg, TRUE); } } @@ -1378,14 +1413,11 @@ modest_platform_run_certificate_confirmation_dialog (const gchar* server_name, GTK_BUTTONS_NONE, question); gtk_dialog_add_buttons (GTK_DIALOG (note), - _HL("wdgt_bd_yes"), GTK_RESPONSE_OK, - _HL("wdgt_bd_view"), GTK_RESPONSE_APPLY, /* abusing this... */ - _HL("wdgt_bd_no"), GTK_RESPONSE_CANCEL, + _HL_YES, GTK_RESPONSE_OK, + _HL_VIEW, GTK_RESPONSE_APPLY, /* abusing this... */ + _HL_NO, GTK_RESPONSE_CANCEL, NULL, NULL); - modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), - (GtkWindow *) note, (GtkWindow *) win); - g_signal_connect (G_OBJECT(note), "response", G_CALLBACK(on_cert_dialog_response), (gpointer) certificate); @@ -1405,6 +1437,7 @@ modest_platform_run_alert_dialog (const gchar* prompt, gboolean retval = TRUE; if (is_question) { + GtkWidget *dialog; /* The Tinymail documentation says that we should show Yes and No buttons, * when it is a question. * Obviously, we need tinymail to use more specific error codes instead, @@ -1420,7 +1453,7 @@ modest_platform_run_alert_dialog (const gchar* prompt, on_destroy_dialog (dialog); } else { /* Just show the error text and use the default response: */ - modest_platform_run_information_dialog (GTK_WINDOW (top_win), + modest_platform_run_information_dialog (NULL, prompt, FALSE); } return retval; @@ -1486,7 +1519,6 @@ modest_platform_connect_and_perform (GtkWindow *parent_window, gboolean device_online; TnyDevice *device; TnyConnectionStatus conn_status; - OnWentOnlineInfo *info; device = modest_runtime_get_device(); device_online = tny_device_is_online (device); @@ -1518,28 +1550,40 @@ modest_platform_connect_and_perform (GtkWindow *parent_window, conn_status = tny_account_get_connection_status (account); if (device_online && conn_status == TNY_CONNECTION_STATUS_CONNECTED) { - + /* We promise to instantly perform the callback, so ... */ if (callback) { callback (FALSE, NULL, parent_window, account, user_data); } - + return; } - - if (device_online) { - } else { - + + if (!device_online) { + OnWentOnlineInfo *info = NULL; + + info = g_slice_new0 (OnWentOnlineInfo); + + info->device = NULL; + info->iap = NULL; + info->account = TNY_ACCOUNT (g_object_ref (account)); + + if (parent_window) + info->parent_window = (GtkWindow *) g_object_ref (parent_window); + else + info->parent_window = NULL; + + /* So we'll put the callback away for later ... */ + info->user_data = user_data; + info->callback = callback; + /* If the device is online, we'll just connect the account */ - - tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (account), TRUE, + tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (account), TRUE, on_account_went_online, info); } - + /* The info gets freed by on_account_went_online or on_conic_device_went_online * in both situations, go look if you don't believe me! */ - - return; } void @@ -1667,7 +1711,8 @@ modest_platform_run_folder_details_dialog (GtkWindow *parent_window, GtkWidget *dialog; /* Create dialog */ - dialog = modest_hildon2_details_dialog_new_with_folder (parent_window, folder); + dialog = modest_toolkit_factory_create_details_dialog_with_folder (modest_runtime_get_toolkit_factory (), + parent_window, folder); /* Run dialog */ modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), @@ -1752,7 +1797,8 @@ modest_platform_run_header_details_dialog (GtkWindow *parent_window, GtkWidget *dialog; /* Create dialog */ - dialog = modest_hildon2_details_dialog_new_with_header (parent_window, header, !async_get_size); + dialog = modest_toolkit_factory_create_details_dialog_with_header (modest_runtime_get_toolkit_factory (), + parent_window, header, !async_get_size); if (async_get_size && msg && TNY_IS_MSG (msg)) { HeaderDetailsGetSizeInfo *info; @@ -1776,12 +1822,6 @@ modest_platform_run_header_details_dialog (GtkWindow *parent_window, dialog); } -static void -modest_platform_play_email_tone (void) -{ - return; -} - #define MOVE_TO_DIALOG_FOLDER_VIEW "folder-view" #define MOVE_TO_DIALOG_BACK_BUTTON "back-button" #define MOVE_TO_DIALOG_ACTION_BUTTON "action-button" @@ -2122,7 +2162,7 @@ modest_platform_create_move_to_dialog (GtkWindow *parent_window, GTK_WINDOW (parent_window), GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT, - _FM ("ckdg_bd_change_folder_new_folder"), + _FM_CHANGE_FOLDER_NEW_FOLDER, MODEST_GTK_RESPONSE_NEW_FOLDER, NULL); @@ -2144,7 +2184,7 @@ modest_platform_create_move_to_dialog (GtkWindow *parent_window, buttons_hbox = gtk_hbox_new (FALSE, MODEST_MARGIN_HALF); back_button = gtk_button_new (); - back_pixbuf = modest_platform_get_icon (_FM("filemanager_folder_up"), MODEST_ICON_SIZE_BIG); + back_pixbuf = modest_platform_get_icon (_FM_FOLDER_UP, MODEST_ICON_SIZE_BIG); if (back_pixbuf) { gtk_button_set_image (GTK_BUTTON (back_button), gtk_image_new_from_pixbuf (back_pixbuf)); g_object_unref (back_pixbuf);