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

playlist.h 24 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
    copyright            : (c) 2007 Michael Pyne
    email                : michael.pyne@kdemail.net
7 8 9 10 11 12 13 14 15 16 17 18 19 20
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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

Laurent Montel's avatar
Laurent Montel committed
21
#include <k3listview.h>
22
#include <kglobalsettings.h>
23
#include <kdebug.h>
24

25
#include <QVector>
26
#include <QEvent>
27
#include <QList>
28

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

Laurent Montel's avatar
Laurent Montel committed
35
class KMenu;
36
class KActionMenu;
37

38 39 40
class QFileInfo;
class QMimeData;
class QDrag;
Matthias Kretz's avatar
Matthias Kretz committed
41
class QAction;
Scott Wheeler's avatar
Scott Wheeler committed
42

43
class WebImageFetcher;
44
class PlaylistItem;
45
class PlaylistCollection;
46
class PlaylistToolTip;
47
class CollectionListItem;
48

49
typedef QList<PlaylistItem *> PlaylistItemList;
50

Laurent Montel's avatar
Laurent Montel committed
51
class Playlist : public K3ListView, public PlaylistInterface
52 53
{
    Q_OBJECT
54

55
public:
56

57
    explicit Playlist(PlaylistCollection *collection, const QString &name = QString(),
Michael Pyne's avatar
Michael Pyne committed
58
             const QString &iconName = "audio-midi");
59
    Playlist(PlaylistCollection *collection, const PlaylistItemList &items,
Michael Pyne's avatar
Michael Pyne committed
60
             const QString &name = QString(), const QString &iconName = "audio-midi");
61
    Playlist(PlaylistCollection *collection, const QFileInfo &playlistFile,
Michael Pyne's avatar
Michael Pyne committed
62
             const QString &iconName = "audio-midi");
63

64
    /**
65 66 67
     * 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.
68 69 70 71 72
     *
     * @param extraColumns is used to preallocate columns for subclasses that
     * need them (since extra columns are assumed to start from 0). extraColumns
     * should be equal to columnOffset() (we can't use columnOffset until the
     * ctor has run).
73
     */
74
    Playlist(PlaylistCollection *collection, bool delaySetup, int extraColumns = 0);
75

76 77
    virtual ~Playlist();

78 79 80 81 82 83 84 85 86 87 88

    // 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();

89 90 91
    /**
     * Plays the top item of the playlist.
     */
92 93
    void playFirst();

94 95 96 97 98 99
    /**
     * Plays the next album in the playlist.  Only useful when in album random
     * play mode.
     */
    void playNextAlbum();

100 101 102
    /**
     * 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
103
     * name.
104
     */
105
    virtual void save();
Scott Wheeler's avatar
Scott Wheeler committed
106 107 108 109 110

    /**
     * Standard "save as".  Prompts the user for a location where to save the
     * playlist to.
     */
111
    virtual void saveAs();
Scott Wheeler's avatar
Scott Wheeler committed
112 113 114 115 116 117 118 119 120 121 122

    /**
     * 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.
     */
123
    virtual void clearItem(PlaylistItem *item, bool emitChanged = true);
Scott Wheeler's avatar
Scott Wheeler committed
124 125 126 127 128

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

131 132 133 134 135 136
    /**
     * 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.
     */
137
    static PlaylistItem *playingItem();
138

139 140
    /**
     * All of the (media) files in the list.
141
     */
142
    QStringList files() const;
143

144
    /**
Scott Wheeler's avatar
Scott Wheeler committed
145
     * Returns a list of all of the items in the playlist.
146
     */
147
    virtual PlaylistItemList items();
148

149
    /**
Scott Wheeler's avatar
Scott Wheeler committed
150
     * Returns a list of all of the \e visible items in the playlist.
151
     */
152
    PlaylistItemList visibleItems();
153

154 155 156
    /**
     * Returns a list of the currently selected items.
     */
157
    PlaylistItemList selectedItems();
158

159 160 161 162 163
    /**
     * Returns properly casted first child item in list.
     */
    PlaylistItem *firstChild() const;

164 165
    /**
     * Allow duplicate files in the playlist.
166
     */
167
    void setAllowDuplicates(bool allow) { m_allowDuplicates = allow; }
168

169
    /**
170
     * This is being used as a mini-factory of sorts to make the construction
171 172
     * of PlaylistItems virtual.  In this case it allows for the creation of
     * both PlaylistItems and CollectionListItems.
173
     */
174
    virtual PlaylistItem *createItem(const FileHandle &file,
175 176
                                     Q3ListViewItem *after = 0,
                                     bool emitChanged = true);
177

Scott Wheeler's avatar
Scott Wheeler committed
178 179
    /**
     * This is implemented as a template method to allow subclasses to
180
     * instantiate their PlaylistItem subclasses using the same method.
Scott Wheeler's avatar
Scott Wheeler committed
181
     */
182
    template <class ItemType>
183
    ItemType *createItem(const FileHandle &file,
184 185
                         Q3ListViewItem *after = 0,
                         bool emitChanged = true);
186

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

189 190 191 192
    /**
     * 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.
193 194 195 196
     *
     * 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.
197
     */
198
    virtual void addFiles(const QStringList &files, PlaylistItem *after = 0);
199

200 201
    /**
     * Returns the file name associated with this playlist (an m3u file) or
202
     * an empty QString if no such file exists.
203
     */
204
    QString fileName() const { return m_fileName; }
205 206 207 208 209

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

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

    /**
220
     * Shows column \a c.  If \a updateSearch is true then a signal that the
221 222 223
     * visible columns have changed will be emitted and things like the search
     * will be udated.
     */
224
    void showColumn(int c, bool updateSearch = true);
225 226
    bool isColumnVisible(int c) const;

227 228 229 230
    /**
     * This sets a name for the playlist that is \e different from the file name.
     */
    void setName(const QString &n);
231

232 233 234 235
    /**
     * Returns the KActionMenu that allows this to be embedded in menus outside
     * of the playlist.
     */
236
    KActionMenu *columnVisibleAction() const { return m_columnVisibleAction; }
237

238
    /**
239 240
     * Set item to be the playing item.  If \a item is null then this will clear
     * the playing indicator.
241
     */
242
    static void setPlaying(PlaylistItem *item, bool addToHistory = true);
243 244 245 246

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

Scott Wheeler's avatar
Scott Wheeler committed
249 250 251
    /**
     * This forces an update of the left most visible column, but does not save
     * the settings for this.
252
     */
Scott Wheeler's avatar
Scott Wheeler committed
253
    void updateLeftColumn();
254

255 256 257 258 259
    /**
     * Returns the leftmost visible column of the listview.
     */
    int leftColumn() const { return m_leftColumn; }

260 261 262 263
    /**
     * Sets the items in the list to be either visible based on the value of
     * visible.  This is useful for search operations and such.
     */
264 265
    static void setItemsVisible(const PlaylistItemList &items, bool visible = true);

266 267 268 269
    /**
     * 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
270
    PlaylistSearch search() const { return m_search; }
271 272 273 274

    /**
     * Set the search associtated with this playlist.
     */
275 276 277 278 279 280 281
    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
282

Scott Wheeler's avatar
Scott Wheeler committed
283 284 285
    /**
     * Marks \a item as either selected or deselected based.
     */
286 287
    void markItemSelected(PlaylistItem *item, bool selected);

Scott Wheeler's avatar
Scott Wheeler committed
288 289 290 291 292 293
    /**
     * 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.
     */
294
    virtual int columnOffset() const { return 0; }
Scott Wheeler's avatar
Scott Wheeler committed
295 296 297 298 299 300

    /**
     * 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.
     */
301
    virtual bool readOnly() const { return false; }
302

303 304 305
    /**
     * Returns true if it's possible to reload this playlist.
     */
306
    virtual bool canReload() const { return !m_fileName.isEmpty(); }
307

308 309 310 311 312 313
    /**
     * Returns true if the playlist is a search playlist and the search should be
     * editable.
     */
    virtual bool searchIsEditable() const { return false; }

314
    /**
315
     * Synchronizes the playing item in this playlist with the playing item
316 317 318 319 320
     * 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);

321 322 323 324 325 326 327
    /**
     * 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();

328 329
    void read(QDataStream &s);

330 331
    static void setShuttingDown() { m_shuttingDown = true; }

332
public slots:
333
    /**
334
     * Remove the currently selected items from the playlist and disk.
335
     */
336
    void slotRemoveSelectedItems() { removeFromDisk(selectedItems()); }
Scott Wheeler's avatar
Scott Wheeler committed
337

338 339 340 341
    /*
     * The edit slots are required to use the canonical names so that they are
     * detected by the application wide framework.
     */
342
    virtual void cut() { copy(); clear(); }
Scott Wheeler's avatar
Scott Wheeler committed
343 344 345 346 347

    /**
     * Puts a list of URLs pointing to the files in the current selection on the
     * clipboard.
     */
348
    virtual void copy();
Scott Wheeler's avatar
Scott Wheeler committed
349 350 351 352

    /**
     * Checks the clipboard for local URLs to be inserted into this playlist.
     */
353
    virtual void paste();
Scott Wheeler's avatar
Scott Wheeler committed
354 355 356 357 358 359 360

    /**
     * Removes the selected items from the list, but not the disk.
     *
     * @see clearItem()
     * @see clearItems()
     */
361
    virtual void clear();
Laurent Montel's avatar
Laurent Montel committed
362
    virtual void selectAll() { K3ListView::selectAll(true); }
363

364 365 366 367 368 369
    /**
     * Refreshes the tags of the selection from disk, or all of the files in the
     * list if there is no selection.
     */
    virtual void slotRefresh();

370
    void slotGuessTagInfo(TagGuesser::Type type);
Scott Wheeler's avatar
Scott Wheeler committed
371 372 373 374 375 376

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

379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
    /**
     * 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();

395 396 397 398 399
    /**
     * Shows the cover manager GUI dialog
     */
    void slotShowCoverManager();

400 401 402
    /**
     * Reload the playlist contents from the m3u file.
     */
403
    virtual void slotReload();
404

405 406 407 408 409
    /**
     * 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.
     */
410
    void slotWeightDirty(int column = -1);
411

412 413
    void slotShowPlaying();

414 415
    void slotColumnResizeModeChanged();

416 417
    virtual void dataChanged();

418
protected:
419 420 421 422
    /**
     * Remove \a items from the playlist and disk.  This will ignore items that
     * are not actually in the list.
     */
423
    void removeFromDisk(const PlaylistItemList &items);
424

425 426 427
    // the following are all reimplemented from base classes

    virtual bool eventFilter(QObject *watched, QEvent *e);
428
    virtual void keyPressEvent(QKeyEvent *e);
429 430
    virtual Q3DragObject *dragObject(QWidget *parent);
    virtual Q3DragObject *dragObject() { return dragObject(this); }
Tim Beaulen's avatar
Tim Beaulen committed
431
    virtual void decode(const QMimeData *s, PlaylistItem *item = 0);
432
    virtual void contentsDropEvent(QDropEvent *e);
433
    virtual void contentsMouseDoubleClickEvent(QMouseEvent *e);
Michael Pyne's avatar
Michael Pyne committed
434
    virtual void contentsDragEnterEvent(QDragEnterEvent *e);
Scott Wheeler's avatar
Scott Wheeler committed
435
    virtual void showEvent(QShowEvent *e);
Michael Pyne's avatar
Michael Pyne committed
436
    virtual bool acceptDrag(QDropEvent *e) const;
437 438 439
    virtual void viewportPaintEvent(QPaintEvent *pe);
    virtual void viewportResizeEvent(QResizeEvent *re);

Laurent Montel's avatar
Laurent Montel committed
440 441
    virtual void insertItem(Q3ListViewItem *item);
    virtual void takeItem(Q3ListViewItem *item);
442

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

445 446
    virtual int addColumn(const QString &label, int width = -1);
    using K3ListView::addColumn;
Scott Wheeler's avatar
Scott Wheeler committed
447

448 449 450 451 452 453 454 455
    /**
     * 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);

456 457 458 459
    /**
     * Forwards the call to the parent to enable or disable automatic deletion
     * of tree view playlists.  Used by CollectionListItem.
     */
460
    void setDynamicListsFrozen(bool frozen);
461

462 463 464
    template <class ItemType, class SiblingType>
    ItemType *createItem(SiblingType *sibling, ItemType *after = 0);

465 466
    /**
     * As a template this allows us to use the same code to initialize the items
467
     * in subclasses. ItemType should be a PlaylistItem subclass.
468
     */
469
    template <class ItemType, class SiblingType>
470
    void createItems(const QList<SiblingType *> &siblings, ItemType *after = 0);
471

472 473
protected slots:
    void slotPopulateBackMenu() const;
Tim Beaulen's avatar
Tim Beaulen committed
474
    void slotPlayFromBackMenu(QAction *) const;
475

476
signals:
477

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

484
    /**
485
     * This signal is emitted just before a playlist item is removed from the
486 487 488
     * 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.
489
     */
490
    void signalAboutToRemove(PlaylistItem *item);
491

492 493
    void signalEnableDirWatch(bool enable);

494 495
    void coverChanged();

496 497
    void signalPlaylistItemsDropped(Playlist *p);

498 499
private:
    void setup();
500

501 502 503 504 505 506
    /**
     * This function is called to let the user know that JuK has automatically enabled
     * manual column width adjust mode.
     */
    void notifyUserColumnWidthModeChanged();

507 508 509 510 511 512
    /**
     * 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.
     */
513
    void loadFile(const QString &fileName, const QFileInfo &fileInfo);
514

515
    /**
Scott Wheeler's avatar
Scott Wheeler committed
516
     * Writes \a text to \a item in \a column.  This is used by the inline tag
517
     * editor.  Returns false if the tag update failed.
518
     */
519
    bool editTag(PlaylistItem *item, const QString &text, int column);
520 521 522 523 524 525

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

528 529 530 531 532 533 534 535
    /**
     * This method is used internally to provide the backend to the other item
     * lists.
     *
     * \see items()
     * \see visibleItems()
     * \see selectedItems()
     */
Laurent Montel's avatar
Laurent Montel committed
536
    PlaylistItemList items(Q3ListViewItemIterator::IteratorFlag flags);
537

538 539 540 541 542
    /**
     * Build the column "weights" for the weighted width mode.
     */
    void calculateColumnWeights();

543
    void addFile(const QString &file, FileHandleList &files, bool importPlaylists,
544
                 PlaylistItem **after);
545
    void addFileHelper(FileHandleList &files, PlaylistItem **after,
546
                       bool ignoreTimer = false);
547 548 549

    void redisplaySearch() { setSearch(m_search); }

550 551 552 553 554
    /**
     * Sets the cover for items to the cover identified by id.
     */
    void refreshAlbums(const PlaylistItemList &items, coverKey id = CoverManager::NoMatch);

555 556
    void refreshAlbum(const QString &artist, const QString &album);

557 558
    void updatePlaying() const;

559 560 561 562 563 564 565
    /**
     * This function should be called when item is deleted to ensure that any
     * internal bookkeeping is performed.  It is automatically called by
     * PlaylistItem::~PlaylistItem and by clearItem() and clearItems().
     */
    void updateDeletedItem(PlaylistItem *item);

566 567 568 569 570 571 572 573
    /**
     * Used as a helper to implement template<> createItem().  This grabs the
     * CollectionListItem for file if it exists, otherwise it creates a new one and
     * returns that.  If 0 is returned then some kind of error occurred, such as file not
     * found and probably nothing should be done with the FileHandle you have.
     */
    CollectionListItem *collectionListItem(const FileHandle &file);

574 575 576 577 578 579
    /**
     * 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;

580 581
    using K3ListView::selectAll; // Avoid warning about hiding this function.

582
private slots:
583

584 585 586 587 588 589 590 591 592 593
    /**
     * Handle the necessary tasks needed to create and setup the playlist that
     * don't need to happen in the ctor, such as setting up the columns,
     * initializing the RMB menu, and setting up signal/slot connections.
     *
     * Used to be a subclass of K3ListView::polish() but the timing of the
     * call is not consistent and therefore lead to crashes.
     */
    void slotInitialize();

594 595
    void slotUpdateColumnWidths();

596 597
    void slotAddToUpcoming();

598
    /**
599
     * Show the RMB menu.  Matches the signature for the signal
600 601
     * QListView::contextMenuRequested().
     */
Laurent Montel's avatar
Laurent Montel committed
602
    void slotShowRMBMenu(Q3ListViewItem *item, const QPoint &point, int column);
603 604

    /**
Scott Wheeler's avatar
Scott Wheeler committed
605 606
     * This slot is called when the inline tag editor has completed its editing
     * and starts the process of renaming the values.
607
     *
Scott Wheeler's avatar
Scott Wheeler committed
608
     * \see editTag()
609
     */
Laurent Montel's avatar
Laurent Montel committed
610
    void slotInlineEditDone(Q3ListViewItem *, const QString &, int column);
611 612

    /**
613
     * This starts the renaming process by displaying a line edit if the mouse is in
614 615
     * an appropriate position.
     */
616
    void slotRenameTag();
617

618 619 620 621 622 623
    /**
     * The image fetcher will update the cover asynchronously, this internal
     * slot is called when it happens.
     */
    void slotCoverChanged(int coverId);

624 625 626 627
    /**
     * Moves the column \a from to the position \a to.  This matches the signature
     * for the signal QHeader::indexChange().
     */
628
    void slotColumnOrderChanged(int, int from, int to);
629 630 631 632 633 634 635

    /**
     * Toggles a columns visible status.  Useful for KActions.
     *
     * \see hideColumn()
     * \see showColumn()
     */
636
    void slotToggleColumnVisible(QAction *action);
637

638 639 640
    /**
     * Prompts the user to create a new playlist with from the selected items.
     */
641
    void slotCreateGroup();
642

643 644 645 646 647 648
    /**
     * 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);

649 650 651 652 653 654 655 656
    /**
     * 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);

657 658
    void slotPlayCurrent();

659
private:
660 661
    friend class PlaylistItem;

662 663
    PlaylistCollection *m_collection;

664
    StringHash m_members;
665

666
    WebImageFetcher *m_fetcher;
667

668
    int m_currentColumn;
669
    int m_processed;
Matthias Kretz's avatar
Matthias Kretz committed
670
    QAction *m_rmbEdit;
671 672
    int m_selectedCount;

673
    bool m_allowDuplicates;
674
    bool m_applySharedSettings;
675
    bool m_columnWidthModeChanged;
676

677
    QList<int> m_weightDirty;
678
    bool m_disableColumnWidthUpdates;
679

680
    mutable int m_time;
681 682
    mutable PlaylistItemList m_addTime;
    mutable PlaylistItemList m_subtractTime;
683

684
    /**
685
     * The average minimum widths of columns to be used in balancing calculations.
686
     */
687 688
    QVector<int> m_columnWeights;
    QVector<int> m_columnFixedWidths;
689
    bool m_widthsDirty;
690

691
    static PlaylistItemList m_history;
692
    PlaylistSearch m_search;
693

694 695
    bool m_searchEnabled;

696
    PlaylistItem *m_lastSelected;
697

698
    /**
699
     * Used to store the text for inline editing before it is changed so that
700 701 702 703
     * we can know if something actually changed and as such if we need to save
     * the tag.
     */
    QString m_editText;
704 705 706 707 708

    /**
     * This is only defined if the playlist name is something other than the
     * file name.
     */
709
    QString m_playlistName;
710
    QString m_fileName;
711

Laurent Montel's avatar
Laurent Montel committed
712 713
    KMenu *m_rmbMenu;
    KMenu *m_headerMenu;
714
    KActionMenu *m_columnVisibleAction;
715
    PlaylistToolTip *m_toolTip;
716

717
    /**
718
     * This is used to indicate if the list of visible items has changed (via a
719 720 721
     * call to setVisibleItems()) while random play is playing.
     */
    static bool m_visibleChanged;
722
    static bool m_shuttingDown;
723
    static int m_leftColumn;
724
    static QMap<int, PlaylistItem *> m_backMenuItems;
725 726

    bool m_blockDataChanged;
727 728
};

