Permalink
Browse files

sortalbumbyyear

sort by date working

release
  • Loading branch information...
fuchsmich committed Nov 21, 2017
1 parent c794da7 commit 9c5bb14afec9a8812a098c24d7e2e743fecf2816
@@ -115,6 +115,18 @@ Page {
}
}
}
TextSwitch{
id: sortAlbumsByYearSwitch
text: qsTr("sort albums of one artist by year")
checked: sortAlbumsByYear
onClicked: {
if ( checked ) {
newSettingKey(["sortAlbumsByYear","1"]);
} else {
newSettingKey(["sortAlbumsByYear","0"]);
}
}
}
TextSwitch{
id: albumArtistSwitch
text: qsTr("use albumartist in artists view")
@@ -125,7 +137,6 @@ Page {
} else {
newSettingKey(["artistsViewUseAlbumArtist","0"]);
}
// mCurrentSongPage = null;
}
}
TextSwitch{
View
@@ -1,7 +1,7 @@
Name: harbour-smpc
Summary: SailfishOS Port of qmobilempd client
URL: https://github.com/djselbeck/smpc
Version: 1.3.3.1
Version: 1.3.3.2
Release: 1
Group: Qt/Qt
License: GPLv3
View
@@ -511,6 +511,7 @@ void Controller::readSettings()
mSectionsInSearch = settings.value("sections_in_search",1).toInt();
mSectionsInPlaylist = settings.value("sections_in_playlist",1).toInt();
mDownloadEnabled = settings.value("lastfm_download",1).toInt();
mNetAccess->setSortAlbumsByYear(settings.value("sort_album_by_year",0).toInt());
mNetAccess->setUseAlbumArtist(settings.value("artist_view_albumartist",0).toInt());
mCoverInNowPlaying = settings.value("show_covernowplaying",1).toInt();
mShowModeLandscape = settings.value("useShowView",1).toInt();
@@ -524,6 +525,7 @@ void Controller::readSettings()
mQuickView->rootContext()->setContextProperty("sectionsInPlaylist", mSectionsInPlaylist);
mQuickView->rootContext()->setContextProperty("lastfmEnabled", mDownloadEnabled);
mQuickView->rootContext()->setContextProperty("artistsViewUseAlbumArtist", mNetAccess->useAlbumArtist());
mQuickView->rootContext()->setContextProperty("sortAlbumsByYear", mNetAccess->sortAlbumsByYear());
mQuickView->rootContext()->setContextProperty("showCoverNowPlaying", mCoverInNowPlaying);
mQuickView->rootContext()->setContextProperty("useShowView", mShowModeLandscape);
@@ -567,6 +569,7 @@ void Controller::writeSettings()
settings.setValue("sections_in_search",mSectionsInSearch);
settings.setValue("sections_in_playlist",mSectionsInPlaylist);
settings.setValue("lastfm_download",mDownloadEnabled);
settings.setValue("sort_album_by_year",mNetAccess->sortAlbumsByYear());
settings.setValue("artist_view_albumartist",mNetAccess->useAlbumArtist());
settings.setValue("show_covernowplaying",mCoverInNowPlaying);
settings.setValue("useShowView",mShowModeLandscape);
@@ -873,6 +876,9 @@ void Controller::receiveSettingKey(QVariant setting)
mDownloadEnabled = settings.at(1).toInt();
mQuickView->rootContext()->setContextProperty("lastfmEnabled", mDownloadEnabled);
emit newDownloadEnabled(mDownloadEnabled);
} else if ( settings.at(0) == "sortAlbumsByYear" ) {
mNetAccess->setSortAlbumsByYear(settings.at(1).toInt());
mQuickView->rootContext()->setContextProperty("sortAlbumsByYear", mNetAccess->sortAlbumsByYear());
} else if ( settings.at(0) == "artistsViewUseAlbumArtist" ) {
mNetAccess->setUseAlbumArtist(settings.at(1).toInt());
mQuickView->rootContext()->setContextProperty("artistsViewUseAlbumArtist", mNetAccess->useAlbumArtist());
View
@@ -5,11 +5,12 @@ MpdAlbum::MpdAlbum(QObject *parent) :
{
}
MpdAlbum::MpdAlbum(QObject *parent, QString title, QString artist, QString mbid) : QObject(parent)
MpdAlbum::MpdAlbum(QObject *parent, QString title, QString artist, QString mbid, QString date) : QObject(parent)
{
mTitle = title;
mArtist = artist;
mMBID = mbid;
mDate = date;
}
MpdAlbum::MpdAlbum(const MpdAlbum &copyObject,QObject *parent) : QObject(parent) {
@@ -29,6 +30,11 @@ QString MpdAlbum::getMBID() const {
return mMBID;
}
QString MpdAlbum::getDate() const
{
return mDate;
}
void MpdAlbum::operator =(MpdAlbum &rhs)
{
mTitle = rhs.mTitle;
@@ -50,6 +56,10 @@ bool MpdAlbum::lessThan(const MpdAlbum *lhs, const MpdAlbum* rhs)
return *lhs<*rhs;
}
bool MpdAlbum::lessThanDate(const MpdAlbum *lhs, const MpdAlbum *rhs)
{
return (lhs->mDate.compare(rhs->mDate,Qt::CaseInsensitive)<0 ? 1 : 0);
}
// Return first letter as section
QString MpdAlbum::getSection() const
View
@@ -10,27 +10,31 @@ class MpdAlbum : public QObject
Q_PROPERTY(QString sectionprop READ getSection NOTIFY changed )
Q_PROPERTY(QString mbid READ getMBID NOTIFY changed )
Q_PROPERTY(QString artist READ getArtist NOTIFY changed )
Q_PROPERTY(QString date READ getDate NOTIFY changed )
public:
explicit MpdAlbum(QObject *parent = 0);
MpdAlbum(QObject *parent,QString mTitle,QString artist="", QString mbid="");
MpdAlbum(QObject *parent,QString mTitle,QString artist="", QString mbid="", QString date="");
MpdAlbum(const MpdAlbum &copyObject, QObject *parent = 0);
QString getTitle() const;
QString getSection() const;
QString getArtist() const;
QString getMBID() const;
QString getDate() const;
bool operator< (const MpdAlbum& rhs) const;
bool operator==(MpdAlbum & rhs) const ;
void operator=(MpdAlbum &rhs);
static bool lessThan(const MpdAlbum *lhs, const MpdAlbum* rhs);
static bool lessThanDate(const MpdAlbum *lhs, const MpdAlbum *rhs);
private:
QString mTitle;
QString mArtist;
QString mMBID;
QString mDate;
signals:
// Dummy signal, so qml shuts up
View
@@ -294,13 +294,13 @@ QList<MpdAlbum*> *NetworkAccess::getArtistsAlbums_prv(QString artist)
//Send request
artist = artist.replace('\"',"\\\"");
if ( mServerInfo->getListFilterSupported() && mServerInfo->getListGroupSupported() ) {
QString artistString;
QString tag;
if (mUseAlbumArtist) {
artistString = "albumartist";
tag = "albumartist";
} else {
artistString = "artist";
tag = "artist";
}
sendMPDCommand(QString("list album ") + artistString + (" \"") + artist + "\"" + " group MUSICBRAINZ_ALBUMID\n");
sendMPDCommand(QString("list album ") + tag + (" \"") + artist + "\"" + " group MUSICBRAINZ_ALBUMID group date\n");
} else {
sendMPDCommand(QString("list album \"") + artist + "\"\n");
}
@@ -310,6 +310,7 @@ QList<MpdAlbum*> *NetworkAccess::getArtistsAlbums_prv(QString artist)
MpdAlbum *tempalbum;
QString name;
QString mbid;
QString date;
bool emptyAlbum = false;
MPD_WHILE_PARSE_LOOP
@@ -320,11 +321,12 @@ QList<MpdAlbum*> *NetworkAccess::getArtistsAlbums_prv(QString artist)
response = QString::fromUtf8(mTCPSocket->readLine());
/* Remove newline at the end */
response.chop(1);
qDebug() << response;
if ( response.startsWith("Album: ") ) {
// Append album if name is already set(last album)
if ( name != "" || emptyAlbum ) {
tempalbum = new MpdAlbum(NULL,name,artist,mbid);
qDebug() << "Album: " << name;
tempalbum = new MpdAlbum(NULL,name,artist,mbid,date);
qDebug() << "Album: " << name << artist << date;
tempalbum->moveToThread(mQMLThread);
QQmlEngine::setObjectOwnership(tempalbum, QQmlEngine::CppOwnership);
albums->append(tempalbum);
@@ -336,13 +338,15 @@ QList<MpdAlbum*> *NetworkAccess::getArtistsAlbums_prv(QString artist)
}
} else if ( response.startsWith("MUSICBRAINZ_ALBUMID:") ) {
mbid = response.right(response.length() - 21);
} else if ( response.startsWith("Date:") ) {
date = response.right(response.length() - 6);
}
}
}
/* Append last album also */
if ( name != "" || emptyAlbum) {
qDebug() << "Album: " << name;
tempalbum = new MpdAlbum(NULL,name,artist,mbid);
tempalbum = new MpdAlbum(NULL,name,artist,mbid,date);
tempalbum->moveToThread(mQMLThread);
QQmlEngine::setObjectOwnership(tempalbum, QQmlEngine::CppOwnership);
albums->append(tempalbum);
@@ -351,7 +355,8 @@ QList<MpdAlbum*> *NetworkAccess::getArtistsAlbums_prv(QString artist)
}
//Get album tracks
qSort(albums->begin(),albums->end(),MpdAlbum::lessThan);
if (mSortAlbumsByYear) qSort(albums->begin(),albums->end(),MpdAlbum::lessThanDate);
else qSort(albums->begin(),albums->end(),MpdAlbum::lessThan);
return albums;
}
@@ -1910,6 +1915,16 @@ MPDPlaybackStatus *NetworkAccess::getMPDPlaybackStatus() {
return mPlaybackStatus;
}
void NetworkAccess::setSortAlbumsByYear(int state)
{
mSortAlbumsByYear = (state == 1);
}
int NetworkAccess::sortAlbumsByYear()
{
return mSortAlbumsByYear*1;
}
void NetworkAccess::setUseAlbumArtist(int state)
{
mUseAlbumArtist = (state == 1);
View
@@ -82,6 +82,9 @@ class NetworkAccess : public QThread
*/
MPDPlaybackStatus *getMPDPlaybackStatus();
void setSortAlbumsByYear(int state);
int sortAlbumsByYear();
void setUseAlbumArtist(int state);
int useAlbumArtist();
@@ -701,6 +704,7 @@ protected slots:
*/
bool authenticate(QString passwort);
bool mSortAlbumsByYear;
bool mUseAlbumArtist;
};

0 comments on commit 9c5bb14

Please sign in to comment.