aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/shortcut-bar/e-shortcut-bar.c
blob: 2826f612d548befec224cf9bb607da497a37450d (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
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* 
 * Author : 
 *  Damon Chaplin <damon@helixcode.com>
 *
 * Copyright 1999, Helix Code, Inc.
 *
 * 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 Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

/*
 * EShortcutBar displays a vertical bar with a number of Groups, each of which
 * contains any number of icons. It is used on the left of the main application
 * window so users can easily access items such as folders and files.
 *
 * The architecture is a bit complicated. EShortcutBar is a sublass of
 * EGroupBar (which supports a number of groups with buttons to slide them
 * into view). EShortcutBar places an EIconBar widget in each group page,
 * which displays an icon and name for each shortcut.
 */

#include <config.h>
#include <string.h>
#include <gal/util/e-util.h>
#include "e-shortcut-bar.h"
#include "e-clipped-label.h"
#include "e-vscrolled-bar.h"

/* Drag and Drop stuff. */
enum {
    TARGET_SHORTCUT
};
static GtkTargetEntry target_table[] = {
    { "E-SHORTCUT",     0, TARGET_SHORTCUT }
};
static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);

gboolean   e_shortcut_bar_default_icon_loaded   = FALSE;
GdkPixbuf *e_shortcut_bar_default_icon      = NULL;
gchar     *e_shortcut_bar_default_icon_filename = "gnome-folder.png";

static void e_shortcut_bar_class_init       (EShortcutBarClass *class);
static void e_shortcut_bar_init         (EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_destroy      (GtkObject  *object);

static void e_shortcut_bar_disconnect_model (EShortcutBar   *shortcut_bar);

static void e_shortcut_bar_on_model_destroyed   (EShortcutModel *model,
                         EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_on_group_added   (EShortcutModel *model,
                         gint        group_num,
                         gchar      *group_name,
                         EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_on_group_removed (EShortcutModel *model,
                         gint        group_num,
                         EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_on_item_added    (EShortcutModel *model,
                         gint        group_num,
                         gint        item_num,
                         gchar      *item_url,
                         gchar      *item_name,
                         EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_on_item_removed  (EShortcutModel *model,
                         gint        group_num,
                         gint        item_num,
                         EShortcutBar   *shortcut_bar);

static gint e_shortcut_bar_add_group        (EShortcutBar   *shortcut_bar,
                         gint        position,
                         const gchar    *group_name);
static void e_shortcut_bar_remove_group     (EShortcutBar   *shortcut_bar,
                         gint        group_num);
static gint e_shortcut_bar_add_item     (EShortcutBar   *shortcut_bar,
                         gint        group_num,
                         gint        position,
                         const gchar    *item_url,
                         const gchar    *item_name);
static void e_shortcut_bar_remove_item      (EShortcutBar   *shortcut_bar,
                         gint        group_num,
                         gint        item_num);


static void e_shortcut_bar_set_canvas_style (EShortcutBar   *shortcut_bar,
                         GtkWidget  *canvas);
static void e_shortcut_bar_item_selected    (EIconBar   *icon_bar,
                         GdkEvent   *event,
                         gint        item_num,
                         EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_item_dragged     (EIconBar   *icon_bar,
                         GdkEvent   *event,
                         gint        item_num,
                         EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_on_drag_data_get (GtkWidget      *widget,
                         GdkDragContext *context,
                         GtkSelectionData *selection_data,
                         guint           info,
                         guint           time,
                         EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_on_drag_data_received(GtkWidget      *widget,
                         GdkDragContext *context,
                         gint            x,
                         gint            y,
                         GtkSelectionData *data,
                         guint           info,
                         guint           time,
                         EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_on_drag_data_delete  (GtkWidget      *widget,
                         GdkDragContext *context,
                         EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_on_drag_end      (GtkWidget      *widget,
                         GdkDragContext *context,
                         EShortcutBar   *shortcut_bar);
static void e_shortcut_bar_stop_editing     (GtkWidget  *button,
                         EShortcutBar   *shortcut_bar);
static GdkPixbuf* e_shortcut_bar_get_image_from_url (EShortcutBar *shortcut_bar,
                             const gchar *item_url);
static GdkPixbuf* e_shortcut_bar_load_image (const gchar    *filename);


enum
{
  ITEM_SELECTED,
  LAST_SIGNAL
};

static guint e_shortcut_bar_signals[LAST_SIGNAL] = {0};

static EGroupBarClass *parent_class;


E_MAKE_TYPE(e_shortcut_bar, "EShortcutBar", EShortcutBar,
        e_shortcut_bar_class_init, e_shortcut_bar_init,
        e_group_bar_get_type())


static void
e_shortcut_bar_class_init (EShortcutBarClass *class)
{
    GtkObjectClass *object_class;
    GtkWidgetClass *widget_class;

    parent_class = gtk_type_class (e_group_bar_get_type ());

    object_class = (GtkObjectClass *) class;
    widget_class = (GtkWidgetClass *) class;

    e_shortcut_bar_signals[ITEM_SELECTED] =
        gtk_signal_new ("item_selected",
                GTK_RUN_LAST | GTK_RUN_ACTION,
                object_class->type,
                GTK_SIGNAL_OFFSET (EShortcutBarClass,
                           selected_item),
                gtk_marshal_NONE__POINTER_INT_INT,
                GTK_TYPE_NONE, 3, GTK_TYPE_GDK_EVENT,
                GTK_TYPE_INT, GTK_TYPE_INT);

    gtk_object_class_add_signals (object_class, e_shortcut_bar_signals,
                      LAST_SIGNAL);

    /* Method override */
    object_class->destroy       = e_shortcut_bar_destroy;
}


static void
e_shortcut_bar_init (EShortcutBar *shortcut_bar)
{
    shortcut_bar->groups = g_array_new (FALSE, FALSE,
                        sizeof (EShortcutBarGroup));

    shortcut_bar->dragged_url = NULL;
    shortcut_bar->dragged_name = NULL;
}


GtkWidget *
e_shortcut_bar_new (void)
{
    GtkWidget *shortcut_bar;

    shortcut_bar = GTK_WIDGET (gtk_type_new (e_shortcut_bar_get_type ()));

    return shortcut_bar;
}


static void
e_shortcut_bar_destroy (GtkObject *object)
{
    EShortcutBar *shortcut_bar;

    shortcut_bar = E_SHORTCUT_BAR (object);

    g_array_free (shortcut_bar->groups, TRUE);

    g_free (shortcut_bar->dragged_url);
    g_free (shortcut_bar->dragged_name);

    GTK_OBJECT_CLASS (parent_class)->destroy (object);
}


void
e_shortcut_bar_set_model (EShortcutBar *shortcut_bar,
              EShortcutModel *model)
{
    gint num_groups, group_num, num_items, item_num;
    gchar *group_name, *item_url, *item_name;

    /* Disconnect any existing model. */
    e_shortcut_bar_disconnect_model (shortcut_bar);

    shortcut_bar->model = model;

    if (!model)
        return;

    gtk_signal_connect (GTK_OBJECT (model), "destroy",
                GTK_SIGNAL_FUNC (e_shortcut_bar_on_model_destroyed),
                shortcut_bar);
    gtk_signal_connect (GTK_OBJECT (model), "group_added",
                GTK_SIGNAL_FUNC (e_shortcut_bar_on_group_added),
                shortcut_bar);
    gtk_signal_connect (GTK_OBJECT (model), "group_removed",
                GTK_SIGNAL_FUNC (e_shortcut_bar_on_group_removed),
                shortcut_bar);
    gtk_signal_connect (GTK_OBJECT (model), "item_added",
                GTK_SIGNAL_FUNC (e_shortcut_bar_on_item_added),
                shortcut_bar);
    gtk_signal_connect (GTK_OBJECT (model), "item_removed",
                GTK_SIGNAL_FUNC (e_shortcut_bar_on_item_removed),
                shortcut_bar);

    /* Add any items already in the model. */
    num_groups = e_shortcut_model_get_num_groups (model);
    for (group_num = 0; group_num < num_groups; group_num++) {
        group_name = e_shortcut_model_get_group_name (model,
                                  group_num);
        e_shortcut_bar_add_group (shortcut_bar, group_num, group_name);
        g_free (group_name);

        num_items = e_shortcut_model_get_num_items (model, group_num);
        for (item_num = 0; item_num < num_items; item_num++) {
            e_shortcut_model_get_item_info (model, group_num,
                            item_num, &item_url,
                            &item_name);
            e_shortcut_bar_add_item (shortcut_bar, group_num,
                         item_num, item_url,
                         item_name);
            g_free (item_url);
            g_free (item_name);
        }
    }
}


static void
e_shortcut_bar_disconnect_model (EShortcutBar *shortcut_bar)
{
    /* Remove all the current groups. */
    while (shortcut_bar->groups->len)
        e_shortcut_bar_remove_group (shortcut_bar, 0);

    if (shortcut_bar->model) {
        /* Disconnect all the signals in one go. */
        gtk_signal_disconnect_by_data (GTK_OBJECT (shortcut_bar->model), shortcut_bar);
        shortcut_bar->model = NULL;
    }
}


static void
e_shortcut_bar_on_model_destroyed   (EShortcutModel *model,
                     EShortcutBar   *shortcut_bar)
{
    e_shortcut_bar_disconnect_model (shortcut_bar);
}


static void
e_shortcut_bar_on_group_added       (EShortcutModel *model,
                     gint        group_num,
                     gchar      *group_name,
                     EShortcutBar   *shortcut_bar)
{
    e_shortcut_bar_add_group (shortcut_bar, group_num, group_name);
}


static void
e_shortcut_bar_on_group_removed     (EShortcutModel *model,
                     gint        group_num,
                     EShortcutBar   *shortcut_bar)
{
    e_shortcut_bar_remove_group (shortcut_bar, group_num);
}


static void
e_shortcut_bar_on_item_added        (EShortcutModel *model,
                     gint        group_num,
                     gint        item_num,
                     gchar      *item_url,
                     gchar      *item_name,
                     EShortcutBar   *shortcut_bar)
{
    e_shortcut_bar_add_item (shortcut_bar, group_num, item_num,
                 item_url, item_name);
}


static void
e_shortcut_bar_on_item_removed (EShortcutModel *model,
                gint group_num,
                gint item_num,
                EShortcutBar *shortcut_bar)
{
    e_shortcut_bar_remove_item (shortcut_bar, group_num, item_num);
}



static gint
e_shortcut_bar_add_group    (EShortcutBar   *shortcut_bar,
                 gint        position,
                 const gchar    *group_name)
{
    EShortcutBarGroup *group, tmp_group;
    gint group_num;
    GtkWidget *button, *label;

    g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), -1);
    g_return_val_if_fail (group_name != NULL, -1);

    gtk_widget_push_colormap (gdk_rgb_get_cmap ());
    gtk_widget_push_visual (gdk_rgb_get_visual ());

    group_num = position;
    g_array_insert_val (shortcut_bar->groups, group_num, tmp_group);

    group = &g_array_index (shortcut_bar->groups,
                EShortcutBarGroup, group_num);

    group->vscrolled_bar = e_vscrolled_bar_new (NULL);
    gtk_widget_show (group->vscrolled_bar);
    gtk_signal_connect (
        GTK_OBJECT (E_VSCROLLED_BAR (group->vscrolled_bar)->up_button),
        "pressed", GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing), shortcut_bar);
    gtk_signal_connect (
        GTK_OBJECT (E_VSCROLLED_BAR (group->vscrolled_bar)->down_button),
        "pressed", GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing), shortcut_bar);

    group->icon_bar = e_icon_bar_new ();
    gtk_widget_show (group->icon_bar);
    gtk_container_add (GTK_CONTAINER (group->vscrolled_bar),
               group->icon_bar);
    gtk_signal_connect (GTK_OBJECT (group->icon_bar), "item_selected",
                GTK_SIGNAL_FUNC (e_shortcut_bar_item_selected),
                shortcut_bar);
    gtk_signal_connect (GTK_OBJECT (group->icon_bar), "item_dragged",
                GTK_SIGNAL_FUNC (e_shortcut_bar_item_dragged),
                shortcut_bar);
    gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_get",
                GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_get),
                shortcut_bar);
    gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_received",
                GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_received),
                shortcut_bar);
    gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_delete",
                GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_delete),
                shortcut_bar);
    gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_end",
                GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_end),
                shortcut_bar);

