public Playlist getPlaylistByName(PlaylistGroup plg, string plName, string Key) { PlaylistGroupItem plgi = this.Find(plg, Key); if (plgi != null) { Playlist pltarget = plgi.Playlists.Where(z => z.Name == plName).FirstOrDefault(); return(pltarget == null ? null : pltarget); } return(null); }
/// <summary> /// previous item /// </summary> /// <param name="curItem"></param> /// <returns></returns> public PlaylistGroupItem Previous(PlaylistGroupItem curItem) { int itemIndex = plGroupItems.IndexOf(curItem); itemIndex--; if (itemIndex < 0) { itemIndex = 0; } return(plGroupItems[itemIndex]); }
/// <summary> /// next item /// </summary> /// <param name="curItem"></param> /// <returns></returns> public PlaylistGroupItem Next(PlaylistGroupItem curItem) { int itemIndex = plGroupItems.IndexOf(curItem); itemIndex++; if (itemIndex >= plGroupItems.Count) { itemIndex = plGroupItems.Count - 1; } return(plGroupItems[itemIndex]); }
/// <summary> /// Add a PlaylistGroupItem to the PlaylistGroup /// </summary> /// <returns></returns> public bool Add(PlaylistGroupItem pli) { if (PlaylistGroupItemExists(pli, pli.Name) == false) { this.plGroupItems.Add(pli); return(true); } else { string tx = "<" + pli.Name + "> is already in this playlistgroup"; MessageBox.Show(tx, "Karaboss", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } }
/// <summary> /// Search existence of PlaylistGroupItem by checking unicity of its key /// </summary> /// <param name="pli"></param> /// <returns></returns> public bool PlaylistGroupItemExists(PlaylistGroupItem pli, string name) { // Interdire même nom de folder si même parent PlaylistGroupItem pitarget; if (pli.ParentKey == null) { pitarget = plGroupItems.Where(z => (z.ParentKey == null) && (z.Name == name)).FirstOrDefault(); return(pitarget == null ? false : true); } else { pitarget = plGroupItems.Where(z => (z.ParentKey != null && z.ParentKey == pli.ParentKey) && (z.Name == name)).FirstOrDefault(); return(pitarget == null ? false : true); } }
/// <summary> /// Sort the PlaylistGroupItems of PlaylistGroup /// </summary> public void Sort() { PlaylistGroupItem[] arrayMenu = new PlaylistGroupItem[_plgroupitems.Count]; for (int i = 0; i < _plgroupitems.Count; i++) { PlaylistGroupItem plgi = _plgroupitems[i]; arrayMenu[i] = plgi; } Array.Sort(arrayMenu, delegate(PlaylistGroupItem pli1, PlaylistGroupItem pli2) { return(pli1.Name.CompareTo(pli2.Name)); }); // restore sorted collection _plgroupitems.Clear(); for (int i = 0; i < arrayMenu.Length; i++) { _plgroupitems.Add(arrayMenu[i]); } }
public PlaylistGroupItem CreateEmptyPlaylistGroupItem(string Name = "myPlaylists1", PlaylistGroupItem Parent = null) { PlaylistGroupItem plgi = new PlaylistGroupItem(); plgi.Name = Name; plgi.Key = generateKey(); if (Parent != null) { plgi.ParentKey = Parent.Key; } plgi.Playlists = new ObservableCollection <Playlist>(); Playlist pl = new Playlist(); pl.Name = "Playlist1"; pl.Style = "Style"; pl.Add("<Artist>", "<Song>", "", "<Album>", "00:00", 4, "<DirSlideShow>", false, "<Karaoke singer>"); plgi.Playlists.Add(pl); return(plgi); }
/// <summary> /// Find a new name not used /// </summary> /// <returns></returns> private string FindNewName() { if (tvPlaylistGroup.Nodes.Count == 0) { return("Playlist1"); } TreeNode tn = tvPlaylistGroup.SelectedNode; if (tn == null) { tn = tvPlaylistGroup.Nodes[0]; } string Key = string.Empty; if (tn.Tag.ToString() == "playlist") { Key = tn.Parent.Tag.ToString(); } else { Key = tn.Tag.ToString(); } PlaylistGroupItem pli = PlGroupHelper.Find(PlGroup, Key); string name = string.Empty; int suffix = 0; do { name = string.Format("Playlist{0}", ++suffix); } while (PlGroupHelper.PlaylistExist(pli.Playlists, name) == true); return(name); }
/// <summary> /// Index of current item /// </summary> /// <param name="curItem"></param> /// <returns></returns> public int SelectedIndex(PlaylistGroupItem curItem) { return(plGroupItems.IndexOf(curItem)); }
/// <summary> /// Remove a PlaylistGroupItem from the collection /// </summary> /// <param name="plg"></param> public void Remove(PlaylistGroupItem plg) { this._plgroupitems.Remove(plg); }
/// <summary> /// OK: create new playlist /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnOk_Click(object sender, EventArgs e) { string name = txtPlName.Text; string NewStyle = txtStyle.Text; name = name.Trim(); NewStyle = NewStyle.Trim(); TreeNode tn = tvPlaylistGroup.SelectedNode; if (tn == null) { return; } string Key = tn.Tag.ToString() == "playlist" ? tn.Parent.Tag.ToString() : tn.Tag.ToString(); /* * string Key = string.Empty; * if (tn.Tag.ToString() == "playlist") * { * Key = tn.Parent.Tag.ToString(); * } * else * { * Key = tn.Tag.ToString(); * } */ // check if the new playlist already exists in the selected folder (PlaylistGroupItem) PlaylistGroupItem pli = PlGroupHelper.Find(PlGroup, Key); if (PlGroupHelper.PlaylistExist(pli.Playlists, name)) { string tx = string.Format("The playlist <{0}> already exists in the folder <{1}>", name, pli.Name); MessageBox.Show(tx, "Karaboss", MessageBoxButtons.OK); CancelClose = true; return; } int nbAdded = 0; int nbTotal = 0; if (Songs != null) { nbTotal = Songs.Count; } // Create playlist and add it to the PlaylistGroupItem Playlist pl = new Playlist() { Name = name, Style = NewStyle, }; string iSong = string.Empty; // If songs have to be added to the new playlist if (nbTotal > 0 && Songs != null) { for (int i = 0; i < Songs.Count; i++) { iSong = Path.GetFileNameWithoutExtension(Songs[i]); if (pl.Add("<Artist>", iSong, Songs[i], "<Album>", "00:00", 4, "<DirSlideShow>", false, "<Song reserved by>")) { nbAdded++; } } } else { // Add an empty song pl.Add("<Artist>", "<Song>", "", "<Album>", "00:00", 4, "<DirSlideShow>", false, "<Karaoke singer>"); } pli.Playlists.Add(pl); // Sort playlists pli.Sort(); // Save all SaveAllPlaylists(); if (Songs == null) { MessageBox.Show("Playlist <" + pl.Name + "> created", "Karaboss", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(nbAdded + "/" + nbTotal + " songs added to <" + pl.Name + ">", "Karaboss", MessageBoxButtons.OK, MessageBoxIcon.Information); } _playlistname = pl.Name; this.Close(); }
/// <summary> /// Populate Treeview (list of Playlists) /// </summary> /// <param name="plg"></param> /// <param name="selectedKey"></param> private void PopulatetvPlaylistGroup(PlaylistGroup plg, string selectedKey = null) { TreeNode tnPl; tvPlaylistGroup.Nodes.Clear(); tvPlaylistGroup.BeginUpdate(); for (int i = 0; i < plg.Count; i++) { PlaylistGroupItem item = plg.plGroupItems[i]; // 1 - Create folder node named item.Name TreeNode tnFolder = new TreeNode(item.Name) { Name = item.Name, ImageIndex = 0, Tag = item.Key, }; // Position new node under item.Parent; TreeNode tnParent = null; if (item.ParentKey != null && tvPlaylistGroup.Nodes.Count > 0) { // Search for a treenode aving a tag equal to ParentKey foreach (TreeNode node in tvPlaylistGroup.Nodes) { var result = FindString(item.ParentKey, node); if (result != null) { tnParent = result; break; } } } // 2 - Add folder node to root or to an existing folder node if (tnParent != null) { tnParent.Nodes.Add(tnFolder); } else { tvPlaylistGroup.Nodes.Add(tnFolder); } // 3 - Add child nodes (playlists) for (int j = 0; j < item.Playlists.Count; j++) { Playlist pl = item.Playlists[j]; tnPl = new TreeNode(pl.Name) { Tag = "playlist", }; // image for treenode not selected tnPl.ImageIndex = 1; // image for selected treenode tnPl.SelectedImageIndex = 2; tnFolder.Nodes.Add(tnPl); } } tvPlaylistGroup.EndUpdate(); tvPlaylistGroup.ExpandAll(); // Set focus to selected node TreeNode tns = null; if (selectedKey != null) { if (tvPlaylistGroup.Nodes.Count > 0) { foreach (TreeNode node in tvPlaylistGroup.Nodes) { var result = FindString(selectedKey, node); if (result != null) { tns = result; break; } } } } if (tns != null) { tvPlaylistGroup.SelectedNode = tns; if (tns.LastNode != null) { tns.LastNode.EnsureVisible(); } else { tns.EnsureVisible(); } } else if (tvPlaylistGroup.Nodes.Count > 0) { tvPlaylistGroup.SelectedNode = tvPlaylistGroup.Nodes[0]; } }