aboutsummaryrefslogtreecommitdiff
path: root/src/timezone.c
blob: ca207f204969434f472efff6de5378557eca485d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Copyright 2013 Canonical Ltd.
 *
 * Authors:
 *   Charles Kerr <charles.kerr@canonical.com>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, 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 "timezone.h"

G_DEFINE_TYPE (IndicatorDatetimeTimezone,
               indicator_datetime_timezone,
               G_TYPE_OBJECT)

enum
{
  PROP_0,
  PROP_TIMEZONE,
  PROP_LAST
};

static GParamSpec * properties[PROP_LAST] = { 0, };

struct _IndicatorDatetimeTimezonePriv
{
  GString * timezone;
};

typedef struct _IndicatorDatetimeTimezonePriv priv_t;

static void
my_get_property (GObject     * o,
                 guint         property_id,
                 GValue      * value,
                 GParamSpec  * pspec)
{
  IndicatorDatetimeTimezone * self = INDICATOR_DATETIME_TIMEZONE (o);

  switch (property_id)
    {
      case PROP_TIMEZONE:
        g_value_set_string (value, indicator_datetime_timezone_get_timezone (self));
        break;

      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
    }
}

static void
my_finalize (GObject * o)
{
  priv_t * p = INDICATOR_DATETIME_TIMEZONE(o)->priv;

  g_string_free (p->timezone, TRUE);

  G_OBJECT_CLASS (indicator_datetime_timezone_parent_class)->finalize (o);
}

static void
/* cppcheck-suppress unusedFunction */
indicator_datetime_timezone_class_init (IndicatorDatetimeTimezoneClass * klass)
{
  GObjectClass * object_class;
  const GParamFlags flags = G_PARAM_READABLE | G_PARAM_STATIC_STRINGS;

  g_type_class_add_private (klass, sizeof (IndicatorDatetimeTimezonePriv));

  object_class = G_OBJECT_CLASS (klass);
  object_class->get_property = my_get_property;
  object_class->finalize = my_finalize;

  properties[PROP_TIMEZONE] = g_param_spec_string ("timezone",
                                                   "Timezone",
                                                   "Timezone",
                                                   "",
                                                   flags);

  g_object_class_install_properties (object_class, PROP_LAST, properties);
}

static void
indicator_datetime_timezone_init (IndicatorDatetimeTimezone * self)
{
  priv_t * p;

  p = G_TYPE_INSTANCE_GET_PRIVATE (self,
                                   INDICATOR_TYPE_DATETIME_TIMEZONE,
                                   IndicatorDatetimeTimezonePriv);

  p->timezone = g_string_new (NULL);

  self->priv = p;
}

/***
****
***/

const char *
indicator_datetime_timezone_get_timezone (IndicatorDatetimeTimezone * self)
{
  g_return_val_if_fail (INDICATOR_IS_DATETIME_TIMEZONE (self), NULL);

  return self->priv->timezone->str;
}

void
indicator_datetime_timezone_set_timezone (IndicatorDatetimeTimezone * self,
                                          const char                * timezone)
{
  priv_t * p = self->priv;

  if (g_strcmp0 (p->timezone->str, timezone))
    {
      g_string_assign (p->timezone, timezone);
      g_debug ("%s new timezone set: '%s'", G_STRLOC, timezone);
      g_object_notify_by_pspec (G_OBJECT(self), properties[PROP_TIMEZONE]);
    }
}