implement the refresh thingy

parent 73408133
......@@ -1078,6 +1078,30 @@ bool Playlist::removeRows(int row, int count, const QModelIndex& parent)
return true;
}
void Playlist::refreshRows(QModelIndexList &l)
{
if(l.isEmpty()) {
for (int i=0; i<rowCount(); i++) {
l.append(index(i, 0));
}
}
for (int i=l.count(); i>=0; --i) {
int row = l[i].row();
m_items[row]->refreshFromDisk();
if(!m_items[row]->file().tag() || !m_items[row]->file().fileInfo().exists()) {
kDebug() << "Error while trying to refresh the tag. "
<< "This file has probably been removed."
<< endl;
delete m_items.takeAt(row);//FIXME update all affected instances
}
processEvents();
}
}
#include "playlist.moc"
// vim: set et sw=4 tw=0 sta:
......@@ -107,6 +107,12 @@ public:
*/
bool deleteRows(int row, int count, const QModelIndex & parent = QModelIndex());
/**
* Refreshes a file from disk
* @return True on success
*/
void refreshRows(QModelIndexList& l);
// The following group of functions implement the PlaylistInterface API.
virtual QString name() const;
......
......@@ -8,6 +8,7 @@
#include <QFileInfo>
#include <QToolTip>
#include "coverinfo.h"
#include <KApplication>
using namespace ActionCollection;
......@@ -128,6 +129,14 @@ bool PlaylistView::event(QEvent *e)
return QAbstractItemView::event(e);
}
void PlaylistView::slotRefresh()
{
QModelIndexList l = selectedIndexes();
KApplication::setOverrideCursor(Qt::waitCursor);
playlist()->refreshRows(l);
KApplication::restoreOverrideCursor();
}
//### TODO: VIEW
/**
* Shared settings between the playlists.
......@@ -374,27 +383,6 @@ bool PlaylistView::event(QEvent *e)
// decode(QApplication::clipboard()->mimeData(), static_cast<PlaylistItem *>(currentItem()));
// }
//
// void Playlist::slotRefresh()
// {
// PlaylistItemList l = selectedItems();
// if(l.isEmpty())
// l = visibleItems();
//
// KApplication::setOverrideCursor(Qt::waitCursor);
// foreach(PlaylistItem *item, l) {
// item->refreshFromDisk();
//
// if(!item->file().tag() || !item->file().fileInfo().exists()) {
// kDebug() << "Error while trying to refresh the tag. "
// << "This file has probably been removed."
// << endl;
// delete item->collectionItem();
// }
//
// processEvents();
// }
// KApplication::restoreOverrideCursor();
// }
//
// void Playlist::slotRenameFile()
// {
......
......@@ -15,6 +15,9 @@ protected slots:
virtual void contextMenuEvent(QContextMenuEvent*);
virtual bool event(QEvent*);
private slots:
void slotRefresh();
private:
Playlist *playlist() { return qobject_cast<Playlist*>(model()); }
......
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