public void ShowAlbumDetails(Album album) { _dlgAlbumDetails = new AlbumDetails(); // Prepare the Details Dialog _dlgAlbumDetails.Artist = album.Artist; _dlgAlbumDetails.Album = album.Title; _dlgAlbumDetails.Year = album.Year; try { using (MemoryStream ms = new MemoryStream(album.AlbumImage.Data)) { Image img = Image.FromStream(ms); _dlgAlbumDetails.Cover.Image = img; } } catch {} // Add Tracks of the selected album foreach (List<AlbumTrack> disc in album.Discs) { foreach (AlbumTrack track in disc) { ListViewItem lvItem = new ListViewItem(track.Number.ToString()); lvItem.SubItems.Add(track.Title); _dlgAlbumDetails.AlbumTracks.Items.Add(lvItem); } } // Add selected Files from Grid foreach (DataGridViewRow row in _tracksGrid.Rows) { if (!row.Selected) continue; TrackData track = Options.Songlist[row.Index]; ListViewItem lvItem = new ListViewItem((row.Index + 1).ToString()); lvItem.SubItems.Add(track.FileName); lvItem.Tag = row.Index; _dlgAlbumDetails.DiscTracks.Items.Add(lvItem); } // if we have less files selected, than in the album, fill the rest with"unassigned" if (_dlgAlbumDetails.DiscTracks.Items.Count < _dlgAlbumDetails.AlbumTracks.Items.Count) { for (int i = _dlgAlbumDetails.DiscTracks.Items.Count - 1; i < _dlgAlbumDetails.AlbumTracks.Items.Count - 1; i++) { ListViewItem unassignedItem = new ListViewItem((i + 2).ToString()); unassignedItem.SubItems.Add(ServiceScope.Get<ILocalisation>().ToString("Lookup", "Unassigned")); unassignedItem.Tag = -1; unassignedItem.Checked = false; _dlgAlbumDetails.DiscTracks.Items.Add(unassignedItem); } } int albumTrackPos = 0; foreach (ListViewItem lvAlbumItem in _dlgAlbumDetails.AlbumTracks.Items) { int discTrackPos = 0; foreach (ListViewItem lvDiscItem in _dlgAlbumDetails.DiscTracks.Items) { if (Util.LongestCommonSubstring(lvAlbumItem.SubItems[1].Text, lvDiscItem.SubItems[1].Text) > 0.75) { lvDiscItem.Checked = true; _dlgAlbumDetails.DiscTracks.Items.RemoveAt(discTrackPos); _dlgAlbumDetails.DiscTracks.Items.Insert(albumTrackPos, lvDiscItem); break; } discTrackPos++; } albumTrackPos++; } _dlgAlbumDetails.Renumber(); if (main.ShowModalDialog(_dlgAlbumDetails) == DialogResult.OK) { int i = -1; foreach (ListViewItem lvItem in _dlgAlbumDetails.DiscTracks.Items) { i++; int index = (int)lvItem.Tag; if (index == -1 || lvItem.Checked == false) continue; TrackData track = Options.Songlist[index]; track.Artist = _dlgAlbumDetails.Artist; track.Album = _dlgAlbumDetails.Album; string strYear = _dlgAlbumDetails.Year; if (strYear.Length > 4) strYear = strYear.Substring(0, 4); int year = 0; try { year = Convert.ToInt32(strYear); } catch (Exception) {} if (year > 0 && track.Year == 0) track.Year = year; // Add the picture ByteVector vector = album.AlbumImage; if (vector != null) { MPTagThat.Core.Common.Picture pic = new MPTagThat.Core.Common.Picture(); pic.MimeType = "image/jpg"; pic.Description = ""; pic.Type = PictureType.FrontCover; pic.Data = vector.Data; track.Pictures.Add(pic); } ListViewItem trackItem = _dlgAlbumDetails.AlbumTracks.Items[i]; track.Track = trackItem.SubItems[0].Text; track.Title = trackItem.SubItems[1].Text; main.TracksGridView.SetBackgroundColorChanged(index); track.Changed = true; Options.Songlist[index] = track; main.TracksGridView.Changed = true; } } _dlgAlbumDetails.Dispose(); }
public void ShowAlbumDetails(AmazonAlbum album) { dlgAlbumDetails = new AlbumDetails(); // Prepare the Details Dialog dlgAlbumDetails.Artist = album.Artist; dlgAlbumDetails.Album = album.Title; dlgAlbumDetails.Year = album.Year; try { using (MemoryStream ms = new MemoryStream(album.AlbumImage.Data)) { Image img = Image.FromStream(ms); if (img != null) { dlgAlbumDetails.Cover.Image = img; } } } catch {} // Add Tracks of the selected album foreach (List <AmazonAlbumTrack> disc in album.Discs) { foreach (AmazonAlbumTrack track in disc) { ListViewItem lvItem = new ListViewItem(track.Number.ToString()); lvItem.SubItems.Add(track.Title); dlgAlbumDetails.AlbumTracks.Items.Add(lvItem); } } // Add selected Files from Grid foreach (DataGridViewRow row in _tracksGrid.Rows) { if (!row.Selected) { continue; } TrackData track = main.TracksGridView.TrackList[row.Index]; ListViewItem lvItem = new ListViewItem((row.Index + 1).ToString()); lvItem.SubItems.Add(track.FileName); lvItem.Tag = row.Index; dlgAlbumDetails.DiscTracks.Items.Add(lvItem); } // if we have less files selected, than in the album, fill the rest with"unassigned" if (dlgAlbumDetails.DiscTracks.Items.Count < dlgAlbumDetails.AlbumTracks.Items.Count) { for (int i = dlgAlbumDetails.DiscTracks.Items.Count - 1; i < dlgAlbumDetails.AlbumTracks.Items.Count - 1; i++) { ListViewItem unassignedItem = new ListViewItem((i + 2).ToString()); unassignedItem.SubItems.Add(ServiceScope.Get <ILocalisation>().ToString("Lookup", "Unassigned")); unassignedItem.Tag = -1; unassignedItem.Checked = false; dlgAlbumDetails.DiscTracks.Items.Add(unassignedItem); } } int albumTrackPos = 0; foreach (ListViewItem lvAlbumItem in dlgAlbumDetails.AlbumTracks.Items) { int discTrackPos = 0; foreach (ListViewItem lvDiscItem in dlgAlbumDetails.DiscTracks.Items) { if (Util.LongestCommonSubstring(lvAlbumItem.SubItems[1].Text, lvDiscItem.SubItems[1].Text) > 0.75) { lvDiscItem.Checked = true; dlgAlbumDetails.DiscTracks.Items.RemoveAt(discTrackPos); dlgAlbumDetails.DiscTracks.Items.Insert(albumTrackPos, lvDiscItem); break; } discTrackPos++; } albumTrackPos++; } dlgAlbumDetails.Renumber(); if (main.ShowModalDialog(dlgAlbumDetails) == DialogResult.OK) { int i = -1; foreach (ListViewItem lvItem in dlgAlbumDetails.DiscTracks.Items) { i++; int index = (int)lvItem.Tag; if (index == -1 || lvItem.Checked == false) { continue; } TrackData track = main.TracksGridView.TrackList[index]; track.Artist = dlgAlbumDetails.Artist; track.Album = dlgAlbumDetails.Album; string strYear = dlgAlbumDetails.Year; if (strYear.Length > 4) { strYear = strYear.Substring(0, 4); } int year = 0; try { year = Convert.ToInt32(strYear); } catch (Exception) {} if (year > 0 && track.Year == 0) { track.Year = year; } // Add the picture ByteVector vector = album.AlbumImage; if (vector != null) { MPTagThat.Core.Common.Picture pic = new MPTagThat.Core.Common.Picture(); pic.MimeType = "image/jpg"; pic.Description = ""; pic.Type = PictureType.FrontCover; pic.Data = pic.ImageFromData(vector.Data); track.Pictures.Add(pic); } ListViewItem trackItem = dlgAlbumDetails.AlbumTracks.Items[i]; track.Track = trackItem.SubItems[0].Text; track.Title = trackItem.SubItems[1].Text; main.TracksGridView.SetBackgroundColorChanged(index); track.Changed = true; main.TracksGridView.Changed = true; main.TracksGridView.SetStatusColumnChange(main.TracksGridView.View.Rows[index]); } } dlgAlbumDetails.Dispose(); }