aboutsummaryrefslogblamecommitdiffstats
path: root/widgets/misc/e-attachment-icon-view.c
blob: edfecb57d883b99cc97afd17f03f4c78d6cd7ff1 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460













                                                                    
                                                                             


























                                                                         
                                             

                             
    
                                                        



                         
























































































































































































































































































































































































































                                                                                       
                                                               


















































































                                                                             
/*
 * e-attachment-icon-view.c
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#include "e-attachment-icon-view.h"

#include <glib/gi18n.h>

#include "e-attachment.h"
#include "e-attachment-store.h"
#include "e-attachment-view.h"

#define E_ATTACHMENT_ICON_VIEW_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_ATTACHMENT_ICON_VIEW, EAttachmentIconViewPrivate))

struct _EAttachmentIconViewPrivate {
    EAttachmentViewPrivate view_priv;
};

enum {
    PROP_0,
    PROP_EDITABLE
};

static gint icon_size = GTK_ICON_SIZE_DIALOG;
static gpointer parent_class;

void
e_attachment_icon_view_set_default_icon_size (gint size)
{
    icon_size = size;
}

static void
attachment_icon_view_set_property (GObject *object,
                                   guint property_id,
                                   const GValue *value,
                                   GParamSpec *pspec)
{
    switch (property_id) {
        case PROP_EDITABLE:
            e_attachment_view_set_editable (
                E_ATTACHMENT_VIEW (object),
                g_value_get_boolean (value));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
attachment_icon_view_get_property (GObject *object,
                                   guint property_id,
                                   GValue *value,
                                   GParamSpec *pspec)
{
    switch (property_id) {
        case PROP_EDITABLE:
            g_value_set_boolean (
                value, e_attachment_view_get_editable (
                E_ATTACHMENT_VIEW (object)));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
attachment_icon_view_dispose (GObject *object)
{
    e_attachment_view_dispose (E_ATTACHMENT_VIEW (object));

    /* Chain up to parent's dispose() method. */
    G_OBJECT_CLASS (parent_class)->dispose (object);
}

static void
attachment_icon_view_finalize (GObject *object)
{
    e_attachment_view_finalize (E_ATTACHMENT_VIEW (object));

    /* Chain up to parent's finalize() method. */
    G_OBJECT_CLASS (parent_class)->finalize (object);
}

static gboolean
attachment_icon_view_button_press_event (GtkWidget *widget,
                                         GdkEventButton *event)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (widget);

    if (e_attachment_view_button_press_event (view, event))
        return TRUE;

    /* Chain up to parent's button_press_event() method. */
    return GTK_WIDGET_CLASS (parent_class)->
        button_press_event (widget, event);
}

static gboolean
attachment_icon_view_button_release_event (GtkWidget *widget,
                                           GdkEventButton *event)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (widget);

    if (e_attachment_view_button_release_event (view, event))
        return TRUE;

    /* Chain up to parent's button_release_event() method. */
    return GTK_WIDGET_CLASS (parent_class)->
        button_release_event (widget, event);
}

static gboolean
attachment_icon_view_key_press_event (GtkWidget *widget,
                                      GdkEventKey *event)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (widget);

    if (e_attachment_view_key_press_event (view, event))
        return TRUE;

    /* Chain up to parent's key_press_event() method. */
    return GTK_WIDGET_CLASS (parent_class)->
        key_press_event (widget, event);
}

static void
attachment_icon_view_drag_begin (GtkWidget *widget,
                                 GdkDragContext *context)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (widget);

    /* Chain up to parent's drag_begin() method. */
    GTK_WIDGET_CLASS (parent_class)->drag_begin (widget, context);

    e_attachment_view_drag_begin (view, context);
}

static void
attachment_icon_view_drag_end (GtkWidget *widget,
                               GdkDragContext *context)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (widget);

    /* Chain up to parent's drag_end() method. */
    GTK_WIDGET_CLASS (parent_class)->drag_end (widget, context);

    e_attachment_view_drag_end (view, context);
}

static void
attachment_icon_view_drag_data_get (GtkWidget *widget,
                                    GdkDragContext *context,
                                    GtkSelectionData *selection,
                                    guint info,
                                    guint time)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (widget);

    e_attachment_view_drag_data_get (
        view, context, selection, info, time);
}

static gboolean
attachment_icon_view_drag_motion (GtkWidget *widget,
                                  GdkDragContext *context,
                                  gint x,
                                  gint y,
                                  guint time)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (widget);

    return e_attachment_view_drag_motion (view, context, x, y, time);
}

static gboolean
attachment_icon_view_drag_drop (GtkWidget *widget,
                                GdkDragContext *context,
                                gint x,
                                gint y,
                                guint time)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (widget);

    if (!e_attachment_view_drag_drop (view, context, x, y, time))
        return FALSE;

    /* Chain up to parent's drag_drop() method. */
    return GTK_WIDGET_CLASS (parent_class)->drag_drop (
        widget, context, x, y, time);
}