729 730
typedef QList<Playlist *> PlaylistList;

731
bool processEvents();
732

733
class FocusUpEvent : public QEvent
734 735
{
public:
736 737 738 739
    FocusUpEvent() : QEvent(id) {}
    Type type() const { return id; }

    static const Type id = static_cast<Type>(QEvent::User + 1);
740 741
};

742
QDataStream &operator<<(QDataStream &s, const Playlist &p);
743 744
QDataStream &operator>>(QDataStream &s, Playlist &p);

745 746
// template method implementations

747
template <class ItemType>
Laurent Montel's avatar
Laurent Montel committed
748
ItemType *Playlist::createItem(const FileHandle &file, Q3ListViewItem *after,
749
                               bool emitChanged)
750
{
751
    CollectionListItem *item = collectionListItem(file);
André Wöbbeking's avatar
André Wöbbeking committed
752
    if(item && (!m_members.insert(file.absFilePath()) || m_allowDuplicates)) {
753

754 755
        ItemType *i = after ? new ItemType(item, this, after) : new ItemType(item, this);
        setupItem(i);
756

757 758
        if(emitChanged)
            dataChanged();
759

760
        return i;
761 762
    }
    else
763
        return 0;
764 765
}

766 767 768 769
template <class ItemType, class SiblingType>
ItemType *Playlist::createItem(SiblingType *sibling, ItemType *after)
{
    m_disableColumnWidthUpdates = true;
770

771
    if(!m_members.insert(sibling->file().absFilePath()) || m_allowDuplicates) {
772 773
        after = new ItemType(sibling->collectionItem(), this, after);
        setupItem(after);
774 775 776 777 778 779 780
    }

    m_disableColumnWidthUpdates = false;

    return after;
}

781
template <class ItemType, class SiblingType>
782
void Playlist::createItems(const QList<SiblingType *> &siblings, ItemType *after)
783
{
784
    if(siblings.isEmpty())
785
        return;
786

787 788
    foreach(SiblingType *sibling, siblings)
        after = createItem(sibling, after);
789

790
    dataChanged();
791
    slotWeightDirty();
792 793
}

794
#endif
795 796

// vim: set et sw=4 tw=0 sta: