Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit a147778f authored by Scott Wheeler's avatar Scott Wheeler

A slight kludge to speed up checking the time of the playlist. Unfortunately

for the moment if the time of an indivitual item changes while the playlist is
visible the change won't be accounted for.  This however is acceptable for a
significant start up / performance boost.

svn path=/trunk/kdemultimedia/juk/; revision=381819
parent b4fb1f7d
......@@ -316,6 +316,7 @@ Playlist::Playlist(PlaylistCollection *collection, const QString &name,
m_applySharedSettings(true),
m_mousePressed(false),
m_disableColumnWidthUpdates(true),
m_time(0),
m_widthsDirty(true),
m_searchEnabled(true),
m_lastSelected(0),
......@@ -337,6 +338,7 @@ Playlist::Playlist(PlaylistCollection *collection, const PlaylistItemList &items
m_applySharedSettings(true),
m_mousePressed(false),
m_disableColumnWidthUpdates(true),
m_time(0),
m_widthsDirty(true),
m_searchEnabled(true),
m_lastSelected(0),
......@@ -359,6 +361,7 @@ Playlist::Playlist(PlaylistCollection *collection, const QFileInfo &playlistFile
m_applySharedSettings(true),
m_mousePressed(false),
m_disableColumnWidthUpdates(true),
m_time(0),
m_widthsDirty(true),
m_searchEnabled(true),
m_lastSelected(0),
......@@ -380,6 +383,7 @@ Playlist::Playlist(PlaylistCollection *collection, bool delaySetup) :
m_applySharedSettings(true),
m_mousePressed(false),
m_disableColumnWidthUpdates(true),
m_time(0),
m_widthsDirty(true),
m_searchEnabled(true),
m_lastSelected(0),
......@@ -422,14 +426,29 @@ FileHandle Playlist::currentFile() const
int Playlist::time() const
{
int time = 0;
QListViewItemIterator it(const_cast<Playlist *>(this));
while (it.current()) {
PlaylistItem *item = static_cast<PlaylistItem *>(it.current());
time += item->file().tag()->seconds();
it++;
// Since this method gets a lot of traffic, let's optimize for such.
if(!m_addTime.isEmpty()) {
for(PlaylistItemList::ConstIterator it = m_addTime.begin();
it != m_addTime.end(); ++it)
{
m_time += (*it)->file().tag()->seconds();
}
m_addTime.clear();
}
if(!m_subtractTime.isEmpty()) {
for(PlaylistItemList::ConstIterator it = m_subtractTime.begin();
it != m_subtractTime.end(); ++it)
{
m_time -= (*it)->file().tag()->seconds();
}
m_subtractTime.clear();
}
return time;
return m_time;
}
void Playlist::playFirst()
......@@ -1115,6 +1134,18 @@ void Playlist::viewportResizeEvent(QResizeEvent *re)
KListView::viewportResizeEvent(re);
}
void Playlist::insertItem(QListViewItem *item)
{
m_addTime.append(static_cast<PlaylistItem *>(item));
KListView::insertItem(item);
}
void Playlist::takeItem(QListViewItem *item)
{
m_subtractTime.append(static_cast<PlaylistItem *>(item));
KListView::takeItem(item);
}
void Playlist::addColumn(const QString &label)
{
slotWeightDirty(columns());
......
......@@ -422,6 +422,9 @@ protected:
virtual void viewportPaintEvent(QPaintEvent *pe);
virtual void viewportResizeEvent(QResizeEvent *re);
virtual void insertItem(QListViewItem *item);
virtual void takeItem(QListViewItem *item);
void addColumn(const QString &label);
/**
......@@ -622,6 +625,10 @@ private:
QValueList<int> m_weightDirty;
bool m_disableColumnWidthUpdates;
mutable int m_time;
mutable PlaylistItemList m_addTime;
mutable PlaylistItemList m_subtractTime;
/**
* The average minimum widths of columns to be used in balancing calculations.
*/
......
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