#ifndef E_USE_STYLES
    e_shortcut_bar_set_canvas_style (shortcut_bar, group->icon_bar);
#endif

    button = gtk_button_new ();
    label = e_clipped_label_new (group_name);
    gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
    gtk_widget_show (label);
    gtk_container_add (GTK_CONTAINER (button), label);
    gtk_widget_show (button);
    gtk_signal_connect (GTK_OBJECT (button), "clicked",
                GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing),
                shortcut_bar);

    gtk_drag_dest_set (GTK_WIDGET (group->icon_bar),
               GTK_DEST_DEFAULT_ALL,
               target_table, n_targets,
               GDK_ACTION_COPY | GDK_ACTION_MOVE);
    gtk_drag_dest_set (GTK_WIDGET (button),
               GTK_DEST_DEFAULT_ALL,
               target_table, n_targets,
               GDK_ACTION_COPY | GDK_ACTION_MOVE);

    e_group_bar_add_group (E_GROUP_BAR (shortcut_bar),
                   group->vscrolled_bar, button, -1);

    gtk_widget_pop_visual ();
    gtk_widget_pop_colormap ();

    return group_num;
}


static void
e_shortcut_bar_remove_group (EShortcutBar   *shortcut_bar,
                 gint        group_num)
{
    e_group_bar_remove_group (E_GROUP_BAR (shortcut_bar), group_num);
    g_array_remove_index (shortcut_bar->groups, group_num);
}


