Re: [Evolution-hackers] Re: lockdown keys



Ok here's an updated patch.  I've included a screenshot of the new ui to
control how often empty trash on exit is run.  This should mean most of
the stuff is done for lockdown ... but it doesn't seem to ...

... while trying to test this (Jeff - please, we should be testing every
commit these days ...), i had trouble finding out how to make keys
readonly.

As far as I can tell, there isn't any such way to do this.

I tried the .gconf.path stuff with a read-only mirror of the mailer
stuff, but everything is still read-write.  I even tried chmod, but that
didn't work (and is too coarse anyway).

I guess i could've done it wrong too, i just tried copying
~/.gconf/apps/evolution/mail -> ~/.gconf.ro/apps/evolution/mail (after
setting that path up), and i even tried copying it
to /etc/gconf/gconf.xml-mandatory/apps/evolution/mail (does it use a
different format?).  I even tried removing the stuff in
~/.gconf/apps/evolution/mail, and it just came up like the values didn't
exist.  I tried a few other things besides, to make sure i wasn't making
a mistake.

What did i do wrong?  Or did we misunderstand gconf?

But basically, it looks like we just wasted our time with a big bunch of
code, and we're going to have to move to doing everything via policy
keys and then enforcing the policies in the client code.

I hate gconf.

Index: e-util/e-account.c
===================================================================
RCS file: /cvs/gnome/evolution/e-util/e-account.c,v
retrieving revision 1.6
diff -u -3 -r1.6 e-account.c
--- e-util/e-account.c	14 Jan 2004 17:29:24 -0000	1.6
+++ e-util/e-account.c	17 Mar 2004 05:58:56 -0000
@@ -32,9 +32,46 @@
 #include <libxml/tree.h>
 #include <libxml/xmlmemory.h>
 
+#include <gconf/gconf-client.h>
+
 #define PARENT_TYPE G_TYPE_OBJECT
 static GObjectClass *parent_class = NULL;
 
+/*
+lock mail accounts	Relatively difficult -- involves redesign of the XML blobs which describe accounts
+disable adding mail accounts	Simple -- can be done with just a Gconf key and some UI work to make assoc. widgets unavailable
+disable editing mail accounts	Relatively difficult -- involves redesign of the XML blobs which describe accounts
+disable removing mail accounts	
+lock default character encoding	Simple -- Gconf key + a little UI work to desensitize widgets, etc
+disable free busy publishing	
+disable specific mime types (from being viewed)	90% done already (Unknown MIME types still pose a problem)
+lock image loading preference	
+lock junk mail filtering settings	
+**  junk mail per account
+lock work week	
+lock first day of work week	
+lock working hours	
+disable forward as icalendar	
+lock color options for tasks	
+lock default contact filing format	
+* forbid signatures	Simple -- can be done with just a Gconf key and some UI work to make assoc. widgets unavailable
+* lock user to having 1 specific signature	Simple -- can be done with just a Gconf key and some UI work to make assoc. widgets unavailable
+* forbid adding/removing signatures	Simple -- can be done with just a Gconf key and some UI work to make assoc. widgets unavailable
+* lock each account to a certain signature	Relatively difficult -- involved redesign of the XML blobs which describe accounts 
+* set default folders	
+set trash emptying frequency	
+* lock displayed mail headers	Simple -- can be done with just a Gconf key and some UI work to make assoc. widgets unavailable
+* lock authentication type (for incoming mail)	Relatively difficult -- involves redesign of the XML blobs which describe accounts
+* lock authentication type (for outgoing mail)	Relatively difficult -- involves redesign of the XML blobs which describe accounts
+* lock minimum check mail on server frequency	Simple -- can be done with just a Gconf key and some UI work to make assoc. widgets unavailable
+** lock save password
+* require ssl always	Relatively difficult -- involves redesign of the XML blobs which describe accounts
+** lock imap subscribed folder option
+** lock filtering of inbox
+** lock source account/options
+** lock destination account/options
+*/
+
 static void finalize (GObject *);
 
 static void
@@ -528,7 +565,6 @@
 	return tmp;
 }
 
