tracker-config.c 9.7 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
	PROP_MAX_BYTES,
44 45
	PROP_MAX_MEDIA_ART_WIDTH,
	PROP_WAIT_FOR_MINER_FS,
46 47
};

48 49
static TrackerConfigMigrationEntry migration[] = {
	{ G_TYPE_ENUM, "General", "Verbosity", "verbosity" },
50
	{ G_TYPE_ENUM, "General", "SchedIdle", "sched-idle" },
51
	{ G_TYPE_INT, "General", "MaxBytes", "max-bytes" },
52
	{ G_TYPE_INT, "General", "MaxMediaArtWidth", "max-media-art-width" },
53
	{ 0 }
54 55
};

56
G_DEFINE_TYPE (TrackerConfig, tracker_config, G_TYPE_SETTINGS);
57 58 59 60 61 62 63

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

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

	/* General */
	g_object_class_install_property (object_class,
Martyn Russell's avatar
Martyn Russell committed
70
	                                 PROP_VERBOSITY,
71
	                                 g_param_spec_enum ("verbosity",
72 73 74 75 76
	                                                    "Log verbosity",
	                                                    "Log verbosity (0=errors, 1=minimal, 2=detailed, 3=debug)",
	                                                    TRACKER_TYPE_VERBOSITY,
	                                                    TRACKER_VERBOSITY_ERRORS,
	                                                    G_PARAM_READWRITE));
77 78 79 80 81 82 83 84
	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));
85

86
	g_object_class_install_property (object_class,
87
	                                 PROP_MAX_BYTES,
88
	                                 g_param_spec_int ("max-bytes",
89
	                                                   "Max Bytes",
90 91
	                                                   "Maximum number of UTF-8 bytes to extract per file [0->10485760]",
	                                                   0, 1024 * 1024 * 10,
92
	                                                   1024 * 1024,
93
	                                                   G_PARAM_READWRITE));
94 95 96 97 98 99 100 101 102 103

	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));
104 105 106 107 108 109 110 111

	g_object_class_install_property (object_class,
	                                 PROP_WAIT_FOR_MINER_FS,
	                                 g_param_spec_boolean ("wait-for-miner-fs",
	                                                       "Wait for FS miner to be done before extracting",
	                                                       "%TRUE to wait for tracker-miner-fs is done before extracting. %FAlSE otherwise",
	                                                       FALSE,
	                                                       G_PARAM_READWRITE));
112 113 114 115 116 117 118 119
}

static void
tracker_config_init (TrackerConfig *object)
{
}

static void
Martyn Russell's avatar
Martyn Russell committed
120 121 122
config_set_property (GObject      *object,
                     guint         param_id,
                     const GValue *value,
123
                     GParamSpec   *pspec)
124
{
125 126
	TrackerConfig *config = TRACKER_CONFIG (object);

127
	switch (param_id) {
128 129 130 131
	/* General */
	/* NOTE: We handle these because we have to be able
	 * to save these based on command line overrides.
	 */
132
	case PROP_VERBOSITY:
133
		tracker_config_set_verbosity (config, g_value_get_enum (value));
134
		break;
135

136
	/* We don't care about the others... we don't save anyway. */
137
	case PROP_SCHED_IDLE:
138
	case PROP_MAX_BYTES:
139
	case PROP_MAX_MEDIA_ART_WIDTH:
140
	case PROP_WAIT_FOR_MINER_FS:
141 142
		break;

143 144 145 146
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
		break;
	};
147 148 149
}

static void
Martyn Russell's avatar
Martyn Russell committed
150 151 152 153
config_get_property (GObject    *object,
                     guint       param_id,
                     GValue     *value,
                     GParamSpec *pspec)
