2 * e-attachment-icon-view.c
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
25 #include "e-attachment-icon-view.h"
27 #include <glib/gi18n.h>
28 #include <libebackend/libebackend.h>
30 #include "e-attachment.h"
31 #include "e-attachment-store.h"
32 #include "e-attachment-view.h"
34 #define E_ATTACHMENT_ICON_VIEW_GET_PRIVATE(obj) \
35 (G_TYPE_INSTANCE_GET_PRIVATE \
36 ((obj), E_TYPE_ATTACHMENT_ICON_VIEW, EAttachmentIconViewPrivate))
38 struct _EAttachmentIconViewPrivate
{
39 EAttachmentViewPrivate view_priv
;
48 static gint icon_size
= GTK_ICON_SIZE_DIALOG
;
50 /* Forward Declarations */
51 static void e_attachment_icon_view_interface_init
52 (EAttachmentViewInterface
*iface
);
54 G_DEFINE_TYPE_WITH_CODE (
56 e_attachment_icon_view
,
58 G_IMPLEMENT_INTERFACE (
59 E_TYPE_ATTACHMENT_VIEW
,
60 e_attachment_icon_view_interface_init
)
61 G_IMPLEMENT_INTERFACE (
62 E_TYPE_EXTENSIBLE
, NULL
))
65 e_attachment_icon_view_set_default_icon_size (gint size
)
71 attachment_icon_view_set_property (GObject
*object
,
76 switch (property_id
) {
78 e_attachment_view_set_dragging (
79 E_ATTACHMENT_VIEW (object
),
80 g_value_get_boolean (value
));
84 e_attachment_view_set_editable (
85 E_ATTACHMENT_VIEW (object
),
86 g_value_get_boolean (value
));
90 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
94 attachment_icon_view_get_property (GObject
*object
,
99 switch (property_id
) {
101 g_value_set_boolean (
102 value
, e_attachment_view_get_dragging (
103 E_ATTACHMENT_VIEW (object
)));
107 g_value_set_boolean (
108 value
, e_attachment_view_get_editable (
109 E_ATTACHMENT_VIEW (object
)));
113 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
117 attachment_icon_view_dispose (GObject
*object
)
119 e_attachment_view_dispose (E_ATTACHMENT_VIEW (object
));
121 /* Chain up to parent's dispose() method. */
122 G_OBJECT_CLASS (e_attachment_icon_view_parent_class
)->dispose (object
);
126 attachment_icon_view_finalize (GObject
*object
)
128 e_attachment_view_finalize (E_ATTACHMENT_VIEW (object
));
130 /* Chain up to parent's finalize() method. */
131 G_OBJECT_CLASS (e_attachment_icon_view_parent_class
)->finalize (object
);
135 attachment_icon_view_constructed (GObject
*object
)
137 GtkCellLayout
*cell_layout
;
138 GtkCellRenderer
*renderer
;
140 /* Chain up to parent's method. */
141 G_OBJECT_CLASS (e_attachment_icon_view_parent_class
)->constructed (object
);
143 cell_layout
= GTK_CELL_LAYOUT (object
);
145 /* This needs to happen after constructor properties are set
146 * so that GtkCellLayout.get_area() returns something valid. */
148 renderer
= gtk_cell_renderer_pixbuf_new ();
149 g_object_set (renderer
, "stock-size", icon_size
, NULL
);
150 gtk_cell_layout_pack_start (cell_layout
, renderer
, FALSE
);
152 gtk_cell_layout_add_attribute (
153 cell_layout
, renderer
, "gicon",
154 E_ATTACHMENT_STORE_COLUMN_ICON
);
156 renderer
= gtk_cell_renderer_text_new ();
158 renderer
, "alignment", PANGO_ALIGN_CENTER
,
159 "wrap-mode", PANGO_WRAP_WORD
, "wrap-width", 150,
160 "yalign", 0.0, NULL
);
161 gtk_cell_layout_pack_start (cell_layout
, renderer
, FALSE
);
163 gtk_cell_layout_add_attribute (
164 cell_layout
, renderer
, "text",
165 E_ATTACHMENT_STORE_COLUMN_CAPTION
);
167 renderer
= gtk_cell_renderer_progress_new ();
168 g_object_set (renderer
, "text", _("Loading"), NULL
);
169 gtk_cell_layout_pack_start (cell_layout
, renderer
, TRUE
);
171 gtk_cell_layout_add_attribute (
172 cell_layout
, renderer
, "value",
173 E_ATTACHMENT_STORE_COLUMN_PERCENT
);
175 gtk_cell_layout_add_attribute (
176 cell_layout
, renderer
, "visible",
177 E_ATTACHMENT_STORE_COLUMN_LOADING
);
179 renderer
= gtk_cell_renderer_progress_new ();
180 g_object_set (renderer
, "text", _("Saving"), NULL
);
181 gtk_cell_layout_pack_start (cell_layout
, renderer
, TRUE
);
183 gtk_cell_layout_add_attribute (
184 cell_layout
, renderer
, "value",
185 E_ATTACHMENT_STORE_COLUMN_PERCENT
);
187 gtk_cell_layout_add_attribute (
188 cell_layout
, renderer
, "visible",
189 E_ATTACHMENT_STORE_COLUMN_SAVING
);
191 e_extensible_load_extensions (E_EXTENSIBLE (object
));
195 attachment_icon_view_button_press_event (GtkWidget
*widget
,
196 GdkEventButton
*event
)
198 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
200 if (!e_attachment_view_button_press_event (view
, event
)) {
201 /* Chain up to parent's button_press_event() method. */
202 GTK_WIDGET_CLASS (e_attachment_icon_view_parent_class
)->
203 button_press_event (widget
, event
);
206 /* Never propagate the event to the parent */
211 attachment_icon_view_button_release_event (GtkWidget
*widget
,
212 GdkEventButton
*event
)
214 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
216 if (!e_attachment_view_button_release_event (view
, event
)) {
217 /* Chain up to parent's button_release_event() method. */
218 GTK_WIDGET_CLASS (e_attachment_icon_view_parent_class
)->
219 button_release_event (widget
, event
);
222 /* Never propagate the event to the parent */
227 attachment_icon_view_motion_notify_event (GtkWidget
*widget
,
228 GdkEventMotion
*event
)
230 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
232 if (!e_attachment_view_motion_notify_event (view
, event
)) {
233 /* Chain up to parent's motion_notify_event() method. */
234 GTK_WIDGET_CLASS (e_attachment_icon_view_parent_class
)->
235 motion_notify_event (widget
, event
);
238 /* Never propagate the event to the parent */
243 attachment_icon_view_key_press_event (GtkWidget
*widget
,
246 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
248 if (e_attachment_view_key_press_event (view
, event
))
251 /* Chain up to parent's key_press_event() method. */
252 return GTK_WIDGET_CLASS (e_attachment_icon_view_parent_class
)->
253 key_press_event (widget
, event
);
257 attachment_icon_view_drag_begin (GtkWidget
*widget
,
258 GdkDragContext
*context
)
260 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
262 /* Chain up to parent's drag_begin() method. */
263 GTK_WIDGET_CLASS (e_attachment_icon_view_parent_class
)->
264 drag_begin (widget
, context
);
266 e_attachment_view_drag_begin (view
, context
);
270 attachment_icon_view_drag_end (GtkWidget
*widget
,
271 GdkDragContext
*context
)
273 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
275 /* Chain up to parent's drag_end() method. */
276 GTK_WIDGET_CLASS (e_attachment_icon_view_parent_class
)->
277 drag_end (widget
, context
);
279 e_attachment_view_drag_end (view
, context
);
283 attachment_icon_view_drag_data_get (GtkWidget
*widget
,
284 GdkDragContext
*context
,
285 GtkSelectionData
*selection
,
289 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
291 e_attachment_view_drag_data_get (
292 view
, context
, selection
, info
, time
);
296 attachment_icon_view_drag_motion (GtkWidget
*widget
,
297 GdkDragContext
*context
,
302 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
304 return e_attachment_view_drag_motion (view
, context
, x
, y
, time
);
308 attachment_icon_view_drag_drop (GtkWidget
*widget
,
309 GdkDragContext
*context
,
314 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
316 if (!e_attachment_view_drag_drop (view
, context
, x
, y
, time
))
319 /* Chain up to parent's drag_drop() method. */
320 return GTK_WIDGET_CLASS (e_attachment_icon_view_parent_class
)->
321 drag_drop (widget
, context
, x
, y
, time
);
325 attachment_icon_view_drag_data_received (GtkWidget
*widget
,
326 GdkDragContext
*context
,
329 GtkSelectionData
*selection
,
333 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
335 e_attachment_view_drag_data_received (
336 view
, context
, x
, y
, selection
, info
, time
);
340 attachment_icon_view_popup_menu (GtkWidget
*widget
)
342 EAttachmentView
*view
= E_ATTACHMENT_VIEW (widget
);
344 e_attachment_view_show_popup_menu (view
, NULL
, NULL
, NULL
);
350 attachment_icon_view_item_activated (GtkIconView
*icon_view
,
353 EAttachmentView
*view
= E_ATTACHMENT_VIEW (icon_view
);
355 e_attachment_view_open_path (view
, path
, NULL
);
358 static EAttachmentViewPrivate
*
359 attachment_icon_view_get_private (EAttachmentView
*view
)
361 EAttachmentIconViewPrivate
*priv
;
363 priv
= E_ATTACHMENT_ICON_VIEW_GET_PRIVATE (view
);
365 return &priv
->view_priv
;
368 static EAttachmentStore
*
369 attachment_icon_view_get_store (EAttachmentView
*view
)
371 GtkIconView
*icon_view
;
374 icon_view
= GTK_ICON_VIEW (view
);
375 model
= gtk_icon_view_get_model (icon_view
);
377 return E_ATTACHMENT_STORE (model
);
381 attachment_icon_view_get_path_at_pos (EAttachmentView
*view
,
385 GtkIconView
*icon_view
;
387 icon_view
= GTK_ICON_VIEW (view
);
389 return gtk_icon_view_get_path_at_pos (icon_view
, x
, y
);
393 attachment_icon_view_get_selected_paths (EAttachmentView
*view
)
395 GtkIconView
*icon_view
;
397 icon_view
= GTK_ICON_VIEW (view
);
399 return gtk_icon_view_get_selected_items (icon_view
);
403 attachment_icon_view_path_is_selected (EAttachmentView
*view
,
406 GtkIconView
*icon_view
;
408 icon_view
= GTK_ICON_VIEW (view
);
410 return gtk_icon_view_path_is_selected (icon_view
, path
);
414 attachment_icon_view_select_path (EAttachmentView
*view
,
417 GtkIconView
*icon_view
;
419 icon_view
= GTK_ICON_VIEW (view
);
421 gtk_icon_view_select_path (icon_view
, path
);
425 attachment_icon_view_unselect_path (EAttachmentView
*view
,
428 GtkIconView
*icon_view
;
430 icon_view
= GTK_ICON_VIEW (view
);
432 gtk_icon_view_unselect_path (icon_view
, path
);
436 attachment_icon_view_select_all (EAttachmentView
*view
)
438 GtkIconView
*icon_view
;
440 icon_view
= GTK_ICON_VIEW (view
);
442 gtk_icon_view_select_all (icon_view
);
446 attachment_icon_view_unselect_all (EAttachmentView
*view
)
448 GtkIconView
*icon_view
;
450 icon_view
= GTK_ICON_VIEW (view
);
452 gtk_icon_view_unselect_all (icon_view
);
456 attachment_icon_view_drag_source_set (EAttachmentView
*view
,
457 GdkModifierType start_button_mask
,
458 const GtkTargetEntry
*targets
,
460 GdkDragAction actions
)
462 GtkIconView
*icon_view
;
464 icon_view
= GTK_ICON_VIEW (view
);
466 gtk_icon_view_enable_model_drag_source (
467 icon_view
, start_button_mask
, targets
, n_targets
, actions
);
471 attachment_icon_view_drag_dest_set (EAttachmentView
*view
,
472 const GtkTargetEntry
*targets
,
474 GdkDragAction actions
)
476 GtkIconView
*icon_view
;
478 icon_view
= GTK_ICON_VIEW (view
);
480 gtk_icon_view_enable_model_drag_dest (
481 icon_view
, targets
, n_targets
, actions
);
485 attachment_icon_view_drag_source_unset (EAttachmentView
*view
)
487 GtkIconView
*icon_view
;
489 icon_view
= GTK_ICON_VIEW (view
);
491 gtk_icon_view_unset_model_drag_source (icon_view
);
495 attachment_icon_view_drag_dest_unset (EAttachmentView
*view
)
497 GtkIconView
*icon_view
;
499 icon_view
= GTK_ICON_VIEW (view
);
501 gtk_icon_view_unset_model_drag_dest (icon_view
);
505 e_attachment_icon_view_class_init (EAttachmentIconViewClass
*class)
507 GObjectClass
*object_class
;
508 GtkWidgetClass
*widget_class
;
509 GtkIconViewClass
*icon_view_class
;
511 g_type_class_add_private (class, sizeof (EAttachmentViewPrivate
));
513 object_class
= G_OBJECT_CLASS (class);
514 object_class
->set_property
= attachment_icon_view_set_property
;
515 object_class
->get_property
= attachment_icon_view_get_property
;
516 object_class
->dispose
= attachment_icon_view_dispose
;
517 object_class
->finalize
= attachment_icon_view_finalize
;
518 object_class
->constructed
= attachment_icon_view_constructed
;
520 widget_class
= GTK_WIDGET_CLASS (class);
521 widget_class
->button_press_event
= attachment_icon_view_button_press_event
;
522 widget_class
->button_release_event
= attachment_icon_view_button_release_event
;
523 widget_class
->motion_notify_event
= attachment_icon_view_motion_notify_event
;
524 widget_class
->key_press_event
= attachment_icon_view_key_press_event
;
525 widget_class
->drag_begin
= attachment_icon_view_drag_begin
;
526 widget_class
->drag_end
= attachment_icon_view_drag_end
;
527 widget_class
->drag_data_get
= attachment_icon_view_drag_data_get
;
528 widget_class
->drag_motion
= attachment_icon_view_drag_motion
;
529 widget_class
->drag_drop
= attachment_icon_view_drag_drop
;
530 widget_class
->drag_data_received
= attachment_icon_view_drag_data_received
;
531 widget_class
->popup_menu
= attachment_icon_view_popup_menu
;
533 icon_view_class
= GTK_ICON_VIEW_CLASS (class);
534 icon_view_class
->item_activated
= attachment_icon_view_item_activated
;
536 g_object_class_override_property (
537 object_class
, PROP_DRAGGING
, "dragging");
539 g_object_class_override_property (
540 object_class
, PROP_EDITABLE
, "editable");
544 e_attachment_icon_view_init (EAttachmentIconView
*icon_view
)
546 icon_view
->priv
= E_ATTACHMENT_ICON_VIEW_GET_PRIVATE (icon_view
);
548 e_attachment_view_init (E_ATTACHMENT_VIEW (icon_view
));
550 gtk_icon_view_set_selection_mode (
551 GTK_ICON_VIEW (icon_view
), GTK_SELECTION_MULTIPLE
);
555 e_attachment_icon_view_interface_init (EAttachmentViewInterface
*iface
)
557 iface
->get_private
= attachment_icon_view_get_private
;
558 iface
->get_store
= attachment_icon_view_get_store
;
560 iface
->get_path_at_pos
= attachment_icon_view_get_path_at_pos
;
561 iface
->get_selected_paths
= attachment_icon_view_get_selected_paths
;
562 iface
->path_is_selected
= attachment_icon_view_path_is_selected
;
563 iface
->select_path
= attachment_icon_view_select_path
;
564 iface
->unselect_path
= attachment_icon_view_unselect_path
;
565 iface
->select_all
= attachment_icon_view_select_all
;
566 iface
->unselect_all
= attachment_icon_view_unselect_all
;
568 iface
->drag_source_set
= attachment_icon_view_drag_source_set
;
569 iface
->drag_dest_set
= attachment_icon_view_drag_dest_set
;
570 iface
->drag_source_unset
= attachment_icon_view_drag_source_unset
;
571 iface
->drag_dest_unset
= attachment_icon_view_drag_dest_unset
;
575 e_attachment_icon_view_new (void)
577 return g_object_new (E_TYPE_ATTACHMENT_ICON_VIEW
, NULL
);