aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc/e-cell-date-edit.c
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 /widgets/misc/e-cell-date-edit.c
parent0e27010e0b193b787e93cbf50c08a6d477e33dee (diff)
downloadgsoc2013-evolution-bacd3a85a434032316b3e63b95282175ce2b0659.tar.gz
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
Diffstat (limited to 'widgets/misc/e-cell-date-edit.c')
-rw-r--r--widgets/misc/e-cell-date-edit.c57
1 files changed, 46 insertions, 11 deletions
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;
+}
+
+