154
{
155 156
	TrackerConfig *config = TRACKER_CONFIG (object);

157 158
	switch (param_id) {
	case PROP_VERBOSITY:
159
		g_value_set_enum (value,
160
		                  tracker_config_get_verbosity (config));
161 162
		break;

163 164
	case PROP_SCHED_IDLE:
		g_value_set_enum (value,
165
		                  tracker_config_get_sched_idle (config));
166 167
		break;

168
	case PROP_MAX_BYTES:
169
		g_value_set_int (value,
170
		                 tracker_config_get_max_bytes (config));
171 172
		break;

173 174
	case PROP_MAX_MEDIA_ART_WIDTH:
		g_value_set_int (value,
175
		                 tracker_config_get_max_media_art_width (config));
176 177
		break;

178 179 180 181 182
	case PROP_WAIT_FOR_MINER_FS:
		g_value_set_boolean (value,
		                     tracker_config_get_wait_for_miner_fs (config));
		break;

183 184 185 186 187 188 189
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
		break;
	};
}

static void
190
config_finalize (GObject *object)
191
{
192 193 194
	/* For now we do nothing here, we left this override in for
	 * future expansion.
	 */
195

196
	(G_OBJECT_CLASS (tracker_config_parent_class)->finalize) (object);
197 198 199
}

static void
200
config_constructed (GObject *object)
201
{
202
	TrackerConfigFile *config_file;
203
	GSettings *settings;
204

205
	(G_OBJECT_CLASS (tracker_config_parent_class)->constructed) (object);
206

207 208 209 210 211 212 213 214 215
	settings = G_SETTINGS (object);

	g_settings_delay (settings);

	/* Set up bindings */
	g_settings_bind (settings, "verbosity", object, "verbosity", G_SETTINGS_BIND_GET_NO_CHANGES);
	g_settings_bind (settings, "sched-idle", object, "sched-idle", G_SETTINGS_BIND_GET);
	g_settings_bind (settings, "max-bytes", object, "max-bytes", G_SETTINGS_BIND_GET);
	g_settings_bind (settings, "max-media-art-width", object, "max-media-art-width", G_SETTINGS_BIND_GET);
216
	g_settings_bind (settings, "wait-for-miner-fs", object, "wait-for-miner-fs", G_SETTINGS_BIND_GET);
217

218 219
	/* Migrate keyfile-based configuration */
	config_file = tracker_config_file_new ();
220

221
	if (config_file) {
222
		tracker_config_file_migrate (config_file, settings, migration);
223
		g_object_unref (config_file);
224 225 226 227 228 229
	}
}

TrackerConfig *
tracker_config_new (void)
{
230
	return g_object_new (TRACKER_TYPE_CONFIG,
231
	                     "schema-id", "org.freedesktop.Tracker.Extract",
232 233
	                     "path", "/org/freedesktop/tracker/extract/",
	                     NULL);
234 235 236 237 238
}

gint
tracker_config_get_verbosity (TrackerConfig *config)
{
239
	g_return_val_if_fail (TRACKER_IS_CONFIG (config), TRACKER_VERBOSITY_ERRORS);
240

241
	return g_settings_get_enum (G_SETTINGS (config), "verbosity");
242 243 244 245
}

void
tracker_config_set_verbosity (TrackerConfig *config,
Martyn Russell's avatar
Martyn Russell committed
246
                              gint           value)
247 248 249
{
	g_return_if_fail (TRACKER_IS_CONFIG (config));

250
	g_settings_set_enum (G_SETTINGS (config), "verbosity", value);
251
}
252

253 254 255 256 257 258 259 260
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");
}

261 262 263
gint
tracker_config_get_max_bytes (TrackerConfig *config)
{
264
	g_return_val_if_fail (TRACKER_IS_CONFIG (config), 0);
265

266
	return g_settings_get_int (G_SETTINGS (config), "max-bytes");
267
}
268 269 270 271 272 273

gint
tracker_config_get_max_media_art_width (TrackerConfig *config)
{
	g_return_val_if_fail (TRACKER_IS_CONFIG (config), 0);

274
	return g_settings_get_int (G_SETTINGS (config), "max-media-art-width");
275
}
276 277 278 279 280 281 282 283

gboolean
tracker_config_get_wait_for_miner_fs (TrackerConfig *config)
{
	g_return_val_if_fail (TRACKER_IS_CONFIG (config), FALSE);

	return g_settings_get_boolean (G_SETTINGS (config), "wait-for-miner-fs");
}