playlist.h 22.9 KB
Newer Older
1 2
/***************************************************************************
    begin                : Sat Feb 16 2002
3
    copyright            : (C) 2002 - 2004 by Scott Wheeler
4
    email                : wheeler@kde.org
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef PLAYLIST_H
#define PLAYLIST_H

#include <klistview.h>
20
#include <kurldrag.h>
Dirk Mueller's avatar
compile  
Dirk Mueller committed
21
#include <kdebug.h>
22
#include <kglobalsettings.h>
23

24
#include <qvaluevector.h>
Dirk Mueller's avatar
compile  
Dirk Mueller committed
25
#include <qfileinfo.h>
26

27
#include "stringhash.h"
Scott Wheeler's avatar
Scott Wheeler committed
28
#include "playlistsearch.h"
29
#include "tagguesser.h"
30
#include "playlistinterface.h"
31
#include "playlistitem.h"
32 33

class KPopupMenu;
34
class KActionMenu;
35 36

class QEvent;
Scott Wheeler's avatar
Scott Wheeler committed
37

38
class PlaylistCollection;
Scott Wheeler's avatar
Scott Wheeler committed
39

40
class PlaylistToolTip;
41 42
class UpcomingPlaylist;

Scott Wheeler's avatar
Scott Wheeler committed
43
typedef QValueList<PlaylistItem *> PlaylistItemList;
44

45
class Playlist : public KListView, public PlaylistInterface
46 47
{
    Q_OBJECT
48

49
public:
50

51 52 53 54 55 56
    Playlist(PlaylistCollection *collection, const QString &name = QString::null,
	     const QString &iconName = "midi");
    Playlist(PlaylistCollection *collection, const PlaylistItemList &items,
	     const QString &name = QString::null, const QString &iconName = "midi");
    Playlist(PlaylistCollection *collection, const QFileInfo &playlistFile,
	     const QString &iconName = "midi");
57

58
    /**
59 60 61
     * This constructor should generally only be used either by the cache
     * restoration methods or by subclasses that want to handle calls to
     * PlaylistCollection::setupPlaylist() differently.
62
     */
63
    Playlist(PlaylistCollection *collection, bool delaySetup);
64

65 66
    virtual ~Playlist();

67 68 69 70 71 72 73 74 75 76 77

    // The following group of functions implement the PlaylistInterface API.

    virtual QString name() const;
    virtual FileHandle currentFile() const;
    virtual int count() const { return childCount(); }
    virtual int time() const;
    virtual void playNext();
    virtual void playPrevious();
    virtual void stop();

78 79 80
    /**
     * Plays the top item of the playlist.
     */
81 82
    void playFirst();

83 84 85 86 87 88
    /**
     * Plays the next album in the playlist.  Only useful when in album random
     * play mode.
     */
    void playNextAlbum();

89 90 91
    /**
     * Saves the file to the currently set file name.  If there is no filename
     * currently set, the default behavior is to prompt the user for a file
92
     * name.
93
     */
94
    virtual void save();
Scott Wheeler's avatar
Scott Wheeler committed
95 96 97 98 99

    /**
     * Standard "save as".  Prompts the user for a location where to save the
     * playlist to.
     */
100
    virtual void saveAs();
Scott Wheeler's avatar
Scott Wheeler committed
101 102 103 104 105 106 107 108 109 110 111

    /**
     * Removes \a item from the Playlist, but not from the disk.  If
     * \a emitChanged is true this will also notify relevant classes
     * that the content of the list has changed.
     *
     * In some situations, for instance when removing items in a loop, it is
     * preferable to delay this notification until after other operations have
     * completed.  In those cases set \a emitChanged to false and call the
     * signal directly.
     */
112
    virtual void clearItem(PlaylistItem *item, bool emitChanged = true);
Scott Wheeler's avatar
Scott Wheeler committed
113 114 115 116 117

    /**
     * Remove \a items from the playlist and emit a signal indicating
     * that the number of items in the list has changed.
     */
118
    virtual void clearItems(const PlaylistItemList &items);
119

120 121 122 123 124 125
    /**
     * Accessor function to return a pointer to the currently playing file.
     *
     * @return 0 if no file is playing, otherwise a pointer to the PlaylistItem
     *     of the track that is currently playing.
     */
126
    static PlaylistItem *playingItem();
127

128 129
    /**
     * All of the (media) files in the list.
130
     */
131
    QStringList files() const;
