2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
4 * Copyright (c) 2007-2008 Juha Kautto (juha at xfce.org)
5 * Copyright (c) 2008 Colin Leroy (colin@colino.net)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "claws-features.h"
29 #include <glib/gi18n.h>
36 #include <glib/gprintf.h>
37 #include <gdk/gdkkeysyms.h>
41 #include "summaryview.h"
42 #include "vcalendar.h"
43 #include "vcal_folder.h"
44 #include "vcal_prefs.h"
45 #include "vcal_manager.h"
46 #include "vcal_meeting_gtk.h"
50 static void view_new_meeting_cb (GtkAction *action,
52 static void view_edit_meeting_cb (GtkAction *action,
54 static void view_cancel_meeting_cb (GtkAction *action,
56 static void view_go_today_cb (GtkAction *action,
59 static GtkActionEntry view_event_popup_entries[] =
61 {"VcalViewEvent", NULL, "VcalViewEvent", NULL, NULL, NULL },
62 {"VcalViewEvent/EditMeeting", NULL, N_("_Edit this meeting..."), NULL, NULL, G_CALLBACK(view_edit_meeting_cb) },
63 {"VcalViewEvent/CancelMeeting", NULL, N_("_Cancel this meeting..."), NULL, NULL, G_CALLBACK(view_cancel_meeting_cb) },
64 {"VcalViewEvent/---", NULL, "---", NULL, NULL, NULL },
65 {"VcalViewEvent/CreateMeeting", NULL, N_("_Create new meeting..."), NULL, NULL, G_CALLBACK(view_new_meeting_cb) },
67 {"VcalViewEvent/GoToday", NULL, N_("_Go to today"), NULL, NULL, G_CALLBACK(view_go_today_cb) },
70 GtkWidget *build_line(gint start_x, gint start_y
71 , gint width, gint height, GtkWidget *hour_line, GdkColor *line_color)
73 GdkColormap *pic1_cmap;
77 GtkWidget *new_hour_line;
79 gboolean first = FALSE;
83 scaled = gdk_pixbuf_scale_simple (pix, w, h, GDK_INTERP_BILINEAR);
86 pic1_cmap = gdk_colormap_get_system();
87 pic1_vis = gdk_colormap_get_visual(pic1_cmap);
88 depth = gdk_visual_get_depth(pic1_vis);
89 if (hour_line == NULL) {
90 pic1 = gdk_pixmap_new(NULL, width, height, depth);
91 gdk_drawable_set_colormap(pic1, pic1_cmap);
95 gtk_image_get_pixmap(GTK_IMAGE(hour_line), &pic1, NULL);
96 pic1_gc = gdk_gc_new(pic1);
98 gdk_gc_set_foreground(pic1_gc, line_color);
99 gdk_draw_rectangle(pic1, pic1_gc, TRUE, start_x, start_y, width, height);
102 gdk_draw_rectangle(pic1, pic1_gc, TRUE, start_x, start_y, width, height);
105 new_hour_line = gtk_image_new_from_pixmap(pic1, NULL);
106 g_object_unref(pic1_gc);
107 g_object_unref(pic1);
108 return(new_hour_line);
111 /* move one day forward or backward */
112 void orage_move_day(struct tm *t, int day)
114 guint monthdays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
117 if (((t->tm_year%4) == 0)
118 && (((t->tm_year%100) != 0) || ((t->tm_year%400) == 0)))
119 ++monthdays[1]; /* leap year, february has 29 days */
121 t->tm_mday += day; /* may be negative */
122 if (t->tm_mday == 0) { /* we went to previous month */
123 if (--t->tm_mon == -1) { /* previous year */
127 t->tm_mday = monthdays[t->tm_mon];
129 else if (t->tm_mday > (monthdays[t->tm_mon])) { /* next month */
130 if (++t->tm_mon == 12) {
143 gint orage_days_between(struct tm *t1, struct tm *t2)
147 g_t1 = g_date_new_dmy(t1->tm_mday, t1->tm_mon, t1->tm_year);
148 g_t2 = g_date_new_dmy(t2->tm_mday, t2->tm_mon, t2->tm_year);
149 dd = g_date_days_between(g_t1, g_t2);
155 gint vcal_view_set_calendar_page(GtkWidget *to_show, GCallback cb, gpointer data)
157 SummaryView *summaryview = NULL;
159 if (mainwindow_get_mainwindow()) {
160 summaryview = mainwindow_get_mainwindow()->summaryview;
161 gtk_container_add(GTK_CONTAINER(summaryview->mainwidget_book),
163 gtk_notebook_set_current_page(GTK_NOTEBOOK(summaryview->mainwidget_book),
164 gtk_notebook_page_num(GTK_NOTEBOOK(summaryview->mainwidget_book),
166 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
167 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
168 selsig = g_signal_connect(G_OBJECT(summaryview->ctree), "tree_select_row",
169 G_CALLBACK(cb), data);
174 void vcal_view_set_summary_page(GtkWidget *to_remove, guint selsig)
176 SummaryView *summaryview = NULL;
177 if (mainwindow_get_mainwindow()) {
178 summaryview = mainwindow_get_mainwindow()->summaryview;
180 g_signal_handler_disconnect(G_OBJECT(summaryview->ctree), selsig);
181 gtk_container_remove(GTK_CONTAINER(summaryview->mainwidget_book),
183 gtk_notebook_set_current_page(GTK_NOTEBOOK(summaryview->mainwidget_book),
184 gtk_notebook_page_num(GTK_NOTEBOOK(summaryview->mainwidget_book),
185 summaryview->scrolledwin));
186 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
187 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
192 void vcal_view_select_event (const gchar *uid, FolderItem *item, gboolean edit,
193 GCallback block_cb, gpointer block_data)
196 VCalEvent *event = NULL;
197 event = vcal_manager_load_event(uid);
199 vcal_meeting_create(event);
200 vcal_manager_free_event(event);
203 SummaryView *summaryview = NULL;
204 if (mainwindow_get_mainwindow()) {
205 MsgInfo *info = folder_item_get_msginfo_by_msgid(item, uid);
207 summaryview = mainwindow_get_mainwindow()->summaryview;
208 g_signal_handlers_block_by_func(G_OBJECT(summaryview->ctree),
209 G_CALLBACK(block_cb), block_data);
210 summary_select_by_msgnum(summaryview, info->msgnum, TRUE);
211 procmsg_msginfo_free(&info);
212 g_signal_handlers_unblock_by_func(G_OBJECT(summaryview->ctree),
213 G_CALLBACK(block_cb), block_data);
219 void vcal_view_create_popup_menus(gpointer data,
220 GtkWidget **view_menu,
221 GtkWidget **event_menu, GtkActionGroup **event_group,
222 GtkUIManager **ui_manager)
224 *ui_manager = gtk_ui_manager_new();
225 *event_group = cm_menu_create_action_group_full(*ui_manager,"VcalViewEvent", view_event_popup_entries,
226 G_N_ELEMENTS(view_event_popup_entries), (gpointer)data);
228 MENUITEM_ADDUI_MANAGER(*ui_manager, "/", "Menus", "Menus", GTK_UI_MANAGER_MENUBAR)
229 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus", "VcalView", "VcalViewEvent", GTK_UI_MANAGER_MENU)
230 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalView", "CreateMeeting", "VcalViewEvent/CreateMeeting", GTK_UI_MANAGER_MENUITEM)
231 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalView", "Separator1", "VcalViewEvent/---", GTK_UI_MANAGER_SEPARATOR)
232 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalView", "GoToday", "VcalViewEvent/GoToday", GTK_UI_MANAGER_MENUITEM)
234 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus", "VcalViewEvent", "VcalViewEvent", GTK_UI_MANAGER_MENU)
235 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "EditMeeting", "VcalViewEvent/EditMeeting", GTK_UI_MANAGER_MENUITEM)
236 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "CancelMeeting", "VcalViewEvent/CancelMeeting", GTK_UI_MANAGER_MENUITEM)
237 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "Separator1", "VcalViewEvent/---", GTK_UI_MANAGER_SEPARATOR)
238 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "CreateMeeting", "VcalViewEvent/CreateMeeting", GTK_UI_MANAGER_MENUITEM)
239 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "Separator2", "VcalViewEvent/---", GTK_UI_MANAGER_SEPARATOR)
240 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "GoToday", "VcalViewEvent/GoToday", GTK_UI_MANAGER_MENUITEM)
242 *view_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
243 gtk_ui_manager_get_widget(*ui_manager, "/Menus/VcalView")) );
244 *event_menu= gtk_menu_item_get_submenu(GTK_MENU_ITEM(
245 gtk_ui_manager_get_widget(*ui_manager, "/Menus/VcalViewEvent")) );
248 static void view_new_meeting_cb (GtkAction *action,
251 gpointer data_i = g_object_get_data(G_OBJECT(user_data), "menu_data_i");
252 gpointer data_s = g_object_get_data(G_OBJECT(user_data), "menu_data_s");
253 gpointer win = g_object_get_data(G_OBJECT(user_data), "menu_win");
254 void (*cb)(gpointer win, gpointer data_i, gpointer data_s) =
255 g_object_get_data(G_OBJECT(user_data), "new_meeting_cb");
257 cb(win, data_i, data_s);
259 static void view_edit_meeting_cb (GtkAction *action,
262 gpointer data_i = g_object_get_data(G_OBJECT(user_data), "menu_data_i");
263 gpointer data_s = g_object_get_data(G_OBJECT(user_data), "menu_data_s");
264 gpointer win = g_object_get_data(G_OBJECT(user_data), "menu_win");
265 void (*cb)(gpointer win, gpointer data_i, gpointer data_s) =
266 g_object_get_data(G_OBJECT(user_data), "edit_meeting_cb");
268 cb(win, data_i, data_s);
270 static void view_cancel_meeting_cb (GtkAction *action,
273 gpointer data_i = g_object_get_data(G_OBJECT(user_data), "menu_data_i");
274 gpointer data_s = g_object_get_data(G_OBJECT(user_data), "menu_data_s");
275 gpointer win = g_object_get_data(G_OBJECT(user_data), "menu_win");
276 void (*cb)(gpointer win, gpointer data_i, gpointer data_s) =
277 g_object_get_data(G_OBJECT(user_data), "cancel_meeting_cb");
279 cb(win, data_i, data_s);
281 static void view_go_today_cb (GtkAction *action,
284 gpointer data_i = g_object_get_data(G_OBJECT(user_data), "menu_data_i");
285 gpointer data_s = g_object_get_data(G_OBJECT(user_data), "menu_data_s");
286 gpointer win = g_object_get_data(G_OBJECT(user_data), "menu_win");
287 void (*cb)(gpointer win, gpointer data_i, gpointer data_s) =
288 g_object_get_data(G_OBJECT(user_data), "go_today_cb");
290 cb(win, data_i, data_s);