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>
35 #include <glib/gprintf.h>
36 #include <gdk/gdkkeysyms.h>
40 #include "summaryview.h"
41 #include "vcalendar.h"
42 #include "vcal_folder.h"
43 #include "vcal_prefs.h"
44 #include "vcal_manager.h"
45 #include "vcal_meeting_gtk.h"
49 static void view_new_meeting_cb (GtkAction *action,
51 static void view_edit_meeting_cb (GtkAction *action,
53 static void view_cancel_meeting_cb (GtkAction *action,
55 static void view_go_today_cb (GtkAction *action,
58 static GtkActionEntry view_event_popup_entries[] =
60 {"VcalViewEvent", NULL, "VcalViewEvent", NULL, NULL, NULL },
61 {"VcalViewEvent/EditMeeting", NULL, N_("_Edit this meeting..."), NULL, NULL, G_CALLBACK(view_edit_meeting_cb) },
62 {"VcalViewEvent/CancelMeeting", NULL, N_("_Cancel this meeting..."), NULL, NULL, G_CALLBACK(view_cancel_meeting_cb) },
63 {"VcalViewEvent/---", NULL, "---", NULL, NULL, NULL },
64 {"VcalViewEvent/CreateMeeting", NULL, N_("_Create new meeting..."), NULL, NULL, G_CALLBACK(view_new_meeting_cb) },
66 {"VcalViewEvent/GoToday", NULL, N_("_Go to today"), NULL, NULL, G_CALLBACK(view_go_today_cb) },
69 GtkWidget *build_line(gint start_x, gint start_y
70 , gint width, gint height, GtkWidget *hour_line, GdkColor *line_color)
72 GdkColormap *pic1_cmap;
76 GtkWidget *new_hour_line;
78 gboolean first = FALSE;
82 scaled = gdk_pixbuf_scale_simple (pix, w, h, GDK_INTERP_BILINEAR);
85 pic1_cmap = gdk_colormap_get_system();
86 pic1_vis = gdk_colormap_get_visual(pic1_cmap);
87 depth = gdk_visual_get_depth(pic1_vis);
88 if (hour_line == NULL) {
89 pic1 = gdk_pixmap_new(NULL, width, height, depth);
90 gdk_drawable_set_colormap(pic1, pic1_cmap);
94 gtk_image_get_pixmap(GTK_IMAGE(hour_line), &pic1, NULL);
95 pic1_gc = gdk_gc_new(pic1);
97 gdk_gc_set_foreground(pic1_gc, line_color);
98 gdk_draw_rectangle(pic1, pic1_gc, TRUE, start_x, start_y, width, height);
101 gdk_draw_rectangle(pic1, pic1_gc, TRUE, start_x, start_y, width, height);
104 new_hour_line = gtk_image_new_from_pixmap(pic1, NULL);
105 g_object_unref(pic1_gc);
106 g_object_unref(pic1);
107 return(new_hour_line);
110 /* move one day forward or backward */
111 void orage_move_day(struct tm *t, int day)
113 guint monthdays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
116 if (((t->tm_year%4) == 0)
117 && (((t->tm_year%100) != 0) || ((t->tm_year%400) == 0)))
118 ++monthdays[1]; /* leap year, february has 29 days */
120 t->tm_mday += day; /* may be negative */
121 if (t->tm_mday == 0) { /* we went to previous month */
122 if (--t->tm_mon == -1) { /* previous year */
126 t->tm_mday = monthdays[t->tm_mon];
128 else if (t->tm_mday > (monthdays[t->tm_mon])) { /* next month */
129 if (++t->tm_mon == 12) {
142 gint orage_days_between(struct tm *t1, struct tm *t2)
146 g_t1 = g_date_new_dmy(t1->tm_mday, t1->tm_mon, t1->tm_year);
147 g_t2 = g_date_new_dmy(t2->tm_mday, t2->tm_mon, t2->tm_year);
148 dd = g_date_days_between(g_t1, g_t2);
154 gint vcal_view_set_calendar_page(GtkWidget *to_show, GCallback cb, gpointer data)
156 SummaryView *summaryview = NULL;
158 if (mainwindow_get_mainwindow()) {
159 summaryview = mainwindow_get_mainwindow()->summaryview;
160 gtk_container_add(GTK_CONTAINER(summaryview->mainwidget_book),
162 gtk_notebook_set_current_page(GTK_NOTEBOOK(summaryview->mainwidget_book),
163 gtk_notebook_page_num(GTK_NOTEBOOK(summaryview->mainwidget_book),
165 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
166 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
167 selsig = g_signal_connect(G_OBJECT(summaryview->ctree), "tree_select_row",
168 G_CALLBACK(cb), data);
173 void vcal_view_set_summary_page(GtkWidget *to_remove, guint selsig)
175 SummaryView *summaryview = NULL;
176 if (mainwindow_get_mainwindow()) {
177 summaryview = mainwindow_get_mainwindow()->summaryview;
179 g_signal_handler_disconnect(G_OBJECT(summaryview->ctree), selsig);
180 gtk_container_remove(GTK_CONTAINER(summaryview->mainwidget_book),
182 gtk_notebook_set_current_page(GTK_NOTEBOOK(summaryview->mainwidget_book),
183 gtk_notebook_page_num(GTK_NOTEBOOK(summaryview->mainwidget_book),
184 summaryview->scrolledwin));
185 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
186 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
191 void vcal_view_select_event (const gchar *uid, FolderItem *item, gboolean edit,
192 GCallback block_cb, gpointer block_data)
195 VCalEvent *event = NULL;
196 event = vcal_manager_load_event(uid);
198 vcal_meeting_create(event);
199 vcal_manager_free_event(event);
202 SummaryView *summaryview = NULL;
203 if (mainwindow_get_mainwindow()) {
204 MsgInfo *info = folder_item_get_msginfo_by_msgid(item, uid);
206 summaryview = mainwindow_get_mainwindow()->summaryview;
207 g_signal_handlers_block_by_func(G_OBJECT(summaryview->ctree),
208 G_CALLBACK(block_cb), block_data);
209 summary_select_by_msgnum(summaryview, info->msgnum, TRUE);
210 procmsg_msginfo_free(&info);
211 g_signal_handlers_unblock_by_func(G_OBJECT(summaryview->ctree),
212 G_CALLBACK(block_cb), block_data);
218 void vcal_view_create_popup_menus(gpointer data,
219 GtkWidget **view_menu,
220 GtkWidget **event_menu, GtkActionGroup **event_group,
221 GtkUIManager **ui_manager)
223 *ui_manager = gtk_ui_manager_new();
224 *event_group = cm_menu_create_action_group_full(*ui_manager,"VcalViewEvent", view_event_popup_entries,
225 G_N_ELEMENTS(view_event_popup_entries), (gpointer)data);
227 MENUITEM_ADDUI_MANAGER(*ui_manager, "/", "Menus", "Menus", GTK_UI_MANAGER_MENUBAR)
228 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus", "VcalView", "VcalViewEvent", GTK_UI_MANAGER_MENU)
229 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalView", "CreateMeeting", "VcalViewEvent/CreateMeeting", GTK_UI_MANAGER_MENUITEM)
230 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalView", "Separator1", "VcalViewEvent/---", GTK_UI_MANAGER_SEPARATOR)
231 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalView", "GoToday", "VcalViewEvent/GoToday", GTK_UI_MANAGER_MENUITEM)
233 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus", "VcalViewEvent", "VcalViewEvent", GTK_UI_MANAGER_MENU)
234 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "EditMeeting", "VcalViewEvent/EditMeeting", GTK_UI_MANAGER_MENUITEM)
235 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "CancelMeeting", "VcalViewEvent/CancelMeeting", GTK_UI_MANAGER_MENUITEM)
236 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "Separator1", "VcalViewEvent/---", GTK_UI_MANAGER_SEPARATOR)
237 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "CreateMeeting", "VcalViewEvent/CreateMeeting", GTK_UI_MANAGER_MENUITEM)
238 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "Separator2", "VcalViewEvent/---", GTK_UI_MANAGER_SEPARATOR)
239 MENUITEM_ADDUI_MANAGER(*ui_manager, "/Menus/VcalViewEvent", "GoToday", "VcalViewEvent/GoToday", GTK_UI_MANAGER_MENUITEM)
241 *view_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
242 gtk_ui_manager_get_widget(*ui_manager, "/Menus/VcalView")) );
243 *event_menu= gtk_menu_item_get_submenu(GTK_MENU_ITEM(
244 gtk_ui_manager_get_widget(*ui_manager, "/Menus/VcalViewEvent")) );
247 static void view_new_meeting_cb (GtkAction *action,
250 gpointer data_i = g_object_get_data(G_OBJECT(user_data), "menu_data_i");
251 gpointer data_s = g_object_get_data(G_OBJECT(user_data), "menu_data_s");
252 gpointer win = g_object_get_data(G_OBJECT(user_data), "menu_win");
253 void (*cb)(gpointer win, gpointer data_i, gpointer data_s) =
254 g_object_get_data(G_OBJECT(user_data), "new_meeting_cb");
256 cb(win, data_i, data_s);
258 static void view_edit_meeting_cb (GtkAction *action,
261 gpointer data_i = g_object_get_data(G_OBJECT(user_data), "menu_data_i");
262 gpointer data_s = g_object_get_data(G_OBJECT(user_data), "menu_data_s");
263 gpointer win = g_object_get_data(G_OBJECT(user_data), "menu_win");
264 void (*cb)(gpointer win, gpointer data_i, gpointer data_s) =
265 g_object_get_data(G_OBJECT(user_data), "edit_meeting_cb");
267 cb(win, data_i, data_s);
269 static void view_cancel_meeting_cb (GtkAction *action,
272 gpointer data_i = g_object_get_data(G_OBJECT(user_data), "menu_data_i");
273 gpointer data_s = g_object_get_data(G_OBJECT(user_data), "menu_data_s");
274 gpointer win = g_object_get_data(G_OBJECT(user_data), "menu_win");
275 void (*cb)(gpointer win, gpointer data_i, gpointer data_s) =
276 g_object_get_data(G_OBJECT(user_data), "cancel_meeting_cb");
278 cb(win, data_i, data_s);
280 static void view_go_today_cb (GtkAction *action,
283 gpointer data_i = g_object_get_data(G_OBJECT(user_data), "menu_data_i");
284 gpointer data_s = g_object_get_data(G_OBJECT(user_data), "menu_data_s");
285 gpointer win = g_object_get_data(G_OBJECT(user_data), "menu_win");
286 void (*cb)(gpointer win, gpointer data_i, gpointer data_s) =
287 g_object_get_data(G_OBJECT(user_data), "go_today_cb");
289 cb(win, data_i, data_s);