static void
attachment_icon_view_drag_data_received (GtkWidget *widget,
                                         GdkDragContext *context,
                                         gint x,
                                         gint y,
                                         GtkSelectionData *selection,
                                         guint info,
                                         guint time)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (widget);

    e_attachment_view_drag_data_received (
        view, context, x, y, selection, info, time);
}

static gboolean
attachment_icon_view_popup_menu (GtkWidget *widget)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (widget);

    e_attachment_view_show_popup_menu (view, NULL, NULL, NULL);

    return TRUE;
}

static void
attachment_icon_view_item_activated (GtkIconView *icon_view,
                                     GtkTreePath *path)
{
    EAttachmentView *view = E_ATTACHMENT_VIEW (icon_view);

    e_attachment_view_open_path (view, path, NULL);
}

static EAttachmentViewPrivate *
attachment_icon_view_get_private (EAttachmentView *view)
{
    EAttachmentIconViewPrivate *priv;

    priv = E_ATTACHMENT_ICON_VIEW_GET_PRIVATE (view);

    return &priv->view_priv;
}

static EAttachmentStore *
attachment_icon_view_get_store (EAttachmentView *view)
{
    GtkIconView *icon_view;
    GtkTreeModel *model;

    icon_view = GTK_ICON_VIEW (view);
    model = gtk_icon_view_get_model (icon_view);

    return E_ATTACHMENT_STORE (model);
}

static GtkTreePath *
attachment_icon_view_get_path_at_pos (EAttachmentView *view,
                                      gint x,
                                      gint y)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    return gtk_icon_view_get_path_at_pos (icon_view, x, y);
}

static GList *
attachment_icon_view_get_selected_paths (EAttachmentView *view)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    return gtk_icon_view_get_selected_items (icon_view);
}

static gboolean
attachment_icon_view_path_is_selected (EAttachmentView *view,
                                       GtkTreePath *path)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    return gtk_icon_view_path_is_selected (icon_view, path);
}

static void
attachment_icon_view_select_path (EAttachmentView *view,
                                  GtkTreePath *path)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    gtk_icon_view_select_path (icon_view, path);
}

static void
attachment_icon_view_unselect_path (EAttachmentView *view,
                                    GtkTreePath *path)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    gtk_icon_view_unselect_path (icon_view, path);
}

static void
attachment_icon_view_select_all (EAttachmentView *view)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    gtk_icon_view_select_all (icon_view);
}

static void
attachment_icon_view_unselect_all (EAttachmentView *view)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    gtk_icon_view_unselect_all (icon_view);
}

static void
attachment_icon_view_drag_source_set (EAttachmentView *view,
                                      GdkModifierType start_button_mask,
                                      const GtkTargetEntry *targets,
                                      gint n_targets,
                                      GdkDragAction actions)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    gtk_icon_view_enable_model_drag_source (
        icon_view, start_button_mask, targets, n_targets, actions);
}

static void
attachment_icon_view_drag_dest_set (EAttachmentView *view,
                                    const GtkTargetEntry *targets,
                                    gint n_targets,
                                    GdkDragAction actions)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    gtk_icon_view_enable_model_drag_dest (
        icon_view, targets, n_targets, actions);
}

static void
attachment_icon_view_drag_source_unset (EAttachmentView *view)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    gtk_icon_view_unset_model_drag_source (icon_view);
}

static void
attachment_icon_view_drag_dest_unset (EAttachmentView *view)
{
    GtkIconView *icon_view;

    icon_view = GTK_ICON_VIEW (view);

    gtk_icon_view_unset_model_drag_dest (icon_view);
}

static void
attachment_icon_view_class_init (EAttachmentIconViewClass *class)
{
    GObjectClass *object_class;
    GtkWidgetClass *widget_class;
    GtkIconViewClass *icon_view_class;

    parent_class = g_type_class_peek_parent (class);
    g_type_class_add_private (class, sizeof (EAttachmentViewPrivate));

    object_class = G_OBJECT_CLASS (class);
    object_class->set_property = attachment_icon_view_set_property;
    object_class->get_property = attachment_icon_view_get_property;
    object_class->dispose = attachment_icon_view_dispose;
    object_class->finalize = attachment_icon_view_finalize;

    widget_class = GTK_WIDGET_CLASS (class);
    widget_class->button_press_event = attachment_icon_view_button_press_event;
    widget_class->button_release_event = attachment_icon_view_button_release_event;
    widget_class->key_press_event = attachment_icon_view_key_press_event;
    widget_class->drag_begin = attachment_icon_view_drag_begin;
    widget_class->drag_end = attachment_icon_view_drag_end;
    widget_class->drag_data_get = attachment_icon_view_drag_data_get;
    widget_class->drag_motion = attachment_icon_view_drag_motion;
    widget_class->drag_drop = attachment_icon_view_drag_drop;
    widget_class->drag_data_received = attachment_icon_view_drag_data_received;
    widget_class->popup_menu = attachment_icon_view_popup_menu;

    icon_view_class = GTK_ICON_VIEW_CLASS (class);
    icon_view_class->item_activated = attachment_icon_view_item_activated;

    g_object_class_override_property (
        object_class, PROP_EDITABLE, "editable");
}