132

133
    /**
Scott Wheeler's avatar
Scott Wheeler committed
134
     * Returns a list of all of the items in the playlist.
135
     */
136
    virtual PlaylistItemList items();
137

138
    /**
Scott Wheeler's avatar
Scott Wheeler committed
139
     * Returns a list of all of the \e visible items in the playlist.
140
     */
141
    PlaylistItemList visibleItems();
142

143 144 145
    /**
     * Returns a list of the currently selected items.
     */
146
    PlaylistItemList selectedItems();
147

148 149 150 151 152
    /**
     * Returns properly casted first child item in list.
     */
    PlaylistItem *firstChild() const;

153 154
    /**
     * Allow duplicate files in the playlist.
155
     */
156
    void setAllowDuplicates(bool allow) { m_allowDuplicates = allow; }
157

158
    /**
159
     * This is being used as a mini-factory of sorts to make the construction
160 161
     * of PlaylistItems virtual.  In this case it allows for the creation of
     * both PlaylistItems and CollectionListItems.
162
     */
163
    virtual PlaylistItem *createItem(const FileHandle &file,
164 165
				     QListViewItem *after = 0,
				     bool emitChanged = true);
166

Scott Wheeler's avatar
Scott Wheeler committed
167 168 169 170 171 172 173
    /**
     * This is implemented as a template method to allow subclasses to
     * instantiate their PlaylistItem subclasses using the same method.  Some
     * of the types here are artificially templatized (i.e. CollectionListType and
     * CollectionItemType) to avoid recursive includes, but in fact will always
     * be the same.     
     */
174
    template <class ItemType, class CollectionItemType, class CollectionListType>
175
    ItemType *createItem(const FileHandle &file,
176 177 178
			 QListViewItem *after = 0,
			 bool emitChanged = true);

179
    virtual void createItems(const PlaylistItemList &siblings, PlaylistItem *after = 0);
180

181 182 183 184
    /**
     * This handles adding files of various types -- music, playlist or directory
     * files.  Music files that are found will be added to this playlist.  New
     * playlist files that are found will result in new playlists being created.
185 186 187 188
     *
     * Note that this should not be used in the case of adding *only* playlist
     * items since it has the overhead of checking to see if the file is a playlist
     * or directory first.
189
     */
190
    virtual void addFiles(const QStringList &files, PlaylistItem *after = 0);
191

192 193 194 195
    /**
     * Returns the file name associated with this playlist (an m3u file) or
     * QString::null if no such file exists.
     */
196
    QString fileName() const { return m_fileName; }
197 198 199 200 201

    /**
     * Sets the file name to be associated with this playlist; this file should
     * have the "m3u" extension.
     */
202
    void setFileName(const QString &n) { m_fileName = n; }
203

204
    /**
205
     * Hides column \a c.  If \a updateSearch is true then a signal that the
206 207 208
     * visible columns have changed will be emitted and things like the search
     * will be udated.
     */
209
    void hideColumn(int c, bool updateSearch = true);
210 211

    /**
212
     * Shows column \a c.  If \a updateSearch is true then a signal that the
213 214 215
     * visible columns have changed will be emitted and things like the search
     * will be udated.
     */
216
    void showColumn(int c, bool updateSearch = true);
217 218
    bool isColumnVisible(int c) const;

219 220 221 222
    /**
     * This sets a name for the playlist that is \e different from the file name.
     */
    void setName(const QString &n);
223

224 225 226 227
    /**
     * Returns the KActionMenu that allows this to be embedded in menus outside
     * of the playlist.
     */
228
    KActionMenu *columnVisibleAction() const { return m_columnVisibleAction; }
229

230
    /**
231 232
     * Set item to be the playing item.  If \a item is null then this will clear
     * the playing indicator.
233
     */
234
    static void setPlaying(PlaylistItem *item, bool addToHistory = true);
235 236 237 238

    /**
     * Returns true if this playlist is currently playing.
     */
Scott Wheeler's avatar
Scott Wheeler committed
239
    bool playing() const;
240

Scott Wheeler's avatar
Scott Wheeler committed
241 242 243
    /**
     * This forces an update of the left most visible column, but does not save
     * the settings for this.
244
     */
Scott Wheeler's avatar
Scott Wheeler committed
245
    void updateLeftColumn();
246

247 248 249 250 251
    /**
     * Returns the leftmost visible column of the listview.
     */
    int leftColumn() const { return m_leftColumn; }

