aboutsummaryrefslogtreecommitdiffstats
path: root/mail/em-folder-selector.c
blob: f31e06c78c598527e60f07ea86cba487531545bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 *  Authors: Jeffrey Stedfast <fejj@ximian.com>
 *
 *  Copyright 2003 Ximian, Inc. (www.ximian.com)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 *
 */


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>

#include <libgnome/gnome-i18n.h>

#include <gal/util/e-util.h>
#include <gal/widgets/e-gui-utils.h>

#include <gtk/gtkentry.h>
#include <gtk/gtkbox.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkscrolledwindow.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkstock.h>

#include <camel/camel-url.h>
#include <camel/camel-store.h>
#include <camel/camel-session.h>

#include "em-folder-tree.h"
#include "em-folder-selector.h"

#define d(x)


extern CamelSession *session;


static void em_folder_selector_class_init (EMFolderSelectorClass *klass);
static void em_folder_selector_init (EMFolderSelector *emfs);
static void em_folder_selector_destroy (GtkObject *obj);
static void em_folder_selector_finalize (GObject *obj);


static GtkDialogClass *parent_class = NULL;


GType
em_folder_selector_get_type (void)
{
    static GType type = 0;
    
    if (!type) {
        static const GTypeInfo info = {
            sizeof (EMFolderSelectorClass),
            NULL, /* base_class_init */
            NULL, /* base_class_finalize */
            (GClassInitFunc) em_folder_selector_class_init,
            NULL, /* class_finalize */
            NULL, /* class_data */
            sizeof (EMFolderSelector),
            0,    /* n_preallocs */
            (GInstanceInitFunc) em_folder_selector_init,
        };
        
        type = g_type_register_static (GTK_TYPE_DIALOG, "EMFolderSelector", &info, 0);
    }
    
    return type;
}

static void
em_folder_selector_class_init (EMFolderSelectorClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
    
    parent_class = g_type_class_ref (GTK_TYPE_DIALOG);
    
    object_class->finalize = em_folder_selector_finalize;
    gtk_object_class->destroy = em_folder_selector_destroy;
}

static void
em_folder_selector_init (EMFolderSelector *emfs)
{
    emfs->selected_path = NULL;
    emfs->selected_uri = NULL;
}

static void
em_folder_selector_destroy (GtkObject *obj)
{
    EMFolderSelector *emfs = (EMFolderSelector *) obj;
    EMFolderTreeModel *model;
    
    if (emfs->created_id != 0) {
        model = em_folder_tree_get_model (emfs->emft);
        g_signal_handler_disconnect (model, emfs->created_id);
        emfs->created_id = 0;
    }
    
    GTK_OBJECT_CLASS (parent_class)->destroy (obj);
}

static void
em_folder_selector_finalize (GObject *obj)
{
    EMFolderSelector *emfs = (EMFolderSelector *) obj;
    
    g_free (emfs->selected_path);
    g_free (emfs->selected_uri);
    g_free (emfs->created_uri);
    
    G_OBJECT_CLASS (parent_class)->finalize (obj);
}

static void
folder_created_cb (EMFolderTreeModel *model, const char *path, const char *uri, EMFolderSelector *emfs)
{
    CamelException ex;
    CamelStore *store;
    
    camel_exception_init (&ex);
    if (!(store = (CamelStore *) camel_session_get_service (session, uri, CAMEL_PROVIDER_STORE, &ex)))
        return;
    
    if (camel_store_folder_uri_equal (store, emfs->created_uri, uri)) {
        em_folder_tree_set_selected (emfs->emft, uri);
        g_signal_handler_disconnect (model, emfs->created_id);
        emfs->created_id = 0;
    }
    
    camel_object_unref (store);
}

static void
emfs_response (GtkWidget *dialog, int response, EMFolderSelector *emfs)
{
    EMFolderTreeModel *model;
    const char *path, *uri;
    EMFolderTree *emft;
    
    if (response != EM_FOLDER_SELECTOR_RESPONSE_NEW)
        return;
    
    model = em_folder_tree_get_model (emfs->emft);
    emft = (EMFolderTree *) em_folder_tree_new_with_model (model);
    dialog = em_folder_selector_create_new (emft, 0, _("Create New Folder"), _("Specify where to create the folder:"));
    gtk_window_set_transient_for ((GtkWindow *) dialog, (GtkWindow *) emfs);
    uri = em_folder_selector_get_selected_uri (emfs);
    em_folder_tree_set_selected (emft, uri);
    
    if (gtk_dialog_run ((GtkDialog *) dialog) == GTK_RESPONSE_OK) {
        uri = em_folder_selector_get_selected_uri ((EMFolderSelector *) dialog);
        path = em_folder_selector_get_selected_path ((EMFolderSelector *) dialog);
        
        g_free (emfs->created_uri);
        emfs->created_uri = g_strdup (uri);
        
        if (emfs->created_id == 0)
            emfs->created_id = g_signal_connect (model, "folder-added", G_CALLBACK (folder_created_cb), emfs);
        
        em_folder_tree_create_folder (emfs->emft, path, uri);
    }
    
    gtk_widget_destroy (dialog);
    
    g_signal_stop_emission_by_name (emfs, "response");
}

static void
emfs_create_name_changed (GtkEntry *entry, EMFolderSelector *emfs)
{
    const char *path, *text = NULL;
    gboolean active;
    
    if (emfs->name_entry->text_length > 0)
        text = gtk_entry_get_text (emfs->name_entry);
    
    path = em_folder_tree_get_selected_path (emfs->emft);

    active = text && path && !strchr (text, '/');
    
    gtk_dialog_set_response_sensitive ((GtkDialog *) emfs, GTK_RESPONSE_OK, active);
}

static void
folder_selected_cb (EMFolderTree *emft, const char *path, const char *uri, guint32 flags, EMFolderSelector *emfs)
{
    if (emfs->name_entry)
        emfs_create_name_changed (emfs->name_entry, emfs);
    else
        gtk_dialog_set_response_sensitive (GTK_DIALOG (emfs), GTK_RESPONSE_OK, TRUE);
}

