* Makefile.am, modest-mail-operation.c:
[modest] / src / gtk / modest-account-view-window.c
index 67d6d9a..aaa9655 100644 (file)
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <glib/gi18n.h>
+#include <modest-runtime.h>
 #include "modest-account-view-window.h"
 #include "modest-account-assistant.h"
 #include "modest-tny-platform-factory.h"
@@ -47,7 +49,9 @@ enum {
 typedef struct _ModestAccountViewWindowPrivate ModestAccountViewWindowPrivate;
 struct _ModestAccountViewWindowPrivate {
        ModestWidgetFactory *widget_factory;
-       GtkWidget           *edit_button, *remove_button;
+       GtkWidget           *edit_button;
+       GtkWidget           *remove_button;
+       ModestAccountView   *account_view;
 };
 #define MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                         MODEST_TYPE_ACCOUNT_VIEW_WINDOW, \
@@ -144,12 +148,55 @@ on_selection_changed (GtkTreeSelection *sel, ModestAccountViewWindow *self)
        gtk_widget_set_sensitive (priv->remove_button, has_selection);  
 }
 
-
-
 static void
 on_remove_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
 {
-       g_message (__FUNCTION__);
+       ModestAccountViewWindowPrivate *priv;
+       ModestAccountMgr *account_mgr;
+       const gchar *account_name;
+       
+       priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self);
+
+       account_mgr = modest_runtime_get_account_mgr(); 
+       account_name = modest_account_view_get_selected_account (priv->account_view);
+
+       if (account_name) {
+               gboolean removed;
+               GError *err = NULL;
+               GtkWidget *dialog;
+               gchar *txt;
+
+               dialog = gtk_dialog_new_with_buttons (_("Confirmation dialog"),
+                                                     GTK_WINDOW (self),
+                                                     GTK_DIALOG_MODAL,
+                                                     GTK_STOCK_CANCEL,
+                                                     GTK_RESPONSE_REJECT,
+                                                     GTK_STOCK_OK,
+                                                     GTK_RESPONSE_ACCEPT,
+                                                     NULL);
+               txt = g_strdup_printf (_("Do you really want to delete the account %s?"), account_name);
+               gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), 
+                                   gtk_label_new (txt), FALSE, FALSE, 0);
+               gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
+               g_free (txt);
+
+               if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+                       /* Remove account. If succeeded it removes also 
+                          the account from the ModestAccountView */
+                       removed = modest_account_mgr_remove_account (account_mgr,
+                                                                    account_name,
+                                                                    FALSE,
+                                                                    &err);
+                       if (removed) {
+                               /* Show confirmation dialog ??? */
+                       } else {
+                               /* Show error dialog ??? */
+                               if (err)
+                                       g_error_free (err);
+                       }
+               }
+               gtk_widget_destroy (dialog);
+       }
 }
 
 static void
@@ -163,14 +210,9 @@ on_add_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
 {
        GtkWidget *assistant;
        ModestAccountViewWindowPrivate *priv;
-       TnyPlatformFactory *fact;
-       ModestAccountMgr *account_mgr;
        
        priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self);
-       fact = modest_tny_platform_factory_get_instance ();
-       account_mgr = modest_tny_platform_factory_get_modest_account_mgr_instance (fact);
-
-       assistant = modest_account_assistant_new (account_mgr,
+       assistant = modest_account_assistant_new (modest_runtime_get_account_mgr(),
                                                  priv->widget_factory);
        gtk_window_set_transient_for (GTK_WINDOW(assistant),
                                      GTK_WINDOW(self));
@@ -198,6 +240,9 @@ button_box_new (ModestAccountViewWindow *self)
        priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self);
        
        button_box   = gtk_vbutton_box_new ();
+       gtk_button_box_set_spacing (GTK_BUTTON_BOX (button_box), 6);
+       gtk_button_box_set_layout (GTK_BUTTON_BOX (button_box), 
+                                  GTK_BUTTONBOX_START);
 
        add_button    = gtk_button_new_from_stock(GTK_STOCK_ADD);
        remove_button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
@@ -245,6 +290,7 @@ window_vbox_new (ModestAccountViewWindow *self)
        main_hbox     = gtk_hbox_new (FALSE, 6);
        
        account_view = modest_widget_factory_get_account_view (priv->widget_factory);
+       priv->account_view = account_view;
        gtk_widget_set_size_request (GTK_WIDGET(account_view), 300, 400);
 
        sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(account_view));