252 253 254 255
    /**
     * Sets the items in the list to be either visible based on the value of
     * visible.  This is useful for search operations and such.
     */
256 257
    static void setItemsVisible(const PlaylistItemList &items, bool visible = true);

258 259 260 261
    /**
     * Returns the search associated with this list, or an empty search if one
     * has not yet been set.
     */
Scott Wheeler's avatar
Scott Wheeler committed
262
    PlaylistSearch search() const { return m_search; }
263 264 265 266

    /**
     * Set the search associtated with this playlist.
     */
267 268 269 270 271 272 273
    void setSearch(const PlaylistSearch &s);

    /**
     * If the search is disabled then all items will be shown, not just those that
     * match the current search.
     */
    void setSearchEnabled(bool searchEnabled);
Scott Wheeler's avatar
Scott Wheeler committed
274

Scott Wheeler's avatar
Scott Wheeler committed
275 276 277
    /**
     * Marks \a item as either selected or deselected based.
     */
278 279
    void markItemSelected(PlaylistItem *item, bool selected);

Scott Wheeler's avatar
Scott Wheeler committed
280 281 282 283 284 285
    /**
     * Subclasses of Playlist which add new columns will set this value to
     * specify how many of those colums exist.  This allows the Playlist
     * class to do some internal calculations on the number and positions
     * of columns.
     */
286
    virtual int columnOffset() const { return 0; }
Scott Wheeler's avatar
Scott Wheeler committed
287 288 289 290 291 292

    /**
     * Some subclasses of Playlist will be "read only" lists (i.e. the history
     * playlist).  This is a way for those subclasses to indicate that to the
     * Playlist internals.
     */
293
    virtual bool readOnly() const { return false; }
294

295 296 297 298 299
    /**
     * Returns true if it's possible to reload this playlist.
     */
    virtual bool canReload() const { return !m_fileName.isNull(); }

300 301 302 303 304 305
    /**
     * Returns true if the playlist is a search playlist and the search should be
     * editable.
     */
    virtual bool searchIsEditable() const { return false; }

306 307 308 309 310 311 312
    /**
     * Synchronizes the the playing item in this playlist with the playing item
     * in \a sources.  If \a setMaster is true, this list will become the source
     * for determining the next item.
     */
    void synchronizePlayingItems(const PlaylistList &sources, bool setMaster);

313 314 315 316 317 318 319
    /**
     * Playlists have a common set of shared settings such as visible columns
     * that should be applied just before the playlist is shown.  Calling this
     * method applies those.
     */
    void applySharedSettings();

320 321
    void read(QDataStream &s);

322
public slots:
323
    /**
324
     * Remove the currently selected items from the playlist and disk.
325
     */
326
    void slotRemoveSelectedItems() { removeFromDisk(selectedItems()); };
Scott Wheeler's avatar
Scott Wheeler committed
327

328 329 330 331
    /*
     * The edit slots are required to use the canonical names so that they are
     * detected by the application wide framework.
     */
332
    virtual void cut() { copy(); clear(); }
Scott Wheeler's avatar
Scott Wheeler committed
333 334 335 336 337

    /**
     * Puts a list of URLs pointing to the files in the current selection on the
     * clipboard.
     */
338
    virtual void copy();
Scott Wheeler's avatar
Scott Wheeler committed
339 340 341 342

    /**
     * Checks the clipboard for local URLs to be inserted into this playlist.
     */
343
    virtual void paste();
Scott Wheeler's avatar
Scott Wheeler committed
344 345 346 347 348 349 350

    /**
     * Removes the selected items from the list, but not the disk.
     *
     * @see clearItem()
     * @see clearItems()
     */
351
    virtual void clear();
352
    virtual void selectAll() { KListView::selectAll(true); }
353

354 355 356 357 358 359
    /**
     * Refreshes the tags of the selection from disk, or all of the files in the
     * list if there is no selection.
     */
    virtual void slotRefresh();

360
    void slotGuessTagInfo(TagGuesser::Type type);
Scott Wheeler's avatar
Scott Wheeler committed
361 362 363 364 365 366

    /**
     * Renames the selected items' files based on their tags contents.
     *
     * @see PlaylistItem::renameFile()
     */
367 368
    void slotRenameFile();

