aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-cell-date-edit-text.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-08-30 13:37:36 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-08-30 13:40:49 +0800
commitcfb9c32b6657165e4d5e11aa7b47804f679a61f8 (patch)
tree1f9c8954df7a357b5dc20a13ac82bf31c1112083 /calendar/gui/e-cell-date-edit-text.c
parentfefeb30f58447f2fa7bcbee16dbe68a9333ce89d (diff)
parent0f7f4cfe38b3c4cd83efbe9922ae15c5aee00317 (diff)
downloadgsoc2013-evolution-cfb9c32b6657165e4d5e11aa7b47804f679a61f8.tar
gsoc2013-evolution-cfb9c32b6657165e4d5e11aa7b47804f679a61f8.tar.gz
gsoc2013-evolution-cfb9c32b6657165e4d5e11aa7b47804f679a61f8.tar.bz2
gsoc2013-evolution-cfb9c32b6657165e4d5e11aa7b47804f679a61f8.tar.lz
gsoc2013-evolution-cfb9c32b6657165e4d5e11aa7b47804f679a61f8.tar.xz
gsoc2013-evolution-cfb9c32b6657165e4d5e11aa7b47804f679a61f8.tar.zst
gsoc2013-evolution-cfb9c32b6657165e4d5e11aa7b47804f679a61f8.zip
Merge commit 'origin/kill-bonobo'
Diffstat (limited to 'calendar/gui/e-cell-date-edit-text.c')
-rw-r--r--calendar/gui/e-cell-date-edit-text.c220
1 files changed, 189 insertions, 31 deletions
diff --git a/calendar/gui/e-cell-date-edit-text.c b/calendar/gui/e-cell-date-edit-text.c
index 5836b8ac66..97dee085ea 100644
--- a/calendar/gui/e-cell-date-edit-text.c
+++ b/calendar/gui/e-cell-date-edit-text.c
@@ -38,47 +38,107 @@
#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;
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);
- return e_datetime_format_format_tm ("calendar", "table", dv->tt.is_date ? DTFormatKindDate : DTFormatKindDateTime, &tmp_tm);
+ return e_datetime_format_format_tm (
+ "calendar", "table", dv->tt.is_date ?
+ DTFormatKindDate : DTFormatKindDateTime, &tmp_tm);
}
static void
-ecd_free_text (ECellText *cell, gchar *text)
+cell_date_edit_text_free_text (ECellText *cell,
+ gchar *text)
{
g_free (text);
}
@@ -97,7 +157,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
@@ -117,8 +177,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;
@@ -159,7 +222,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;
@@ -169,20 +232,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;
}
/**
@@ -198,10 +317,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");
}