X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-ui.c;h=d236c4cac489b96d0bdc1679ef9260052c60539f;hb=7682620c7cd97669d2d99283c038c63433c1d66d;hp=084b7815decfe49b6aa4f8f32e059d8f0a2d4a2e;hpb=4ccc72431ceabc3e42e666bcfb6177c9745d0efd;p=modest diff --git a/src/modest-ui.c b/src/modest-ui.c index 084b781..d236c4c 100644 --- a/src/modest-ui.c +++ b/src/modest-ui.c @@ -99,6 +99,14 @@ static void reply_forward (GtkWidget *widget, static gchar* ask_for_folder_name (GtkWindow *parent_window, const gchar *title); +static void _modest_ui_actions_on_connection_changed (TnyDevice *device, + gboolean online, + ModestUI *modest_ui); + + +static void _modest_ui_actions_on_accounts_reloaded (TnyAccountStore *store, + gpointer user_data); + GType modest_ui_get_type (void) { @@ -306,6 +314,7 @@ static void connect_signals (ModestUI *self) { TnyDevice *device; + TnyAccountStore *account_store; ModestUIPrivate *priv; ModestFolderView *folder_view; ModestHeaderView *header_view; @@ -317,12 +326,12 @@ connect_signals (ModestUI *self) widget_factory = modest_runtime_get_widget_factory (); - folder_view = modest_widget_factory_get_folder_view (widget_factory); - header_view = modest_widget_factory_get_header_view (widget_factory); - msg_view = modest_widget_factory_get_msg_preview (widget_factory); - toggle = modest_widget_factory_get_online_toggle (widget_factory); - device = tny_account_store_get_device - (TNY_ACCOUNT_STORE(modest_runtime_get_account_store())); + folder_view = modest_widget_factory_get_folder_view (widget_factory); + header_view = modest_widget_factory_get_header_view (widget_factory); + msg_view = modest_widget_factory_get_msg_preview (widget_factory); + toggle = modest_widget_factory_get_online_toggle (widget_factory); + account_store = TNY_ACCOUNT_STORE(modest_runtime_get_account_store()); + device = tny_account_store_get_device (account_store); /* folder view */ g_signal_connect (G_OBJECT(folder_view), "folder_selection_changed", @@ -349,13 +358,20 @@ connect_signals (ModestUI *self) G_CALLBACK(_modest_ui_actions_on_msg_attachment_clicked), priv->main_window); + /* Account store */ + g_signal_connect (G_OBJECT (account_store), "accounts_reloaded", + G_CALLBACK (_modest_ui_actions_on_accounts_reloaded), + priv->main_window); + /* Device */ g_signal_connect (G_OBJECT(device), "connection_changed", G_CALLBACK(_modest_ui_actions_on_connection_changed), - priv->main_window); - g_signal_connect (G_OBJECT(toggle), "toggled", - G_CALLBACK(_modest_ui_actions_on_online_toggle_toggled), - priv->main_window); + self); + + priv->toggle_button_signal= + g_signal_connect (G_OBJECT(toggle), "toggled", + G_CALLBACK(_modest_ui_actions_on_online_toggle_toggled), + priv->main_window); /* Destroy window */ g_signal_connect (G_OBJECT(priv->main_window), @@ -363,11 +379,10 @@ connect_signals (ModestUI *self) G_CALLBACK(on_main_window_destroy), NULL); - /* Init toggle in correct state */ _modest_ui_actions_on_connection_changed (device, tny_device_is_online (device), - MODEST_MAIN_WINDOW (priv->main_window)); + self); } @@ -606,6 +621,7 @@ reply_forward (GtkWidget *widget, tny_folder_get_msg_async (folder, header, get_msg_cb, helper); /* Clean */ + g_object_unref (G_OBJECT (header)); g_object_unref (G_OBJECT (folder)); } @@ -733,10 +749,13 @@ get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data) g_object_unref (G_OBJECT (headers)); g_object_unref (G_OBJECT (helper->iter)); g_slice_free (GetMsgAsyncHelper, helper); - } else - tny_folder_get_msg_async (folder, - TNY_HEADER (tny_iterator_get_current (helper->iter)), + } else { + TnyHeader *header; + header = TNY_HEADER (tny_iterator_get_current (helper->iter)); + tny_folder_get_msg_async (folder, header, get_msg_cb, helper); + g_object_unref (G_OBJECT(header)); + } } void @@ -882,36 +901,50 @@ statusbar_push (ModestWidgetFactory *factory, guint context_id, const gchar *msg } /****************************************************************************/ -void -_modest_ui_actions_on_connection_changed (TnyDevice *device, gboolean online, - ModestMainWindow *main_window) +static void +_modest_ui_actions_on_connection_changed (TnyDevice *device, + gboolean online, + ModestUI *self) { GtkWidget *online_toggle; ModestHeaderView *header_view; ModestWidgetFactory *widget_factory; + ModestUIPrivate *priv; + GtkWidget *icon; + const gchar *icon_name; + + g_return_if_fail (device); + g_return_if_fail (self); + + priv = MODEST_UI_GET_PRIVATE (self); + + icon_name = online ? GTK_STOCK_CONNECT : GTK_STOCK_DISCONNECT; + icon = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON); - g_return_if_fail (main_window); - widget_factory = modest_runtime_get_widget_factory (); header_view = modest_widget_factory_get_header_view (widget_factory); online_toggle = modest_widget_factory_get_online_toggle (widget_factory); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(online_toggle), - online); - gtk_button_set_label (GTK_BUTTON(online_toggle), - online ? _("Online") : _("Offline")); + /* Block handlers in order to avoid unnecessary calls */ + g_signal_handler_block (G_OBJECT (online_toggle), priv->toggle_button_signal); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(online_toggle), online); + g_signal_handler_unblock (G_OBJECT (online_toggle), priv->toggle_button_signal); + gtk_button_set_image (GTK_BUTTON(online_toggle), icon); statusbar_push (widget_factory, 0, online ? _("Modest went online") : _("Modest went offline")); /* If Modest has became online and the header view has a header selected then show it */ - if (online) { - GtkTreeSelection *selected; + /* FIXME: there is a race condition if some account needs to + ask the user for a password */ - selected = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view)); - _modest_header_view_change_selection (selected, header_view); - } +/* if (online) { */ +/* GtkTreeSelection *selected; */ + +/* selected = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view)); */ +/* _modest_header_view_change_selection (selected, header_view); */ +/* } */ } void @@ -941,15 +974,13 @@ _modest_ui_actions_on_item_not_found (ModestHeaderView *header_view, gchar *txt, *item; gboolean online; TnyDevice *device; - TnyPlatformFactory *factory; TnyAccountStore *account_store; item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message"; /* Get device. Do not ask the platform factory for it, because it returns always a new one */ - factory = modest_tny_platform_factory_get_instance (); - account_store = tny_platform_factory_new_account_store (factory); + account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()); device = tny_account_store_get_device (account_store); if (g_main_depth > 0) @@ -1068,42 +1099,38 @@ _modest_ui_actions_on_send (GtkWidget *widget, TnyTransportAccount *transport_account; ModestMailOperation *mail_operation; MsgData *data; - + gchar *account_name, *from; + ModestAccountMgr *account_mgr; + + data = modest_edit_msg_window_get_msg_data (edit_window); /* FIXME: Code added just for testing. The final version will use the send queue provided by tinymail and some classifier */ - { - TnyList *accounts; - TnyIterator *iter; - - accounts = TNY_LIST(tny_simple_list_new ()); - tny_account_store_get_accounts (TNY_ACCOUNT_STORE(modest_runtime_get_account_store()), - accounts, - TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS); - - iter = tny_list_create_iterator(accounts); - tny_iterator_first (iter); - if (tny_iterator_is_done (iter)) { - /* FIXME: Add error handling through mail operation */ - g_printerr("modest: no transport accounts defined\n"); - modest_edit_msg_window_free_msg_data (edit_window, data); - return; - } - transport_account = TNY_TRANSPORT_ACCOUNT (tny_iterator_get_current(iter)); - g_object_ref (transport_account); - - tny_list_foreach (accounts, (GFunc) g_object_unref, NULL); - g_object_unref (G_OBJECT (accounts)); - g_object_unref (G_OBJECT (iter)); + account_mgr = modest_runtime_get_account_mgr(); + account_name = modest_account_mgr_get_default_account (account_mgr); + if (!account_name) { + g_printerr ("modest: no default account found\n"); + modest_edit_msg_window_free_msg_data (edit_window, data); + return; } - + transport_account = + TNY_TRANSPORT_ACCOUNT(modest_account_mgr_get_tny_account (account_mgr, + account_name, + TNY_ACCOUNT_TYPE_TRANSPORT)); + if (!transport_account) { + g_printerr ("modest: no transport account found\n"); + g_free (account_name); + modest_edit_msg_window_free_msg_data (edit_window, data); + return; + } + from = modest_account_mgr_get_from_string (account_mgr, account_name); + mail_operation = modest_mail_operation_new (); - modest_mail_operation_send_new_mail (mail_operation, transport_account, - data->from, + from, data->to, data->cc, data->bcc, @@ -1111,6 +1138,8 @@ _modest_ui_actions_on_send (GtkWidget *widget, data->body, NULL); /* Frees */ + g_free (from); + g_free (account_name); g_object_unref (G_OBJECT (mail_operation)); g_object_unref (G_OBJECT (transport_account)); modest_edit_msg_window_free_msg_data (edit_window, data); @@ -1254,3 +1283,12 @@ _modest_ui_actions_on_move_to_trash_folder (GtkWidget *widget, { delete_folder (main_window, TRUE); } + +static void +_modest_ui_actions_on_accounts_reloaded (TnyAccountStore *store, gpointer user_data) +{ + ModestFolderView *folder_view; + + folder_view = modest_widget_factory_get_folder_view (modest_runtime_get_widget_factory()); + modest_folder_view_update_model (folder_view, store); +}