static void
attachment_icon_view_iface_init (EAttachmentViewIface *iface)
{
    iface->get_private = attachment_icon_view_get_private;
    iface->get_store = attachment_icon_view_get_store;

    iface->get_path_at_pos = attachment_icon_view_get_path_at_pos;
    iface->get_selected_paths = attachment_icon_view_get_selected_paths;
    iface->path_is_selected = attachment_icon_view_path_is_selected;
    iface->select_path = attachment_icon_view_select_path;
    iface->unselect_path = attachment_icon_view_unselect_path;
    iface->select_all = attachment_icon_view_select_all;
    iface->unselect_all = attachment_icon_view_unselect_all;

    iface->drag_source_set = attachment_icon_view_drag_source_set;
    iface->drag_dest_set = attachment_icon_view_drag_dest_set;
    iface->drag_source_unset = attachment_icon_view_drag_source_unset;
    iface->drag_dest_unset = attachment_icon_view_drag_dest_unset;
}

static void
attachment_icon_view_init (EAttachmentIconView *icon_view)
{
    GtkCellLayout *cell_layout;
    GtkCellRenderer *renderer;
    cell_layout = GTK_CELL_LAYOUT (icon_view);
    icon_view->priv = E_ATTACHMENT_ICON_VIEW_GET_PRIVATE (icon_view);

    e_attachment_view_init (E_ATTACHMENT_VIEW (icon_view));

    gtk_icon_view_set_selection_mode (
        GTK_ICON_VIEW (icon_view), GTK_SELECTION_MULTIPLE);

    renderer = gtk_cell_renderer_pixbuf_new ();
    g_object_set (renderer, "stock-size", icon_size, NULL);
    gtk_cell_layout_pack_start (cell_layout, renderer, FALSE);

    gtk_cell_layout_add_attribute (
        cell_layout, renderer, "gicon",
        E_ATTACHMENT_STORE_COLUMN_ICON);

    renderer = gtk_cell_renderer_text_new ();
    g_object_set (
        renderer, "alignment", PANGO_ALIGN_CENTER,
        "wrap-mode", PANGO_WRAP_WORD, "wrap-width", 150,
        "yalign", 0.0, NULL);
    gtk_cell_layout_pack_start (cell_layout, renderer, FALSE);

    gtk_cell_layout_add_attribute (
        cell_layout, renderer, "text",
        E_ATTACHMENT_STORE_COLUMN_CAPTION);

    renderer = gtk_cell_renderer_progress_new ();
    g_object_set (renderer, "text", _("Loading"), NULL);
    gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);

    gtk_cell_layout_add_attribute (
        cell_layout, renderer, "value",
        E_ATTACHMENT_STORE_COLUMN_PERCENT);

    gtk_cell_layout_add_attribute (
        cell_layout, renderer, "visible",
        E_ATTACHMENT_STORE_COLUMN_LOADING);

    renderer = gtk_cell_renderer_progress_new ();
    g_object_set (renderer, "text", _("Saving"), NULL);
    gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);

    gtk_cell_layout_add_attribute (
        cell_layout, renderer, "value",
        E_ATTACHMENT_STORE_COLUMN_PERCENT);

    gtk_cell_layout_add_attribute (
        cell_layout, renderer, "visible",
        E_ATTACHMENT_STORE_COLUMN_SAVING);
}

GType
e_attachment_icon_view_get_type (void)
{
    static GType type = 0;

    if (G_UNLIKELY (type == 0)) {
        static const GTypeInfo type_info = {
            sizeof (EAttachmentIconViewClass),
            (GBaseInitFunc) NULL,
            (GBaseFinalizeFunc) NULL,
            (GClassInitFunc) attachment_icon_view_class_init,
            (GClassFinalizeFunc) NULL,
            NULL,  /* class_data */
            sizeof (EAttachmentIconView),
            0,     /* n_preallocs */
            (GInstanceInitFunc) attachment_icon_view_init,
            NULL   /* value_table */
        };

        static const GInterfaceInfo iface_info = {
            (GInterfaceInitFunc) attachment_icon_view_iface_init,
            (GInterfaceFinalizeFunc) NULL,
            NULL   /* interface_data */
        };

        type = g_type_register_static (
            GTK_TYPE_ICON_VIEW, "EAttachmentIconView",
            &type_info, 0);

        g_type_add_interface_static (
            type, E_TYPE_ATTACHMENT_VIEW, &iface_info);
    }

    return type;
}

GtkWidget *
e_attachment_icon_view_new (void)
{
    return g_object_new (E_TYPE_ATTACHMENT_ICON_VIEW, NULL);
}