Branch data Line data Source code
1 : : // SPDX-License-Identifier: GPL-3.0-or-later
2 : : // SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>
3 : :
4 : : #define G_LOG_DOMAIN "valent-preferences-page"
5 : :
6 : : #include "config.h"
7 : :
8 : : #include <adwaita.h>
9 : : #include <libvalent-core.h>
10 : :
11 : : #include "valent-preferences-page.h"
12 : :
13 : :
14 : : /**
15 : : * ValentPreferencesPage:
16 : : *
17 : : * An abstract base class for plugin preferences.
18 : : *
19 : : * `ValentPreferencesPage` is a base class for plugins that want to provide a
20 : : * preferences page. Unlike [class@Valent.DevicePreferencesGroup] the page should
21 : : * configure all of the plugin's extension implementations, with the exception
22 : : * of [class@Valent.DevicePlugin].
23 : : *
24 : : * Implementations of [class@Valent.DevicePlugin] should instead implement
25 : : * [class@Valent.DevicePreferencesGroup], which will allow plugins to store
26 : : * per-devices settings.
27 : : *
28 : : * Since: 1.0
29 : : */
30 : :
31 : : typedef struct
32 : : {
33 : : PeasPluginInfo *plugin_info;
34 : : } ValentPreferencesPagePrivate;
35 : :
36 [ + + + - ]: 339 : G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ValentPreferencesPage, valent_preferences_page, ADW_TYPE_PREFERENCES_PAGE)
37 : :
38 : : enum {
39 : : PROP_0,
40 : : PROP_PLUGIN_INFO,
41 : : N_PROPERTIES
42 : : };
43 : :
44 : : static GParamSpec *properties[N_PROPERTIES] = { NULL, };
45 : :
46 : : /**
47 : : * ValentPreferencesPageClass:
48 : : *
49 : : * The virtual function table for `ValentPreferencesPage`.
50 : : *
51 : : * Since: 1.0
52 : : */
53 : :
54 : :
55 : : /*
56 : : * GObject
57 : : */
58 : : static void
59 : 6 : valent_preferences_page_finalize (GObject *object)
60 : : {
61 : 6 : ValentPreferencesPage *self = VALENT_PREFERENCES_PAGE (object);
62 : 6 : ValentPreferencesPagePrivate *priv = valent_preferences_page_get_instance_private (self);
63 : :
64 [ + - ]: 6 : g_clear_object (&priv->plugin_info);
65 : :
66 : 6 : G_OBJECT_CLASS (valent_preferences_page_parent_class)->finalize (object);
67 : 6 : }
68 : :
69 : : static void
70 : 1 : valent_preferences_page_get_property (GObject *object,
71 : : guint prop_id,
72 : : GValue *value,
73 : : GParamSpec *pspec)
74 : : {
75 : 1 : ValentPreferencesPage *self = VALENT_PREFERENCES_PAGE (object);
76 : 1 : ValentPreferencesPagePrivate *priv = valent_preferences_page_get_instance_private (self);
77 : :
78 [ + - ]: 1 : switch (prop_id)
79 : : {
80 : 1 : case PROP_PLUGIN_INFO:
81 : 1 : g_value_set_object (value, priv->plugin_info);
82 : 1 : break;
83 : :
84 : 0 : default:
85 : 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
86 : : }
87 : 1 : }
88 : :
89 : : static void
90 : 6 : valent_preferences_page_set_property (GObject *object,
91 : : guint prop_id,
92 : : const GValue *value,
93 : : GParamSpec *pspec)
94 : : {
95 : 6 : ValentPreferencesPage *self = VALENT_PREFERENCES_PAGE (object);
96 : 6 : ValentPreferencesPagePrivate *priv = valent_preferences_page_get_instance_private (self);
97 : :
98 [ + - ]: 6 : switch (prop_id)
99 : : {
100 : 6 : case PROP_PLUGIN_INFO:
101 : 6 : priv->plugin_info = g_value_dup_object (value);
102 : 6 : break;
103 : :
104 : 0 : default:
105 : 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
106 : : }
107 : 6 : }
108 : :
109 : : static void
110 : 66 : valent_preferences_page_class_init (ValentPreferencesPageClass *klass)
111 : : {
112 : 66 : GObjectClass *object_class = G_OBJECT_CLASS (klass);
113 : :
114 : 66 : object_class->finalize = valent_preferences_page_finalize;
115 : 66 : object_class->get_property = valent_preferences_page_get_property;
116 : 66 : object_class->set_property = valent_preferences_page_set_property;
117 : :
118 : : /**
119 : : * ValentPreferencesPage:plugin-info:
120 : : *
121 : : * The [class@Peas.PluginInfo] describing the plugin this page configures.
122 : : *
123 : : * Since: 1.0
124 : : */
125 : 132 : properties [PROP_PLUGIN_INFO] =
126 : 66 : g_param_spec_object ("plugin-info", NULL, NULL,
127 : : PEAS_TYPE_PLUGIN_INFO,
128 : : (G_PARAM_READWRITE |
129 : : G_PARAM_CONSTRUCT_ONLY |
130 : : G_PARAM_EXPLICIT_NOTIFY |
131 : : G_PARAM_STATIC_STRINGS));
132 : :
133 : 66 : g_object_class_install_properties (object_class, N_PROPERTIES, properties);
134 : 66 : }
135 : :
136 : : static void
137 : 6 : valent_preferences_page_init (ValentPreferencesPage *self)
138 : : {
139 : 6 : }
140 : :
|