|
Packit |
15f964 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
Packit |
15f964 |
/*
|
|
Packit |
15f964 |
* Copyright (C) 2017 Red Hat, Inc. (www.redhat.com)
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* This library is free software: you can redistribute it and/or modify it
|
|
Packit |
15f964 |
* under the terms of the GNU Lesser General Public License as published by
|
|
Packit |
15f964 |
* the Free Software Foundation.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* This library is distributed in the hope that it will be useful, but
|
|
Packit |
15f964 |
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
Packit |
15f964 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
Packit |
15f964 |
* for more details.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
15f964 |
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
15f964 |
*/
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* SECTION: e-config-lookup
|
|
Packit |
15f964 |
* @include: e-util/e-util.h
|
|
Packit |
15f964 |
* @short_description: Configuration lookup
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* #EConfigLookup is used to search for configuration of an account,
|
|
Packit |
15f964 |
* which is identified by an e-mail address, server address or such.
|
|
Packit |
15f964 |
* It is an #EExtensible object, where the extensions connect to
|
|
Packit |
15f964 |
* the #EConfigLookup::run signal to run the configuration lookup.
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
#include "evolution-config.h"
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
#include <glib/gi18n-lib.h>
|
|
Packit |
15f964 |
#include <camel/camel.h>
|
|
Packit |
15f964 |
#include <libedataserver/libedataserver.h>
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
#include "e-config-lookup-result.h"
|
|
Packit |
15f964 |
#include "e-config-lookup-worker.h"
|
|
Packit |
15f964 |
#include "e-simple-async-result.h"
|
|
Packit |
15f964 |
#include "e-util-enumtypes.h"
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
#include "e-config-lookup.h"
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
struct _EConfigLookupPrivate {
|
|
Packit |
15f964 |
ESourceRegistry *registry;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
GMutex property_lock;
|
|
Packit |
15f964 |
GSList *workers; /* EConfigLookupWorker * */
|
|
Packit |
15f964 |
GSList *results; /* EConfigLookupResult * */
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
ESimpleAsyncResult *run_result;
|
|
Packit |
15f964 |
GCancellable *run_cancellable;
|
|
Packit |
15f964 |
GSList *worker_cancellables; /* CamelOperation * */
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
GThreadPool *pool;
|
|
Packit |
15f964 |
};
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
enum {
|
|
Packit |
15f964 |
PROP_0,
|
|
Packit |
15f964 |
PROP_REGISTRY,
|
|
Packit |
15f964 |
PROP_BUSY
|
|
Packit |
15f964 |
};
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
enum {
|
|
Packit |
15f964 |
GET_SOURCE,
|
|
Packit |
15f964 |
WORKER_STARTED,
|
|
Packit |
15f964 |
WORKER_FINISHED,
|
|
Packit |
15f964 |
RESULT_ADDED,
|
|
Packit |
15f964 |
LAST_SIGNAL
|
|
Packit |
15f964 |
};
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static guint signals[LAST_SIGNAL];
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
G_DEFINE_TYPE_WITH_CODE (EConfigLookup, e_config_lookup, G_TYPE_OBJECT,
|
|
Packit |
15f964 |
G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL))
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
enum {
|
|
Packit |
15f964 |
EMIT_BUSY = 1 << 0,
|
|
Packit |
15f964 |
EMIT_WORKER_STARTED = 1 << 1,
|
|
Packit |
15f964 |
EMIT_WORKER_FINISHED = 1 << 2
|
|
Packit |
15f964 |
};
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
typedef struct _EmitData {
|
|
Packit |
15f964 |
EConfigLookup *config_lookup;
|
|
Packit |
15f964 |
EConfigLookupWorker *worker;
|
|
Packit |
15f964 |
guint32 flags;
|
|
Packit |
15f964 |
GCancellable *cancellable;
|
|
Packit |
15f964 |
ENamedParameters *params;
|
|
Packit |
15f964 |
GError *error;
|
|
Packit |
15f964 |
} EmitData;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
emit_data_free (gpointer ptr)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
EmitData *ed = ptr;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (ed) {
|
|
Packit |
15f964 |
e_named_parameters_free (ed->params);
|
|
Packit |
15f964 |
g_clear_object (&ed->config_lookup);
|
|
Packit |
15f964 |
g_clear_object (&ed->worker);
|
|
Packit |
15f964 |
g_clear_object (&ed->cancellable);
|
|
Packit |
15f964 |
g_clear_error (&ed->error);
|
|
Packit |
15f964 |
g_free (ed);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static gboolean
|
|
Packit |
15f964 |
config_lookup_emit_idle_cb (gpointer user_data)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
EmitData *ed = user_data;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_val_if_fail (ed != NULL, FALSE);
|
|
Packit |
15f964 |
g_return_val_if_fail (E_IS_CONFIG_LOOKUP (ed->config_lookup), FALSE);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if ((ed->flags & EMIT_WORKER_STARTED) != 0)
|
|
Packit |
15f964 |
g_signal_emit (ed->config_lookup, signals[WORKER_STARTED], 0, ed->worker, ed->cancellable);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if ((ed->flags & EMIT_WORKER_FINISHED) != 0)
|
|
Packit |
15f964 |
g_signal_emit (ed->config_lookup, signals[WORKER_FINISHED], 0, ed->worker, ed->params, ed->error);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if ((ed->flags & EMIT_BUSY) != 0)
|
|
Packit |
15f964 |
g_object_notify (G_OBJECT (ed->config_lookup), "busy");
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return FALSE;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
config_lookup_schedule_emit_idle (EConfigLookup *config_lookup,
|
|
Packit |
15f964 |
guint32 emit_flags,
|
|
Packit |
15f964 |
EConfigLookupWorker *worker,
|
|
Packit |
15f964 |
GCancellable *cancellable,
|
|
Packit |
15f964 |
const ENamedParameters *params,
|
|
Packit |
15f964 |
const GError *error)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
EmitData *ed;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
|
|
Packit |
15f964 |
if (worker)
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP_WORKER (worker));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
ed = g_new0 (EmitData, 1);
|
|
Packit |
15f964 |
ed->config_lookup = g_object_ref (config_lookup);
|
|
Packit |
15f964 |
ed->flags = emit_flags;
|
|
Packit |
15f964 |
ed->worker = worker ? g_object_ref (worker) : NULL;
|
|
Packit |
15f964 |
ed->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
Packit |
15f964 |
ed->params = params ? e_named_parameters_new_clone (params) : NULL;
|
|
Packit |
15f964 |
ed->error = error ? g_error_copy (error) : NULL;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_idle_add_full (G_PRIORITY_HIGH_IDLE, config_lookup_emit_idle_cb, ed, emit_data_free);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
typedef struct _ThreadData {
|
|
Packit |
15f964 |
ENamedParameters *params;
|
|
Packit |
15f964 |
EConfigLookupWorker *worker;
|
|
Packit |
15f964 |
GCancellable *cancellable;
|
|
Packit |
15f964 |
} ThreadData;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
config_lookup_thread (gpointer data,
|
|
Packit |
15f964 |
gpointer user_data)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
ThreadData *td = data;
|
|
Packit |
15f964 |
EConfigLookup *config_lookup = user_data;
|
|
Packit |
15f964 |
ESimpleAsyncResult *run_result = NULL;
|
|
Packit |
15f964 |
guint32 emit_flags;
|
|
Packit |
15f964 |
ENamedParameters *restart_params = NULL;
|
|
Packit |
15f964 |
GError *error = NULL;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_if_fail (td != NULL);
|
|
Packit |
15f964 |
g_return_if_fail (td->params != NULL);
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP_WORKER (td->worker));
|
|
Packit |
15f964 |
g_return_if_fail (G_IS_CANCELLABLE (td->cancellable));
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_config_lookup_worker_run (td->worker, config_lookup, td->params, &restart_params, td->cancellable, &error);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
emit_flags = EMIT_WORKER_FINISHED;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (g_slist_find (config_lookup->priv->worker_cancellables, td->cancellable)) {
|
|
Packit |
15f964 |
config_lookup->priv->worker_cancellables = g_slist_remove (config_lookup->priv->worker_cancellables, td->cancellable);
|
|
Packit |
15f964 |
g_object_unref (td->cancellable);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (!config_lookup->priv->worker_cancellables)
|
|
Packit |
15f964 |
emit_flags |= EMIT_BUSY;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
config_lookup_schedule_emit_idle (config_lookup, emit_flags, td->worker, NULL, restart_params, error);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if ((emit_flags & EMIT_BUSY) != 0) {
|
|
Packit |
15f964 |
run_result = config_lookup->priv->run_result;
|
|
Packit |
15f964 |
config_lookup->priv->run_result = NULL;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_clear_object (&config_lookup->priv->run_cancellable);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (run_result) {
|
|
Packit |
15f964 |
e_simple_async_result_complete_idle (run_result);
|
|
Packit |
15f964 |
g_object_unref (run_result);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_named_parameters_free (restart_params);
|
|
Packit |
15f964 |
e_named_parameters_free (td->params);
|
|
Packit |
15f964 |
g_clear_object (&td->worker);
|
|
Packit |
15f964 |
g_clear_object (&td->cancellable);
|
|
Packit |
15f964 |
g_clear_error (&error);
|
|
Packit |
15f964 |
g_free (td);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
config_lookup_set_registry (EConfigLookup *config_lookup,
|
|
Packit |
15f964 |
ESourceRegistry *registry)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
|
|
Packit |
15f964 |
g_return_if_fail (config_lookup->priv->registry == NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
config_lookup->priv->registry = g_object_ref (registry);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
config_lookup_set_property (GObject *object,
|
|
Packit |
15f964 |
guint property_id,
|
|
Packit |
15f964 |
const GValue *value,
|
|
Packit |
15f964 |
GParamSpec *pspec)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
switch (property_id) {
|
|
Packit |
15f964 |
case PROP_REGISTRY:
|
|
Packit |
15f964 |
config_lookup_set_registry (
|
|
Packit |
15f964 |
E_CONFIG_LOOKUP (object),
|
|
Packit |
15f964 |
g_value_get_object (value));
|
|
Packit |
15f964 |
return;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
config_lookup_get_property (GObject *object,
|
|
Packit |
15f964 |
guint property_id,
|
|
Packit |
15f964 |
GValue *value,
|
|
Packit |
15f964 |
GParamSpec *pspec)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
switch (property_id) {
|
|
Packit |
15f964 |
case PROP_BUSY:
|
|
Packit |
15f964 |
g_value_set_boolean (
|
|
Packit |
15f964 |
value,
|
|
Packit |
15f964 |
e_config_lookup_get_busy (
|
|
Packit |
15f964 |
E_CONFIG_LOOKUP (object)));
|
|
Packit |
15f964 |
return;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
case PROP_REGISTRY:
|
|
Packit |
15f964 |
g_value_set_object (
|
|
Packit |
15f964 |
value,
|
|
Packit |
15f964 |
e_config_lookup_get_registry (
|
|
Packit |
15f964 |
E_CONFIG_LOOKUP (object)));
|
|
Packit |
15f964 |
return;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
config_lookup_constructed (GObject *object)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
/* Chain up to parent's method. */
|
|
Packit |
15f964 |
G_OBJECT_CLASS (e_config_lookup_parent_class)->constructed (object);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_extensible_load_extensions (E_EXTENSIBLE (object));
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
config_lookup_dispose (GObject *object)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
EConfigLookup *config_lookup = E_CONFIG_LOOKUP (object);
|
|
Packit |
15f964 |
gboolean had_running_workers;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_config_lookup_cancel_all (config_lookup);
|
|
Packit |
15f964 |
|
|
Packit Service |
a0921a |
if (config_lookup->priv->pool) {
|
|
Packit Service |
a0921a |
g_thread_pool_free (config_lookup->priv->pool, TRUE, TRUE);
|
|
Packit Service |
a0921a |
config_lookup->priv->pool = NULL;
|
|
Packit Service |
a0921a |
}
|
|
Packit Service |
a0921a |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_clear_object (&config_lookup->priv->run_cancellable);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_slist_free_full (config_lookup->priv->workers, g_object_unref);
|
|
Packit |
15f964 |
config_lookup->priv->workers = NULL;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
had_running_workers = config_lookup->priv->worker_cancellables != NULL;
|
|
Packit |
15f964 |
g_slist_free_full (config_lookup->priv->worker_cancellables, g_object_unref);
|
|
Packit |
15f964 |
config_lookup->priv->worker_cancellables = NULL;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (had_running_workers)
|
|
Packit |
15f964 |
g_object_notify (object, "busy");
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_clear_object (&config_lookup->priv->registry);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Chain up to parent's method. */
|
|
Packit |
15f964 |
G_OBJECT_CLASS (e_config_lookup_parent_class)->dispose (object);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
config_lookup_finalize (GObject *object)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
EConfigLookup *config_lookup = E_CONFIG_LOOKUP (object);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_slist_free_full (config_lookup->priv->results, g_object_unref);
|
|
Packit |
15f964 |
g_mutex_clear (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/* Chain up to parent's method. */
|
|
Packit |
15f964 |
G_OBJECT_CLASS (e_config_lookup_parent_class)->finalize (object);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
e_config_lookup_class_init (EConfigLookupClass *klass)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
GObjectClass *object_class;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_type_class_add_private (klass, sizeof (EConfigLookupPrivate));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
object_class = G_OBJECT_CLASS (klass);
|
|
Packit |
15f964 |
object_class->set_property = config_lookup_set_property;
|
|
Packit |
15f964 |
object_class->get_property = config_lookup_get_property;
|
|
Packit |
15f964 |
object_class->constructed = config_lookup_constructed;
|
|
Packit |
15f964 |
object_class->dispose = config_lookup_dispose;
|
|
Packit |
15f964 |
object_class->finalize = config_lookup_finalize;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* EConfigLookup:registry:
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* The #ESourceRegistry manages #ESource instances.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.26
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
g_object_class_install_property (
|
|
Packit |
15f964 |
object_class,
|
|
Packit |
15f964 |
PROP_REGISTRY,
|
|
Packit |
15f964 |
g_param_spec_object (
|
|
Packit |
15f964 |
"registry",
|
|
Packit |
15f964 |
"Registry",
|
|
Packit |
15f964 |
"Data source registry",
|
|
Packit |
15f964 |
E_TYPE_SOURCE_REGISTRY,
|
|
Packit |
15f964 |
G_PARAM_READWRITE |
|
|
Packit |
15f964 |
G_PARAM_CONSTRUCT_ONLY |
|
|
Packit |
15f964 |
G_PARAM_STATIC_STRINGS));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* EConfigLookup:busy:
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Whether the EConfigLookup has any running workers.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
g_object_class_install_property (
|
|
Packit |
15f964 |
object_class,
|
|
Packit |
15f964 |
PROP_BUSY,
|
|
Packit |
15f964 |
g_param_spec_boolean (
|
|
Packit |
15f964 |
"busy",
|
|
Packit |
15f964 |
"Busy",
|
|
Packit |
15f964 |
NULL,
|
|
Packit |
15f964 |
FALSE,
|
|
Packit |
15f964 |
G_PARAM_READABLE |
|
|
Packit |
15f964 |
G_PARAM_STATIC_STRINGS));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* EConfigLookup::get-source:
|
|
Packit |
15f964 |
* @kind: an #EConfigLookupSourceKind
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Emitted to get an #ESource of the given @kind. Return %NULL, when not available.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.26
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
signals[GET_SOURCE] = g_signal_new (
|
|
Packit |
15f964 |
"get-source",
|
|
Packit |
15f964 |
G_TYPE_FROM_CLASS (klass),
|
|
Packit |
15f964 |
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
Packit |
15f964 |
G_STRUCT_OFFSET (EConfigLookupClass, get_source),
|
|
Packit |
15f964 |
NULL, NULL,
|
|
Packit |
15f964 |
NULL,
|
|
Packit |
15f964 |
G_TYPE_POINTER, 1,
|
|
Packit |
15f964 |
E_TYPE_CONFIG_LOOKUP_SOURCE_KIND);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* EConfigLookup::worker-started:
|
|
Packit |
15f964 |
* @worker: an #EConfigLookupWorker
|
|
Packit |
15f964 |
* @cancellable: associated #GCancellable for this worker run
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Emitted when the @worker is about to start running.
|
|
Packit |
15f964 |
* Corresponding @EConfigLookup::worker-finished is emitted when
|
|
Packit |
15f964 |
* the run is finished.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Note that this signal is always emitted in the main thread.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
signals[WORKER_STARTED] = g_signal_new (
|
|
Packit |
15f964 |
"worker-started",
|
|
Packit |
15f964 |
G_TYPE_FROM_CLASS (klass),
|
|
Packit |
15f964 |
G_SIGNAL_RUN_LAST,
|
|
Packit |
15f964 |
G_STRUCT_OFFSET (EConfigLookupClass, worker_started),
|
|
Packit |
15f964 |
NULL, NULL,
|
|
Packit |
15f964 |
NULL,
|
|
Packit |
15f964 |
G_TYPE_NONE, 2,
|
|
Packit |
15f964 |
E_TYPE_CONFIG_LOOKUP_WORKER,
|
|
Packit |
15f964 |
G_TYPE_CANCELLABLE);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* EConfigLookup::worker-finished:
|
|
Packit |
15f964 |
* @worker: an #EConfigLookupWorker
|
|
Packit |
15f964 |
* @restart_params: an optional #ENamedParameters to use when the @worker might be restarted
|
|
Packit |
15f964 |
* @error: an optional #GError with an overall result of the run
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Emitted when the @worker finished its running.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Note that this signal is always emitted in the main thread.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
signals[WORKER_FINISHED] = g_signal_new (
|
|
Packit |
15f964 |
"worker-finished",
|
|
Packit |
15f964 |
G_TYPE_FROM_CLASS (klass),
|
|
Packit |
15f964 |
G_SIGNAL_RUN_LAST,
|
|
Packit |
15f964 |
G_STRUCT_OFFSET (EConfigLookupClass, worker_finished),
|
|
Packit |
15f964 |
NULL, NULL,
|
|
Packit |
15f964 |
NULL,
|
|
Packit |
15f964 |
G_TYPE_NONE, 3,
|
|
Packit |
15f964 |
E_TYPE_CONFIG_LOOKUP_WORKER,
|
|
Packit |
15f964 |
E_TYPE_NAMED_PARAMETERS,
|
|
Packit |
15f964 |
G_TYPE_ERROR);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* EConfigLookup::result-added:
|
|
Packit |
15f964 |
* @result: an #EConfigLookupResult
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Emitted when a new @result is added to the config lookup.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Note that this signal can be emitted in a worker's dedicated thread.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
signals[RESULT_ADDED] = g_signal_new (
|
|
Packit |
15f964 |
"result-added",
|
|
Packit |
15f964 |
G_TYPE_FROM_CLASS (klass),
|
|
Packit |
15f964 |
G_SIGNAL_RUN_LAST,
|
|
Packit |
15f964 |
G_STRUCT_OFFSET (EConfigLookupClass, result_added),
|
|
Packit |
15f964 |
NULL, NULL,
|
|
Packit |
15f964 |
NULL,
|
|
Packit |
15f964 |
G_TYPE_NONE, 1,
|
|
Packit |
15f964 |
E_TYPE_CONFIG_LOOKUP_RESULT);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
static void
|
|
Packit |
15f964 |
e_config_lookup_init (EConfigLookup *config_lookup)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
config_lookup->priv = G_TYPE_INSTANCE_GET_PRIVATE (config_lookup, E_TYPE_CONFIG_LOOKUP, EConfigLookupPrivate);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_init (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
config_lookup->priv->pool = g_thread_pool_new (config_lookup_thread, config_lookup, 10, FALSE, NULL);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_new:
|
|
Packit |
15f964 |
* @registry: an #ESourceRegistry
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Creates a new #EConfigLookup instance.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns: (transfer full): a new #EConfigLookup
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.26
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
EConfigLookup *
|
|
Packit |
15f964 |
e_config_lookup_new (ESourceRegistry *registry)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return g_object_new (E_TYPE_CONFIG_LOOKUP,
|
|
Packit |
15f964 |
"registry", registry,
|
|
Packit |
15f964 |
NULL);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_get_registry:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns the #ESourceRegistry passed to e_config_lookup_new().
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns: (transfer none): an #ESourceRegistry
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.26
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
ESourceRegistry *
|
|
Packit |
15f964 |
e_config_lookup_get_registry (EConfigLookup *config_lookup)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
g_return_val_if_fail (E_IS_CONFIG_LOOKUP (config_lookup), NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return config_lookup->priv->registry;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_get_source:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
* @kind: one of #EConfigLookupSourceKind, except of the %E_CONFIG_LOOKUP_SOURCE_UNKNOWN
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Emits the #EConfigLookup::get-source signal and any listener can provide
|
|
Packit |
15f964 |
* the source. The function can return %NULL, when there are no listeners
|
|
Packit |
15f964 |
* or when such source is not available.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns: (transfer none) (nullable): an #ESource of the given @kind, or %NULL, if not found
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.26
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
ESource *
|
|
Packit |
15f964 |
e_config_lookup_get_source (EConfigLookup *config_lookup,
|
|
Packit |
15f964 |
EConfigLookupSourceKind kind)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
ESource *source = NULL;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_val_if_fail (E_IS_CONFIG_LOOKUP (config_lookup), NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_signal_emit (config_lookup, signals[GET_SOURCE], 0, kind, &source);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return source;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_get_busy:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns whether there's any running worker. They can be cancelled
|
|
Packit |
15f964 |
* with e_config_lookup_cancel_all().
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns: whether there's any running worker
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
gboolean
|
|
Packit |
15f964 |
e_config_lookup_get_busy (EConfigLookup *config_lookup)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
gboolean busy;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_val_if_fail (E_IS_CONFIG_LOOKUP (config_lookup), FALSE);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
busy = config_lookup->priv->worker_cancellables != NULL;
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return busy;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_cancel_all:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Cancels all pending workers.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
void
|
|
Packit |
15f964 |
e_config_lookup_cancel_all (EConfigLookup *config_lookup)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
GSList *cancellables;
|
|
Packit |
15f964 |
GCancellable *run_cancellable;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
cancellables = g_slist_copy_deep (config_lookup->priv->worker_cancellables, (GCopyFunc) g_object_ref, NULL);
|
|
Packit |
15f964 |
run_cancellable = config_lookup->priv->run_cancellable ? g_object_ref (config_lookup->priv->run_cancellable) : NULL;
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_slist_foreach (cancellables, (GFunc) g_cancellable_cancel, NULL);
|
|
Packit |
15f964 |
g_slist_free_full (cancellables, g_object_unref);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (run_cancellable) {
|
|
Packit |
15f964 |
g_cancellable_cancel (run_cancellable);
|
|
Packit |
15f964 |
g_object_unref (run_cancellable);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_register_worker:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
* @worker: an #EConfigLookupWorker
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Registers a @worker as a worker, which can be run as part of e_config_lookup_run().
|
|
Packit |
15f964 |
* The function adds its own reference to @worker.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
void
|
|
Packit |
15f964 |
e_config_lookup_register_worker (EConfigLookup *config_lookup,
|
|
Packit |
15f964 |
EConfigLookupWorker *worker)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
GSList *existing_worker;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP_WORKER (worker));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
existing_worker = g_slist_find (config_lookup->priv->workers, worker);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_warn_if_fail (existing_worker == NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (!existing_worker)
|
|
Packit |
15f964 |
config_lookup->priv->workers = g_slist_prepend (config_lookup->priv->workers, g_object_ref (worker));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_unregister_worker:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
* @worker: an #EConfigLookupWorker
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Removes a @worker previously registered with e_config_lookup_register_worker().
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
void
|
|
Packit |
15f964 |
e_config_lookup_unregister_worker (EConfigLookup *config_lookup,
|
|
Packit |
15f964 |
EConfigLookupWorker *worker)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
GSList *existing_worker;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP_WORKER (worker));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
existing_worker = g_slist_find (config_lookup->priv->workers, worker);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_warn_if_fail (existing_worker != NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (existing_worker) {
|
|
Packit |
15f964 |
config_lookup->priv->workers = g_slist_remove (config_lookup->priv->workers, worker);
|
|
Packit |
15f964 |
g_object_unref (worker);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_dup_registered_workers:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns a list of all registered #EConfigLookupWorker objects.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* The returned #GSList should be freed with
|
|
Packit |
15f964 |
* g_slist_free_full (workers, g_object_unref);
|
|
Packit |
15f964 |
* when no longer needed.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns: (transfer full) (element-type EConfigLookupWorker): a #GSList with all
|
|
Packit |
15f964 |
* workers registered with e_config_lookup_register_worker().
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
GSList *
|
|
Packit |
15f964 |
e_config_lookup_dup_registered_workers (EConfigLookup *config_lookup)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
GSList *workers;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_val_if_fail (E_IS_CONFIG_LOOKUP (config_lookup), NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
workers = g_slist_copy_deep (config_lookup->priv->workers, (GCopyFunc) g_object_ref, NULL);
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return workers;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_run:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
* @params: an #ENamedParameters with lookup parameters
|
|
Packit |
15f964 |
* @cancellable: an optional #GCancellable, or %NULL
|
|
Packit |
15f964 |
* @callback: a callback to call, when the run is finished
|
|
Packit |
15f964 |
* @user_data: user data for the @callback
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Runs configuration lookup asynchronously. Once the run is done, the @callback is called,
|
|
Packit |
15f964 |
* and the call can be finished with e_config_lookup_run_finish(). The @callback is always
|
|
Packit |
15f964 |
* called from the main thread.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Workers can be run individually using e_config_lookup_run_worker().
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Note that there cannot be run two lookups at the same time, thus if it
|
|
Packit |
15f964 |
* happens, then the @callback is called immediately with a %NULL result.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.26
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
void
|
|
Packit |
15f964 |
e_config_lookup_run (EConfigLookup *config_lookup,
|
|
Packit |
15f964 |
const ENamedParameters *params,
|
|
Packit |
15f964 |
GCancellable *cancellable,
|
|
Packit |
15f964 |
GAsyncReadyCallback callback,
|
|
Packit |
15f964 |
gpointer user_data)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
GSList *workers, *link;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
|
|
Packit |
15f964 |
g_return_if_fail (params != NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (config_lookup->priv->run_result) {
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (callback)
|
|
Packit |
15f964 |
callback (G_OBJECT (config_lookup), NULL, user_data);
|
|
Packit |
15f964 |
return;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_slist_free_full (config_lookup->priv->results, g_object_unref);
|
|
Packit |
15f964 |
config_lookup->priv->results = NULL;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (cancellable)
|
|
Packit |
15f964 |
g_object_ref (cancellable);
|
|
Packit |
15f964 |
else
|
|
Packit |
15f964 |
cancellable = g_cancellable_new ();
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
config_lookup->priv->run_result = e_simple_async_result_new (G_OBJECT (config_lookup), callback, user_data, e_config_lookup_run);
|
|
Packit |
15f964 |
config_lookup->priv->run_cancellable = cancellable;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
workers = g_slist_copy_deep (config_lookup->priv->workers, (GCopyFunc) g_object_ref, NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (workers) {
|
|
Packit |
15f964 |
for (link = workers; link; link = g_slist_next (link)) {
|
|
Packit |
15f964 |
EConfigLookupWorker *worker = link->data;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
e_config_lookup_run_worker (config_lookup, worker, params, cancellable);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_slist_free_full (workers, g_object_unref);
|
|
Packit |
15f964 |
} else {
|
|
Packit |
15f964 |
ESimpleAsyncResult *run_result;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
run_result = config_lookup->priv->run_result;
|
|
Packit |
15f964 |
config_lookup->priv->run_result = NULL;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_clear_object (&config_lookup->priv->run_cancellable);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (run_result) {
|
|
Packit |
15f964 |
e_simple_async_result_complete_idle (run_result);
|
|
Packit |
15f964 |
g_object_unref (run_result);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_run_finish:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
* @result: result of the operation
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Finishes the configuration lookup previously run by e_config_lookup_run().
|
|
Packit |
15f964 |
* It's expected that the extensions may fail, thus it doesn't return
|
|
Packit |
15f964 |
* anything and is provided mainly for consistency with asynchronous API.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.26
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
void
|
|
Packit |
15f964 |
e_config_lookup_run_finish (EConfigLookup *config_lookup,
|
|
Packit |
15f964 |
GAsyncResult *result)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
|
|
Packit |
15f964 |
g_return_if_fail (G_IS_ASYNC_RESULT (result));
|
|
Packit |
15f964 |
g_return_if_fail (g_async_result_is_tagged (result, e_config_lookup_run));
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_run_worker:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
* @worker: an #EConfigLookupWorker to run in a dedicated thread
|
|
Packit |
15f964 |
* @params: an #ENamedParameters with lookup parameters
|
|
Packit |
15f964 |
* @cancellable: an optional #GCancellable, or %NULL
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Creates a new thread and runs @worker in it. When the @cancellable is %NULL,
|
|
Packit |
15f964 |
* then there's creates a new #CamelOperation, which either proxies currently
|
|
Packit |
15f964 |
* running lookup or the newly created cancellable is completely independent.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* This function can be called while there's an ongoing configuration lookup, but
|
|
Packit |
15f964 |
* also when the @worker is restarted.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
void
|
|
Packit |
15f964 |
e_config_lookup_run_worker (EConfigLookup *config_lookup,
|
|
Packit |
15f964 |
EConfigLookupWorker *worker,
|
|
Packit |
15f964 |
const ENamedParameters *params,
|
|
Packit |
15f964 |
GCancellable *cancellable)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
ThreadData *td;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP_WORKER (worker));
|
|
Packit |
15f964 |
g_return_if_fail (params != NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
td = g_new0 (ThreadData, 1);
|
|
Packit |
15f964 |
td->params = e_named_parameters_new_clone (params);
|
|
Packit |
15f964 |
td->worker = g_object_ref (worker);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (cancellable)
|
|
Packit |
15f964 |
td->cancellable = camel_operation_new_proxy (cancellable);
|
|
Packit |
15f964 |
else if (config_lookup->priv->run_cancellable)
|
|
Packit |
15f964 |
td->cancellable = camel_operation_new_proxy (config_lookup->priv->run_cancellable);
|
|
Packit |
15f964 |
else
|
|
Packit |
15f964 |
td->cancellable = camel_operation_new ();
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
camel_operation_push_message (td->cancellable, "%s", _("Running…"));
|
|
Packit |
15f964 |
config_lookup->priv->worker_cancellables = g_slist_prepend (config_lookup->priv->worker_cancellables, g_object_ref (td->cancellable));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
config_lookup_schedule_emit_idle (config_lookup, EMIT_WORKER_STARTED |
|
|
Packit |
15f964 |
(!config_lookup->priv->worker_cancellables->next ? EMIT_BUSY : 0),
|
|
Packit |
15f964 |
worker, td->cancellable, NULL, NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_thread_pool_push (config_lookup->priv->pool, td, NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_add_result:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
* @result: (transfer full): an #EConfigLookupResult
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Adds a new @result in a list of known configuration lookup results.
|
|
Packit |
15f964 |
* The @config_lookup assumes ownership of the @result and frees it
|
|
Packit |
15f964 |
* when no longer needed.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* The list of results can be obtained with e_config_lookup_dup_results().
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.26
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
void
|
|
Packit |
15f964 |
e_config_lookup_add_result (EConfigLookup *config_lookup,
|
|
Packit |
15f964 |
EConfigLookupResult *result)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP_RESULT (result));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
config_lookup->priv->results = g_slist_prepend (config_lookup->priv->results, result);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_signal_emit (config_lookup, signals[RESULT_ADDED], 0, result);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_count_results:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns: how many results had been added already.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
gint
|
|
Packit |
15f964 |
e_config_lookup_count_results (EConfigLookup *config_lookup)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
gint n_results;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_val_if_fail (E_IS_CONFIG_LOOKUP (config_lookup), -1);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
n_results = g_slist_length (config_lookup->priv->results);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return n_results;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_dup_results:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
* @kind: an #EConfigLookupResultKind to filter the results with
|
|
Packit |
15f964 |
* @protocol: (nullable): optional protocol to filter the results with, or %NULL
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns a #GSList with #EConfigLookupResult objects satisfying
|
|
Packit |
15f964 |
* the @kind and @protocol filtering conditions. To receive all
|
|
Packit |
15f964 |
* gathered results use %E_CONFIG_LOOKUP_RESULT_UNKNOWN for @kind
|
|
Packit |
15f964 |
* and %NULL for the @protocol.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Free the returned #GSList with
|
|
Packit |
15f964 |
* g_slist_free_full (results, g_object_unref);
|
|
Packit |
15f964 |
* when no longer needed.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns: (transfer full) (element-type EConfigLookupResult): a #GSList
|
|
Packit |
15f964 |
* with results satisfying the @kind and @protocol filtering conditions.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
GSList *
|
|
Packit |
15f964 |
e_config_lookup_dup_results (EConfigLookup *config_lookup,
|
|
Packit |
15f964 |
EConfigLookupResultKind kind,
|
|
Packit |
15f964 |
const gchar *protocol)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
GSList *results = NULL, *link;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_return_val_if_fail (E_IS_CONFIG_LOOKUP (config_lookup), NULL);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
for (link = config_lookup->priv->results; link; link = g_slist_next (link)) {
|
|
Packit |
15f964 |
EConfigLookupResult *result = link->data;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (!E_IS_CONFIG_LOOKUP_RESULT (result))
|
|
Packit |
15f964 |
continue;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (kind != E_CONFIG_LOOKUP_RESULT_UNKNOWN &&
|
|
Packit |
15f964 |
kind != e_config_lookup_result_get_kind (result))
|
|
Packit |
15f964 |
continue;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (protocol &&
|
|
Packit |
15f964 |
g_strcmp0 (protocol, e_config_lookup_result_get_protocol (result)) != 0)
|
|
Packit |
15f964 |
continue;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
results = g_slist_prepend (results, g_object_ref (result));
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return results;
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_clear_results:
|
|
Packit |
15f964 |
* @config_lookup: an #EConfigLookup
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Frees all gathered results. This might be usually called before
|
|
Packit |
15f964 |
* starting new custom lookup. The e_config_lookup_run() frees
|
|
Packit |
15f964 |
* all results automatically.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
void
|
|
Packit |
15f964 |
e_config_lookup_clear_results (EConfigLookup *config_lookup)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
g_return_if_fail (E_IS_CONFIG_LOOKUP (config_lookup));
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_lock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_slist_free_full (config_lookup->priv->results, g_object_unref);
|
|
Packit |
15f964 |
config_lookup->priv->results = NULL;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
g_mutex_unlock (&config_lookup->priv->property_lock);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_encode_certificate_trust:
|
|
Packit |
15f964 |
* @response: an #ETrustPromptResponse to encode
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Encodes @response to a string. This can be decoded back to enum
|
|
Packit |
15f964 |
* with e_config_lookup_decode_certificate_trust().
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns: string representation of @response.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
const gchar *
|
|
Packit |
15f964 |
e_config_lookup_encode_certificate_trust (ETrustPromptResponse response)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
return e_enum_to_string (E_TYPE_TRUST_PROMPT_RESPONSE, response);
|
|
Packit |
15f964 |
}
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
/**
|
|
Packit |
15f964 |
* e_config_lookup_decode_certificate_trust:
|
|
Packit |
15f964 |
* @value: a text value to decode
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Decodes text @value to #ETrustPromptResponse, previously encoded
|
|
Packit |
15f964 |
* with e_config_lookup_encode_certificate_trust().
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Returns: an #ETrustPromptResponse corresponding to @value.
|
|
Packit |
15f964 |
*
|
|
Packit |
15f964 |
* Since: 3.28
|
|
Packit |
15f964 |
**/
|
|
Packit |
15f964 |
ETrustPromptResponse
|
|
Packit |
15f964 |
e_config_lookup_decode_certificate_trust (const gchar *value)
|
|
Packit |
15f964 |
{
|
|
Packit |
15f964 |
gint decoded;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
if (!value ||
|
|
Packit |
15f964 |
!e_enum_from_string (E_TYPE_TRUST_PROMPT_RESPONSE, value, &decoded))
|
|
Packit |
15f964 |
decoded = E_TRUST_PROMPT_RESPONSE_UNKNOWN;
|
|
Packit |
15f964 |
|
|
Packit |
15f964 |
return decoded;
|
|
Packit |
15f964 |
}
|