mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-07 04:15:32 +00:00
settings: Convert to the singleton pattern
We only have a single source of settings, so we should reflect that by using a singleton. This also reduces our LoC. This doesn't impair our ability to run tests because there we run with GSETTINGS_BACKEND=memory
This commit is contained in:
parent
d28be2650b
commit
94fa13af4c
11 changed files with 26 additions and 57 deletions
|
@ -154,7 +154,6 @@ calls_sip_media_manager_finalize (GObject *object)
|
|||
CallsSipMediaManager *self = CALLS_SIP_MEDIA_MANAGER (object);
|
||||
|
||||
g_list_free (self->preferred_codecs);
|
||||
g_object_unref (self->settings);
|
||||
g_object_unref (self->pipelines);
|
||||
|
||||
G_OBJECT_CLASS (calls_sip_media_manager_parent_class)->finalize (object);
|
||||
|
@ -176,7 +175,7 @@ calls_sip_media_manager_init (CallsSipMediaManager *self)
|
|||
if (!gst_is_initialized ())
|
||||
gst_init (NULL, NULL);
|
||||
|
||||
self->settings = calls_settings_new ();
|
||||
self->settings = calls_settings_get_default ();
|
||||
g_signal_connect_swapped (self->settings,
|
||||
"notify::preferred-audio-codecs",
|
||||
G_CALLBACK (on_notify_preferred_audio_codecs),
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "calls-contacts-provider.h"
|
||||
#include "calls-best-match.h"
|
||||
#include "calls-settings.h"
|
||||
|
||||
#include <gee-0.8/gee.h>
|
||||
#include <folks/folks.h>
|
||||
|
@ -72,7 +73,6 @@ G_DEFINE_TYPE (CallsContactsProvider, calls_contacts_provider, G_TYPE_OBJECT)
|
|||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_SETTINGS,
|
||||
PROP_CAN_ADD_CONTACTS,
|
||||
PROP_LAST_PROP
|
||||
};
|
||||
|
@ -239,26 +239,6 @@ on_contacts_appeared (GDBusConnection *connection,
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_contacts_provider_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
CallsContactsProvider *self = CALLS_CONTACTS_PROVIDER (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_SETTINGS:
|
||||
self->settings = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_contacts_provider_get_property (GObject *object,
|
||||
guint property_id,
|
||||
|
@ -287,7 +267,6 @@ calls_contacts_provider_finalize (GObject *object)
|
|||
g_clear_handle_id (&self->bus_watch_id, g_bus_unwatch_name);
|
||||
g_clear_object (&self->contacts_action_group);
|
||||
g_clear_object (&self->folks_aggregator);
|
||||
g_clear_object (&self->settings);
|
||||
g_clear_pointer (&self->best_matches, g_hash_table_unref);
|
||||
|
||||
G_OBJECT_CLASS (calls_contacts_provider_parent_class)->finalize (object);
|
||||
|
@ -300,7 +279,6 @@ calls_contacts_provider_class_init (CallsContactsProviderClass *klass)
|
|||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->get_property = calls_contacts_provider_get_property;
|
||||
object_class->set_property = calls_contacts_provider_set_property;
|
||||
object_class->finalize = calls_contacts_provider_finalize;
|
||||
|
||||
/**
|
||||
|
@ -338,20 +316,6 @@ calls_contacts_provider_class_init (CallsContactsProviderClass *klass)
|
|||
1,
|
||||
FOLKS_TYPE_INDIVIDUAL);
|
||||
|
||||
/**
|
||||
* CallsContactsProvider::settings:
|
||||
*
|
||||
* The settings are used to get the country code
|
||||
* which is used for contact lookups.
|
||||
*/
|
||||
props[PROP_SETTINGS] =
|
||||
g_param_spec_object ("settings",
|
||||
"settings",
|
||||
"The settings object to use",
|
||||
CALLS_TYPE_SETTINGS,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* CallsContactsProvider::can-add-contacts:
|
||||
*
|
||||
|
@ -372,6 +336,8 @@ static void
|
|||
calls_contacts_provider_init (CallsContactsProvider *self)
|
||||
{
|
||||
g_autoptr (GeeCollection) individuals = NULL;
|
||||
|
||||
self->settings = calls_settings_get_default ();
|
||||
self->folks_aggregator = folks_individual_aggregator_dup ();
|
||||
|
||||
individuals = calls_contacts_provider_get_individuals (self);
|
||||
|
@ -404,9 +370,9 @@ calls_contacts_provider_init (CallsContactsProvider *self)
|
|||
|
||||
|
||||
CallsContactsProvider *
|
||||
calls_contacts_provider_new (CallsSettings *settings)
|
||||
calls_contacts_provider_new (void)
|
||||
{
|
||||
return g_object_new (CALLS_TYPE_CONTACTS_PROVIDER, "settings", settings, NULL);
|
||||
return g_object_new (CALLS_TYPE_CONTACTS_PROVIDER, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "calls-best-match.h"
|
||||
#include "calls-settings.h"
|
||||
|
||||
#include <folks/folks.h>
|
||||
#include <glib-object.h>
|
||||
|
@ -49,7 +48,7 @@ typedef void (*IdleCallback) (gpointer user_data,
|
|||
|
||||
G_DECLARE_FINAL_TYPE (CallsContactsProvider, calls_contacts_provider, CALLS, CONTACTS_PROVIDER, GObject);
|
||||
|
||||
CallsContactsProvider *calls_contacts_provider_new (CallsSettings *settings);
|
||||
CallsContactsProvider *calls_contacts_provider_new (void);
|
||||
GeeCollection *calls_contacts_provider_get_individuals (CallsContactsProvider *self);
|
||||
CallsBestMatch *calls_contacts_provider_lookup_id (CallsContactsProvider *self,
|
||||
const char *id);
|
||||
|
|
|
@ -646,7 +646,6 @@ calls_manager_finalize (GObject *object)
|
|||
|
||||
g_clear_object (&self->origins);
|
||||
g_clear_object (&self->contacts_provider);
|
||||
g_clear_object (&self->settings);
|
||||
|
||||
g_clear_pointer (&self->providers, g_hash_table_unref);
|
||||
g_clear_pointer (&self->origins_by_protocol, g_hash_table_unref);
|
||||
|
@ -795,9 +794,9 @@ calls_manager_init (CallsManager *self)
|
|||
/* This hash table only owns the value, not the key */
|
||||
self->calls = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref);
|
||||
|
||||
self->settings = calls_settings_new ();
|
||||
self->settings = calls_settings_get_default ();
|
||||
// Load the contacts provider
|
||||
self->contacts_provider = calls_contacts_provider_new (self->settings);
|
||||
self->contacts_provider = calls_contacts_provider_new ();
|
||||
|
||||
peas = peas_engine_get_default ();
|
||||
|
||||
|
|
|
@ -195,14 +195,21 @@ calls_settings_init (CallsSettings *self)
|
|||
}
|
||||
|
||||
/**
|
||||
* calls_settings_new:
|
||||
* calls_settings_get_default:
|
||||
*
|
||||
* Returns: (transfer full): A #CallsSettings.
|
||||
* Returns: (transfer none): A #CallsSettings.
|
||||
*/
|
||||
CallsSettings *
|
||||
calls_settings_new (void)
|
||||
calls_settings_get_default (void)
|
||||
{
|
||||
return g_object_new (CALLS_TYPE_SETTINGS, NULL);
|
||||
static CallsSettings *instance = NULL;
|
||||
|
||||
if (!instance) {
|
||||
instance = g_object_new (CALLS_TYPE_SETTINGS, NULL);
|
||||
g_object_add_weak_pointer (G_OBJECT (instance), (gpointer *)&instance);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ G_BEGIN_DECLS
|
|||
|
||||
G_DECLARE_FINAL_TYPE (CallsSettings, calls_settings, CALLS, SETTINGS, GObject);
|
||||
|
||||
CallsSettings *calls_settings_new (void);
|
||||
CallsSettings *calls_settings_get_default (void);
|
||||
gboolean calls_settings_get_use_default_origins (CallsSettings *self);
|
||||
void calls_settings_set_use_default_origins (CallsSettings *self,
|
||||
gboolean enable);
|
||||
|
|
|
@ -11,4 +11,4 @@
|
|||
|
||||
#include "calls-contacts-provider.h"
|
||||
|
||||
CallsContactsProvider *__wrap_calls_contacts_provider_new (CallsSettings *settings);
|
||||
CallsContactsProvider *__wrap_calls_contacts_provider_new (void);
|
||||
|
|
|
@ -14,9 +14,8 @@
|
|||
static void
|
||||
test_contacts_null_contact (void)
|
||||
{
|
||||
g_autoptr (CallsSettings) settings = calls_settings_new ();
|
||||
g_autoptr (CallsContactsProvider) contacts_provider =
|
||||
calls_contacts_provider_new (settings);
|
||||
calls_contacts_provider_new ();
|
||||
CallsBestMatch *best_match;
|
||||
|
||||
best_match = calls_contacts_provider_lookup_id (contacts_provider, NULL);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <libpeas/peas.h>
|
||||
|
||||
CallsContactsProvider *
|
||||
__wrap_calls_contacts_provider_new (CallsSettings *settings)
|
||||
__wrap_calls_contacts_provider_new (void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ __wrap_lfb_event_end_feedback_finish (LfbEvent *self,
|
|||
|
||||
|
||||
CallsContactsProvider *
|
||||
__wrap_calls_contacts_provider_new (CallsSettings *settings)
|
||||
__wrap_calls_contacts_provider_new (void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <gtk/gtk.h>
|
||||
|
||||
CallsContactsProvider *
|
||||
__wrap_calls_contacts_provider_new (CallsSettings *settings)
|
||||
__wrap_calls_contacts_provider_new (void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue