Add emision of signals for account created and removed through dbus
[modest] / src / hildon2 / modest-platform.c
index 91992a9..d8f9225 100644 (file)
@@ -34,7 +34,6 @@
 #include <modest-defs.h>
 #include <modest-scrollable.h>
 #include <modest-runtime.h>
-#include <modest-main-window.h>
 #include <modest-header-view.h>
 #include "modest-hildon2-global-settings-dialog.h"
 #include "modest-widget-memory.h"
@@ -65,6 +64,7 @@
 #include <osso-mem.h>
 #include "hildon2/modest-hildon2-details-dialog.h"
 #include "widgets/modest-window-mgr.h"
+#include "widgets/modest-msg-view-window.h"
 #ifdef MODEST_USE_PROFILE
 #include <profiled/keys_nokia.h>
 #include <profiled/libprofile.h>
@@ -427,7 +427,7 @@ activate_uri_popup_item (GtkMenuItem *menu_item,
                        uri = popup_info->uri + strlen ("mailto:");
 
                gtk_clipboard_set_text (clipboard, uri, strlen (uri));
-               modest_platform_information_banner (NULL, NULL, _CS("ecoc_ib_edwin_copied"));
+               modest_platform_information_banner (NULL, NULL, _CS_COPIED);
                return; /* we're done */
        }
 
