[evolution] Add e_meeting_store_find_self().



commit 67c0ce8617f12ee0a937ffe14fb40f390e4df86d
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Apr 26 10:26:55 2011 -0400

    Add e_meeting_store_find_self().
    
    Convenience function that uses registered mail identities to find the
    user among meeting attendees.

 calendar/gui/dialogs/event-editor.c |   23 +++-------------
 calendar/gui/dialogs/task-editor.c  |   24 ++++-------------
 calendar/gui/e-meeting-store.c      |   47 +++++++++++++++++++++++++++++++++++
 calendar/gui/e-meeting-store.h      |    3 ++
 4 files changed, 61 insertions(+), 36 deletions(-)
---
diff --git a/calendar/gui/dialogs/event-editor.c b/calendar/gui/dialogs/event-editor.c
index b66063d..41985bd 100644
--- a/calendar/gui/dialogs/event-editor.c
+++ b/calendar/gui/dialogs/event-editor.c
@@ -33,7 +33,6 @@
 #include <glib/gi18n.h>
 
 #include <misc/e-dateedit.h>
-#include <e-util/e-account-utils.h>
 #include <e-util/e-plugin-ui.h>
 #include <e-util/e-util-private.h>
 #include <e-util/e-ui-manager.h>
@@ -674,23 +673,11 @@ event_editor_edit_comp (CompEditor *editor, ECalComponent *comp)
 
 			/* If we aren't the organizer we can still change our own status */
 			if (!comp_editor_get_user_org (editor)) {
-				EAccountList *accounts;
-				EAccount *account;
-				EIterator *it;
-
-				accounts = e_get_account_list ();
-				for (it = e_list_get_iterator ((EList *)accounts);
-					e_iterator_is_valid (it);
-					e_iterator_next (it)) {
-					EMeetingAttendee *ia;
-
-					account = (EAccount*)e_iterator_get (it);
-
-					ia = e_meeting_store_find_attendee (priv->model, account->id->address, &row);
-					if (ia != NULL)
-						e_meeting_attendee_set_edit_level (ia, E_MEETING_ATTENDEE_EDIT_STATUS);
-				}
-				g_object_unref (it);
+				EMeetingAttendee *ia;
+
+				ia = e_meeting_store_find_self (priv->model, &row);
+				if (ia != NULL)
+					e_meeting_attendee_set_edit_level (ia, E_MEETING_ATTENDEE_EDIT_STATUS);
 			} else if (e_cal_get_organizer_must_attend (client)) {
 				EMeetingAttendee *ia;
 
diff --git a/calendar/gui/dialogs/task-editor.c b/calendar/gui/dialogs/task-editor.c
index 2deee3b..110b666 100644
--- a/calendar/gui/dialogs/task-editor.c
+++ b/calendar/gui/dialogs/task-editor.c
@@ -32,7 +32,6 @@
 #include <string.h>
 #include <glib/gi18n.h>
 
-#include "e-util/e-account-utils.h"
 #include "e-util/e-plugin-ui.h"
 #include "e-util/e-util-private.h"
 
@@ -422,23 +421,12 @@ task_editor_edit_comp (CompEditor *editor, ECalComponent *comp)
 
 		/* If we aren't the organizer we can still change our own status */
 		if (!comp_editor_get_user_org (editor)) {
-			EAccountList *accounts;
-			EAccount *account;
-			EIterator *it;
-
-			accounts = e_get_account_list ();
-			for (it = e_list_get_iterator ((EList *)accounts);
-				e_iterator_is_valid (it);
-				e_iterator_next (it)) {
-				EMeetingAttendee *ia;
-
-				account = (EAccount*)e_iterator_get (it);
-
-				ia = e_meeting_store_find_attendee (priv->model, account->id->address, &row);
-				if (ia != NULL)
-					e_meeting_attendee_set_edit_level (ia, E_MEETING_ATTENDEE_EDIT_STATUS);
-			}
-			g_object_unref (it);
+			EMeetingAttendee *ia;
+
+			ia = e_meeting_store_find_self (priv->model, &row);
+
+			if (ia != NULL)
+				e_meeting_attendee_set_edit_level (ia, E_MEETING_ATTENDEE_EDIT_STATUS);
 		} else if (e_cal_get_organizer_must_attend (client)) {
 			EMeetingAttendee *ia;
 
diff --git a/calendar/gui/e-meeting-store.c b/calendar/gui/e-meeting-store.c
index c89bd44..b0c6582 100644
--- a/calendar/gui/e-meeting-store.c
+++ b/calendar/gui/e-meeting-store.c
@@ -35,6 +35,7 @@
 #include <libedataserver/e-proxy.h>
 #include <libedataserverui/e-passwords.h>
 #include <e-util/e-extensible.h>
+#include <e-util/e-account-utils.h>
 #include <e-util/e-util-enumtypes.h>
 #include "itip-utils.h"
 #include "e-meeting-utils.h"
@@ -1086,6 +1087,52 @@ e_meeting_store_remove_all_attendees (EMeetingStore *store)
 	}
 }
 
+/**
+ * e_meeting_store_find_self:
+ * @store: an #EMeetingStore
+ * @row: return location for the matching row number, or %NULL
+ *
+ * Looks for the user in @store by comparing attendee email addresses to
+ * registered mail identities.  If a matching email address is found and
+ * @row is not %NULL, @row will be set to the #EMeetingStore row number
+ * with the matching email address.
+ *
+ * Returns: an #EMeetingAttendee, or %NULL
+ **/
+EMeetingAttendee *
+e_meeting_store_find_self (EMeetingStore *store,
+                           gint *row)
+{
+	EMeetingAttendee *attendee = NULL;
+	EAccountList *account_list;
+	EIterator *iterator;
+
+	g_return_val_if_fail (E_IS_MEETING_STORE (store), NULL);
+
+	account_list = e_get_account_list ();
+
+	iterator = e_list_get_iterator (E_LIST (account_list));
+
+	while (e_iterator_is_valid (iterator)) {
+		EAccount *account;
+
+		/* XXX EIterator misuses const. */
+		account = (EAccount *) e_iterator_get (iterator);
+
+		attendee = e_meeting_store_find_attendee (
+			store, account->id->address, row);
+
+		if (attendee != NULL)
+			break;
+
+		e_iterator_next (iterator);
+	}
+
+	g_object_unref (iterator);
+
+	return attendee;
+}
+
 EMeetingAttendee *
 e_meeting_store_find_attendee (EMeetingStore *store,
                                const gchar *address,
diff --git a/calendar/gui/e-meeting-store.h b/calendar/gui/e-meeting-store.h
index 3565657..2c863ef 100644
--- a/calendar/gui/e-meeting-store.h
+++ b/calendar/gui/e-meeting-store.h
@@ -122,6 +122,9 @@ void		e_meeting_store_remove_attendee	(EMeetingStore *meeting_store,
 void		e_meeting_store_remove_all_attendees
 						(EMeetingStore *meeting_store);
 EMeetingAttendee *
+		e_meeting_store_find_self	(EMeetingStore *meeting_store,
+						 gint *row);
+EMeetingAttendee *
 		e_meeting_store_find_attendee	(EMeetingStore *meeting_store,
 						 const gchar *address,
 						 gint *row);



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