-
 /**
  * e_account_uid_from_xml:
  * @xml: an XML account description
@@ -558,3 +594,189 @@
 
 	return uid;
 }
+
+enum {
+	EAP_IMAP_SUBSCRIBED = 0,
+	EAP_IMAP_NAMESPACE,
+	EAP_FILTER_INBOX,
+	EAP_FILTER_JUNK,
+	EAP_FORCE_SSL,
+	EAP_LOCK_SIGNATURE,
+	EAP_LOCK_AUTH,
+	EAP_LOCK_AUTOCHECK,
+	EAP_LOCK_DEFAULT_FOLDERS,
+	EAP_LOCK_SAVE_PASSWD,
+	EAP_LOCK_SOURCE_URL,
+	EAP_LOCK_TRANSPORT_URL,
+};
+
+static struct _system_info {
+	const char *key;
+	guint32 perm;
+} system_perms[] = {
+	{ "imap_subscribed", 1<<EAP_IMAP_SUBSCRIBED },
+	{ "imap_namespace", 1<<EAP_IMAP_NAMESPACE },
+	{ "filter_inbox", 1<<EAP_FILTER_INBOX },
+	{ "filter_junk", 1<<EAP_FILTER_JUNK },
+	{ "force_ssl", 1<<EAP_FORCE_SSL },
+	{ "signature", 1<<EAP_LOCK_SIGNATURE },
+	{ "authtype", 1<<EAP_LOCK_AUTH },
+	{ "autocheck", 1<<EAP_LOCK_AUTOCHECK },
+	{ "default_folders", 1<<EAP_LOCK_DEFAULT_FOLDERS },
+	{ "save_passwd" , 1<<EAP_LOCK_SAVE_PASSWD },
+/*	{ "source_url", 1<<EAP_LOCK_SOURCE_URL },
+	{ "transport_url", 1<<EAP_LOCK_TRANSPORT_URL },*/
+};
+
+static struct {
+	guint32 perms;
+} account_perms[E_ACCOUNT_ITEM_LAST] = {
+	{ /* E_ACCOUNT_ID_NAME, */ },
+	{ /* E_ACCOUNT_ID_ADDRESS, */ },
+	{ /* E_ACCOUNT_ID_REPLY_TO, */ },
+	{ /* E_ACCOUNT_ID_ORGANIZATION */ },
+	{ /* E_ACCOUNT_ID_DEF_SIGNATURE */ 1<<EAP_LOCK_SIGNATURE },
+	{ /* E_ACCOUNT_ID_AUTO_SIGNATURE */ 1<<EAP_LOCK_SIGNATURE },
+
+	{ /* E_ACCOUNT_SOURCE_URL */ },
+	{ /* E_ACCOUNT_SOURCE_KEEP_ON_SERVER */ },
+	{ /* E_ACCOUNT_SOURCE_AUTO_CHECK */ 1<<EAP_LOCK_AUTOCHECK },
+	{ /* E_ACCOUNT_SOURCE_AUTO_CHECK_TIME */ 1<<EAP_LOCK_AUTOCHECK },
+	{ /* E_ACCOUNT_SOURCE_SAVE_PASSWD */ 1<<EAP_LOCK_SAVE_PASSWD },
+
+	{ /* E_ACCOUNT_TRANSPORT_URL */ },
+	{ /* E_ACCOUNT_TRANSPORT_SAVE_PASSWD */ 1<<EAP_LOCK_SAVE_PASSWD },
+
+	{ /* E_ACCOUNT_DRAFTS_FOLDER_URI */ 1<<EAP_LOCK_DEFAULT_FOLDERS },
+	{ /* E_ACCOUNT_SENT_FOLDER_URI */ 1<<EAP_LOCK_DEFAULT_FOLDERS },
+
+	{ /* E_ACCOUNT_CC_ALWAYS */ },
+	{ /* E_ACCOUNT_CC_ADDRS */ },
+
+	{ /* E_ACCOUNT_BCC_ALWAYS */ },
+	{ /* E_ACCOUNT_BCC_ADDRS */ },
+
+	{ /* E_ACCOUNT_PGP_KEY */ },
+	{ /* E_ACCOUNT_PGP_ENCRYPT_TO_SELF */ },
+	{ /* E_ACCOUNT_PGP_ALWAYS_SIGN */ },
+	{ /* E_ACCOUNT_PGP_NO_IMIP_SIGN */ },
+	{ /* E_ACCOUNT_PGP_ALWAYS_TRUST */ },
+
+	{ /* E_ACCOUNT_SMIME_SIGN_KEY */ },
+	{ /* E_ACCOUNT_SMIME_ENCRYPT_KEY */ },
+	{ /* E_ACCOUNT_SMIME_SIGN_DEFAULT */ },
+	{ /* E_ACCOUNT_SMIME_ENCRYPT_TO_SELF */ },
+	{ /* E_ACCOUNT_SMIME_ENCRYPE_DEFAULT */ },
+};
+
+static GHashTable *ea_option_table;
+static GHashTable *ea_system_table;
+static guint32 ea_perms;
+
+static struct _option_info {
+	char *key;
+	guint32 perms;
+} ea_option_list[] = {
+	{ "imap_use_lsub", 1<<EAP_IMAP_SUBSCRIBED },
+	{ "imap_override_namespace", 1<<EAP_IMAP_NAMESPACE },
+	{ "imap_filter", 1<<EAP_FILTER_INBOX },
+	{ "imap_filter_junk", 1<<EAP_FILTER_JUNK },
+	{ "imap_filter_junk_inbox", 1<<EAP_FILTER_JUNK },
+	{ "*_use_ssl", 1<<EAP_FORCE_SSL },
+	{ "*_auth", 1<<EAP_LOCK_AUTH },
+};
+
+#define LOCK_BASE "/apps/evolution/lock/mail/accounts"
+
+static void
+ea_setting_notify(GConfClient *gconf, guint cnxn_id, GConfEntry *entry, void *crap)
+{
+	GConfValue *value;
+	char *tkey;
+	struct _system_info *info;
+
+	g_return_if_fail (gconf_entry_get_key (entry) != NULL);
+	
+	if (!(value = gconf_entry_get_value (entry)))
+		return;
+	
+	tkey = strrchr(entry->key, '/');
+	g_return_if_fail (tkey != NULL);
+
+	info = g_hash_table_lookup(ea_system_table, tkey+1);
+	if (info) {
+		if (gconf_value_get_bool(value))
+			ea_perms |= info->perm;
+		else
+			ea_perms &= ~info->perm;
+	}
+
+	printf("checking key '%s', new perms '%08x'\n", tkey+1, ea_perms);
+}
+
+static void
+ea_setting_setup(void)
+{
+	if (ea_option_table == NULL) {
+		GConfClient *gconf = gconf_client_get_default();
+		GConfEntry *entry;
+		GError *err = NULL;
+		int i;
+		char key[64];
+
+		ea_option_table = g_hash_table_new(g_str_hash, g_str_equal);
+		for (i=0;i<sizeof(ea_option_list)/sizeof(ea_option_list[0]);i++)
+			g_hash_table_insert(ea_option_table, ea_option_list[i].key, &ea_option_list[i]);
+
+		gconf_client_add_dir(gconf, LOCK_BASE, GCONF_CLIENT_PRELOAD_NONE, NULL);
+
+		ea_system_table = g_hash_table_new(g_str_hash, g_str_equal);
+		for (i=0;i<sizeof(system_perms)/sizeof(system_perms[0]);i++) {
+			g_hash_table_insert(ea_system_table, (char *)system_perms[i].key, &system_perms[i]);
+			sprintf(key, LOCK_BASE "/%s", system_perms[i].key);
+			entry = gconf_client_get_entry(gconf, key, NULL, TRUE, &err);
+			if (entry)
+				ea_setting_notify(gconf, 0, entry, NULL);
+			gconf_entry_free(entry);
+		}
+
+		if (err) {
+			g_warning("Could not load account lock settings: %s", err->message);
+			g_error_free(err);
+		}
+
+		gconf_client_notify_add(gconf, LOCK_BASE, (GConfClientNotifyFunc)ea_setting_notify, NULL, NULL, NULL);
+		g_object_unref(gconf);
+	}
+}
+
+gboolean
+e_account_writable_option(EAccount *ea, const char *protocol, const char *option)
+{
+	char *key;
+	struct _option_info *info;
+
+	ea_setting_setup();
+
+	key = alloca(strlen(protocol)+strlen(option)+2);
+	sprintf(key, "%s_%s", protocol, option);
+
+	info = g_hash_table_lookup(ea_option_table, key);
+	if (info == NULL) {
+		sprintf(key, "*_%s", option);
+		info = g_hash_table_lookup(ea_option_table, key);
+	}
+
+	printf("checking writable option '%s' perms=%08x\n", option, info?info->perms:0);
+
+	return info == NULL
+		|| (info->perms & ea_perms) == 0;
+}
+
+gboolean
+e_account_writable(EAccount *ea, e_account_item_t type)
+{
+	ea_setting_setup();
+
+	return (account_perms[type].perms & ea_perms) == 0;
+}
Index: e-util/e-account.h
===================================================================
RCS file: /cvs/gnome/evolution/e-util/e-account.h,v
retrieving revision 1.4
diff -u -3 -r1.4 e-account.h
--- e-util/e-account.h	31 Oct 2003 04:55:41 -0000	1.4
+++ e-util/e-account.h	17 Mar 2004 05:58:56 -0000
@@ -28,6 +28,51 @@
 #define E_IS_ACCOUNT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_ACCOUNT))
 #define E_IS_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), E_TYPE_ACCOUNT))
 
