Better structure for song sorter and bugfix for "DateAdded" sorting
This commit is contained in:
1 parent
65d029e333
commit
e1f8bf4843
7 files changed
+118
-135
No files matched your search
@@ -83,7 +83,7 @@ namespace Vocaluxe.Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region Highscores
|
#region Highscores
|
||||||
public static bool GetDataBaseSongInfos(string artist, string title, out int numPlayed, out string dateAdded, out int highscoreID)
|
public static bool GetDataBaseSongInfos(string artist, string title, out int numPlayed, out DateTime dateAdded, out int highscoreID)
|
||||||
{
|
{
|
||||||
string sArtist;
|
string sArtist;
|
||||||
string sTitle;
|
string sTitle;
|
||||||
@@ -384,12 +384,12 @@ namespace Vocaluxe.Base
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool _GetDataBaseSongInfos(int songID, out string artist, out string title, out int numPlayed, out string dateAdded, string filePath)
|
private static bool _GetDataBaseSongInfos(int songID, out string artist, out string title, out int numPlayed, out DateTime dateAdded, string filePath)
|
||||||
{
|
{
|
||||||
artist = String.Empty;
|
artist = String.Empty;
|
||||||
title = String.Empty;
|
title = String.Empty;
|
||||||
numPlayed = 0;
|
numPlayed = 0;
|
||||||
dateAdded = String.Empty;
|
dateAdded = DateTime.Today;
|
||||||
|
|
||||||
using (var connection = new SQLiteConnection())
|
using (var connection = new SQLiteConnection())
|
||||||
{
|
{
|
||||||
@@ -425,7 +425,7 @@ namespace Vocaluxe.Base
|
|||||||
artist = reader.GetString(0);
|
artist = reader.GetString(0);
|
||||||
title = reader.GetString(1);
|
title = reader.GetString(1);
|
||||||
numPlayed = reader.GetInt32(2);
|
numPlayed = reader.GetInt32(2);
|
||||||
dateAdded = new DateTime(reader.GetInt64(3)).ToString("dd/MM/yyyy");
|
dateAdded = new DateTime(reader.GetInt64(3));
|
||||||
reader.Dispose();
|
reader.Dispose();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1036,7 +1036,8 @@ namespace Vocaluxe.Base
|
|||||||
int shortsong = source.GetInt32(7);
|
int shortsong = source.GetInt32(7);
|
||||||
int diff = source.GetInt32(8);
|
int diff = source.GetInt32(8);
|
||||||
|
|
||||||
string artist, title, dateadded;
|
string artist, title;
|
||||||
|
DateTime dateadded;
|
||||||
int numplayed;
|
int numplayed;
|
||||||
if (_GetDataBaseSongInfos(songid, out artist, out title, out numplayed, out dateadded, sourceDBPath))
|
if (_GetDataBaseSongInfos(songid, out artist, out title, out numplayed, out dateadded, sourceDBPath))
|
||||||
AddScore(player, score, linenr, date, medley, duet, shortsong, diff, artist, title, numplayed, _HighscoreFilePath);
|
AddScore(player, score, linenr, date, medley, duet, shortsong, diff, artist, title, numplayed, _HighscoreFilePath);
|
||||||
|
|||||||
@@ -839,7 +839,7 @@ namespace Vocaluxe.Base
|
|||||||
return CDataBase.GetCover(fileName, ref texture, coverSize);
|
return CDataBase.GetCover(fileName, ref texture, coverSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GetDataBaseSongInfos(string artist, string title, out int numPlayed, out string dateAdded, out int highscoreID)
|
public bool GetDataBaseSongInfos(string artist, string title, out int numPlayed, out DateTime dateAdded, out int highscoreID)
|
||||||
{
|
{
|
||||||
return CDataBase.GetDataBaseSongInfos(artist, title, out numPlayed, out dateAdded, out highscoreID);
|
return CDataBase.GetDataBaseSongInfos(artist, title, out numPlayed, out dateAdded, out highscoreID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Diagnostics;
|
||||||
using VocaluxeLib;
|
using VocaluxeLib;
|
||||||
using VocaluxeLib.Songs;
|
using VocaluxeLib.Songs;
|
||||||
|
|
||||||
@@ -61,36 +61,10 @@ namespace Vocaluxe.Base
|
|||||||
_SetChanged();
|
_SetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _CreateCategoriesLetter()
|
private void _CreateCategories()
|
||||||
{
|
{
|
||||||
CCategory lastCategory = null;
|
_AdjustCategoryNames();
|
||||||
CCategory notLetterCat = null;
|
|
||||||
foreach (CSongPointer songPointer in CSongs.Sorter.SortedSongs)
|
|
||||||
{
|
|
||||||
Char firstLetter = Char.ToUpper(songPointer.SortString.Normalize(NormalizationForm.FormD)[0]);
|
|
||||||
if (Char.IsLetter(firstLetter))
|
|
||||||
{
|
|
||||||
if (lastCategory == null || firstLetter.ToString() != lastCategory.Name)
|
|
||||||
{
|
|
||||||
lastCategory = new CCategory(firstLetter.ToString());
|
|
||||||
_Categories.Add(lastCategory);
|
|
||||||
}
|
|
||||||
lastCategory.Songs.Add(songPointer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (notLetterCat == null)
|
|
||||||
{
|
|
||||||
notLetterCat = new CCategory("#");
|
|
||||||
_Categories.Add(notLetterCat);
|
|
||||||
}
|
|
||||||
notLetterCat.Songs.Add(songPointer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void _CreateCategoriesNormal(string noCategoryName)
|
|
||||||
{
|
|
||||||
CCategory lastCategory = null;
|
CCategory lastCategory = null;
|
||||||
CCategory noCategory = null;
|
CCategory noCategory = null;
|
||||||
foreach (CSongPointer songPointer in CSongs.Sorter.SortedSongs)
|
foreach (CSongPointer songPointer in CSongs.Sorter.SortedSongs)
|
||||||
@@ -108,7 +82,7 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
if (noCategory == null)
|
if (noCategory == null)
|
||||||
{
|
{
|
||||||
noCategory = new CCategory(noCategoryName);
|
noCategory = new CCategory(_GetNoCategoryName());
|
||||||
_Categories.Add(noCategory);
|
_Categories.Add(noCategory);
|
||||||
}
|
}
|
||||||
noCategory.Songs.Add(songPointer);
|
noCategory.Songs.Add(songPointer);
|
||||||
@@ -116,37 +90,15 @@ namespace Vocaluxe.Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _CreateCategories()
|
/// <summary>
|
||||||
|
/// Sets the SortStrings of the songpointers to the actual category names
|
||||||
|
/// </summary>
|
||||||
|
private static void _AdjustCategoryNames()
|
||||||
{
|
{
|
||||||
string noCategoryName = "";
|
|
||||||
|
|
||||||
ESongSorting sorting = CSongs.Sorter.SongSorting;
|
ESongSorting sorting = CSongs.Sorter.SongSorting;
|
||||||
|
|
||||||
switch (sorting)
|
switch (sorting)
|
||||||
{
|
{
|
||||||
case ESongSorting.TR_CONFIG_EDITION:
|
|
||||||
noCategoryName = CLanguage.Translate("TR_SCREENSONG_NOEDITION");
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_GENRE:
|
|
||||||
noCategoryName = CLanguage.Translate("TR_SCREENSONG_NOGENRE");
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_DECADE:
|
case ESongSorting.TR_CONFIG_DECADE:
|
||||||
case ESongSorting.TR_CONFIG_YEAR:
|
|
||||||
noCategoryName = CLanguage.Translate("TR_SCREENSONG_NOYEAR");
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_LANGUAGE:
|
|
||||||
noCategoryName = CLanguage.Translate("TR_SCREENSONG_NOLANGUAGE");
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_NONE:
|
|
||||||
noCategoryName = CLanguage.Translate("TR_SCREENSONG_ALLSONGS");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (sorting == ESongSorting.TR_CONFIG_ARTIST_LETTER || sorting == ESongSorting.TR_CONFIG_TITLE_LETTER)
|
|
||||||
_CreateCategoriesLetter();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (sorting == ESongSorting.TR_CONFIG_DECADE)
|
|
||||||
{
|
|
||||||
foreach (CSongPointer songPointer in CSongs.Sorter.SortedSongs)
|
foreach (CSongPointer songPointer in CSongs.Sorter.SortedSongs)
|
||||||
{
|
{
|
||||||
string year = songPointer.SortString;
|
string year = songPointer.SortString;
|
||||||
@@ -156,11 +108,59 @@ namespace Vocaluxe.Base
|
|||||||
songPointer.SortString = year + "0 - " + year + "9";
|
songPointer.SortString = year + "0 - " + year + "9";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
_CreateCategoriesNormal(noCategoryName);
|
case ESongSorting.TR_CONFIG_TITLE_LETTER:
|
||||||
|
case ESongSorting.TR_CONFIG_ARTIST_LETTER:
|
||||||
|
foreach (CSongPointer songPointer in CSongs.Sorter.SortedSongs)
|
||||||
|
songPointer.SortString = (songPointer.SortString.Length == 0 || !Char.IsLetter(songPointer.SortString, 0)) ? "#" : songPointer.SortString[0].ToString();
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_DATEADDED:
|
||||||
|
foreach (CSongPointer songPointer in CSongs.Sorter.SortedSongs)
|
||||||
|
songPointer.SortString = CSongs.GetSong(songPointer.SongID).DateAdded.ToString("dd/MM/yyyy");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string _GetNoCategoryName()
|
||||||
|
{
|
||||||
|
string noCategoryName;
|
||||||
|
switch (CSongs.Sorter.SongSorting)
|
||||||
|
{
|
||||||
|
case ESongSorting.TR_CONFIG_NONE:
|
||||||
|
noCategoryName = CLanguage.Translate("TR_SCREENSONG_ALLSONGS");
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_FOLDER:
|
||||||
|
case ESongSorting.TR_CONFIG_ARTIST:
|
||||||
|
case ESongSorting.TR_CONFIG_ARTIST_LETTER:
|
||||||
|
case ESongSorting.TR_CONFIG_TITLE_LETTER:
|
||||||
|
noCategoryName = "";
|
||||||
|
Debug.Assert(false, "Should not have an uncategorized song");
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_EDITION:
|
||||||
|
noCategoryName = CLanguage.Translate("TR_SCREENSONG_NOEDITION");
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_GENRE:
|
||||||
|
noCategoryName = CLanguage.Translate("TR_SCREENSONG_NOGENRE");
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_LANGUAGE:
|
||||||
|
noCategoryName = CLanguage.Translate("TR_SCREENSONG_NOLANGUAGE");
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_DECADE:
|
||||||
|
case ESongSorting.TR_CONFIG_YEAR:
|
||||||
|
noCategoryName = CLanguage.Translate("TR_SCREENSONG_NOYEAR");
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_DATEADDED:
|
||||||
|
noCategoryName = "";
|
||||||
|
Debug.Assert(false, "Should not have an uncategorized song");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
noCategoryName = "";
|
||||||
|
Debug.Assert(false, "Forgot category option");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return noCategoryName;
|
||||||
|
}
|
||||||
|
|
||||||
private void _FillCategories()
|
private void _FillCategories()
|
||||||
{
|
{
|
||||||
if (!_Changed)
|
if (!_Changed)
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using VocaluxeLib;
|
using VocaluxeLib;
|
||||||
using VocaluxeLib.Songs;
|
using VocaluxeLib.Songs;
|
||||||
|
|
||||||
@@ -110,83 +111,65 @@ namespace Vocaluxe.Base
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CSongPointer> _CreateSortList(string fieldName)
|
private void _AddSongToList(CSong song, List<CSongPointer> list)
|
||||||
{
|
{
|
||||||
var sortList = new List<CSongPointer>();
|
string value = null;
|
||||||
if (fieldName == "")
|
List<string> values = null;
|
||||||
CSongs.Filter.FilteredSongs.ForEach(song => sortList.Add(new CSongPointer(song.ID, "")));
|
switch (_SongSorting)
|
||||||
|
{
|
||||||
|
case ESongSorting.TR_CONFIG_NONE:
|
||||||
|
value = "";
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_FOLDER:
|
||||||
|
value = song.FolderName;
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_ARTIST:
|
||||||
|
case ESongSorting.TR_CONFIG_ARTIST_LETTER:
|
||||||
|
value = _IgnoreArticles == EOffOn.TR_CONFIG_ON ? song.ArtistSorting : song.Artist;
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_TITLE_LETTER:
|
||||||
|
value = _IgnoreArticles == EOffOn.TR_CONFIG_ON ? song.TitleSorting : song.Title;
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_EDITION:
|
||||||
|
values = song.Editions;
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_GENRE:
|
||||||
|
values = song.Genres;
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_LANGUAGE:
|
||||||
|
values = song.Languages;
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_DECADE:
|
||||||
|
case ESongSorting.TR_CONFIG_YEAR:
|
||||||
|
value = song.Year;
|
||||||
|
break;
|
||||||
|
case ESongSorting.TR_CONFIG_DATEADDED:
|
||||||
|
value = song.DateAdded.ToString("yyyyMMdd");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Debug.Assert(false, "Forgot sorting option");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Debug.Assert(value != null || values != null, "Sorting implementation faulty");
|
||||||
|
if (value != null)
|
||||||
|
list.Add(new CSongPointer(song.ID, value));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FieldInfo field = typeof(CSong).GetField(fieldName, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
|
if (list.Count == 0)
|
||||||
if (field == null)
|
list.Add(new CSongPointer(song.ID, ""));
|
||||||
{
|
else
|
||||||
CLog.LogError("Unknow sorting field: " + fieldName);
|
list.AddRange(values.Select(val => new CSongPointer(song.ID, val)));
|
||||||
return _CreateSortList("");
|
|
||||||
}
|
|
||||||
bool isString = field.FieldType == typeof(string);
|
|
||||||
if (!isString && field.FieldType != typeof(List<String>))
|
|
||||||
throw new Exception("Unkown sort field type");
|
|
||||||
foreach (CSong song in CSongs.Filter.FilteredSongs)
|
|
||||||
{
|
|
||||||
object value = field.GetValue(song);
|
|
||||||
if (isString)
|
|
||||||
sortList.Add(new CSongPointer(song.ID, (String)value));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var values = (List<String>)value;
|
|
||||||
if (values.Count == 0)
|
|
||||||
sortList.Add(new CSongPointer(song.ID, ""));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// ReSharper disable LoopCanBeConvertedToQuery
|
|
||||||
foreach (String sortString in values)
|
|
||||||
// ReSharper restore LoopCanBeConvertedToQuery
|
|
||||||
sortList.Add(new CSongPointer(song.ID, sortString));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return sortList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _SortSongs()
|
private void _SortSongs()
|
||||||
{
|
{
|
||||||
if (!_Changed)
|
if (!_Changed)
|
||||||
return;
|
return;
|
||||||
String fieldName;
|
|
||||||
switch (_SongSorting)
|
List<CSongPointer> sortList = new List<CSongPointer>();
|
||||||
{
|
foreach (CSong song in CSongs.Filter.FilteredSongs)
|
||||||
case ESongSorting.TR_CONFIG_EDITION:
|
_AddSongToList(song, sortList);
|
||||||
fieldName = "Editions";
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_GENRE:
|
|
||||||
fieldName = "Genres";
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_FOLDER:
|
|
||||||
fieldName = "FolderName";
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_ARTIST_LETTER:
|
|
||||||
case ESongSorting.TR_CONFIG_ARTIST:
|
|
||||||
fieldName = _IgnoreArticles == EOffOn.TR_CONFIG_ON ? "ArtistSorting" : "Artist";
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_TITLE_LETTER:
|
|
||||||
fieldName = _IgnoreArticles == EOffOn.TR_CONFIG_ON ? "TitleSorting" : "Title";
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_YEAR:
|
|
||||||
case ESongSorting.TR_CONFIG_DECADE:
|
|
||||||
fieldName = "Year";
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_LANGUAGE:
|
|
||||||
fieldName = "Languages";
|
|
||||||
break;
|
|
||||||
case ESongSorting.TR_CONFIG_DATEADDED:
|
|
||||||
fieldName = "DateAdded";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fieldName = "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
List<CSongPointer> sortList = _CreateSortList(fieldName);
|
|
||||||
switch (_SongSorting)
|
switch (_SongSorting)
|
||||||
{
|
{
|
||||||
case ESongSorting.TR_CONFIG_ARTIST_LETTER:
|
case ESongSorting.TR_CONFIG_ARTIST_LETTER:
|
||||||
|
|||||||
@@ -189,7 +189,6 @@ namespace VocaluxeLib
|
|||||||
{
|
{
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
TR_CONFIG_NONE,
|
TR_CONFIG_NONE,
|
||||||
//TR_CONFIG_RANDOM,
|
|
||||||
TR_CONFIG_FOLDER,
|
TR_CONFIG_FOLDER,
|
||||||
TR_CONFIG_ARTIST,
|
TR_CONFIG_ARTIST,
|
||||||
TR_CONFIG_ARTIST_LETTER,
|
TR_CONFIG_ARTIST_LETTER,
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ namespace VocaluxeLib
|
|||||||
public interface IDataBase
|
public interface IDataBase
|
||||||
{
|
{
|
||||||
bool GetCover(string fileName, ref CTexture texture, int coverSize);
|
bool GetCover(string fileName, ref CTexture texture, int coverSize);
|
||||||
bool GetDataBaseSongInfos(string artist, string title, out int numPlayed, out string dateAdded, out int highscoreID);
|
bool GetDataBaseSongInfos(string artist, string title, out int numPlayed, out DateTime dateAdded, out int highscoreID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IControllers
|
public interface IControllers
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ namespace VocaluxeLib.Songs
|
|||||||
public readonly List<string> Languages = new List<string>();
|
public readonly List<string> Languages = new List<string>();
|
||||||
|
|
||||||
public int DataBaseSongID = -1;
|
public int DataBaseSongID = -1;
|
||||||
public string DateAdded = "";
|
public DateTime DateAdded = DateTime.Today;
|
||||||
public int NumPlayed;
|
public int NumPlayed;
|
||||||
public int NumPlayedSession;
|
public int NumPlayedSession;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user