Commit 6592034c authored by Kacper Kasper's avatar Kacper Kasper

Fix sorting and build.

parent 381082b0
......@@ -172,9 +172,8 @@ void Cache::loadPlaylists(PlaylistCollection *collection) // static
if(version >= 2) {
qint32 sortColumn;
s >> sortColumn;
// FIXME
if(playlist)
playlist->model()->sort(sortColumn);
playlist->sortByColumn(sortColumn);
}
} // while !s.atEnd()
......@@ -271,8 +270,7 @@ void Cache::savePlaylists(const PlaylistList &playlists)
s << qint32(Normal)
<< *(*it);
}
// FIXME
//s << qint32((*it)->sortColumn());
s << qint32((*it)->sortColumn());
s << 0;
}
}
......
......@@ -38,6 +38,7 @@
#include <QTime>
#include <QClipboard>
#include <QFileInfo>
#include <QHeaderView>
#include "playlistcollection.h"
#include "splashscreen.h"
......@@ -121,11 +122,7 @@ void CollectionList::completedLoadingCachedItems()
if(config.readEntry("CollectionListSortAscending", true))
order = Qt::AscendingOrder;
// FIXME
//m_list->setSortOrder(order);
//m_list->setSortColumn(config.readEntry("CollectionListSortColumn", 1));
//m_list->sort();
m_list->sortByColumn(config.readEntry("CollectionListSortColumn", 1), order);
SplashScreen::finishedLoading();
......@@ -346,8 +343,7 @@ CollectionList::CollectionList(PlaylistCollection *collection) :
this, SLOT(slotPopulateBackMenu()));
connect(action<KToolBarPopupAction>("back")->menu(), SIGNAL(triggered(QAction*)),
this, SLOT(slotPlayFromBackMenu(QAction*)));
//FIXME
//setSorting(-1); // Temporarily disable sorting to add items faster.
setSortingEnabled(false); // Temporarily disable sorting to add items faster.
m_columnTags[PlaylistItem::ArtistColumn] = new TagCountDict;
m_columnTags[PlaylistItem::AlbumColumn] = new TagCountDict;
......@@ -360,9 +356,8 @@ CollectionList::CollectionList(PlaylistCollection *collection) :
CollectionList::~CollectionList()
{
KConfigGroup config(KGlobal::config(), "Playlists");
//FIXME
//config.writeEntry("CollectionListSortColumn", sortColumn());
//config.writeEntry("CollectionListSortAscending", sortOrder() == Qt::AscendingOrder);
config.writeEntry("CollectionListSortColumn", header()->sortIndicatorSection());
config.writeEntry("CollectionListSortAscending", header()->sortIndicatorOrder() == Qt::AscendingOrder);
// In some situations the dataChanged signal from clearItems will cause observers to
// subsequently try to access a deleted item. Since we're going away just remove all
......
......@@ -57,7 +57,7 @@ DynamicPlaylist::DynamicPlaylist(const PlaylistList &playlists,
setName(name);
setAllowDuplicates(false);
sortItems(columnCount() + 1, Qt::AscendingOrder);
setSortingEnabled(false);
for(PlaylistList::ConstIterator it = playlists.constBegin(); it != playlists.constEnd(); ++it)
m_observers.append(new PlaylistDirtyObserver(this, *it));
......
......@@ -38,7 +38,7 @@ HistoryPlaylist::HistoryPlaylist(PlaylistCollection *collection) :
m_timer->setSingleShot(true);
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotCreateNewItem()));
sortItems(-1, Qt::AscendingOrder);
setSortingEnabled(false);
headerItem()->setText(0, i18n("Time"));
}
......
......@@ -244,9 +244,9 @@ void Playlist::SharedSettings::apply(Playlist *l) const
l->header()->moveSection(i++ + offset, column + offset);
for(int i = 0; i < m_columnsVisible.size(); i++) {
if(m_columnsVisible[i] && !l->isColumnVisible(i + offset))
if(m_columnsVisible[i] && l->isColumnHidden(i + offset))
l->showColumn(i + offset, false);
else if(!m_columnsVisible[i] && l->isColumnVisible(i + offset))
else if(!m_columnsVisible[i] && !l->isColumnHidden(i + offset))
l->hideColumn(i + offset, false);
}
......@@ -916,7 +916,7 @@ void Playlist::slotWeightDirty(int column)
if(column < 0) {
m_weightDirty.clear();
for(int i = 0; i < columnCount(); i++) {
if(isColumnVisible(i))
if(!isColumnHidden(i))
m_weightDirty.append(i);
}
return;
......@@ -943,7 +943,7 @@ void Playlist::slotShowPlaying()
m_collection->raise(l);
l->setCurrentItem(playingItem());
l->scrollTo(currentIndex());
l->scrollToItem(playingItem());
}
void Playlist::slotColumnResizeModeChanged()
......@@ -1260,7 +1260,7 @@ void Playlist::read(QDataStream &s)
throw BICStreamException();
// Do not sort. Add the files in the order they were saved.
sortItems(columnCount() + 1, Qt::AscendingOrder);
setSortingEnabled(false);
QStringList files;
s >> files;
......@@ -1491,6 +1491,12 @@ void Playlist::showColumn(int c, bool updateSearch)
redisplaySearch();
}
void Playlist::sortByColumn(int column, Qt::SortOrder order)
{
setSortingEnabled(true);
QTreeWidget::sortByColumn(column, order);
}
void Playlist::slotInitialize()
{
addColumn(i18n("Track Name"));
......@@ -1515,9 +1521,9 @@ void Playlist::slotInitialize()
setRenameable(PlaylistItem::YearColumn, true);*/
setAllColumnsShowFocus(true);
/*setSelectionMode(QTreeWidget::Extended);
setShowSortIndicator(true);
setDropVisualizer(true);*/
setSelectionMode(QTreeWidget::ExtendedSelection);
header()->setSortIndicatorShown(true);
//setDropVisualizer(true);
m_columnFixedWidths.resize(columnCount());
......@@ -1678,7 +1684,7 @@ void Playlist::setup()
// progress.
connect(this, SIGNAL(itemSelectionChanged()), m_fetcher, SLOT(abortSearch()));
sortItems(1, Qt::AscendingOrder);
sortByColumn(1, Qt::AscendingOrder);
// This apparently must be created very early in initialization for other
// Playlist code requiring m_headerMenu.
......@@ -1704,7 +1710,7 @@ void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
// Turn off non-explicit sorting.
sortItems(PlaylistItem::lastColumn() + columnOffset() + 1, Qt::AscendingOrder);
setSortingEnabled(false);
PlaylistItem *after = 0;
......@@ -1778,7 +1784,7 @@ bool Playlist::playing() const
int Playlist::leftMostVisibleColumn() const
{
int i = 0;
while(!isColumnVisible(header()->sectionPosition(i)) && i < PlaylistItem::lastColumn())
while(isColumnHidden(header()->sectionPosition(i)) && i < PlaylistItem::lastColumn())
i++;
return header()->sectionPosition(i);
......@@ -1944,7 +1950,7 @@ void Playlist::slotUpdateColumnWidths()
QList<int> visibleColumns;
for(int i = 0; i < columnCount(); i++) {
if(isColumnVisible(i))
if(!isColumnHidden(i))
visibleColumns.append(i);
}
......@@ -2300,21 +2306,21 @@ void Playlist::slotToggleColumnVisible(QAction *action)
{
int column = action->data().toInt();
if(!isColumnVisible(column)) {
if(isColumnHidden(column)) {
int fileNameColumn = PlaylistItem::FileNameColumn + columnOffset();
int fullPathColumn = PlaylistItem::FullPathColumn + columnOffset();
if(column == fileNameColumn && isColumnVisible(fullPathColumn)) {
if(column == fileNameColumn && !isColumnHidden(fullPathColumn)) {
hideColumn(fullPathColumn, false);
SharedSettings::instance()->toggleColumnVisible(fullPathColumn);
}
if(column == fullPathColumn && isColumnVisible(fileNameColumn)) {
if(column == fullPathColumn && !isColumnHidden(fileNameColumn)) {
hideColumn(fileNameColumn, false);
SharedSettings::instance()->toggleColumnVisible(fileNameColumn);
}
}
if(isColumnVisible(column))
if(!isColumnHidden(column))
hideColumn(column);
else
showColumn(column);
......
......@@ -221,6 +221,8 @@ public:
*/
void showColumn(int c, bool updateSearch = true);
void sortByColumn(int column, Qt::SortOrder order = Qt::AscendingOrder);
/**
* This sets a name for the playlist that is \e different from the file name.
*/
......
......@@ -850,10 +850,10 @@ void PlaylistBox::Item::slotSetName(const QString &name)
setText(0, name);
setSelected(true);
// FIXME
/*listView()->sort();
listView()->ensureItemVisible(listView()->currentItem());*/
listView()->viewMode()->queueRefresh();
treeWidget()->sortItems(0, Qt::AscendingOrder);
treeWidget()->scrollToItem(treeWidget()->currentItem());
//FIXME
//listView()->viewMode()->queueRefresh();
}
}
......
......@@ -329,10 +329,10 @@ int PlaylistItem::compare(QTreeWidgetItem *item, int column, bool ascending) con
// Loop through the columns doing comparisons until something is differnt.
// If all else is the same, compare the track name.
int last = playlist()->isColumnVisible(AlbumColumn + offset) ? TrackNumberColumn : ArtistColumn;
int last = !playlist()->isColumnHidden(AlbumColumn + offset) ? TrackNumberColumn : ArtistColumn;
for(int i = ArtistColumn; i <= last; i++) {
if(playlist()->isColumnVisible(i + offset)) {
if(!playlist()->isColumnHidden(i + offset)) {
c = compare(this, playlistItem, i, ascending);
if(c != 0)
return c;
......
......@@ -188,7 +188,7 @@ bool PlaylistSearch::Component::matches(PlaylistItem *item) const
if(m_columns.isEmpty()) {
Playlist *p = static_cast<Playlist *>(item->treeWidget());
for(int i = 0; i < p->columnCount(); i++) {
if(p->isColumnVisible(i))
if(!p->isColumnHidden(i))
m_columns.append(i);
}
}
......
......@@ -92,7 +92,7 @@ PlaylistSearch::Component SearchLine::searchComponent() const
if(!m_searchFieldsBox || m_searchFieldsBox->currentIndex() == 0) {
foreach(int column, m_columnList) {
if(playlist->isColumnVisible(column))
if(!playlist->isColumnHidden(column))
searchedColumns.append(column);
}
}
......
......@@ -36,7 +36,7 @@ UpcomingPlaylist::UpcomingPlaylist(PlaylistCollection *collection) :
{
setName(i18n("Play Queue"));
setAllowDuplicates(true);
sortItems(-1, Qt::AscendingOrder);
setSortingEnabled(false);
}
UpcomingPlaylist::~UpcomingPlaylist()
......
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