tracker-0.16.2/src/tracker-extract/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 Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2.1 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  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser 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 <libtracker-common/tracker-keyfile-object.h>
 23 #include <libtracker-common/tracker-enum-types.h>
 24 #include <libtracker-common/tracker-enums.h>
 25 
 26 #include "tracker-config.h"
 27 
 28 static void     config_set_property         (GObject       *object,
 29                                              guint          param_id,
 30                                              const GValue  *value,
 31                                              GParamSpec    *pspec);
 32 static void     config_get_property         (GObject       *object,
 33                                              guint          param_id,
 34                                              GValue        *value,
 35                                              GParamSpec    *pspec);
 36 static void     config_finalize             (GObject       *object);
 37 static void     config_constructed          (GObject       *object);
 38 
 39 enum {
 40 	PROP_0,
 41 	PROP_VERBOSITY,
 42 	PROP_SCHED_IDLE,
 43 	PROP_MAX_BYTES,
 44 	PROP_MAX_MEDIA_ART_WIDTH
 45 };
 46 
 47 static TrackerConfigMigrationEntry migration[] = {
 48 	{ G_TYPE_ENUM, "General", "Verbosity", "verbosity" },
 49 	{ G_TYPE_ENUM, "General", "SchedIdle", "sched-idle" },
 50 	{ G_TYPE_INT, "General", "MaxBytes", "max-bytes" },
 51 	{ G_TYPE_INT, "General", "MaxMediaArtWidth", "max-media-art-width" },
 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 	/* General */
 68 	g_object_class_install_property (object_class,
 69 	                                 PROP_VERBOSITY,
 70 	                                 g_param_spec_enum ("verbosity",
 71 	                                                    "Log verbosity",
 72 	                                                    "Log verbosity (0=errors, 1=minimal, 2=detailed, 3=debug)",
 73 	                                                    TRACKER_TYPE_VERBOSITY,
 74 	                                                    TRACKER_VERBOSITY_ERRORS,
 75 	                                                    G_PARAM_READWRITE));
 76 	g_object_class_install_property (object_class,
 77 	                                 PROP_SCHED_IDLE,
 78 	                                 g_param_spec_enum ("sched-idle",
 79 	                                                    "Scheduler priority when idle",
 80 	                                                    "Scheduler priority when idle (0=always, 1=first-index, 2=never)",
 81 	                                                    TRACKER_TYPE_SCHED_IDLE,
 82 	                                                    TRACKER_SCHED_IDLE_FIRST_INDEX,
 83 	                                                    G_PARAM_READWRITE));
 84 
 85 	g_object_class_install_property (object_class,
 86 	                                 PROP_MAX_BYTES,
 87 	                                 g_param_spec_int ("max-bytes",
 88 	                                                   "Max Bytes",
 89 	                                                   "Maximum number of UTF-8 bytes to extract per file [0->10485760]",
 90 	                                                   0, 1024 * 1024 * 10,
 91 	                                                   1024 * 1024,
 92 	                                                   G_PARAM_READWRITE));
 93 
 94 	g_object_class_install_property (object_class,
 95 	                                 PROP_MAX_MEDIA_ART_WIDTH,
 96 	                                 g_param_spec_int ("max-media-art-width",
 97 	                                                   "Max Media Art Width",
 98 	                                                   " Maximum width of the Media Art to be generated (-1=disable, 0=original width, 1->2048=max pixel width)",
 99 	                                                   -1,
100 	                                                   2048,
101 	                                                   0,
102 	                                                   G_PARAM_READWRITE));
103 }
104 
105 static void
106 tracker_config_init (TrackerConfig *object)
107 {
108 }
109 
110 static void
111 config_set_property (GObject      *object,
112                      guint         param_id,
113                      const GValue *value,
114                      GParamSpec   *pspec)
115 {
116 	switch (param_id) {
117 	case PROP_VERBOSITY:
118 		g_settings_set_enum (G_SETTINGS (object), "verbosity",
119 		                     g_value_get_enum (value));
120 		break;
121 
122 	case PROP_SCHED_IDLE:
123 		g_settings_set_enum (G_SETTINGS (object), "sched-idle",
124 		                     g_value_get_enum (value));
125 		break;
126 
127 	case PROP_MAX_BYTES:
128 		g_settings_set_int (G_SETTINGS (object), "max-bytes",
129 		                    g_value_get_int (value));
130 		break;
131 
132 	case PROP_MAX_MEDIA_ART_WIDTH:
133 		g_settings_set_int (G_SETTINGS (object), "max-media-art-width",
134 		                    g_value_get_int (value));
135 		break;
136 
137 	default:
138 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
139 		break;
140 	};
141 }
142 
143 static void
144 config_get_property (GObject    *object,
145                      guint       param_id,
146                      GValue     *value,
147                      GParamSpec *pspec)
148 {
149 	switch (param_id) {
150 	case PROP_VERBOSITY:
151 		g_value_set_enum (value,
152 		                  g_settings_get_enum (G_SETTINGS (object), "verbosity"));
153 		break;
154 
155 	case PROP_SCHED_IDLE:
156 		g_value_set_enum (value,
157 		                  g_settings_get_enum (G_SETTINGS (object), "sched-idle"));
158 		break;
159 
160 	case PROP_MAX_BYTES:
161 		g_value_set_int (value,
162 		                 g_settings_get_int (G_SETTINGS (object), "max-bytes"));
163 		break;
164 
165 	case PROP_MAX_MEDIA_ART_WIDTH:
166 		g_value_set_int (value,
167 		                 g_settings_get_int (G_SETTINGS (object), "max-media-art-width"));
168 		break;
169 
170 	default:
171 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
172 		break;
173 	};
174 }
175 
176 static void
177 config_finalize (GObject *object)
178 {
179 	/* For now we do nothing here, we left this override in for
180 	 * future expansion.
181 	 */
182 
183 	(G_OBJECT_CLASS (tracker_config_parent_class)->finalize) (object);
184 }
185 
186 static void
187 config_constructed (GObject *object)
188 {
189 	TrackerConfigFile *config_file;
190 
191 	(G_OBJECT_CLASS (tracker_config_parent_class)->constructed) (object);
192 
193 	g_settings_delay (G_SETTINGS (object));
194 
195 	/* Migrate keyfile-based configuration */
196 	config_file = tracker_config_file_new ();
197 
198 	if (config_file) {
199 		tracker_config_file_migrate (config_file, G_SETTINGS (object), migration);
200 		g_object_unref (config_file);
201 	}
202 }
203 
204 TrackerConfig *
205 tracker_config_new (void)
206 {
207 	return g_object_new (TRACKER_TYPE_CONFIG,
208 	                     "schema", "org.freedesktop.Tracker.Extract",
209 	                     "path", "/org/freedesktop/tracker/extract/",
210 	                     NULL);
211 }
212 
213 gint
214 tracker_config_get_verbosity (TrackerConfig *config)
215 {
216 	gint verbosity;
217 
218 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), TRACKER_VERBOSITY_ERRORS);
219 
220 	g_object_get (config, "verbosity", &verbosity, NULL);
221 
222 	return verbosity;
223 }
224 
225 void
226 tracker_config_set_verbosity (TrackerConfig *config,
227                               gint           value)
228 {
229 	g_return_if_fail (TRACKER_IS_CONFIG (config));
230 
231 	g_object_set (G_OBJECT (config), "verbosity", value, NULL);
232 }
233 
234 gint
235 tracker_config_get_sched_idle (TrackerConfig *config)
236 {
237 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), TRACKER_SCHED_IDLE_FIRST_INDEX);
238 
239 	return g_settings_get_enum (G_SETTINGS (config), "sched-idle");
240 }
241 
242 void
243 tracker_config_set_sched_idle (TrackerConfig *config,
244                                gint           value)
245 {
246 
247 	g_return_if_fail (TRACKER_IS_CONFIG (config));
248 
249 	g_settings_set_enum (G_SETTINGS (config), "sched-idle", value);
250 	g_object_notify (G_OBJECT (config), "sched-idle");
251 }
252 
253 gint
254 tracker_config_get_max_bytes (TrackerConfig *config)
255 {
256 	gint max_bytes;
257 
258 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), 0);
259 
260 	g_object_get (config, "max-bytes", &max_bytes, NULL);
261 
262 	return max_bytes;
263 }
264 
265 void
266 tracker_config_set_max_bytes (TrackerConfig *config,
267                               gint           value)
268 {
269 	g_return_if_fail (TRACKER_IS_CONFIG (config));
270 
271 	g_object_set (G_OBJECT (config), "max-bytes", value, NULL);
272 }
273 
274 gint
275 tracker_config_get_max_media_art_width (TrackerConfig *config)
276 {
277 	gint max_media_art_width;
278 
279 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), 0);
280 
281 	g_object_get (config, "max-media-art-width", &max_media_art_width, NULL);
282 
283 	return max_media_art_width;
284 }
285 
286 void
287 tracker_config_set_max_media_art_width (TrackerConfig *config,
288                                        gint           value)
289 {
290 	g_return_if_fail (TRACKER_IS_CONFIG (config));
291 
292 	g_object_set (G_OBJECT (config), "max-media-art-width", value, NULL);
293 }