application: move GoaClient to manager

This commit is contained in:
Georges Basile Stavracas Neto
2015-05-25 12:35:56 -04:00
committed by Erick Pérez Castellanos
parent 0142b0494e
commit 7942677b8e
5 changed files with 65 additions and 119 deletions
-73
View File
@@ -38,8 +38,6 @@ struct _GcalApplicationPrivate
{
GtkWidget *window;
GoaClient *client;
GSettings *settings;
GcalManager *manager;
@@ -52,14 +50,6 @@ struct _GcalApplicationPrivate
icaltimetype *initial_date;
};
enum
{
GOA_CLIENT_READY,
NUM_SIGNALS
};
static guint signals[NUM_SIGNALS] = { 0, };
static void gcal_application_finalize (GObject *object);
static void gcal_application_activate (GApplication *app);
@@ -100,10 +90,6 @@ static void gcal_application_dbus_unregister (GApplication *
GDBusConnection *connection,
const gchar *object_path);
static void gcal_application_goa_client_ready (GObject *source,
GAsyncResult *result,
gpointer user_data);
G_DEFINE_TYPE_WITH_PRIVATE (GcalApplication, gcal_application, GTK_TYPE_APPLICATION);
static gboolean show_version = FALSE;
@@ -211,22 +197,6 @@ gcal_application_class_init (GcalApplicationClass *klass)
application_class->dbus_register = gcal_application_dbus_register;
application_class->dbus_unregister = gcal_application_dbus_unregister;
/**
* GcalApplication::goa-client-ready:
*
* Emited when the #GoaClient asyncronous loading is finished.
*/
signals[GOA_CLIENT_READY] = g_signal_new ("source-removed",
GCAL_TYPE_APPLICATION,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GcalApplicationClass, goa_client_ready),
NULL,
NULL,
NULL,
G_TYPE_NONE,
1,
GOA_TYPE_CLIENT);
}
static void
@@ -243,35 +213,9 @@ gcal_application_init (GcalApplication *self)
priv->search_provider = gcal_shell_search_provider_new ();
gcal_shell_search_provider_connect (priv->search_provider, priv->manager);
goa_client_new (NULL, // we won't really cancel it
(GAsyncReadyCallback) gcal_application_goa_client_ready,
self);
self->priv = priv;
}
static void
gcal_application_goa_client_ready (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GcalApplicationPrivate *priv = GCAL_APPLICATION (user_data)->priv;
GError *error = NULL;
priv->client = goa_client_new_finish (result, &error);
g_signal_emit (user_data, signals[GOA_CLIENT_READY], 0, priv->client);
if (error != NULL)
{
g_warning ("%s: Error retrieving GoaClient: %s",
G_STRFUNC,
error->message);
g_error_free (error);
}
}
static void
gcal_application_finalize (GObject *object)
{
@@ -636,20 +580,3 @@ gcal_application_set_initial_date (GcalApplication *application,
g_free (priv->initial_date);
priv->initial_date = gcal_dup_icaltime (date);
}
/**
* gcal_application_get_client:
* @application: a #GcalApplication
*
* Retrieves the internal #GoaClient from @application. It
* should not be unreferenced after usage.
*
* Returns: (transfer none): the #GoaClient of @application
*/
GoaClient*
gcal_application_get_client (GcalApplication *application)
{
g_return_val_if_fail (GCAL_IS_APPLICATION (application), NULL);
return application->priv->client;
}
-3
View File
@@ -49,8 +49,6 @@ struct _GcalApplication
struct _GcalApplicationClass
{
GtkApplicationClass parent_class;
void (*goa_client_ready) (GcalApplication *app, GoaClient *client);
};
GType gcal_application_get_type (void) G_GNUC_CONST;
@@ -61,7 +59,6 @@ void gcal_application_set_uuid (GcalApplication *application,
const gchar *uuid);
void gcal_application_set_initial_date (GcalApplication *application,
const icaltimetype *date);
GoaClient* gcal_application_get_client (GcalApplication *application);
G_END_DECLS
+59 -1
View File
@@ -67,7 +67,10 @@ typedef struct
GCancellable *async_ops;
GoaClient *client;
/* state flags */
gboolean goa_client_ready;
gchar **disabled_sources;
gint sources_at_launch;
@@ -102,6 +105,7 @@ enum
SOURCE_REMOVED,
LOAD_COMPLETED,
QUERY_COMPLETED,
GOA_CLIENT_READY,
NUM_SIGNALS
};
@@ -675,12 +679,42 @@ gcal_manager_class_init (GcalManagerClass *klass)
G_STRUCT_OFFSET (GcalManagerClass, query_completed),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[GOA_CLIENT_READY] = g_signal_new ("goa-client-ready", GCAL_TYPE_MANAGER, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GcalManagerClass, goa_client_ready),
NULL, NULL, NULL,
G_TYPE_NONE, 1, GOA_TYPE_CLIENT);
}
static void
gcal_manager_client_ready_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GcalManagerPrivate *priv = gcal_manager_get_instance_private (GCAL_MANAGER (user_data));
GError *error = NULL;
priv->client = goa_client_new_finish (result, &error);
priv->goa_client_ready = TRUE;
g_signal_emit (user_data, signals[GOA_CLIENT_READY], 0, priv->client);
if (error != NULL)
{
g_warning ("%s: Error retrieving GoaClient: %s",
G_STRFUNC,
error->message);
g_error_free (error);
}
}
static void
gcal_manager_init (GcalManager *self)
{
;
goa_client_new (NULL, // we won't really cancel it
(GAsyncReadyCallback) gcal_manager_client_ready_cb,
self);
}
static void
@@ -1495,3 +1529,27 @@ gcal_manager_get_event_from_shell_search (GcalManager *manager,
return new_data;
}
gboolean
gcal_manager_is_client_ready (GcalManager *manager)
{
GcalManagerPrivate *priv;
g_return_val_if_fail (GCAL_IS_MANAGER (manager), FALSE);
priv = gcal_manager_get_instance_private (manager);
return priv->goa_client_ready;
}
GoaClient*
gcal_manager_get_client (GcalManager *manager)
{
GcalManagerPrivate *priv;
g_return_val_if_fail (GCAL_IS_MANAGER (manager), FALSE);
priv = gcal_manager_get_instance_private (manager);
return priv->client;
}
+6
View File
@@ -23,6 +23,7 @@
#include "e-cal-data-model.h"
#include <libical/icaltime.h>
#include <goa/goa.h>
G_BEGIN_DECLS
@@ -51,6 +52,7 @@ struct _GcalManagerClass
void (*source_removed) (GcalManager *manager, ESource *source);
void (*load_completed) (GcalManager *manager);
void (*query_completed) (GcalManager *manager);
void (*goa_client_ready) (GcalManager *manager, GoaClient *client);
};
typedef struct
@@ -161,6 +163,10 @@ gboolean gcal_manager_load_completed (GcalManager *manager
GcalEventData* gcal_manager_get_event_from_shell_search (GcalManager *manager,
const gchar *uuid);
gboolean gcal_manager_is_client_ready (GcalManager *manager);
GoaClient* gcal_manager_get_client (GcalManager *manager);
G_END_DECLS
#endif /* __GCAL_MANAGER_H__ */
-42
View File
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gcal-application.h"
#include "gcal-source-dialog.h"
#include "gcal-utils.h"
@@ -89,7 +88,6 @@ typedef struct
GSimpleActionGroup *action_group;
/* manager */
GcalApplication *application;
GcalManager *manager;
} GcalSourceDialogPrivate;
@@ -1824,44 +1822,6 @@ gcal_source_dialog_constructed (GObject *object)
gtk_window_set_titlebar (GTK_WINDOW (object), priv->headerbar);
}
static void
gcal_source_dialog_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GcalSourceDialog *self = GCAL_SOURCE_DIALOG (object);
switch (prop_id)
{
case PROP_APPLICATION:
g_value_set_object (value, self->priv->application);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_source_dialog_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GcalSourceDialog *self = GCAL_SOURCE_DIALOG (object);
switch (prop_id)
{
case PROP_APPLICATION:
self->priv->application = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_source_dialog_class_init (GcalSourceDialogClass *klass)
{
@@ -1876,8 +1836,6 @@ gcal_source_dialog_class_init (GcalSourceDialogClass *klass)
g_type_ensure (E_TYPE_SOURCE_LOCAL);
object_class->constructed = gcal_source_dialog_constructed;
object_class->get_property = gcal_source_dialog_get_property;
object_class->set_property = gcal_source_dialog_set_property;
widget_class = GTK_WIDGET_CLASS (klass);