+typedef enum _e_account_item_t {
+	E_ACCOUNT_ID_NAME,
+	E_ACCOUNT_ID_ADDRESS,
+	E_ACCOUNT_ID_REPLY_TO,
+	E_ACCOUNT_ID_ORGANIZATION,
+	E_ACCOUNT_ID_DEF_SIGNATURE, /* why aren't these two options the same? */
+	E_ACCOUNT_ID_AUTO_SIGNATURE,
+
+	E_ACCOUNT_SOURCE_URL,
+	E_ACCOUNT_SOURCE_KEEP_ON_SERVER,
+	E_ACCOUNT_SOURCE_AUTO_CHECK,
+	E_ACCOUNT_SOURCE_AUTO_CHECK_TIME,
+	E_ACCOUNT_SOURCE_SAVE_PASSWD,
+
+	E_ACCOUNT_TRANSPORT_URL,
+	E_ACCOUNT_TRANSPORT_SAVE_PASSWD,
+
+	E_ACCOUNT_DRAFTS_FOLDER_URI,
+	E_ACCOUNT_SENT_FOLDER_URI,
+
+	E_ACCOUNT_CC_ALWAYS,
+	E_ACCOUNT_CC_ADDRS,
+
+	E_ACCOUNT_BCC_ALWAYS,
+	E_ACCOUNT_BCC_ADDRS,
+
+	E_ACCOUNT_PGP_KEY,
+	E_ACCOUNT_PGP_ENCRYPT_TO_SELF,
+	E_ACCOUNT_PGP_ALWAYS_SIGN,
+	E_ACCOUNT_PGP_NO_IMIP_SIGN,
+	E_ACCOUNT_PGP_ALWAYS_TRUST,
+
+	E_ACCOUNT_SMIME_SIGN_KEY,
+	E_ACCOUNT_SMIME_ENCRYPT_KEY,
+	E_ACCOUNT_SMIME_SIGN_DEFAULT,
+	E_ACCOUNT_SMIME_ENCRYPT_TO_SELF,
+	E_ACCOUNT_SMIME_ENCRYPE_DEFAULT,
+
+	E_ACCOUNT_ITEM_LAST
+} e_account_item_t;
+
+typedef enum _e_account_access_t {
+	E_ACCOUNT_ACCESS_WRITE = 1<<0,
+} e_account_access_t;
+
 typedef struct {
 	char *name;
 	char *address;
@@ -46,7 +91,6 @@
 	gboolean save_passwd;
 } EAccountService;
 
-
 typedef struct {
 	GObject parent_object;
 
@@ -90,17 +134,22 @@
 EAccount *e_account_new          (void);
 
 EAccount *e_account_new_from_xml (const char *xml);
-
-gboolean  e_account_set_from_xml (EAccount   *account,
-				  const char *xml);
-
-void      e_account_import       (EAccount   *dest,
-				  EAccount   *src);
-
+gboolean  e_account_set_from_xml (EAccount   *account, const char *xml);
+void      e_account_import       (EAccount   *dest, EAccount   *src);
 char     *e_account_to_xml       (EAccount   *account);
-
-
 char     *e_account_uid_from_xml (const char *xml);
 
+#if 0
+const char *e_account_get_string(EAccount *, e_account_item_t type);
+int e_account_get_int(EAccount *, e_account_item_t type);
+gboolean e_account_get_bool(EAccount *, e_account_item_t type);
+
+void e_account_set_string(EAccount *, e_account_item_t type, const char *);
+void e_account_set_int(EAccount *, e_account_item_t type, const char *);
+void e_account_set_bool(EAccount *, e_account_item_t type, const char *);
+#endif
+
+gboolean e_account_writable(EAccount *ea, e_account_item_t type);
+gboolean e_account_writable_option(EAccount *ea, const char *protocol, const char *option);
 
 #endif /* __E_ACCOUNT__ */
Index: mail/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.3170
diff -u -3 -r1.3170 ChangeLog
--- mail/ChangeLog	16 Mar 2004 22:54:54 -0000	1.3170
+++ mail/ChangeLog	17 Mar 2004 05:59:03 -0000
@@ -1,3 +1,23 @@
+2004-03-17  Not Zed  <NotZed Ximian com>
+
+	* em-account-prefs.c (account_cursor_change): disable
+	editing/adding/removing accounts etc if accounts aren't editable.
+	(em_account_prefs_construct): call above after setup.
+
+	* mail-component.c (mc_quit_sync): if we have empty on exit days,
+	check that.  keep track of the last empty on exit time.
+
+	* em-mailer-prefs.c (emmp_empty_trash_init): init the trash stuff
+	here.
+	(em_mailer_prefs_apply): save empty trash on exit frequency.
+
+2004-03-16  Not Zed  <NotZed Ximian com>
+
+	* mail-account-gui.c (mail_account_gui_auto_detect_extra_conf):
+	check extra conf items are writable.
+	(mail_account_gui_build_extra_conf): same.
+	(setup_service): add gui arg, and do above for auth and ssl args.
+
 2004-03-16  Jeffrey Stedfast  <fejj ximian com>
 
 	Fix for bug #55358.
Index: mail/em-account-prefs.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-account-prefs.c,v
retrieving revision 1.2
diff -u -3 -r1.2 em-account-prefs.c
--- mail/em-account-prefs.c	13 Nov 2003 22:33:02 -0000	1.2
+++ mail/em-account-prefs.c	17 Mar 2004 05:59:04 -0000
@@ -389,18 +389,23 @@
 	GtkTreeModel *model;
 	GtkTreeIter iter;
 	int state;
-	
-	state = gtk_tree_selection_get_selected (selection, &model, &iter);
+
+	state = gconf_client_key_is_writable(mail_config_get_gconf_client(), "/apps/evolution/mail/accounts", NULL);
 	if (state) {
-		gtk_tree_model_get (model, &iter, 3, &account, -1);
-		if (account->source && account->enabled)
-			gtk_button_set_label (prefs->mail_able, _("Disable"));
-		else
-			gtk_button_set_label (prefs->mail_able, _("Enable"));
+		state = gtk_tree_selection_get_selected (selection, &model, &iter);
+		if (state) {
+			gtk_tree_model_get (model, &iter, 3, &account, -1);
+			if (account->source && account->enabled)
+				gtk_button_set_label (prefs->mail_able, _("Disable"));
+			else
+				gtk_button_set_label (prefs->mail_able, _("Enable"));
+		} else {
+			gtk_widget_grab_focus (GTK_WIDGET (prefs->mail_add));
+		}
 	} else {
-		gtk_widget_grab_focus (GTK_WIDGET (prefs->mail_add));
+		gtk_widget_set_sensitive (GTK_WIDGET (prefs->mail_add), FALSE);
 	}
-	
+
 	gtk_widget_set_sensitive (GTK_WIDGET (prefs->mail_edit), state);
 	gtk_widget_set_sensitive (GTK_WIDGET (prefs->mail_delete), state);
 	gtk_widget_set_sensitive (GTK_WIDGET (prefs->mail_default), state);
@@ -557,8 +562,9 @@
 	
 	prefs->mail_able = GTK_BUTTON (glade_xml_get_widget (gui, "cmdAccountAble"));
 	g_signal_connect (prefs->mail_able, "clicked", G_CALLBACK (account_able_clicked), prefs);
-}
 
