1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-12-12 07:37:35 +00:00

Ringer: Use Manager

This commit is contained in:
Julian Sparber 2020-03-18 12:53:13 +01:00
parent c5cb1a97ed
commit 3d4b547d04
No known key found for this signature in database
GPG key ID: 7A0E81F405F35D6A
3 changed files with 31 additions and 80 deletions

View file

@ -335,7 +335,7 @@ start_proper (CallsApplication *self)
provider = calls_manager_get_real_provider (calls_manager_get_default ()); provider = calls_manager_get_real_provider (calls_manager_get_default ());
g_assert (provider != NULL); g_assert (provider != NULL);
self->ringer = calls_ringer_new (provider); self->ringer = calls_ringer_new ();
g_assert (self->ringer != NULL); g_assert (self->ringer != NULL);
self->record_store = calls_record_store_new (provider); self->record_store = calls_record_store_new (provider);

View file

@ -23,7 +23,7 @@
*/ */
#include "calls-ringer.h" #include "calls-ringer.h"
#include "calls-enumerate.h" #include "calls-manager.h"
#include "config.h" #include "config.h"
#include <gsound.h> #include <gsound.h>
@ -35,7 +35,6 @@ struct _CallsRinger
{ {
GObject parent_instance; GObject parent_instance;
CallsProvider *provider;
gchar *theme_name; gchar *theme_name;
GSoundContext *ctx; GSoundContext *ctx;
unsigned ring_count; unsigned ring_count;
@ -44,13 +43,6 @@ struct _CallsRinger
G_DEFINE_TYPE (CallsRinger, calls_ringer, G_TYPE_OBJECT); G_DEFINE_TYPE (CallsRinger, calls_ringer, G_TYPE_OBJECT);
enum {
PROP_0,
PROP_PROVIDER,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
static void static void
ringer_error (CallsRinger *self, ringer_error (CallsRinger *self,
@ -330,13 +322,20 @@ static void
call_added_cb (CallsRinger *self, CallsCall *call) call_added_cb (CallsRinger *self, CallsCall *call)
{ {
update_count (self, call, +1); update_count (self, call, +1);
g_signal_connect_swapped (call,
"state-changed",
G_CALLBACK (state_changed_cb),
self);
} }
static void static void
call_removed_cb (CallsRinger *self, CallsCall *call, const gchar *reason) call_removed_cb (CallsRinger *self, CallsCall *call)
{ {
update_count (self, call, -1); update_count (self, call, -1);
g_signal_handlers_disconnect_by_data (call, self);
} }
@ -346,67 +345,32 @@ calls_ringer_init (CallsRinger *self)
} }
static void
set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
CallsRinger *self = CALLS_RINGER (object);
switch (property_id) {
case PROP_PROVIDER:
g_set_object (&self->provider, CALLS_PROVIDER (g_value_get_object (value)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
set_up_provider (CallsRinger *self)
{
CallsEnumerateParams *params;
params = calls_enumerate_params_new (self);
calls_enumerate_params_add
(params, CALLS_TYPE_ORIGIN, "call-added", G_CALLBACK (call_added_cb));
calls_enumerate_params_add
(params, CALLS_TYPE_ORIGIN, "call-removed", G_CALLBACK (call_removed_cb));
calls_enumerate_params_add
(params, CALLS_TYPE_CALL, "state-changed", G_CALLBACK (state_changed_cb));
calls_enumerate (self->provider, params);
g_object_unref (params);
}
static void static void
constructed (GObject *object) constructed (GObject *object)
{ {
g_autoptr (GList) calls = NULL;
GList *c;
CallsRinger *self = CALLS_RINGER (object); CallsRinger *self = CALLS_RINGER (object);
monitor_theme_name (self); monitor_theme_name (self);
create_ctx (self); create_ctx (self);
set_up_provider (self);
G_OBJECT_CLASS (calls_ringer_parent_class)->constructed (object); g_signal_connect_swapped (calls_manager_get_default (),
"call-add",
G_CALLBACK (call_added_cb),
self);
g_signal_connect_swapped (calls_manager_get_default (),
"call-remove",
G_CALLBACK (call_removed_cb),
self);
calls = calls_manager_get_calls (calls_manager_get_default ());
for (c = calls; c != NULL; c = c->next) {
call_added_cb (self, c->data);
} }
G_OBJECT_CLASS (calls_ringer_parent_class)->constructed (object);
static void
dispose (GObject *object)
{
CallsRinger *self = CALLS_RINGER (object);
g_clear_object (&self->provider);
G_OBJECT_CLASS (calls_ringer_parent_class)->dispose (object);
} }
@ -426,25 +390,12 @@ calls_ringer_class_init (CallsRingerClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = set_property;
object_class->constructed = constructed; object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize; object_class->finalize = finalize;
props[PROP_PROVIDER] =
g_param_spec_object ("provider",
_("Provider"),
_("An object implementing low-level call-making functionality"),
CALLS_TYPE_PROVIDER,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
} }
CallsRinger * CallsRinger *
calls_ringer_new (CallsProvider *provider) calls_ringer_new (void)
{ {
return g_object_new (CALLS_TYPE_RINGER, return g_object_new (CALLS_TYPE_RINGER, NULL);
"provider", provider,
NULL);
} }

View file

@ -25,7 +25,7 @@
#ifndef CALLS_RINGER_H__ #ifndef CALLS_RINGER_H__
#define CALLS_RINGER_H__ #define CALLS_RINGER_H__
#include "calls-provider.h" #include <glib-object.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -33,7 +33,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (CallsRinger, calls_ringer, CALLS, RINGER, GObject); G_DECLARE_FINAL_TYPE (CallsRinger, calls_ringer, CALLS, RINGER, GObject);
CallsRinger *calls_ringer_new (CallsProvider *provider); CallsRinger *calls_ringer_new (void);
G_END_DECLS G_END_DECLS