~ubuntu-branches/ubuntu/karmic/hipo/karmic

« back to all changes in this revision

Viewing changes to src/HipoMainWindow.cs

  • Committer: Bazaar Package Importer
  • Author(s): Arthur Loiret
  • Date: 2007-09-30 21:51:29 UTC
  • mto: (2.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20070930215129-aphjk24c8h30r9d1
Tags: upstream-0.5
ImportĀ upstreamĀ versionĀ 0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
using System.Threading;
25
25
using System.Collections;
26
26
using System.Collections.Generic;
 
27
using System.Text;
27
28
using Gtk;
28
29
using Gdk;
29
30
using Glade;
40
41
                public EditableCellRenderer ()
41
42
                {
42
43
                        base.Editable = true;
 
44
                        base.Ellipsize = Pango.EllipsizeMode.End;
43
45
                }
44
46
                
45
47
                public int Column
58
60
                [Widget] private Gtk.TreeView plistView;
59
61
                [Widget] private Gtk.Entry filterEntry;
60
62
                [Widget] private Gtk.ProgressBar ipodCapacityBar;
61
 
                [Widget] private Gtk.Statusbar statusbar1;
62
63
                
63
64
                private Glade.XML gxml;
64
65
                private Gnome.Program program;
74
75
                private Gtk.Menu menu;
75
76
                private Hashtable menuTable;
76
77
                private Gtk.Image coverpreview;
77
 
                private ProgressDialog pdialog;
 
78
                private ImportDialog pdialog;
78
79
                
79
80
                ActionGroup group = null;
80
81
                         
81
82
                private static TargetEntry [] tracksview_source_entries = {
82
 
                        new TargetEntry ("text/uri-list", 0, 0)
 
83
                        new TargetEntry ("text/uri-list", 0, 0),
 
84
                        new TargetEntry ("application/x-hipo", 0, 0)
83
85
                };
84
86
 
85
87
                private static TargetEntry [] playlist_dest_entries = {
86
 
                        new TargetEntry ("text/uri-list", 0, 0)
 
88
                        new TargetEntry ("application/x-hipo", 0, 0)
87
89
                };
88
90
 
89
91
                public void CreateWindow (string [] args)
104
106
                                new ActionEntry ("HelpMenu", null, Catalog.GetString ("_Help"), null, null, null),
105
107
                                new ActionEntry ("AddFile", Gtk.Stock.Add, Catalog.GetString ("_Add File..."), null,
106
108
                                                 Catalog.GetString ("Add a file to your iPod"), OnAddActivated),
107
 
                                new ActionEntry ("AddFolder", Gtk.Stock.Add, Catalog.GetString ("Add Folder..."),  "<control>O",
 
109
                                new ActionEntry ("AddFolder", Gtk.Stock.Add, Catalog.GetString ("A_dd Folder..."),  "<control>O",
108
110
                                                 Catalog.GetString ("Add a folder to your iPod"), OnAddFolder),
109
 
                                new ActionEntry ("Remove", Gtk.Stock.Remove, Catalog.GetString ("_Remove"), null,
 
111
                                new ActionEntry ("Remove", Gtk.Stock.Remove, null, null,
110
112
                                                 Catalog.GetString ("Remove a file from your iPod"), OnRemoveActivated),
111
113
                                new ActionEntry ("AddToPlaylist", Gtk.Stock.Add, Catalog.GetString ("Add to Playlist..."), null,
112
114
                                                 Catalog.GetString ("Add file to a Playlist"), null),
117
119
                                new ActionEntry ("RemoveFromPlaylist", Gtk.Stock.Remove, Catalog.GetString ("_Remove from Playlist"), null,
118
120
                                                 Catalog.GetString ("Remove the track from the Playlist"), OnRemoveFromPlaylist),
119
121
                                new ActionEntry ("Eject", null, Catalog.GetString ("_Eject"), null, null, OnEjectActivated),
120
 
                                new ActionEntry ("Quit", Gtk.Stock.Quit, Catalog.GetString ("_Quit"), null, null, OnQuitActivated),
121
 
                                new ActionEntry ("Preferences", Gtk.Stock.Preferences, Catalog.GetString ("Prefere_nces"), null,
 
122
                                new ActionEntry ("Quit", Gtk.Stock.Quit, null, "<control>Q", null, OnQuitActivated),
 
123
                                new ActionEntry ("Preferences", Gtk.Stock.Preferences, null, null,
122
124
                                                 null, OnPreferences),
123
 
                                new ActionEntry ("Help", Gtk.Stock.Help, Catalog.GetString ("_Contents"), "F1",
 
125
                                new ActionEntry ("Help", Gtk.Stock.Help, null, "F1",
124
126
                                                 null, OnHelp),
125
 
                                new ActionEntry ("About", Gnome.Stock.About, Catalog.GetString ("_About"), null,
 
127
                                new ActionEntry ("About", Gnome.Stock.About, null, null,
126
128
                                                 null, OnAboutActivated),
127
129
 
128
130
                                new ActionEntry ("NewPlaylist", Gtk.Stock.New, Catalog.GetString ("New Playlist"), null,
129
131
                                                 Catalog.GetString ("Create a new Playlist"), OnNewPlaylist),
130
132
                                new ActionEntry ("DeletePlaylist", Gtk.Stock.Remove, Catalog.GetString ("Delete Playlist"), null,
131
133
                                                 Catalog.GetString ("Delete the Playlist"), OnDeletePlaylist),
 
134
                                new ActionEntry ("RenamePlaylist", Gtk.Stock.Copy, Catalog.GetString ("Rename Playlist"), null,
 
135
                                                 Catalog.GetString ("Rename the Playlist"), OnRenamePlaylist),
132
136
 
133
137
                                new ActionEntry ("OnDeviceProperties", Gtk.Stock.Properties, Catalog.GetString ("Device Properties"), null,
134
138
                                                 Catalog.GetString ("Device Properties"), OnDeviceProperties)
140
144
                        uim = new UIManager ();
141
145
                        uim.InsertActionGroup (group, 0);
142
146
                        uim.AddUiFromResource ("hipo.xml");
 
147
                        hipoWindow.AddAccelGroup (uim.AccelGroup);
143
148
                        
144
149
                        numTracks = new Gtk.Label ("(0)");
145
150
                        numTracks.UseMarkup = true;
162
167
                        
163
168
                        tracksView.ButtonPressEvent += OnTracksButtonPress;
164
169
                        tracksView.PopupMenu += OnTracksPopupMenu;
165
 
 
 
170
                        
 
171
                        
166
172
                        tracksView.EnableModelDragSource (Gdk.ModifierType.Button1Mask,
167
173
                                                          tracksview_source_entries, Gdk.DragAction.Copy);
168
174
 
173
179
                        plistView.PopupMenu += OnPlaylistPopupMenu;
174
180
                        
175
181
                        plistView.EnableModelDragDest (playlist_dest_entries, Gdk.DragAction.Copy);
176
 
 
 
182
                        
177
183
                        plistView.DragDataReceived += OnPlistDragDataReceived;
 
184
 
 
185
                        tracksView.EnableModelDragDest (tracksview_source_entries, Gdk.DragAction.Copy);
 
186
                        tracksView.DragDataReceived += OnTracksDragDataReceived;
178
187
                        
179
188
                        hipoWindow.DeleteEvent += OnDeleteEvent;
180
189
                        plistView.Selection.Changed += OnPlaylistSelectionChanged;
182
191
                        menuTable = new Hashtable ();
183
192
                        coverpreview = new Gtk.Image ();
184
193
 
185
 
                        pdialog = new ProgressDialog (hipoWindow);
 
194
                        pdialog = new ImportDialog (hipoWindow);
186
195
 
187
196
                        hipoWindow.ShowAll ();
188
197
 
194
203
                private void CreateTreeView ()
195
204
                {
196
205
                        EditableCellRenderer cell = new EditableCellRenderer ();
197
 
                        cell.Edited += OnEdit;
 
206
                        cell.Edited += OnTrackEdit;
198
207
                        cell.Column = 0;
199
208
                        
200
209
                        TreeViewColumn column = new Gtk.TreeViewColumn (Catalog.GetString ("Artist"),
203
212
                        column.Expand = false;
204
213
                        column.SortIndicator = true;
205
214
                        column.SortColumnId = 0;
206
 
                        
 
215
                        column.Sizing = TreeViewColumnSizing.Fixed;
 
216
                        column.FixedWidth = 200;
207
217
                        tracksView.AppendColumn (column);
208
218
                        
209
219
                        cell = new EditableCellRenderer ();
210
 
                        cell.Edited += OnEdit;
 
220
                        cell.Edited += OnTrackEdit;
211
221
                        cell.Column = 1;
212
 
                        
 
222
                                
213
223
                        column = new Gtk.TreeViewColumn (Catalog.GetString ("Album"),
214
224
                                                         cell, "text", 1);
215
225
                        column.Resizable = true;
216
226
                        column.Expand = false;
217
227
                        column.SortIndicator = true;
218
228
                        column.SortColumnId = 1;
 
229
                        column.Sizing = TreeViewColumnSizing.Fixed;
 
230
                        column.FixedWidth = 200;
219
231
                        
220
232
                        tracksView.AppendColumn (column);
221
233
                        
222
234
                        cell = new EditableCellRenderer ();
223
 
                        cell.Edited += OnEdit;
 
235
                        cell.Edited += OnTrackEdit;
224
236
                        cell.Column = 2;
225
 
                        
 
237
                                
226
238
                        column = new Gtk.TreeViewColumn (Catalog.GetString ("Title"),
227
239
                                                         cell, "text", 2);
228
240
                        column.Resizable = true;
229
241
                        column.Expand = false;
230
242
                        column.SortIndicator = true;
231
243
                        column.SortColumnId = 2;
 
244
                        column.Sizing = TreeViewColumnSizing.Fixed;
 
245
                        column.FixedWidth = 200;
232
246
                        
233
247
                        tracksView.AppendColumn (column);
234
248
                        
235
249
                        cell = new EditableCellRenderer ();
236
 
                        cell.Edited += OnEdit;
 
250
                        cell.Edited += OnTrackEdit;
237
251
                        cell.Column = 3;
238
 
 
 
252
                        
239
253
                        column = new Gtk.TreeViewColumn (Catalog.GetString ("Genre"),
240
254
                                                         cell, "text", 3);
241
255
                        column.Resizable = true;
242
256
                        column.Expand = false;
243
257
                        column.SortIndicator = true;
244
258
                        column.SortColumnId = 3;
 
259
                        column.Sizing = TreeViewColumnSizing.Fixed;
 
260
                        column.FixedWidth = 100;
245
261
                        
246
262
                        tracksView.AppendColumn (column);
247
263
                        
249
265
                        tracksView.HeadersClickable = true;
250
266
 
251
267
                        column = new Gtk.TreeViewColumn ("Icon", new Gtk.CellRendererPixbuf (), "pixbuf", 0);
252
 
                        plistView.AppendColumn (column);
253
 
 
254
 
                        column = new Gtk.TreeViewColumn ("Name", new Gtk.CellRendererText (), "text", 1);
255
 
                        plistView.AppendColumn (column);
256
 
                        
257
 
                        column = new Gtk.TreeViewColumn ("Counts", new Gtk.CellRendererText (), "text", 2);
258
 
                        plistView.AppendColumn (column);
259
 
 
 
268
                        column.Expand = false;
 
269
                        plistView.AppendColumn (column);
 
270
                        
 
271
                        cell = new EditableCellRenderer ();
 
272
                        cell.Edited += OnPlaylistEdit;
 
273
                        cell.Column = 1;
 
274
                        
 
275
                        column = new Gtk.TreeViewColumn ("Name", cell, "text", 1);
 
276
                        column.Expand = true;
 
277
                        plistView.AppendColumn (column);
 
278
                                
 
279
                        Gtk.CellRendererText celltext = new Gtk.CellRendererText ();
 
280
                        celltext.Foreground = "grey";
 
281
                        column = new Gtk.TreeViewColumn ("Counts", celltext, "text", 2);
 
282
                        column.Expand = false;
 
283
                        plistView.AppendColumn (column);
 
284
                        
260
285
                        plistView.HeadersVisible = false;
261
286
                }
262
287
 
319
344
                        }             
320
345
                }
321
346
                
322
 
                private void OnEdit (object o, EditedArgs args)
 
347
                private void OnTrackEdit (object o, EditedArgs args)
323
348
                {
324
349
                        TreeIter iter = TreeIter.Zero;
325
350
                        ListStore store = tracks.GetModel ();
375
400
                                thr.Start ();
376
401
                        }
377
402
                }
378
 
 
 
403
                
 
404
                private void OnPlaylistEdit (object o, EditedArgs args)
 
405
                {
 
406
                        TreeIter iter = TreeIter.Zero;
 
407
                        TreeStore store = playlists.GetModel ();
 
408
                        bool modified = false;
 
409
 
 
410
                        if (!store.GetIter (out iter, new TreePath (args.Path)))
 
411
                                return;
 
412
                        else
 
413
                        {
 
414
                                string plistName = (string) store.GetValue (iter, 1);
 
415
 
 
416
                                if (args.NewText != plistName)
 
417
                                {
 
418
                                        if (playlists.UpdatePlaylistName (db, iter, args.NewText))
 
419
                                                modified = true;
 
420
                                }
 
421
                        }
 
422
                        
 
423
                        if (modified)
 
424
                        {
 
425
                                Thread thr = new Thread (new ThreadStart (SaveDB));
 
426
                                thr.Start ();
 
427
                        }
 
428
                }
 
429
 
 
430
                private void OnRenamePlaylist (object o, EventArgs args)
 
431
                {
 
432
                        TreeModel model;
 
433
                        TreeIter iter;
 
434
                        bool modified = false;
 
435
                        
 
436
                        if (plistView.Selection.GetSelected (out model, out iter)) 
 
437
                        {
 
438
                                string plistName = (string) model.GetValue (iter, 1);
 
439
                                
 
440
                                Dialog dialog = new Dialog (Catalog.GetString ("Rename the Playlist"), hipoWindow, Gtk.DialogFlags.DestroyWithParent);
 
441
                                
 
442
                                dialog.Modal = true;
 
443
                                dialog.AddButton ("Cancel", ResponseType.Close);
 
444
                                dialog.AddButton ("OK", ResponseType.Ok);
 
445
                                
 
446
                                Gtk.Entry entry = new Gtk.Entry (plistName);
 
447
                                dialog.VBox.PackStart (entry, false, false, 5);
 
448
                                dialog.DefaultResponse = ResponseType.Ok;
 
449
                                
 
450
                                dialog.ShowAll ();
 
451
                                ResponseType r = (ResponseType) dialog.Run ();
 
452
                                
 
453
                                if (r == ResponseType.Ok)
 
454
                                {
 
455
                                        if (entry.Text != plistName)
 
456
                                        {
 
457
                                                if (playlists.UpdatePlaylistName (db, iter, entry.Text))
 
458
                                                        modified = true;
 
459
                                        }
 
460
                                }
 
461
                                
 
462
                                dialog.Destroy ();
 
463
                        }
 
464
                        
 
465
                        if (modified)
 
466
                        {
 
467
                                Thread thr = new Thread (new ThreadStart (SaveDB));
 
468
                                thr.Start ();
 
469
                        }
 
470
                }
 
471
        
379
472
                private void PlaylistPopupMenu (Gdk.EventButton ev)
380
473
                {
381
474
                        TreeModel model;
387
480
                                
388
481
                                string plistName = (string) model.GetValue (iter, 1);
389
482
                                Playlist plist = null;
390
 
                                
391
 
                                if ((plist = this.db.LookupPlaylist (plistName)) != null) {
392
 
                                        menupl = (Gtk.Menu) uim.GetWidget ("/ui/PlaylistPopup");
 
483
 
 
484
                                if (model.IterHasChild (iter)) {
 
485
                                        menupl = (Gtk.Menu) uim.GetWidget ("/ui/DevicePopup");
393
486
                                        menupl.ShowAll ();
394
487
 
395
488
                                        menupl.Popup (null, null, null, (ev != null) ? ev.Button : 0,
396
489
                                                      (ev != null) ? ev.Time : 0);
397
490
                                } else {
398
 
                                        if (plistName == device.Name) {
399
 
                                                menupl = (Gtk.Menu) uim.GetWidget ("/ui/DevicePopup");
 
491
                                        if ((plist = this.db.LookupPlaylist (plistName)) != null) {
 
492
                                                menupl = (Gtk.Menu) uim.GetWidget ("/ui/PlaylistPopup");
400
493
                                                menupl.ShowAll ();
401
 
 
 
494
                                                
402
495
                                                menupl.Popup (null, null, null, (ev != null) ? ev.Button : 0,
403
496
                                                              (ev != null) ? ev.Time : 0);
404
 
                                        }
405
 
                                }       
 
497
                                        }                                         
 
498
                                }
406
499
                        }
407
500
                }
408
501
 
526
619
                
527
620
                private void PopulateView ()
528
621
                {
 
622
                        Gtk.TreeIter iter;
 
623
                        
529
624
                        this.db = this.device.TrackDatabase;
530
625
                        pdialog.TrackDatabase = this.db;
531
626
                        
538
633
                        
539
634
                        Thread thrb = new Thread (new ThreadStart (PopulateTracksView));
540
635
                        thrb.Start ();
 
636
 
 
637
                        if (plistView.Model.GetIterFirst (out iter)) {
 
638
                                
 
639
                                if (plistView.Model.IterHasChild (iter)) {
 
640
                                        plistView.ExpandAll ();
 
641
                                }
 
642
                        }
541
643
                }
542
644
 
543
645
                private void PopulateTracksView ()
573
675
 
574
676
                private void AddFolder ()
575
677
                {
576
 
                        Gtk.Application.Invoke (delegate {
577
 
                                        statusbar1.Push (1, Catalog.GetString ("Adding Track/s"));
578
 
                                });
579
 
                        
580
 
                        tracks.AddFolder (db, uris);
581
 
 
582
 
                        Gtk.Application.Invoke (delegate {
583
 
                                        statusbar1.Push (1, "");
584
 
                                });
585
 
 
586
 
                        playlists.RefreshDevice (this.device);
587
 
                        SaveDB ();
588
 
                        notify.WakeupMain ();
 
678
                        if (tracks.AddFolder (db, uris)) {
 
679
                                playlists.RefreshDevice (this.device);
 
680
                                SaveDB ();
 
681
                                notify.WakeupMain ();
 
682
                        }
589
683
                }
590
684
                
591
685
                private void OnAddActivated (System.Object o, EventArgs args)
620
714
 
621
715
                private void AddTrack ()
622
716
                {
623
 
                        Gtk.Application.Invoke (delegate {
624
 
                                        statusbar1.Push (1, Catalog.GetString ("Adding Track/s"));
625
 
                                });
 
717
                        bool modified = false;
626
718
                        
627
719
                        foreach (string urin in uris)
628
720
                        {
629
721
                                Uri uri = new Uri (urin);
630
 
                                tracks.AddTrack (this.db, uri.LocalPath);
631
 
                        }
632
 
 
633
 
                        Thread thr = new Thread (new ThreadStart (SaveDB));
634
 
                        thr.Start ();
635
 
 
636
 
                        Gtk.Application.Invoke (delegate {
637
 
                                        statusbar1.Push (1, "");
638
 
                                });
639
 
 
640
 
                        playlists.RefreshDevice (this.device);
641
 
                        notify.WakeupMain ();
 
722
                                modified = tracks.AddTrack (this.db, uri.LocalPath);
 
723
                        }
 
724
 
 
725
                        if (modified) {
 
726
                                Thread thr = new Thread (new ThreadStart (SaveDB));
 
727
                                thr.Start ();
 
728
                      
 
729
                                playlists.RefreshDevice (this.device);
 
730
                                notify.WakeupMain ();
 
731
                        }
642
732
                }
643
733
 
644
734
                private void OnAddToPlaylist (System.Object o, EventArgs args)
683
773
                        TreeView view;
684
774
                        Queue iterQueue;
685
775
 
 
776
                        if (tracksView.Selection.CountSelectedRows() < 1)
 
777
                                return;
 
778
                        
686
779
                        iterQueue = new Queue ();
687
780
                        hbox = new Gtk.HBox ();
688
781
                        hbox.BorderWidth = 5;
787
880
                                long trackId = (long) model.GetValue (iter, 4);
788
881
                                
789
882
                                track = tracks.GetTrackbyId (this.db, trackId);
790
 
                                
 
883
                                /* artist name and track title properties */
791
884
                                trackProperties.Title = String.Format (Catalog.GetString ("{0} {1} Properties"),
792
885
                                                                       track.Artist, track.Title);
793
886
                                artistEntry.Text = track.Artist;
903
996
                {
904
997
                        Glade.XML xml = new Glade.XML (null, "hipo.glade", "deviceProperties", null);
905
998
                        xml.Autoconnect (this);
906
 
 
 
999
                        /* ipod name properties ex: my ipod properties */
907
1000
                        deviceProperties.Title = String.Format (Catalog.GetString ("{0} Properties"), this.device.Name);
908
1001
                        nameEntry.Text = this.device.Name;
909
1002
 
1088
1181
 
1089
1182
                        capacity = FormatString ((double) this.device.VolumeSize);
1090
1183
                        used = FormatString ((double) this.device.VolumeUsed);
1091
 
                        percent = (((double) this.device.VolumeUsed / 1073741824) * 100) / System.Convert.ToDouble (capacity);
1092
1184
 
 
1185
                        percent = ((double) this.device.VolumeUsed * 100) / ((double) this.device.VolumeSize);
 
1186
                        /* space used in the device, example: used 15G of 60G */ 
1093
1187
                        ipodCapacityBar.Text = String.Format (Catalog.GetString ("Used {0} of {1}"), used, capacity);
1094
 
                        ipodCapacityBar.Fraction = (percent * 1.0) / 100;
 
1188
                        ipodCapacityBar.Fraction = percent  / 100;
1095
1189
                }
1096
1190
 
1097
1191
                private string FormatString (double value)
1163
1257
                        TreeIter iter;
1164
1258
                        TreeModel model;
1165
1259
                        Atom[] targets = args.Context.Targets; 
1166
 
                        byte[] bytes;
1167
 
 
1168
 
                        if (tracksView.Selection.GetSelected (out model, out iter))
1169
 
                        {
1170
 
                                long trackId = (long) model.GetValue (iter, 4);
1171
 
 
1172
 
                                Track track = tracks.GetTrackbyId (this.db, trackId);
1173
 
 
1174
 
                                if (track == null)
1175
 
                                        return;
1176
 
                                        
1177
 
                                bytes = System.Text.Encoding.UTF8.GetBytes (trackId.ToString ());
1178
 
                                args.SelectionData.Set (targets[0], 8, bytes);
1179
 
                        }
 
1260
                        ArrayList list = new ArrayList ();
 
1261
                        StringBuilder dragData = new StringBuilder ();
 
1262
                        
 
1263
                        Array treePaths = tracksView.Selection.GetSelectedRows (out model);
 
1264
 
 
1265
                        foreach (TreePath tPath in treePaths)
 
1266
                        {
 
1267
                                if (model.GetIter (out iter, tPath)) {
 
1268
                                        
 
1269
                                        long trackId = (long) model.GetValue (iter, 4);
 
1270
                                        Track track = tracks.GetTrackbyId (this.db, trackId);
 
1271
 
 
1272
                                        if (track != null)
 
1273
                                                list.Add (track);
 
1274
                                }
 
1275
                        }
 
1276
 
 
1277
                        Track[] songs = (Track[]) list.ToArray (typeof  (Track));
 
1278
                        
 
1279
                        if (args.SelectionData.Target == "text/uri-list") {
 
1280
                                foreach (Track track in songs) {
 
1281
                                        dragData.Append (track.FileName + "\r\n");
 
1282
                                }
 
1283
                                
 
1284
                                args.SelectionData.Set (targets[0], 8,
 
1285
                                                        System.Text.Encoding.UTF8.GetBytes (dragData.ToString()));
 
1286
                                
 
1287
                        } else {
 
1288
                                foreach (Track track in songs) {
 
1289
                                        dragData.Append (track.Id + "\n");
 
1290
                                }
 
1291
                                
 
1292
                                args.SelectionData.Set (targets[0], 8,
 
1293
                                                        System.Text.Encoding.UTF8.GetBytes (dragData.ToString ()));
 
1294
                        }
 
1295
                        
1180
1296
                }
1181
1297
 
1182
1298
                private void OnPlistDragDataReceived (object o, DragDataReceivedArgs args)
1190
1306
                        plistView.GetDestRowAtPos (args.X, args.Y, out treepath, out position);
1191
1307
                        model.GetIter (out iter, treepath);
1192
1308
 
1193
 
                        string plistName = (string) model.GetValue (iter, 1);
1194
 
 
1195
 
                        if ((plist = this.db.LookupPlaylist (plistName)) != null) {
1196
 
                                string data = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data);
1197
 
 
1198
 
                                Track track = tracks.GetTrackbyId (this.db, long.Parse (data));
1199
 
 
1200
 
                                if (track == null)
1201
 
                                        return;
1202
 
                                
1203
 
                                plist.AddTrack (track);
1204
 
 
1205
 
                                Thread thr = new Thread (new ThreadStart (SaveDB));
1206
 
                                thr.Start ();
1207
 
 
1208
 
                                playlists.UpdateTrackNumber (this.db, plist);
1209
 
                                
1210
 
                                Gtk.Drag.Finish (args.Context, true, false, args.Time);
1211
 
                        }
 
1309
                        try {
 
1310
                                string plistName = (string) model.GetValue (iter, 1);
 
1311
 
 
1312
                                if ((plist = this.db.LookupPlaylist (plistName)) != null) {
 
1313
                                        string data = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data);
 
1314
 
 
1315
                                        foreach (string d in data.Trim ().Split ('\n')) {
 
1316
                                                Track track = tracks.GetTrackbyId (this.db, long.Parse (d));
 
1317
                                                
 
1318
                                                if (track == null)
 
1319
                                                        return;
 
1320
                                        
 
1321
                                                plist.AddTrack (track);
 
1322
 
 
1323
                                                Thread thr = new Thread (new ThreadStart (SaveDB));
 
1324
                                                thr.Start ();
 
1325
                                        
 
1326
                                                playlists.UpdateTrackNumber (this.db, plist);
 
1327
                                
 
1328
                                                Gtk.Drag.Finish (args.Context, true, false, args.Time);
 
1329
                                        }
 
1330
                                }
 
1331
                                
 
1332
                        } catch (Exception e) {
 
1333
                                Console.WriteLine ("{0}", e.Message);
 
1334
                        }
1212
1335
                }
 
1336
 
 
1337
                private void OnTracksDragDataReceived (object o, DragDataReceivedArgs args)
 