static gint
e_shortcut_bar_add_item     (EShortcutBar   *shortcut_bar,
                 gint        group_num,
                 gint        position,
                 const gchar    *item_url,
                 const gchar    *item_name)
{
    EShortcutBarGroup *group;
    GdkPixbuf *image;
    gint item_num;

    g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), -1);
    g_return_val_if_fail (group_num >= 0, -1);
    g_return_val_if_fail (group_num < shortcut_bar->groups->len, -1);
    g_return_val_if_fail (item_url != NULL, -1);
    g_return_val_if_fail (item_name != NULL, -1);

    image = e_shortcut_bar_get_image_from_url (shortcut_bar, item_url);
    group = &g_array_index (shortcut_bar->groups,
                EShortcutBarGroup, group_num);

    item_num = e_icon_bar_add_item (E_ICON_BAR (group->icon_bar),
                    image, item_name, position);
    gdk_pixbuf_unref (image);
    e_icon_bar_set_item_data_full (E_ICON_BAR (group->icon_bar), item_num,
                       g_strdup (item_url), g_free);

    return item_num;
}


static void
e_shortcut_bar_remove_item  (EShortcutBar   *shortcut_bar,
                 gint        group_num,
                 gint        item_num)
{
    EShortcutBarGroup *group;

    g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar));
    g_return_if_fail (group_num >= 0);
    g_return_if_fail (group_num < shortcut_bar->groups->len);

    group = &g_array_index (shortcut_bar->groups,
                EShortcutBarGroup, group_num);

    e_icon_bar_remove_item (E_ICON_BAR (group->icon_bar), item_num);
}


static void
e_shortcut_bar_set_canvas_style (EShortcutBar *shortcut_bar,
                 GtkWidget *canvas)
{
        GtkRcStyle *rc_style;

        rc_style = gtk_rc_style_new ();

        rc_style->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG | GTK_RC_BG;
        rc_style->fg[GTK_STATE_NORMAL].red   = 65535;
        rc_style->fg[GTK_STATE_NORMAL].green = 65535;
        rc_style->fg[GTK_STATE_NORMAL].blue  = 65535;

        rc_style->bg[GTK_STATE_NORMAL].red   = 32512;
        rc_style->bg[GTK_STATE_NORMAL].green = 32512;
        rc_style->bg[GTK_STATE_NORMAL].blue  = 32512;

        gtk_widget_modify_style (GTK_WIDGET (canvas), rc_style);
        gtk_rc_style_unref (rc_style);
}


void
e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar,
                  gint group_num,
                  EIconBarViewType view_type)
{
    EShortcutBarGroup *group;

    g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar));
    g_return_if_fail (group_num >= 0);
    g_return_if_fail (group_num < shortcut_bar->groups->len);

    group = &g_array_index (shortcut_bar->groups,
                EShortcutBarGroup, group_num);

    e_icon_bar_set_view_type (E_ICON_BAR (group->icon_bar), view_type);
}


EIconBarViewType
e_shortcut_bar_get_view_type (EShortcutBar *shortcut_bar,
                  gint group_num)
{
    EShortcutBarGroup *group;

    g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), E_ICON_BAR_SMALL_ICONS);
    g_return_val_if_fail (group_num >= 0, E_ICON_BAR_SMALL_ICONS);
    g_return_val_if_fail (group_num < shortcut_bar->groups->len, E_ICON_BAR_SMALL_ICONS);

    group = &g_array_index (shortcut_bar->groups,
                EShortcutBarGroup, group_num);

    return E_ICON_BAR (group->icon_bar)->view_type;
}


static void
e_shortcut_bar_item_selected (EIconBar *icon_bar,
                  GdkEvent *event,
                  gint item_num,
                  EShortcutBar *shortcut_bar)
{
    gint group_num;

    group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar),
                           GTK_WIDGET (icon_bar)->parent);

    gtk_signal_emit (GTK_OBJECT (shortcut_bar),
             e_shortcut_bar_signals[ITEM_SELECTED],
             event, group_num, item_num);
}


static void
e_shortcut_bar_item_dragged (EIconBar *icon_bar,
                 GdkEvent *event,
                 gint item_num,
                 EShortcutBar *shortcut_bar)
{
    GtkTargetList *target_list;
    gint group_num;

    group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar),
                           GTK_WIDGET (icon_bar)->parent);

    shortcut_bar->dragged_url = g_strdup (e_icon_bar_get_item_data (icon_bar, item_num));
    shortcut_bar->dragged_name = e_icon_bar_get_item_text (icon_bar, item_num);

    target_list = gtk_target_list_new (target_table, n_targets);
    gtk_drag_begin (GTK_WIDGET (icon_bar), target_list,
            GDK_ACTION_COPY | GDK_ACTION_MOVE,
            1, event);
    gtk_target_list_unref (target_list);
}


static void
e_shortcut_bar_on_drag_data_get (GtkWidget          *widget,
                 GdkDragContext     *context,
                 GtkSelectionData   *selection_data,
                 guint               info,
                 guint               time,
                 EShortcutBar       *shortcut_bar)
{
    gchar *data;

    if (info == TARGET_SHORTCUT) {
        data = g_strdup_printf ("%s%c%s", shortcut_bar->dragged_name,
                    '\0', shortcut_bar->dragged_url);
        gtk_selection_data_set (selection_data, selection_data->target,
                    8, data,
                    strlen (shortcut_bar->dragged_name)
                    + strlen (shortcut_bar->dragged_url)
                    + 2);
        g_free (data);
    }
}


