diff options
author | Michael Zucci <zucchi@src.gnome.org> | 2004-09-20 13:59:55 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-09-20 13:59:55 +0800 |
commit | ef6a3af717132e0750f226fa8a0ee0f3c98e19f0 (patch) | |
tree | f4ed25f7a247a8ccb855a8d940777e7a3d21a3e3 /mail/em-folder-properties.c | |
parent | 96111b1f1487ca3fe454b340a73ba927cc6bfb83 (diff) | |
download | gsoc2013-evolution-ef6a3af717132e0750f226fa8a0ee0f3c98e19f0.tar.gz gsoc2013-evolution-ef6a3af717132e0750f226fa8a0ee0f3c98e19f0.tar.zst gsoc2013-evolution-ef6a3af717132e0750f226fa8a0ee0f3c98e19f0.zip |
Merged notzed-eplugin-2-branch to head.
svn path=/trunk/; revision=27300
Diffstat (limited to 'mail/em-folder-properties.c')
-rw-r--r-- | mail/em-folder-properties.c | 226 |
1 files changed, 129 insertions, 97 deletions
diff --git a/mail/em-folder-properties.c b/mail/em-folder-properties.c index 885abcceef..9c32e30a87 100644 --- a/mail/em-folder-properties.c +++ b/mail/em-folder-properties.c @@ -39,8 +39,10 @@ #include <gtk/gtkvbox.h> #include <camel/camel-folder.h> +#include <libgnome/gnome-i18n.h> #include "em-folder-properties.h" +#include "em-config.h" #include "mail-ops.h" #include "mail-mt.h" @@ -50,19 +52,32 @@ struct _prop_data { void *object; CamelArgV *argv; GtkWidget **widgets; + + GSList *properties; + char *name; + int total; + int unread; + EMConfig *config; }; static void emfp_dialog_response (GtkWidget *dialog, int response, struct _prop_data *prop_data) { + if (response == GTK_RESPONSE_OK) + e_config_commit((EConfig *)prop_data->config); + else + e_config_abort((EConfig *)prop_data->config); + + gtk_widget_destroy (dialog); +} + +static void +emfp_commit(EConfig *ec, GSList *items, void *data) +{ + struct _prop_data *prop_data = data; CamelArgV *argv = prop_data->argv; int i; - if (response != GTK_RESPONSE_OK) { - gtk_widget_destroy (dialog); - return; - } - for (i = 0; i < argv->argc; i++) { CamelArg *arg = &argv->argv[i]; @@ -81,136 +96,75 @@ emfp_dialog_response (GtkWidget *dialog, int response, struct _prop_data *prop_d } camel_object_setv (prop_data->object, NULL, argv); - gtk_widget_destroy (dialog); } static void -emfp_dialog_free (void *data) +emfp_free(EConfig *ec, GSList *items, void *data) { struct _prop_data *prop_data = data; int i; + g_slist_free(items); + for (i = 0; i < prop_data->argv->argc; i++) { if ((prop_data->argv->argv[i].tag & CAMEL_ARG_TYPE) == CAMEL_ARG_STR) g_free (prop_data->argv->argv[i].ca_str); } + + camel_object_free (prop_data->object, CAMEL_FOLDER_PROPERTIES, prop_data->properties); + camel_object_free (prop_data->object, CAMEL_FOLDER_NAME, prop_data->name); camel_object_unref (prop_data->object); g_free (prop_data->argv); + g_free (prop_data); } -static void -emfp_dialog_got_folder (char *uri, CamelFolder *folder, void *data) +static GtkWidget * +emfp_get_folder_item(EConfig *ec, EConfigItem *item, struct _GtkWidget *parent, struct _GtkWidget *old, void *data) { - GtkWidget *dialog, *w, *table, *label, *vbox, *hbox; - struct _prop_data *prop_data; - CamelArgGetV *arggetv; - CamelArgV *argv; - GSList *list, *l; - gint32 count, i; - char *name, *title; char countstr[16]; - int row = 0, total=0, unread=0; - - if (folder == NULL) - return; - - camel_object_get (folder, NULL, CAMEL_FOLDER_PROPERTIES, &list, CAMEL_FOLDER_NAME, &name, - CAMEL_FOLDER_TOTAL, &total, CAMEL_FOLDER_UNREAD, &unread, NULL); - - dialog = gtk_dialog_new_with_buttons (_("Folder Properties"), NULL, - GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - gtk_window_set_default_size ((GtkWindow *) dialog, 192, 160); - gtk_widget_ensure_style (dialog); - gtk_container_set_border_width ((GtkContainer *) ((GtkDialog *) dialog)->vbox, 0); - gtk_container_set_border_width ((GtkContainer *) ((GtkDialog *) dialog)->vbox, 12); - - vbox = gtk_vbox_new (FALSE, 12); - gtk_container_set_border_width ((GtkContainer *) vbox, 12); - gtk_box_pack_start ((GtkBox *) ((GtkDialog *) dialog)->vbox, vbox, TRUE, TRUE, 0); - gtk_widget_show (vbox); - - title = g_strdup_printf ("<b>%s</b>", name); - label = gtk_label_new (title); - gtk_label_set_use_markup ((GtkLabel *) label, TRUE); - gtk_misc_set_alignment ((GtkMisc *) label, 0.0, 0.5); - gtk_box_pack_start ((GtkBox *) vbox, label, FALSE, FALSE, 0); - gtk_widget_show (label); - g_free (title); - - hbox = gtk_hbox_new (FALSE, 12); - gtk_box_pack_start ((GtkBox *) vbox, hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); + GtkWidget *w, *table, *label; + struct _prop_data *prop_data = data; + int row = 0, i; + GSList *l; - label = gtk_label_new (""); - gtk_box_pack_start ((GtkBox *) hbox, label, FALSE, FALSE, 0); - gtk_widget_show (label); + if (old) + return old; - /* TODO: maybe we want some basic properties here, like message counts/approximate size/etc */ - table = gtk_table_new (g_slist_length (list) + 2, 2, FALSE); + table = gtk_table_new (g_slist_length (prop_data->properties) + 2, 2, FALSE); gtk_table_set_row_spacings ((GtkTable *) table, 6); gtk_table_set_col_spacings ((GtkTable *) table, 12); gtk_widget_show (table); - gtk_box_pack_start ((GtkBox *) hbox, table, TRUE, TRUE, 0); + gtk_box_pack_start ((GtkBox *) parent, table, TRUE, TRUE, 0); /* TODO: can this be done in a loop? */ - label = gtk_label_new (ngettext ("Total message:", "Total messages:", total)); + label = gtk_label_new (ngettext ("Total message:", "Total messages:", prop_data->total)); gtk_widget_show (label); gtk_misc_set_alignment ((GtkMisc *) label, 0.0, 0.5); gtk_table_attach ((GtkTable *) table, label, 0, 1, row, row+1, GTK_FILL, 0, 0, 0); - sprintf(countstr, "%d", total); + sprintf(countstr, "%d", prop_data->total); label = gtk_label_new (countstr); gtk_widget_show (label); gtk_misc_set_alignment ((GtkMisc *) label, 1.0, 0.5); gtk_table_attach ((GtkTable *) table, label, 1, 2, row, row+1, GTK_FILL | GTK_EXPAND, 0, 0, 0); row++; - label = gtk_label_new (ngettext ("Unread message:", "Unread messages:", unread)); + label = gtk_label_new (ngettext ("Unread message:", "Unread messages:", prop_data->unread)); gtk_widget_show (label); gtk_misc_set_alignment ((GtkMisc *) label, 0.0, 0.5); gtk_table_attach ((GtkTable *) table, label, 0, 1, row, row+1, GTK_FILL, 0, 0, 0); - sprintf(countstr, "%d", unread); + sprintf(countstr, "%d", prop_data->unread); label = gtk_label_new (countstr); gtk_widget_show (label); gtk_misc_set_alignment ((GtkMisc *) label, 1.0, 0.5); gtk_table_attach ((GtkTable *) table, label, 1, 2, row, row+1, GTK_FILL | GTK_EXPAND, 0, 0, 0); row++; - /* build an arggetv/argv to retrieve/store the results */ - count = g_slist_length (list); - arggetv = g_malloc0 (sizeof (*arggetv) + (count - CAMEL_ARGV_MAX) * sizeof (arggetv->argv[0])); - arggetv->argc = count; - argv = g_malloc0 (sizeof (*argv) + (count - CAMEL_ARGV_MAX) * sizeof (argv->argv[0])); - argv->argc = count; - - i = 0; - l = list; - while (l) { - CamelProperty *prop = l->data; - - argv->argv[i].tag = prop->tag; - arggetv->argv[i].tag = prop->tag; - arggetv->argv[i].ca_ptr = &argv->argv[i].ca_ptr; - - l = l->next; - i++; - } - - camel_object_getv (folder, NULL, arggetv); - g_free (arggetv); - - prop_data = g_malloc0 (sizeof (*prop_data)); - prop_data->widgets = g_malloc0 (sizeof (prop_data->widgets[0]) * count); - prop_data->argv = argv; - /* setup the ui with the values retrieved */ - l = list; + l = prop_data->properties; i = 0; while (l) { CamelProperty *prop = l->data; @@ -218,7 +172,7 @@ emfp_dialog_got_folder (char *uri, CamelFolder *folder, void *data) switch (prop->tag & CAMEL_ARG_TYPE) { case CAMEL_ARG_BOO: w = gtk_check_button_new_with_label (prop->description); - gtk_toggle_button_set_active ((GtkToggleButton *) w, argv->argv[i].ca_int != 0); + gtk_toggle_button_set_active ((GtkToggleButton *) w, prop_data->argv->argv[i].ca_int != 0); gtk_widget_show (w); gtk_table_attach ((GtkTable *) table, w, 0, 2, row, row + 1, GTK_FILL | GTK_EXPAND, 0, 0, 0); prop_data->widgets[i] = w; @@ -231,10 +185,10 @@ emfp_dialog_got_folder (char *uri, CamelFolder *folder, void *data) w = gtk_entry_new (); gtk_widget_show (w); - if (argv->argv[i].ca_str) { - gtk_entry_set_text ((GtkEntry *) w, argv->argv[i].ca_str); - camel_object_free (folder, argv->argv[i].tag, argv->argv[i].ca_str); - argv->argv[i].ca_str = NULL; + if (prop_data->argv->argv[i].ca_str) { + gtk_entry_set_text ((GtkEntry *) w, prop_data->argv->argv[i].ca_str); + camel_object_free (prop_data->object, prop_data->argv->argv[i].tag, prop_data->argv->argv[i].ca_str); + prop_data->argv->argv[i].ca_str = NULL; } gtk_table_attach ((GtkTable *) table, w, 1, 2, row, row + 1, GTK_FILL | GTK_EXPAND, 0, 0, 0); prop_data->widgets[i] = w; @@ -247,17 +201,95 @@ emfp_dialog_got_folder (char *uri, CamelFolder *folder, void *data) row++; l = l->next; } - + + return table; +} + +#define EMFP_FOLDER_SECTION (2) + +static EMConfigItem emfp_items[] = { + { E_CONFIG_BOOK, "", NULL }, + { E_CONFIG_PAGE, "00.general", N_("General") }, + { E_CONFIG_SECTION, "00.general/00.folder", NULL /* set by code */ }, + { E_CONFIG_ITEM, "00.general/00.folder/00.info", NULL, emfp_get_folder_item }, +}; + +static void +emfp_dialog_got_folder (char *uri, CamelFolder *folder, void *data) +{ + GtkWidget *dialog, *w; + struct _prop_data *prop_data; + GSList *l; + gint32 count, i; + EMConfig *ec; + EMConfigTargetFolder *target; + CamelArgGetV *arggetv; + CamelArgV *argv; + + if (folder == NULL) + return; + + prop_data = g_malloc0 (sizeof (*prop_data)); prop_data->object = folder; camel_object_ref (folder); + + camel_object_get (folder, NULL, CAMEL_FOLDER_PROPERTIES, &prop_data->properties, CAMEL_FOLDER_NAME, &prop_data->name, + CAMEL_FOLDER_TOTAL, &prop_data->total, CAMEL_FOLDER_UNREAD, &prop_data->unread, NULL); + + emfp_items[EMFP_FOLDER_SECTION].label = prop_data->name; + + count = g_slist_length (prop_data->properties); + + prop_data->widgets = g_malloc0 (sizeof (prop_data->widgets[0]) * count); + + /* build an arggetv/argv to retrieve/store the results */ + argv = g_malloc0 (sizeof (*argv) + (count - CAMEL_ARGV_MAX) * sizeof (argv->argv[0])); + argv->argc = count; + arggetv = g_malloc0 (sizeof (*arggetv) + (count - CAMEL_ARGV_MAX) * sizeof (arggetv->argv[0])); + arggetv->argc = count; - camel_object_free (folder, CAMEL_FOLDER_PROPERTIES, list); - camel_object_free (folder, CAMEL_FOLDER_NAME, name); + i = 0; + l = prop_data->properties; + while (l) { + CamelProperty *prop = l->data; + + argv->argv[i].tag = prop->tag; + arggetv->argv[i].tag = prop->tag; + arggetv->argv[i].ca_ptr = &argv->argv[i].ca_ptr; + + l = l->next; + i++; + } + camel_object_getv (prop_data->object, NULL, arggetv); + g_free (arggetv); + prop_data->argv = argv; + + dialog = gtk_dialog_new_with_buttons (_("Folder Properties"), NULL, + GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); + gtk_window_set_default_size ((GtkWindow *) dialog, 192, 160); + gtk_widget_ensure_style (dialog); + gtk_container_set_border_width ((GtkContainer *) ((GtkDialog *) dialog)->vbox, 12); + + ec = em_config_new(E_CONFIG_BOOK, "com.novell.evolution.mail.folderConfig"); + prop_data->config = ec; + l = NULL; + for (i=0;i<sizeof(emfp_items)/sizeof(emfp_items[0]);i++) + l = g_slist_prepend(l, &emfp_items[i]); + e_config_add_items((EConfig *)ec, l, emfp_commit, NULL, emfp_free, prop_data); + + target = em_config_target_new_folder(ec, folder, uri); + e_config_set_target((EConfig *)ec, (EConfigTarget *)target); + w = e_config_create_widget((EConfig *)ec); + + gtk_box_pack_start ((GtkBox *) ((GtkDialog *) dialog)->vbox, w, TRUE, TRUE, 0); + /* we do 'apply on ok' ... since instant apply may apply some very long running tasks */ g_signal_connect (dialog, "response", G_CALLBACK (emfp_dialog_response), prop_data); - g_object_set_data_full ((GObject *) dialog, "e-prop-data", prop_data, emfp_dialog_free); gtk_widget_show (dialog); } |