Commit da02d118 authored by Scott Wheeler's avatar Scott Wheeler

Fixed sorting in the FileList by reimplementing QListViewItem::compare()

in FileListItem.

svn path=/trunk/kdemultimedia/juk/; revision=141977
parent 6590093b
......@@ -19,6 +19,10 @@
#include "filelistitem.h"
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
FileListItem::FileListItem(QFileInfo *file, KListView *parent) : KListViewItem(parent)
{
header = 0;
......@@ -63,3 +67,52 @@ MPEGHeader *FileListItem::getHeader()
}
return(header);
}
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
int FileListItem::compare(QListViewItem *item, int column, bool ascending) const
{
// reimplemented from QListViewItem
FileListItem *fileListItem = dynamic_cast<FileListItem *>(item);
FileListItem *thisFileListItem = const_cast<FileListItem *>(this);
// The following statments first check to see if you can sort based on the
// specified column. If the values for the two FileListItems are the same
// in that column it then trys to sort based on columns 1, 2, 3 and 0,
// (artist, album, track number, track name) in that order.
if(fileListItem && thisFileListItem) {
if(compare(thisFileListItem, fileListItem, column, ascending) != 0) {
return(compare(thisFileListItem, fileListItem, column, ascending));
}
else {
for(int i = 1; i <= 3; i++) {
if(compare(thisFileListItem, fileListItem, i, ascending) != 0)
return(compare(thisFileListItem, fileListItem, i, ascending));
}
if(compare(thisFileListItem, fileListItem, 0, ascending) != 0)
return(compare(thisFileListItem, fileListItem, 0, ascending));
return(0);
}
}
else
return(0); // cast failed, something is wrong
}
int FileListItem::compare(FileListItem *firstItem, FileListItem *secondItem, int column, bool ascending) const
{
if(column == 3) {
if(firstItem->getTag()->getTrackNumber() > secondItem->getTag()->getTrackNumber())
return(1);
else if(firstItem->getTag()->getTrackNumber() < secondItem->getTag()->getTrackNumber())
return(-1);
else
return(0);
}
else {
return(firstItem->key(column, ascending).compare(secondItem->key(column, ascending)));
}
}
......@@ -33,7 +33,11 @@ public:
Tag *getTag();
MPEGHeader *getHeader();
protected:
private:
virtual int compare(QListViewItem *item, int column, bool ascending) const;
int compare(FileListItem *firstItem, FileListItem *secondItem, int column, bool ascending) const;
QFileInfo *fileInfo;
Tag *tag;
MPEGHeader *header;
......
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