static void  
e_shortcut_bar_on_drag_data_received  (GtkWidget          *widget,
                       GdkDragContext     *context,
                       gint                x,
                       gint                y,
                       GtkSelectionData   *data,
                       guint               info,
                       guint               time,
                       EShortcutBar   *shortcut_bar)
{
    gchar *item_name, *item_url;
    EIconBar *icon_bar;
    gint position, group_num;

    icon_bar = E_ICON_BAR (widget);
    position = icon_bar->dragging_before_item_num;

    if ((data->length >= 0) && (data->format == 8)
        &&  position != -1) {
        item_name = data->data;
        item_url = item_name + strlen (item_name) + 1;

        group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar),
                               GTK_WIDGET (icon_bar)->parent);

        e_shortcut_model_add_item (shortcut_bar->model, group_num,
                       position, item_url, item_name);

        gtk_drag_finish (context, TRUE, TRUE, time);
        return;
    }
  
    gtk_drag_finish (context, FALSE, FALSE, time);
}


static void  
e_shortcut_bar_on_drag_data_delete (GtkWidget          *widget,
                    GdkDragContext     *context,
                    EShortcutBar       *shortcut_bar)
{
    EIconBar *icon_bar;
    gint group_num;

    icon_bar = E_ICON_BAR (widget);

    group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar),
                           widget->parent);

    e_shortcut_model_remove_item (shortcut_bar->model, group_num,
                      icon_bar->dragged_item_num);
}


static void
e_shortcut_bar_on_drag_end (GtkWidget      *widget,
                GdkDragContext *context,
                EShortcutBar   *shortcut_bar)
{
    g_free (shortcut_bar->dragged_name);
    shortcut_bar->dragged_name = NULL;

    g_free (shortcut_bar->dragged_url);
    shortcut_bar->dragged_url = NULL;
}


void
e_shortcut_bar_start_editing_item (EShortcutBar *shortcut_bar,
                   gint group_num,
                   gint item_num)
{
    EShortcutBarGroup *group;

    g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar));
    g_return_if_fail (group_num >= 0);
    g_return_if_fail (group_num < shortcut_bar->groups->len);

    group = &g_array_index (shortcut_bar->groups,
                EShortcutBarGroup, group_num);

    e_icon_bar_start_editing_item (E_ICON_BAR (group->icon_bar), item_num);
}


/* We stop editing any item when a scroll button is pressed. */
static void
e_shortcut_bar_stop_editing (GtkWidget *button,
                 EShortcutBar *shortcut_bar)
{
    EShortcutBarGroup *group;
    gint group_num;

    for (group_num = 0;
         group_num < shortcut_bar->groups->len;
         group_num++) {
        group = &g_array_index (shortcut_bar->groups,
                    EShortcutBarGroup, group_num);
        e_icon_bar_stop_editing_item (E_ICON_BAR (group->icon_bar),
                          TRUE);
    }
}


/* Sets the callback which is called to return the icon to use for a particular
   URL. */
void
e_shortcut_bar_set_icon_callback (EShortcutBar *shortcut_bar,
                  EShortcutBarIconCallback cb,
                  gpointer data)
{
    shortcut_bar->icon_callback = cb;
    shortcut_bar->icon_callback_data = data;
}


static GdkPixbuf *
e_shortcut_bar_get_image_from_url (EShortcutBar *shortcut_bar,
                   const gchar *item_url)
{
    GdkPixbuf *icon = NULL;

    if (shortcut_bar->icon_callback)
        icon = (*shortcut_bar->icon_callback) (shortcut_bar,
                               item_url,
                               shortcut_bar->icon_callback_data);

    if (!icon) {
        if (!e_shortcut_bar_default_icon_loaded) {
            e_shortcut_bar_default_icon_loaded = TRUE;
            e_shortcut_bar_default_icon = e_shortcut_bar_load_image (e_shortcut_bar_default_icon_filename);
        }
        icon = e_shortcut_bar_default_icon;
        /* ref the default icon each time we return it */
        gdk_pixbuf_ref (icon);
    }

    return icon;
}


static GdkPixbuf *
e_shortcut_bar_load_image (const gchar *filename)
{
    gchar *pathname;
    GdkPixbuf *image = NULL;

    pathname = gnome_pixmap_file (filename);
    if (pathname)
        image = gdk_pixbuf_new_from_file (pathname);
    else
        g_warning ("Couldn't find pixmap: %s", filename);

    g_free (pathname);

    return image;
}