Listing configured accounts in the preferences menu
This commit is contained in:
parent
dd058085f8
commit
7df68d3123
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
@ -127,7 +132,14 @@ void on_edit_preferences(GtkWidget * widget, gpointer data)
|
||||
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);
|
||||
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)
|
||||
if(gtk_tree_model_get_iter_first(model, &iter) == FALSE)
|
||||
return;
|
||||
do
|
||||
{
|
||||
/* 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);
|
||||
gtk_tree_model_get(model, &iter, AC_DATA, &account,
|
||||
AC_ACTIVE, &active, AC_ENABLED, &enabled, -1);
|
||||
if(active)
|
||||
{
|
||||
if(enabled)
|
||||
continue;
|
||||
if(mailer_account_disable(mailer, account) == 0)
|
||||
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
|
||||
AC_ACTIVE, FALSE, -1);
|
||||
}
|
||||
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);
|
||||
/* FIXME remove remaining accounts */
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user