Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/MP1-4225-Music_Rating_vi…
Browse files Browse the repository at this point in the history
…ew_is_broken'
  • Loading branch information
HomeY committed Jul 24, 2014
2 parents 63ddde1 + 3479b1d commit 1eb1935
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
39 changes: 30 additions & 9 deletions mediaportal/Databases/Music/MusicDatabase.Lookups.cs
Expand Up @@ -42,7 +42,6 @@ public bool AssignAllSongFieldsFromResultSet(ref Song aSong, SQLiteResultSet aRe
{
return false;
}

aSong.Id = DatabaseUtility.GetAsInt(aResult, aRow, "tracks.idTrack");
aSong.FileName = DatabaseUtility.Get(aResult, aRow, "tracks.strPath");
aSong.Artist = DatabaseUtility.Get(aResult, aRow, "tracks.strArtist").Trim(trimChars);
Expand Down Expand Up @@ -236,9 +235,14 @@ public void GetSongsBySQL(string aSQL, out List<Song> aSongs)
}
}

public void GetSongsByFilter(string aSQL, out List<Song> aSongs, string filter)
public void GetSongsByFilter(string aSQL, out List<Song> aSongs, string aFilter)
{
Log.Debug("MusicDatabase: GetSongsByFilter - SQL: {0}, Filter: {1}", aSQL, filter);
GetSongsByFilter(aSQL, out aSongs, aFilter, string.Empty, false);
}

public void GetSongsByFilter(string aSQL, out List<Song> aSongs, string aFilter, string aSearchField, bool aGrouping)
{
Log.Debug("MusicDatabase: GetSongsByFilter - SQL: {0}, Filter: {1}", aSQL, aFilter);
aSongs = new List<Song>();
//if (string.IsNullOrEmpty(filter))
// return;
Expand All @@ -252,36 +256,53 @@ public void GetSongsByFilter(string aSQL, out List<Song> aSongs, string filter)
song = new Song();
SQLiteResultSet.Row fields = results.Rows[i];
int columnIndex = 0;
if (filter == "artist")
if (aFilter == "artist")
{
columnIndex = (int)results.ColumnIndices["strArtist"];
song.Artist = fields.fields[columnIndex].Trim(trimChars);
}
if (filter == "albumartist")
else if (aFilter == "albumartist")
{
columnIndex = (int)results.ColumnIndices["strAlbumArtist"];
song.AlbumArtist = fields.fields[columnIndex].Trim(trimChars);
}
if (filter == "album")
else if (aFilter == "album")
{
AssignAllSongFieldsFromResultSet(ref song, results, i);
}
if (filter == "genre")
else if (aFilter == "genre")
{
AssignAllSongFieldsFromResultSet(ref song, results, i);
columnIndex = (int)results.ColumnIndices["strGenre"];
song.Genre = fields.fields[columnIndex].Trim(trimChars);
}
if (filter == "composer")
else if (aFilter == "composer")
{
AssignAllSongFieldsFromResultSet(ref song, results, i);
columnIndex = (int)results.ColumnIndices["strComposer"];
song.Composer = fields.fields[columnIndex].Trim(trimChars);
}
if (filter == "tracks")
else if (aFilter == "tracks")
{
AssignAllSongFieldsFromResultSet(ref song, results, i);
}

// Now set the fields when we had grouping
if (aGrouping && aSearchField != string.Empty)
{
if (aSearchField.ToLower() == "rating")
{
song.Rating = Convert.ToInt32(fields.fields[0].Trim(trimChars));
}
else if (aSearchField.ToLower() == "year")
{
song.Year = Convert.ToInt32(fields.fields[0].Trim(trimChars));
}

// When we have grouping active, the second field contains the number of items found which shall be put into duration
song.Duration = Convert.ToInt16(fields.fields[1]);
}

aSongs.Add(song);
}
}
Expand Down
Expand Up @@ -164,13 +164,13 @@ public bool Execute(out List<Song> songs)
countField = "strAlbumArtist";
}

sql = String.Format("Select UPPER(SUBSTR({0},1,{1})) as IX, Count(distinct {2}) from {3} GROUP BY IX",
sql = String.Format("Select UPPER(SUBSTR({0},1,{1})) as IX, Count({2}) from {3} GROUP BY IX",
searchField, definition.Restriction, countField, searchTable);
// only group special characters into a "#" entry is field is text based
// only group special characters into a "#" entry is field is text based
if (defRoot.Where == "rating" || defRoot.Where == "year" || defRoot.Where == "track" || defRoot.Where == "disc#" ||
defRoot.Where == "timesplayed" || defRoot.Where == "favourites" || defRoot.Where == "date")
{
database.GetSongsByFilter(sql, out songs, table);
database.GetSongsByFilter(sql, out songs, table, defRoot.Where, true);
}
else
{
Expand Down Expand Up @@ -537,8 +537,8 @@ private void BuildSelect(FilterDefinition filter, ref string whereClause, int fi
}
else
{
whereClause += String.Format(" ({0} like '{1}%' or '{2}%')", GetField(filter.Where),
selectedValue.PadRight(restrictionLength), selectedValue);
whereClause += String.Format(" {0} like '{1}%'", GetField(filter.Where),
selectedValue.PadRight(restrictionLength));
}
}
}
Expand All @@ -552,8 +552,8 @@ private void BuildSelect(FilterDefinition filter, ref string whereClause, int fi
}
else
{
whereClause += String.Format(" ({0} like '{1}%' or '{2}%')", GetField(filter.Where),
selectedValue.PadRight(restrictionLength), selectedValue);
whereClause += String.Format(" {0} like '{1}%'", GetField(filter.Where),
selectedValue.PadRight(restrictionLength));
}
}
}
Expand Down
20 changes: 17 additions & 3 deletions mediaportal/WindowPlugins/GUIMusic/GUIMusicGenres.cs
Expand Up @@ -21,7 +21,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO;
using DShowNET.Helper;
using MediaPortal.Configuration;
using MediaPortal.Dialogs;
using MediaPortal.GUI.Library;
Expand Down Expand Up @@ -858,7 +859,10 @@ protected override void LoadDirectory(string strNotUsed)
pItem.IsFolder = true;
Util.Utils.SetDefaultIcons(pItem);
itemsToAdd.Add(pItem);
}
}

// Get current Filter used
var currentFilter = (FilterDefinition)handler.View.Filters[handler.CurrentLevel];

for (int i = 0; i < songs.Count; ++i)
{
Expand All @@ -874,7 +878,17 @@ protected override void LoadDirectory(string strNotUsed)
{
item.IsFolder = true;
item.Label = MusicViewHandler.GetFieldValue(song, handler.CurrentLevelWhere);
SetSortLabel(ref item, CurrentSortMethod, handler.CurrentLevelWhere);

// If we are grouping on a specific value, we have in the Duration field the number of items
// Use this in the sort field
if (currentFilter.SqlOperator == "group")
{
item.Label2 = tag.Duration.ToString();
}
else
{
SetSortLabel(ref item, CurrentSortMethod, handler.CurrentLevelWhere);
}
}
else
{
Expand Down

0 comments on commit 1eb1935

Please sign in to comment.