Replaced modest_toolkit_utils_parent_window by gtk_widget_get_toplevel
[modest] / src / gtk / modest-platform.c
index b82bf74..f492eb6 100644 (file)
@@ -62,8 +62,9 @@
 #include <modest-ui-constants.h>
 #include <modest-icon-names.h>
 #include <modest-count-stream.h>
+#include <modest-gtk-details-dialog.h>
 #include <math.h>
-
+#include "widgets/modest-toolkit-utils.h"
 
 #define HILDON_OSSO_URI_ACTION "uri-action"
 #define URI_ACTION_COPY "copy:"
 #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 +97,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 +112,7 @@ check_required_files (void)
                g_printerr ("modest: cannot find providers data\n");
                return FALSE;
        }
-
+#endif
        return TRUE;
 }
 
@@ -216,9 +212,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*
@@ -876,14 +874,14 @@ 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"),
@@ -997,57 +995,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;
@@ -1228,7 +1179,7 @@ modest_platform_animation_banner (GtkWidget *parent,
                                  const gchar *animation_name,
                                  const gchar *text)
 {
-       return;
+       return NULL;
 }
 
 typedef struct
@@ -1342,16 +1293,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);
        }
 }
 
@@ -1383,9 +1331,6 @@ modest_platform_run_certificate_confirmation_dialog (const gchar* server_name,
                                _HL("wdgt_bd_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 +1350,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 +1366,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 +1432,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 +1463,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 +1624,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 +1710,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 +1735,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"