369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
    /**
     * Sets the cover of the selected items, pass in true if you want to load from the local system,
     * false if you want to load from the internet.
     */
    void slotAddCover(bool fromLocal);

    /**
     * Shows a large image of the cover
     */
    void slotViewCover();

    /**
     * Removes covers from the selected items
     */
    void slotRemoveCover();

385 386 387 388 389
    /**
     * Shows the cover manager GUI dialog
     */
    void slotShowCoverManager();

390 391 392
    /**
     * Reload the playlist contents from the m3u file.
     */
393
    virtual void slotReload();
394

395 396 397 398 399
    /**
     * Tells the listview that the next time that it paints that the weighted
     * column widths must be recalculated.  If this is called without a column
     * all visible columns are marked as dirty.
     */
400
    void slotWeightDirty(int column = -1);
401

402 403
    void slotShowPlaying();

404 405
    void slotColumnResizeModeChanged();

406 407
    virtual void dataChanged();

408
protected:
409 410 411 412
    /**
     * Remove \a items from the playlist and disk.  This will ignore items that
     * are not actually in the list.
     */
413
    void removeFromDisk(const PlaylistItemList &items);
414

415 416 417
    // the following are all reimplemented from base classes

    virtual bool eventFilter(QObject *watched, QEvent *e);
418
    virtual QDragObject *dragObject(QWidget *parent);
419
    virtual QDragObject *dragObject() { return dragObject(this); }
420
    virtual bool canDecode(QMimeSource *s);
421
    virtual void decode(QMimeSource *s, PlaylistItem *item = 0);
422
    virtual void contentsDropEvent(QDropEvent *e);
423
    virtual void contentsMouseDoubleClickEvent(QMouseEvent *e);
Scott Wheeler's avatar
Scott Wheeler committed
424
    virtual void showEvent(QShowEvent *e);
425
    virtual bool acceptDrag(QDropEvent *e) const { return KURLDrag::canDecode(e); }
426 427 428
    virtual void viewportPaintEvent(QPaintEvent *pe);
    virtual void viewportResizeEvent(QResizeEvent *re);

429 430 431
    virtual void insertItem(QListViewItem *item);
    virtual void takeItem(QListViewItem *item);

432 433
    virtual bool hasItem(const QString &file) const { return m_members.contains(file); }

434
    void addColumn(const QString &label);
Scott Wheeler's avatar
Scott Wheeler committed
435 436 437 438 439 440 441 442

    /**
     * Here I'm using delayed setup of some things that aren't quite intuitive.
     * Creating columns and setting up connections are both time consuming if
     * there are a lot of playlists to initialize.  This moves that cost from the
     * startup time to the time when the widget is "polished" -- i.e. just before
     * it's painted the first time.
     */
443
    virtual void polish();
444

445 446 447 448 449 450 451 452
    /**
     * Do some finial initialization of created items.  Notably ensure that they
     * are shown or hidden based on the contents of the current PlaylistSearch.
     *
     * This is called by the PlaylistItem constructor.
     */
    void setupItem(PlaylistItem *item);

453 454 455 456 457 458
    /**
     * Forwards the call to the parent to enable or disable automatic deletion
     * of tree view playlists.  Used by CollectionListItem.
     */
    void setCanDeletePlaylist(bool canDelete);

459 460 461
    template <class ItemType, class SiblingType>
    ItemType *createItem(SiblingType *sibling, ItemType *after = 0);

462 463 464 465 466 467
    /**
     * 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>
468
    void createItems(const QValueList<SiblingType *> &siblings, ItemType *after = 0);
469

470 471 472 473
protected slots:
    void slotPopulateBackMenu() const;
    void slotPlayFromBackMenu(int number) const;

474
signals:
475

476
    /**
477
     * This is connected to the PlaylistBox::Item to let it know when the
478 479
     * playlist's name has changed.
     */
480
    void signalNameChanged(const QString &name);
481

482
    /**
483
     * This signal is emitted just before a playlist item is removed from the
484 485 486
     * list allowing for any cleanup that needs to happen.  Typically this
     * is used to remove the item from the history and safeguard against
     * dangling pointers.
487
     */
488
    void signalAboutToRemove(PlaylistItem *item);
489

490 491
    void signalEnableDirWatch(bool enable);

492 493
    void coverChanged();

494 495
    void signalPlaylistItemsDropped(Playlist *p);

496 497
private:
    void setup();
