Commit efd23e7e authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Display a warning when an unsupported SortingCriteria is used

parent 7948e089
......@@ -207,6 +207,9 @@ std::string Album::orderTracksBy( const QueryParameters* params = nullptr )
req += "med.release_date";
break;
default:
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Default" );
/* fall-through */
case SortingCriteria::Default:
if ( desc == true )
req += "att.disc_number DESC, att.track_number DESC, med.filename";
else
......@@ -243,6 +246,10 @@ std::string Album::orderBy( const QueryParameters* params )
req += " DESC";
break;
default:
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Default (Alpha)" );
/* fall-through */
case SortingCriteria::Default:
case SortingCriteria::Alpha:
req += "title";
if ( desc == true )
req += " DESC";
......@@ -366,6 +373,9 @@ Query<IArtist> Album::artists( const QueryParameters* params ) const
"INNER JOIN AlbumArtistRelation aar ON aar.artist_id = art.id_artist "
"WHERE aar.album_id = ?";
std::string orderBy = "ORDER BY art.name";
if ( params != nullptr && ( params->sort != SortingCriteria::Alpha &&
params->sort != SortingCriteria::Default ) )
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Alpha" );
if ( params != nullptr && params->desc == true )
orderBy += " DESC";
return make_query<Artist, IArtist>( m_ml, "art.*", std::move( req ),
......@@ -546,7 +556,12 @@ Query<IAlbum> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, const Que
if ( desc == true )
groupAndOrder += " DESC";
break;
default:
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Default (ReleaseDate)" );
/* fall-through */
case SortingCriteria::Default:
case SortingCriteria::ReleaseDate:
// When listing albums of an artist, default order is by descending year (with album title
// discrimination in case 2+ albums went out the same year)
// This leads to DESC being used for "non-desc" case
......
......@@ -177,6 +177,9 @@ Query<IMedia> AlbumTrack::fromGenre( MediaLibraryPtr ml, int64_t genreId, const
orderBy += "m.title";
break;
default:
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Default" );
/* fall-through */
case SortingCriteria::Default:
if ( desc == true )
orderBy += "t.artist_id DESC, t.album_id DESC, t.disc_number DESC, t.track_number DESC, m.filename";
else
......
......@@ -146,6 +146,10 @@ Query<IMedia> Artist::tracks( const QueryParameters* params ) const
orderBy += "alb.title, atr.disc_number, atr.track_number";
break;
default:
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Default (Alpha)" );
/* fall-through */
case SortingCriteria::Default:
case SortingCriteria::Alpha:
orderBy += "med.title";
break;
}
......@@ -454,8 +458,13 @@ Query<IArtist> Artist::searchByGenre( MediaLibraryPtr ml, const std::string& pat
std::string groupBy = "GROUP BY att.artist_id "
"ORDER BY a.name";
if ( params != nullptr && params->desc == true )
groupBy += " DESC";
if ( params != nullptr )
{
if ( params->sort != SortingCriteria::Default && params->sort != SortingCriteria::Alpha )
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Alpha" );
if ( params->desc == true )
groupBy += " DESC";
}
return make_query<Artist, IArtist>( ml, "a.*", std::move( req ),
std::move( groupBy ), pattern, genreId );
}
......@@ -463,8 +472,13 @@ Query<IArtist> Artist::searchByGenre( MediaLibraryPtr ml, const std::string& pat
std::string Artist::sortRequest( const QueryParameters* params )
{
std::string req = " ORDER BY name";
if ( params != nullptr && params->desc == true )
req += " DESC";
if ( params != nullptr )
{
if ( params->sort != SortingCriteria::Default && params->sort != SortingCriteria::Alpha )
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Alpha" );
if ( params->desc == true )
req += " DESC";
}
return req;
}
......
......@@ -81,8 +81,13 @@ Query<IArtist> Genre::artists( const QueryParameters* params ) const
"INNER JOIN " + AlbumTrack::Table::Name + " att ON att.artist_id = a.id_artist "
"WHERE att.genre_id = ?";
std::string groupAndOrderBy = "GROUP BY att.artist_id ORDER BY a.name";
if ( params != nullptr && params->desc == true )
groupAndOrderBy += " DESC";
if ( params != nullptr )
{
if ( params->sort != SortingCriteria::Default && params->sort != SortingCriteria::Alpha )
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Alpha" );
if ( params->desc == true )
groupAndOrderBy += " DESC";
}
return make_query<Artist, IArtist>( m_ml, "a.*", std::move( req ),
std::move( groupAndOrderBy ), m_id );
}
......@@ -186,8 +191,13 @@ Query<IGenre> Genre::search( MediaLibraryPtr ml, const std::string& name,
"(SELECT rowid FROM " + Genre::Table::Name + "Fts "
"WHERE name MATCH '*' || ? || '*')";
std::string orderBy = "ORDER BY name";
if ( params != nullptr && params->desc == true )
orderBy += " DESC";
if ( params != nullptr )
{
if ( params->sort != SortingCriteria::Default && params->sort != SortingCriteria::Alpha )
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Alpha" );
if ( params->desc == true )
orderBy += " DESC";
}
return make_query<Genre, IGenre>( ml, "*", std::move( req ),
std::move( orderBy ), name );
}
......@@ -196,8 +206,13 @@ Query<IGenre> Genre::listAll( MediaLibraryPtr ml, const QueryParameters* params
{
std::string req = "FROM " + Genre::Table::Name;
std::string orderBy = " ORDER BY name";
if ( params != nullptr && params->desc == true )
orderBy += " DESC";
if ( params != nullptr )
{
if ( params->sort != SortingCriteria::Default && params->sort != SortingCriteria::Alpha )
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Alpha" );
if ( params->desc == true )
orderBy += " DESC";
}
return make_query<Genre, IGenre>( ml, "*", std::move( req ),
std::move( orderBy ) );
}
......
......@@ -498,6 +498,10 @@ std::string Media::sortRequest( const QueryParameters* params, bool hasAlbTrackT
req += "tra.album_id, tra.track_number";
break;
default:
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Default (Alpha)" );
/* fall-through */
case SortingCriteria::Default:
case SortingCriteria::Alpha:
req += "m.title";
break;
}
......
......@@ -350,6 +350,10 @@ std::string Playlist::sortRequest( const QueryParameters* params )
req += "creation_date";
break;
default:
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Default (Alpha)" );
/* fall-through */
case SortingCriteria::Default:
case SortingCriteria::Alpha:
req += "name";
break;
}
......
......@@ -153,6 +153,9 @@ Query<IMedia> Show::episodes( const QueryParameters* params ) const
orderBy += " DESC";
break;
default:
LOG_WARN( "Unsupported sorting criteria, falling back to SortingCriteria::Default" );
/* fall-through */
case SortingCriteria::Default:
if ( desc == true )
orderBy += "ep.season_number DESC, ep.episode_number DESC";
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment