~ubuntu-branches/ubuntu/precise/rhythmbox/precise-201203091205

« back to all changes in this revision

Viewing changes to shell/rb-shell-clipboard.c

Tags: upstream-0.9.2cvs20060102
ImportĀ upstreamĀ versionĀ 0.9.2cvs20060102

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 
2
 * 
2
3
 *  arch-tag: Implementation of song cut/paste handler object
3
4
 *
4
5
 *  Copyright (C) 2002 Jorn Baayen <jorn@nl.linux.org>
20
21
 *
21
22
 */
22
23
 
 
24
#include <config.h>
 
25
 
 
26
#include <glib/gi18n.h>
 
27
#include <gtk/gtk.h>
 
28
 
23
29
#include "rb-shell-clipboard.h"
24
30
#include "rhythmdb.h"
25
31
#include "rb-debug.h"
26
 
#include <libgnome/gnome-i18n.h>
 
32
#include "rb-static-playlist-source.h"
 
33
#include "rb-play-queue-source.h"
27
34
#include <gtk/gtkstock.h>
28
35
 
29
36
static void rb_shell_clipboard_class_init (RBShellClipboardClass *klass);
52
59
                                          RBShellClipboard *clipboard);
53
60
static void rb_shell_clipboard_cmd_delete (GtkAction *action,
54
61
                                           RBShellClipboard *clipboard);
 
62
static void rb_shell_clipboard_cmd_queue_delete (GtkAction *action,
 
63
                                                 RBShellClipboard *clipboard);
 
64
static void rb_shell_clipboard_cmd_move_to_trash (GtkAction *action,
 
65
                                                  RBShellClipboard *clipboard);
55
66
static void rb_shell_clipboard_set (RBShellClipboard *clipboard,
56
67
                                    GList *nodes);
57
68
static gboolean rb_shell_clipboard_idle_poll_deletions (RBShellClipboard *clipboard);
60
71
                                                 RBShellClipboard *clipboard);
61
72
static void rb_shell_clipboard_entryview_changed_cb (RBEntryView *view,
62
73
                                                     RBShellClipboard *clipboard);
 
74
static void rb_shell_clipboard_cmd_add_song_to_queue (GtkAction *action,
 
75
                                                      RBShellClipboard *clipboard);
 
76
static void rb_shell_clipboard_cmd_song_info (GtkAction *action,
 
77
                                              RBShellClipboard *clipboard);
 
78
static void rb_shell_clipboard_cmd_queue_song_info (GtkAction *action,
 
79
                                                    RBShellClipboard *clipboard);
63
80
 
64
81
struct RBShellClipboardPrivate
65
82
{
66
83
        RhythmDB *db;
67
84
        RBSource *source;
 
85
        RBStaticPlaylistSource *queue_source;
68
86
 
69
87
        GtkActionGroup *actiongroup;
70
88
 
77
95
        GList *entries;
78
96
};
79
97
 
 
98
#define RB_SHELL_CLIPBOARD_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_SHELL_CLIPBOARD, RBShellClipboardPrivate))
 
99
 
80
100
enum
81
101
{
82
102
        PROP_0,
83
103
        PROP_SOURCE,
84
104
        PROP_ACTION_GROUP,
85
105
        PROP_DB,
 
106
        PROP_QUEUE_SOURCE,
86
107
};
87
108
 
88
109
static GtkActionEntry rb_shell_clipboard_actions [] =
105
126
        { "EditDelete", NULL, N_("_Delete"), NULL,
106
127
          N_("Delete selection"),
107
128
          G_CALLBACK (rb_shell_clipboard_cmd_delete) },
 
129
        { "EditMovetoTrash", NULL, N_("_Move To Trash"), "<control>T",
 
130
          N_("Move selection to the trash"),
 
131
          G_CALLBACK (rb_shell_clipboard_cmd_move_to_trash) },
 
132
 
 
133
        { "AddToQueue", GTK_STOCK_ADD, N_("Add _to Play Queue"), "<control>T",
 
134
          N_("Add the selected songs to the play queue"),
 
135
          G_CALLBACK (rb_shell_clipboard_cmd_add_song_to_queue) },
 
136
        { "QueueDelete", NULL, N_("Delete"), NULL,
 
137
          N_("Delete selection"),
 
138
          G_CALLBACK (rb_shell_clipboard_cmd_queue_delete) },
 
139
 
 
140
        { "MusicProperties", GTK_STOCK_PROPERTIES, N_("_Properties"), "<Alt>Return",
 
141
          N_("Show information on the selected song"),
 
142
          G_CALLBACK (rb_shell_clipboard_cmd_song_info) },
 
143
        { "QueueMusicProperties", GTK_STOCK_PROPERTIES, N_("_Properties"), NULL,
 
144
          N_("Show information on the selected song"),
 
145
          G_CALLBACK (rb_shell_clipboard_cmd_queue_song_info) },
108
146
};
109
147
static guint rb_shell_clipboard_n_actions = G_N_ELEMENTS (rb_shell_clipboard_actions);
110
148
 
111
 
static GObjectClass *parent_class = NULL;
112
 
 
113
 
GType
114
 
rb_shell_clipboard_get_type (void)
115
 
{
116
 
        static GType rb_shell_clipboard_type = 0;
117
 
 
118
 
        if (rb_shell_clipboard_type == 0)
119
 
        {
120
 
                static const GTypeInfo our_info =
121
 
                {
122
 
                        sizeof (RBShellClipboardClass),
123
 
                        NULL,
124
 
                        NULL,
125
 
                        (GClassInitFunc) rb_shell_clipboard_class_init,
126
 
                        NULL,
127
 
                        NULL,
128
 
                        sizeof (RBShellClipboard),
129
 
                        0,
130
 
                        (GInstanceInitFunc) rb_shell_clipboard_init
131
 
                };
132
 
 
133
 
                rb_shell_clipboard_type = g_type_register_static (G_TYPE_OBJECT,
134
 
                                                                  "RBShellClipboard",
135
 
                                                                  &our_info, 0);
136
 
        }
137
 
 
138
 
        return rb_shell_clipboard_type;
139
 
}
 
149
G_DEFINE_TYPE (RBShellClipboard, rb_shell_clipboard, G_TYPE_OBJECT)
140
150
 
141
151
static void
142
152
rb_shell_clipboard_class_init (RBShellClipboardClass *klass)
143
153
{
144
154
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
145
155
 
146
 
        parent_class = g_type_class_peek_parent (klass);
147
 
 
148
156
        object_class->finalize = rb_shell_clipboard_finalize;
149
157
        object_class->constructor = rb_shell_clipboard_constructor;
150
158
 
172
180
                                                              "RhythmDB database",
173
181
                                                              RHYTHMDB_TYPE,
174
182
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
183
        g_object_class_install_property (object_class,
 
184
                                         PROP_QUEUE_SOURCE,
 
185
                                         g_param_spec_object ("queue-source",
 
186
                                                              "RBPlaylistSource",
 
187
                                                              "RBPlaylistSource object",
 
188
                                                              RB_TYPE_PLAYLIST_SOURCE,
 
189
                                                              G_PARAM_READWRITE));
175
190
 
 
191
        g_type_class_add_private (klass, sizeof (RBShellClipboardPrivate));
176
192
}
177
193
 
178
194
static void
179
195
rb_shell_clipboard_init (RBShellClipboard *shell_clipboard)
180
196
{
181
 
        shell_clipboard->priv = g_new0 (RBShellClipboardPrivate, 1);
 
197
        shell_clipboard->priv = RB_SHELL_CLIPBOARD_GET_PRIVATE (shell_clipboard);
182
198
 
183
199
        shell_clipboard->priv->signal_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal,
184
200
                                                                    NULL, g_free);
209
225
        if (shell_clipboard->priv->idle_sync_id)
210
226
                g_source_remove (shell_clipboard->priv->idle_sync_id);
211
227
        
212
 
        g_free (shell_clipboard->priv);
213
 
 
214
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
 
228
        G_OBJECT_CLASS (rb_shell_clipboard_parent_class)->finalize (object);
215
229
}
216
230
 
217
231
static GObject *
224
238
 
225
239
        klass = RB_SHELL_CLIPBOARD_CLASS (g_type_class_peek (RB_TYPE_SHELL_CLIPBOARD));
226
240
 
227
 
        parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
 
241
        parent_class = G_OBJECT_CLASS (rb_shell_clipboard_parent_class);
228
242
        clip = RB_SHELL_CLIPBOARD (parent_class->constructor (type,
229
243
                                                              n_construct_properties,
230
244
                                                              construct_properties));
266
280
                        RBEntryView *songs = rb_source_get_entry_view (clipboard->priv->source);
267
281
 
268
282
                        g_signal_connect_object (G_OBJECT (songs),
269
 
                                                 "changed",
 
283
                                                 "selection-changed",
270
284
                                                 G_CALLBACK (rb_shell_clipboard_entryview_changed_cb),
271
285
                                                 clipboard, 0);
272
286
                }
281
295
        case PROP_DB:
282
296
                clipboard->priv->db = g_value_get_object (value);
283
297
                break;
 
298
        case PROP_QUEUE_SOURCE:
 
299
                clipboard->priv->queue_source = g_value_get_object (value);
 
300
                if (clipboard->priv->queue_source) {
 
301
                        RBEntryView *sidebar;
 
302
                        g_object_get (G_OBJECT (clipboard->priv->queue_source), "sidebar", &sidebar, NULL);
 
303
                        g_signal_connect_object (G_OBJECT (sidebar), "selection-changed",
 
304
                                                 G_CALLBACK (rb_shell_clipboard_entryview_changed_cb),
 
305
                                                 clipboard, 0);
 
306
                        g_object_unref (G_OBJECT (sidebar));
 
307
                }
 
308
                break;
284
309
        default:
285
310
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
286
311
                break;
306
331
        case PROP_DB:
307
332
                g_value_set_object (value, clipboard->priv->db);
308
333
                break;
 
334
        case PROP_QUEUE_SOURCE:
 
335
                g_value_set_object (value, clipboard->priv->queue_source);
 
336
                break;
309
337
        default:
310
338
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
311
339
                break;
317
345
                               RBSource *source)
318
346
{
319
347
        g_return_if_fail (RB_IS_SHELL_CLIPBOARD (clipboard));
320
 
        g_return_if_fail (RB_IS_SOURCE (source));
 
348
        if (source != NULL)
 
349
                g_return_if_fail (RB_IS_SOURCE (source));
321
350
 
322
351
        g_object_set (G_OBJECT (clipboard), "source", source, NULL);
323
352
}
335
364
rb_shell_clipboard_sync (RBShellClipboard *clipboard)
336
365
{
337
366
        gboolean have_selection;
338
 
        gboolean can_cut;       
339
 
        gboolean can_paste;
340
 
        gboolean can_delete;    
341
 
        gboolean can_copy;      
 
367
        gboolean have_sidebar_selection = FALSE;
 
368
        gboolean can_cut = FALSE;
 
369
        gboolean can_paste = FALSE;
 
370
        gboolean can_delete = FALSE;
 
371
        gboolean can_copy = FALSE;
 
372
        gboolean can_add_to_queue = FALSE;
 
373
        gboolean can_move_to_trash = FALSE;
342
374
        GtkAction *action;
343
375
 
344
376
        if (!clipboard->priv->source)
345
377
                return;
346
378
 
347
379
        have_selection = rb_entry_view_have_selection (rb_source_get_entry_view (clipboard->priv->source));
348
 
        can_cut = have_selection;       
349
 
        can_paste = have_selection;
350
 
        can_delete = have_selection;    
351
 
        can_copy = have_selection;      
 
380
        if (clipboard->priv->queue_source) {
 
381
                RBEntryView *sidebar;
 
382
                g_object_get (G_OBJECT (clipboard->priv->queue_source), "sidebar", &sidebar, NULL);
 
383
                have_sidebar_selection = rb_entry_view_have_selection (sidebar);
 
384
                g_object_unref (G_OBJECT (sidebar));
 
385
        }
352
386
 
353
387
        rb_debug ("syncing clipboard");
354
388
        
355
 
        if (have_selection)
 
389
        if (g_list_length (clipboard->priv->entries) > 0)
 
390
                can_paste = rb_source_can_cut (clipboard->priv->source);
 
391
 
 
392
        if (have_selection) {
356
393
                can_cut = rb_source_can_cut (clipboard->priv->source);
357
 
 
358
 
        can_paste = rb_source_can_cut (clipboard->priv->source);
359
 
 
360
 
        if (have_selection)
361
394
                can_delete = rb_source_can_delete (clipboard->priv->source);
362
 
        if (have_selection)
363
395
                can_copy = rb_source_can_copy (clipboard->priv->source);
 
396
                can_move_to_trash = rb_source_can_move_to_trash (clipboard->priv->source);
 
397
                if (clipboard->priv->queue_source)
 
398
                        can_add_to_queue = rb_source_can_add_to_queue (clipboard->priv->source);
 
399
        }
364
400
 
365
401
        action = gtk_action_group_get_action (clipboard->priv->actiongroup,
366
402
                                              "EditCut");
369
405
                                              "EditDelete");