+	account_cursor_change(gtk_tree_view_get_selection(prefs->table), prefs);
+}
 
 GtkWidget *
 em_account_prefs_new (GNOME_Evolution_Shell shell)
Index: mail/em-mailer-prefs.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-mailer-prefs.c,v
retrieving revision 1.9
diff -u -3 -r1.9 em-mailer-prefs.c
--- mail/em-mailer-prefs.c	3 Mar 2004 06:39:09 -0000	1.9
+++ mail/em-mailer-prefs.c	17 Mar 2004 05:59:06 -0000
@@ -76,6 +76,17 @@
 
 #define EM_FORMAT_HEADER_XMAILER "x-evolution-mailer"
 
+/* for empty trash on exit frequency */
+static const struct {
+	const char *label;
+	int days;
+} empty_trash_frequency[] = {
+	{ N_("Every time"), 0 },
+	{ N_("Once per day"), 1 },
+	{ N_("Once per week"), 7 },
+	{ N_("Once per month"), 30 },
+};
+
 GtkType
 em_mailer_prefs_get_type (void)
 {
@@ -234,7 +245,6 @@
 	}
 }
 
-
 static void
 emmp_header_remove_sensitivity (EMMailerPrefs *prefs)
 {
@@ -445,6 +455,36 @@
 }
 
 static void
