No issues found
1 /*
2 * Copyright (C) 2009, Nokia <ivan.frade@nokia.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21
22 #include <string.h>
23 #include <stdlib.h>
24
25 #include <glib.h>
26 #include <gio/gio.h>
27
28 #include <libtracker-common/tracker-enum-types.h>
29 #include <libtracker-common/tracker-config-file.h>
30 #include <libtracker-common/tracker-keyfile-object.h>
31
32 #include "tracker-config.h"
33
34 static void config_set_property (GObject *object,
35 guint param_id,
36 const GValue *value,
37 GParamSpec *pspec);
38 static void config_get_property (GObject *object,
39 guint param_id,
40 GValue *value,
41 GParamSpec *pspec);
42 static void config_finalize (GObject *object);
43 static void config_constructed (GObject *object);
44
45 enum {
46 PROP_0,
47 PROP_VERBOSITY,
48 };
49
50 static TrackerConfigMigrationEntry migration[] = {
51 { G_TYPE_ENUM, "General", "Verbosity", "verbosity" },
52 { 0 }
53 };
54
55 G_DEFINE_TYPE (TrackerConfig, tracker_config, G_TYPE_SETTINGS);
56
57 static void
58 tracker_config_class_init (TrackerConfigClass *klass)
59 {
60 GObjectClass *object_class = G_OBJECT_CLASS (klass);
61
62 object_class->set_property = config_set_property;
63 object_class->get_property = config_get_property;
64 object_class->finalize = config_finalize;
65 object_class->constructed = config_constructed;
66
67 g_object_class_install_property (object_class,
68 PROP_VERBOSITY,
69 g_param_spec_enum ("verbosity",
70 "Log verbosity",
71 "Log verbosity (0=errors, 1=minimal, 2=detailed, 3=debug)",
72 TRACKER_TYPE_VERBOSITY,
73 TRACKER_VERBOSITY_ERRORS,
74 G_PARAM_READWRITE));
75 }
76
77 static void
78 tracker_config_init (TrackerConfig *object)
79 {
80 }
81
82 static void
83 config_set_property (GObject *object,
84 guint param_id,
85 const GValue *value,
86 GParamSpec *pspec)
87 {
88 switch (param_id) {
89 case PROP_VERBOSITY:
90 tracker_config_set_verbosity (TRACKER_CONFIG (object),
91 g_value_get_enum (value));
92 break;
93 default:
94 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
95 break;
96 };
97 }
98
99 static void
100 config_get_property (GObject *object,
101 guint param_id,
102 GValue *value,
103 GParamSpec *pspec)
104 {
105 switch (param_id) {
106 /* General */
107 case PROP_VERBOSITY:
108 g_value_set_enum (value, tracker_config_get_verbosity (TRACKER_CONFIG (object)));
109 break;
110 default:
111 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
112 break;
113 };
114 }
115
116 static void
117 config_finalize (GObject *object)
118 {
119 /* For now we do nothing here, we left this override in for
120 * future expansion.
121 */
122
123 (G_OBJECT_CLASS (tracker_config_parent_class)->finalize) (object);
124 }
125
126 static void
127 config_constructed (GObject *object)
128 {
129 TrackerConfigFile *config_file;
130
131 (G_OBJECT_CLASS (tracker_config_parent_class)->constructed) (object);
132
133 g_settings_delay (G_SETTINGS (object));
134
135 /* Migrate keyfile-based configuration */
136 config_file = tracker_config_file_new ();
137
138 if (config_file) {
139 tracker_config_file_migrate (config_file, G_SETTINGS (object), migration);
140 g_object_unref (config_file);
141 }
142 }
143
144 TrackerConfig *
145 tracker_config_new (void)
146 {
147 return g_object_new (TRACKER_TYPE_CONFIG,
148 "schema", "org.freedesktop.Tracker.Store",
149 "path", "/org/freedesktop/tracker/store/",
150 NULL);
151 }
152
153 gint
154 tracker_config_get_verbosity (TrackerConfig *config)
155 {
156 g_return_val_if_fail (TRACKER_IS_CONFIG (config), 0);
157
158 return g_settings_get_enum (G_SETTINGS (config), "verbosity");
159 }
160
161 void
162 tracker_config_set_verbosity (TrackerConfig *config,
163 gint value)
164 {
165 g_return_if_fail (TRACKER_IS_CONFIG (config));
166
167 g_settings_set_enum (G_SETTINGS (config), "verbosity", value);
168 g_object_notify (G_OBJECT (config), "verbosity");
169 }