Inheritance: INotifyPropertyChanged
Example #1
0
 public bool GetFromCache(ListboxEntry entry)
 {
     Uri uri = null;
       if (m_Cache.TryGetValue(entry.Key, out uri)) {
     entry.ImageUrl = uri;
     return true;
       }
       return false;
 }
Example #2
0
        public void Add(ListboxEntry entry, int index)
        {
            if (GetFromCache(entry))
            return;

              m_Mutex.WaitOne();
              if (m_Entries.Contains(entry))
            m_Entries.Remove(entry);

              if (index < 0)
            m_Entries.Add(entry);
              else
            m_Entries.Insert(index, entry);
              m_Mutex.ReleaseMutex();
        }
Example #3
0
    private async void lstGenres_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
      if (!CheckMpdConnection())
        return;

      if (lstGenres.SelectedItem == null) {
        m_GenresAlbumsSource.Clear();
        return;
      }

      m_GenresAlbumsSpinner.Visibility = Visibility.Visible;
      m_GenresAlbumsSource.Clear();
      string genre = lstGenres.SelectedItem.ToString();
      if (genre == Mpc.NoGenre)
        genre = string.Empty;

      List<MpdFile> files = null;
      try{
        files = await Task.Factory.StartNew(() => m_Mpc.Find(ScopeSpecifier.Genre, genre));
      }catch (Exception ex){
        m_GenresAlbumsSpinner.Visibility = Visibility.Collapsed;
        ShowException(ex);        
        return;
      }
      files.Sort(delegate(MpdFile p1, MpdFile p2)
                 { 
                   return string.Compare(p1.Album, p2.Album);
                 });
      MpdFile lastFile = null;
      MpdFile last = files.Count > 0 ? files[files.Count - 1] : null;
      m_GenresAlbumsSource.Clear();
      foreach (MpdFile file in files){
        if (lastFile != null && lastFile.Album != file.Album || file == last){
          string album = file == last ? file.Album : lastFile.Album;
          if (string.IsNullOrEmpty(album))
            album = Mpc.NoAlbum;
          ListboxEntry entry = new ListboxEntry()
          {
            Type = ListboxEntry.EntryType.Album,
            Artist = file == last ? file.Artist : lastFile.Artist,
            Album = album
          };
          m_GenresAlbumsSource.Add(entry);
        }
        lastFile = file;
      }

      if (m_GenresAlbumsSource.Count > 0) {
        lstGenresAlbums.SelectedIndex = 0;
        lstGenresAlbums.ScrollIntoView(m_GenresAlbumsSource[0]);
      }
      m_GenresAlbumsSpinner.Visibility = Visibility.Collapsed;
    }
Example #4
0
    private async void lstArtist_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
      if (!CheckMpdConnection())
        return;

      if (lstArtist.SelectedItem == null) {
        m_AlbumsSource.Clear();
        return;
      }

      m_AlbumsSpinner.Visibility = Visibility.Visible;
      m_AlbumsSource.Clear();
      string artist = SelectedArtist();
      List<string> albums = null;
      try{
        albums = await Task.Factory.StartNew(() => m_Mpc.List(ScopeSpecifier.Album, ScopeSpecifier.Artist, artist));
      }catch (Exception ex){
        m_AlbumsSpinner.Visibility = Visibility.Collapsed;
        ShowException(ex);
        return;
      }
      albums.Sort();
      m_AlbumsSource.Clear();
      for (int i = 0; i < albums.Count; i++) {
        if (string.IsNullOrEmpty(albums[i]))
          albums[i] = Mpc.NoAlbum;
        ListboxEntry entry = new ListboxEntry() { Type = ListboxEntry.EntryType.Album, 
                                                  Artist = artist,
                                                  Album = albums[i] };
        m_AlbumsSource.Add(entry);
      }
      if (albums.Count > 0){
        lstAlbums.SelectedIndex = 0;
        lstAlbums.ScrollIntoView(m_AlbumsSource[0]);
      }
      m_AlbumsSpinner.Visibility = Visibility.Collapsed;
    }
Example #5
0
    } // Connect

    private async Task<bool> PopulateArtists()
    {
      if (!CheckMpdConnection())
        return false;

      m_ArtistsSpinner.Visibility = Visibility.Visible;
      m_ArtistsSource.Clear();

      List<string> artists = null;
      try{
        artists = await Task.Factory.StartNew(() => m_Mpc.List(ScopeSpecifier.Artist));
      }catch (Exception ex){
        m_ArtistsSpinner.Visibility = Visibility.Collapsed;
        ShowException(ex);
        return false;
      }

      artists.Sort();
      for (int i = 0; i < artists.Count; i++) {
        if (string.IsNullOrEmpty(artists[i]))
          artists[i] = Mpc.NoArtist;
        ListboxEntry entry = new ListboxEntry() { Type = ListboxEntry.EntryType.Artist, 
                                                  Artist = artists[i] };
          m_ArtistsSource.Add(entry);
      }

      if (artists.Count > 0) {
        lstArtist.SelectedIndex = 0;
        lstArtist.ScrollIntoView(m_ArtistsSource[0]);
      }

      m_ArtistsSpinner.Visibility = Visibility.Collapsed;
      return true;
    }
Example #6
0
        void Add(ListboxEntry entry, int index)
        {
            if (GetFromCache(entry))
            return;

              m_Mutex.WaitOne();
              m_Entries.Add(entry);
              m_Mutex.ReleaseMutex();
        }
Example #7
0
 public void Soon(ListboxEntry entry)
 {
     Add(entry, -1);
 }
Example #8
0
 public void Now(ListboxEntry entry)
 {
     Add(entry, 0);
 }
Example #9
0
        public bool GetFromCache(ListboxEntry entry)
        {
            Uri uri = null;
              if (m_Cache.TryGetValue(entry.Key, out uri)) {
            entry.ImageUrl = uri;
            return uri != null || entry.Tracks == null;
              }
              else
              {
            var url = DiskImageCache.GetFromCache(new Uri(entry.Key, UriKind.Relative), entry.Key);
            if (!string.IsNullOrEmpty(url))
            {
              m_Cache[entry.Key] = new Uri(url);
              return true;
            }
              }

              return false;
        }
Example #10
0
        private void lstAlbums_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (m_Mpc == null || !m_Mpc.Connected)
            return;

              ListBox list = sender as ListBox;
              if (list.SelectedItem != null) {
            Dictionary<ScopeSpecifier, string> search = new Dictionary<ScopeSpecifier, string>();

            ListBox listBox = null;
            if (tabBrowse.SelectedIndex == 0 && lstArtist.SelectedItem != null) {
              string artist = lstArtist.Selected().Artist();
              search[ScopeSpecifier.Artist] = artist;
              listBox = lstAlbums;
            } else if (tabBrowse.SelectedIndex == 1 && lstGenres.SelectedItem != null) {
              string genre = lstGenres.SelectedItem.ToString();
              if (genre == Mpc.NoGenre)
            genre = string.Empty;
              search[ScopeSpecifier.Genre] = genre;
              listBox = lstGenresAlbums;
            }

            var album = listBox.Selected();
            search[ScopeSpecifier.Album] = album.Album();

               Action<Cancel, Action<Action>> populate = (c, call) => {
               try {
            if (c.cancel)
              return;
            if (album != null) {
              album.Related.Do(r => r.Selected = true);

              if (e != null) {
            var old = e.RemovedItems.OfType<ListboxEntry>().FirstOrDefault();
            if (old != null && !(album.Related != null && album.Related.Contains(old)))
              old.Related.Do(r => r.Selected = false);
              }

              if (c.cancel)
            return;
              call(() => {
              listBox.ScrollIntoView(album);
              });
            }

            try {
              m_Tracks = m_Mpc.Find(search);
              if (c.cancel)
            return;
              if (album != null) {
            Albums[album.Artist + ":" + album.Album] = album;
            album.Tracks = () => m_Tracks;
            if (album.Info == null)
              album.Info = new ObservableCollection<object>();
            m_ArtDownloader.Now(album);
              }
              m_Tracks.Do(m => m.AlbumEntry = album);
              var selection = m_Tracks.ToDictionary(m => m.File);
              var all = m_Tracks
            .OrderBy(m => m.Disc).ThenBy(m => m.TrackNo).ThenBy(m => m.Title, Utilities.VersionComparer.Instance)
            .GroupBy(m => dir.Replace(m.File, "$1"))
            .Where(g => {
              if (album != null && album.Album != "Misc")
                FindInfo(album.Info, g.Key, 20, Dispatcher);
              return true;
            })
            .SelectMany(Utilities.Try<IGrouping<string, MpdFile>, IEnumerable<MpdFile>>(g =>
              m_Mpc.ListAllInfo(g.Key)
                .OrderBy(m => m.Disc).ThenBy(m => m.TrackNo).ThenBy(m => m.Title, Utilities.VersionComparer.Instance)
                .Where(m => (m.Supplement = !selection.Remove(m.File)) || true)
            ))
            .ToList();
              if (c.cancel)
            return;
              all.GroupBy(m => m.Artist).Do(a =>
            a.GroupBy(m => m.Album).Do(b => {
            var i = new ListboxEntry() {
              Type = ListboxEntry.EntryType.Album,
              Artist = a.Key,
              Album = b.Key,
              Tracks = () => b,
            };
            b.Do(m => m.AlbumEntry = i);
            m_ArtDownloader.Soon(i);
              }));
              all.AddRange(selection.Values);
              if (c.cancel)
            return;
              call(() => {
            if (album != null)
              lstInfo.ItemsSource = album.Info;
            lstTracks.ItemsSource = all;
            ScrollTracksToLeft();
              });
            }
            catch (Exception ex)
            {
            ShowException(ex);
            return;
            }
               } finally {
            lock(lstArtist_Jobs)
              lstArtist_Jobs.Remove(c);
               }};
               var cancel = new Cancel();
               Cancel.Set(lstArtist_Jobs, cancel);
               if (navigating)
             populate(cancel, x => x());
               else
             populate.BeginInvoke(cancel, (Action<Action>)(x => Dispatcher.BeginInvoke(x)), populate.EndInvoke, null);
              }
              else
              {
            m_Tracks = null;
            lstTracks.ItemsSource = null;
              }
        }