static void
folder_activated_cb (EMFolderTree *emft, const char *path, const char *uri, EMFolderSelector *emfs)
{
    gtk_dialog_response ((GtkDialog *) emfs, GTK_RESPONSE_OK);
}

void
em_folder_selector_construct (EMFolderSelector *emfs, EMFolderTree *emft, guint32 flags, const char *title, const char *text, const char *oklabel)
{
    GtkWidget *label;
    
    gtk_window_set_modal (GTK_WINDOW (emfs), FALSE);
    gtk_window_set_default_size (GTK_WINDOW (emfs), 350, 300);
    gtk_window_set_title (GTK_WINDOW (emfs), title);
    gtk_container_set_border_width (GTK_CONTAINER (emfs), 6);
    
    gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (emfs)->vbox), 6);
    gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (emfs)->vbox), 6);
    
    emfs->flags = flags;
    if (flags & EM_FOLDER_SELECTOR_CAN_CREATE) {
        gtk_dialog_add_button (GTK_DIALOG (emfs), GTK_STOCK_NEW, EM_FOLDER_SELECTOR_RESPONSE_NEW);
        g_signal_connect (emfs, "response", G_CALLBACK (emfs_response), emfs);
    }
    
    gtk_dialog_add_buttons (GTK_DIALOG (emfs), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                oklabel?oklabel:GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
    
    gtk_dialog_set_response_sensitive (GTK_DIALOG (emfs), GTK_RESPONSE_OK, FALSE);
    gtk_dialog_set_default_response (GTK_DIALOG (emfs), GTK_RESPONSE_OK);
    
    emfs->emft = emft;
    gtk_widget_show ((GtkWidget *) emft);
    
    g_signal_connect (emfs->emft, "folder-selected", G_CALLBACK (folder_selected_cb), emfs);
    g_signal_connect (emfs->emft, "folder-activated", G_CALLBACK (folder_activated_cb), emfs);
    gtk_box_pack_end (GTK_BOX (GTK_DIALOG (emfs)->vbox), (GtkWidget *)emft, TRUE, TRUE, 6);
    
    if (text != NULL) {
        label = gtk_label_new (text);
        gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); 
        gtk_widget_show (label);
        
        gtk_box_pack_end (GTK_BOX (GTK_DIALOG (emfs)->vbox), label, FALSE, TRUE, 6);
    }
    
    gtk_widget_grab_focus ((GtkWidget *) emfs->emft);
}

GtkWidget *
em_folder_selector_new (EMFolderTree *emft, guint32 flags, const char *title, const char *text, const char *oklabel)
{
    EMFolderSelector *emfs;
    
    emfs = g_object_new (em_folder_selector_get_type (), NULL);
    em_folder_selector_construct (emfs, emft, flags, title, text, oklabel);
    
    return (GtkWidget *) emfs;
}


static void
emfs_create_name_activate (GtkEntry *entry, EMFolderSelector *emfs)
{
    if (emfs->name_entry->text_length > 0) {
        const char *path, *text;
        
        text = gtk_entry_get_text (emfs->name_entry);
        path = em_folder_tree_get_selected_path (emfs->emft);
        
        if (text && path && !strchr (text, '/'))
            g_signal_emit_by_name (emfs, "response", GTK_RESPONSE_OK);
    }
}

GtkWidget *
em_folder_selector_create_new (EMFolderTree *emft, guint32 flags, const char *title, const char *text)
{
    EMFolderSelector *emfs;
    GtkWidget *hbox, *w;
    
    /* remove the CREATE flag if it is there since that's the
     * whole purpose of this dialog */
    flags &= ~EM_FOLDER_SELECTOR_CAN_CREATE;
    
    emfs = g_object_new (em_folder_selector_get_type (), NULL);
    em_folder_selector_construct (emfs, emft, flags, title, text, _("Create"));
    em_folder_tree_set_excluded(emft, EMFT_EXCLUDE_NOINFERIORS);
    
    hbox = gtk_hbox_new (FALSE, 0);
    w = gtk_label_new_with_mnemonic (_("Folder _name:"));
    gtk_box_pack_start ((GtkBox *) hbox, w, FALSE, FALSE, 6);
    emfs->name_entry = (GtkEntry *) gtk_entry_new ();
    gtk_label_set_mnemonic_widget (GTK_LABEL (w), (GtkWidget *) emfs->name_entry);
    g_signal_connect (emfs->name_entry, "changed", G_CALLBACK (emfs_create_name_changed), emfs);
    g_signal_connect (emfs->name_entry, "activate", G_CALLBACK (emfs_create_name_activate), emfs);
    gtk_box_pack_start ((GtkBox *) hbox, (GtkWidget *) emfs->name_entry, TRUE, FALSE, 6);
    gtk_widget_show_all (hbox);
    
    gtk_box_pack_start ((GtkBox *) ((GtkDialog *) emfs)->vbox, hbox, FALSE, TRUE, 0);
    
    gtk_widget_grab_focus ((GtkWidget *) emfs->name_entry);
    
    return (GtkWidget *) emfs;
}


void
em_folder_selector_set_selected (EMFolderSelector *emfs, const char *uri)
{
    em_folder_tree_set_selected (emfs->emft, uri);
}

void
em_folder_selector_set_selected_list (EMFolderSelector *emfs, GList *list)
{
    em_folder_tree_set_selected_list (emfs->emft, list);
}

const char *
em_folder_selector_get_selected_uri (EMFolderSelector *emfs)
{
    const char *uri, *name;
    
    if (!(uri = em_folder_tree_get_selected_uri (emfs->emft))) {
        d(printf ("no selected folder?\n"));
        return NULL;
    }
    
    if (uri && emfs->name_entry) {
        CamelProvider *provider;
        CamelURL *url;
        char *newpath;
        
        provider = camel_provider_get(uri, NULL);
        
        name = gtk_entry_get_text (emfs->name_entry);
        
        url = camel_url_new (uri, NULL);
        if (provider && (provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH)) {
            if (url->fragment)
                newpath = g_strdup_printf ("%s/%s", url->fragment, name);
            else
                newpath = g_strdup (name);
            
            camel_url_set_fragment (url, newpath);
        } else {
            char *path;

            path = g_strdup_printf("%s/%s", (url->path == NULL || strcmp(url->path, "/") == 0) ? "":url->path, name);
            camel_url_set_path(url, path);
            if (path[0] == '/') {
                newpath = g_strdup(path+1);
                g_free(path);
            } else
                newpath = path;
        }
        
        g_free (emfs->selected_path);
        emfs->selected_path = newpath;
        
        g_free (emfs->selected_uri);
        emfs->selected_uri = camel_url_to_string (url, 0);
        
        camel_url_free (url);
        uri = emfs->selected_uri;
    }
    
    return uri;
}