+emmp_empty_trash_init(EMMailerPrefs *prefs)
+{
+	int days, hist = 0, i;
+	GtkWidget *menu, *item;
+
+	toggle_button_init (prefs->empty_trash, prefs->gconf,
+			    "/apps/evolution/mail/trash/empty_on_exit",
+			    FALSE, G_CALLBACK (settings_changed), prefs);
+
+	days = gconf_client_get_int(prefs->gconf, "/apps/evolution/mail/trash/empty_on_exit_days", NULL);
+	menu = gtk_menu_new();
+	for (i=0;i<sizeof(empty_trash_frequency)/sizeof(empty_trash_frequency[0]);i++) {
+		if (days >= empty_trash_frequency[i].days)
+			hist = i;
+
+		item = gtk_menu_item_new_with_label(_(empty_trash_frequency[i].label));
+		gtk_widget_show(item);
+		gtk_menu_shell_append((GtkMenuShell *)menu, item);
+	}
+
+	gtk_widget_show(menu);
+	gtk_option_menu_set_menu((GtkOptionMenu *)prefs->empty_trash_days, menu);
+	gtk_option_menu_set_history((GtkOptionMenu *)prefs->empty_trash_days, hist);
+	g_signal_connect(prefs->empty_trash_days, "changed", G_CALLBACK(settings_changed), prefs);
+
+	gtk_widget_set_sensitive((GtkWidget *)prefs->empty_trash_days,
+				 gconf_client_key_is_writable(prefs->gconf, "/apps/evolution/mail/trash/empty_on_exit_days", NULL));
+}
+
+static void
 em_mailer_prefs_construct (EMMailerPrefs *prefs)
 {
 	GSList *list, *header_config_list, *header_add_list, *p;
@@ -507,9 +547,8 @@
 	
 	/* Deleting Mail */
 	prefs->empty_trash = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkEmptyTrashOnExit"));
-	toggle_button_init (prefs->empty_trash, prefs->gconf,
-			    "/apps/evolution/mail/trash/empty_on_exit",
-			    FALSE, G_CALLBACK (settings_changed), prefs);
+	prefs->empty_trash_days = GTK_OPTION_MENU(glade_xml_get_widget (gui, "omenuEmptyTrashDays"));
+	emmp_empty_trash_init(prefs);
 	
 	prefs->confirm_expunge = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkConfirmExpunge"));
 	toggle_button_init (prefs->confirm_expunge, prefs->gconf,
@@ -813,6 +852,12 @@
 	/* Deleting Mail */
 	gconf_client_set_bool (prefs->gconf, "/apps/evolution/mail/trash/empty_on_exit",
 			       gtk_toggle_button_get_active (prefs->empty_trash), NULL);
+	val = gtk_option_menu_get_history(prefs->empty_trash_days);
+	if (val > sizeof(empty_trash_frequency)/sizeof(empty_trash_frequency[0]))
+		val = sizeof(empty_trash_frequency)/sizeof(empty_trash_frequency[0]);
+	if (val < 0)
+		val = 0;
+	gconf_client_set_int(prefs->gconf, "/apps/evolution/mail/trash/empty_on_exit_days", empty_trash_frequency[val].days, NULL);
 	
 	gconf_client_set_bool (prefs->gconf, "/apps/evolution/mail/prompts/expunge",
 			       gtk_toggle_button_get_active (prefs->confirm_expunge), NULL);
Index: mail/em-mailer-prefs.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-mailer-prefs.h,v
retrieving revision 1.8
diff -u -3 -r1.8 em-mailer-prefs.h
--- mail/em-mailer-prefs.h	3 Mar 2004 06:39:09 -0000	1.8
+++ mail/em-mailer-prefs.h	17 Mar 2004 05:59:06 -0000
@@ -78,6 +78,7 @@
 	
 	/* Deleting Mail */
 	GtkToggleButton *empty_trash;
+	GtkOptionMenu *empty_trash_days;
 	GtkToggleButton *confirm_expunge;
 	
 	/* New Mail Notification */
Index: mail/evolution-mail.schemas.in.in
===================================================================
RCS file: /cvs/gnome/evolution/mail/evolution-mail.schemas.in.in,v
retrieving revision 1.9
diff -u -3 -r1.9 evolution-mail.schemas.in.in
--- mail/evolution-mail.schemas.in.in	3 Mar 2004 06:39:09 -0000	1.9
+++ mail/evolution-mail.schemas.in.in	17 Mar 2004 05:59:07 -0000
@@ -652,6 +652,34 @@
       </locale>
     </schema>
 
+    <schema>
+      <key>/schemas/apps/evolution/mail/trash/empty_on_exit_days</key>
+      <applyto>/apps/evolution/mail/trash/empty_on_exit_days</applyto>
+      <owner>evolution-mail</owner>
+      <type>int</type>
+      <default>0</default>
+      <locale name="C">
+         <short>Minimum days between emptying the trash on exit</short>
+         <long>
+	Minimum time between emptying the trash on exit, in days.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/evolution/mail/trash/empty_date</key>
+      <applyto>/apps/evolution/mail/trash/empty_date</applyto>
+      <owner>evolution-mail</owner>
+      <type>int</type>
+      <default>0</default>
+      <locale name="C">
+         <short>Last time empty trash was run</short>
+         <long>
+	The last time empty trash was run, in days since the epoch.
+         </long>
+      </locale>
+    </schema>
+
     <!-- Labels and Colours -->
 
     <schema>
Index: mail/mail-account-gui.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-account-gui.c,v
retrieving revision 1.148
diff -u -3 -r1.148 mail-account-gui.c
--- mail/mail-account-gui.c	24 Feb 2004 21:31:19 -0000	1.148
+++ mail/mail-account-gui.c	17 Mar 2004 05:59:10 -0000
@@ -286,6 +286,8 @@
 		entries = service->provider->extra_conf;
 		
 		for (i = 0; entries[i].type != CAMEL_PROVIDER_CONF_END; i++) {
+			GtkWidget *enable_widget = NULL;
+
 			if (!entries[i].name)
 				continue;
 			
@@ -297,12 +299,14 @@
 			case CAMEL_PROVIDER_CONF_CHECKBOX:
 				toggle = g_hash_table_lookup (gui->extra_config, entries[i].name);
 				gtk_toggle_button_set_active (toggle, atoi (value));
+				enable_widget = (GtkWidget *)toggle;
 				break;
 				
 			case CAMEL_PROVIDER_CONF_ENTRY:
 				entry = g_hash_table_lookup (gui->extra_config, entries[i].name);
 				if (value)
 					gtk_entry_set_text (entry, value);
+				enable_widget = (GtkWidget *)entry;
 				break;
 				
 			case CAMEL_PROVIDER_CONF_CHECKSPIN:
@@ -321,11 +325,16 @@
 				g_assert (*value == ':');
 				val = strtod (++value, NULL);
 				gtk_spin_button_set_value (spin, val);
+				enable_widget = (GtkWidget *)spin;
 			}
 			break;
 			default:
 				break;
 			}
+
+			if (enable_widget)
+				gtk_widget_set_sensitive(enable_widget, e_account_writable_option(gui->account, prov->protocol, entries[i].name));
+
 		}
 		
 		g_hash_table_foreach (auto_detected, auto_detected_foreach, NULL);
@@ -811,6 +820,8 @@
 	cur_table = main_table;
 	rows = main_table->nrows;
 	for (i = 0; ; i++) {
+		GtkWidget *enable_widget = NULL;
+
 		switch (entries[i].type) {
 		case CAMEL_PROVIDER_CONF_SECTION_START:
 		{
@@ -846,10 +857,13 @@
 				
 				if (!strcmp (entries[i].name, "username")) {
 					gtk_label_set_text_with_mnemonic (GTK_LABEL (username_label), entries[i].text);
+					enable_widget = username_label;
 				} else if (!strcmp (entries[i].name, "hostname")) {
 					gtk_label_set_text_with_mnemonic (GTK_LABEL (hostname_label), entries[i].text);
+					enable_widget = hostname_label;
 				} else if (!strcmp (entries[i].name, "path")) {
 					gtk_label_set_text_with_mnemonic (GTK_LABEL (path_label), entries[i].text);
+					enable_widget = path_label;
 				} else {
 					/* make a new label */
 					label = gtk_label_new (entries[i].text);
@@ -857,6 +871,7 @@
 					gtk_table_attach (cur_table, label, 0, 2, rows, rows + 1,
 							  GTK_EXPAND | GTK_FILL, 0, 0, 0);
 					rows++;
+					enable_widget = label;
 				}
 			}
 			break;
@@ -879,6 +894,8 @@
 			g_hash_table_insert (gui->extra_config, entries[i].name, checkbox);
 			if (entries[i].depname)
 				setup_toggle (checkbox, entries[i].depname, gui);
+
+			enable_widget = checkbox;
 			break;
 		}
 		
@@ -926,7 +943,8 @@
 			}
 
 			g_hash_table_insert (gui->extra_config, entries[i].name, entry);
