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 8c8df11d authored by Scott Wheeler's avatar Scott Wheeler

Convert "createItems" to a template method so that subclasses can reuse the

code but still create their own subclasses of PlaylistItem.

svn path=/trunk/kdemultimedia/juk/; revision=241663
parent f062e146
......@@ -698,16 +698,7 @@ PlaylistItem *Playlist::createItem(const QFileInfo &file, const QString &absFile
void Playlist::createItems(const PlaylistItemList &siblings)
{
PlaylistItem *previous = 0;
for(PlaylistItemList::ConstIterator it = siblings.begin(); it != siblings.end(); ++it) {
if(!m_members.insert(resolveSymLinks((*it)->absFilePath()))) {
previous = new PlaylistItem((*it)->collectionItem(), this, previous);
connect((*it)->collectionItem(), SIGNAL(destroyed()), *it, SLOT(deleteLater()));
}
}
emit signalCountChanged(this);
createItems<CollectionListItem, PlaylistItem, PlaylistItem>(siblings);
}
void Playlist::hideColumn(int c)
......
......@@ -112,7 +112,7 @@ public:
QListViewItem *after = 0,
bool emitChanged = true);
void createItems(const PlaylistItemList &siblings);
virtual void createItems(const PlaylistItemList &siblings);
/**
* Returns the file name associated with this playlist (an m3u file) or
......@@ -263,6 +263,14 @@ protected:
virtual bool acceptDrag(QDropEvent *e) const { return KURLDrag::canDecode(e); }
virtual void polish();
/**
* As a template this allows us to use the same code to initialize the items
* in subclasses. CollectionItemType should always be CollectionListItem and
* ItemType should be a PlaylistItem subclass.
*/
template <class CollectionItemType, class ItemType, class SiblingType>
void createItems(const QValueList<SiblingType *> &siblings);
/**
* Though it's somewhat obvious, this function will stat the file, so only use it when
* you're out of a performance critical loop.
......@@ -461,4 +469,22 @@ private:
QDataStream &operator<<(QDataStream &s, const Playlist &p);
QDataStream &operator>>(QDataStream &s, Playlist &p);
// template method implementations
template <class CollectionItemType, class ItemType, class SiblingType>
void Playlist::createItems(const QValueList<SiblingType *> &siblings)
{
ItemType *previous = 0;
QValueListConstIterator<SiblingType *> it = siblings.begin();
for(; it != siblings.end(); ++it) {
if(!m_members.insert(resolveSymLinks((*it)->absFilePath()))) {
previous = new ItemType((*it)->collectionItem(), this, previous);
connect((*it)->collectionItem(), SIGNAL(destroyed()), (*it), SLOT(deleteLater()));
}
}
emit signalCountChanged(this);
}
#endif
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