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 GtkWidget
*new_hour_line
;
74 cairo_surface_t
*pic1
;
75 gboolean first
= FALSE
;
77 debug_print("build_line [%d,%d] %dx%d %s\n",
78 start_x
, start_y
, width
, height
, hour_line
? "widget" : "no widget");
81 scaled = gdk_pixbuf_scale_simple (pix, w, h, GDK_INTERP_BILINEAR);
84 pic1
= cairo_image_surface_create(CAIRO_FORMAT_A1
, width
, height
);
85 cr
= cairo_create(pic1
);
87 if (hour_line
== NULL
) {
90 gdk_cairo_set_source_pixbuf(cr
, gtk_image_get_pixbuf(GTK_IMAGE(hour_line
)), 0, 0);
94 cairo_set_source_rgb(cr
,
95 (double)line_color
->red
/255,
96 (double)line_color
->green
/255,
97 (double)line_color
->blue
/255);
98 cairo_rectangle(cr
, start_x
, start_y
, width
, height
);
101 cairo_rectangle(cr
, start_x
, start_y
, width
, height
);
107 new_hour_line
= gtk_image_new_from_surface(pic1
);
108 cairo_surface_destroy(pic1
);
109 return(new_hour_line
);
112 /* move one day forward or backward */
113 void orage_move_day(struct tm
*t
, int day
)
115 guint monthdays
[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
118 if (((t
->tm_year
%4) == 0)
119 && (((t
->tm_year
%100) != 0) || ((t
->tm_year
%400) == 0)))
120 ++monthdays
[1]; /* leap year, february has 29 days */
122 t
->tm_mday
+= day
; /* may be negative */
123 if (t
->tm_mday
== 0) { /* we went to previous month */
124 if (--t
->tm_mon
== -1) { /* previous year */
128 t
->tm_mday
= monthdays
[t
->tm_mon
];
130 else if (t
->tm_mday
> (monthdays
[t
->tm_mon
])) { /* next month */
131 if (++t
->tm_mon
== 12) {
144 gint
orage_days_between(struct tm
*t1
, struct tm
*t2
)
148 g_t1
= g_date_new_dmy(t1
->tm_mday
, t1
->tm_mon
, t1
->tm_year
);
149 g_t2
= g_date_new_dmy(t2
->tm_mday
, t2
->tm_mon
, t2
->tm_year
);
150 dd
= g_date_days_between(g_t1
, g_t2
);
156 gint
vcal_view_set_calendar_page(GtkWidget
*to_show
, GCallback cb
, gpointer data
)
158 SummaryView
*summaryview
= NULL
;
160 if (mainwindow_get_mainwindow()) {
161 summaryview
= mainwindow_get_mainwindow()->summaryview
;
162 gtk_container_add(GTK_CONTAINER(summaryview
->mainwidget_book
),
164 gtk_notebook_set_current_page(GTK_NOTEBOOK(summaryview
->mainwidget_book
),
165 gtk_notebook_page_num(GTK_NOTEBOOK(summaryview
->mainwidget_book
),
167 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
168 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
169 selsig
= g_signal_connect(G_OBJECT(summaryview
->ctree
), "tree_select_row",
170 G_CALLBACK(cb
), data
);
175 void vcal_view_set_summary_page(GtkWidget
*to_remove
, guint selsig
)
177 SummaryView
*summaryview
= NULL
;
178 if (mainwindow_get_mainwindow()) {
179 summaryview
= mainwindow_get_mainwindow()->summaryview
;
181 g_signal_handler_disconnect(G_OBJECT(summaryview
->ctree
), selsig
);
182 gtk_container_remove(GTK_CONTAINER(summaryview
->mainwidget_book
),
184 gtk_notebook_set_current_page(GTK_NOTEBOOK(summaryview
->mainwidget_book
),
185 gtk_notebook_page_num(GTK_NOTEBOOK(summaryview
->mainwidget_book
),
186 summaryview
->scrolledwin
));
187 main_window_set_menu_sensitive(mainwindow_get_mainwindow());
188 toolbar_main_set_sensitive(mainwindow_get_mainwindow());
193 void vcal_view_select_event (const gchar
*uid
, FolderItem
*item
, gboolean edit
,
194 GCallback block_cb
, gpointer block_data
)
197 VCalEvent
*event
= NULL
;
198 event
= vcal_manager_load_event(uid
);
200 vcal_meeting_create(event
);
201 vcal_manager_free_event(event
);
204 SummaryView
*summaryview
= NULL
;
205 if (mainwindow_get_mainwindow()) {
206 MsgInfo
*info
= folder_item_get_msginfo_by_msgid(item
, uid
);
208 summaryview
= mainwindow_get_mainwindow()->summaryview
;
209 g_signal_handlers_block_by_func(G_OBJECT(summaryview
->ctree
),
210 G_CALLBACK(block_cb
), block_data
);
211 summary_select_by_msgnum(summaryview
, info
->msgnum
, TRUE
);
212 procmsg_msginfo_free(&info
);
213 g_signal_handlers_unblock_by_func(G_OBJECT(summaryview
->ctree
),
214 G_CALLBACK(block_cb
), block_data
);
220 void vcal_view_create_popup_menus(gpointer data
,
221 GtkWidget
**view_menu
,
222 GtkWidget
**event_menu
, GtkActionGroup
**event_group
,
223 GtkUIManager
**ui_manager
)
225 *ui_manager
= gtk_ui_manager_new();
226 *event_group
= cm_menu_create_action_group_full(*ui_manager
,"VcalViewEvent", view_event_popup_entries
,
227 G_N_ELEMENTS(view_event_popup_entries
), (gpointer
)data
);
229 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/", "Menus", "Menus", GTK_UI_MANAGER_MENUBAR
)
230 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus", "VcalView", "VcalViewEvent", GTK_UI_MANAGER_MENU
)
231 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus/VcalView", "CreateMeeting", "VcalViewEvent/CreateMeeting", GTK_UI_MANAGER_MENUITEM
)
232 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus/VcalView", "Separator1", "VcalViewEvent/---", GTK_UI_MANAGER_SEPARATOR
)
233 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus/VcalView", "GoToday", "VcalViewEvent/GoToday", GTK_UI_MANAGER_MENUITEM
)
235 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus", "VcalViewEvent", "VcalViewEvent", GTK_UI_MANAGER_MENU
)
236 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus/VcalViewEvent", "EditMeeting", "VcalViewEvent/EditMeeting", GTK_UI_MANAGER_MENUITEM
)
237 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus/VcalViewEvent", "CancelMeeting", "VcalViewEvent/CancelMeeting", GTK_UI_MANAGER_MENUITEM
)
238 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus/VcalViewEvent", "Separator1", "VcalViewEvent/---", GTK_UI_MANAGER_SEPARATOR
)
239 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus/VcalViewEvent", "CreateMeeting", "VcalViewEvent/CreateMeeting", GTK_UI_MANAGER_MENUITEM
)
240 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus/VcalViewEvent", "Separator2", "VcalViewEvent/---", GTK_UI_MANAGER_SEPARATOR
)
241 MENUITEM_ADDUI_MANAGER(*ui_manager
, "/Menus/VcalViewEvent", "GoToday", "VcalViewEvent/GoToday", GTK_UI_MANAGER_MENUITEM
)
243 *view_menu
= gtk_menu_item_get_submenu(GTK_MENU_ITEM(
244 gtk_ui_manager_get_widget(*ui_manager
, "/Menus/VcalView")) );
245 *event_menu
= gtk_menu_item_get_submenu(GTK_MENU_ITEM(
246 gtk_ui_manager_get_widget(*ui_manager
, "/Menus/VcalViewEvent")) );
249 static void view_new_meeting_cb (GtkAction
*action
,
252 gpointer data_i
= g_object_get_data(G_OBJECT(user_data
), "menu_data_i");
253 gpointer data_s
= g_object_get_data(G_OBJECT(user_data
), "menu_data_s");
254 gpointer win
= g_object_get_data(G_OBJECT(user_data
), "menu_win");
255 void (*cb
)(gpointer win
, gpointer data_i
, gpointer data_s
) =
256 g_object_get_data(G_OBJECT(user_data
), "new_meeting_cb");
258 cb(win
, data_i
, data_s
);
260 static void view_edit_meeting_cb (GtkAction
*action
,
263 gpointer data_i
= g_object_get_data(G_OBJECT(user_data
), "menu_data_i");
264 gpointer data_s
= g_object_get_data(G_OBJECT(user_data
), "menu_data_s");
265 gpointer win
= g_object_get_data(G_OBJECT(user_data
), "menu_win");
266 void (*cb
)(gpointer win
, gpointer data_i
, gpointer data_s
) =
267 g_object_get_data(G_OBJECT(user_data
), "edit_meeting_cb");
269 cb(win
, data_i
, data_s
);
271 static void view_cancel_meeting_cb (GtkAction
*action
,
274 gpointer data_i
= g_object_get_data(G_OBJECT(user_data
), "menu_data_i");
275 gpointer data_s
= g_object_get_data(G_OBJECT(user_data
), "menu_data_s");
276 gpointer win
= g_object_get_data(G_OBJECT(user_data
), "menu_win");
277 void (*cb
)(gpointer win
, gpointer data_i
, gpointer data_s
) =
278 g_object_get_data(G_OBJECT(user_data
), "cancel_meeting_cb");
280 cb(win
, data_i
, data_s
);
282 static void view_go_today_cb (GtkAction
*action
,
285 gpointer data_i
= g_object_get_data(G_OBJECT(user_data
), "menu_data_i");
286 gpointer data_s
= g_object_get_data(G_OBJECT(user_data
), "menu_data_s");
287 gpointer win
= g_object_get_data(G_OBJECT(user_data
), "menu_win");
288 void (*cb
)(gpointer win
, gpointer data_i
, gpointer data_s
) =
289 g_object_get_data(G_OBJECT(user_data
), "go_today_cb");
291 cb(win
, data_i
, data_s
);