-						
+
+			enable_widget = entry;
 			break;
 		}
 		
@@ -990,12 +1008,17 @@
 				setup_toggle (spin, entries[i].depname, gui);
 				setup_toggle (label, entries[i].depname, gui);
 			}
+
+			enable_widget = hbox;
 			break;
 		}
 		
 		case CAMEL_PROVIDER_CONF_END:
 			goto done;
 		}
+
+		if (enable_widget)
+			gtk_widget_set_sensitive(enable_widget, e_account_writable_option(gui->account, gui->source.provider->protocol, entries[i].name));
 	}
 	
  done:
@@ -1099,7 +1122,7 @@
 }
 
 static gboolean
-setup_service (MailAccountGuiService *gsvc, EAccountService *service)
+setup_service (MailAccountGui *gui, MailAccountGuiService *gsvc, EAccountService *service)
 {
 	CamelURL *url = camel_url_new (service->url, NULL);
 	gboolean has_auth = FALSE;
@@ -1169,6 +1192,9 @@
 	camel_url_free (url);
 	
 	gtk_toggle_button_set_active (gsvc->remember, service->save_passwd);
+
+	gtk_widget_set_sensitive((GtkWidget *)gsvc->authtype, e_account_writable_option(gui->account, gsvc->provider->protocol, "auth"));
+	gtk_widget_set_sensitive((GtkWidget *)gsvc->use_ssl, e_account_writable_option(gui->account, gsvc->provider->protocol, "use_ssl"));
 	
 	return has_auth;
 }
@@ -1599,8 +1625,8 @@
 	em_folder_selection_button_set_selection((EMFolderSelectionButton *)gui->sent_folder_button, gui->sent_folder_uri);
 	
 	/* Special Folders "Reset Defaults" button */
-	button = glade_xml_get_widget (gui->xml, "default_folders_button");
-	g_signal_connect (button, "clicked", G_CALLBACK (default_folders_clicked), gui);
+	gui->restore_folders_button = glade_xml_get_widget (gui->xml, "default_folders_button");
+	g_signal_connect (gui->restore_folders_button, "clicked", G_CALLBACK (default_folders_clicked), gui);
 	
 	/* Always Cc */
 	gui->always_cc = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui->xml, "always_cc"));
@@ -1663,7 +1689,7 @@
 		gtk_widget_destroy (frame);
 	}
 #endif /* HAVE_NSS */
-	
+
 	return gui;
 }
 
@@ -1677,6 +1703,8 @@
 	char *max_authname = NULL;
 	char *source_proto, *transport_proto;
 	GList *providers, *l;
+
+	printf("account gui setup\n");
 	
 	if (gui->account->source && gui->account->source->url) {
 		source_proto = gui->account->source->url;
@@ -1834,7 +1862,7 @@
 	}
 	
 	if (source_proto) {
-		setup_service (&gui->source, gui->account->source);
+		setup_service (gui, &gui->source, gui->account->source);
 		gui->source.provider_type = CAMEL_PROVIDER_STORE;
 		g_free (source_proto);
 		if (gui->account->source->auto_check) {
@@ -1845,11 +1873,32 @@
 	}
 	
 	if (transport_proto) {
-		if (setup_service (&gui->transport, gui->account->transport))
+		if (setup_service (gui, &gui->transport, gui->account->transport))
 			gtk_toggle_button_set_active (gui->transport_needs_auth, TRUE);
 		gui->transport.provider_type = CAMEL_PROVIDER_TRANSPORT;
 		g_free (transport_proto);
 	}
+
+	/* FIXME: drive by table?? */
+	if (gui->source.provider) {
+		gtk_widget_set_sensitive((GtkWidget *)gui->source.authtype, e_account_writable_option(gui->account, gui->source.provider->protocol, "auth"));
+		gtk_widget_set_sensitive((GtkWidget *)gui->source.use_ssl, e_account_writable_option(gui->account, gui->source.provider->protocol, "use_ssl"));
+	}
+	if (gui->transport.provider) {
+		gtk_widget_set_sensitive((GtkWidget *)gui->transport.authtype, e_account_writable_option(gui->account, gui->transport.provider->protocol, "auth"));
+		gtk_widget_set_sensitive((GtkWidget *)gui->transport.use_ssl, e_account_writable_option(gui->account, gui->transport.provider->protocol, "use_ssl"));
+	}
+
+	gtk_widget_set_sensitive((GtkWidget *)gui->drafts_folder_button, e_account_writable(gui->account, E_ACCOUNT_DRAFTS_FOLDER_URI));
+	gtk_widget_set_sensitive((GtkWidget *)gui->sent_folder_button, e_account_writable(gui->account, E_ACCOUNT_SENT_FOLDER_URI));
+	gtk_widget_set_sensitive((GtkWidget *)gui->restore_folders_button,
+				 e_account_writable(gui->account, E_ACCOUNT_SENT_FOLDER_URI)
+				 || e_account_writable(gui->account, E_ACCOUNT_DRAFTS_FOLDER_URI));
+	gtk_widget_set_sensitive((GtkWidget *)gui->source.remember, e_account_writable(gui->account, E_ACCOUNT_SOURCE_SAVE_PASSWD));
+	gtk_widget_set_sensitive((GtkWidget *)gui->transport.remember, e_account_writable(gui->account, E_ACCOUNT_TRANSPORT_SAVE_PASSWD));
+	gtk_widget_set_sensitive((GtkWidget *)gui->sig_option_menu, e_account_writable(gui->account, E_ACCOUNT_ID_DEF_SIGNATURE));
+	gtk_widget_set_sensitive((GtkWidget *)gui->source_auto_check, e_account_writable(gui->account, E_ACCOUNT_SOURCE_AUTO_CHECK));
+	gtk_widget_set_sensitive((GtkWidget *)gui->source_auto_check_min, e_account_writable(gui->account, E_ACCOUNT_SOURCE_AUTO_CHECK_TIME));
 }
 
 static void
