aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamon Chaplin <damon@ximian.com>2001-07-03 12:12:17 +0800
committerDamon Chaplin <damon@src.gnome.org>2001-07-03 12:12:17 +0800
commitbacd3a85a434032316b3e63b95282175ce2b0659 (patch)
tree00e6b5444efed4ad1ef742968c292d52f4ee6a78
parent0e27010e0b193b787e93cbf50c08a6d477e33dee (diff)
downloadgsoc2013-evolution-bacd3a85a434032316b3e63b95282175ce2b0659.tar
gsoc2013-evolution-bacd3a85a434032316b3e63b95282175ce2b0659.tar.gz
gsoc2013-evolution-bacd3a85a434032316b3e63b95282175ce2b0659.tar.bz2
gsoc2013-evolution-bacd3a85a434032316b3e63b95282175ce2b0659.tar.lz
gsoc2013-evolution-bacd3a85a434032316b3e63b95282175ce2b0659.tar.xz
gsoc2013-evolution-bacd3a85a434032316b3e63b95282175ce2b0659.tar.zst
gsoc2013-evolution-bacd3a85a434032316b3e63b95282175ce2b0659.zip
added functions to set a callback to get the current time, which is used
2001-07-02 Damon Chaplin <damon@ximian.com> * e-calendar-item.c: * e-cell-date-edit.c: * e-dateedit.c: added functions to set a callback to get the current time, which is used instead of localtime(). We need this as we have to use our own timezones. svn path=/trunk/; revision=10728
-rw-r--r--widgets/misc/ChangeLog8
-rw-r--r--widgets/misc/e-calendar-item.c43
-rw-r--r--widgets/misc/e-calendar-item.h19
-rw-r--r--widgets/misc/e-cell-date-edit.c57
-rw-r--r--widgets/misc/e-cell-date-edit.h31
-rw-r--r--widgets/misc/e-dateedit.c106
-rw-r--r--widgets/misc/e-dateedit.h16
7 files changed, 230 insertions, 50 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog
index 5066477a8c..e992692c71 100644
--- a/widgets/misc/ChangeLog
+++ b/widgets/misc/ChangeLog
@@ -1,3 +1,11 @@
+2001-07-02 Damon Chaplin <damon@ximian.com>
+
+ * e-calendar-item.c:
+ * e-cell-date-edit.c:
+ * e-dateedit.c: added functions to set a callback to get the current
+ time, which is used instead of localtime(). We need this as we have to
+ use our own timezones.
+
2001-07-02 Jeffrey Stedfast <fejj@ximian.com>
* e-charset-picker.c (e_charset_picker_bonobo_ui_populate): Take a
diff --git a/widgets/misc/e-calendar-item.c b/widgets/misc/e-calendar-item.c
index c2f13ca1a6..c5399c14f8 100644
--- a/widgets/misc/e-calendar-item.c
+++ b/widgets/misc/e-calendar-item.c
@@ -415,8 +415,13 @@ e_calendar_item_init (ECalendarItem *calitem)
calitem->date_range_changed = FALSE;
calitem->style_callback = NULL;
+ calitem->style_callback_data = NULL;
calitem->style_callback_destroy = NULL;
+ calitem->time_callback = NULL;
+ calitem->time_callback_data = NULL;
+ calitem->time_callback_destroy = NULL;
+
/* Translators: These are the first characters of each day of the
week, 'M' for 'Monday', 'T' for Tuesday etc. */
calitem->days = _("MTWTFSS");
@@ -433,6 +438,7 @@ e_calendar_item_destroy (GtkObject *o)
calitem = E_CALENDAR_ITEM (o);
e_calendar_item_set_style_callback (calitem, NULL, NULL, NULL);
+ e_calendar_item_set_get_time_callback (calitem, NULL, NULL, NULL);
g_free (calitem->styles);
@@ -1162,7 +1168,7 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
GdkFont *font, *wkfont;
GdkGC *fg_gc;
GdkColor *bg_color, *fg_color, *box_color;
- struct tm *today_tm;
+ struct tm today_tm;
time_t t;
gint char_height, min_cell_width, min_cell_height;
gint day_num, drow, dcol, day_x, day_y;
@@ -1235,11 +1241,15 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
}
/* Get today's date, so we can highlight it. */
- t = time (NULL);
- today_tm = localtime (&t);
- today_year = today_tm->tm_year + 1900;
- today_month = today_tm->tm_mon;
- today_mday = today_tm->tm_mday;
+ if (calitem->time_callback) {
+ today_tm = (*calitem->time_callback) (calitem, calitem->time_callback_data);
+ } else {
+ t = time (NULL);
+ today_tm = *localtime (&t);
+ }
+ today_year = today_tm.tm_year + 1900;
+ today_month = today_tm.tm_mon;
+ today_mday = today_tm.tm_mday;
/* We usually skip the last days of the previous month (mon = 0),
except for the top-left month displayed. */
@@ -2827,7 +2837,7 @@ e_calendar_item_set_style_callback (ECalendarItem *calitem,
{
g_return_if_fail (E_IS_CALENDAR_ITEM (calitem));
- if (calitem->style_callback_data)
+ if (calitem->style_callback_data && calitem->style_callback_destroy)
(*calitem->style_callback_destroy) (calitem->style_callback_data);
calitem->style_callback = cb;
@@ -2884,3 +2894,22 @@ e_calendar_item_signal_emission_idle_cb (gpointer data)
return FALSE;
}
+
+/* Sets a callback to use to get the current time. This is useful if the
+ application needs to use its own timezone data rather than rely on the
+ Unix timezone. */
+void
+e_calendar_item_set_get_time_callback (ECalendarItem *calitem,
+ ECalendarItemGetTimeCallback cb,
+ gpointer data,
+ GtkDestroyNotify destroy)
+{
+ g_return_if_fail (E_IS_CALENDAR_ITEM (calitem));
+
+ if (calitem->time_callback_data && calitem->time_callback_destroy)
+ (*calitem->time_callback_destroy) (calitem->time_callback_data);
+
+ calitem->time_callback = cb;
+ calitem->time_callback_data = data;
+ calitem->time_callback_destroy = destroy;
+}
diff --git a/widgets/misc/e-calendar-item.h b/widgets/misc/e-calendar-item.h
index 3d4e582e39..0ef25ed62a 100644
--- a/widgets/misc/e-calendar-item.h
+++ b/widgets/misc/e-calendar-item.h
@@ -55,6 +55,8 @@ typedef enum
typedef struct _ECalendarItem ECalendarItem;
typedef struct _ECalendarItemClass ECalendarItemClass;
+/* The type of the callback function optionally used to get the colors to
+ use for each day. */
typedef void (*ECalendarItemStyleCallback) (ECalendarItem *calitem,
gint year,
gint month,
@@ -71,6 +73,11 @@ typedef void (*ECalendarItemStyleCallback) (ECalendarItem *calitem,
gboolean *bold,
gpointer data);
+/* The type of the callback function optionally used to get the current time.
+ */
+typedef struct tm (*ECalendarItemGetTimeCallback) (ECalendarItem *calitem,
+ gpointer data);
+
#define E_CALENDAR_ITEM(obj) (GTK_CHECK_CAST((obj), \
e_calendar_item_get_type (), ECalendarItem))
@@ -199,6 +206,10 @@ struct _ECalendarItem
gpointer style_callback_data;
GtkDestroyNotify style_callback_destroy;
+ ECalendarItemGetTimeCallback time_callback;
+ gpointer time_callback_data;
+ GtkDestroyNotify time_callback_destroy;
+
/* Colors for drawing. */
GdkColor colors[E_CALENDAR_ITEM_COLOR_LAST];
@@ -313,6 +324,14 @@ void e_calendar_item_set_style_callback (ECalendarItem *calitem,
gpointer data,
GtkDestroyNotify destroy);
+/* Sets a callback to use to get the current time. This is useful if the
+ application needs to use its own timezone data rather than rely on the
+ Unix timezone. */
+void e_calendar_item_set_get_time_callback (ECalendarItem *calitem,
+ ECalendarItemGetTimeCallback cb,
+ gpointer data,
+ GtkDestroyNotify destroy);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/widgets/misc/e-cell-date-edit.c b/widgets/misc/e-cell-date-edit.c
index 6f572f2cd0..f6670c844e 100644
--- a/widgets/misc/e-cell-date-edit.c
+++ b/widgets/misc/e-cell-date-edit.c
@@ -155,6 +155,9 @@ e_cell_date_edit_init (ECellDateEdit *ecde)
ecde->use_24_hour_format = TRUE;
ecde->need_time_list_rebuild = TRUE;
ecde->freeze_count = 0;
+ ecde->time_callback = NULL;
+ ecde->time_callback_data = NULL;
+ ecde->time_callback_destroy = NULL;
/* We create one popup window for the ECell, since there will only
ever be one popup in use at a time. */
@@ -281,6 +284,8 @@ e_cell_date_edit_destroy (GtkObject *object)
{
ECellDateEdit *ecde = E_CELL_DATE_EDIT (object);
+ e_cell_date_edit_set_get_time_callback (ecde, NULL, NULL, NULL);
+
gtk_widget_unref (ecde->popup_window);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
@@ -742,15 +747,19 @@ static void
e_cell_date_edit_on_now_clicked (GtkWidget *button,
ECellDateEdit *ecde)
{
- struct tm *tmp_tm;
+ struct tm tmp_tm;
time_t t;
char buffer[64];
g_print ("In e_cell_date_edit_on_now_clicked\n");
- t = time (NULL);
- tmp_tm = localtime (&t);
- e_time_format_date_and_time (tmp_tm,
+ if (ecde->time_callback) {
+ tmp_tm = (*ecde->time_callback) (ecde, ecde->time_callback_data);
+ } else {
+ t = time (NULL);
+ tmp_tm = *localtime (&t);
+ }
+ e_time_format_date_and_time (&tmp_tm,
ecde->use_24_hour_format,
TRUE, FALSE,
buffer, sizeof (buffer));
@@ -775,18 +784,23 @@ static void
e_cell_date_edit_on_today_clicked (GtkWidget *button,
ECellDateEdit *ecde)
{
- struct tm *tmp_tm;
+ struct tm tmp_tm;
time_t t;
char buffer[64];
g_print ("In e_cell_date_edit_on_today_clicked\n");
- t = time (NULL);
- tmp_tm = localtime (&t);
- tmp_tm->tm_hour = 0;
- tmp_tm->tm_min = 0;
- tmp_tm->tm_sec = 0;
- e_time_format_date_and_time (tmp_tm,
+ if (ecde->time_callback) {
+ tmp_tm = (*ecde->time_callback) (ecde, ecde->time_callback_data);
+ } else {
+ t = time (NULL);
+ tmp_tm = *localtime (&t);
+ }
+
+ tmp_tm.tm_hour = 0;
+ tmp_tm.tm_min = 0;
+ tmp_tm.tm_sec = 0;
+ e_time_format_date_and_time (&tmp_tm,
ecde->use_24_hour_format,
FALSE, FALSE,
buffer, sizeof (buffer));
@@ -873,3 +887,24 @@ e_cell_date_edit_thaw (ECellDateEdit *ecde)
}
}
+
+/* Sets a callback to use to get the current time. This is useful if the
+ application needs to use its own timezone data rather than rely on the
+ Unix timezone. */
+void
+e_cell_date_edit_set_get_time_callback (ECellDateEdit *ecde,
+ ECellDateEditGetTimeCallback cb,
+ gpointer data,
+ GtkDestroyNotify destroy)
+{
+ g_return_if_fail (E_IS_CELL_DATE_EDIT (ecde));
+
+ if (ecde->time_callback_data && ecde->time_callback_destroy)
+ (*ecde->time_callback_destroy) (ecde->time_callback_data);
+
+ ecde->time_callback = cb;
+ ecde->time_callback_data = data;
+ ecde->time_callback_destroy = destroy;
+}
+
+
diff --git a/widgets/misc/e-cell-date-edit.h b/widgets/misc/e-cell-date-edit.h
index f3f8beb02b..67af112c94 100644
--- a/widgets/misc/e-cell-date-edit.h
+++ b/widgets/misc/e-cell-date-edit.h
@@ -30,6 +30,7 @@
#ifndef _E_CELL_DATE_EDIT_H_
#define _E_CELL_DATE_EDIT_H_
+#include <time.h>
#include <gal/e-table/e-cell-popup.h>
#define E_CELL_DATE_EDIT_TYPE (e_cell_date_edit_get_type ())
@@ -39,7 +40,15 @@
#define E_IS_CELL_DATE_EDIT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_DATE_EDIT_TYPE))
-typedef struct {
+typedef struct _ECellDateEdit ECellDateEdit;
+typedef struct _ECellDateEditClass ECellDateEditClass;
+
+/* The type of the callback function optionally used to get the current time.
+ */
+typedef struct tm (*ECellDateEditGetTimeCallback) (ECellDateEdit *ecde,
+ gpointer data);
+
+struct _ECellDateEdit {
ECellPopup parent;
GtkWidget *popup_window;
@@ -64,11 +73,15 @@ typedef struct {
/* The freeze count for rebuilding the time list. We only rebuild when
this is 0. */
gint freeze_count;
-} ECellDateEdit;
-typedef struct {
+ ECellDateEditGetTimeCallback time_callback;
+ gpointer time_callback_data;
+ GtkDestroyNotify time_callback_destroy;
+};
+
+struct _ECellDateEditClass {
ECellPopupClass parent_class;
-} ECellDateEditClass;
+};
GtkType e_cell_date_edit_get_type (void);
@@ -81,4 +94,14 @@ ECell *e_cell_date_edit_new (void);
void e_cell_date_edit_freeze (ECellDateEdit *ecde);
void e_cell_date_edit_thaw (ECellDateEdit *ecde);
+
+/* Sets a callback to use to get the current time. This is useful if the
+ application needs to use its own timezone data rather than rely on the
+ Unix timezone. */
+void e_cell_date_edit_set_get_time_callback(ECellDateEdit *ecde,
+ ECellDateEditGetTimeCallback cb,
+ gpointer data,
+ GtkDestroyNotify destroy);
+
+
#endif /* _E_CELL_DATE_EDIT_H_ */
diff --git a/widgets/misc/e-dateedit.c b/widgets/misc/e-dateedit.c
index bcd1dc18ea..6abd74eb71 100644
--- a/widgets/misc/e-dateedit.c
+++ b/widgets/misc/e-dateedit.c
@@ -117,6 +117,10 @@ struct _EDateEditPrivate {
gboolean time_set_to_none;
gint hour;
gint minute;
+
+ EDateEditGetTimeCallback time_callback;
+ gpointer time_callback_data;
+ GtkDestroyNotify time_callback_destroy;
};
enum {
@@ -275,6 +279,9 @@ e_date_edit_init (EDateEdit *dedit)
priv->date_set_to_none = TRUE;
priv->time_is_valid = TRUE;
priv->time_set_to_none = TRUE;
+ priv->time_callback = NULL;
+ priv->time_callback_data = NULL;
+ priv->time_callback_destroy = NULL;
create_children (dedit);
@@ -445,6 +452,8 @@ e_date_edit_destroy (GtkObject *object)
dedit = E_DATE_EDIT (object);
+ e_date_edit_set_get_time_callback (dedit, NULL, NULL, NULL);
+
gtk_widget_destroy (dedit->priv->cal_popup);
dedit->priv->cal_popup = NULL;
@@ -530,13 +539,17 @@ e_date_edit_get_time (EDateEdit *dedit)
* Description: Changes the displayed date and time in the EDateEdit
* widget to be the one represented by @the_time. If @the_time is 0
* then current time is used. If it is -1, then the date is set to None.
+ *
+ * Note that the time is converted to local time using the Unix timezone,
+ * so if you are using your own timezones then you should use
+ * e_date_edit_set_date() and e_date_edit_set_time_of_day() instead.
*/
void
e_date_edit_set_time (EDateEdit *dedit,
time_t the_time)
{
EDateEditPrivate *priv;
- struct tm *tmp_tm;
+ struct tm tmp_tm;
gboolean date_changed = FALSE, time_changed = FALSE;
g_return_if_fail (E_IS_DATE_EDIT (dedit));
@@ -549,20 +562,26 @@ e_date_edit_set_time (EDateEdit *dedit,
time_changed = e_date_edit_set_time_internal (dedit, TRUE,
TRUE, 0, 0);
} else {
- if (the_time == 0)
- the_time = time (NULL);
-
- tmp_tm = localtime (&the_time);
+ if (the_time == 0) {
+ if (priv->time_callback) {
+ tmp_tm = (*priv->time_callback) (dedit, priv->time_callback_data);
+ } else {
+ the_time = time (NULL);
+ tmp_tm = *localtime (&the_time);
+ }
+ } else {
+ tmp_tm = *localtime (&the_time);
+ }
date_changed = e_date_edit_set_date_internal (dedit, TRUE,
FALSE,
- tmp_tm->tm_year,
- tmp_tm->tm_mon,
- tmp_tm->tm_mday);
+ tmp_tm.tm_year,
+ tmp_tm.tm_mon,
+ tmp_tm.tm_mday);
time_changed = e_date_edit_set_time_internal (dedit, TRUE,
FALSE,
- tmp_tm->tm_hour,
- tmp_tm->tm_min);
+ tmp_tm.tm_hour,
+ tmp_tm.tm_min);
}
e_date_edit_update_date_entry (dedit);
@@ -651,8 +670,8 @@ e_date_edit_set_date (EDateEdit *dedit,
/**
* e_date_edit_get_time_of_day:
* @dedit: an #EDateEdit widget.
- * @hour: returns the hour set.
- * @minute: returns the minute set.
+ * @hour: returns the hour set, or 0 if the time isn't set.
+ * @minute: returns the minute set, or 0 if the time isn't set.
* @Returns: TRUE if a time was set, or FALSE if the field is empty or 'None'.
*
* Returns the last valid time entered into the time field.
@@ -671,13 +690,15 @@ e_date_edit_get_time_of_day (EDateEdit *dedit,
/* Try to parse any new value now. */
e_date_edit_check_time_changed (dedit);
- if (priv->time_set_to_none)
+ if (priv->time_set_to_none) {
+ *hour = 0;
+ *minute = 0;
return FALSE;
-
- *hour = priv->hour;
- *minute = priv->minute;
-
- return TRUE;
+ } else {
+ *hour = priv->hour;
+ *minute = priv->minute;
+ return TRUE;
+ }
}
@@ -951,10 +972,10 @@ e_date_edit_set_allow_no_date_set (EDateEdit *dedit,
time is showing we make sure it isn't 'None'. */
if (dedit->priv->show_date) {
if (dedit->priv->date_set_to_none)
- e_date_edit_set_time (dedit, time (NULL));
+ e_date_edit_set_time (dedit, 0);
} else {
if (dedit->priv->time_set_to_none)
- e_date_edit_set_time (dedit, time (NULL));
+ e_date_edit_set_time (dedit, 0);
}
}
}
@@ -1110,7 +1131,7 @@ on_date_popup_now_button_clicked (GtkWidget *button,
EDateEdit *dedit)
{
hide_date_popup (dedit);
- e_date_edit_set_time (dedit, time (NULL));
+ e_date_edit_set_time (dedit, 0);
}
@@ -1118,16 +1139,23 @@ static void
on_date_popup_today_button_clicked (GtkWidget *button,
EDateEdit *dedit)
{
- struct tm *tmp_tm;
+ EDateEditPrivate *priv;
+ struct tm tmp_tm;
time_t t;
+ priv = dedit->priv;
+
hide_date_popup (dedit);
- t = time (NULL);
- tmp_tm = localtime (&t);
+ if (priv->time_callback) {
+ tmp_tm = (*priv->time_callback) (dedit, priv->time_callback_data);
+ } else {
+ t = time (NULL);
+ tmp_tm = *localtime (&t);
+ }
- e_date_edit_set_date (dedit, tmp_tm->tm_year + 1900,
- tmp_tm->tm_mon + 1, tmp_tm->tm_mday);
+ e_date_edit_set_date (dedit, tmp_tm.tm_year + 1900,
+ tmp_tm.tm_mon + 1, tmp_tm.tm_mday);
}
@@ -1731,3 +1759,29 @@ e_date_edit_set_time_internal (EDateEdit *dedit,
return time_changed;
}
+
+
+/* Sets a callback to use to get the current time. This is useful if the
+ application needs to use its own timezone data rather than rely on the
+ Unix timezone. */
+void
+e_date_edit_set_get_time_callback (EDateEdit *dedit,
+ EDateEditGetTimeCallback cb,
+ gpointer data,
+ GtkDestroyNotify destroy)
+{
+ EDateEditPrivate *priv;
+
+ g_return_if_fail (E_IS_DATE_EDIT (dedit));
+
+ priv = dedit->priv;
+
+ if (priv->time_callback_data && priv->time_callback_destroy)
+ (*priv->time_callback_destroy) (priv->time_callback_data);
+
+ priv->time_callback = cb;
+ priv->time_callback_data = data;
+ priv->time_callback_destroy = destroy;
+
+}
+
diff --git a/widgets/misc/e-dateedit.h b/widgets/misc/e-dateedit.h
index 87a40b8d10..022cf1fd5f 100644
--- a/widgets/misc/e-dateedit.h
+++ b/widgets/misc/e-dateedit.h
@@ -56,11 +56,15 @@ BEGIN_GNOME_DECLS
#define E_IS_DATE_EDIT(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_DATE_EDIT))
#define E_IS_DATE_EDIT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_DATE_EDIT))
-
typedef struct _EDateEdit EDateEdit;
typedef struct _EDateEditPrivate EDateEditPrivate;
typedef struct _EDateEditClass EDateEditClass;
+/* The type of the callback function optionally used to get the current time.
+ */
+typedef struct tm (*EDateEditGetTimeCallback) (EDateEdit *dedit,
+ gpointer data);
+
struct _EDateEdit {
GtkHBox hbox;
@@ -91,7 +95,7 @@ void e_date_edit_set_time (EDateEdit *dedit,
/* This returns the last valid date set, without the time. It returns TRUE
if a date is set, or FALSE if the date is set to 'None' and this is
- permitted via e_date_edit_set_allow_no_date_set. */
+ permitted via e_date_edit_set_allow_no_date_set. (Month is 1 - 12). */
gboolean e_date_edit_get_date (EDateEdit *dedit,
gint *year,
gint *month,
@@ -150,6 +154,14 @@ void e_date_edit_set_time_popup_range (EDateEdit *dedit,
gint lower_hour,
gint upper_hour);
+/* Sets a callback to use to get the current time. This is useful if the
+ application needs to use its own timezone data rather than rely on the
+ Unix timezone. */
+void e_date_edit_set_get_time_callback (EDateEdit *dedit,
+ EDateEditGetTimeCallback cb,
+ gpointer data,
+ GtkDestroyNotify destroy);
+
END_GNOME_DECLS
#endif