From 7df68d31231f959269cbc989af443f5537a1dbfd Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Thu, 23 Aug 2007 03:00:21 +0000 Subject: [PATCH] Listing configured accounts in the preferences menu --- src/account.c | 18 ++++++++++++++++ src/account/account.h | 3 +++ src/callbacks.c | 49 ++++++++++++++++++++++++++++++++----------- src/mailer.h | 4 ++++ 4 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/account.c b/src/account.c index 08ead63..4a0f662 100644 --- a/src/account.c +++ b/src/account.c @@ -62,6 +62,7 @@ Account * account_new(char const * type, char const * name) } free(filename); account->title = strdup(name); + account->enabled = 1; account->identity = NULL; return account; } @@ -95,6 +96,23 @@ int account_set_title(Account * account, char const * title) /* useful */ +/* account_disable */ +int account_disable(Account * account) +{ + account->enabled = 0; + return 0; +} + + +/* account_enable */ +int account_enable(Account * account) +{ + account->enabled = 1; + return 0; +} + + +/* account_folders */ AccountFolder ** account_folders(Account * account) { return account->plugin->folders(); diff --git a/src/account/account.h b/src/account/account.h index 3f2ad53..fa08bfe 100644 --- a/src/account/account.h +++ b/src/account/account.h @@ -69,6 +69,7 @@ typedef struct _Account { char * name; char * title; + int enabled; AccountIdentity * identity; void * handle; AccountPlugin * plugin; @@ -83,6 +84,8 @@ void account_delete(Account * account); int account_set_title(Account * account, char const * title); /* useful */ +int account_disable(Account * account); +int account_enable(Account * account); /* FIXME wrong we just need receive, then it calls callbacks */ AccountFolder ** account_folders(Account * account); diff --git a/src/callbacks.c b/src/callbacks.c index 45d97a3..420846d 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -28,6 +28,8 @@ static char const _copyright[] = #include "callbacks.h" #include "../config.h" +#define DEBUG + /* constants */ static char const * _authors[] = @@ -82,6 +84,7 @@ void on_file_quit(GtkWidget * widget, gpointer data) typedef enum _AccountColumn { AC_DATA, + AC_ACTIVE, AC_ENABLED, AC_TITLE, AC_TYPE @@ -100,6 +103,8 @@ void on_edit_preferences(GtkWidget * widget, gpointer data) GtkWidget * vbox3; GtkSizeGroup * group; GtkListStore * store; + unsigned int i; + GtkTreeIter iter; if(mailer->pr_window != NULL) { @@ -126,8 +131,15 @@ void on_edit_preferences(GtkWidget * widget, gpointer data) GTK_SHADOW_IN); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - store = gtk_list_store_new(AC_LAST+1, G_TYPE_POINTER, G_TYPE_BOOLEAN, - G_TYPE_STRING, G_TYPE_STRING); + store = gtk_list_store_new(AC_LAST + 1, G_TYPE_POINTER, G_TYPE_BOOLEAN, + G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING); + for(i = 0; i < mailer->account_cnt; i++) + gtk_list_store_insert_with_values(store, &iter, -1, + AC_DATA, mailer->account[i], + AC_ACTIVE, TRUE, + AC_ENABLED, mailer->account[i]->enabled, + AC_TITLE, mailer->account[i]->title, + AC_TYPE, mailer->account[i]->plugin->type, -1); mailer->pr_accounts = gtk_tree_view_new_with_model(GTK_TREE_MODEL( store)); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(mailer->pr_accounts), @@ -301,26 +313,39 @@ void on_print(GtkWidget * widget, gpointer data) void on_preferences_ok(GtkWidget * widget, gpointer data) { Mailer * mailer = data; - Account * account; GtkTreeModel * model; GtkTreeIter iter; GtkTreeModel * view_model; - GtkTreeIter view_iter; + Account * account; + gboolean active; + gboolean enabled; gtk_widget_hide(mailer->pr_window); model = gtk_tree_view_get_model(GTK_TREE_VIEW(mailer->pr_accounts)); view_model = gtk_tree_view_get_model(GTK_TREE_VIEW( mailer->view_folders)); - if(gtk_tree_model_get_iter_first(model, &iter) != FALSE) - do + if(gtk_tree_model_get_iter_first(model, &iter) == FALSE) + return; + do + { + gtk_tree_model_get(model, &iter, AC_DATA, &account, + AC_ACTIVE, &active, AC_ENABLED, &enabled, -1); + if(active) { - /* FIXME check if already present, update if needed */ - /* else add account with full information */ - gtk_tree_model_get(model, &iter, AC_DATA, &account, -1); - mailer_account_add(mailer, account); + if(enabled) + continue; + if(mailer_account_disable(mailer, account) == 0) + gtk_list_store_set(GTK_LIST_STORE(model), &iter, + AC_ACTIVE, FALSE, -1); } - while(gtk_tree_model_iter_next(model, &iter) == TRUE); - /* FIXME remove remaining accounts */ + else if(enabled) + { + if(mailer_account_add(mailer, account) == 0) + gtk_list_store_set(GTK_LIST_STORE(model), &iter, + AC_ACTIVE, TRUE, -1); + } + } + while(gtk_tree_model_iter_next(model, &iter) == TRUE); } diff --git a/src/mailer.h b/src/mailer.h index 4b9f6c8..ea01284 100644 --- a/src/mailer.h +++ b/src/mailer.h @@ -66,5 +66,9 @@ void mailer_delete(Mailer * mailer); int mailer_error(Mailer * mailer, char const * message, int ret); int mailer_account_add(Mailer * mailer, Account * account); +int mailer_account_disable(Mailer * mailer, Account * account); +int mailer_account_enable(Mailer * mailer, Account * account); +/* FIXME implement +int mailer_account_remove(Mailer * mailer, Account * account); */ #endif