Commit 6be2668e authored by Matthew Barnes's avatar Matthew Barnes
Browse files

Adapt to CamelSession API changes.

These functions now return new references:

  camel_session_add_service()
  camel_session_list_services()

These functions have been renamed and also return new references:

  camel_session_get_service()        -> camel_session_ref_service()
  camel_session_get_service_by_url() -> camel_session_ref_service_by_url()
parent 6456e814
......@@ -309,7 +309,7 @@ mail_folder_expunge_pop3_stores (CamelFolder *folder,
if (!enabled || g_strcmp0 (backend_name, "pop") != 0)
continue;
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (session), source_uid);
service_uid = camel_service_get_uid (service);
......@@ -321,14 +321,17 @@ mail_folder_expunge_pop3_stores (CamelFolder *folder,
"keep-on-server", &keep_on_server,
NULL);
if (!keep_on_server || !delete_expunged)
if (!keep_on_server || !delete_expunged) {
g_object_unref (service);
continue;
}
folder = camel_store_get_inbox_folder_sync (
CAMEL_STORE (service), cancellable, error);
/* Abort the loop on error. */
if (folder == NULL) {
g_object_unref (service);
success = FALSE;
break;
}
......@@ -336,6 +339,7 @@ mail_folder_expunge_pop3_stores (CamelFolder *folder,
uids = camel_folder_get_uids (folder);
if (uids == NULL) {
g_object_unref (service);
g_object_unref (folder);
continue;
}
......@@ -359,6 +363,7 @@ mail_folder_expunge_pop3_stores (CamelFolder *folder,
folder, TRUE, cancellable, error);
g_object_unref (folder);
g_object_unref (service);
/* Abort the loop on error. */
if (!success)
......@@ -1801,7 +1806,7 @@ e_mail_folder_uri_parse (CamelSession *session,
uid = g_strconcat (
url->user, "@", url->host, NULL);
service = camel_session_get_service (session, uid);
service = camel_session_ref_service (session, uid);
g_free (uid);
}
......@@ -1845,7 +1850,7 @@ e_mail_folder_uri_parse (CamelSession *session,
}
if (uid != NULL) {
service = camel_session_get_service (session, uid);
service = camel_session_ref_service (session, uid);
g_free (uid);
}
......@@ -1858,7 +1863,7 @@ e_mail_folder_uri_parse (CamelSession *session,
* To determine which it is, you have to check the provider
* flags for CAMEL_URL_FRAGMENT_IS_PATH. */
} else {
service = camel_session_get_service_by_url (
service = camel_session_ref_service_by_url (
session, url, CAMEL_PROVIDER_STORE);
if (CAMEL_IS_STORE (service)) {
......@@ -1891,6 +1896,9 @@ e_mail_folder_uri_parse (CamelSession *session,
folder_uri);
}
if (service != NULL)
g_object_unref (service);
g_free (folder_name);
camel_url_free (url);
......
......@@ -410,15 +410,25 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple,
CamelService *service;
gboolean did_connect = FALSE;
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (session), context->transport_uid);
if (service == NULL) {
g_simple_async_result_set_error (
simple, CAMEL_SERVICE_ERROR,
CAMEL_SERVICE_ERROR_URL_INVALID,
_("No mail service found with UID '%s'"),
context->transport_uid);
return;
}
if (!CAMEL_IS_TRANSPORT (service)) {
g_simple_async_result_set_error (simple,
CAMEL_SERVICE_ERROR,
g_simple_async_result_set_error (
simple, CAMEL_SERVICE_ERROR,
CAMEL_SERVICE_ERROR_URL_INVALID,
_("Cannot get transport for account '%s'"),
_("UID '%s' is not a mail transport"),
context->transport_uid);
g_object_unref (service);
return;
}
......@@ -431,6 +441,7 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple,
if (error != NULL) {
g_simple_async_result_take_error (simple, error);
g_object_unref (service);
return;
}
}
......@@ -450,6 +461,8 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple,
service, error == NULL,
cancellable, error ? NULL : &error);
g_object_unref (service);
if (error != NULL) {
g_simple_async_result_take_error (simple, error);
return;
......
......@@ -78,8 +78,8 @@ struct _EMailSessionPrivate {
gulong source_disabled_handler_id;
gulong default_mail_account_handler_id;
CamelStore *local_store;
CamelStore *vfolder_store;
CamelService *local_store;
CamelService *vfolder_store;
FILE *filter_logfile;
GHashTable *junk_filters;
......@@ -445,10 +445,12 @@ mail_session_refresh_cb (ESource *source,
const gchar *uid;
uid = e_source_get_uid (source);
service = camel_session_get_service (session, uid);
g_return_if_fail (CAMEL_IS_SERVICE (service));
service = camel_session_ref_service (session, uid);
g_return_if_fail (service != NULL);
g_signal_emit (session, signals[REFRESH_SERVICE], 0, service);
g_object_unref (service);
}
static gboolean
......@@ -478,6 +480,7 @@ mail_session_add_from_source (EMailSession *session,
ESource *source)
{
ESourceBackend *extension;
CamelService *service;
const gchar *uid;
const gchar *backend_name;
const gchar *display_name;
......@@ -512,12 +515,15 @@ mail_session_add_from_source (EMailSession *session,
if (mail_session_check_goa_mail_disabled (session, source))
return;
/* Our own CamelSession.add_service() method will handle the
* resulting CamelService, so we don't need the return value. */
camel_session_add_service (
service = camel_session_add_service (
CAMEL_SESSION (session), uid,
backend_name, type, &error);
/* Our own CamelSession.add_service() method will handle the
* new CamelService, so we only need to unreference it here. */
if (service != NULL)
g_object_unref (service);
if (error != NULL) {
g_warning (
"Failed to add service '%s' (%s): %s",
......@@ -578,10 +584,12 @@ mail_session_source_removed_cb (ESourceRegistry *registry,
camel_session = CAMEL_SESSION (session);
uid = e_source_get_uid (source);
service = camel_session_get_service (camel_session, uid);
service = camel_session_ref_service (camel_session, uid);
if (CAMEL_IS_SERVICE (service))
if (service != NULL) {
camel_session_remove_service (camel_session, service);
g_object_unref (service);
}
}
static void
......@@ -676,8 +684,9 @@ mail_session_configure_local_store (EMailSession *session)
camel_session = CAMEL_SESSION (session);
uid = E_MAIL_SESSION_LOCAL_UID;
service = camel_session_get_service (camel_session, uid);
g_return_if_fail (CAMEL_IS_SERVICE (service));
service = camel_session_ref_service (camel_session, uid);
session->priv->local_store = service; /* takes ownership */
g_return_if_fail (service != NULL);
settings = camel_service_get_settings (service);
local_settings = CAMEL_LOCAL_SETTINGS (settings);
......@@ -721,8 +730,6 @@ mail_session_configure_local_store (EMailSession *session)
g_error_free (error);
}
}
session->priv->local_store = g_object_ref (service);
}
static void
......@@ -735,8 +742,9 @@ mail_session_configure_vfolder_store (EMailSession *session)
camel_session = CAMEL_SESSION (session);
uid = E_MAIL_SESSION_VFOLDER_UID;
service = camel_session_get_service (camel_session, uid);
g_return_if_fail (CAMEL_IS_SERVICE (service));
service = camel_session_ref_service (camel_session, uid);
session->priv->vfolder_store = service; /* takes ownership */
g_return_if_fail (service != NULL);
camel_service_connect_sync (service, NULL, NULL);
......@@ -744,8 +752,6 @@ mail_session_configure_vfolder_store (EMailSession *session)
* but it requires an EMailBackend, which we don't have access
* to from here, so it has to be called from elsewhere. Kinda
* thinking about reworking that... */
session->priv->vfolder_store = g_object_ref (service);
}
static void
......@@ -1944,7 +1950,7 @@ e_mail_session_get_local_store (EMailSession *session)
{
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
return session->priv->local_store;
return CAMEL_STORE (session->priv->local_store);
}
CamelFolder *
......@@ -2037,21 +2043,30 @@ e_mail_session_get_inbox_sync (EMailSession *session,
GError **error)
{
CamelService *service;
CamelFolder *folder = NULL;
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
g_return_val_if_fail (service_uid != NULL, NULL);
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (session), service_uid);
if (!CAMEL_IS_STORE (service))
if (service == NULL)
return NULL;
if (!CAMEL_IS_STORE (service))
goto exit;
if (!camel_service_connect_sync (service, cancellable, error))
return NULL;
goto exit;
return camel_store_get_inbox_folder_sync (
folder = camel_store_get_inbox_folder_sync (
CAMEL_STORE (service), cancellable, error);
exit:
g_object_unref (service);
return folder;
}
void
......@@ -2136,21 +2151,30 @@ e_mail_session_get_trash_sync (EMailSession *session,
GError **error)
{
CamelService *service;
CamelFolder *folder = NULL;
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
g_return_val_if_fail (service_uid != NULL, NULL);
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (session), service_uid);
if (!CAMEL_IS_STORE (service))
if (service == NULL)
return NULL;
if (!CAMEL_IS_STORE (service))
goto exit;
if (!camel_service_connect_sync (service, cancellable, error))
return NULL;
goto exit;
return camel_store_get_trash_folder_sync (
folder = camel_store_get_trash_folder_sync (
CAMEL_STORE (service), cancellable, error);
exit:
g_object_unref (service);
return folder;
}
void
......@@ -2377,12 +2401,12 @@ e_binding_transform_source_to_service (GBinding *binding,
return FALSE;
uid = e_source_get_uid (source);
service = camel_session_get_service (session, uid);
service = camel_session_ref_service (session, uid);
if (!CAMEL_IS_SERVICE (service))
if (service == NULL)
return FALSE;
g_value_set_object (target_value, service);
g_value_take_object (target_value, service);
return TRUE;
}
......@@ -2433,7 +2457,7 @@ e_mail_session_get_vfolder_store (EMailSession *session)
{
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
return session->priv->vfolder_store;
return CAMEL_STORE (session->priv->vfolder_store);
}
EMVFolderContext *
......
......@@ -610,7 +610,7 @@ mail_send_message (struct _send_queue_msg *m,
if (sent_folder_uri == NULL && tmp != NULL)
sent_folder_uri = g_strstrip (g_strdup (tmp));
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (m->session), transport_uid);
if (service != NULL)
provider = camel_service_get_provider (service);
......@@ -825,6 +825,10 @@ exit:
}
if (info)
camel_message_info_free (info);
if (service != NULL)
g_object_unref (service);
g_object_unref (recipients);
g_object_unref (from);
g_free (sent_folder_uri);
......
......@@ -811,9 +811,9 @@ rule_changed (EFilterRule *rule,
full_name = camel_folder_get_full_name (folder);
session = get_session (folder);
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (session), E_MAIL_SESSION_VFOLDER_UID);
g_return_if_fail (CAMEL_IS_SERVICE (service));
g_return_if_fail (service != NULL);
/* If the folder has changed name, then
* add it, then remove the old manually. */
......@@ -846,6 +846,9 @@ rule_changed (EFilterRule *rule,
g_free (oldname);
}
g_object_unref (service);
service = NULL;
d(printf("Filter rule changed? for folder '%s'!!\n", folder->name));
camel_vee_folder_set_auto_update (CAMEL_VEE_FOLDER (folder),
......@@ -910,9 +913,9 @@ context_rule_added (ERuleContext *ctx,
d(printf("rule added: %s\n", rule->name));
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (session), E_MAIL_SESSION_VFOLDER_UID);
g_return_if_fail (CAMEL_IS_SERVICE (service));
g_return_if_fail (service != NULL);
/* this always runs quickly */
/* FIXME Not passing a GCancellable or GError. */
......@@ -929,6 +932,8 @@ context_rule_added (ERuleContext *ctx,
rule_changed (rule, folder);
}
g_object_unref (service);
}
static void
......@@ -941,9 +946,9 @@ context_rule_removed (ERuleContext *ctx,
d(printf("rule removed; %s\n", rule->name));
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (session), E_MAIL_SESSION_VFOLDER_UID);
g_return_if_fail (CAMEL_IS_SERVICE (service));
g_return_if_fail (service != NULL);
/* TODO: remove from folder info cache? */
......@@ -960,6 +965,8 @@ context_rule_removed (ERuleContext *ctx,
/* this must be unref'd after its deleted */
if (folder)
g_object_unref ((CamelFolder *) folder);
g_object_unref (service);
}
static void
......
......@@ -1528,7 +1528,7 @@ e_mail_account_store_load_sort_order (EMailAccountStore *store,
for (ii = 0; ii < length; ii++) {
CamelService *service;
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (session), service_uids[ii]);
if (service != NULL)
g_queue_push_tail (&service_queue, service);
......@@ -1536,7 +1536,9 @@ e_mail_account_store_load_sort_order (EMailAccountStore *store,
e_mail_account_store_reorder_services (store, &service_queue);
g_queue_clear (&service_queue);
while (!g_queue_is_empty (&service_queue))
g_object_unref (g_queue_pop_head (&service_queue));
g_strfreev (service_uids);
g_key_file_free (key_file);
......
......@@ -166,18 +166,22 @@ mail_backend_prepare_for_offline_cb (EShell *shell,
const gchar *uid;
uid = e_source_get_uid (source);
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (session), uid);
if (!CAMEL_IS_STORE (service))
if (service == NULL)
continue;
/* FIXME Not passing a GCancellable. */
e_mail_store_go_offline (
CAMEL_STORE (service), G_PRIORITY_DEFAULT,
NULL, (GAsyncReadyCallback)
mail_backend_store_operation_done_cb,
g_object_ref (activity));
if (CAMEL_IS_STORE (service))
e_mail_store_go_offline (
CAMEL_STORE (service),
G_PRIORITY_DEFAULT,
NULL, (GAsyncReadyCallback)
mail_backend_store_operation_done_cb,
g_object_ref (activity));
g_object_unref (service);
}
g_list_free_full (list, (GDestroyNotify) g_object_unref);
......@@ -210,18 +214,22 @@ mail_backend_prepare_for_online_cb (EShell *shell,
continue;
uid = e_source_get_uid (source);
service = camel_session_get_service (
service = camel_session_ref_service (
CAMEL_SESSION (session), uid);
if (!CAMEL_IS_STORE (service))
if (service == NULL)
continue;
/* FIXME Not passing a GCancellable. */
e_mail_store_go_online (
CAMEL_STORE (service), G_PRIORITY_DEFAULT,
NULL, (GAsyncReadyCallback)
mail_backend_store_operation_done_cb,
g_object_ref (activity));
if (CAMEL_IS_STORE (service))
e_mail_store_go_online (
CAMEL_STORE (service),
G_PRIORITY_DEFAULT,
NULL, (GAsyncReadyCallback)
mail_backend_store_operation_done_cb,
g_object_ref (activity));
g_object_unref (service);
}
g_list_free_full (list, (GDestroyNotify) g_object_unref);
......@@ -331,7 +339,7 @@ mail_backend_prepare_for_quit_cb (EShell *shell,
g_object_ref (activity));
}
g_list_free (list);
g_list_free_full (list, (GDestroyNotify) g_object_unref);
/* Now we poll until all activities are actually cancelled or finished.
* Reffing the activity delays quitting; the reference count
......
......@@ -146,7 +146,6 @@ mail_config_auth_check_update (EMailConfigAuthCheck *auth_check)
"user-cache-dir", temp_dir,
NULL);
/* This returns a BORROWED reference to the CamelService. */
service = camel_session_add_service (
session, "fake-uid",
backend_class->backend_name,
......@@ -182,6 +181,8 @@ mail_config_auth_check_update (EMailConfigAuthCheck *auth_check)
camel_service_query_auth_types (
service, G_PRIORITY_DEFAULT, cancellable,
mail_config_auth_check_update_done_cb, async_context);
g_object_unref (service);
}
static void
......
......@@ -93,7 +93,7 @@ mail_config_defaults_page_maybe_get_settings (EMailConfigDefaultsPage *page)
}
static CamelStore *
mail_config_defaults_page_get_store (EMailConfigDefaultsPage *page)
mail_config_defaults_page_ref_store (EMailConfigDefaultsPage *page)
{
ESource *source;
EMailSession *session;
......@@ -104,9 +104,17 @@ mail_config_defaults_page_get_store (EMailConfigDefaultsPage *page)
source = e_mail_config_defaults_page_get_account_source (page);
uid = e_source_get_uid (source);
service = camel_session_get_service (CAMEL_SESSION (session), uid);
service = camel_session_ref_service (CAMEL_SESSION (session), uid);
return CAMEL_IS_STORE (service) ? CAMEL_STORE (service) : NULL;
if (service == NULL)
return NULL;
if (!CAMEL_IS_STORE (service)) {
g_object_unref (service);
return NULL;
}
return CAMEL_STORE (service);
}
static gboolean
......@@ -185,8 +193,8 @@ mail_config_defaults_page_folder_name_to_uri (GBinding *binding,
gchar *folder_uri = NULL;
page = E_MAIL_CONFIG_DEFAULTS_PAGE (data);
store = mail_config_defaults_page_get_store (page);
g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
store = mail_config_defaults_page_ref_store (page);
g_return_val_if_fail (store != NULL, FALSE);
folder_name = g_value_get_string (source_value);
......@@ -197,6 +205,8 @@ mail_config_defaults_page_folder_name_to_uri (GBinding *binding,
g_free (folder_uri);
g_object_unref (store);
return TRUE;
}
......@@ -286,9 +296,6 @@ mail_config_defaults_page_add_real_folder (EMailConfigDefaultsPage *page,
CamelStore *store;
GObjectClass *class;
store = mail_config_defaults_page_get_store (page);
g_return_val_if_fail (CAMEL_IS_STORE (store), NULL);
session = e_mail_config_defaults_page_get_session (page);
settings = mail_config_defaults_page_maybe_get_settings (page);
......@@ -306,6 +313,9 @@ mail_config_defaults_page_add_real_folder (EMailConfigDefaultsPage *page,
if (g_object_class_find_property (class, use_property_name) == NULL)
return NULL;
store = mail_config_defaults_page_ref_store (page);
g_return_val_if_fail (store != NULL, NULL);
/* We're good to go. */
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
......@@ -352,6 +362,8 @@ mail_config_defaults_page_add_real_folder (EMailConfigDefaultsPage *page,
G_CALLBACK (mail_config_defaults_page_restore_real_folder),
check_button);
g_object_unref (store);
return box;
}
......
......@@ -207,7 +207,7 @@ filter_source_element_xml_decode (EFilterElement *fe,
xmlFree (content);
if (url != NULL) {
service = camel_session_get_service_by_url (
service = camel_session_ref_service_by_url (
CAMEL_SESSION (session),
url, CAMEL_PROVIDER_STORE);
camel_url_free (url);
......@@ -218,6 +218,8 @@ filter_source_element_xml_decode (EFilterElement *fe,
uid = camel_service_get_uid (service);
active_id = g_strdup (uid);
g_object_unref (service);
}
break;
......
......@@ -491,7 +491,7 @@ static void
folder_tree_expand_node (const gchar *key,
EMFolderTree *folder_tree)
{
struct _EMFolderTreeModelStoreInfo *si;
struct _EMFolderTreeModelStoreInfo *si = NULL;
GtkTreeRowReference *row;
GtkTreeView *tree_view;
GtkTreeModel *model;
......@@ -517,21 +517,18 @@ folder_tree_expand_node (const gchar *key,
session = em_folder_tree_get_session (folder_tree);