2
* Go to date dialog for Evolution
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) version 3.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with the program; if not, see <http://www.gnu.org/licenses/>
19
* Federico Mena <federico@ximian.com>
20
* JP Rosevear <jpr@ximian.com>
22
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
23
* Copyright (C) 1998 Red Hat, Inc.
33
#include "goto-dialog.h"
35
#include "e-util/e-util.h"
36
#include "e-util/e-util-private.h"
37
#include "calendar/gui/calendar-config.h"
38
#include "calendar/gui/tag-calendar.h"
45
GtkWidget *month_combobox;
57
static GoToDialog *dlg = NULL;
59
/* Callback used when the year adjustment is changed */
61
year_changed (GtkAdjustment *adj, gpointer data)
63
GtkSpinButton *spin_button;
64
GoToDialog *dlg = data;
66
spin_button = GTK_SPIN_BUTTON (dlg->year);
67
dlg->year_val = gtk_spin_button_get_value_as_int (spin_button);
69
e_calendar_item_set_first_month (
70
dlg->ecal->calitem, dlg->year_val, dlg->month_val);
73
/* Callback used when a month button is toggled */
75
month_changed (GtkToggleButton *toggle, gpointer data)
77
GtkComboBox *combo_box;
78
GoToDialog *dlg = data;
80
combo_box = GTK_COMBO_BOX (dlg->month_combobox);
81
dlg->month_val = gtk_combo_box_get_active (combo_box);
83
e_calendar_item_set_first_month (
84
dlg->ecal->calitem, dlg->year_val, dlg->month_val);
88
ecal_date_range_changed (ECalendarItem *calitem, gpointer user_data)
90
GoToDialog *dlg = user_data;
94
model = gnome_calendar_get_model (dlg->gcal);
95
client = e_cal_model_get_default_client (model);
97
tag_calendar_by_client (dlg->ecal, client);
100
/* Event handler for day groups in the month item. A button press makes
101
* the calendar jump to the selected day and destroys the Go-to dialog box. */
103
ecal_event (ECalendarItem *calitem, gpointer user_data)
105
GoToDialog *dlg = user_data;
106
GDate start_date, end_date;
108
struct icaltimetype tt = icaltime_null_time ();
109
icaltimezone *timezone;
112
model = gnome_calendar_get_model (dlg->gcal);
113
e_calendar_item_get_selection (calitem, &start_date, &end_date);
114
timezone = e_cal_model_get_timezone (model);
116
tt.year = g_date_get_year (&start_date);
117
tt.month = g_date_get_month (&start_date);
118
tt.day = g_date_get_day (&start_date);
120
et = icaltime_as_timet_with_zone (tt, timezone);
122
gnome_calendar_goto (dlg->gcal, et);
124
gtk_dialog_response (GTK_DIALOG (dlg->dialog), GTK_RESPONSE_NONE);
127
/* Returns the current time, for the ECalendarItem. */
129
get_current_time (ECalendarItem *calitem, gpointer data)
132
struct tm tmp_tm = { 0 };
133
struct icaltimetype tt;
135
/* Get the current timezone. */
136
zone = calendar_config_get_icaltimezone ();
138
tt = icaltime_from_timet_with_zone (time (NULL), FALSE, zone);
140
/* Now copy it to the struct tm and return it. */
141
tmp_tm.tm_year = tt.year - 1900;
142
tmp_tm.tm_mon = tt.month - 1;
143
tmp_tm.tm_mday = tt.day;
144
tmp_tm.tm_hour = tt.hour;
145
tmp_tm.tm_min = tt.minute;
146
tmp_tm.tm_sec = tt.second;
147
tmp_tm.tm_isdst = -1;
152
/* Creates the ecalendar */
154
create_ecal (GoToDialog *dlg)
156
ECalendarItem *calitem;
158
dlg->ecal = E_CALENDAR (e_calendar_new ());
159
calitem = dlg->ecal->calitem;
161
gnome_canvas_item_set (GNOME_CANVAS_ITEM (calitem),
162
"move_selection_when_moving", FALSE,
164
e_calendar_item_set_display_popup (calitem, FALSE);
165
gtk_widget_show (GTK_WIDGET (dlg->ecal));
166
gtk_box_pack_start (GTK_BOX (dlg->vbox), GTK_WIDGET (dlg->ecal), TRUE, TRUE, 0);
168
e_calendar_item_set_first_month (calitem, dlg->year_val, dlg->month_val);
169
e_calendar_item_set_get_time_callback (calitem,
173
ecal_date_range_changed (calitem, dlg);
177
goto_today (GoToDialog *dlg)
179
gnome_calendar_goto_today (dlg->gcal);
182
/* Gets the widgets from the XML file and returns if they are all available. */
184
get_widgets (GoToDialog *dlg)
186
#define GW(name) e_builder_get_widget (dlg->builder, name)
188
dlg->dialog = GW ("goto-dialog");
190
dlg->month_combobox = GW ("month-combobox");
191
dlg->year = GW ("year");
192
dlg->vbox = GW ("vbox");
197
&& dlg->month_combobox
203
goto_dialog_init_widgets (GoToDialog *dlg)
208
dlg->month_combobox, "changed",
209
G_CALLBACK (month_changed), dlg);
211
adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (dlg->year));
213
adj, "value_changed",
214
G_CALLBACK (year_changed), dlg);
217
dlg->ecal->calitem, "date_range_changed",
218
G_CALLBACK (ecal_date_range_changed), dlg);
220
dlg->ecal->calitem, "selection_changed",
221
G_CALLBACK (ecal_event), dlg);
224
/* Creates a "goto date" dialog and runs it */
226
goto_dialog (GtkWindow *parent, GnomeCalendar *gcal)
230
struct icaltimetype tt;
231
icaltimezone *timezone;
239
dlg = g_new0 (GoToDialog, 1);
241
/* Load the content widgets */
242
dlg->builder = gtk_builder_new ();
243
e_load_ui_builder_definition (dlg->builder, "goto-dialog.ui");
245
if (!get_widgets (dlg)) {
246
g_message ("goto_dialog(): Could not find all widgets in the XML file!");
252
model = gnome_calendar_get_model (gcal);
253
timezone = e_cal_model_get_timezone (model);
254
e_cal_model_get_time_range (model, &start_time, NULL);
255
tt = icaltime_from_timet_with_zone (start_time, FALSE, timezone);
256
dlg->year_val = tt.year;
257
dlg->month_val = tt.month - 1;
258
dlg->day_val = tt.day;
260
gtk_combo_box_set_active (GTK_COMBO_BOX (dlg->month_combobox), dlg->month_val);
261
gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->year), dlg->year_val);
265
goto_dialog_init_widgets (dlg);
267
gtk_window_set_transient_for (GTK_WINDOW (dlg->dialog), parent);
269
/* set initial selection to current day */
271
dlg->ecal->calitem->selection_set = TRUE;
272
dlg->ecal->calitem->selection_start_month_offset = 0;
273
dlg->ecal->calitem->selection_start_day = tt.day;
274
dlg->ecal->calitem->selection_end_month_offset = 0;
275
dlg->ecal->calitem->selection_end_day = tt.day;
277
/* Set week_start_day. Convert it to 0 (Mon) to 6 (Sun), which is what we use. */
278
week_start_day = e_cal_model_get_week_start_day (model);
279
dlg->ecal->calitem->week_start_day = (week_start_day + 6) % 7;
281
gnome_canvas_item_grab_focus (GNOME_CANVAS_ITEM (dlg->ecal->calitem));
283
b = gtk_dialog_run (GTK_DIALOG (dlg->dialog));
284
gtk_widget_destroy (dlg->dialog);
289
g_object_unref (dlg->builder);