Example #11
0
        private void PopulateArtists()
        {
            if (m_Mpc == null || !m_Mpc.Connected)
            return;

              m_ArtistsSource.Clear();
              List<string> artists = null;
              try{
            artists = m_Mpc.List(ScopeSpecifier.Artist);
              }catch (Exception ex){
            ShowException(ex);
            return;
              }

              artists.Sort();
              for (int i = 0; i < artists.Count; i++) {
            if (string.IsNullOrEmpty(artists[i]))
              continue;
            ListboxEntry entry = new ListboxEntry() { Type = ListboxEntry.EntryType.Artist,
                                                  Artist = artists[i] };
            m_ArtistsSource.Add(entry);
              }
              if (artists.Count > 0){
            lstArtist.SelectedIndex = 0;
            lstArtist.ScrollIntoView(m_ArtistsSource[0]);
              }
        }
Example #12
0
        private void MpcIdleSubsystemsChanged(Mpc connection, Mpc.Subsystems subsystems)
        {
            if (m_Mpc == null || !m_Mpc.Connected)
            return;

              MpdStatus status = null;
              try{
            status = m_Mpc.Status();
              }catch{
            return;
              }
              if ((subsystems & Mpc.Subsystems.output) != 0) {
            var os = m_Mpc.Outputs();
            Outputs.Where(o => !os.Any(_ => _.Name == o.Name && ((o.IsEnabled = _.IsEnabled) || true))).ToList().Count(Outputs.Remove);
            os.Where(o => o.Name != "Quiet" && !Outputs.Any(_ => _.Name == o.Name)).Select(o => new Output() {
              Name = o.Name,
              Id = o.Id,
              IsEnabled = o.IsEnabled,
              Mpc = m_Mpc,
             }).Do(Outputs.Add);
              }
              if ((subsystems & Mpc.Subsystems.player) != 0 || (subsystems & Mpc.Subsystems.mixer) != 0 ||
              (subsystems & Mpc.Subsystems.options) != 0){
            Dispatcher.BeginInvoke(new Action(() =>
            {
              MenuItem m = m_NotifyIconMenu.Items[1] as MenuItem;
              m.Visibility = status.State != MpdState.Play ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
              m = m_NotifyIconMenu.Items[2] as MenuItem;
              m.Visibility = status.State == MpdState.Play ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;

              MpdFile file = m_Mpc.CurrentSong();
              if (file != null)
              {
            ListboxEntry album;
            if (Albums.TryGetValue(file.Artist + ":" + file.Album, out album))
              file.AlbumEntry = album;
            else
            {
              file.AlbumEntry = album = new ListboxEntry();
              album.Info = new ObservableCollection<object>();
              Action<IList<object>, string, int, System.Windows.Threading.Dispatcher> find = FindInfo;
              find.BeginInvoke(
                album.Info, dir.Replace(file.File, "$1"), 5, Dispatcher,
                find.EndInvoke, null
              );
            }
              }
              playerControl.Update(status, file);
              if (m_MiniPlayer != null)
            m_MiniPlayer.Update(status, file);

              if (m_CurrentTrack == null || file == null || m_CurrentTrack.Id != file.Id) {
            TrackChanged(file);
            m_CurrentTrack = file;
            CurrentTrackId = file != null ? file.Id : 0;
            m_CurrentTrackStart = DateTime.Now;
              }
            }));
              }

              if ((subsystems & Mpc.Subsystems.playlist) != 0){
            Dispatcher.BeginInvoke(new Action(() =>
            {
              PopulatePlaylist();
            }));
              }

              if ((subsystems & Mpc.Subsystems.update) != 0){
            int lastUpdate = m_LastStatus != null ? m_LastStatus.UpdatingDb : -1;
            Dispatcher.BeginInvoke(new Action(() =>
            {
              btnUpdate.IsEnabled = status.UpdatingDb <= 0;
              // Update db finished:
              if (lastUpdate > 0 && status.UpdatingDb <= 0)
              UpdateDbFinished();
            }));
              }

              if ((subsystems & Mpc.Subsystems.subscription) != 0)
            PopulateChannels();
              if ((subsystems & Mpc.Subsystems.message) != 0)
            PopulateMessages();

              m_LastStatus = status;
        }