/*
 * camel-mh-settings.c
 *
 * This library is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "camel-mh-settings.h"

struct _CamelMhSettingsPrivate {
	gboolean use_dot_folders;
};

enum {
	PROP_0,
	PROP_USE_DOT_FOLDERS,
	N_PROPS
};

static GParamSpec *properties[N_PROPS] = { NULL, };

G_DEFINE_TYPE_WITH_PRIVATE (
	CamelMhSettings,
	camel_mh_settings,
	CAMEL_TYPE_LOCAL_SETTINGS)

static void
mh_settings_set_property (GObject *object,
                             guint property_id,
                             const GValue *value,
                             GParamSpec *pspec)
{
	switch (property_id) {
		case PROP_USE_DOT_FOLDERS:
			camel_mh_settings_set_use_dot_folders (
				CAMEL_MH_SETTINGS (object),
				g_value_get_boolean (value));
			return;
	}

	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
mh_settings_get_property (GObject *object,
                             guint property_id,
                             GValue *value,
                             GParamSpec *pspec)
{
	switch (property_id) {
		case PROP_USE_DOT_FOLDERS:
			g_value_set_boolean (
				value,
				camel_mh_settings_get_use_dot_folders (
				CAMEL_MH_SETTINGS (object)));
			return;
	}

	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
camel_mh_settings_class_init (CamelMhSettingsClass *class)
{
	GObjectClass *object_class;

	object_class = G_OBJECT_CLASS (class);
	object_class->set_property = mh_settings_set_property;
	object_class->get_property = mh_settings_get_property;

	/**
	 * CamelMhSettings:use-dot-folders
	 *
	 * Update the exmh .folders file
	 **/
	properties[PROP_USE_DOT_FOLDERS] =
		g_param_spec_boolean (
			"use-dot-folders", NULL, NULL,
			FALSE,
			G_PARAM_READWRITE |
			G_PARAM_CONSTRUCT |
			G_PARAM_EXPLICIT_NOTIFY |
			G_PARAM_STATIC_STRINGS);

	g_object_class_install_properties (object_class, N_PROPS, properties);
}

static void
camel_mh_settings_init (CamelMhSettings *settings)
{
	settings->priv = camel_mh_settings_get_instance_private (settings);
}

/**
 * camel_mh_settings_get_use_dot_folders:
 * @settings: a #CamelMhSettings
 *
 * Returns whether @settings should keep the .folders summary file used by
 * the exmh (http://www.beedub.com/exmh/) mail client updated as it makes
 * changes to the MH folders.
 *
 * Returns: whether to use exmh's .folders file
 *
 * Since: 3.2
 **/
gboolean
camel_mh_settings_get_use_dot_folders (CamelMhSettings *settings)
{
	g_return_val_if_fail (CAMEL_IS_MH_SETTINGS (settings), FALSE);

	return settings->priv->use_dot_folders;
}

/**
 * camel_mh_settings_set_use_dot_folders:
 * @settings: a #CamelMhSettings
 * @use_dot_folders: whether to use exmh's .folders file
 *
 * Sets whether @settings should keep the .folders summary file used by
 * the exmh (http://www.beedub.com/exmh/) mail client updated as it makes
 * changes to the MH folders.
 *
 * Since: 3.2
 **/
void
camel_mh_settings_set_use_dot_folders (CamelMhSettings *settings,
                                       gboolean use_dot_folders)
{
	g_return_if_fail (CAMEL_IS_MH_SETTINGS (settings));

	if (settings->priv->use_dot_folders == use_dot_folders)
		return;

	settings->priv->use_dot_folders = use_dot_folders;

	g_object_notify_by_pspec (G_OBJECT (settings), properties[PROP_USE_DOT_FOLDERS]);
}