370
406
        g_object_set (G_OBJECT (action), "sensitive", can_delete, NULL);
371
407
        action = gtk_action_group_get_action (clipboard->priv->actiongroup,
 
408
                                              "EditMovetoTrash");
 
409
        g_object_set (G_OBJECT (action), "sensitive", can_move_to_trash, NULL);
 
410
        action = gtk_action_group_get_action (clipboard->priv->actiongroup,
372
411
                                              "EditCopy");
373
412
        g_object_set (G_OBJECT (action), "sensitive", can_copy, NULL);
374
413
 
375
 
        can_paste = can_paste && g_list_length (clipboard->priv->entries) > 0;
376
 
 
377
414
        action = gtk_action_group_get_action (clipboard->priv->actiongroup,
378
415
                                              "EditPaste");
379
416
        g_object_set (G_OBJECT (action), "sensitive", can_paste, NULL);
 
417
 
 
418
        action = gtk_action_group_get_action (clipboard->priv->actiongroup,
 
419
                                              "AddToQueue");
 
420
        g_object_set (G_OBJECT (action), "sensitive", can_add_to_queue, NULL);
 
421
        
 
422
        action = gtk_action_group_get_action (clipboard->priv->actiongroup,
 
423
                                              "MusicProperties");
 
424
        g_object_set (G_OBJECT (action), "sensitive", have_selection, NULL);
 
425
        
 
426
        action = gtk_action_group_get_action (clipboard->priv->actiongroup,
 
427
                                              "QueueMusicProperties");
 
428
        g_object_set (G_OBJECT (action), "sensitive", have_sidebar_selection, NULL);
 
429
        action = gtk_action_group_get_action (clipboard->priv->actiongroup,
 
430
                                              "QueueDelete");
 
431
        g_object_set (G_OBJECT (action), "sensitive", have_sidebar_selection, NULL);
380
432
}
381
433
 
382
434
static void
436
488
}
437
489
 
438
490
static void
 
491
rb_shell_clipboard_cmd_queue_delete (GtkAction *action,
 
492
                                     RBShellClipboard *clipboard)
 
493
{
 
494
        rb_debug ("delete");
 
495
        rb_play_queue_source_sidebar_delete (RB_PLAY_QUEUE_SOURCE (clipboard->priv->queue_source));
 
496
}
 
497
 
 
498
static void
 
499
rb_shell_clipboard_cmd_move_to_trash (GtkAction *action,
 
500
                                      RBShellClipboard *clipboard)
 
501
{
 
502
        rb_debug ("movetotrash");
 
503
        rb_source_move_to_trash (clipboard->priv->source);
 
504
}
 
505
 
 
506
static void
439
507
rb_shell_clipboard_set (RBShellClipboard *clipboard,
440
508
                        GList *entries)
441
509
{
517
585
        rb_debug ("entryview changed");
518
586
        rb_shell_clipboard_sync (clipboard);
519
587
}
 
588
 
 
589
static void
 
590
rb_shell_clipboard_cmd_add_song_to_queue (GtkAction *action,
 
591
                                          RBShellClipboard *clipboard)
 
592
{
 
593
        rb_debug ("add to queue");
 
594
        rb_source_add_to_queue (clipboard->priv->source,
 
595
                                RB_SOURCE (clipboard->priv->queue_source));
 
596
}
 
597
 
 
598
static void
 
599
rb_shell_clipboard_cmd_song_info (GtkAction *action,
 
600
                                  RBShellClipboard *clipboard)
 
601
{
 
602
        rb_debug ("song info");
 
603
 
 
604
        rb_source_song_properties (clipboard->priv->source);
 
605
}
 
606
 
 
607
static void
 
608
rb_shell_clipboard_cmd_queue_song_info (GtkAction *action,
 
609
                                        RBShellClipboard *clipboard)
 
610
{
 
611
        rb_debug ("song info");
 
612
        rb_play_queue_source_sidebar_song_info (RB_PLAY_QUEUE_SOURCE (clipboard->priv->queue_source));
 
613
}
 
614