mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-06 11:35:32 +00:00
application: Add CallsSettings class
This makes it easy to access application wide settings.
This commit is contained in:
parent
0b2f146053
commit
fef1531749
8 changed files with 279 additions and 1 deletions
|
@ -67,3 +67,14 @@ install_data(
|
|||
'apps'
|
||||
)
|
||||
)
|
||||
|
||||
install_data('sm.puri.Calls.gschema.xml',
|
||||
install_dir: join_paths(get_option('datadir'), 'glib-2.0/schemas')
|
||||
)
|
||||
|
||||
compile_schemas = find_program('glib-compile-schemas', required: false)
|
||||
if compile_schemas.found()
|
||||
test('Validate schema file', compile_schemas,
|
||||
args: ['--strict', '--dry-run', meson.current_source_dir()]
|
||||
)
|
||||
endif
|
||||
|
|
12
data/sm.puri.Calls.gschema.xml
Normal file
12
data/sm.puri.Calls.gschema.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schemalist gettext-domain="purism-calls">
|
||||
<schema id="sm.puri.Calls" path="/sm/puri/Calls/">
|
||||
|
||||
<key name="auto-use-default-origins" type="b">
|
||||
<default>true</default>
|
||||
<summary>Whether calls should automatically use the default origin</summary>
|
||||
<description>Whether calls should automatically use the default origin</description>
|
||||
</key>
|
||||
|
||||
</schema>
|
||||
</schemalist>
|
1
debian/gnome-calls.install
vendored
1
debian/gnome-calls.install
vendored
|
@ -2,6 +2,7 @@
|
|||
/usr/bin
|
||||
/usr/lib
|
||||
/usr/share/applications
|
||||
/usr/share/glib-2.0
|
||||
/usr/share/icons
|
||||
/usr/share/locale
|
||||
/usr/share/metainfo
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "calls-call-window.h"
|
||||
#include "calls-main-window.h"
|
||||
#include "calls-manager.h"
|
||||
#include "calls-settings.h"
|
||||
#include "calls-application.h"
|
||||
#include "version.h"
|
||||
|
||||
|
@ -63,6 +64,7 @@ struct _CallsApplication
|
|||
CallsRecordStore *record_store;
|
||||
CallsMainWindow *main_window;
|
||||
CallsCallWindow *call_window;
|
||||
CallsSettings *settings;
|
||||
|
||||
char *uri;
|
||||
};
|
||||
|
@ -374,6 +376,9 @@ start_proper (CallsApplication *self)
|
|||
self->call_window = calls_call_window_new (gtk_app);
|
||||
g_assert (self->call_window != NULL);
|
||||
|
||||
self->settings = calls_settings_new ();
|
||||
g_assert (self->settings != NULL);
|
||||
|
||||
g_signal_connect (self->call_window,
|
||||
"notify::visible",
|
||||
G_CALLBACK (notify_window_visible_cb),
|
||||
|
@ -522,6 +527,7 @@ finalize (GObject *object)
|
|||
g_clear_object (&self->record_store);
|
||||
g_clear_object (&self->ringer);
|
||||
g_clear_object (&self->notifier);
|
||||
g_clear_object (&self->settings);
|
||||
g_free (self->uri);
|
||||
|
||||
G_OBJECT_CLASS (calls_application_parent_class)->finalize (object);
|
||||
|
@ -593,3 +599,20 @@ calls_application_new (void)
|
|||
"register-session", TRUE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
calls_application_get_use_default_origins_setting (CallsApplication *self)
|
||||
{
|
||||
g_return_val_if_fail (CALLS_IS_APPLICATION (self), FALSE);
|
||||
|
||||
return calls_settings_get_use_default_origins (self->settings);
|
||||
}
|
||||
|
||||
void
|
||||
calls_application_set_use_default_origins_setting (CallsApplication *self,
|
||||
gboolean enabled)
|
||||
{
|
||||
g_return_if_fail (CALLS_IS_APPLICATION (self));
|
||||
|
||||
calls_settings_set_use_default_origins (self->settings, enabled);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ G_BEGIN_DECLS
|
|||
|
||||
G_DECLARE_FINAL_TYPE (CallsApplication, calls_application, CALLS, APPLICATION, GtkApplication)
|
||||
|
||||
CallsApplication *calls_application_new (void);
|
||||
CallsApplication *calls_application_new (void);
|
||||
gboolean calls_application_get_use_default_origins_setting (CallsApplication *self);
|
||||
void calls_application_set_use_default_origins_setting (CallsApplication *self,
|
||||
gboolean enabled);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
186
src/calls-settings.c
Normal file
186
src/calls-settings.c
Normal file
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
* Copyright (C) 2021 Purism SPC
|
||||
*
|
||||
* This file is part of Calls.
|
||||
*
|
||||
* Calls is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calls is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Evangelos Ribeiro Tzaras <evangelos.tzaras@puri.sm>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "CallsSettings"
|
||||
|
||||
#include "calls-settings.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
/**
|
||||
* SECTION: calls-settings
|
||||
* @title: CallsSettings
|
||||
* @short_description: The application settings
|
||||
*
|
||||
* Manage application settings
|
||||
*/
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_AUTO_USE_DEFAULT_ORIGINS,
|
||||
PROP_LAST_PROP
|
||||
};
|
||||
static GParamSpec *props[PROP_LAST_PROP];
|
||||
|
||||
struct _CallsSettings {
|
||||
GObject parent_instance;
|
||||
|
||||
GSettings *settings;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (CallsSettings, calls_settings, G_TYPE_OBJECT)
|
||||
|
||||
|
||||
static void
|
||||
calls_settings_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
CallsSettings *self = CALLS_SETTINGS (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_AUTO_USE_DEFAULT_ORIGINS:
|
||||
calls_settings_set_use_default_origins (self, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_settings_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
CallsSettings *self = CALLS_SETTINGS (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_AUTO_USE_DEFAULT_ORIGINS:
|
||||
g_value_set_boolean (value, calls_settings_get_use_default_origins (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_settings_constructed (GObject *object)
|
||||
{
|
||||
CallsSettings *self = CALLS_SETTINGS (object);
|
||||
|
||||
g_settings_bind (self->settings, "auto-use-default-origins",
|
||||
self, "auto-use-default-origins", G_SETTINGS_BIND_DEFAULT);
|
||||
|
||||
G_OBJECT_CLASS (calls_settings_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_settings_finalize (GObject *object)
|
||||
{
|
||||
CallsSettings *self = CALLS_SETTINGS (object);
|
||||
|
||||
g_object_unref (self->settings);
|
||||
|
||||
G_OBJECT_CLASS (calls_settings_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
calls_settings_class_init (CallsSettingsClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->set_property = calls_settings_set_property;
|
||||
object_class->get_property = calls_settings_get_property;
|
||||
object_class->constructed = calls_settings_constructed;
|
||||
object_class->finalize = calls_settings_finalize;
|
||||
|
||||
props[PROP_AUTO_USE_DEFAULT_ORIGINS] =
|
||||
g_param_spec_boolean ("auto-use-default-origins",
|
||||
"auto use default origins",
|
||||
"Automatically use default origins",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
||||
}
|
||||
|
||||
static void
|
||||
calls_settings_init (CallsSettings *self)
|
||||
{
|
||||
self->settings = g_settings_new ("sm.puri.Calls");
|
||||
}
|
||||
|
||||
/**
|
||||
* calls_settings_new:
|
||||
*
|
||||
* Returns: (transfer full): A #CallsSettings.
|
||||
*/
|
||||
CallsSettings *
|
||||
calls_settings_new (void)
|
||||
{
|
||||
return g_object_new (CALLS_TYPE_SETTINGS, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* calls_settings_get_use_default_origins:
|
||||
* @self: A #CallsSettings
|
||||
*
|
||||
* Whether to prompt the user when there multiple origigins or fall back to defaults
|
||||
*
|
||||
* Returns: %TRUE if using defaults, %FALSE when the user should be prompted
|
||||
*/
|
||||
gboolean
|
||||
calls_settings_get_use_default_origins (CallsSettings *self)
|
||||
{
|
||||
g_return_val_if_fail (CALLS_IS_SETTINGS (self), FALSE);
|
||||
|
||||
return g_settings_get_boolean (G_SETTINGS (self->settings), "auto-use-default-origins");
|
||||
}
|
||||
|
||||
/**
|
||||
* calls_settings_set_use_default_origins:
|
||||
* @self: A #CallsSettings
|
||||
* @enable: %TRUE to use default origins, %FALSE otherwise
|
||||
*
|
||||
* Sets whether to prompt the user when there multiple origigins or fall back to defaults
|
||||
*/
|
||||
void
|
||||
calls_settings_set_use_default_origins (CallsSettings *self,
|
||||
gboolean enable)
|
||||
{
|
||||
g_return_if_fail (CALLS_IS_SETTINGS (self));
|
||||
|
||||
g_debug ("%sabling the use of default origins", enable ? "En" : "Dis");
|
||||
g_settings_set_boolean (G_SETTINGS (self->settings), "auto-use-default-origins", enable);
|
||||
}
|
41
src/calls-settings.h
Normal file
41
src/calls-settings.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2021 Purism SPC
|
||||
*
|
||||
* This file is part of Calls.
|
||||
*
|
||||
* Calls is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calls is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Evangelos Ribeiro Tzaras <evangelos.tzaras@puri.sm>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CALLS_TYPE_SETTINGS (calls_settings_get_type ())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (CallsSettings, calls_settings, CALLS, SETTINGS, GObject)
|
||||
|
||||
CallsSettings *calls_settings_new (void);
|
||||
gboolean calls_settings_get_use_default_origins (CallsSettings *self);
|
||||
void calls_settings_set_use_default_origins (CallsSettings *self,
|
||||
gboolean enable);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
@ -113,6 +113,7 @@ calls_sources = files(['calls-message-source.c', 'calls-message-source.h',
|
|||
'calls-credentials.c', 'calls-credentials.h',
|
||||
'calls-account.c', 'calls-account.h',
|
||||
'calls-account-provider.c', 'calls-account-provider.h',
|
||||
'calls-settings.c', 'calls-settings.h',
|
||||
]) + wayland_sources + calls_generated_sources
|
||||
|
||||
calls_config_data = config_data
|
||||
|
|
Loading…
Reference in a new issue