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;
79
80
ActionGroup group = null;
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)
85
87
private static TargetEntry [] playlist_dest_entries = {
86
new TargetEntry ("text/uri-list", 0, 0)
88
new TargetEntry ("application/x-hipo", 0, 0)
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",
125
new ActionEntry ("About", Gnome.Stock.About, Catalog.GetString ("_About"), null,
127
new ActionEntry ("About", Gnome.Stock.About, null, null,
126
128
null, OnAboutActivated),
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),
133
137
new ActionEntry ("OnDeviceProperties", Gtk.Stock.Properties, Catalog.GetString ("Device Properties"), null,
134
138
Catalog.GetString ("Device Properties"), OnDeviceProperties)
173
179
plistView.PopupMenu += OnPlaylistPopupMenu;
175
181
plistView.EnableModelDragDest (playlist_dest_entries, Gdk.DragAction.Copy);
177
183
plistView.DragDataReceived += OnPlistDragDataReceived;
185
tracksView.EnableModelDragDest (tracksview_source_entries, Gdk.DragAction.Copy);
186
tracksView.DragDataReceived += OnTracksDragDataReceived;
179
188
hipoWindow.DeleteEvent += OnDeleteEvent;
180
189
plistView.Selection.Changed += OnPlaylistSelectionChanged;
203
212
column.Expand = false;
204
213
column.SortIndicator = true;
205
214
column.SortColumnId = 0;
215
column.Sizing = TreeViewColumnSizing.Fixed;
216
column.FixedWidth = 200;
207
217
tracksView.AppendColumn (column);
209
219
cell = new EditableCellRenderer ();
210
cell.Edited += OnEdit;
220
cell.Edited += OnTrackEdit;
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;
220
232
tracksView.AppendColumn (column);
222
234
cell = new EditableCellRenderer ();
223
cell.Edited += OnEdit;
235
cell.Edited += OnTrackEdit;
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;
233
247
tracksView.AppendColumn (column);
235
249
cell = new EditableCellRenderer ();
236
cell.Edited += OnEdit;
250
cell.Edited += OnTrackEdit;
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;
246
262
tracksView.AppendColumn (column);
249
265
tracksView.HeadersClickable = true;
251
267
column = new Gtk.TreeViewColumn ("Icon", new Gtk.CellRendererPixbuf (), "pixbuf", 0);
252
plistView.AppendColumn (column);
254
column = new Gtk.TreeViewColumn ("Name", new Gtk.CellRendererText (), "text", 1);
255
plistView.AppendColumn (column);
257
column = new Gtk.TreeViewColumn ("Counts", new Gtk.CellRendererText (), "text", 2);
258
plistView.AppendColumn (column);
268
column.Expand = false;
269
plistView.AppendColumn (column);
271
cell = new EditableCellRenderer ();
272
cell.Edited += OnPlaylistEdit;
275
column = new Gtk.TreeViewColumn ("Name", cell, "text", 1);
276
column.Expand = true;
277
plistView.AppendColumn (column);
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);
260
285
plistView.HeadersVisible = false;
404
private void OnPlaylistEdit (object o, EditedArgs args)
406
TreeIter iter = TreeIter.Zero;
407
TreeStore store = playlists.GetModel ();
408
bool modified = false;
410
if (!store.GetIter (out iter, new TreePath (args.Path)))
414
string plistName = (string) store.GetValue (iter, 1);
416
if (args.NewText != plistName)
418
if (playlists.UpdatePlaylistName (db, iter, args.NewText))
425
Thread thr = new Thread (new ThreadStart (SaveDB));
430
private void OnRenamePlaylist (object o, EventArgs args)
434
bool modified = false;
436
if (plistView.Selection.GetSelected (out model, out iter))
438
string plistName = (string) model.GetValue (iter, 1);
440
Dialog dialog = new Dialog (Catalog.GetString ("Rename the Playlist"), hipoWindow, Gtk.DialogFlags.DestroyWithParent);
443
dialog.AddButton ("Cancel", ResponseType.Close);
444
dialog.AddButton ("OK", ResponseType.Ok);
446
Gtk.Entry entry = new Gtk.Entry (plistName);
447
dialog.VBox.PackStart (entry, false, false, 5);
448
dialog.DefaultResponse = ResponseType.Ok;
451
ResponseType r = (ResponseType) dialog.Run ();
453
if (r == ResponseType.Ok)
455
if (entry.Text != plistName)
457
if (playlists.UpdatePlaylistName (db, iter, entry.Text))
467
Thread thr = new Thread (new ThreadStart (SaveDB));
379
472
private void PlaylistPopupMenu (Gdk.EventButton ev)
388
481
string plistName = (string) model.GetValue (iter, 1);
389
482
Playlist plist = null;
391
if ((plist = this.db.LookupPlaylist (plistName)) != null) {
392
menupl = (Gtk.Menu) uim.GetWidget ("/ui/PlaylistPopup");
484
if (model.IterHasChild (iter)) {
485
menupl = (Gtk.Menu) uim.GetWidget ("/ui/DevicePopup");
393
486
menupl.ShowAll ();
395
488
menupl.Popup (null, null, null, (ev != null) ? ev.Button : 0,
396
489
(ev != null) ? ev.Time : 0);
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 ();
402
495
menupl.Popup (null, null, null, (ev != null) ? ev.Button : 0,
403
496
(ev != null) ? ev.Time : 0);
574
676
private void AddFolder ()
576
Gtk.Application.Invoke (delegate {
577
statusbar1.Push (1, Catalog.GetString ("Adding Track/s"));
580
tracks.AddFolder (db, uris);
582
Gtk.Application.Invoke (delegate {
583
statusbar1.Push (1, "");
586
playlists.RefreshDevice (this.device);
588
notify.WakeupMain ();
678
if (tracks.AddFolder (db, uris)) {
679
playlists.RefreshDevice (this.device);
681
notify.WakeupMain ();
591
685
private void OnAddActivated (System.Object o, EventArgs args)
621
715
private void AddTrack ()
623
Gtk.Application.Invoke (delegate {
624
statusbar1.Push (1, Catalog.GetString ("Adding Track/s"));
717
bool modified = false;
627
719
foreach (string urin in uris)
629
721
Uri uri = new Uri (urin);
630
tracks.AddTrack (this.db, uri.LocalPath);
633
Thread thr = new Thread (new ThreadStart (SaveDB));
636
Gtk.Application.Invoke (delegate {
637
statusbar1.Push (1, "");
640
playlists.RefreshDevice (this.device);
641
notify.WakeupMain ();
722
modified = tracks.AddTrack (this.db, uri.LocalPath);
726
Thread thr = new Thread (new ThreadStart (SaveDB));
729
playlists.RefreshDevice (this.device);
730
notify.WakeupMain ();
644
734
private void OnAddToPlaylist (System.Object o, EventArgs args)
787
880
long trackId = (long) model.GetValue (iter, 4);
789
882
track = tracks.GetTrackbyId (this.db, trackId);
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;
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);
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;
1097
1191
private string FormatString (double value)
1164
1258
TreeModel model;
1165
1259
Atom[] targets = args.Context.Targets;
1168
if (tracksView.Selection.GetSelected (out model, out iter))
1170
long trackId = (long) model.GetValue (iter, 4);
1172
Track track = tracks.GetTrackbyId (this.db, trackId);
1177
bytes = System.Text.Encoding.UTF8.GetBytes (trackId.ToString ());
1178
args.SelectionData.Set (targets[0], 8, bytes);
1260
ArrayList list = new ArrayList ();
1261
StringBuilder dragData = new StringBuilder ();
1263
Array treePaths = tracksView.Selection.GetSelectedRows (out model);
1265
foreach (TreePath tPath in treePaths)
1267
if (model.GetIter (out iter, tPath)) {
1269
long trackId = (long) model.GetValue (iter, 4);
1270
Track track = tracks.GetTrackbyId (this.db, trackId);
1277
Track[] songs = (Track[]) list.ToArray (typeof (Track));
1279
if (args.SelectionData.Target == "text/uri-list") {
1280
foreach (Track track in songs) {
1281
dragData.Append (track.FileName + "\r\n");
1284
args.SelectionData.Set (targets[0], 8,
1285
System.Text.Encoding.UTF8.GetBytes (dragData.ToString()));
1288
foreach (Track track in songs) {
1289
dragData.Append (track.Id + "\n");
1292
args.SelectionData.Set (targets[0], 8,
1293
System.Text.Encoding.UTF8.GetBytes (dragData.ToString ()));
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);
1193
string plistName = (string) model.GetValue (iter, 1);
1195
if ((plist = this.db.LookupPlaylist (plistName)) != null) {
1196
string data = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data);
1198
Track track = tracks.GetTrackbyId (this.db, long.Parse (data));
1203
plist.AddTrack (track);
1205
Thread thr = new Thread (new ThreadStart (SaveDB));
1208
playlists.UpdateTrackNumber (this.db, plist);
1210
Gtk.Drag.Finish (args.Context, true, false, args.Time);
1310
string plistName = (string) model.GetValue (iter, 1);
1312
if ((plist = this.db.LookupPlaylist (plistName)) != null) {
1313
string data = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data);
1315
foreach (string d in data.Trim ().Split ('\n')) {
1316
Track track = tracks.GetTrackbyId (this.db, long.Parse (d));
1321
plist.AddTrack (track);
1323
Thread thr = new Thread (new ThreadStart (SaveDB));
1326
playlists.UpdateTrackNumber (this.db, plist);
1328
Gtk.Drag.Finish (args.Context, true, false, args.Time);
1332
} catch (Exception e) {
1333
Console.WriteLine ("{0}", e.Message);
1337
private void OnTracksDragDataReceived (object o, DragDataReceivedArgs args)
1340
if ((Gtk.Drag.GetSourceWidget (args.Context) != tracksView) &&
1341
(args.SelectionData.Length >=0 && args.SelectionData.Format == 8))
1343
string data = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data);
1345
bool modified = false;
1347
foreach (string ur in data.Trim ().Split ('\n')) {
1348
string formatUri = ur.Trim ();
1350
Uri uri = new Uri (formatUri);
1352
if (Directory.Exists (uri.LocalPath)) {
1353
string[] tmp = { uri.LocalPath };
1354
if (tracks.AddFolder (this.db, tmp))
1357
} else if (File.Exists (uri.LocalPath)) {
1358
if (tracks.AddTrack (this.db, uri.LocalPath))
1364
Gtk.Drag.Finish (args.Context, true, false, args.Time);
1367
Thread thr = new Thread (new ThreadStart (SaveDB));
1370
playlists.RefreshDevice (this.device);
1374
} catch (Exception e) {
1375
Console.WriteLine (e.Message);