tracker-0.16.2/src/tracker-writeback/tracker-config.c

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 #include <libtracker-common/tracker-file-utils.h>
 32 #include <libtracker-common/tracker-type-utils.h>
 33 
 34 #include "tracker-config.h"
 35 
 36 static void     config_set_property         (GObject           *object,
 37                                              guint              param_id,
 38                                              const GValue      *value,
 39                                              GParamSpec        *pspec);
 40 static void     config_get_property         (GObject           *object,
 41                                              guint              param_id,
 42                                              GValue            *value,
 43                                              GParamSpec        *pspec);
 44 static void     config_finalize             (GObject           *object);
 45 static void     config_constructed          (GObject           *object);
 46 
 47 enum {
 48 	PROP_0,
 49 	PROP_VERBOSITY,
 50 };
 51 
 52 static TrackerConfigMigrationEntry migration[] = {
 53 	{ G_TYPE_ENUM, "General", "Verbosity", "verbosity" },
 54 	{ 0 }
 55 };
 56 
 57 G_DEFINE_TYPE (TrackerConfig, tracker_config, G_TYPE_SETTINGS);
 58 
 59 static void
 60 tracker_config_class_init (TrackerConfigClass *klass)
 61 {
 62 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 63 
 64 	object_class->set_property = config_set_property;
 65 	object_class->get_property = config_get_property;
 66 	object_class->finalize     = config_finalize;
 67 	object_class->constructed  = config_constructed;
 68 
 69 	g_object_class_install_property (object_class,
 70 	                                 PROP_VERBOSITY,
 71 	                                 g_param_spec_enum ("verbosity",
 72 	                                                    "Log verbosity",
 73 	                                                    "Log verbosity (0=errors, 1=minimal, 2=detailed, 3=debug)",
 74 	                                                    TRACKER_TYPE_VERBOSITY,
 75 	                                                    TRACKER_VERBOSITY_ERRORS,
 76 	                                                    G_PARAM_READWRITE));
 77 }
 78 
 79 static void
 80 tracker_config_init (TrackerConfig *object)
 81 {
 82 }
 83 
 84 static void
 85 config_set_property (GObject      *object,
 86                      guint         param_id,
 87                      const GValue *value,
 88                      GParamSpec           *pspec)
 89 {
 90 	switch (param_id) {
 91 	case PROP_VERBOSITY:
 92 		tracker_config_set_verbosity (TRACKER_CONFIG (object),
 93 		                              g_value_get_enum (value));
 94 		break;
 95 	default:
 96 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 97 		break;
 98 	};
 99 }
100 
101 static void
102 config_get_property (GObject    *object,
103                      guint       param_id,
104                      GValue     *value,
105                      GParamSpec *pspec)
106 {
107 	switch (param_id) {
108 	case PROP_VERBOSITY:
109 		g_value_set_enum (value, tracker_config_get_verbosity (TRACKER_CONFIG (object)));
110 		break;
111 	default:
112 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
113 		break;
114 	};
115 }
116 
117 static void
118 config_finalize (GObject *object)
119 {
120 	(G_OBJECT_CLASS (tracker_config_parent_class)->finalize) (object);
121 }
122 
123 static void
124 config_constructed (GObject *object)
125 {
126 	TrackerConfigFile *config_file;
127 
128 	(G_OBJECT_CLASS (tracker_config_parent_class)->constructed) (object);
129 
130 	g_settings_delay (G_SETTINGS (object));
131 
132 	/* Migrate keyfile-based configuration */
133 	config_file = tracker_config_file_new ();
134 
135 	if (config_file) {
136 		tracker_config_file_migrate (config_file, G_SETTINGS (object), migration);
137 		g_object_unref (config_file);
138 	}
139 }
140 
141 TrackerConfig *
142 tracker_config_new (void)
143 {
144 	return g_object_new (TRACKER_TYPE_CONFIG,
145 			     "schema", "org.freedesktop.Tracker.Writeback",
146 			     "path", "/org/freedesktop/tracker/writeback/",
147 			     NULL);
148 }
149 
150 gint
151 tracker_config_get_verbosity (TrackerConfig *config)
152 {
153 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), 0);
154 
155 	return g_settings_get_enum (G_SETTINGS (config), "verbosity");
156 }
157 
158 void
159 tracker_config_set_verbosity (TrackerConfig *config,
160                               gint           value)
161 {
162 	g_return_if_fail (TRACKER_IS_CONFIG (config));
163 
164 	g_settings_set_enum (G_SETTINGS (config), "verbosity", value);
165 	g_object_notify (G_OBJECT (config), "verbosity");
166 }