/*
 *  Entangle: Tethered Camera Control & Capture
 *
 *  Copyright (C) 2009-2018 Daniel P. Berrangé
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdio.h>

#include "entangle-control-date.h"

#include "entangle-debug.h"

/**
 * SECTION:entangle-control-date
 * @Short_description: a device control that stores a date
 * @Title: EntangleControlDate
 *
 * The #EntangleControlDate object provides a device control that represents
 * a date string.
 */

struct _EntangleControlDate
{
    EntangleControl parent;
    int value;
};

G_DEFINE_TYPE(EntangleControlDate,
              entangle_control_date,
              ENTANGLE_TYPE_CONTROL);

enum
{
    PROP_0,
    PROP_VALUE,
};

static void
entangle_control_get_property(GObject *object,
                              guint prop_id,
                              GValue *value,
                              GParamSpec *pspec)
{
    EntangleControlDate *control = ENTANGLE_CONTROL_DATE(object);

    switch (prop_id) {
    case PROP_VALUE:
        g_value_set_int(value, control->value);
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}

static void
entangle_control_set_property(GObject *object,
                              guint prop_id,
                              const GValue *value,
                              GParamSpec *pspec)
{
    EntangleControlDate *control = ENTANGLE_CONTROL_DATE(object);

    switch (prop_id) {
    case PROP_VALUE:
        if (g_value_get_int(value) != control->value) {
            control->value = g_value_get_int(value);
            entangle_control_set_dirty(ENTANGLE_CONTROL(object), TRUE);
        }
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}

static void
entangle_control_date_finalize(GObject *object)
{
    G_OBJECT_CLASS(entangle_control_date_parent_class)->finalize(object);
}

static void
entangle_control_date_class_init(EntangleControlDateClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS(klass);

    object_class->finalize = entangle_control_date_finalize;
    object_class->get_property = entangle_control_get_property;
    object_class->set_property = entangle_control_set_property;

    g_object_class_install_property(
        object_class, PROP_VALUE,
        g_param_spec_int("value", "Control value",
                         "Current value of the control", G_MININT, G_MAXINT, 0,
                         G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
                             G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
}

EntangleControlDate *
entangle_control_date_new(const char *path,
                          int id,
                          const char *label,
                          const char *info,
                          gboolean readonly)
{
    g_return_val_if_fail(path != NULL, NULL);
    g_return_val_if_fail(label != NULL, NULL);

    return ENTANGLE_CONTROL_DATE(
        g_object_new(ENTANGLE_TYPE_CONTROL_DATE, "path", path, "id", id,
                     "label", label, "info", info, "readonly", readonly, NULL));
}

static void
entangle_control_date_init(EntangleControlDate *control G_GNUC_UNUSED)
{}

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  indent-tabs-mode: nil
 *  tab-width: 8
 * End:
 */
