Update Serbian translation
[evolution.git] / src / calendar / gui / e-memo-table.c
blob581bf3da4bdab9074bc5b8051f46ef08c6615a10
1 /*
2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as published by
4 * the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9 * for more details.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 * Authors:
16 * Damon Chaplin <damon@ximian.com>
17 * Rodrigo Moya <rodrigo@ximian.com>
18 * Nathan Owens <pianocomp81@yahoo.com>
20 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
25 * EMemoTable - displays the ECalComponent objects in a table (an ETable).
28 #include "evolution-config.h"
30 #include "e-memo-table.h"
32 #include <sys/stat.h>
33 #include <unistd.h>
34 #include <glib/gi18n.h>
35 #include <glib/gstdio.h>
37 #include "e-cal-dialogs.h"
38 #include "e-cal-model-memos.h"
39 #include "e-cal-ops.h"
40 #include "e-calendar-view.h"
41 #include "e-cell-date-edit-text.h"
42 #include "print.h"
43 #include "misc.h"
45 #define E_MEMO_TABLE_GET_PRIVATE(obj) \
46 (G_TYPE_INSTANCE_GET_PRIVATE \
47 ((obj), E_TYPE_MEMO_TABLE, EMemoTablePrivate))
49 struct _EMemoTablePrivate {
50 gpointer shell_view; /* weak pointer */
51 ECalModel *model;
53 GtkTargetList *copy_target_list;
54 GtkTargetList *paste_target_list;
57 enum {
58 PROP_0,
59 PROP_COPY_TARGET_LIST,
60 PROP_MODEL,
61 PROP_PASTE_TARGET_LIST,
62 PROP_SHELL_VIEW
65 enum {
66 OPEN_COMPONENT,
67 POPUP_EVENT,
68 LAST_SIGNAL
71 static guint signals[LAST_SIGNAL];
73 /* The icons to represent the task. */
74 static const gchar *icon_names[] = {
75 "stock_notes",
76 "stock_insert-note"
79 /* Forward Declarations */
80 static void e_memo_table_selectable_init
81 (ESelectableInterface *iface);
83 G_DEFINE_TYPE_WITH_CODE (
84 EMemoTable,
85 e_memo_table,
86 E_TYPE_TABLE,
87 G_IMPLEMENT_INTERFACE (
88 E_TYPE_SELECTABLE,
89 e_memo_table_selectable_init))
91 static void
92 memo_table_emit_open_component (EMemoTable *memo_table,
93 ECalModelComponent *comp_data)
95 guint signal_id = signals[OPEN_COMPONENT];
97 g_signal_emit (memo_table, signal_id, 0, comp_data);
100 static void
101 memo_table_emit_popup_event (EMemoTable *memo_table,
102 GdkEvent *event)
104 guint signal_id = signals[POPUP_EVENT];
106 g_signal_emit (memo_table, signal_id, 0, event);
109 /* Returns the current time, for the ECellDateEdit items.
110 * FIXME: Should probably use the timezone of the item rather than the
111 * current timezone, though that may be difficult to get from here. */
112 static struct tm
113 memo_table_get_current_time (ECellDateEdit *ecde,
114 gpointer user_data)
116 EMemoTable *memo_table = user_data;
117 ECalModel *model;
118 icaltimezone *zone;
119 struct tm tmp_tm = { 0 };
120 struct icaltimetype tt;
122 /* Get the current timezone. */
123 model = e_memo_table_get_model (memo_table);
124 zone = e_cal_model_get_timezone (model);
126 tt = icaltime_from_timet_with_zone (time (NULL), FALSE, zone);
128 /* Now copy it to the struct tm and return it. */
129 tmp_tm.tm_year = tt.year - 1900;
130 tmp_tm.tm_mon = tt.month - 1;
131 tmp_tm.tm_mday = tt.day;
132 tmp_tm.tm_hour = tt.hour;
133 tmp_tm.tm_min = tt.minute;
134 tmp_tm.tm_sec = tt.second;
135 tmp_tm.tm_isdst = -1;
137 return tmp_tm;
140 /* Deletes all of the selected components in the table */
141 static void
142 delete_selected_components (EMemoTable *memo_table)
144 GSList *objs;
146 objs = e_memo_table_get_selected (memo_table);
147 e_cal_ops_delete_ecalmodel_components (memo_table->priv->model, objs);
148 g_slist_free (objs);
151 static void
152 memo_table_set_model (EMemoTable *memo_table,
153 ECalModel *model)
155 g_return_if_fail (memo_table->priv->model == NULL);
157 memo_table->priv->model = g_object_ref (model);
160 static void
161 memo_table_set_shell_view (EMemoTable *memo_table,
162 EShellView *shell_view)
164 g_return_if_fail (memo_table->priv->shell_view == NULL);
166 memo_table->priv->shell_view = shell_view;
168 g_object_add_weak_pointer (
169 G_OBJECT (shell_view),
170 &memo_table->priv->shell_view);
173 static void
174 memo_table_set_property (GObject *object,
175 guint property_id,
176 const GValue *value,
177 GParamSpec *pspec)
179 switch (property_id) {
180 case PROP_MODEL:
181 memo_table_set_model (
182 E_MEMO_TABLE (object),
183 g_value_get_object (value));
184 return;
186 case PROP_SHELL_VIEW:
187 memo_table_set_shell_view (
188 E_MEMO_TABLE (object),
189 g_value_get_object (value));
190 return;
193 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
196 static void
197 memo_table_get_property (GObject *object,
198 guint property_id,
199 GValue *value,
200 GParamSpec *pspec)
202 switch (property_id) {
203 case PROP_COPY_TARGET_LIST:
204 g_value_set_boxed (
205 value, e_memo_table_get_copy_target_list (
206 E_MEMO_TABLE (object)));
207 return;
209 case PROP_MODEL:
210 g_value_set_object (
211 value, e_memo_table_get_model (
212 E_MEMO_TABLE (object)));
213 return;
215 case PROP_PASTE_TARGET_LIST:
216 g_value_set_boxed (
217 value, e_memo_table_get_paste_target_list (
218 E_MEMO_TABLE (object)));
219 return;
221 case PROP_SHELL_VIEW:
222 g_value_set_object (
223 value, e_memo_table_get_shell_view (
224 E_MEMO_TABLE (object)));
225 return;
228 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
231 static void
232 memo_table_dispose (GObject *object)
234 EMemoTablePrivate *priv;
236 priv = E_MEMO_TABLE_GET_PRIVATE (object);
238 if (priv->shell_view != NULL) {
239 g_object_remove_weak_pointer (
240 G_OBJECT (priv->shell_view), &priv->shell_view);
241 priv->shell_view = NULL;
244 if (priv->model != NULL) {
245 g_object_unref (priv->model);
246 priv->model = NULL;
249 if (priv->copy_target_list != NULL) {
250 gtk_target_list_unref (priv->copy_target_list);
251 priv->copy_target_list = NULL;
254 if (priv->paste_target_list != NULL) {
255 gtk_target_list_unref (priv->paste_target_list);
256 priv->paste_target_list = NULL;
259 /* Chain up to parent's dispose() method. */
260 G_OBJECT_CLASS (e_memo_table_parent_class)->dispose (object);
263 static void
264 memo_table_constructed (GObject *object)
266 EMemoTable *memo_table;
267 ECalModel *model;
268 ECell *cell, *popup_cell;
269 ETableExtras *extras;
270 ETableSpecification *specification;
271 AtkObject *a11y;
272 gchar *etspecfile;
273 GError *local_error = NULL;
275 memo_table = E_MEMO_TABLE (object);
276 model = e_memo_table_get_model (memo_table);
278 /* Create the header columns */
280 extras = e_table_extras_new ();
283 * Normal string fields.
285 cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT);
286 g_object_set (cell, "bg_color_column", E_CAL_MODEL_FIELD_COLOR, NULL);
287 e_table_extras_add_cell (extras, "calstring", cell);
288 g_object_unref (cell);
291 * Date fields.
293 cell = e_cell_date_edit_text_new (NULL, GTK_JUSTIFY_LEFT);
294 g_object_set (cell, "bg_color_column", E_CAL_MODEL_FIELD_COLOR, NULL);
296 e_binding_bind_property (
297 model, "timezone",
298 cell, "timezone",
299 G_BINDING_BIDIRECTIONAL |
300 G_BINDING_SYNC_CREATE);
302 e_binding_bind_property (
303 model, "use-24-hour-format",
304 cell, "use-24-hour-format",
305 G_BINDING_BIDIRECTIONAL |
306 G_BINDING_SYNC_CREATE);
308 popup_cell = e_cell_date_edit_new ();
309 e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell);
310 g_object_unref (cell);
312 e_binding_bind_property (
313 model, "use-24-hour-format",
314 popup_cell, "use-24-hour-format",
315 G_BINDING_BIDIRECTIONAL |
316 G_BINDING_SYNC_CREATE);
318 e_table_extras_add_cell (extras, "dateedit", popup_cell);
319 g_object_unref (popup_cell);
320 memo_table->dates_cell = E_CELL_DATE_EDIT (popup_cell);
322 e_cell_date_edit_set_get_time_callback (
323 E_CELL_DATE_EDIT (popup_cell),
324 memo_table_get_current_time, memo_table, NULL);
326 /* Sorting */
327 e_table_extras_add_compare (
328 extras, "date-compare", e_cell_date_edit_compare_cb);
330 /* Create pixmaps */
332 cell = e_cell_toggle_new (icon_names, G_N_ELEMENTS (icon_names));
333 e_table_extras_add_cell (extras, "icon", cell);
334 g_object_unref (cell);
336 e_table_extras_add_icon_name (extras, "icon", "stock_notes");
338 /* set proper format component for a default 'date' cell renderer */
339 cell = e_table_extras_get_cell (extras, "date");
340 e_cell_date_set_format_component (E_CELL_DATE (cell), "calendar");
342 /* Construct the table */
344 etspecfile = g_build_filename (
345 EVOLUTION_ETSPECDIR, "e-memo-table.etspec", NULL);
346 specification = e_table_specification_new (etspecfile, &local_error);
348 /* Failure here is fatal. */
349 if (local_error != NULL) {
350 g_error ("%s: %s", etspecfile, local_error->message);
351 g_return_if_reached ();
354 e_table_construct (
355 E_TABLE (memo_table),
356 E_TABLE_MODEL (model),
357 extras, specification);
359 g_object_unref (specification);
360 g_free (etspecfile);
362 gtk_widget_set_has_tooltip (GTK_WIDGET (memo_table), TRUE);
364 g_object_unref (extras);
366 a11y = gtk_widget_get_accessible (GTK_WIDGET (memo_table));
367 if (a11y)
368 atk_object_set_name (a11y, _("Memos"));
370 /* Chain up to parent's constructed() method. */
371 G_OBJECT_CLASS (e_memo_table_parent_class)->constructed (object);
374 static gboolean
375 memo_table_popup_menu (GtkWidget *widget)
377 EMemoTable *memo_table;
379 memo_table = E_MEMO_TABLE (widget);
380 memo_table_emit_popup_event (memo_table, NULL);
382 return TRUE;
385 static gboolean
386 memo_table_query_tooltip (GtkWidget *widget,
387 gint x,
388 gint y,
389 gboolean keyboard_mode,
390 GtkTooltip *tooltip)
392 EMemoTable *memo_table;
393 ECalModel *model;
394 ECalModelComponent *comp_data;
395 gint row = -1, col = -1, row_y = -1, row_height = -1;
396 GtkWidget *box, *l, *w;
397 GdkRGBA sel_bg, sel_fg, norm_bg, norm_text;
398 gchar *tmp;
399 const gchar *str;
400 GString *tmp2;
401 gboolean free_text = FALSE;
402 ECalComponent *new_comp;
403 ECalComponentOrganizer organizer;
404 ECalComponentDateTime dtstart, dtdue;
405 icalcomponent *clone;
406 icaltimezone *zone, *default_zone;
407 GSList *desc, *p;
408 gint len;
409 ESelectionModel *esm;
410 struct tm tmp_tm;
412 if (keyboard_mode)
413 return FALSE;
415 memo_table = E_MEMO_TABLE (widget);
417 e_table_get_mouse_over_cell (E_TABLE (memo_table), &row, &col);
418 if (row == -1)
419 return FALSE;
421 /* Respect sorting option; the 'e_table_get_mouse_over_cell'
422 * returns sorted row, not the model one. */
423 esm = e_table_get_selection_model (E_TABLE (memo_table));
424 if (esm && esm->sorter && e_sorter_needs_sorting (esm->sorter))
425 row = e_sorter_sorted_to_model (esm->sorter, row);
427 if (row < 0)
428 return FALSE;
430 model = e_memo_table_get_model (memo_table);
431 comp_data = e_cal_model_get_component_at (model, row);
432 if (!comp_data || !comp_data->icalcomp)
433 return FALSE;
435 new_comp = e_cal_component_new ();
436 clone = icalcomponent_new_clone (comp_data->icalcomp);
437 if (!e_cal_component_set_icalcomponent (new_comp, clone)) {
438 g_object_unref (new_comp);
439 return FALSE;
442 e_utils_get_theme_color (widget, "theme_selected_bg_color", E_UTILS_DEFAULT_THEME_SELECTED_BG_COLOR, &sel_bg);
443 e_utils_get_theme_color (widget, "theme_selected_fg_color", E_UTILS_DEFAULT_THEME_SELECTED_FG_COLOR, &sel_fg);
444 e_utils_get_theme_color (widget, "theme_bg_color", E_UTILS_DEFAULT_THEME_BG_COLOR, &norm_bg);
445 e_utils_get_theme_color (widget, "theme_text_color,theme_fg_color", E_UTILS_DEFAULT_THEME_TEXT_COLOR, &norm_text);
447 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
449 str = e_calendar_view_get_icalcomponent_summary (
450 comp_data->client, comp_data->icalcomp, &free_text);
451 if (!(str && *str)) {
452 if (free_text)
453 g_free ((gchar *) str);
454 free_text = FALSE;
455 str = _("* No Summary *");
458 l = gtk_label_new (NULL);
459 tmp = g_markup_printf_escaped ("<b>%s</b>", str);
460 gtk_label_set_line_wrap (GTK_LABEL (l), TRUE);
461 gtk_label_set_markup (GTK_LABEL (l), tmp);
462 gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
463 w = gtk_event_box_new ();
465 gtk_widget_override_background_color (w, GTK_STATE_FLAG_NORMAL, &sel_bg);
466 gtk_widget_override_color (l, GTK_STATE_FLAG_NORMAL, &sel_fg);
467 gtk_container_add (GTK_CONTAINER (w), l);
468 gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
469 g_free (tmp);
471 if (free_text)
472 g_free ((gchar *) str);
473 free_text = FALSE;
475 w = gtk_event_box_new ();
476 gtk_widget_override_background_color (w, GTK_STATE_FLAG_NORMAL, &norm_bg);
478 l = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
479 gtk_container_add (GTK_CONTAINER (w), l);
480 gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0);
481 w = l;
483 e_cal_component_get_organizer (new_comp, &organizer);
484 if (organizer.cn) {
485 gchar *ptr;
486 ptr = strchr (organizer.value, ':');
488 if (ptr) {
489 ptr++;
490 tmp = g_strdup_printf (
491 /* Translators: It will display
492 * "Organizer: NameOfTheUser <email@ofuser.com>" */
493 _("Organizer: %s <%s>"), organizer.cn, ptr);
494 } else {
495 /* With SunOne accounts, there may be no ':' in
496 * organizer.value */
497 tmp = g_strdup_printf (
498 _("Organizer: %s"), organizer.cn);
501 l = gtk_label_new (tmp);
502 gtk_label_set_line_wrap (GTK_LABEL (l), FALSE);
503 gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
504 gtk_box_pack_start (GTK_BOX (w), l, FALSE, FALSE, 0);
505 g_free (tmp);
507 gtk_widget_override_color (l, GTK_STATE_FLAG_NORMAL, &norm_text);
510 e_cal_component_get_dtstart (new_comp, &dtstart);
511 e_cal_component_get_due (new_comp, &dtdue);
513 default_zone = e_cal_model_get_timezone (model);
515 if (dtstart.tzid) {
516 zone = icalcomponent_get_timezone (
517 e_cal_component_get_icalcomponent (new_comp),
518 dtstart.tzid);
519 if (!zone)
520 e_cal_client_get_timezone_sync (
521 comp_data->client, dtstart.tzid, &zone, NULL, NULL);
522 if (!zone)
523 zone = default_zone;
524 } else {
525 zone = NULL;
528 tmp2 = g_string_new ("");
530 if (dtstart.value) {
531 gchar *str;
533 tmp_tm = icaltimetype_to_tm_with_zone (dtstart.value, zone, default_zone);
534 str = e_datetime_format_format_tm ("calendar", "table",
535 dtstart.value->is_date ? DTFormatKindDate : DTFormatKindDateTime,
536 &tmp_tm);
538 if (str && *str) {
539 /* Translators: This is followed by an event's start date/time */
540 g_string_append (tmp2, _("Start: "));
541 g_string_append (tmp2, str);
544 g_free (str);
547 if (dtdue.value) {
548 gchar *str;
550 tmp_tm = icaltimetype_to_tm_with_zone (dtdue.value, zone, default_zone);
551 str = e_datetime_format_format_tm ("calendar", "table",
552 dtdue.value->is_date ? DTFormatKindDate : DTFormatKindDateTime,
553 &tmp_tm);
555 if (str && *str) {
556 if (tmp2->len)
557 g_string_append (tmp2, "; ");
559 /* Translators: This is followed by an event's due date/time */
560 g_string_append (tmp2, _("Due: "));
561 g_string_append (tmp2, str);
564 g_free (str);
567 if (tmp2->len) {
568 l = gtk_label_new (tmp2->str);
569 gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
570 gtk_box_pack_start (GTK_BOX (w), l, FALSE, FALSE, 0);
572 gtk_widget_override_color (l, GTK_STATE_FLAG_NORMAL, &norm_text);
575 g_string_free (tmp2, TRUE);
577 e_cal_component_free_datetime (&dtstart);
578 e_cal_component_free_datetime (&dtdue);
580 tmp2 = g_string_new ("");
581 e_cal_component_get_description_list (new_comp, &desc);
582 for (len = 0, p = desc; p != NULL; p = p->next) {
583 ECalComponentText *text = p->data;
585 if (text->value != NULL) {
586 len += strlen (text->value);
587 g_string_append (tmp2, text->value);
588 if (len > 1024) {
589 g_string_set_size (tmp2, 1020);
590 g_string_append (tmp2, "...");
591 break;
595 e_cal_component_free_text_list (desc);
597 if (tmp2->len) {
598 l = gtk_label_new (tmp2->str);
599 gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
600 gtk_box_pack_start (GTK_BOX (w), l, FALSE, FALSE, 0);
602 gtk_widget_override_color (l, GTK_STATE_FLAG_NORMAL, &norm_text);
605 g_string_free (tmp2, TRUE);
607 gtk_widget_show_all (box);
608 gtk_tooltip_set_custom (tooltip, box);
610 g_object_unref (new_comp);
612 if (esm && esm->sorter && e_sorter_needs_sorting (esm->sorter))
613 row = e_sorter_model_to_sorted (esm->sorter, row);
615 e_table_get_cell_geometry (E_TABLE (memo_table), row, 0, NULL, &row_y, NULL, &row_height);
617 if (row_y != -1 && row_height != -1) {
618 ETable *etable;
619 GdkRectangle rect;
620 GtkAllocation allocation;
622 etable = E_TABLE (memo_table);
624 if (etable && etable->table_canvas) {
625 gtk_widget_get_allocation (GTK_WIDGET (etable->table_canvas), &allocation);
626 } else {
627 allocation.x = 0;
628 allocation.y = 0;
629 allocation.width = 0;
630 allocation.height = 0;
633 rect.x = allocation.x;
634 rect.y = allocation.y + row_y - BUTTON_PADDING;
635 rect.width = allocation.width;
636 rect.height = row_height + 2 * BUTTON_PADDING;
638 if (etable && etable->header_canvas) {
639 gtk_widget_get_allocation (GTK_WIDGET (etable->header_canvas), &allocation);
641 rect.y += allocation.height;
644 gtk_tooltip_set_tip_area (tooltip, &rect);
647 return TRUE;
650 static void
651 memo_table_double_click (ETable *table,
652 gint row,
653 gint col,
654 GdkEvent *event)
656 EMemoTable *memo_table;
657 ECalModel *model;
658 ECalModelComponent *comp_data;
660 memo_table = E_MEMO_TABLE (table);
661 model = e_memo_table_get_model (memo_table);
662 comp_data = e_cal_model_get_component_at (model, row);
663 memo_table_emit_open_component (memo_table, comp_data);
666 static gint
667 memo_table_right_click (ETable *table,
668 gint row,
669 gint col,
670 GdkEvent *event)
672 EMemoTable *memo_table;
674 memo_table = E_MEMO_TABLE (table);
675 memo_table_emit_popup_event (memo_table, event);
677 return TRUE;
680 static gboolean
681 memo_table_white_space_event (ETable *table,
682 GdkEvent *event)
684 guint event_button = 0;
686 g_return_val_if_fail (E_IS_MEMO_TABLE (table), FALSE);
687 g_return_val_if_fail (event != NULL, FALSE);
689 if (event->type == GDK_BUTTON_PRESS &&
690 gdk_event_get_button (event, &event_button) &&
691 event_button == 3) {
692 GtkWidget *table_canvas;
694 table_canvas = GTK_WIDGET (table->table_canvas);
696 if (!gtk_widget_has_focus (table_canvas))
697 gtk_widget_grab_focus (table_canvas);
699 memo_table_emit_popup_event (E_MEMO_TABLE (table), event);
701 return TRUE;
704 return FALSE;
707 static void
708 memo_table_update_actions (ESelectable *selectable,
709 EFocusTracker *focus_tracker,
710 GdkAtom *clipboard_targets,
711 gint n_clipboard_targets)
713 EMemoTable *memo_table;
714 GtkAction *action;
715 GtkTargetList *target_list;
716 GSList *list, *iter;
717 gboolean can_paste = FALSE;
718 gboolean sources_are_editable = TRUE;
719 gboolean is_editing;
720 gboolean sensitive;
721 const gchar *tooltip;
722 gint n_selected;
723 gint ii;
725 memo_table = E_MEMO_TABLE (selectable);
726 n_selected = e_table_selected_count (E_TABLE (memo_table));
727 is_editing = e_table_is_editing (E_TABLE (memo_table));
729 list = e_memo_table_get_selected (memo_table);
730 for (iter = list; iter != NULL && sources_are_editable; iter = iter->next) {
731 ECalModelComponent *comp_data = iter->data;
733 sources_are_editable = sources_are_editable &&
734 !e_client_is_readonly (E_CLIENT (comp_data->client));
736 g_slist_free (list);
738 target_list = e_selectable_get_paste_target_list (selectable);
739 for (ii = 0; ii < n_clipboard_targets && !can_paste; ii++)
740 can_paste = gtk_target_list_find (
741 target_list, clipboard_targets[ii], NULL);
743 action = e_focus_tracker_get_cut_clipboard_action (focus_tracker);
744 sensitive = (n_selected > 0) && sources_are_editable && !is_editing;
745 tooltip = _("Cut selected memos to the clipboard");
746 gtk_action_set_sensitive (action, sensitive);
747 gtk_action_set_tooltip (action, tooltip);
749 action = e_focus_tracker_get_copy_clipboard_action (focus_tracker);
750 sensitive = (n_selected > 0) && !is_editing;
751 tooltip = _("Copy selected memos to the clipboard");
752 gtk_action_set_sensitive (action, sensitive);
753 gtk_action_set_tooltip (action, tooltip);
755 action = e_focus_tracker_get_paste_clipboard_action (focus_tracker);
756 sensitive = sources_are_editable && can_paste && !is_editing;
757 tooltip = _("Paste memos from the clipboard");
758 gtk_action_set_sensitive (action, sensitive);
759 gtk_action_set_tooltip (action, tooltip);
761 action = e_focus_tracker_get_delete_selection_action (focus_tracker);
762 sensitive = (n_selected > 0) && sources_are_editable && !is_editing;
763 tooltip = _("Delete selected memos");
764 gtk_action_set_sensitive (action, sensitive);
765 gtk_action_set_tooltip (action, tooltip);
767 action = e_focus_tracker_get_select_all_action (focus_tracker);
768 sensitive = TRUE;
769 tooltip = _("Select all visible memos");
770 gtk_action_set_sensitive (action, sensitive);
771 gtk_action_set_tooltip (action, tooltip);
774 static void
775 memo_table_cut_clipboard (ESelectable *selectable)
777 EMemoTable *memo_table;
779 memo_table = E_MEMO_TABLE (selectable);
781 e_selectable_copy_clipboard (selectable);
782 delete_selected_components (memo_table);
785 /* Helper for memo_table_copy_clipboard() */
786 static void
787 copy_row_cb (gint model_row,
788 gpointer data)
790 EMemoTable *memo_table;
791 ECalModelComponent *comp_data;
792 ECalModel *model;
793 gchar *comp_str;
794 icalcomponent *child;
796 memo_table = E_MEMO_TABLE (data);
798 g_return_if_fail (memo_table->tmp_vcal != NULL);
800 model = e_memo_table_get_model (memo_table);
801 comp_data = e_cal_model_get_component_at (model, model_row);
802 if (comp_data == NULL)
803 return;
805 /* Add timezones to the VCALENDAR component. */
806 e_cal_util_add_timezones_from_component (
807 memo_table->tmp_vcal, comp_data->icalcomp);
809 /* Add the new component to the VCALENDAR component. */
810 comp_str = icalcomponent_as_ical_string_r (comp_data->icalcomp);
811 child = icalparser_parse_string (comp_str);
812 if (child) {
813 icalcomponent_add_component (
814 memo_table->tmp_vcal,
815 icalcomponent_new_clone (child));
816 icalcomponent_free (child);
818 g_free (comp_str);
821 static void
822 memo_table_copy_clipboard (ESelectable *selectable)
824 EMemoTable *memo_table;
825 GtkClipboard *clipboard;
826 gchar *comp_str;
828 memo_table = E_MEMO_TABLE (selectable);
830 /* Create a temporary VCALENDAR object. */
831 memo_table->tmp_vcal = e_cal_util_new_top_level ();
833 e_table_selected_row_foreach (
834 E_TABLE (memo_table), copy_row_cb, memo_table);
835 comp_str = icalcomponent_as_ical_string_r (memo_table->tmp_vcal);
837 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
838 e_clipboard_set_calendar (clipboard, comp_str, -1);
839 gtk_clipboard_store (clipboard);
841 g_free (comp_str);
843 icalcomponent_free (memo_table->tmp_vcal);
844 memo_table->tmp_vcal = NULL;
847 static void
848 memo_table_paste_clipboard (ESelectable *selectable)
850 EMemoTable *memo_table;
851 GtkClipboard *clipboard;
852 GnomeCanvasItem *item;
853 GnomeCanvas *table_canvas;
855 memo_table = E_MEMO_TABLE (selectable);
857 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
859 table_canvas = E_TABLE (memo_table)->table_canvas;
860 item = table_canvas->focused_item;
862 /* XXX Should ECellText implement GtkEditable? */
864 /* Paste text into a cell being edited. */
865 if (gtk_clipboard_wait_is_text_available (clipboard) &&
866 gtk_widget_has_focus (GTK_WIDGET (table_canvas)) &&
867 E_IS_TABLE_ITEM (item) &&
868 E_TABLE_ITEM (item)->editing_col >= 0 &&
869 E_TABLE_ITEM (item)->editing_row >= 0) {
871 ETableItem *etable_item = E_TABLE_ITEM (item);
873 e_cell_text_paste_clipboard (
874 etable_item->cell_views[etable_item->editing_col],
875 etable_item->editing_col,
876 etable_item->editing_row);
878 /* Paste iCalendar data into the table. */
879 } else if (e_clipboard_wait_is_calendar_available (clipboard)) {
880 ECalModel *model;
881 gchar *ical_str;
883 model = e_memo_table_get_model (memo_table);
885 ical_str = e_clipboard_wait_for_calendar (clipboard);
886 e_cal_ops_paste_components (model, ical_str);
887 g_free (ical_str);
891 /* Used from e_table_selected_row_foreach(); puts the selected row number in an
892 * gint pointed to by the closure data.
894 static void
895 get_selected_row_cb (gint model_row,
896 gpointer data)
898 gint *row;
900 row = data;
901 *row = model_row;
905 * Returns the component that is selected in the table; only works if there is
906 * one and only one selected row.
908 static ECalModelComponent *
909 get_selected_comp (EMemoTable *memo_table)
911 ECalModel *model;
912 gint row;
914 model = e_memo_table_get_model (memo_table);
915 if (e_table_selected_count (E_TABLE (memo_table)) != 1)
916 return NULL;
918 row = -1;
919 e_table_selected_row_foreach (
920 E_TABLE (memo_table), get_selected_row_cb, &row);
921 g_return_val_if_fail (row != -1, NULL);
923 return e_cal_model_get_component_at (model, row);
926 static void
927 memo_table_delete_selection (ESelectable *selectable)
929 ECalModel *model;
930 EMemoTable *memo_table;
931 ECalComponent *comp = NULL;
932 ECalModelComponent *comp_data;
933 gboolean delete = TRUE;
934 gint n_selected;
936 memo_table = E_MEMO_TABLE (selectable);
937 model = e_memo_table_get_model (memo_table);
939 n_selected = e_table_selected_count (E_TABLE (memo_table));
940 if (n_selected <= 0)
941 return;
943 if (n_selected == 1)
944 comp_data = get_selected_comp (memo_table);
945 else
946 comp_data = NULL;
948 /* FIXME: this may be something other than a TODO component */
950 if (comp_data) {
951 comp = e_cal_component_new ();
952 e_cal_component_set_icalcomponent (
953 comp, icalcomponent_new_clone (comp_data->icalcomp));
956 if (e_cal_model_get_confirm_delete (model))
957 delete = e_cal_dialogs_delete_component (
958 comp, FALSE, n_selected,
959 E_CAL_COMPONENT_JOURNAL,
960 GTK_WIDGET (memo_table));
962 if (delete)
963 delete_selected_components (memo_table);
965 /* free memory */
966 if (comp)
967 g_object_unref (comp);
970 static void
971 memo_table_select_all (ESelectable *selectable)
973 e_table_select_all (E_TABLE (selectable));
976 static void
977 e_memo_table_class_init (EMemoTableClass *class)
979 GObjectClass *object_class;
980 GtkWidgetClass *widget_class;
981 ETableClass *table_class;
983 g_type_class_add_private (class, sizeof (EMemoTablePrivate));
985 object_class = G_OBJECT_CLASS (class);
986 object_class->set_property = memo_table_set_property;
987 object_class->get_property = memo_table_get_property;
988 object_class->dispose = memo_table_dispose;
989 object_class->constructed = memo_table_constructed;
991 widget_class = GTK_WIDGET_CLASS (class);
992 widget_class->popup_menu = memo_table_popup_menu;
993 widget_class->query_tooltip = memo_table_query_tooltip;
995 table_class = E_TABLE_CLASS (class);
996 table_class->double_click = memo_table_double_click;
997 table_class->right_click = memo_table_right_click;
998 table_class->white_space_event = memo_table_white_space_event;
1000 /* Inherited from ESelectableInterface */
1001 g_object_class_override_property (
1002 object_class,
1003 PROP_COPY_TARGET_LIST,
1004 "copy-target-list");
1006 g_object_class_install_property (
1007 object_class,
1008 PROP_MODEL,
1009 g_param_spec_object (
1010 "model",
1011 "Model",
1012 NULL,
1013 E_TYPE_CAL_MODEL,
1014 G_PARAM_READWRITE |
1015 G_PARAM_CONSTRUCT_ONLY));
1017 /* Inherited from ESelectableInterface */
1018 g_object_class_override_property (
1019 object_class,
1020 PROP_PASTE_TARGET_LIST,
1021 "paste-target-list");
1023 g_object_class_install_property (
1024 object_class,
1025 PROP_SHELL_VIEW,
1026 g_param_spec_object (
1027 "shell-view",
1028 "Shell View",
1029 NULL,
1030 E_TYPE_SHELL_VIEW,
1031 G_PARAM_READWRITE |
1032 G_PARAM_CONSTRUCT_ONLY));
1034 signals[OPEN_COMPONENT] = g_signal_new (
1035 "open-component",
1036 G_TYPE_FROM_CLASS (class),
1037 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1038 G_STRUCT_OFFSET (EMemoTableClass, open_component),
1039 NULL, NULL,
1040 g_cclosure_marshal_VOID__OBJECT,
1041 G_TYPE_NONE, 1,
1042 E_TYPE_CAL_MODEL_COMPONENT);
1044 signals[POPUP_EVENT] = g_signal_new (
1045 "popup-event",
1046 G_TYPE_FROM_CLASS (class),
1047 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1048 G_STRUCT_OFFSET (EMemoTableClass, popup_event),
1049 NULL, NULL,
1050 g_cclosure_marshal_VOID__BOXED,
1051 G_TYPE_NONE, 1,
1052 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1055 static void
1056 e_memo_table_init (EMemoTable *memo_table)
1058 GtkTargetList *target_list;
1060 memo_table->priv = E_MEMO_TABLE_GET_PRIVATE (memo_table);
1062 target_list = gtk_target_list_new (NULL, 0);
1063 e_target_list_add_calendar_targets (target_list, 0);
1064 memo_table->priv->copy_target_list = target_list;
1066 target_list = gtk_target_list_new (NULL, 0);
1067 e_target_list_add_calendar_targets (target_list, 0);
1068 memo_table->priv->paste_target_list = target_list;
1071 static void
1072 e_memo_table_selectable_init (ESelectableInterface *iface)
1074 iface->update_actions = memo_table_update_actions;
1075 iface->cut_clipboard = memo_table_cut_clipboard;
1076 iface->copy_clipboard = memo_table_copy_clipboard;
1077 iface->paste_clipboard = memo_table_paste_clipboard;
1078 iface->delete_selection = memo_table_delete_selection;
1079 iface->select_all = memo_table_select_all;
1083 * e_memo_table_new:
1084 * @shell_view: an #EShellView
1085 * @model: an #ECalModel for the table
1087 * Returns a new #EMemoTable.
1089 * Returns: a new #EMemoTable
1091 GtkWidget *
1092 e_memo_table_new (EShellView *shell_view,
1093 ECalModel *model)
1095 g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
1096 g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
1098 return g_object_new (
1099 E_TYPE_MEMO_TABLE,
1100 "model", model, "shell-view", shell_view, NULL);
1104 * e_memo_table_get_model:
1105 * @memo_table: A calendar table.
1107 * Queries the calendar data model that a calendar table is using.
1109 * Return value: A memo model.
1111 ECalModel *
1112 e_memo_table_get_model (EMemoTable *memo_table)
1114 g_return_val_if_fail (memo_table != NULL, NULL);
1115 g_return_val_if_fail (E_IS_MEMO_TABLE (memo_table), NULL);
1117 return memo_table->priv->model;
1120 EShellView *
1121 e_memo_table_get_shell_view (EMemoTable *memo_table)
1123 g_return_val_if_fail (E_IS_MEMO_TABLE (memo_table), NULL);
1125 return memo_table->priv->shell_view;
1128 struct get_selected_uids_closure {
1129 EMemoTable *memo_table;
1130 GSList *objects;
1133 /* Used from e_table_selected_row_foreach(), builds a list of the selected UIDs */
1134 static void
1135 add_uid_cb (gint model_row,
1136 gpointer data)
1138 struct get_selected_uids_closure *closure;
1139 ECalModelComponent *comp_data;
1140 ECalModel *model;
1142 closure = data;
1144 model = e_memo_table_get_model (closure->memo_table);
1145 comp_data = e_cal_model_get_component_at (model, model_row);
1147 closure->objects = g_slist_prepend (closure->objects, comp_data);
1151 * e_memo_table_get_selected:
1152 * @memo_table:
1154 * Get the currently selected ECalModelComponent's on the table.
1156 * Return value: A GSList of the components, which should be
1157 * g_slist_free'd when finished with.
1159 GSList *
1160 e_memo_table_get_selected (EMemoTable *memo_table)
1162 struct get_selected_uids_closure closure;
1164 closure.memo_table = memo_table;
1165 closure.objects = NULL;
1167 e_table_selected_row_foreach (
1168 E_TABLE (memo_table), add_uid_cb, &closure);
1170 return closure.objects;
1173 GtkTargetList *
1174 e_memo_table_get_copy_target_list (EMemoTable *memo_table)
1176 g_return_val_if_fail (E_IS_MEMO_TABLE (memo_table), NULL);
1178 return memo_table->priv->copy_target_list;
1181 GtkTargetList *
1182 e_memo_table_get_paste_target_list (EMemoTable *memo_table)
1184 g_return_val_if_fail (E_IS_MEMO_TABLE (memo_table), NULL);
1186 return memo_table->priv->paste_target_list;