Commit 9088efbd authored by Scott Wheeler's avatar Scott Wheeler

Only show the "short" file name (i.e. not the path) in the column by default

but include the full path in the tooltip and by default sort by the full path.

However this does KMail-style "click twice on the header to change the sort
mode" and toggles between sorting on the full path and the file name.

CCMAIL:79118-done@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=303244
parent 9a1db0b8
......@@ -191,7 +191,9 @@ void CollectionListItem::refresh()
{
// All columns other than track num and length need local-encoded data for sorting
QCString lower = text(i).lower().local8Bit();
QCString lower = id == FileNameColumn
? file().absFilePath().lower().local8Bit()
: text(i).lower().local8Bit();
// For some columns, we may be able to share some strings
......@@ -202,6 +204,7 @@ void CollectionListItem::refresh()
lower = StringShare::tryShare(lower);
}
data()->local8Bit[id] = lower;
data()->shortFileName = file().fileInfo().fileName().lower().local8Bit();
}
int newWidth = width(listView()->fontMetrics(), listView(), i);
......
......@@ -29,6 +29,7 @@
#include <qcursor.h>
#include <qdir.h>
#include <qeventloop.h>
#include <qtooltip.h>
#include <id3v1genres.h>
......@@ -44,6 +45,45 @@
#include "actioncollection.h"
#include "tag.h"
/**
* A tooltip specialized to show full filenames over the file name column.
*/
class PlaylistToolTip : public QToolTip
{
public:
PlaylistToolTip(QWidget *parent, Playlist *playlist) :
QToolTip(parent), m_playlist(playlist) {}
virtual void maybeTip(const QPoint &p)
{
PlaylistItem *item = static_cast<PlaylistItem *>(m_playlist->itemAt(p));
if(!item)
return;
QPoint contentsPosition = m_playlist->viewportToContents(p);
int column = m_playlist->header()->sectionAt(contentsPosition.x());
if(column == m_playlist->columnOffset() + PlaylistItem::FileNameColumn ||
item->cachedWidths()[column] > m_playlist->columnWidth(column))
{
QRect r = m_playlist->itemRect(item);
int headerPosition = m_playlist->header()->sectionPos(column);
r.setLeft(headerPosition);
r.setRight(headerPosition + m_playlist->header()->sectionSize(column));
if(column == m_playlist->columnOffset() + PlaylistItem::FileNameColumn)
tip(r, item->file().absFilePath());
else
tip(r, item->text(column));
}
}
private:
Playlist *m_playlist;
};
////////////////////////////////////////////////////////////////////////////////
// Playlist::SharedSettings definition
////////////////////////////////////////////////////////////////////////////////
......@@ -232,6 +272,7 @@ Playlist::Playlist(QWidget *parent, const QString &name) :
m_allowDuplicates(false),
m_polished(false),
m_applySharedSettings(true),
m_fileColumnFullPathSort(true),
m_disableColumnWidthUpdates(true),
m_widthsDirty(true),
m_lastSelected(0),
......@@ -247,6 +288,7 @@ Playlist::Playlist(const QFileInfo &playlistFile, QWidget *parent, const QString
m_allowDuplicates(false),
m_polished(false),
m_applySharedSettings(true),
m_fileColumnFullPathSort(true),
m_disableColumnWidthUpdates(true),
m_widthsDirty(true),
m_lastSelected(0),
......@@ -749,6 +791,22 @@ void Playlist::applySharedSettings()
m_applySharedSettings = true;
}
void Playlist::setSorting(int column, bool ascending = true)
{
if(column == columnOffset() + PlaylistItem::FileNameColumn) {
if(sortColumn() == column && ascending)
m_fileColumnFullPathSort = !m_fileColumnFullPathSort;
setColumnText(column, m_fileColumnFullPathSort
? i18n("File Name (Full Path)")
: i18n("File Name"));
}
else if(sortColumn() == columnOffset() + PlaylistItem::FileNameColumn)
setColumnText(sortColumn(), i18n("File Name"));
KListView::setSorting(column, ascending);
}
void Playlist::viewportPaintEvent(QPaintEvent *pe)
{
// If there are columns that need to be updated, well, update them.
......@@ -923,6 +981,9 @@ void Playlist::polish()
setDropVisualizer(true);
m_disableColumnWidthUpdates = false;
setShowToolTips(false);
new PlaylistToolTip(viewport(), this);
}
void Playlist::setupItem(PlaylistItem *item)
......@@ -1046,7 +1107,7 @@ void Playlist::calculateColumnWeights()
for(PlaylistItemList::ConstIterator it = l.begin(); it != l.end(); ++it) {
cachedWidth = (*it)->cachedWidths();
for(columnIt = m_weightDirty.begin(); columnIt != m_weightDirty.end(); ++columnIt)
averageWidth[*columnIt] += pow(double(cachedWidth[*columnIt]) , 2.0) / itemCount;
averageWidth[*columnIt] += pow(double(cachedWidth[*columnIt]), 2.0) / itemCount;
}
m_columnWeights.resize(columns(), -1);
......
......@@ -295,6 +295,18 @@ public:
void emitDataChanged() { emit signalDataChanged(); }
/**
* Returns true if full path sort is currently enabled for the file column.
*/
bool fileColumnFullPathSort() const { return m_fileColumnFullPathSort; }
/**
* Reimplemented to add toggling of the file column sorting mode.
*
* \see fileColumnFullPathSort()
*/
virtual void setSorting(int column, bool ascending = true);
public slots:
/**
* Remove the currently selected items from the playlist and disk.
......@@ -589,6 +601,7 @@ private:
bool m_allowDuplicates;
bool m_polished;
bool m_applySharedSettings;
bool m_fileColumnFullPathSort;
QValueList<int> m_weightDirty;
bool m_disableColumnWidthUpdates;
......
......@@ -82,7 +82,7 @@ QString PlaylistItem::text(int column) const
case CommentColumn:
return d->fileHandle.tag()->comment();
case FileNameColumn:
return d->fileHandle.absFilePath();
return d->fileHandle.fileInfo().fileName();
default:
return KListViewItem::text(column);
}
......@@ -286,6 +286,14 @@ int PlaylistItem::compare(const PlaylistItem *firstItem, const PlaylistItem *sec
else
return 0;
break;
case FileNameColumn:
if(playlist()->fileColumnFullPathSort())
return strcoll(firstItem->d->local8Bit[column - offset],
secondItem->d->local8Bit[column - offset]);
else
return strcoll(firstItem->d->shortFileName,
secondItem->d->shortFileName);
break;
default:
return strcoll(firstItem->d->local8Bit[column - offset],
secondItem->d->local8Bit[column - offset]);
......
......@@ -138,6 +138,7 @@ protected:
FileHandle fileHandle;
QValueVector<QCString> local8Bit;
QValueVector<int> cachedWidths;
QCString shortFileName;
};
KSharedPtr<Data> data() const { return d; }
......
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