aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-cell-date-edit-text.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-08-01 19:29:41 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-08-06 04:13:02 +0800
commitde85e3c7862100da10fe860aef2b651245a1fdbf (patch)
treedd4a3482966c041a80c9798d45b73f5fe986dad6 /calendar/gui/e-cell-date-edit-text.c
parentfac731e7359c978ff730d48f9ab88a5794450206 (diff)
downloadgsoc2013-evolution-de85e3c7862100da10fe860aef2b651245a1fdbf.tar
gsoc2013-evolution-de85e3c7862100da10fe860aef2b651245a1fdbf.tar.gz
gsoc2013-evolution-de85e3c7862100da10fe860aef2b651245a1fdbf.tar.bz2
gsoc2013-evolution-de85e3c7862100da10fe860aef2b651245a1fdbf.tar.lz
gsoc2013-evolution-de85e3c7862100da10fe860aef2b651245a1fdbf.tar.xz
gsoc2013-evolution-de85e3c7862100da10fe860aef2b651245a1fdbf.tar.zst
gsoc2013-evolution-de85e3c7862100da10fe860aef2b651245a1fdbf.zip
Replace more "config" classes with property bindings.
Diffstat (limited to 'calendar/gui/e-cell-date-edit-text.c')
-rw-r--r--calendar/gui/e-cell-date-edit-text.c218
1 files changed, 187 insertions, 31 deletions
diff --git a/calendar/gui/e-cell-date-edit-text.c b/calendar/gui/e-cell-date-edit-text.c
index 64dd48ddf1..c99d62d4e9 100644
--- a/calendar/gui/e-cell-date-edit-text.c
+++ b/calendar/gui/e-cell-date-edit-text.c
@@ -37,51 +37,109 @@
#include "e-cell-date-edit-text.h"
-G_DEFINE_TYPE (ECellDateEditText, e_cell_date_edit_text, E_CELL_TEXT_TYPE)
+#define E_CELL_DATE_EDIT_TEXT_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_CELL_DATE_EDIT_TEXT, ECellDateEditTextPrivate))
-void
-e_cell_date_edit_text_set_timezone (ECellDateEditText *ecd,
- icaltimezone *zone)
+struct _ECellDateEditTextPrivate {
+
+ /* The timezone to display the date in. */
+ icaltimezone *timezone;
+
+ /* Whether to display in 24-hour format. */
+ gboolean use_24_hour_format;
+};
+
+enum {
+ PROP_0,
+ PROP_TIMEZONE,
+ PROP_USE_24_HOUR_FORMAT
+};
+
+static gpointer parent_class;
+
+static void
+cell_date_edit_text_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- g_return_if_fail (E_IS_CELL_DATE_EDIT_TEXT (ecd));
+ switch (property_id) {
+ case PROP_TIMEZONE:
+ e_cell_date_edit_text_set_timezone (
+ E_CELL_DATE_EDIT_TEXT (object),
+ g_value_get_pointer (value));
+ return;
- ecd->zone = zone;
+ case PROP_USE_24_HOUR_FORMAT:
+ e_cell_date_edit_text_set_use_24_hour_format (
+ E_CELL_DATE_EDIT_TEXT (object),
+ g_value_get_boolean (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
-void
-e_cell_date_edit_text_set_use_24_hour_format (ECellDateEditText *ecd,
- gboolean use_24_hour)
+static void
+cell_date_edit_text_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- g_return_if_fail (E_IS_CELL_DATE_EDIT_TEXT (ecd));
+ switch (property_id) {
+ case PROP_TIMEZONE:
+ g_value_set_pointer (
+ value,
+ e_cell_date_edit_text_get_timezone (
+ E_CELL_DATE_EDIT_TEXT (object)));
+ return;
+
+ case PROP_USE_24_HOUR_FORMAT:
+ g_value_set_boolean (
+ value,
+ e_cell_date_edit_text_get_use_24_hour_format (
+ E_CELL_DATE_EDIT_TEXT (object)));
+ return;
+ }
- ecd->use_24_hour_format = use_24_hour;
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static gchar *
-ecd_get_text (ECellText *cell, ETableModel *model, gint col, gint row)
+cell_date_edit_text_get_text (ECellText *cell,
+ ETableModel *model,
+ gint col,
+ gint row)
{
ECellDateEditText *ecd = E_CELL_DATE_EDIT_TEXT (cell);
ECellDateEditValue *dv = e_table_model_value_at (model, col, row);
+ gboolean use_24_hour_format;
+ icaltimezone *timezone;
struct tm tmp_tm;
gchar buffer[64];
if (!dv)
return g_strdup ("");
+ timezone = e_cell_date_edit_text_get_timezone (ecd);
+ use_24_hour_format = e_cell_date_edit_text_get_use_24_hour_format (ecd);
+
/* Note that although the property may be in a different
timezone, we convert it to the current timezone to display
it in the table. If the user actually edits the value,
it will be set to the current timezone. See set_value(). */
- tmp_tm = icaltimetype_to_tm_with_zone (&dv->tt, dv->zone, ecd->zone);
+ tmp_tm = icaltimetype_to_tm_with_zone (&dv->tt, dv->zone, timezone);
- e_time_format_date_and_time (&tmp_tm, ecd->use_24_hour_format,
+ e_time_format_date_and_time (&tmp_tm, use_24_hour_format,
!dv->tt.is_date, FALSE,
buffer, sizeof (buffer));
return g_strdup (buffer);
}
static void
-ecd_free_text (ECellText *cell, gchar *text)
+cell_date_edit_text_free_text (ECellText *cell,
+ gchar *text)
{
g_free (text);
}
@@ -100,7 +158,7 @@ show_date_warning (ECellDateEditText *ecd)
matter. */
tmp_tm = localtime (&t);
- if (ecd->use_24_hour_format)
+ if (e_cell_date_edit_text_get_use_24_hour_format (ecd))
/* strftime format of a weekday, a date and a time, 24-hour. */
format = _("%a %m/%d/%Y %H:%M:%S");
else
@@ -120,8 +178,11 @@ show_date_warning (ECellDateEditText *ecd)
}
static void
-ecd_set_value (ECellText *cell, ETableModel *model, gint col, gint row,
- const gchar *text)
+cell_date_edit_text_set_value (ECellText *cell,
+ ETableModel *model,
+ gint col,
+ gint row,
+ const gchar *text)
{
ECellDateEditText *ecd = E_CELL_DATE_EDIT_TEXT (cell);
ETimeParseStatus status;
@@ -162,7 +223,7 @@ ecd_set_value (ECellText *cell, ETableModel *model, gint col, gint row,
if (is_date) {
dv.zone = NULL;
} else {
- dv.zone = ecd->zone;
+ dv.zone = e_cell_date_edit_text_get_timezone (ecd);
}
value = &dv;
@@ -172,20 +233,76 @@ ecd_set_value (ECellText *cell, ETableModel *model, gint col, gint row,
}
static void
-e_cell_date_edit_text_class_init (ECellDateEditTextClass *ecdet)
+cell_date_edit_text_class_init (ECellDateEditTextClass *class)
{
- ECellTextClass *ectc = E_CELL_TEXT_CLASS (ecdet);
-
- ectc->get_text = ecd_get_text;
- ectc->free_text = ecd_free_text;
- ectc->set_value = ecd_set_value;
+ GObjectClass *object_class;
+ ECellTextClass *cell_text_class;
+
+ parent_class = g_type_class_peek_parent (class);
+ g_type_class_add_private (class, sizeof (ECellDateEditTextPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = cell_date_edit_text_set_property;
+ object_class->get_property = cell_date_edit_text_get_property;
+
+ cell_text_class = E_CELL_TEXT_CLASS (class);
+ cell_text_class->get_text = cell_date_edit_text_get_text;
+ cell_text_class->free_text = cell_date_edit_text_free_text;
+ cell_text_class->set_value = cell_date_edit_text_set_value;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_TIMEZONE,
+ g_param_spec_pointer (
+ "timezone",
+ "Time Zone",
+ NULL,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_USE_24_HOUR_FORMAT,
+ g_param_spec_boolean (
+ "use-24-hour-format",
+ "Use 24-Hour Format",
+ NULL,
+ TRUE,
+ G_PARAM_READWRITE));
}
static void
-e_cell_date_edit_text_init (ECellDateEditText *ecd)
+cell_date_edit_text_init (ECellDateEditText *ecd)
{
- ecd->zone = icaltimezone_get_utc_timezone ();
- ecd->use_24_hour_format = TRUE;
+ ecd->priv = E_CELL_DATE_EDIT_TEXT_GET_PRIVATE (ecd);
+
+ ecd->priv->timezone = icaltimezone_get_utc_timezone ();
+ ecd->priv->use_24_hour_format = TRUE;
+}
+
+GType
+e_cell_date_edit_text_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ const GTypeInfo type_info = {
+ sizeof (ECellDateEditTextClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) cell_date_edit_text_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class_data */
+ sizeof (ECellDateEditText),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) cell_date_edit_text_init,
+ NULL /* value_table */
+ };
+
+ type = g_type_register_static (
+ E_CELL_TEXT_TYPE, "ECellDateEditText", &type_info, 0);
+ }
+
+ return type;
}
/**
@@ -201,10 +318,49 @@ ECell *
e_cell_date_edit_text_new (const gchar *fontname,
GtkJustification justify)
{
- ECellDateEditText *ecd = g_object_new (e_cell_date_edit_text_get_type (), NULL);
+ ECell *cell;
+
+ cell = g_object_new (E_TYPE_CELL_DATE_EDIT_TEXT, NULL);
+ e_cell_text_construct (E_CELL_TEXT (cell), fontname, justify);
+
+ return cell;
+}
+
+icaltimezone *
+e_cell_date_edit_text_get_timezone (ECellDateEditText *ecd)
+{
+ g_return_val_if_fail (E_IS_CELL_DATE_EDIT_TEXT (ecd), NULL);
+
+ return ecd->priv->timezone;
+}
+
+void
+e_cell_date_edit_text_set_timezone (ECellDateEditText *ecd,
+ icaltimezone *timezone)
+{
+ g_return_if_fail (E_IS_CELL_DATE_EDIT_TEXT (ecd));
+
+ ecd->priv->timezone = timezone;
+
+ g_object_notify (G_OBJECT (ecd), "timezone");
+}
+
+gboolean
+e_cell_date_edit_text_get_use_24_hour_format (ECellDateEditText *ecd)
+{
+ g_return_val_if_fail (E_IS_CELL_DATE_EDIT_TEXT (ecd), FALSE);
+
+ return ecd->priv->use_24_hour_format;
+}
+
+void
+e_cell_date_edit_text_set_use_24_hour_format (ECellDateEditText *ecd,
+ gboolean use_24_hour)
+{
+ g_return_if_fail (E_IS_CELL_DATE_EDIT_TEXT (ecd));
- e_cell_text_construct (E_CELL_TEXT (ecd), fontname, justify);
+ ecd->priv->use_24_hour_format = use_24_hour;
- return (ECell *) ecd;
+ g_object_notify (G_OBJECT (ecd), "use-24-hour-format");
}