aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-cell-date-edit-text.c
diff options
context:
space:
mode:
authorDamon Chaplin <damon@ximian.com>2001-10-23 08:23:42 +0800
committerDamon Chaplin <damon@src.gnome.org>2001-10-23 08:23:42 +0800
commit04bda8ad1e0cb676d711dbf0f22ff9f4fb615891 (patch)
tree7f1ff1303c52e9b48a0006c500b204902b9d77c5 /calendar/gui/e-cell-date-edit-text.c
parent68de308a89a844dcc579e1d9f24d7813d645c956 (diff)
downloadgsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.gz
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.zst
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.zip
added setDefaultTimezone() method.
2001-10-22 Damon Chaplin <damon@ximian.com> * idl/evolution-calendar.idl: added setDefaultTimezone() method. * pcs/cal-backend.c (cal_backend_get_default_timezone): (cal_backend_set_default_timezone): new functions to call class methods. * pcs/cal-backend-file.c: lots of changes to handle the default timezone and use it. * pcs/query.c: use the default timezone. * gui/dialogs/task-details-page.c (date_changed_cb): initialized completed_tt. * gui/dialogs/event-page.c: changed it to handle DATE values. The 'All Day Event' checkbox is only set now when the DTSTART and DTEND are DATE values. * gui/dialogs/comp-editor-util.c (comp_editor_free_dates): free the CalComponentDateTime structs as well. * gui/e-tasks.c: set the default timezone on the server. * gui/tag-calendar.c: * gui/gnome-cal.c: * gui/e-week-view.c: * gui/e-day-view.c: updates to handle DATE values. * gui/e-calendar-table.c (date_compare_cb): updated to use the new ECellDateEditValue values, so it now works. (percent_compare_cb): updated to use GPOINTER_TO_INT values. (e_calendar_table_init): use an ECellPercent for the percent field and an ECellDateEditText for the date fields. * gui/comp-util.c (cal_comp_util_compare_event_timezones): return TRUE if the DTSTART or DTEND is a DATE value. We don't want to show the timezone icons for DATE values. * gui/comp-editor-factory.c (resolve_pending_requests): set the default timezone on the server. * gui/calendar-model.c: major changes to support sorting properly. For date and percent fields we now use subclasses of ECellText, so we don't use a char* as the model value. For the percent field we now use a GINT_TO_POINTER. For the date fields we now use a ECellDateEditValue* as the value. * gui/calendar-config.c (calendar_config_configure_e_cell_date_edit): set the timezone and use_24_hour flags of the new ECellDateEditText. * conduits/todo/todo-conduit.c (pre_sync): * conduits/calendar/calendar-conduit.c (pre_sync): set the default timezone on the server. * cal-util/timeutil.c (time_days_in_month): removed debug message. * cal-util/test-recur.c: try to handle timezones in the iCalendar file properly, and updated to pass default timezone. * cal-util/cal-util.c (cal_util_generate_alarms_for_comp): (cal_util_generate_alarms_for_list): added default timezone argument. * cal-util/cal-recur.c: changed many of the functions to take a default timezone, to use to resolve DATE and floating DATE-TIME values. * cal-client/cal-client.c (cal_client_set_default_timezone): new function to set the default timezone. (cal_client_ensure_timezone_on_server): new function to ensure that a given timezone is on the server. * gui/e-cell-date-edit-text.c: new subclass of ECellText to display and edit a date value. * cal-util/cal-recur.c (cal_obj_byday_expand_monthly): changed week_num to -week_num when calculating the weeks to go back from the end of the month for things like BYDAY=-2WE. Fixes bug #11525. (cal_recur_generate_instances_of_rule): only go up to MAX_YEAR (2037). We can't really handle anything past that anyway. (cal_recur_ensure_rule_end_date): initialize cb_date.end_date to 0, so if the RULE doesn't generate COUNT instances we save 0 as the time_t. svn path=/trunk/; revision=13920
Diffstat (limited to 'calendar/gui/e-cell-date-edit-text.c')
-rw-r--r--calendar/gui/e-cell-date-edit-text.c234
1 files changed, 234 insertions, 0 deletions
diff --git a/calendar/gui/e-cell-date-edit-text.c b/calendar/gui/e-cell-date-edit-text.c
new file mode 100644
index 0000000000..d0b9d2bf7a
--- /dev/null
+++ b/calendar/gui/e-cell-date-edit-text.c
@@ -0,0 +1,234 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * Author :
+ * Damon Chaplin <damon@ximian.com>
+ *
+ * Copyright 2001, Ximian, Inc.
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+/*
+ * ECellDateEditText - a subclass of ECellText used to show and edit the text
+ * representation of the date, from a CalComponentDateTime* model value.
+ */
+
+#include <config.h>
+
+#include <sys/time.h>
+#include <time.h>
+#include <unistd.h>
+#include <string.h>
+#include <libgnomeui/gnome-messagebox.h>
+#include <libgnomeui/gnome-stock.h>
+#include <libgnome/gnome-i18n.h>
+#include <gal/util/e-util.h>
+#include <gal/widgets/e-unicode.h>
+#include <e-util/e-time-utils.h>
+#include <cal-util/timeutil.h>
+
+#include "e-cell-date-edit-text.h"
+
+
+#define PARENT_TYPE e_cell_text_get_type ()
+
+static ECellTextClass *parent_class;
+
+
+void
+e_cell_date_edit_text_set_timezone (ECellDateEditText *ecd,
+ icaltimezone *zone)
+{
+ g_return_if_fail (E_IS_CELL_DATE_EDIT_TEXT (ecd));
+
+ ecd->zone = zone;
+}
+
+
+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));
+
+ ecd->use_24_hour_format = use_24_hour;
+}
+
+
+static char *
+ecd_get_text (ECellText *cell, ETableModel *model, int col, int row)
+{
+ ECellDateEditText *ecd = E_CELL_DATE_EDIT_TEXT (cell);
+ ECellDateEditValue *dv = e_table_model_value_at (model, col, row);
+ struct icaltimetype tt;
+ struct tm tmp_tm;
+ char buffer[64];
+
+ if (!dv)
+ return g_strdup ("");
+
+ /* 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(). */
+ tt = dv->tt;
+ icaltimezone_convert_time (&tt, dv->zone, ecd->zone);
+
+ tmp_tm.tm_year = tt.year - 1900;
+ tmp_tm.tm_mon = tt.month - 1;
+ tmp_tm.tm_mday = tt.day;
+ tmp_tm.tm_hour = tt.hour;
+ tmp_tm.tm_min = tt.minute;
+ tmp_tm.tm_sec = tt.second;
+ tmp_tm.tm_isdst = -1;
+
+ tmp_tm.tm_wday = time_day_of_week (tt.day, tt.month - 1, tt.year);
+
+ e_time_format_date_and_time (&tmp_tm, ecd->use_24_hour_format,
+ TRUE, FALSE,
+ buffer, sizeof (buffer));
+ return g_strdup (buffer);
+}
+
+
+static void
+ecd_free_text (ECellText *cell, char *text)
+{
+ g_free (text);
+}
+
+
+/* FIXME: We need to set the "transient_for" property for the dialog. */
+static void
+show_date_warning (ECellDateEditText *ecd)
+{
+ GtkWidget *dialog;
+ char buffer[64], message[256], *format;
+ time_t t;
+ struct tm *tmp_tm;
+
+ t = time (NULL);
+ /* We are only using this as an example, so the timezone doesn't
+ matter. */
+ tmp_tm = localtime (&t);
+
+ if (ecd->use_24_hour_format)
+ /* strftime format of a weekday, a date and a time, 24-hour. */
+ format = _("%a %m/%d/%Y %H:%M:%S");
+ else
+ /* strftime format of a weekday, a date and a time, 12-hour. */
+ format = _("%a %m/%d/%Y %I:%M:%S %p");
+
+ strftime (buffer, sizeof (buffer), format, tmp_tm);
+
+ g_snprintf (message, 256,
+ _("The date must be entered in the format: \n\n%s"),
+ buffer);
+
+ dialog = gnome_message_box_new (message,
+ GNOME_MESSAGE_BOX_ERROR,
+ GNOME_STOCK_BUTTON_OK, NULL);
+ gtk_widget_show (dialog);
+}
+
+
+static void
+ecd_set_value (ECellText *cell, ETableModel *model, int col, int row,
+ const char *text)
+{
+ ECellDateEditText *ecd = E_CELL_DATE_EDIT_TEXT (cell);
+ ETimeParseStatus status;
+ struct tm tmp_tm;
+ ECellDateEditValue *value;
+
+ status = e_time_parse_date_and_time (text, &tmp_tm);
+
+ if (status == E_TIME_PARSE_INVALID) {
+ show_date_warning (ecd);
+ return;
+ } else if (status == E_TIME_PARSE_NONE) {
+ value = NULL;
+ } else {
+ ECellDateEditValue dv;
+
+ dv.tt = icaltime_null_time ();
+
+ dv.tt.year = tmp_tm.tm_year + 1900;
+ dv.tt.month = tmp_tm.tm_mon + 1;
+ dv.tt.day = tmp_tm.tm_mday;
+ dv.tt.hour = tmp_tm.tm_hour;
+ dv.tt.minute = tmp_tm.tm_min;
+ dv.tt.second = tmp_tm.tm_sec;
+
+ /* FIXME: We assume it is being set to the current timezone.
+ Is that OK? */
+ dv.zone = ecd->zone;
+
+ value = &dv;
+ }
+
+ e_table_model_set_value_at (model, col, row, value);
+}
+
+
+static void
+e_cell_date_edit_text_class_init (GtkObjectClass *object_class)
+{
+ ECellTextClass *ectc = (ECellTextClass *) object_class;
+
+ parent_class = gtk_type_class (PARENT_TYPE);
+
+ ectc->get_text = ecd_get_text;
+ ectc->free_text = ecd_free_text;
+ ectc->set_value = ecd_set_value;
+}
+
+
+static void
+e_cell_date_edit_text_init (GtkObject *object)
+{
+ ECellDateEditText *ecd = E_CELL_DATE_EDIT_TEXT (object);
+
+ ecd->zone = icaltimezone_get_utc_timezone ();
+ ecd->use_24_hour_format = TRUE;
+}
+
+
+/**
+ * e_cell_date_edit_text_new:
+ *
+ * Creates a new ECell renderer that can be used to render and edit dates that
+ * that come from the model. The value returned from the model is
+ * interpreted as being a CalComponentDateTime*.
+ *
+ * Returns: an ECell object that can be used to render dates.
+ */
+ECell *
+e_cell_date_edit_text_new (const char *fontname,
+ GtkJustification justify)
+{
+ ECellDateEditText *ecd = gtk_type_new (e_cell_date_edit_text_get_type ());
+
+ e_cell_text_construct (E_CELL_TEXT (ecd), fontname, justify);
+
+ return (ECell *) ecd;
+}
+
+
+E_MAKE_TYPE (e_cell_date_edit_text, "ECellDateEditText", ECellDateEditText,
+ e_cell_date_edit_text_class_init, e_cell_date_edit_text_init,
+ PARENT_TYPE);