1 /* Copyright (c) 2006, 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.
30 #include <libgnomevfs/gnome-vfs-mime.h>
31 #include <libgnomeui/gnome-icon-lookup.h>
32 #include <tny-gnome-device.h>
33 #include <tny-camel-imap-store-account.h>
34 #include <tny-camel-pop-store-account.h>
35 #include <tny-simple-list.h>
36 #include "modest-platform.h"
37 #include "modest-mail-operation-queue.h"
38 #include "modest-runtime.h"
39 #include "gnome/modest-gnome-global-settings-dialog.h"
40 #include "widgets/modest-default-account-settings-dialog.h"
41 #include "gnome/modest-account-assistant.h"
42 #include "gnome/modest-gnome-sort-dialog.h"
43 #include "widgets/modest-details-dialog.h"
44 #include "widgets/modest-main-window.h"
47 modest_platform_init (int argc, char *argv[])
49 return TRUE; /* nothing to do */
53 gboolean modest_platform_uninit (void)
55 return TRUE; /*nothing to do */
60 modest_platform_get_new_device (void)
62 return TNY_DEVICE (tny_gnome_device_new ());
67 modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
68 gchar **effective_mime_type)
70 GString *mime_str = NULL;
71 gchar *icon_name = NULL;
73 const static gchar* octet_stream = "application/octet-stream";
75 g_return_val_if_fail (name || mime_type, NULL);
77 if (!mime_type || g_ascii_strcasecmp (mime_type, octet_stream))
78 mime_str = g_string_new(gnome_vfs_mime_type_from_name_or_default
79 (name, "application/octet-stream"));
81 mime_str = g_string_new (mime_type);
82 g_string_ascii_down (mime_str);
85 uri = g_strconcat ("file:///", name ? name : "dummy", NULL);
86 icon_name = gnome_icon_lookup (gtk_icon_theme_get_default(), NULL,
87 uri, NULL, NULL, mime_str->str, 0, 0);
90 if (effective_mime_type)
91 *effective_mime_type = g_string_free (mime_str, FALSE);
93 g_string_free (mime_str, TRUE);
99 modest_platform_activate_uri (const gchar *uri)
101 g_message ("NOT IMPLEMENTED");;
106 modest_platform_activate_file (const gchar *path, const gchar *mime_type)
108 g_message ("NOT IMPLEMENTED");;
113 modest_platform_show_uri_popup (const gchar *uri)
115 g_message ("NOT IMPLEMENTED");;
120 modest_platform_get_icon (const gchar *name, guint icon_size)
125 g_return_val_if_fail (name, NULL);
127 pixbuf = gdk_pixbuf_new_from_file (name, &err);
130 /* g_printerr ("modest: error while loading icon '%s': %s\n", */
131 /* name, err->message); */
135 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), name, icon_size, 0, &err);
146 modest_platform_get_app_name (void)
152 modest_platform_run_new_folder_dialog (GtkWindow *parent_window,
153 TnyFolderStore *suggested_parent,
154 gchar *suggested_name,
156 TnyFolderStore **parent_folder)
158 GtkWidget *dialog, *entry;
161 /* Ask the user for the folder name */
162 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
170 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
171 gtk_label_new (_("Please enter a name for the new folder")),
174 entry = gtk_entry_new_with_max_length (40);
175 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
179 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
181 result = gtk_dialog_run (GTK_DIALOG(dialog));
182 if (result == GTK_RESPONSE_ACCEPT)
183 *folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
185 gtk_widget_destroy (dialog);
187 if (parent_folder != NULL) {
188 parent_folder = suggested_parent?g_object_ref (suggested_parent): NULL;
196 modest_platform_run_confirmation_dialog (GtkWindow *parent_window,
202 dialog = gtk_message_dialog_new (parent_window,
204 GTK_MESSAGE_QUESTION,
205 GTK_BUTTONS_OK_CANCEL,
208 response = gtk_dialog_run (GTK_DIALOG(dialog));
209 gtk_widget_destroy (dialog);
215 modest_platform_run_confirmation_dialog_with_buttons (GtkWindow *parent_window,
216 const gchar *message,
217 const gchar *button_accept,
218 const gchar *button_cancel)
223 dialog = gtk_dialog_new_with_buttons (message,
225 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
232 response = gtk_dialog_run (GTK_DIALOG(dialog));
233 gtk_widget_destroy (dialog);
239 modest_platform_run_information_dialog (GtkWindow *parent_window,
240 const gchar *message,
245 dialog = gtk_message_dialog_new (parent_window,
251 gtk_dialog_run (GTK_DIALOG (dialog));
252 gtk_widget_destroy (dialog);
256 gboolean modest_platform_connect_and_wait (GtkWindow *parent_window, TnyAccount *account)
258 /* TODO: Do something with network-manager?
259 Otherwise, maybe it is safe to assume that we would already be online if we could be. */
263 gboolean modest_platform_connect_and_wait_if_network_account (GtkWindow *parent_window, TnyAccount *account)
265 /* TODO: Do something with network-manager?
266 Otherwise, maybe it is safe to assume that we would already be online if we could be. */
272 modest_platform_connect_if_remote_and_perform (GtkWindow *parent_window,
274 TnyFolderStore *folder_store,
275 ModestConnectedPerformer callback,
278 TnyAccount *account = NULL;
281 /* We promise to instantly perform the callback, so ... */
283 callback (FALSE, NULL, parent_window, NULL, user_data);
287 /* Original comment: Maybe it is something local. */
288 /* PVH's comment: maybe we should KNOW this in stead of assuming? */
290 } else if (TNY_IS_FOLDER (folder_store)) {
291 /* Get the folder's parent account: */
292 account = tny_folder_get_account(TNY_FOLDER (folder_store));
293 } else if (TNY_IS_ACCOUNT (folder_store)) {
294 /* Use the folder store as an account: */
295 account = TNY_ACCOUNT (folder_store);
298 if (tny_account_get_account_type (account) == TNY_ACCOUNT_TYPE_STORE) {
299 if (!TNY_IS_CAMEL_POP_STORE_ACCOUNT (account) &&
300 !TNY_IS_CAMEL_IMAP_STORE_ACCOUNT (account)) {
302 /* This IS a local account like a maildir account, which does not require
303 * a connection. (original comment had a vague assumption in its language
304 * usage. There's no assuming needed, this IS what it IS: a local account), */
306 /* We promise to instantly perform the callback, so ... */
308 callback (FALSE, NULL, parent_window, account, user_data);
315 modest_platform_connect_and_perform (parent_window, force, account, callback, user_data);
321 gboolean modest_platform_set_update_interval (guint minutes)
328 modest_platform_create_sort_dialog (GtkWindow *parent_window)
330 return modest_gnome_sort_dialog_new (parent_window);
334 modest_platform_get_global_settings_dialog ()
336 return modest_gnome_global_settings_dialog_new ();
340 modest_platform_push_email_notification(void)
342 /* TODO: implement this */
343 g_print ("--------------- NEW MESSAGE ARRIVED ---------------\n");
347 modest_platform_on_new_headers_received (TnyList *header_list,
348 gboolean show_visual)
350 /* TODO: implement this */
351 g_print ("--------------- NEW MESSAGE ARRIVED ---------------\n");
357 modest_platform_show_help (GtkWindow *parent_window, const gchar *help_id)
363 modest_platform_information_banner (GtkWidget *widget,
364 const gchar *icon_name,
367 g_message ("NOT IMPLEMENTED");;
371 modest_platform_information_banner_with_timeout (GtkWidget *widget,
372 const gchar *icon_name,
376 g_message ("NOT IMPLEMENTED");;
380 modest_platform_animation_banner (GtkWidget *widget,
381 const gchar *icon_name,
384 g_message ("NOT IMPLEMENTED");
390 modest_platform_show_search_messages (GtkWindow *parent_window)
392 g_message ("NOT IMPLEMENTED");;
396 modest_platform_create_folder_view (TnyFolderStoreQuery *query)
398 GtkWidget *widget = modest_folder_view_new (query);
400 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (widget), FALSE);
401 /* Show all accounts by default */
402 modest_folder_view_set_style (MODEST_FOLDER_VIEW (widget),
403 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
409 modest_platform_run_alert_dialog (const gchar* prompt,
410 gboolean is_question)
417 modest_platform_connect_and_perform (GtkWindow *parent_window,
420 ModestConnectedPerformer callback,
424 callback (FALSE, NULL, parent_window, account, user_data);
428 modest_platform_double_connect_and_perform (GtkWindow *parent_window,
430 TnyFolderStore *folder_store,
431 DoubleConnectionInfo *connect_info)
433 if (connect_info->callback)
434 connect_info->callback (FALSE, NULL, parent_window, TNY_ACCOUNT (folder_store), connect_info->data);
438 modest_platform_connect_and_perform_if_network_account (GtkWindow *parent_window,
441 ModestConnectedPerformer callback,
445 callback (FALSE, NULL, parent_window, account, user_data);
449 modest_platform_connect_and_perform_if_network_folderstore (GtkWindow *parent_window,
450 TnyFolderStore *folder_store,
451 ModestConnectedPerformer callback,
455 callback (FALSE, NULL, parent_window, NULL, user_data);
460 modest_platform_remove_new_mail_notifications (gboolean only_visuals)
462 g_message ("NOT IMPLEMENTED %s", __FUNCTION__);
466 modest_platform_check_and_wait_for_account_is_online(TnyAccount *account)
468 g_message ("NOT IMPLEMENTED %s", __FUNCTION__);
473 modest_platform_run_certificate_confirmation_dialog (const gchar* server_name,
474 const gchar *certificate)
476 g_message ("NOT IMPLEMENTED %s", __FUNCTION__);
481 modest_platform_run_rename_folder_dialog (GtkWindow *parent_window,
482 TnyFolderStore *parent_folder,
483 const gchar *suggested_name,
486 g_message ("NOT IMPLEMENTED %s", __FUNCTION__);
487 return GTK_RESPONSE_CANCEL;
491 modest_platform_show_addressbook (GtkWindow *parent_window)
493 g_message ("NOT IMPLEMENTED %s", __FUNCTION__);
497 modest_platform_get_account_settings_dialog (ModestAccountSettings *settings)
499 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
501 modest_account_settings_dialog_load_settings (dialog, settings);
502 return GTK_WIDGET (dialog);
506 modest_platform_get_account_settings_wizard (void)
508 GtkWidget *widget = modest_account_assistant_new (modest_runtime_get_account_mgr ());
514 gboolean modest_platform_check_memory_low (ModestWindow *win,
517 g_debug ("%s not implemented", __FUNCTION__);
522 modest_platform_run_folder_details_dialog (GtkWindow *parent_window,
528 dialog = modest_details_dialog_new_with_folder (parent_window, folder);
531 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
534 gtk_widget_show_all (dialog);
536 g_signal_connect_swapped (dialog, "response",
537 G_CALLBACK (gtk_widget_destroy),
542 modest_platform_run_header_details_dialog (GtkWindow *parent_window,
548 dialog = modest_details_dialog_new_with_header (parent_window, header);
551 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
554 gtk_widget_show_all (dialog);
556 g_signal_connect_swapped (dialog, "response",
557 G_CALLBACK (gtk_widget_destroy),
562 modest_platform_create_move_to_dialog (GtkWindow *parent_window,
563 GtkWidget **folder_view)
565 GtkWidget *dialog, *folder_view_container;
567 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
568 GTK_WINDOW (parent_window),
569 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR |
570 GTK_DIALOG_DESTROY_WITH_PARENT,
571 _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK,
572 _("mcen_bd_new"), MODEST_GTK_RESPONSE_NEW_FOLDER,
573 _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL,
576 /* Create folder view */
577 *folder_view = modest_platform_create_folder_view (NULL);
579 /* Create pannable and add it to the dialog */
580 folder_view_container = gtk_scrolled_window_new (NULL, NULL);
581 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (folder_view_container),
582 GTK_POLICY_AUTOMATIC,
583 GTK_POLICY_AUTOMATIC);
584 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), folder_view_container);
585 gtk_container_add (GTK_CONTAINER (folder_view_container), *folder_view);
587 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
593 modest_platform_get_list_to_move (ModestWindow *window)
595 TnyList *list = NULL;
597 /* If it's a main window then it could be that we're moving a
598 folder or a set of messages */
599 if (MODEST_IS_MAIN_WINDOW (window)) {
600 ModestHeaderView *header_view = NULL;
601 ModestFolderView *folder_view = NULL;
603 folder_view = (ModestFolderView *)
604 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
605 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
606 header_view = (ModestHeaderView *)
607 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
608 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
610 /* Get folder or messages to transfer */
611 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
612 TnyFolderStore *src_folder;
614 src_folder = modest_folder_view_get_selected (folder_view);
616 list = tny_simple_list_new ();
617 tny_list_prepend (list, G_OBJECT (src_folder));
618 g_object_unref (src_folder);
620 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
621 list = modest_header_view_get_selected_headers(header_view);
623 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
624 TnyHeader *header = NULL;
626 /* We simply return the currently viewed message */
627 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (window));
629 list = tny_simple_list_new ();
630 tny_list_prepend (list, G_OBJECT (header));
631 g_object_unref (header);
634 g_return_val_if_reached (NULL);