1338
                {
 
1339
                        try {
 
1340
                                if ((Gtk.Drag.GetSourceWidget (args.Context) != tracksView) &&
 
1341
                                    (args.SelectionData.Length >=0 && args.SelectionData.Format == 8))
 
1342
                                {
 
1343
                                        string data = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data);
 
1344
 
 
1345
                                        bool modified = false;
 
1346
 
 
1347
                                        foreach (string ur in data.Trim ().Split ('\n')) {
 
1348
                                                string formatUri = ur.Trim ();
 
1349
                                                
 
1350
                                                Uri uri = new Uri (formatUri);
 
1351
 
 
1352
                                                if (Directory.Exists (uri.LocalPath)) {
 
1353
                                                        string[] tmp = { uri.LocalPath };
 
1354
                                                        if (tracks.AddFolder (this.db, tmp))
 
1355
                                                                if (!modified)
 
1356
                                                                        modified = true;
 
1357
                                                } else if (File.Exists (uri.LocalPath)) {
 
1358
                                                        if (tracks.AddTrack (this.db, uri.LocalPath))
 
1359
                                                                if (!modified)
 
1360
                                                                        modified = true;
 
1361
                                                }
 
1362
                                        }
 
1363
                                        
 
1364
                                        Gtk.Drag.Finish (args.Context, true, false, args.Time);
 
1365
                                        
 
1366
                                        if (modified) {
 
1367
                                                Thread thr = new Thread (new ThreadStart (SaveDB));
 
1368
                                                thr.Start ();
 
1369
                                                
 
1370
                                                playlists.RefreshDevice (this.device);
 
1371
                                        }
 
1372
                                        
 
1373
                                }
 
1374
                        } catch (Exception e) {
 
1375
                                Console.WriteLine (e.Message);
 
1376
                        }
 
1377
                }
1213
1378
        }
1214
1379
}
1215
1380
 
 
1381
 
 
1382