private void BuildSyncLists() { // This smart playlist is the list of items we want on the device - nothing more, nothing less sync_src = new SmartPlaylistSource("sync_list", library); sync_src.IsTemporary = true; sync_src.Save(); sync_src.AddCondition(library.AttributesCondition); sync_src.AddCondition(library.SyncCondition); // This is the same as the previous list with the items that are already on the device removed to_add = new SmartPlaylistSource("to_add", library); to_add.IsTemporary = true; to_add.Save(); to_add.ConditionTree = UserQueryParser.Parse(String.Format("smartplaylistid:{0}", sync_src.DbId), Banshee.Query.BansheeQuery.FieldSet); to_add.DatabaseTrackModel.AddCondition(String.Format( "MetadataHash NOT IN (SELECT MetadataHash FROM CoreTracks WHERE PrimarySourceId = {0})", sync.Dap.DbId )); // Any items on the device that aren't in the sync lists need to be removed to_remove = new SmartPlaylistSource("to_remove", sync.Dap); to_remove.IsTemporary = true; to_remove.Save(); to_remove.AddCondition(library.AttributesCondition); to_remove.AddCondition(String.Format( @"MetadataHash NOT IN (SELECT MetadataHash FROM CoreTracks, CoreSmartPlaylistEntries WHERE CoreSmartPlaylistEntries.SmartPlaylistID = {0} AND CoreTracks.TrackID = CoreSmartPlaylistEntries.TrackID)", sync_src.DbId )); }
internal void CalculateSync() { if (SyncEntireLibrary) { sync_src.ConditionTree = null; } else if (SyncSource != null) { var src = SyncSource; QueryListNode playlists_node = new QueryListNode(Keyword.Or); if (src is PlaylistSource) { playlists_node.AddChild(UserQueryParser.Parse(String.Format("playlistid:{0}", (src as PlaylistSource).DbId), BansheeQuery.FieldSet)); } else if (src is SmartPlaylistSource) { playlists_node.AddChild(UserQueryParser.Parse(String.Format("smartplaylistid:{0}", (src as SmartPlaylistSource).DbId), BansheeQuery.FieldSet)); } sync_src.ConditionTree = playlists_node; } sync_src.RefreshAndReload(); to_add.RefreshAndReload(); to_remove.RefreshAndReload(); }
private void GenerateUserQueryFragment() { if (!have_new_user_query) { return; } if (String.IsNullOrEmpty(UserQuery)) { query_fragment = null; query_tree = null; } else { query_tree = UserQueryParser.Parse(UserQuery, BansheeQuery.FieldSet); query_fragment = (query_tree == null) ? null : query_tree.ToSql(BansheeQuery.FieldSet); if (query_fragment != null && query_fragment.Length == 0) { query_fragment = null; query_tree = null; } } have_new_user_query = false; }
// Test behavior issues described in // http://bugzilla.gnome.org/show_bug.cgi?id=547078 public void ParenthesesInQuotes() { string query = "artist==\"foo (disc 2)\""; QueryNode query_tree = UserQueryParser.Parse(query, FieldSet); Assert.IsNotNull(query_tree, "Query should parse"); Assert.AreEqual("by==\"foo (disc 2)\"", query_tree.ToUserQuery()); }
public SmartPlaylistSource ToSmartPlaylistSource(PrimarySource primary_source) { return(new SmartPlaylistSource( Name, UserQueryParser.Parse(Condition, BansheeQuery.FieldSet), Order, Limit, LimitNumber, primary_source )); }
private static void UserQueryParsesAndGenerates(string query) { QueryNode node = UserQueryParser.Parse(query, FieldSet); if (query == null || query.Trim() == String.Empty) { Assert.AreEqual(node, null); return; } Assert.AreEqual(query, node.ToUserQuery()); }
public SearchResultInfo SearchFiles(string query) { string sql; IDbCommand command; DataSet ds; int x; SearchResultInfo result; var directories = new List <string>(); var files = new List <SharedFileListing>(); result = new SearchResultInfo(); var queryNode = UserQueryParser.Parse(query, FieldSet); var queryFragment = queryNode.ToSql(FieldSet); var sb = new StringBuilder(); sb.Append("SELECT * FROM directoryitems WHERE "); sb.Append(queryFragment); sb.AppendFormat(" LIMIT {0}", MAX_RESULTS); UseConnection(delegate(IDbConnection connection) { command = connection.CreateCommand(); command.CommandText = sb.ToString(); ds = ExecuteDataSet(command); for (x = 0; x < ds.Tables[0].Rows.Count; x++) { if (ds.Tables[0].Rows[x]["type"].ToString() == "F") { files.Add(new SharedFileListing(LocalFile.FromDataRow(core.FileSystem, ds.Tables[0].Rows[x]), false)); } else { var dir = LocalDirectory.FromDataRow(this, ds.Tables[0].Rows[x]); // FIXME: Ugly: Remove '/local' from begining of path var path = "/" + string.Join("/", dir.FullPath.Split('/').Slice(2)); directories.Add(path); } } }); result.Files = files.ToArray(); result.Directories = directories.ToArray(); return(result); }