@@ -561,7 +561,7 @@ entry_insert_text (GtkEditable *editable,
        /* Show WID-INF036 */
        if (chars_length >= 20) {
                hildon_banner_show_information  (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 */
@@ -569,7 +569,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);
                        hildon_banner_show_information  (gtk_widget_get_parent (GTK_WIDGET (data)),
                                                         NULL, msg);
                        g_free (msg);
@@ -577,7 +577,7 @@ entry_insert_text (GtkEditable *editable,
                } else {
                        if (length >= 20) {
                                hildon_banner_show_information  (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,
@@ -608,7 +608,7 @@ entry_changed (GtkEditable *editable,
 
        if (g_utf8_strlen (chars,-1) >= 20) {
                hildon_banner_show_information  (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));
 
@@ -660,9 +660,9 @@ on_response (GtkDialog *dialog,
        if (exists) {
                /* Show an error */
                hildon_banner_show_information (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_editable_select_region (GTK_EDITABLE (entry), 0, -1);
                gtk_widget_grab_focus (entry);
                /* Do not close the dialog */
                g_signal_stop_emission_by_name (dialog, "response");
@@ -697,7 +697,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));
@@ -870,7 +870,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;
 
@@ -885,7 +885,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,
@@ -1019,7 +1019,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);
 
@@ -1040,16 +1040,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)));
-               gtk_entry_select_region (GTK_ENTRY (entry), 0, -1);
+                                               g_utf8_strlen (_FM_NEW_FOLDER_NAME_STUB, -1)));
+               gtk_editable_select_region (GTK_EDITABLE (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);
@@ -1178,7 +1178,7 @@ 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"),
+                                                          _FM_NEW_FOLDER_NAME,
                                                           real_suggested_name,
                                                           TRUE,
                                                           TRUE,
@@ -1610,6 +1610,7 @@ modest_platform_on_new_headers_received (GList *URI_list,
        gchar *from;
        TnyAccountStore *acc_store;
        TnyAccount *account;
+       gchar *acc_name;
 
        data = (ModestMsgNotificationData *) URI_list->data;
 
@@ -1659,10 +1660,9 @@ modest_platform_on_new_headers_received (GList *URI_list,
        /* Set the account of the headers */
        acc_store = (TnyAccountStore *) modest_runtime_get_account_store ();
        account = tny_account_store_find_account (acc_store, data->uri);
+       acc_name = NULL;
        if (account) {
-               const gchar *acc_name;
-               acc_name =
-                       modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+               acc_name = g_strdup (modest_tny_account_get_parent_modest_account_name_for_server_account (account));
                notify_notification_set_hint_string(NOTIFY_NOTIFICATION (notification),
                                                    "email-account",
                                                    acc_name);
@@ -1673,9 +1673,11 @@ modest_platform_on_new_headers_received (GList *URI_list,
                GSList *notifications_list = NULL;
 
                /* Get previous notifications ids */
-               notifications_list = modest_conf_get_list (modest_runtime_get_conf (),
-                                                          MODEST_CONF_NOTIFICATION_IDS,
-                                                          MODEST_CONF_VALUE_INT, NULL);
+               if (acc_name) {
+                       notifications_list = modest_account_mgr_get_list (modest_runtime_get_account_mgr (), acc_name,
+                                                                         MODEST_ACCOUNT_NOTIFICATION_IDS,
+                                                                         MODEST_CONF_VALUE_INT, FALSE);
+               }
 
                /* Save id in the list */
                g_object_get(G_OBJECT (notification), "id", &notif_id, NULL);
@@ -1686,19 +1688,22 @@ modest_platform_on_new_headers_received (GList *URI_list,
                   not to store the list in gconf */
 
                /* Save the ids */
-               modest_conf_set_list (modest_runtime_get_conf (), MODEST_CONF_NOTIFICATION_IDS,
-                                     notifications_list, MODEST_CONF_VALUE_INT, NULL);
-
+               if (acc_name)
+                       modest_account_mgr_set_list (modest_runtime_get_account_mgr (), acc_name,
+                                                    MODEST_ACCOUNT_NOTIFICATION_IDS,
+                                                    notifications_list, MODEST_CONF_VALUE_INT, FALSE);
+                       
                g_slist_free (notifications_list);
        } else {
                g_warning ("Failed to send notification");
        }
+       g_free (acc_name);
 
 #endif /*MODEST_HAVE_HILDON_NOTIFY*/
 }
 
 void
-modest_platform_remove_new_mail_notifications (gboolean only_visuals) 
+modest_platform_remove_new_mail_notifications (gboolean only_visuals, const gchar *acc_name) 
 {
        if (only_visuals) {
 #ifdef MODEST_HAVE_MCE
@@ -1718,9 +1723,10 @@ modest_platform_remove_new_mail_notifications (gboolean only_visuals)
        GSList *notif_list = NULL;
 
        /* Get previous notifications ids */
-       notif_list = modest_conf_get_list (modest_runtime_get_conf (), 
-                                          MODEST_CONF_NOTIFICATION_IDS, 
-                                          MODEST_CONF_VALUE_INT, NULL);
+       notif_list = modest_account_mgr_get_list (modest_runtime_get_account_mgr (), 
+                                                 acc_name,
+                                                 MODEST_ACCOUNT_NOTIFICATION_IDS, 
+                                                 MODEST_CONF_VALUE_INT, FALSE);
 
         while (notif_list) {
                gint notif_id;
@@ -1743,10 +1749,13 @@ modest_platform_remove_new_mail_notifications (gboolean only_visuals)
         }
 
        /* Save the ids */
-       modest_conf_set_list (modest_runtime_get_conf (), MODEST_CONF_NOTIFICATION_IDS, 
-                             notif_list, MODEST_CONF_VALUE_INT, NULL);
+       if (notif_list) {
+               modest_account_mgr_set_list (modest_runtime_get_account_mgr (), acc_name,
+                                            MODEST_ACCOUNT_NOTIFICATION_IDS,
+                                            notif_list, MODEST_CONF_VALUE_INT, FALSE);
 
-       g_slist_free (notif_list);
+               g_slist_free (notif_list);
+       }
 
 #endif /* MODEST_HAVE_HILDON_NOTIFY */
 }
@@ -2121,7 +2130,7 @@ modest_platform_run_alert_dialog (const gchar* prompt,
 
 /***************/
 typedef struct {
-       GtkWindow *parent_window;
+       ModestWindow *parent_window;
        ModestConnectedPerformer callback;
        TnyAccount *account;
        gpointer user_data;
@@ -2221,7 +2230,7 @@ on_conic_device_went_online (TnyMaemoConicDevice *device, const gchar* iap_id, g
 }
        
 void 
-modest_platform_connect_and_perform (GtkWindow *parent_window, 
+modest_platform_connect_and_perform (ModestWindow *parent_window,
                                     gboolean force,
                                     TnyAccount *account, 
                                     ModestConnectedPerformer callback, 
@@ -2254,7 +2263,7 @@ modest_platform_connect_and_perform (GtkWindow *parent_window,
                        info->account = NULL;
                
                        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;
                        info->user_data = user_data;
@@ -2299,7 +2308,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;
        
@@ -2332,7 +2341,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, 
@@ -2381,7 +2390,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)
 {
@@ -2403,13 +2412,13 @@ src_account_connect_performer (gboolean canceled,
 }
 
 
-void 
-modest_platform_double_connect_and_perform (GtkWindow *parent_window, 
+void
+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, 
@@ -3032,7 +3041,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);
 
@@ -3054,7 +3063,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);
@@ -3156,3 +3165,49 @@ modest_platform_get_list_to_move (ModestWindow *window)
 
        return list;
 }
+
+DBusConnection*
+modest_platform_get_dbus_connection (void)
+{
+       osso_context_t *osso_context;
+       DBusConnection *con;
+
+       osso_context = modest_maemo_utils_get_osso_context();
+
+       con = osso_get_dbus_connection (osso_context);
+
+       return con;
+}
+
+void
+modest_platform_emit_folder_updated_signal (const gchar *account_id, const gchar *folder_id)
+{
+       DBusConnection *con;
+
+       con = modest_platform_get_dbus_connection ();
+       if (!con) return;
+
+       modest_dbus_emit_folder_updated_signal (con, account_id, folder_id);
+}
+
+void
+modest_platform_emit_account_created_signal (const gchar *account_id)
+{
+       DBusConnection *con;
+
+       con = modest_platform_get_dbus_connection ();
+       if (!con) return;
+
+       modest_dbus_emit_account_created_signal (con, account_id);
+}
+
+void
+modest_platform_emit_account_removed_signal (const gchar *account_id)
+{
+       DBusConnection *con;
+
+       con = modest_platform_get_dbus_connection ();
+       if (!con) return;
+
+       modest_dbus_emit_account_removed_signal (con, account_id);
+}