498 499 500 501 502 503 504

    /**
     * Load the playlist from a file.  \a fileName should be the absolute path.
     * \a fileInfo should point to the same file as \a fileName.  This is a
     * little awkward API-wise, but keeps us from throwing away useful
     * information.
     */
505
    void loadFile(const QString &fileName, const QFileInfo &fileInfo);
506

507
    /**
Scott Wheeler's avatar
Scott Wheeler committed
508
     * Writes \a text to \a item in \a column.  This is used by the inline tag
509
     * editor.  Returns false if the tag update failed.
510
     */
511
    bool editTag(PlaylistItem *item, const QString &text, int column);
512 513 514 515 516 517

    /**
     * Returns the index of the left most visible column in the playlist.
     *
     * \see isColumnVisible()
     */
518
    int leftMostVisibleColumn() const;
519

520 521 522 523 524 525 526 527 528 529
    /**
     * This method is used internally to provide the backend to the other item
     * lists.
     *
     * \see items()
     * \see visibleItems()
     * \see selectedItems()
     */
    PlaylistItemList items(QListViewItemIterator::IteratorFlag flags);

530 531 532 533 534
    /**
     * Build the column "weights" for the weighted width mode.
     */
    void calculateColumnWeights();

535 536
    void addFile(const QString &file, FileHandleList &files, bool importPlaylists,
		 PlaylistItem **after);
537 538
    void addFileHelper(FileHandleList &files, PlaylistItem **after,
		       bool ignoreTimer = false);
539 540 541

    void redisplaySearch() { setSearch(m_search); }

542
    void refreshAlbums(const PlaylistItemList &items, const QImage &image = QImage());
543 544
    void refreshAlbum(const QString &artist, const QString &album);

545 546 547 548 549 550 551
    /**
     * Returns the number of PlaylistItems in @p items that can be assigned a
     * cover.  Used to avoid wasting the users' time setting the cover for 20
     * items when none are eligible.
     */
    int eligibleCoverItems(const PlaylistItemList &items);

552 553
    void updatePlaying() const;

554 555 556 557 558 559
    /**
     * This class is used internally to store settings that are shared by all
     * of the playlists, such as column order.  It is implemented as a singleton.
     */
    class SharedSettings;

560
private slots:
561

562 563
    void slotUpdateColumnWidths();

564 565
    void slotAddToUpcoming();

566 567 568 569
    /**
     * Show the RMB menu.  Matches the signature for the signal 
     * QListView::contextMenuRequested().
     */
570
    void slotShowRMBMenu(QListViewItem *item, const QPoint &point, int column);
571 572

    /**
Scott Wheeler's avatar
Scott Wheeler committed
573 574
     * This slot is called when the inline tag editor has completed its editing
     * and starts the process of renaming the values.
575
     *
Scott Wheeler's avatar
Scott Wheeler committed
576
     * \see editTag()
577
     */
Scott Wheeler's avatar
Scott Wheeler committed
578
    void slotInlineEditDone(QListViewItem *, const QString &, int column);
579 580 581 582 583

    /**
     * This starts the renaming process by displaying a line edit if the mouse is in 
     * an appropriate position.
     */
584
    void slotRenameTag();
585 586 587 588 589

    /**
     * Moves the column \a from to the position \a to.  This matches the signature
     * for the signal QHeader::indexChange().
     */
590
    void slotColumnOrderChanged(int, int from, int to);
591 592 593 594 595 596 597

    /**
     * Toggles a columns visible status.  Useful for KActions.
     *
     * \see hideColumn()
     * \see showColumn()
     */
598
    void slotToggleColumnVisible(int column);
599

600 601 602
    /**
     * Prompts the user to create a new playlist with from the selected items.
     */
603
    void slotCreateGroup();
604

605 606 607 608 609 610
    /**
     * This slot is called when the user drags the slider in the listview header
     * to manually set the size of the column.
     */
    void slotColumnSizeChanged(int column, int oldSize, int newSize);

611 612 613 614 615 616 617 618
    /**
     * The slot is called when the completion mode for the line edit in the
     * inline tag editor is changed.  It saves the settings and through the
     * magic of the SharedSettings class will apply it to the other playlists as
     * well.
     */
    void slotInlineCompletionModeChanged(KGlobalSettings::Completion mode);

619 620
    void slotPlayCurrent();

621
private:
622 623
    PlaylistCollection *m_collection;

624
    StringHash m_members;
625

626
    int m_currentColumn;
627
    int m_processed;
628
    int m_rmbEditID;