GList *
em_folder_selector_get_selected_uris (EMFolderSelector *emfs)
{
    return em_folder_tree_get_selected_uris (emfs->emft);
}

GList *
em_folder_selector_get_selected_paths (EMFolderSelector *emfs)
{
    return em_folder_tree_get_selected_paths (emfs->emft);
}

const char *
em_folder_selector_get_selected_path (EMFolderSelector *emfs)
{
    const char *path;
    
    if (emfs->selected_path) {
        /* already did the work in a previous call */
        return emfs->selected_path;
    }
    
    if (!(path = em_folder_tree_get_selected_path (emfs->emft))) {
        d(printf ("no selected folder?\n"));
        return NULL;
    }
    
    if (path && emfs->name_entry) {
        const char *name;
        char *newpath;
        
        name = gtk_entry_get_text (emfs->name_entry);
        if (strcmp (path, "") != 0)
            newpath = g_strdup_printf ("%s/%s", path, name);
        else
            newpath = g_strdup_printf ("/%s", name);
        
        path = emfs->selected_path = newpath;
    }
    
    return path;
}
t_col, end_col, rect_x, rect_y, rect_w, rect_h; start_col = day_view->selection_start_day; end_col = day_view->selection_end_day; if (end_col > start_col || day_view->selection_start_row == -1 || day_view->selection_end_row == -1) { rect_x = day_view->day_offsets[start_col]; rect_y = item_height; rect_w = day_view->day_offsets[end_col + 1] - rect_x; rect_h = canvas_height - 1 - rect_y; gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED]); gdk_draw_rectangle (drawable, gc, TRUE, rect_x - x, rect_y - y, rect_w, rect_h); } } /* Draw the date. Set a clipping rectangle so we don't draw over the next day. */ for (day = 0; day < day_view->days_shown; day++) { e_day_view_top_item_get_day_label (day_view, day, buffer, sizeof (buffer)); clip_rect.x = day_view->day_offsets[day] - x; clip_rect.y = 2 - y; clip_rect.width = day_view->day_widths[day]; clip_rect.height = item_height - 2; gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); pango_layout_get_pixel_size (layout, &date_width, NULL); date_x = day_view->day_offsets[day] + (day_view->day_widths[day] - date_width) / 2; gdk_draw_layout (drawable, fg_gc, date_x - x, 3 - y, layout); g_object_unref (layout); gdk_gc_set_clip_rectangle (fg_gc, NULL); /* Draw the lines down the left and right of the date cols. */ if (day != 0) { gdk_draw_line (drawable, light_gc, day_view->day_offsets[day] - x, 4 - y, day_view->day_offsets[day] - x, item_height - 4 - y); gdk_draw_line (drawable, dark_gc, day_view->day_offsets[day] - 1 - x, 4 - y, day_view->day_offsets[day] - 1 - x, item_height - 4 - y); } /* Draw the lines between each column. */ if (day != 0) { gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_GRID]); gdk_draw_line (drawable, gc, day_view->day_offsets[day] - x, item_height - y, day_view->day_offsets[day] - x, canvas_height - y); } } /* Draw the long events. */ for (event_num = 0; event_num < day_view->long_events->len; event_num++) { e_day_view_top_item_draw_long_event (dvtitem, event_num, drawable, x, y, width, height); } } /* This draws one event in the top canvas. */ static void e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, gint event_num, GdkDrawable *drawable, int x, int y, int width, int height) { EDayView *day_view; EDayViewEvent *event; GtkStyle *style; GdkGC *gc, *fg_gc; gint start_day, end_day; gint item_x, item_y, item_w, item_h; gint text_x, icon_x, icon_y, icon_x_inc; ECalComponent *comp; gchar buffer[16]; gint hour, display_hour, minute, offset, time_width, time_x; gint min_end_time_x, suffix_width, max_icon_x; gchar *suffix; gboolean draw_start_triangle, draw_end_triangle; GdkRectangle clip_rect; GSList *categories_list, *elem; PangoLayout *layout; GdkColor bg_color; day_view = dvtitem->day_view; /* If the event is currently being dragged, don't draw it. It will be drawn in the special drag items. */ if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT && day_view->drag_event_num == event_num) return; if (!e_day_view_get_long_event_position (day_view, event_num, &start_day, &end_day, &item_x, &item_y, &item_w, &item_h)) return; event = &g_array_index (day_view->long_events, EDayViewEvent, event_num); style = gtk_widget_get_style (GTK_WIDGET (day_view)); gc = day_view->main_gc; fg_gc = style->fg_gc[GTK_STATE_NORMAL]; comp = e_cal_component_new (); e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp)); /* Draw the lines across the top & bottom of the entire event. */ gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); gdk_draw_line (drawable, gc, item_x - x, item_y - y, item_x + item_w - 1 - x, item_y - y); gdk_draw_line (drawable, gc, item_x - x, item_y + item_h - 1 - y, item_x + item_w - 1 - x, item_y + item_h - 1 - y); /* Fill it in. */ if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data), &bg_color)) { GdkColormap *colormap; colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view)); if (gdk_colormap_alloc_color (colormap, &bg_color, TRUE, TRUE)) gdk_gc_set_foreground (gc, &bg_color); else gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); } else gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); gdk_draw_rectangle (drawable, gc, TRUE, item_x - x, item_y + 1 - y, item_w, item_h - 2); /* When resizing we don't draw the triangles.*/ draw_start_triangle = TRUE; draw_end_triangle = TRUE; if (day_view->resize_drag_pos != E_CALENDAR_VIEW_POS_NONE && day_view->resize_event_day == E_DAY_VIEW_LONG_EVENT && day_view->resize_event_num == event_num) { if (day_view->resize_drag_pos == E_CALENDAR_VIEW_POS_LEFT_EDGE) draw_start_triangle = FALSE; if (day_view->resize_drag_pos == E_CALENDAR_VIEW_POS_RIGHT_EDGE) draw_end_triangle = FALSE; } /* If the event starts before the first day shown, draw a triangle, else just draw a vertical line down the left. */ if (draw_start_triangle && event->start < day_view->day_starts[start_day]) { e_day_view_top_item_draw_triangle (dvtitem, drawable, item_x - x, item_y - y, -E_DAY_VIEW_BAR_WIDTH, item_h, event_num); } else { gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); gdk_draw_line (drawable, gc, item_x - x, item_y - y, item_x - x, item_y + item_h - 1 - y); } /* Similar for the event end. */ if (draw_end_triangle && event->end > day_view->day_starts[end_day + 1]) { e_day_view_top_item_draw_triangle (dvtitem, drawable, item_x + item_w - 1 - x, item_y - y, E_DAY_VIEW_BAR_WIDTH, item_h, event_num); } else { gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); gdk_draw_line (drawable, gc, item_x + item_w - 1 - x, item_y - y, item_x + item_w - 1 - x, item_y + item_h - 1 - y); } /* If we are editing the event we don't show the icons or the start & end times. */ if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT && day_view->editing_event_num == event_num) return; /* Determine the position of the label, so we know where to place the icons. Note that since the top canvas never scrolls we don't need to take the scroll offset into account. It will always be 0. */ text_x = event->canvas_item->x1; /* Draw the start & end times, if necessary. */ min_end_time_x = item_x + E_DAY_VIEW_LONG_EVENT_X_PAD - x; time_width = e_day_view_get_time_string_width (day_view); if (event->start > day_view->day_starts[start_day]) { offset = day_view->first_hour_shown * 60 + day_view->first_minute_shown + event->start_minute; hour = offset / 60; minute = offset % 60; /* Calculate the actual hour number to display. For 12-hour format we convert 0-23 to 12-11am/12-11pm. */ e_day_view_convert_time_to_display (day_view, hour, &display_hour, &suffix, &suffix_width); if (e_calendar_view_get_use_24_hour_format (E_CALENDAR_VIEW (day_view))) { g_snprintf (buffer, sizeof (buffer), "%i:%02i", display_hour, minute); } else { g_snprintf (buffer, sizeof (buffer), "%i:%02i%s", display_hour, minute, suffix); } clip_rect.x = item_x - x; clip_rect.y = item_y - y; clip_rect.width = item_w - E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH; clip_rect.height = item_h; gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); time_x = item_x + E_DAY_VIEW_LONG_EVENT_X_PAD - x; if (display_hour < 10) time_x += day_view->digit_width; layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); gdk_draw_layout (drawable, fg_gc, time_x, item_y + E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + E_DAY_VIEW_LONG_EVENT_Y_PAD - y, layout); g_object_unref (layout); gdk_gc_set_clip_rectangle (fg_gc, NULL); min_end_time_x += time_width + E_DAY_VIEW_LONG_EVENT_TIME_X_PAD; } max_icon_x = item_x + item_w - E_DAY_VIEW_LONG_EVENT_X_PAD - E_DAY_VIEW_ICON_WIDTH; if (event->end < day_view->day_starts[end_day + 1]) { offset = day_view->first_hour_shown * 60 + day_view->first_minute_shown + event->end_minute; hour = offset / 60; minute = offset % 60; time_x = item_x + item_w - E_DAY_VIEW_LONG_EVENT_X_PAD - time_width - E_DAY_VIEW_LONG_EVENT_TIME_X_PAD - x; if (time_x >= min_end_time_x) { /* Calculate the actual hour number to display. */ e_day_view_convert_time_to_display (day_view, hour, &display_hour, &suffix, &suffix_width); if (e_calendar_view_get_use_24_hour_format (E_CALENDAR_VIEW (day_view))) { g_snprintf (buffer, sizeof (buffer), "%i:%02i", display_hour, minute); } else { g_snprintf (buffer, sizeof (buffer), "%i:%02i%s", display_hour, minute, suffix); } if (display_hour < 10) time_x += day_view->digit_width; layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); gdk_draw_layout (drawable, fg_gc, time_x, item_y + E_DAY_VIEW_LONG_EVENT_Y_PAD + 1 - y, layout); g_object_unref (layout); max_icon_x -= time_width + E_DAY_VIEW_LONG_EVENT_TIME_X_PAD; } } /* Draw the icons. */ icon_x_inc = E_DAY_VIEW_ICON_WIDTH + E_DAY_VIEW_ICON_X_PAD; icon_x = text_x - E_DAY_VIEW_LONG_EVENT_ICON_R_PAD - icon_x_inc - x; icon_y = item_y + E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + E_DAY_VIEW_ICON_Y_PAD - y; if (icon_x <= max_icon_x && (e_cal_component_has_recurrences (comp) || e_cal_component_is_instance (comp))) { gdk_gc_set_clip_mask (gc, NULL); gdk_draw_pixbuf (drawable, gc, day_view->recurrence_icon, 0, 0, icon_x, icon_y, E_DAY_VIEW_ICON_WIDTH, E_DAY_VIEW_ICON_HEIGHT, GDK_RGB_DITHER_NORMAL, 0, 0); icon_x -= icon_x_inc; } if (icon_x <= max_icon_x && e_cal_component_has_attachments (comp)) { gdk_gc_set_clip_mask (gc, NULL); gdk_draw_pixbuf (drawable, gc, day_view->attach_icon, 0, 0, icon_x, icon_y, E_DAY_VIEW_ICON_WIDTH, E_DAY_VIEW_ICON_HEIGHT, GDK_RGB_DITHER_NORMAL, 0, 0); icon_x -= icon_x_inc; } if (icon_x <= max_icon_x && e_cal_component_has_alarms (comp)) { gdk_gc_set_clip_mask (gc, NULL); gdk_draw_pixbuf (drawable, gc, day_view->reminder_icon, 0, 0, icon_x, icon_y, E_DAY_VIEW_ICON_WIDTH, E_DAY_VIEW_ICON_HEIGHT, GDK_RGB_DITHER_NORMAL, 0, 0); icon_x -= icon_x_inc; } if (icon_x <= max_icon_x && e_cal_component_has_organizer (comp)) { gdk_gc_set_clip_mask (gc, NULL); gdk_draw_pixbuf (drawable, gc, day_view->meeting_icon, 0, 0, icon_x, icon_y, E_DAY_VIEW_ICON_WIDTH, E_DAY_VIEW_ICON_HEIGHT, GDK_RGB_DITHER_NORMAL, 0, 0); icon_x -= icon_x_inc; } /* draw categories icons */ e_cal_component_get_categories_list (comp, &categories_list); for (elem = categories_list; elem; elem = elem->next) { char *category; GdkPixmap *pixmap = NULL; GdkBitmap *mask = NULL; category = (char *) elem->data; e_categories_config_get_icon_for (category, &pixmap, &mask); if (pixmap == NULL) continue; if (icon_x <= max_icon_x) { gdk_gc_set_clip_origin (gc, icon_x, icon_y); if (mask != NULL) gdk_gc_set_clip_mask (gc, mask); gdk_draw_drawable (drawable, gc, pixmap, 0, 0, icon_x, icon_y, E_DAY_VIEW_ICON_WIDTH, E_DAY_VIEW_ICON_HEIGHT); icon_x -= icon_x_inc; } g_object_unref (pixmap); if (mask != NULL) g_object_unref (mask); } e_cal_component_free_categories_list (categories_list); g_object_unref (comp); gdk_gc_set_clip_mask (gc, NULL); } /* This draws a little triangle to indicate that an event extends past the days visible on screen. */ static void e_day_view_top_item_draw_triangle (EDayViewTopItem *dvtitem, GdkDrawable *drawable, gint x, gint y, gint w, gint h, gint event_num) { EDayView *day_view; EDayViewEvent *event; GdkGC *gc; GdkColor bg_color; GdkPoint points[3]; gint c1, c2; day_view = dvtitem->day_view; gc = day_view->main_gc; points[0].x = x; points[0].y = y; points[1].x = x + w; points[1].y = y + (h / 2); points[2].x = x; points[2].y = y + h - 1; /* If the height is odd we can use the same central point for both lines. If it is even we use different end-points. */ c1 = c2 = y + (h / 2); if (h % 2 == 0) c1--; event = &g_array_index (day_view->long_events, EDayViewEvent, event_num); /* Fill it in. */ if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data), &bg_color)) { GdkColormap *colormap; colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view)); if (gdk_colormap_alloc_color (colormap, &bg_color, TRUE, TRUE)) gdk_gc_set_foreground (gc, &bg_color); else gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); } else gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); gdk_draw_polygon (drawable, gc, TRUE, points, 3); gdk_gc_set_foreground (gc, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); gdk_draw_line (drawable, gc, x, y, x + w, c1); gdk_draw_line (drawable, gc, x, y + h - 1, x + w, c2); } #endif #ifdef ENABLE_CAIRO static void e_day_view_top_item_draw (GnomeCanvasItem *canvas_item, GdkDrawable *drawable, int x, int y, int width, int height) { EDayViewTopItem *dvtitem; EDayView *day_view; GtkStyle *style; GdkGC *gc, *fg_gc, *bg_gc, *light_gc, *dark_gc; gchar buffer[128]; GdkRectangle clip_rect; gint canvas_width, canvas_height, left_edge, day, date_width, date_x; gint item_height, event_num; PangoLayout *layout; cairo_t *cr; GdkColor fg, bg, light, dark; gboolean show_dates; #if 0 g_print ("In e_day_view_top_item_draw %i,%i %ix%i\n", x, y, width, height); #endif dvtitem = E_DAY_VIEW_TOP_ITEM (canvas_item); day_view = dvtitem->day_view; g_return_if_fail (day_view != NULL); show_dates = dvtitem->show_dates; cr = gdk_cairo_create (drawable); style = gtk_widget_get_style (GTK_WIDGET (day_view)); gc = day_view->main_gc; fg_gc = style->fg_gc[GTK_STATE_NORMAL]; bg_gc = style->bg_gc[GTK_STATE_NORMAL]; light_gc = style->light_gc[GTK_STATE_NORMAL]; dark_gc = style->dark_gc[GTK_STATE_NORMAL]; canvas_width = GTK_WIDGET (canvas_item->canvas)->allocation.width; canvas_height = (show_dates ? 1 : (MAX (1, day_view->rows_in_top_display) + 1)) * day_view->top_row_height; left_edge = 0; item_height = day_view->top_row_height - E_DAY_VIEW_TOP_CANVAS_Y_GAP; fg = style->fg[GTK_STATE_NORMAL]; bg = style->bg[GTK_STATE_NORMAL]; light = style->light[GTK_STATE_NORMAL]; dark = style->dark[GTK_STATE_NORMAL]; if (show_dates) { /* Draw the shadow around the dates. */ cairo_save (cr); gdk_cairo_set_source_color (cr, &light); cairo_move_to (cr, left_edge - x, 1 - y); cairo_line_to (cr, canvas_width - 2 - x, 1 - y); cairo_move_to (cr, left_edge - x, 2 - y); cairo_line_to (cr, left_edge - x, item_height - 2 - y); cairo_stroke (cr); cairo_restore (cr); cairo_save (cr); gdk_cairo_set_source_color (cr, &dark); cairo_move_to (cr, left_edge - x, item_height - 1 - y); cairo_line_to (cr, canvas_width - 1 - x, item_height - 1 - y); cairo_move_to (cr, canvas_width - 1 - x, 1 - y); cairo_line_to (cr, canvas_width - 1 - x, item_height - 1 - y); cairo_stroke (cr); cairo_restore (cr); /* Draw the background for the dates. */ cairo_save (cr); gdk_cairo_set_source_color (cr, &bg); cairo_rectangle (cr, left_edge + 2 - x, 2 - y, canvas_width - left_edge - 3, item_height - 3); cairo_fill (cr); cairo_restore (cr); } if (!show_dates) { /* Clear the main area background. */ cairo_save (cr); gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS]); cairo_rectangle (cr, left_edge - x, - y, canvas_width - left_edge, canvas_height); cairo_fill (cr); cairo_restore (cr); /* Draw the selection background. */ if (GTK_WIDGET_HAS_FOCUS (day_view) && day_view->selection_start_day != -1) { gint start_col, end_col, rect_x, rect_y, rect_w, rect_h; start_col = day_view->selection_start_day; end_col = day_view->selection_end_day; if (end_col > start_col || day_view->selection_start_row == -1 || day_view->selection_end_row == -1) { rect_x = day_view->day_offsets[start_col]; rect_y = 0; rect_w = day_view->day_offsets[end_col + 1] - rect_x; rect_h = canvas_height - 1 - rect_y; cairo_save (cr); gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED]); cairo_rectangle (cr, rect_x - x, rect_y - y, rect_w, rect_h); cairo_fill (cr); cairo_restore (cr); } } } if (show_dates) { /* Draw the date. Set a clipping rectangle so we don't draw over the next day. */ for (day = 0; day < day_view->days_shown; day++) { e_day_view_top_item_get_day_label (day_view, day, buffer, sizeof (buffer)); clip_rect.x = day_view->day_offsets[day] - x; clip_rect.y = 2 - y; clip_rect.width = day_view->day_widths[day]; clip_rect.height = item_height - 2; gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); pango_layout_get_pixel_size (layout, &date_width, NULL); date_x = day_view->day_offsets[day] + (day_view->day_widths[day] - date_width) / 2; gdk_draw_layout (drawable, fg_gc, date_x - x, 3 - y, layout); g_object_unref (layout); gdk_gc_set_clip_rectangle (fg_gc, NULL); /* Draw the lines down the left and right of the date cols. */ if (day != 0) { cairo_save (cr); gdk_cairo_set_source_color (cr, &light); cairo_move_to (cr, day_view->day_offsets[day] - x, 4 - y); cairo_line_to (cr, day_view->day_offsets[day] - x, item_height - 4 - y); cairo_stroke (cr); gdk_cairo_set_source_color (cr, &dark); cairo_move_to (cr, day_view->day_offsets[day] - 1 - x, 4 - y); cairo_line_to (cr, day_view->day_offsets[day] - 1 - x, item_height - 4 - y); cairo_stroke (cr); cairo_restore (cr); } /* Draw the lines between each column. */ if (day != 0) { cairo_save (cr); gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_GRID]); cairo_move_to (cr, day_view->day_offsets[day] - x, item_height - y); cairo_line_to (cr, day_view->day_offsets[day] - x, canvas_height - y); cairo_stroke (cr); cairo_restore (cr); } } } if (!show_dates) { /* Draw the long events. */ for (event_num = 0; event_num < day_view->long_events->len; event_num++) { e_day_view_top_item_draw_long_event (dvtitem, event_num, drawable, x, y, width, height); } } cairo_destroy (cr); } /* This draws one event in the top canvas. */ static void e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, gint event_num, GdkDrawable *drawable, int x, int y, int width, int height) { EDayView *day_view; EDayViewEvent *event; GConfClient *gconf_client; GtkStyle *style; GdkGC *gc, *fg_gc; gint start_day, end_day; gint item_x, item_y, item_w, item_h; gint text_x, icon_x, icon_y, icon_x_inc; ECalComponent *comp; gchar buffer[16]; gint hour, display_hour, minute, offset, time_width, time_x; gint min_end_time_x, suffix_width, max_icon_x; gchar *suffix; gboolean draw_start_triangle, draw_end_triangle; GdkRectangle clip_rect; GSList *categories_list, *elem; PangoLayout *layout; GdkColor bg_color; cairo_t *cr; cairo_pattern_t *pat; guint16 red, green, blue; GdkColor fg; gdouble cc = 65535.0; gboolean gradient; gfloat alpha; gdouble x0, y0, rect_height, rect_width, radius; day_view = dvtitem->day_view; cr = gdk_cairo_create (drawable); gconf_client = gconf_client_get_default (); alpha = gconf_client_get_float (gconf_client, "/apps/evolution/calendar/display/events_transparency", NULL); gradient = gconf_client_get_bool (gconf_client, "/apps/evolution/calendar/display/events_gradient", NULL); g_object_unref (gconf_client); /* If the event is currently being dragged, don't draw it. It will be drawn in the special drag items. */ if (day_view->drag_event_day == E_DAY_VIEW_LONG_EVENT && day_view->drag_event_num == event_num) return; if (!e_day_view_get_long_event_position (day_view, event_num, &start_day, &end_day, &item_x, &item_y, &item_w, &item_h)) return; event = &g_array_index (day_view->long_events, EDayViewEvent, event_num); style = gtk_widget_get_style (GTK_WIDGET (day_view)); gc = day_view->main_gc; fg_gc = style->fg_gc[GTK_STATE_NORMAL]; fg = style->fg[GTK_STATE_NORMAL]; comp = e_cal_component_new (); e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (event->comp_data->icalcomp)); if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data), &bg_color)) { GdkColormap *colormap; colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view)); if (gdk_colormap_alloc_color (colormap, &bg_color, TRUE, TRUE)){ red = bg_color.red; green = bg_color.green; blue = bg_color.blue; } else { red = day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND].red; green = day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND].green; blue = day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND].blue; } } else { red = day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND].red; green = day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND].green; blue = day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND].blue; } /* Fill the background with white to play with transparency */ cairo_save (cr); x0 = item_x - x + 4; y0 = item_y + 1 - y; rect_width = item_w - 8; rect_height = item_h - 2; radius = 12; draw_curved_rectangle (cr, x0, y0, rect_width, rect_height, radius); cairo_set_source_rgba (cr, 1, 1, 1, alpha); cairo_fill_preserve (cr); cairo_restore (cr); /* Draw the border around the event */ cairo_save (cr); x0 = item_x - x + 4; y0 = item_y + 1 - y; rect_width = item_w - 8; rect_height = item_h - 2; radius = 12; draw_curved_rectangle (cr, x0, y0, rect_width, rect_height, radius); cairo_set_source_rgb (cr, red/cc, green/cc, blue/cc); cairo_set_line_width (cr, 1.5); cairo_stroke (cr); cairo_restore (cr); /* Fill in with gradient */ cairo_save (cr); x0 = item_x - x + 5.5; y0 = item_y + 2.5 - y; rect_width = item_w - 11; rect_height = item_h - 5; radius = 10; draw_curved_rectangle (cr, x0, y0, rect_width, rect_height, radius); if (gradient){ pat = cairo_pattern_create_linear (item_x - x + 5.5, item_y + 2.5 - y, item_x - x + 5, item_y - y + item_h + 7.5); cairo_pattern_add_color_stop_rgba (pat, 1, red/cc, green/cc, blue/cc, 0.8); cairo_pattern_add_color_stop_rgba (pat, 0, red/cc, green/cc, blue/cc, 0.4); cairo_set_source (cr, pat); cairo_fill_preserve (cr); cairo_pattern_destroy (pat); } else { cairo_set_source_rgba (cr, red/cc, green/cc, blue/cc, 0.8); cairo_fill_preserve (cr); } cairo_set_source_rgba (cr, red/cc, green/cc, blue/cc, 0); cairo_set_line_width (cr, 0.5); cairo_stroke (cr); cairo_restore (cr); /* When resizing we don't draw the triangles.*/ draw_start_triangle = TRUE; draw_end_triangle = TRUE; if (day_view->resize_drag_pos != E_CALENDAR_VIEW_POS_NONE && day_view->resize_event_day == E_DAY_VIEW_LONG_EVENT && day_view->resize_event_num == event_num) { if (day_view->resize_drag_pos == E_CALENDAR_VIEW_POS_LEFT_EDGE) draw_start_triangle = FALSE; if (day_view->resize_drag_pos == E_CALENDAR_VIEW_POS_RIGHT_EDGE) draw_end_triangle = FALSE; } /* If the event starts before the first day shown, draw a triangle */ if (draw_start_triangle && event->start < day_view->day_starts[start_day]) { e_day_view_top_item_draw_triangle (dvtitem, drawable, item_x - x + 4, item_y - y, -E_DAY_VIEW_BAR_WIDTH, item_h, event_num); } /* Similar for the event end. */ if (draw_end_triangle && event->end > day_view->day_starts[end_day + 1]) { e_day_view_top_item_draw_triangle (dvtitem, drawable, item_x + item_w - 4 - x, item_y - y, E_DAY_VIEW_BAR_WIDTH, item_h, event_num); } /* If we are editing the event we don't show the icons or the start & end times. */ if (day_view->editing_event_day == E_DAY_VIEW_LONG_EVENT && day_view->editing_event_num == event_num) return; /* Determine the position of the label, so we know where to place the icons. Note that since the top canvas never scrolls we don't need to take the scroll offset into account. It will always be 0. */ text_x = event->canvas_item->x1; /* Draw the start & end times, if necessary. */ min_end_time_x = item_x + E_DAY_VIEW_LONG_EVENT_X_PAD - x; time_width = e_day_view_get_time_string_width (day_view); if (event->start > day_view->day_starts[start_day]) { offset = day_view->first_hour_shown * 60 + day_view->first_minute_shown + event->start_minute; hour = offset / 60; minute = offset % 60; /* Calculate the actual hour number to display. For 12-hour format we convert 0-23 to 12-11am/12-11pm. */ e_day_view_convert_time_to_display (day_view, hour, &display_hour, &suffix, &suffix_width); if (e_calendar_view_get_use_24_hour_format (E_CALENDAR_VIEW (day_view))) { g_snprintf (buffer, sizeof (buffer), "%i:%02i", display_hour, minute); } else { g_snprintf (buffer, sizeof (buffer), "%i:%02i%s", display_hour, minute, suffix); } clip_rect.x = item_x - x; clip_rect.y = item_y - y; clip_rect.width = item_w - E_DAY_VIEW_LONG_EVENT_BORDER_WIDTH; clip_rect.height = item_h; gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); time_x = item_x + E_DAY_VIEW_LONG_EVENT_X_PAD - x; if (display_hour < 10) time_x += day_view->digit_width; layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); gdk_draw_layout (drawable, fg_gc, time_x, item_y + E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + E_DAY_VIEW_LONG_EVENT_Y_PAD - y, layout); g_object_unref (layout); gdk_gc_set_clip_rectangle (fg_gc, NULL); min_end_time_x += time_width + E_DAY_VIEW_LONG_EVENT_TIME_X_PAD; } max_icon_x = item_x + item_w - E_DAY_VIEW_LONG_EVENT_X_PAD - E_DAY_VIEW_ICON_WIDTH; if (event->end < day_view->day_starts[end_day + 1]) { offset = day_view->first_hour_shown * 60 + day_view->first_minute_shown + event->end_minute; hour = offset / 60; minute = offset % 60; time_x = item_x + item_w - E_DAY_VIEW_LONG_EVENT_X_PAD - time_width - E_DAY_VIEW_LONG_EVENT_TIME_X_PAD - x; if (time_x >= min_end_time_x) { /* Calculate the actual hour number to display. */ e_day_view_convert_time_to_display (day_view, hour, &display_hour, &suffix, &suffix_width); if (e_calendar_view_get_use_24_hour_format (E_CALENDAR_VIEW (day_view))) { g_snprintf (buffer, sizeof (buffer), "%i:%02i", display_hour, minute); } else { g_snprintf (buffer, sizeof (buffer), "%i:%02i%s", display_hour, minute, suffix); } if (display_hour < 10) time_x += day_view->digit_width; layout = gtk_widget_create_pango_layout (GTK_WIDGET (day_view), buffer); gdk_draw_layout (drawable, fg_gc, time_x, item_y + E_DAY_VIEW_LONG_EVENT_Y_PAD + 1 - y, layout); g_object_unref (layout); max_icon_x -= time_width + E_DAY_VIEW_LONG_EVENT_TIME_X_PAD; } } /* Draw the icons. */ icon_x_inc = E_DAY_VIEW_ICON_WIDTH + E_DAY_VIEW_ICON_X_PAD; icon_x = text_x - E_DAY_VIEW_LONG_EVENT_ICON_R_PAD - icon_x_inc - x; icon_y = item_y + E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + E_DAY_VIEW_ICON_Y_PAD - y; if (icon_x <= max_icon_x && (e_cal_component_has_recurrences (comp) || e_cal_component_is_instance (comp))) { cairo_save (cr); gdk_cairo_set_source_pixbuf (cr, day_view->recurrence_icon, icon_x, icon_y); cairo_paint (cr); cairo_restore (cr); icon_x -= icon_x_inc; } if (icon_x <= max_icon_x && e_cal_component_has_attachments (comp)) { cairo_save (cr); gdk_cairo_set_source_pixbuf (cr, day_view->attach_icon, icon_x, icon_y); cairo_paint (cr); cairo_restore (cr); icon_x -= icon_x_inc; } if (icon_x <= max_icon_x && e_cal_component_has_alarms (comp)) { cairo_save (cr); gdk_cairo_set_source_pixbuf (cr, day_view->reminder_icon, icon_x, icon_y); cairo_paint (cr); cairo_restore (cr); icon_x -= icon_x_inc; } if (icon_x <= max_icon_x && e_cal_component_has_organizer (comp)) { cairo_save (cr); gdk_cairo_set_source_pixbuf (cr, day_view->meeting_icon, icon_x, icon_y); cairo_paint (cr); cairo_restore (cr); icon_x -= icon_x_inc; } /* draw categories icons */ e_cal_component_get_categories_list (comp, &categories_list); for (elem = categories_list; elem; elem = elem->next) { char *category; GdkPixmap *pixmap = NULL; GdkBitmap *mask = NULL; category = (char *) elem->data; e_categories_config_get_icon_for (category, &pixmap, &mask); if (pixmap == NULL) continue; if (icon_x <= max_icon_x) { gdk_gc_set_clip_origin (gc, icon_x, icon_y); if (mask != NULL) gdk_gc_set_clip_mask (gc, mask); gdk_draw_drawable (drawable, gc, pixmap, 0, 0, icon_x, icon_y, E_DAY_VIEW_ICON_WIDTH, E_DAY_VIEW_ICON_HEIGHT); icon_x -= icon_x_inc; } g_object_unref (pixmap); if (mask != NULL) g_object_unref (mask); } e_cal_component_free_categories_list (categories_list); g_object_unref (comp); cairo_destroy (cr); gdk_gc_set_clip_mask (gc, NULL); } /* This draws a little triangle to indicate that an event extends past the days visible on screen. */ static void e_day_view_top_item_draw_triangle (EDayViewTopItem *dvtitem, GdkDrawable *drawable, gint x, gint y, gint w, gint h, gint event_num) { EDayView *day_view; EDayViewEvent *event; GdkGC *gc; GdkColor bg_color; GdkPoint points[3]; gint c1, c2; cairo_t *cr; cr = gdk_cairo_create (drawable); day_view = dvtitem->day_view; gc = day_view->main_gc; points[0].x = x; points[0].y = y; points[1].x = x + w; points[1].y = y + (h / 2); points[2].x = x; points[2].y = y + h - 1; /* If the height is odd we can use the same central point for both lines. If it is even we use different end-points. */ c1 = c2 = y + (h / 2); if (h % 2 == 0) c1--; event = &g_array_index (day_view->long_events, EDayViewEvent, event_num); cairo_save (cr); /* Fill it in. */ if (gdk_color_parse (e_cal_model_get_color_for_component (e_calendar_view_get_model (E_CALENDAR_VIEW (day_view)), event->comp_data), &bg_color)) { GdkColormap *colormap; colormap = gtk_widget_get_colormap (GTK_WIDGET (day_view)); if (gdk_colormap_alloc_color (colormap, &bg_color, TRUE, TRUE)) { gdk_cairo_set_source_color (cr, &bg_color); } else { gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); } } else { gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BACKGROUND]); } cairo_move_to (cr, points[0].x, points[0].y); cairo_line_to (cr, points[1].x, points[1].y); cairo_line_to (cr, points[2].x, points[2].y); cairo_line_to (cr, points[0].x, points[0].y); cairo_fill (cr); cairo_restore (cr); cairo_save (cr); gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_LONG_EVENT_BORDER]); cairo_move_to (cr, x, y); cairo_line_to (cr, x + w, c1); cairo_move_to (cr, x, y + h - 1); cairo_line_to (cr, x + w, c2); cairo_stroke (cr); cairo_restore (cr); cairo_destroy (cr); } #endif /* This is supposed to return the nearest item the the point and the distance. Since we are the only item we just return ourself and 0 for the distance. This is needed so that we get button/motion events. */ static double e_day_view_top_item_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item) { *actual_item = item; return 0.0; } static gint e_day_view_top_item_event (GnomeCanvasItem *item, GdkEvent *event) { switch (event->type) { case GDK_BUTTON_PRESS: case GDK_BUTTON_RELEASE: case GDK_MOTION_NOTIFY: default: break; } return FALSE; } void e_day_view_top_item_get_day_label (EDayView *day_view, gint day, gchar *buffer, gint buffer_len) { struct icaltimetype day_start_tt; struct tm day_start = { 0 }; gchar *format; day_start_tt = icaltime_from_timet_with_zone (day_view->day_starts[day], FALSE, e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view))); day_start.tm_year = day_start_tt.year - 1900; day_start.tm_mon = day_start_tt.month - 1; day_start.tm_mday = day_start_tt.day; day_start.tm_isdst = -1; day_start.tm_wday = time_day_of_week (day_start_tt.day, day_start_tt.month - 1, day_start_tt.year); if (day_view->date_format == E_DAY_VIEW_DATE_FULL) /* strftime format %A = full weekday name, %d = day of month, %B = full month name. Don't use any other specifiers. */ format = _("%A %d %B"); else if (day_view->date_format == E_DAY_VIEW_DATE_ABBREVIATED) /* strftime format %a = abbreviated weekday name, %d = day of month, %b = abbreviated month name. Don't use any other specifiers. */ format = _("%a %d %b"); else if (day_view->date_format == E_DAY_VIEW_DATE_NO_WEEKDAY) /* strftime format %d = day of month, %b = abbreviated month name. Don't use any other specifiers. */ format = _("%d %b"); else format = "%d"; e_utf8_strftime (buffer, buffer_len, format, &day_start); }