private Query.Match createMatch(string rhs, int cbxMatch, int cbxOp) { Query.Match m = null; if (rhs != "") { m = new Query.Match(); switch (cbxMatch) { case 0: m.lhs = Query.MatchLHS.All; break; case 1: m.lhs = Query.MatchLHS.SHA1; break; case 2: m.lhs = Query.MatchLHS.TrackNr; break; case 3: m.lhs = Query.MatchLHS.Title; break; case 4: m.lhs = Query.MatchLHS.Album; break; case 5: m.lhs = Query.MatchLHS.Artist; break; case 6: m.lhs = Query.MatchLHS.Rating; break; case 7: m.lhs = Query.MatchLHS.Year; break; case 8: m.lhs = Query.MatchLHS.Genre; break; case 9: m.lhs = Query.MatchLHS.Comment; break; } switch (cbxOp) { case 0: m.op = Query.MatchOp.Is; break; case 1: m.op = Query.MatchOp.IsNot; break; case 2: m.op = Query.MatchOp.Contains; break; } m.rhs = rhs; } return m; }
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(); } } }