Commit ff8bbf69 authored by Michael Pyne's avatar Michael Pyne
Browse files

Do not auto-save playlists, instead save only after the playlist data has changed. A 3-second

window is used to avoid repeatedly trying to save during rapid changes.  Cover manager was
already fixed a couple of weeks ago.

I believe this should help for bug 165899 (JuK causes high amount of wakeups)
although the timer was set to fire infrequently so there's probably more going
on.

CCBUG:165899

svn path=/trunk/KDE/kdemultimedia/juk/; revision=853008
parent 40c114dd
......@@ -163,8 +163,11 @@ PlaylistBox::PlaylistBox(QWidget *parent, Q3WidgetStack *playlistStack) :
QTimer::singleShot(0, object(), SLOT(slotScanFolders()));
enableDirWatch(true);
// Auto-save playlists after 10 minutes
QTimer::singleShot(600000, this, SLOT(slotSavePlaylists()));
// Auto-save playlists after they change.
m_savePlaylistTimer = new QTimer(this);
m_savePlaylistTimer->setInterval(3000); // 3 seconds with no change? -> commit
m_savePlaylistTimer->setSingleShot(true);
connect(m_savePlaylistTimer, SIGNAL(timeout()), SLOT(slotSavePlaylists()));
m_showTimer = new QTimer(this);
connect(m_showTimer, SIGNAL(timeout()), SLOT(slotShowDropTarget()));
......@@ -243,6 +246,11 @@ void PlaylistBox::slotUnfreezePlaylists()
setDynamicListsFrozen(false);
}
void PlaylistBox::slotPlaylistDataChanged()
{
m_savePlaylistTimer->start(); // Restarts the timer if it's already running.
}
void PlaylistBox::setupPlaylist(Playlist *playlist, const QString &iconName)
{
setupPlaylist(playlist, iconName, 0);
......@@ -386,7 +394,7 @@ void PlaylistBox::setDynamicListsFrozen(bool frozen)
void PlaylistBox::slotSavePlaylists()
{
kDebug(65432) << "Auto-saving playlists and covers.\n";
kDebug(65432) << "Auto-saving playlists.\n";
PlaylistList l;
CollectionList *collection = CollectionList::instance();
......@@ -397,8 +405,6 @@ void PlaylistBox::slotSavePlaylists()
}
Cache::savePlaylists(l);
QTimer::singleShot(600000, this, SLOT(slotSavePlaylists()));
}
void PlaylistBox::slotShowDropTarget()
......@@ -717,6 +723,7 @@ PlaylistBox::Item *PlaylistBox::Item::m_collectionItem = 0;
PlaylistBox::Item::Item(PlaylistBox *listBox, const QString &icon, const QString &text, Playlist *l)
: QObject(listBox), K3ListViewItem(listBox, 0, text),
PlaylistObserver(l),
m_playlist(l), m_text(text), m_iconName(icon), m_sortedFirst(false)
{
init();
......@@ -724,6 +731,7 @@ PlaylistBox::Item::Item(PlaylistBox *listBox, const QString &icon, const QString
PlaylistBox::Item::Item(Item *parent, const QString &icon, const QString &text, Playlist *l)
: QObject(parent->listView()), K3ListViewItem(parent, text),
PlaylistObserver(l),
m_playlist(l), m_text(text), m_iconName(icon), m_sortedFirst(false)
{
init();
......@@ -785,6 +793,15 @@ void PlaylistBox::Item::slotSetName(const QString &name)
}
}
void PlaylistBox::Item::updateCurrent()
{
}
void PlaylistBox::Item::updateData()
{
listView()->slotPlaylistDataChanged();
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox::Item private methods
////////////////////////////////////////////////////////////////////////////////
......
......@@ -71,6 +71,7 @@ public slots:
void slotFreezePlaylists();
void slotUnfreezePlaylists();
void slotPlaylistDataChanged();
protected:
virtual void setupPlaylist(Playlist *playlist, const QString &iconName);
......@@ -133,9 +134,10 @@ private:
bool m_doingMultiSelect;
Item *m_dropItem;
QTimer *m_showTimer;
QTimer *m_savePlaylistTimer;
};
class PlaylistBox::Item : public QObject, public K3ListViewItem
class PlaylistBox::Item : public QObject, public K3ListViewItem, public PlaylistObserver
{
friend class PlaylistBox;
friend class ViewMode;
......@@ -173,6 +175,15 @@ protected:
static Item *collectionItem() { return m_collectionItem; }
static void setCollectionItem(Item *item) { m_collectionItem = item; }
//
// Reimplemented from PlaylistObserver
//
virtual void updateCurrent();
// Used to post a timer in PlaylistBox to save playlists.
virtual void updateData();
protected slots:
void slotSetName(const QString &name);
......
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