X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fgtk%2Fmodest-platform.c;h=a1a9361fb24dd561bb93d00b2aca4a8e2348b612;hp=f492eb61a81956f7cc45be850dd7e253093ecd4f;hb=HEAD;hpb=50571176a5fd878e78793a6644ca178d55ce1238 diff --git a/src/gtk/modest-platform.c b/src/gtk/modest-platform.c index f492eb6..a1a9361 100644 --- a/src/gtk/modest-platform.c +++ b/src/gtk/modest-platform.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include "modest-widget-memory.h" #include @@ -63,8 +62,13 @@ #include #include #include +#include #include #include "widgets/modest-toolkit-utils.h" +#include "widgets/modest-msg-view-window.h" +#include +#include +#include #define HILDON_OSSO_URI_ACTION "uri-action" #define URI_ACTION_COPY "copy:" @@ -174,11 +178,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; - } @@ -186,18 +219,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 @@ -242,7 +313,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 */ @@ -250,7 +321,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); @@ -258,7 +329,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, @@ -289,7 +360,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)); @@ -341,7 +412,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); @@ -375,10 +446,17 @@ folder_chooser_dialog_run (ModestFolderView *original, const gchar *visible_id = NULL; userdata.dialog = gtk_dialog_new (); + + gtk_widget_set_size_request (GTK_WIDGET (userdata.dialog), + MODEST_DIALOG_WINDOW_MAX_WIDTH, + MODEST_DIALOG_WINDOW_MAX_HEIGHT); + + gtk_dialog_add_button (GTK_DIALOG (userdata.dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); + 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)); @@ -551,7 +629,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; @@ -566,7 +644,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, @@ -699,7 +777,9 @@ 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"), + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + _FM_NEW_FOLDER_DIALOG_OK, GTK_RESPONSE_ACCEPT, NULL); @@ -720,16 +800,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); @@ -857,8 +937,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, @@ -879,12 +959,15 @@ modest_platform_run_rename_folder_dialog (ModestWindow *parent_window, const gchar *suggested_name, gchar **folder_name) { + GtkWindow *toplevel; + g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent_folder), GTK_RESPONSE_REJECT); - return modest_platform_run_folder_common_dialog (gtk_widget_get_toplevel (GTK_WIDGET (parent_window)), + toplevel = (GtkWindow *) gtk_widget_get_toplevel (GTK_WIDGET (parent_window)); + return modest_platform_run_folder_common_dialog (toplevel, parent_folder, - _HL("ckdg_ti_rename_folder"), - _HL("ckdg_fi_rename_name"), + _HL_TITLE_RENAME_FOLDER, + _HL_RENAME_NAME, suggested_name, TRUE, FALSE, @@ -1070,10 +1153,75 @@ modest_platform_create_sort_dialog (GtkWindow *parent_window) } +static guint timeout_handler_id = 0; +static gboolean weak_ref_enabled = FALSE; + +static void +shell_weak_ref (gpointer data, + GObject *was) +{ + if (timeout_handler_id > 0) { + g_source_remove (timeout_handler_id); + timeout_handler_id = 0; + } +} + +static gboolean +update_timeout_handler (gpointer userdata) +{ + gboolean auto_update; + gboolean right_connection = FALSE; + + /* Check if the autoupdate feature is on */ + auto_update = modest_conf_get_bool (modest_runtime_get_conf (), + MODEST_CONF_AUTO_UPDATE, NULL); + + if (auto_update) { + gint connect_when; + /* Do send receive. Never set the current top window + as we always assume that DBus send/receive requests + are not user driven */ + + connect_when = modest_conf_get_int (modest_runtime_get_conf (), + MODEST_CONF_UPDATE_WHEN_CONNECTED_BY, NULL); + /* Perform a send and receive if the user selected to connect + via any mean or if the current connection method is the + same as the one specified by the user */ + if (connect_when == MODEST_CONNECTED_VIA_ANY || + connect_when == modest_platform_get_current_connection ()) { + right_connection = TRUE; + } + } else { + /* Disable auto update */ + modest_platform_set_update_interval (0); + } + + if (auto_update && right_connection) { + modest_ui_actions_do_send_receive_all (NULL, FALSE, FALSE, FALSE); + } + + return TRUE; +} + gboolean modest_platform_set_update_interval (guint minutes) { + if (!weak_ref_enabled) { + ModestWindowMgr *mgr; + GtkWidget *shell; + mgr = modest_runtime_get_window_mgr (); + shell = modest_gtk_window_mgr_get_shell (MODEST_GTK_WINDOW_MGR (mgr)); + g_object_weak_ref ((GObject *) shell, shell_weak_ref, NULL); + weak_ref_enabled = TRUE; + } + if (timeout_handler_id > 0) { + g_source_remove (timeout_handler_id); + timeout_handler_id = 0; + } + if (minutes > 0) + timeout_handler_id = g_timeout_add_seconds (minutes*60, update_timeout_handler, NULL); + return TRUE; } @@ -1091,7 +1239,7 @@ modest_platform_on_new_headers_received (GList *URI_list, } void -modest_platform_remove_new_mail_notifications (gboolean only_visuals) +modest_platform_remove_new_mail_notifications (gboolean only_visuals, const gchar *acc_name) { return; } @@ -1101,7 +1249,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 @@ -1154,6 +1302,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; } @@ -1162,7 +1316,7 @@ modest_platform_system_banner (GtkWidget *parent, const gchar *icon_name, const gchar *text) { - return; + modest_platform_information_banner (parent, icon_name, text); } void @@ -1171,6 +1325,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; } @@ -1179,7 +1339,13 @@ modest_platform_animation_banner (GtkWidget *parent, const gchar *animation_name, const gchar *text) { - return NULL; + 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 @@ -1326,9 +1492,9 @@ 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); g_signal_connect (G_OBJECT(note), "response", @@ -1374,7 +1540,7 @@ modest_platform_run_alert_dialog (const gchar* prompt, /***************/ typedef struct { - GtkWindow *parent_window; + ModestWindow *parent_window; ModestConnectedPerformer callback; TnyAccount *account; gpointer user_data; @@ -1423,7 +1589,7 @@ on_account_went_online (TnyCamelAccount *account, gboolean canceled, GError *err } void -modest_platform_connect_and_perform (GtkWindow *parent_window, +modest_platform_connect_and_perform (ModestWindow *parent_window, gboolean force, TnyAccount *account, ModestConnectedPerformer callback, @@ -1482,7 +1648,7 @@ modest_platform_connect_and_perform (GtkWindow *parent_window, info->account = TNY_ACCOUNT (g_object_ref (account)); if (parent_window) - info->parent_window = (GtkWindow *) g_object_ref (parent_window); + info->parent_window = (ModestWindow *) g_object_ref (parent_window); else info->parent_window = NULL; @@ -1500,7 +1666,7 @@ modest_platform_connect_and_perform (GtkWindow *parent_window, } void -modest_platform_connect_if_remote_and_perform (GtkWindow *parent_window, +modest_platform_connect_if_remote_and_perform (ModestWindow *parent_window, gboolean force, TnyFolderStore *folder_store, ModestConnectedPerformer callback, @@ -1549,7 +1715,7 @@ modest_platform_connect_if_remote_and_perform (GtkWindow *parent_window, static void src_account_connect_performer (gboolean canceled, GError *err, - GtkWindow *parent_window, + ModestWindow *parent_window, TnyAccount *src_account, gpointer user_data) { @@ -1572,12 +1738,12 @@ src_account_connect_performer (gboolean canceled, void -modest_platform_double_connect_and_perform (GtkWindow *parent_window, +modest_platform_double_connect_and_perform (ModestWindow *parent_window, gboolean force, TnyFolderStore *folder_store, DoubleConnectionInfo *connect_info) { - modest_platform_connect_if_remote_and_perform(parent_window, + modest_platform_connect_if_remote_and_perform(parent_window, force, folder_store, src_account_connect_performer, @@ -2075,7 +2241,9 @@ 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"), + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + _FM_CHANGE_FOLDER_NEW_FOLDER, MODEST_GTK_RESPONSE_NEW_FOLDER, NULL); @@ -2097,7 +2265,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); @@ -2198,3 +2366,29 @@ modest_platform_get_list_to_move (ModestWindow *window) return list; } + +void +modest_platform_emit_folder_updated_signal (const gchar *account_id, const gchar *folder_id) +{ + return; +} + + +void +modest_platform_emit_account_created_signal (const gchar *account_id) +{ + return; +} + +void +modest_platform_emit_account_removed_signal (const gchar *account_id) +{ + return; +} + +void +modest_platform_emit_msg_read_changed_signal (const gchar *msg_uid, + gboolean is_read) +{ + return; +}