Beispiel #1
0
 /// <summary>
 /// Invoked when the user clicks "Save" in playlist context menu
 /// </summary>
 /// <param name="sender">The sender of the event</param>
 /// <param name="e">The event data</param>
 public void SavePlaylist_Clicked(object sender, RoutedEventArgs e)
 {
     foreach (TreeViewItem tvi in GetCurrentItems())
     {
         PlaylistData pld = Tvi2Pl(tvi);
         try
         {
             Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();
             dialog.Title      = "Save Playlist";
             dialog.DefaultExt = ".pls";
             dialog.Filter     = "Playlist (*.pls)|*.pls|Playlist (*.m3u)|*.m3u";
             dialog.FileName   = pld.Name;
             bool result = (bool)dialog.ShowDialog();
             if (result == true)
             {
                 PlaylistManager.SavePlaylist(dialog.FileName, pld.Name);
             }
         }
         catch (Exception exc)
         {
             MessageBox.Show(U.T("MessageSavingPlaylist", "Message") + ":\n" + exc.Message,
                             U.T("MessageSavingPlaylist", "Title"),
                             MessageBoxButton.OK,
                             MessageBoxImage.Error);
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Invoked when the user selects to rename a playlist item.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event data</param>
        public void RenamePlaylist_Clicked(object sender, RoutedEventArgs e)
        {
            EditableTextBlock etb = sender as EditableTextBlock;

            if (etb == null && sender is TreeViewItem)
            {
                etb = Tvi2Etb(sender as TreeViewItem);
            }
            if (etb == null)
            {
                etb = Tvi2Etb(NavigationTree.SelectedItem as TreeViewItem);
            }
            if (etb == null || !etb.IsEditable)
            {
                return;
            }
            var playlist = PlaylistManager.FindPlaylist(etb.Text);

            // do not rename playlists we don't own
            if (PlaylistManager.IsSomeoneElses(playlist))
            {
                return;
            }

            etb.IsInEditMode = true;
        }
Beispiel #3
0
        /// <summary>
        /// Invoked when the control has been fully loaded.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event data</param>
        private void Navigation_Loaded(object sender, RoutedEventArgs e)
        {
            if (SettingsManager.CurrentSelectedNavigation.StartsWith("Playlist:"))
            {
                if (PlaylistManager.FindPlaylist(SettingsManager.CurrentSelectedNavigation.Split(new[] { ':' }, 2)[1]) == null)
                {
                    SettingsManager.CurrentSelectedNavigation = "Files";
                }
            }

            if (System.Windows.Forms.VisualStyles.VisualStyleInformation.DisplayName == "")
            {
                NavigationTree.ItemContainerStyle = (Style)TryFindResource("ClassicNavigationStyle");
                NowPlaying.ItemContainerStyle     = (Style)TryFindResource("ClassicNavigationStyle");
                Music.ItemContainerStyle          = (Style)TryFindResource("ClassicNavigationStyle");
                Playlists.ItemContainerStyle      = (Style)TryFindResource("ClassicNavigationStyle");
            }
            else
            {
                NavigationTree.ItemContainerStyle = (Style)TryFindResource("AeroNavigationStyle");
                NowPlaying.ItemContainerStyle     = (Style)TryFindResource("AeroNavigationStyle");
                Music.ItemContainerStyle          = (Style)TryFindResource("AeroNavigationStyle");
                Playlists.ItemContainerStyle      = (Style)TryFindResource("AeroNavigationStyle");
            }

            AddToPlaylistQueue = new List <object>();
        }
        /// <summary>
        /// Invoked when the user clicks "Generate".
        /// </summary>
        /// <remarks>
        /// Will verify the name and generate a playlist.
        /// </remarks>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event data</param>
        private void Generate_Click(object sender, RoutedEventArgs e)
        {
            Regex alphaNumPattern = new Regex("[^a-zA-Z0-9 ]");

            if (alphaNumPattern.IsMatch(ListName.Text))
            {
                ErrorMessage.Text       = U.T("DialogNameInvalidError");
                ErrorMessage.Visibility = System.Windows.Visibility.Visible;
            }
            else if (ListName.Text == "")
            {
                ErrorMessage.Text       = U.T("DialogNameEmptyError");
                ErrorMessage.Visibility = System.Windows.Visibility.Visible;
            }
            else if (PlaylistManager.FindPlaylist(ListName.Text) != null)
            {
                ErrorMessage.Text       = U.T("DialogNameExistsError");
                ErrorMessage.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                // copy tracks to temporary list
                List <TrackData> tracks = new List <TrackData>();
                string           filter = GetFilter();
                foreach (TrackData t in GetTracks())
                {
                    if (!(bool)DoFilter.IsChecked || filterMatches(t, filter))
                    {
                        tracks.Add(t);
                    }
                }

                int n = GetNumber();
                if (n < 0)
                {
                    return;
                }

                if (tracks.Count > 0)
                {
                    // create empty playlist
                    PlaylistData p = PlaylistManager.CreatePlaylist(ListName.Text);
                    if (p != null)
                    {
                        // move tracks from temporary list into playlist
                        for (int i = 0; i < n && tracks.Count > 0; i++)
                        {
                            Random    r = new Random();
                            int       x = r.Next(tracks.Count - 1);
                            TrackData t = tracks[x];
                            p.Tracks.Add(t);
                            tracks.RemoveAt(x);
                        }
                    }
                }

                Close();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Returns the playlist corresponding to a TreeViewItem if possible
        /// </summary>
        /// <param name="tvi">The playlist item in the TreeView</param>
        /// <returns>The corresponding playlist if such could be found, otherwise null</returns>
        private PlaylistData Tvi2Pl(TreeViewItem tvi)
        {
            EditableTextBlock etb = Tvi2Etb(tvi);

            if (etb == null)
            {
                return(null);
            }
            return(PlaylistManager.FindPlaylist(etb.Text));
        }
Beispiel #6
0
 /// <summary>
 /// Invoked when the "New playlist" item has been edited.
 /// </summary>
 /// <param name="sender">The sender of the event</param>
 /// <param name="e">The event data</param>
 private void CreateNewPlaylist_Edited(object sender, EditableTextBlockEventArgs e)
 {
     if (e.NewText != U.T("NavigationCreateNew") && e.NewText != "")
     {
         List <object> addQueue = AddToPlaylistQueue;
         PlaylistManager.CreatePlaylist(e.NewText, addQueue.Count == 0);
         if (addQueue.Count > 0)
         {
             PlaylistManager.AddToPlaylist(addQueue, e.NewText);
             addQueue.Clear();
         }
     }
     else
     {
         CreateNewPlaylist_Canceled(sender, e);
     }
 }
Beispiel #7
0
        /// <summary>
        /// Invoked after a short delay after the user has changed the URL text.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event data</param>
        private void inputDelay_Tick(object sender, EventArgs e)
        {
            inputDelay.Stop();

            ToggleProgressbar(true);

            string url = URL.Text;

            if (PlaylistManager.IsSupported(url))
            {
                ThreadStart ParseThread = delegate()
                {
                    HttpWebRequest  req  = (HttpWebRequest)WebRequest.Create(url);
                    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                    Stream          str  = resp.GetResponseStream();
                    Encoding        enc  = Encoding.GetEncoding("utf-8");
                    StreamReader    read = new StreamReader(str, enc);

                    URLs.Clear();
                    foreach (TrackData track in PlaylistManager.ParsePlaylist(read, PlaylistManager.GetType(url)))
                    {
                        track.Icon = "pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/Radio.ico";
                        URLs.Add(track);
                    }

                    resp.Close();
                    read.Close();

                    ToggleProgressbar(false);

                    if (callCallback && callback != null)
                    {
                        callback(URLs);
                    }
                };
                Thread parse_thread = new Thread(ParseThread);
                parse_thread.Name         = "URL Parser";
                parse_thread.IsBackground = true;
                parse_thread.Priority     = ThreadPriority.Lowest;
                parse_thread.Start();
            }
            else
            {
                MediaManager.ParseURLAsync(URL.Text, URL_Parsed, true);
            }
        }
Beispiel #8
0
 /// <summary>
 /// Invoked when the users selects to remove a playlist item.
 /// </summary>
 /// <param name="sender">The sender of the event</param>
 /// <param name="e">The event data</param>
 public void RemovePlaylist_Clicked(object sender, RoutedEventArgs e)
 {
     foreach (TreeViewItem tvi in GetCurrentItems())
     {
         PlaylistData pld = Tvi2Pl(tvi);
         if (pld != null)
         {
             string title   = U.T("MessageDeletePlaylist", "Title");
             string message = U.T("MessageDeletePlaylist", "Message");
             message = message.Replace("%name", pld.Name);
             if (pld.Tracks.Count == 0 ||
                 MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
             {
                 PlaylistManager.RemovePlaylist(pld.Name);
             }
         }
     }
 }
 /// <summary>
 /// Gets the corresponding collection of tracks given the selected list.
 /// </summary>
 /// <returns>The collection of tracks corresponding to the selected list</returns>
 private ObservableCollection <TrackData> GetTracks()
 {
     if (Lists.SelectedIndex > 0)
     {
         ComboBoxItem cbi = Lists.SelectedItem as ComboBoxItem;
         PlaylistData p   = PlaylistManager.FindPlaylist((string)cbi.Content);
         if (p != null)
         {
             return(p.Tracks);
         }
         else
         {
             return(new ObservableCollection <TrackData>());
         }
     }
     else
     {
         return(SettingsManager.FileTracks);
     }
 }
 /// <summary>
 /// Gets the corresponding filter given the selected list.
 /// </summary>
 /// <returns>The filter corresponding to the selected list</returns>
 private string GetFilter()
 {
     if (Lists.SelectedIndex > 0)
     {
         ComboBoxItem cbi = Lists.SelectedItem as ComboBoxItem;
         PlaylistData p   = PlaylistManager.FindPlaylist((string)cbi.Content);
         if (p != null)
         {
             return(p.ListConfig.Filter);
         }
         else
         {
             return("");
         }
     }
     else
     {
         return(SettingsManager.FileListConfig.Filter);
     }
 }
Beispiel #11
0
        /// <summary>
        /// Invoked when the user right-clicks on a playlist
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event data</param>
        public void Playlist_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            TreeViewItem tvi = sender as TreeViewItem;

            if (tvi == null)
            {
                return;
            }
            if (!tvi.IsSelected)
            {
                rightClickedTvi = tvi;
                tvi.IsSelected  = true;
            }

            playlistMenuRename.Visibility = Visibility.Visible;

            var dp = tvi.Header as DockPanel;

            if (dp == null)
            {
                return;
            }
            var etb = dp.Children[1] as EditableTextBlock;

            if (etb == null)
            {
                return;
            }
            var pl = PlaylistManager.FindPlaylist(etb.Text);

            if (pl == null)
            {
                return;
            }

            // do not rename playlists we don't own
            if (PlaylistManager.IsSomeoneElses(pl))
            {
                playlistMenuRename.Visibility = Visibility.Collapsed;
            }
        }
Beispiel #12
0
        /// <summary>
        /// Invoked when a drop occurs on a playlist item.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event data</param>
        public void Playlist_Drop(object sender, DragEventArgs e)
        {
            List <object>     DraggedItems = e.Data.GetData(typeof(List <object>)) as List <object>;
            TreeViewItem      tvi          = sender as TreeViewItem;
            DockPanel         dp           = tvi.Header as DockPanel;
            EditableTextBlock etb          = dp.Children[1] as EditableTextBlock;

            if (etb.Text == U.T("NavigationCreateNew"))
            {
                AddToPlaylistQueue.Clear();
                foreach (TrackData track in DraggedItems)
                {
                    AddToPlaylistQueue.Add(track);
                }
                CreateNewPlaylistETB.IsInEditMode = true;
            }
            else
            {
                PlaylistManager.AddToPlaylist(DraggedItems, etb.Text);
            }
        }
Beispiel #13
0
 /// <summary>
 /// Invoked when a playlist's name has been edited.
 /// </summary>
 /// <param name="sender">The sender of the event</param>
 /// <param name="e">The event data</param>
 public void Playlist_Edited(object sender, EditableTextBlockEventArgs e)
 {
     PlaylistManager.RenamePlaylist(e.OldText, e.NewText);
     SelectPlaylist(e.NewText);
 }