aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-04-27 20:14:15 +0800
committerRodrigo Moya <rodrigo@gnome-db.org>2011-06-30 00:42:03 +0800
commit76b102e4038c63e29e4b427e4bdfe4db720970f2 (patch)
tree12551ca631f4aca4d51102e80f4872653e43e617
parent698e3476e392ea52f95fcea1c899d1dfa6354e8d (diff)
downloadgsoc2013-evolution-76b102e4038c63e29e4b427e4bdfe4db720970f2.tar.gz
gsoc2013-evolution-76b102e4038c63e29e4b427e4bdfe4db720970f2.tar.zst
gsoc2013-evolution-76b102e4038c63e29e4b427e4bdfe4db720970f2.zip
Add itip_get_fallback_identity().
Convenience function returns a name + address string from the default mail identity, to be used as a fallback for organizers.
-rw-r--r--calendar/gui/dialogs/event-page.c20
-rw-r--r--calendar/gui/dialogs/memo-page.c20
-rw-r--r--calendar/gui/dialogs/task-page.c18
-rw-r--r--calendar/gui/itip-utils.c27
-rw-r--r--calendar/gui/itip-utils.h1
5 files changed, 48 insertions, 38 deletions
diff --git a/calendar/gui/dialogs/event-page.c b/calendar/gui/dialogs/event-page.c
index a4856b1792..d2fc4ae091 100644
--- a/calendar/gui/dialogs/event-page.c
+++ b/calendar/gui/dialogs/event-page.c
@@ -110,6 +110,7 @@ struct _EventPagePrivate {
GtkWidget *location_label;
gchar **address_strings;
+ gchar *fallback_address;
EMeetingAttendee *ia;
gchar *user_add;
ECalComponent *comp;
@@ -897,6 +898,7 @@ event_page_finalize (GObject *object)
priv = EVENT_PAGE_GET_PRIVATE (object);
g_strfreev (priv->address_strings);
+ g_free (priv->fallback_address);
g_ptr_array_foreach (
priv->deleted_attendees, (GFunc) g_object_unref, NULL);
@@ -3186,18 +3188,12 @@ event_page_select_organizer (EventPage *epage, const gchar *backend_address)
EventPagePrivate *priv = epage->priv;
CompEditor *editor;
ECal *client;
- EAccount *def_account;
- gchar *def_address = NULL;
const gchar *default_address;
gboolean subscribed_cal = FALSE;
ESource *source = NULL;
const gchar *user_addr = NULL;
gint ii;
- def_account = e_get_default_account ();
- if (def_account && def_account->enabled)
- def_address = g_strdup_printf("%s <%s>", def_account->id->name, def_account->id->address);
-
editor = comp_editor_page_get_editor (COMP_EDITOR_PAGE (epage));
client = comp_editor_get_client (editor);
@@ -3211,7 +3207,8 @@ event_page_select_organizer (EventPage *epage, const gchar *backend_address)
else
user_addr = (backend_address && *backend_address) ? backend_address : NULL;
- default_address = NULL;
+ default_address = priv->fallback_address;
+
if (user_addr) {
for (ii = 0; priv->address_strings[ii] != NULL; ii++) {
if (g_strrstr (priv->address_strings[ii], user_addr) != NULL) {
@@ -3221,10 +3218,7 @@ event_page_select_organizer (EventPage *epage, const gchar *backend_address)
}
}
- if (!default_address && def_address)
- default_address = def_address;
-
- if (default_address) {
+ if (default_address != NULL) {
if (!priv->comp || !e_cal_component_has_organizer (priv->comp)) {
GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->organizer)));
@@ -3235,8 +3229,6 @@ event_page_select_organizer (EventPage *epage, const gchar *backend_address)
}
} else
g_warning ("No potential organizers!");
-
- g_free (def_address);
}
/**
@@ -3276,6 +3268,8 @@ event_page_construct (EventPage *epage,
model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->organizer));
priv->address_strings = itip_get_user_identities ();
+ priv->fallback_address = itip_get_fallback_identity ();
+
for (ii = 0; priv->address_strings[ii] != NULL; ii++)
e_dialog_append_list_store_text (
model, 0, priv->address_strings[ii]);
diff --git a/calendar/gui/dialogs/memo-page.c b/calendar/gui/dialogs/memo-page.c
index 54692894e3..e708cefc0c 100644
--- a/calendar/gui/dialogs/memo-page.c
+++ b/calendar/gui/dialogs/memo-page.c
@@ -93,6 +93,7 @@ struct _MemoPagePrivate {
GtkWidget *source_selector;
gchar **address_strings;
+ gchar *fallback_address;
ENameSelector *name_selector;
};
@@ -188,6 +189,7 @@ memo_page_dispose (GObject *object)
priv = MEMO_PAGE (object)->priv;
g_strfreev (priv->address_strings);
+ g_free (priv->fallback_address);
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (memo_page_parent_class)->dispose (object);
@@ -1096,18 +1098,12 @@ memo_page_select_organizer (MemoPage *mpage, const gchar *backend_address)
CompEditor *editor;
CompEditorFlags flags;
ECal *client;
- EAccount *def_account;
- gchar *def_address = NULL;
const gchar *default_address;
gboolean subscribed_cal = FALSE;
ESource *source = NULL;
const gchar *user_addr = NULL;
gint ii;
- def_account = e_get_default_account ();
- if (def_account && def_account->enabled)
- def_address = g_strdup_printf("%s <%s>", def_account->id->name, def_account->id->address);
-
priv = mpage->priv;
editor = comp_editor_page_get_editor (COMP_EDITOR_PAGE (mpage));
client = comp_editor_get_client (editor);
@@ -1123,7 +1119,8 @@ memo_page_select_organizer (MemoPage *mpage, const gchar *backend_address)
else
user_addr = (backend_address && *backend_address) ? backend_address : NULL;
- default_address = NULL;
+ default_address = priv->fallback_address;
+
if (user_addr) {
for (ii = 0; priv->address_strings[ii] != NULL; ii++) {
if (g_strrstr (priv->address_strings[ii], user_addr) != NULL) {
@@ -1133,18 +1130,13 @@ memo_page_select_organizer (MemoPage *mpage, const gchar *backend_address)
}
}
- if (!default_address && def_account)
- default_address = def_address;
-
- if (default_address) {
+ if (default_address != NULL) {
if (flags & COMP_EDITOR_NEW_ITEM) {
gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->org_combo))), default_address);
gtk_widget_set_sensitive (priv->org_combo, !subscribed_cal);
}
} else
g_warning ("No potential organizers!");
-
- g_free (def_address);
}
/**
@@ -1183,6 +1175,8 @@ memo_page_construct (MemoPage *mpage)
model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->org_combo));
priv->address_strings = itip_get_user_identities ();
+ priv->fallback_address = itip_get_fallback_identity ();
+
for (ii = 0; priv->address_strings[ii] != NULL; ii++)
e_dialog_append_list_store_text (
model, 0, priv->address_strings[ii]);
diff --git a/calendar/gui/dialogs/task-page.c b/calendar/gui/dialogs/task-page.c
index 1120ccf263..bb18780250 100644
--- a/calendar/gui/dialogs/task-page.c
+++ b/calendar/gui/dialogs/task-page.c
@@ -66,6 +66,7 @@ struct _TaskPagePrivate {
GtkWidget *main;
gchar **address_strings;
+ gchar *fallback_address;
EMeetingAttendee *ia;
gchar *user_add;
ECalComponent *comp;
@@ -426,6 +427,7 @@ task_page_finalize (GObject *object)
priv = TASK_PAGE_GET_PRIVATE (object);
g_strfreev (priv->address_strings);
+ g_free (priv->fallback_address);
g_ptr_array_foreach (
priv->deleted_attendees, (GFunc) g_object_unref, NULL);
@@ -2036,8 +2038,6 @@ task_page_select_organizer (TaskPage *tpage, const gchar *backend_address)
{
TaskPagePrivate *priv = tpage->priv;
CompEditor *editor;
- EAccount *def_account;
- gchar *def_address = NULL;
const gchar *default_address;
gboolean subscribed_cal = FALSE;
ESource *source = NULL;
@@ -2048,10 +2048,6 @@ task_page_select_organizer (TaskPage *tpage, const gchar *backend_address)
editor = comp_editor_page_get_editor (COMP_EDITOR_PAGE (tpage));
client = comp_editor_get_client (editor);
- def_account = e_get_default_account ();
- if (def_account && def_account->enabled)
- def_address = g_strdup_printf("%s <%s>", def_account->id->name, def_account->id->address);
-
if (client)
source = e_cal_get_source (client);
if (source)
@@ -2062,7 +2058,8 @@ task_page_select_organizer (TaskPage *tpage, const gchar *backend_address)
else
user_addr = (backend_address && *backend_address) ? backend_address : NULL;
- default_address = NULL;
+ default_address = priv->fallback_address;
+
if (user_addr) {
for (ii = 0; priv->address_strings[ii] != NULL; ii++) {
if (g_strrstr (priv->address_strings[ii], user_addr) != NULL) {
@@ -2072,9 +2069,6 @@ task_page_select_organizer (TaskPage *tpage, const gchar *backend_address)
}
}
- if (!default_address && def_address)
- default_address = def_address;
-
if (default_address) {
if (!priv->comp || !e_cal_component_has_organizer (priv->comp)) {
GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->organizer)));
@@ -2086,8 +2080,6 @@ task_page_select_organizer (TaskPage *tpage, const gchar *backend_address)
}
} else
g_warning ("No potential organizers!");
-
- g_free (def_address);
}
/**
@@ -2130,6 +2122,8 @@ task_page_construct (TaskPage *tpage,
model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->organizer));
priv->address_strings = itip_get_user_identities ();
+ priv->fallback_address = itip_get_fallback_identity ();
+
for (ii = 0; priv->address_strings[ii] != NULL; ii++)
e_dialog_append_list_store_text (
model, 0, priv->address_strings[ii]);
diff --git a/calendar/gui/itip-utils.c b/calendar/gui/itip-utils.c
index 4ab53de115..8c7c72f2f6 100644
--- a/calendar/gui/itip-utils.c
+++ b/calendar/gui/itip-utils.c
@@ -104,6 +104,33 @@ itip_get_user_identities (void)
}
/**
+ * itip_get_fallback_identity:
+ *
+ * Returns a name + address string taken from the default mail identity,
+ * but only if the corresponding account is enabled. If the account is
+ * disabled, the function returns %NULL. This is meant to be used as a
+ * fallback identity for organizers. Free the returned string with
+ * g_free().
+ *
+ * Returns: a fallback mail identity, or %NULL
+ **/
+gchar *
+itip_get_fallback_identity (void)
+{
+ EAccount *account;
+ gchar *identity = NULL;
+
+ account = e_get_default_account ();
+ if (account != NULL && account->enabled)
+ identity = g_strdup_printf (
+ "%s <%s>",
+ account->id->name,
+ account->id->address);
+
+ return identity;
+}
+
+/**
* itip_address_is_user:
* @address: an email address
*
diff --git a/calendar/gui/itip-utils.h b/calendar/gui/itip-utils.h
index 720540e239..21fe2ac1dc 100644
--- a/calendar/gui/itip-utils.h
+++ b/calendar/gui/itip-utils.h
@@ -51,6 +51,7 @@ struct CalMimeAttach {
};
gchar ** itip_get_user_identities (void);
+gchar * itip_get_fallback_identity (void);
gboolean itip_address_is_user (const gchar *address);
gboolean itip_organizer_is_user (ECalComponent *comp,
ECal *client);