Index: mail/mail-account-gui.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-account-gui.h,v
retrieving revision 1.26
diff -u -3 -r1.26 mail-account-gui.h
--- mail/mail-account-gui.h	31 Oct 2003 04:56:46 -0000	1.26
+++ mail/mail-account-gui.h	17 Mar 2004 05:59:10 -0000
@@ -95,7 +95,8 @@
 	char *drafts_folder_uri;
 	GtkButton *sent_folder_button;
 	char *sent_folder_uri;
-	
+	GtkButton *restore_folders_button;
+
 	/* always cc/bcc */
 	GtkToggleButton *always_cc;
 	GtkEntry *cc_addrs;
Index: mail/mail-component.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-component.c,v
retrieving revision 1.64
diff -u -3 -r1.64 mail-component.c
--- mail/mail-component.c	16 Mar 2004 22:54:55 -0000	1.64
+++ mail/mail-component.c	17 Mar 2004 05:59:11 -0000
@@ -539,10 +539,19 @@
 static void
 mc_quit_sync(CamelStore *store, struct _store_info *si, MailComponent *mc)
 {
-	int expunge = gconf_client_get_bool(mail_config_get_gconf_client(), "/apps/evolution/mail/trash/empty_on_exit", NULL);
+	GConfClient *gconf = mail_config_get_gconf_client();
+	gboolean expunge;
+	int now = time(NULL)/60/60/24, days;
+
+	expunge = gconf_client_get_bool(gconf, "/apps/evolution/mail/trash/empty_on_exit", NULL)
+		&& ((days = gconf_client_get_int(gconf, "/apps/evolution/mail/trash/empty_on_exit_days", NULL)) == 0
+		     || (days + gconf_client_get_int(gconf, "/apps/evolution/mail/trash/empty_date", NULL)) <= now);
 
 	mc->priv->quit_count++;
 	mail_sync_store(store, expunge, mc_quit_sync_done, mc);
+
+	if (expunge)
+		gconf_client_set_int(gconf, "/apps/evolution/mail/trash/empty_date", now, NULL);
 }
 
 static CORBA_boolean
Index: mail/mail-config.glade
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-config.glade,v
retrieving revision 1.131
diff -u -3 -r1.131 mail-config.glade
--- mail/mail-config.glade	3 Mar 2004 06:39:10 -0000	1.131
+++ mail/mail-config.glade	17 Mar 2004 05:59:20 -0000
@@ -3764,15 +3764,46 @@
 		  <property name="spacing">3</property>
 
 		  <child>
-		    <widget class="GtkCheckButton" id="chkEmptyTrashOnExit">
+		    <widget class="GtkHBox" id="hbox177">
 		      <property name="visible">True</property>
-		      <property name="can_focus">True</property>
-		      <property name="label" translatable="yes">Empty _trash folders on exit</property>
-		      <property name="use_underline">True</property>
-		      <property name="relief">GTK_RELIEF_NORMAL</property>
-		      <property name="active">False</property>
-		      <property name="inconsistent">False</property>
-		      <property name="draw_indicator">True</property>
+		      <property name="homogeneous">False</property>
+		      <property name="spacing">3</property>
+
+		      <child>
+			<widget class="GtkCheckButton" id="chkEmptyTrashOnExit">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="label" translatable="yes">Empty _trash folders on exit</property>
+			  <property name="use_underline">True</property>
+			  <property name="relief">GTK_RELIEF_NORMAL</property>
+			  <property name="active">False</property>
+			  <property name="inconsistent">False</property>
+			  <property name="draw_indicator">True</property>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">False</property>
+			  <property name="fill">False</property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkOptionMenu" id="omenuEmptyTrashDays">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="history">-1</property>
+
+			  <child>
+			    <widget class="GtkMenu" id="menu1">
+			    </widget>
+			  </child>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">False</property>
+			  <property name="fill">False</property>
+			</packing>
+		      </child>
 		    </widget>
 		    <packing>
 		      <property name="padding">0</property>

Attachment: empty-trash-exit.png
Description: Binary data



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]