tracker-config.c 9.25 KB
Newer Older
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 10
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17 18 19 20 21
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

#include "config.h"

22
#include <libtracker-common/tracker-keyfile-object.h>
23 24
#include <libtracker-common/tracker-enum-types.h>
#include <libtracker-common/tracker-enums.h>
25 26 27 28

#include "tracker-config.h"

static void     config_set_property         (GObject       *object,
Martyn Russell's avatar
Martyn Russell committed
29 30 31
                                             guint          param_id,
                                             const GValue  *value,
                                             GParamSpec    *pspec);
32
static void     config_get_property         (GObject       *object,
Martyn Russell's avatar
Martyn Russell committed
33 34 35
                                             guint          param_id,
                                             GValue        *value,
                                             GParamSpec    *pspec);
36 37
static void     config_finalize             (GObject       *object);
static void     config_constructed          (GObject       *object);
38 39 40

enum {
	PROP_0,
41
	PROP_VERBOSITY,
42
	PROP_SCHED_IDLE,
43 44
	PROP_MAX_BYTES,
	PROP_MAX_MEDIA_ART_WIDTH
45 46
};

47 48
static TrackerConfigMigrationEntry migration[] = {
	{ 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 58 59 60 61 62

static void
tracker_config_class_init (TrackerConfigClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	object_class->set_property = config_set_property;
63
	object_class->get_property = config_get_property;
Martyn Russell's avatar
Martyn Russell committed
64
	object_class->finalize     = config_finalize;
65
	object_class->constructed  = config_constructed;
66 67 68

	/* General */
	g_object_class_install_property (object_class,
Martyn Russell's avatar
Martyn Russell committed
69
	                                 PROP_VERBOSITY,
70
	                                 g_param_spec_enum ("verbosity",
71 72 73 74 75
	                                                    "Log verbosity",
	                                                    "Log verbosity (0=errors, 1=minimal, 2=detailed, 3=debug)",
	                                                    TRACKER_TYPE_VERBOSITY,
	                                                    TRACKER_VERBOSITY_ERRORS,
	                                                    G_PARAM_READWRITE));
76 77 78 79 80 81 82 83
	g_object_class_install_property (object_class,
	                                 PROP_SCHED_IDLE,
	                                 g_param_spec_enum ("sched-idle",
	                                                    "Scheduler priority when idle",
	                                                    "Scheduler priority when idle (0=always, 1=first-index, 2=never)",
	                                                    TRACKER_TYPE_SCHED_IDLE,
	                                                    TRACKER_SCHED_IDLE_FIRST_INDEX,
	                                                    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 90
	                                                   "Maximum number of UTF-8 bytes to extract per file [0->10485760]",
	                                                   0, 1024 * 1024 * 10,
91
	                                                   1024 * 1024,
92
	                                                   G_PARAM_READWRITE));
93 94 95 96 97 98 99 100 101 102

	g_object_class_install_property (object_class,
	                                 PROP_MAX_MEDIA_ART_WIDTH,
	                                 g_param_spec_int ("max-media-art-width",
	                                                   "Max Media Art Width",
	                                                   " Maximum width of the Media Art to be generated (-1=disable, 0=original width, 1->2048=max pixel width)",
	                                                   -1,
	                                                   2048,
	                                                   0,
	                                                   G_PARAM_READWRITE));
103 104 105 106 107 108 109 110
}

static void
tracker_config_init (TrackerConfig *object)
{
}

static void
Martyn Russell's avatar
Martyn Russell committed
111 112 113
config_set_property (GObject      *object,
                     guint         param_id,
                     const GValue *value,
114
                     GParamSpec   *pspec)
115
{
116 117
	switch (param_id) {
	case PROP_VERBOSITY:
118 119
		g_settings_set_enum (G_SETTINGS (object), "verbosity",
		                     g_value_get_enum (value));
120
		break;
121

122 123 124 125 126
	case PROP_SCHED_IDLE:
		g_settings_set_enum (G_SETTINGS (object), "sched-idle",
		                     g_value_get_enum (value));
		break;

127
	case PROP_MAX_BYTES:
128 129
		g_settings_set_int (G_SETTINGS (object), "max-bytes",
		                    g_value_get_int (value));
130 131
		break;

132 133 134 135 136
	case PROP_MAX_MEDIA_ART_WIDTH:
		g_settings_set_int (G_SETTINGS (object), "max-media-art-width",
		                    g_value_get_int (value));
		break;

137 138 139 140
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
		break;
	};
141 142 143
}

static void
Martyn Russell's avatar
Martyn Russell committed
144 145 146 147
config_get_property (GObject    *object,
                     guint       param_id,
                     GValue     *value,
                     GParamSpec *pspec)
148 149 150
{
	switch (param_id) {
	case PROP_VERBOSITY:
151 152
		g_value_set_enum (value,
		                  g_settings_get_enum (G_SETTINGS (object), "verbosity"));
153 154
		break;

155 156 157 158 159
	case PROP_SCHED_IDLE:
		g_value_set_enum (value,
		                  g_settings_get_enum (G_SETTINGS (object), "sched-idle"));
		break;

160
	case PROP_MAX_BYTES:
161 162
		g_value_set_int (value,
		                 g_settings_get_int (G_SETTINGS (object), "max-bytes"));
163 164
		break;

165 166 167 168 169
	case PROP_MAX_MEDIA_ART_WIDTH:
		g_value_set_int (value,
		                 g_settings_get_int (G_SETTINGS (object), "max-media-art-width"));
		break;

170 171 172 173 174 175 176
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
		break;
	};
}

static void
177
config_finalize (GObject *object)
178
{
179 180 181
	/* For now we do nothing here, we left this override in for
	 * future expansion.
	 */
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 196
	/* Migrate keyfile-based configuration */
	config_file = tracker_config_file_new ();
197

198 199 200
	if (config_file) {
		tracker_config_file_migrate (config_file, G_SETTINGS (object), migration);
		g_object_unref (config_file);
201 202 203 204 205 206
	}
}

TrackerConfig *
tracker_config_new (void)
{
207
	return g_object_new (TRACKER_TYPE_CONFIG,
208 209 210
	                     "schema", "org.freedesktop.Tracker.Extract",
	                     "path", "/org/freedesktop/tracker/extract/",
	                     NULL);
211 212 213 214 215
}

gint
tracker_config_get_verbosity (TrackerConfig *config)
{
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 226
}

void
tracker_config_set_verbosity (TrackerConfig *config,
Martyn Russell's avatar
Martyn Russell committed
227
                              gint           value)
228 229 230
{
	g_return_if_fail (TRACKER_IS_CONFIG (config));

231
	g_object_set (G_OBJECT (config), "verbosity", value, NULL);
232
}
233

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
gint
tracker_config_get_sched_idle (TrackerConfig *config)
{
	g_return_val_if_fail (TRACKER_IS_CONFIG (config), TRACKER_SCHED_IDLE_FIRST_INDEX);

	return g_settings_get_enum (G_SETTINGS (config), "sched-idle");
}

void
tracker_config_set_sched_idle (TrackerConfig *config,
                               gint           value)
{

	g_return_if_fail (TRACKER_IS_CONFIG (config));

	g_settings_set_enum (G_SETTINGS (config), "sched-idle", value);
	g_object_notify (G_OBJECT (config), "sched-idle");
}
252 253 254 255

gint
tracker_config_get_max_bytes (TrackerConfig *config)
{
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 266 267 268 269 270
}

void
tracker_config_set_max_bytes (TrackerConfig *config,
                              gint           value)
{
	g_return_if_fail (TRACKER_IS_CONFIG (config));

271
	g_object_set (G_OBJECT (config), "max-bytes", value, NULL);
272
}
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293

gint
tracker_config_get_max_media_art_width (TrackerConfig *config)
{
	gint max_media_art_width;

	g_return_val_if_fail (TRACKER_IS_CONFIG (config), 0);

	g_object_get (config, "max-media-art-width", &max_media_art_width, NULL);

	return max_media_art_width;
}

void
tracker_config_set_max_media_art_width (TrackerConfig *config,
                                       gint           value)
{
	g_return_if_fail (TRACKER_IS_CONFIG (config));

	g_object_set (G_OBJECT (config), "max-media-art-width", value, NULL);
}