示例#1
0
        private void queryPlaylist()
        {
            if (tbxSearch.Text != "")
            {
                if (mediaListBackup == null)
                {
                    mediaListBackup = new List<Media>();
                    mediaListBackup.AddRange((Media[])Playlist.Instance);
                }

                Query.Match match = new Query.Match();
                match.lhs = Query.MatchLHS.All;
                match.op = Query.MatchOp.Contains;
                match.rhs = tbxSearch.Text;

                List<Query.Match> matches = new List<Query.Match>();
                matches.Add(match);

                Query q = new Query(matches);
                q.conj = Query.Conjunction.And;
                q.sort.by = this.StandardQuery.sort.by;
                q.sort.order = this.StandardQuery.sort.order;
                q.numberOfResults = -1;

                queryEngine qe = new queryEngine();
                qe.Data = mediaListBackup.ToArray();
                Media[] result = qe.query(q);

                Playlist.Instance.clearPlaylist();
                Playlist.Instance.addMedia(result);

                lvPlaylist.SelectedIndices.Clear();
                if (lvPlaylist.VirtualListSize > 0) lvPlaylist.Items[0].EnsureVisible();
                lvPlaylist.VirtualListSize = Playlist.Instance.Count;
                lvPlaylist.Refresh();
            }
            else
            {
                if (mediaListBackup != null)
                {
                    StandardQuery.sort.by = Query.SortBy.Smart;
                    StandardQuery.sort.order = Query.SortOrder.Ascending;

                    Playlist.Instance.clearPlaylist();
                    Playlist.Instance.addMedia(mediaListBackup.ToArray());
                    mediaListBackup = null;
                    updatePlaylist();
                }
            }
        }
示例#2
0
        private void tvMediaLibrary_DoubleClick(object sender, EventArgs e)
        {
            TreeNode node = tvMediaLibrary.SelectedNode;

            if (node != null && node.Tag != null)
            {
                if (node == tnMediaLibrary)
                {
                    MediaDB.Instance.rebuild();
                    MediaDB.Instance.commit();
                    Playlist.Instance.clearPlaylist();
                    Playlist.Instance.addMedia(MediaDB.Instance.mediaList.ToArray());
                    mediaListBackup = null;
                    tbxSearch.Text = "";
                    updatePlaylist();
                }
                if (node.Parent == tnPlaylists)
                {
                    try
                    {
                        Playlist.Instance.loadFromFile((Uri)node.Tag, false);
                        mediaListBackup = null;
                        tbxSearch.Text = "";
                    }
                    catch (IOException)
                    {
                        MessageBox.Show("One or more files from the Playlist are already in use", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }

                    updatePlaylist();
                }
                else if (node.Parent == tnSmartlists)
                {
                    Query q = (Query)node.Tag;

                    queryEngine qe = new queryEngine();
                    qe.Data = MediaDB.Instance.mediaList.ToArray();
                    Media[] result = qe.query(q);

                    Playlist.Instance.clearPlaylist();
                    Playlist.Instance.addMedia(result);

                    lvPlaylist.SelectedIndices.Clear();
                    if (lvPlaylist.VirtualListSize > 0) lvPlaylist.Items[0].EnsureVisible();
                    lvPlaylist.VirtualListSize = Playlist.Instance.Count;
                    lvPlaylist.Refresh();

                }
                else if (node.Parent == tnAudioCDs)
                {
                    string drive = (string)node.Tag;
                    List<Media> tracks = new List<Media>();

                    foreach (string file in Directory.GetFiles(drive, "*.cda", SearchOption.TopDirectoryOnly))
                    {
                        tracks.Add(new Media(new Uri(file)));
                    }

                    Playlist.Instance.clearPlaylist();
                    Playlist.Instance.addMedia(tracks.ToArray());

                    lvPlaylist.SelectedIndices.Clear();
                    if (lvPlaylist.VirtualListSize > 0) lvPlaylist.Items[0].EnsureVisible();
                    lvPlaylist.VirtualListSize = Playlist.Instance.Count;
                    lvPlaylist.Refresh();
                }
                else if (node.Parent == tnPeer2Peer)
                {
                    P2PDB.Instance.Resolve((NetService)node.Tag);
                }
            }
        }