Re: [Evolution-hackers] Proposal to auto-update the composer's from optionmenu when account info changes



The UI department (er, me :) thinks this sounds like a nice, useful,
logical change. 

(I can't comment on the way it is implemented, of course, but I do think
that the behavior it provides is desirable.)

-Anna




On Wed, 2003-01-22 at 14:51, Jeffrey Stedfast wrote:
> http://bugzilla.ximian.com/show_bug.cgi?id=3862
> 
> This is now doable so I went ahead and implemented it. Ettore thought
> that since this is a UI change that I should bring it up on the list, so
> here we are.
> 
> The other option, of course, is to just leave things sty the way they
> are where the composer owns a "copy" of the accounts that existed at the
> time that the composer was instantiated.
> 
> Jeff
> 
> ______________________________________________________________________
> 
> ? mail/accounts.xml
> ? mail/evolution-mail-account.schemas
> ? mail/fb.c
> ? mail/mail-account-list.h
> ? mail/mail-account.c
> ? mail/mail-account.h
> Index: composer/ChangeLog
> ===================================================================
> RCS file: /cvs/gnome/evolution/composer/ChangeLog,v
> retrieving revision 1.486
> diff -u -r1.486 ChangeLog
> --- composer/ChangeLog	17 Jan 2003 23:32:07 -0000	1.486
> +++ composer/ChangeLog	22 Jan 2003 19:41:40 -0000
> @@ -1,3 +1,17 @@
> +2003-01-22  Jeffrey Stedfast  <fejj ximian com>
> +
> +	* e-msg-composer-hdrs.c (init): Get the list of accounts here and
> +	ref the account-list.
> +	(destroy): Unref the accounts list here.
> +	(create_from_optionmenu): Connect to the added/changed/removed
> +	account-list signals here.
> +	(account_added_cb): New callback function that adds the newly
> +	added account to the from-dropdown menu.
> +	(account_changed_cb): New callback that changes the label for the
> +	account that got changed in the dropdown menu.
> +	(account_removed_cb): Removes the account from the from dropdown
> +	menu.
> +
>  2003-01-17  Jeffrey Stedfast  <fejj ximian com>
>  
>  	* evolution-composer.c (impl_Composer_set_headers): Updated to use
> Index: composer/e-msg-composer-hdrs.c
> ===================================================================
> RCS file: /cvs/gnome/evolution/composer/e-msg-composer-hdrs.c,v
> retrieving revision 1.103
> diff -u -r1.103 e-msg-composer-hdrs.c
> --- composer/e-msg-composer-hdrs.c	17 Jan 2003 23:32:07 -0000	1.103
> +++ composer/e-msg-composer-hdrs.c	22 Jan 2003 19:41:40 -0000
> @@ -80,6 +80,7 @@
>  	/* The tooltips.  */
>  	GtkTooltips *tooltips;
>  	
> +	EAccountList *accounts;
>  	GSList *from_options;
>  	
>  	/* Standard headers.  */
> @@ -189,17 +190,115 @@
>  	g_signal_emit (hdrs, signals [FROM_CHANGED], 0);
>  }
>  
> +static void
> +account_added_cb (EAccountList *accounts, EAccount *account, EMsgComposerHdrs *hdrs)
> +{
> +	GtkWidget *item, *menu, *omenu, *toplevel;
> +	char *label;
> +	
> +	omenu = e_msg_composer_hdrs_get_from_omenu (hdrs);
> +	menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (omenu));
> +	
> +	label = g_strdup_printf ("%s <%s>", account->id->name, account->id->address);
> +	item = gtk_menu_item_new_with_label (label);
> +	gtk_widget_show (item);
> +	g_free (label);
> +	
> +	g_object_ref (account);
> +	g_object_set_data ((GObject *) item, "account", account);
> +	g_signal_connect (item, "activate", G_CALLBACK (from_changed), hdrs);
> +	
> +	/* this is so we can later set which one we want */
> +	hdrs->priv->from_options = g_slist_append (hdrs->priv->from_options, item);
> +	
> +	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
> +	
> +	toplevel = gtk_widget_get_toplevel ((GtkWidget *) hdrs);
> +	gtk_widget_set_sensitive (toplevel, TRUE);
> +}
> +
> +static void
> +account_changed_cb (EAccountList *accounts, EAccount *account, EMsgComposerHdrs *hdrs)
> +{
> +	GtkWidget *item, *label;
> +	EAccount *acnt;
> +	GSList *node;
> +	char *text;
> +	
> +	node = hdrs->priv->from_options;
> +	while (node != NULL) {
> +		item = node->data;
> +		acnt = g_object_get_data ((GObject *) item, "account");
> +		if (acnt == account) {
> +			text = g_strdup_printf ("%s <%s>", account->id->name, account->id->address);
> +			label = gtk_bin_get_child ((GtkBin *) item);
> +			gtk_label_set_text ((GtkLabel *) label, text);
> +			g_free (text);
> +			break;
> +		}
> +		
> +		node = node->next;
> +	}
> +}
> +
> +static void
> +account_removed_cb (EAccountList *accounts, EAccount *account, EMsgComposerHdrs *hdrs)
> +{
> +	struct _EMsgComposerHdrsPrivate *priv = hdrs->priv;
> +	GtkWidget *item, *omenu, *toplevel, *dialog;
> +	EAccount *acnt;
> +	GSList *node;
> +	
> +	node = priv->from_options;
> +	while (node != NULL) {
> +		item = node->data;
> +		acnt = g_object_get_data ((GObject *) item, "account");
> +		if (acnt == account) {
> +			if (hdrs->account == account)
> +				hdrs->account = NULL;
> +			
> +			priv->from_options = g_slist_remove_link (priv->from_options, node);
> +			g_slist_free_1 (node);
> +			g_object_unref (account);
> +			gtk_widget_destroy (item);
> +			break;
> +		}
> +		
> +		node = node->next;
> +	}
> +	
> +	if (hdrs->account == NULL) {
> +		if (priv->from_options) {
> +			/* the previously selected account was removed,
> +			   default the new selection to the first account in
> +			   the menu list */
> +			omenu = e_msg_composer_hdrs_get_from_omenu (hdrs);
> +			
> +			item = priv->from_options->data;
> +			gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), 0);
> +			g_signal_emit_by_name (item, "activate", hdrs);
> +		} else {
> +			toplevel = gtk_widget_get_toplevel ((GtkWidget *) hdrs);
> +			gtk_widget_set_sensitive (toplevel, FALSE);
> +			
> +			dialog = gtk_message_dialog_new ((GtkWindow *) toplevel, GTK_DIALOG_MODAL |
> +							 GTK_DIALOG_DESTROY_WITH_PARENT,
> +							 GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "%s",
> +							 _("Hey you, dunce. You need an account to send mail doncha know."));
> +		}
> +	}
> +}
> +
>  static GtkWidget *
>  create_from_optionmenu (EMsgComposerHdrs *hdrs)
>  {
> -	GtkWidget *omenu, *menu, *first = NULL;
> -	EAccountList *accounts;
> -	EAccount *account;
> -	EIterator *iter;
> -	GPtrArray *addresses;
> -	GtkWidget *item, *hbox;
> +	struct _EMsgComposerHdrsPrivate *priv = hdrs->priv;
> +	GtkWidget *hbox, *omenu, *menu, *item, *first = NULL;
>  	int i = 0, history = 0, m, matches;
> +	GPtrArray *addresses;
>  	GConfClient *gconf;
> +	EAccount *account;
> +	EIterator *iter;
>  	int index;
>  	
>  	omenu = gtk_option_menu_new ();
> @@ -210,8 +309,7 @@
>  	
>  	/* Make list of account email addresses */
>  	addresses = g_ptr_array_new ();
> -	accounts = mail_config_get_accounts ();
> -	iter = e_list_get_iterator ((EList *) accounts);
> +	iter = e_list_get_iterator ((EList *) priv->accounts);
>  	while (e_iterator_is_valid (iter)) {
>  		account = (EAccount *) e_iterator_get (iter);
>  		
> @@ -290,6 +388,11 @@
>  	
>  	g_object_set_data ((GObject *) hbox, "from_menu", omenu);
>  	
> +	/* listen for changes to the account list so we can auto-update the from menu */
> +	g_signal_connect (priv->accounts, "account-added", G_CALLBACK (account_added_cb), hdrs);
> +	g_signal_connect (priv->accounts, "account-changed", G_CALLBACK (account_changed_cb), hdrs);
> +	g_signal_connect (priv->accounts, "account-removed", G_CALLBACK (account_removed_cb), hdrs);
> +	
>  	return hbox;
>  }
>  
> Index: mail/ChangeLog
> ===================================================================
> RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
> retrieving revision 1.2551
> diff -u -r1.2551 ChangeLog
> --- mail/ChangeLog	22 Jan 2003 16:14:14 -0000	1.2551
> +++ mail/ChangeLog	22 Jan 2003 19:41:48 -0000
> @@ -1,3 +1,12 @@
> +2003-01-22  Jeffrey Stedfast  <fejj ximian com>
> +
> +	* mail-config.c (mail_config_add_account): Emit the account-added
> +	event.
> +	(mail_config_remove_account): Emit the account-removed event.
> +
> +	* mail-account-gui.c (mail_account_gui_save): Emit the changed
> +	event on the account-list for the changed account.
> +
>  2003-01-22  Radek Doulik  <rodo ximian com>
>  
>  	* mail-callbacks.c (do_mail_print): put unrealized html widget
> Index: mail/mail-account-gui.c
> ===================================================================
> RCS file: /cvs/gnome/evolution/mail/mail-account-gui.c,v
> retrieving revision 1.121
> diff -u -r1.121 mail-account-gui.c
> --- mail/mail-account-gui.c	17 Jan 2003 23:31:25 -0000	1.121
> +++ mail/mail-account-gui.c	22 Jan 2003 19:41:49 -0000
> @@ -1823,6 +1823,7 @@
>  gboolean
>  mail_account_gui_save (MailAccountGui *gui)
>  {
> +	EAccountList *accounts;
>  	EAccount *account, *new;
>  	CamelProvider *provider = NULL;
>  	CamelURL *source_url = NULL, *url;
> @@ -1953,8 +1954,12 @@
>  	e_account_import (account, new);
>  	g_object_unref (new);
>  	
> -	if (is_new)
> +	if (is_new) {
>  		mail_config_add_account (account);
> +	} else {
> +		accounts = mail_config_get_accounts ();
> +		g_signal_emit_by_name (accounts, "account-changed", account);
> +	}
>  	
>  	/* if the account provider is something we can stick
>  	   in the folder-tree and not added by some other
> Index: mail/mail-config.c
> ===================================================================
> RCS file: /cvs/gnome/evolution/mail/mail-config.c,v
> retrieving revision 1.260
> diff -u -r1.260 mail-config.c
> --- mail/mail-config.c	21 Jan 2003 19:12:37 -0000	1.260
> +++ mail/mail-config.c	22 Jan 2003 19:41:50 -0000
> @@ -849,6 +849,7 @@
>  mail_config_add_account (EAccount *account)
>  {
>  	e_list_append ((EList *) config->accounts, account);
> +	g_signal_emit_by_name (config->accounts, "account-added", account);
>  	
>  	mail_config_save_accounts ();
>  }
> @@ -885,7 +886,10 @@
>  			gconf_client_set_int (config->gconf, "/apps/evolution/mail/default_account", cur - 1, NULL);
>  	}
>  	
> +	g_object_ref (account);
>  	e_list_remove ((EList *) config->accounts, account);
> +	g_signal_emit_by_name (config->accounts, "account-removed", account);
> +	g_object_unref (account);
>  	
>  	mail_config_save_accounts ();
>  }
-- 
Anna Marie Dirks <anna ximian com>




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