629
    int m_rmbUpcomingID;
630 631
    int m_selectedCount;

632
    bool m_allowDuplicates;
633
    bool m_polished;
634
    bool m_applySharedSettings;
635
    bool m_mousePressed;
636

637
    QValueList<int> m_weightDirty;
638
    bool m_disableColumnWidthUpdates;
639

640
    mutable int m_time;
641 642
    mutable QValueList<PlaylistItem::Pointer> m_addTime;
    mutable QValueList<PlaylistItem::Pointer> m_subtractTime;
643

644
    /**
645
     * The average minimum widths of columns to be used in balancing calculations.
646
     */
647
    QValueVector<int> m_columnWeights;
648 649
    QValueVector<int> m_columnFixedWidths;
    bool m_widthsDirty;
650 651

    PlaylistItemList m_randomList;
652
    static PlaylistItemList m_history;
653
    PlaylistSearch m_search;
654

655 656
    bool m_searchEnabled;

657
    PlaylistItem *m_lastSelected;
658

659
    /**
660
     * Used to store the text for inline editing before it is changed so that
661 662 663 664
     * we can know if something actually changed and as such if we need to save
     * the tag.
     */
    QString m_editText;
665 666 667 668 669

    /**
     * This is only defined if the playlist name is something other than the
     * file name.
     */
670
    QString m_playlistName;
671
    QString m_fileName;
672

673 674 675
    KPopupMenu *m_rmbMenu;
    KPopupMenu *m_headerMenu;
    KActionMenu *m_columnVisibleAction;
676
    PlaylistToolTip *m_toolTip;
677

678 679 680 681 682
    /**
     * This is used to indicate if the list of visible items has changed (via a 
     * call to setVisibleItems()) while random play is playing.
     */
    static bool m_visibleChanged;
683
    static int m_leftColumn;
684
    static QMap<int, PlaylistItem *> m_backMenuItems;
685 686

    bool m_blockDataChanged;
687 688
};

689
bool processEvents();
690

691
QDataStream &operator<<(QDataStream &s, const Playlist &p);
692 693
QDataStream &operator>>(QDataStream &s, Playlist &p);

694 695
// template method implementations

696
template <class ItemType, class CollectionItemType, class CollectionListType>
697 698
ItemType *Playlist::createItem(const FileHandle &file, QListViewItem *after,
			       bool emitChanged)
699
{
700
    CollectionItemType *item = CollectionListType::instance()->lookup(file.absFilePath());
701 702

    if(!item) {
703
	item = new CollectionItemType(file);
704
	setupItem(item);
705 706

	// If a valid tag was not created, destroy the CollectionListItem.
707

708 709
	if(!item->isValid()) {
	    kdError(65432) << "Playlist::createItem() -- A valid tag was not created for \""
710
			   << file.absFilePath() << "\"" << endl;
711 712 713 714 715
	    delete item;
	    return 0;
	}
    }

716
    if(item && !m_members.insert(file.absFilePath()) || m_allowDuplicates) {
717

718
	ItemType *i = after ? new ItemType(item, this, after) : new ItemType(item, this);
719 720
	setupItem(i);

721 722
        if(!m_randomList.isEmpty() && !m_visibleChanged)
            m_randomList.append(i);
723

724
	if(emitChanged)
725
	    dataChanged();
726 727 728 729

	return i;
    }
    else
730
	return 0;
731 732
}

733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
template <class ItemType, class SiblingType>
ItemType *Playlist::createItem(SiblingType *sibling, ItemType *after)
{
    m_disableColumnWidthUpdates = true;
    
    if(!m_members.insert(sibling->file().absFilePath()) || m_allowDuplicates) {
	after = new ItemType(sibling->collectionItem(), this, after);
	setupItem(after);
	if(!m_randomList.isEmpty() && !m_visibleChanged)
	    m_randomList.append(after);
    }

    m_disableColumnWidthUpdates = false;

    return after;
}

750
template <class CollectionItemType, class ItemType, class SiblingType>
751
void Playlist::createItems(const QValueList<SiblingType *> &siblings, ItemType *after)
752
{
753 754 755
    if(siblings.isEmpty())
	return;

756
    QValueListConstIterator<SiblingType *> it = siblings.begin();
757 758
    for(; it != siblings.end(); ++it)
	after = createItem(*it, after);
759

760
    dataChanged();
761
    slotWeightDirty();
762 763
}

764
#endif