playlist.h 23.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/**
 * Copyright (C) 2002-2004 Scott Wheeler <wheeler@kde.org>
 * Copyright (C) 2007 Michael Pyne <mpyne@kde.org>
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
17

Michael Pyne's avatar
Michael Pyne committed
18 19
#ifndef JUK_PLAYLIST_H
#define JUK_PLAYLIST_H
20

Michael Pyne's avatar
Michael Pyne committed
21
#include <KCompletion>
22

23
#include <QVector>
24
#include <QEvent>
25
#include <QList>
26
#include <QTreeWidget>
27

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

36
class KActionMenu;
37

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

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

48
typedef QList<PlaylistItem *> PlaylistItemList;
49

50
class Playlist : public QTreeWidget, public PlaylistInterface
51 52
{
    Q_OBJECT
53

54
public:
55

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

63
    /**
64 65 66
     * 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.
67 68 69 70 71
     *
     * @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).
72
     */
73
    Playlist(PlaylistCollection *collection, bool delaySetup, int extraColumns = 0);
74

75 76
    virtual ~Playlist();

77 78 79 80 81

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

    virtual QString name() const;
    virtual FileHandle currentFile() const;
82
    virtual int count() const { return model()->rowCount(); }
83 84 85 86 87
    virtual int time() const;
    virtual void playNext();
    virtual void playPrevious();
    virtual void stop();

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

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

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

    /**
     * Standard "save as".  Prompts the user for a location where to save the
     * playlist to.
     */
110
    virtual void saveAs();
Scott Wheeler's avatar
Scott Wheeler committed
111 112

    /**
113
     * Removes \a item from the Playlist, but not from the disk.
Scott Wheeler's avatar
Scott Wheeler committed
114
     *
115 116 117
     * Since the GUI updates after an item is cleared, you should use clearItems() if you have
     * a list of items to remove, as that will remove the whole batch before updating
     * other components/GUI to the change.
Scott Wheeler's avatar
Scott Wheeler committed
118
     */
119
    virtual void clearItem(PlaylistItem *item);
Scott Wheeler's avatar
Scott Wheeler committed
120 121 122 123 124

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

127 128 129 130 131 132
    /**
     * 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.
     */
133
    static PlaylistItem *playingItem();
134

135 136
    /**
     * All of the (media) files in the list.
137
     */
138
    QStringList files() const;
139

140
    /**
Scott Wheeler's avatar
Scott Wheeler committed
141
     * Returns a list of all of the items in the playlist.
142
     */
143
    virtual PlaylistItemList items();
144

145
    /**
Scott Wheeler's avatar
Scott Wheeler committed
146
     * Returns a list of all of the \e visible items in the playlist.
147
     */
148
    PlaylistItemList visibleItems();
149

150 151 152
    /**
     * Returns a list of the currently selected items.
     */
153
    PlaylistItemList selectedItems();
154

155 156 157 158 159
    /**
     * Returns properly casted first child item in list.
     */
    PlaylistItem *firstChild() const;

160 161
    /**
     * Allow duplicate files in the playlist.
162
     */
163
    void setAllowDuplicates(bool allow) { m_allowDuplicates = allow; }
164

165
    /**
166
     * This is being used as a mini-factory of sorts to make the construction
167 168
     * of PlaylistItems virtual.  In this case it allows for the creation of
     * both PlaylistItems and CollectionListItems.
169
     */
170
    virtual PlaylistItem *createItem(const FileHandle &file,
171
                                     QTreeWidgetItem *after = nullptr);
172

Scott Wheeler's avatar
Scott Wheeler committed
173 174
    /**
     * This is implemented as a template method to allow subclasses to
175
     * instantiate their PlaylistItem subclasses using the same method.
Scott Wheeler's avatar
Scott Wheeler committed
176
     */
177
    template <class ItemType>
178
    ItemType *createItem(const FileHandle &file,
179
                         QTreeWidgetItem *after = nullptr);
180

181
    virtual void createItems(const PlaylistItemList &siblings, PlaylistItem *after = nullptr);
182

183 184 185 186
    /**
     * 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.
187 188 189 190
     *
     * 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.
191
     */
192
    virtual void addFiles(const QStringList &files, PlaylistItem *after = 0);
193

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

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

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

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

Kacper Kasper's avatar
Kacper Kasper committed
220
    void sortByColumn(int column, Qt::SortOrder order = Qt::AscendingOrder);
221

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

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

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

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

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

250 251 252 253 254
    /**
     * Returns the leftmost visible column of the listview.
     */
    int leftColumn() const { return m_leftColumn; }

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

261 262 263 264
    /**
     * 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
265
    PlaylistSearch search() const { return m_search; }
266 267 268 269

    /**
     * Set the search associtated with this playlist.
     */
270 271 272 273 274 275 276
    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
277

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

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

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

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

304
    /**
305
     * Synchronizes the playing item in this playlist with the playing item
306 307 308 309 310
     * 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);

311 312 313 314 315 316 317
    /**
     * 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();

318 319
    void read(QDataStream &s);

320 321
    static void setShuttingDown() { m_shuttingDown = true; }

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() { QTreeView::selectAll(); }
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
    virtual void playlistItemsChanged();
407

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 418 419 420 421 422 423
    /**
     * Adds and removes items from this Playlist as necessary to ensure that
     * the same items are present in this Playlist as in @p itemList.
     *
     * No ordering guarantees are imposed, just that the playlist will have the
     * same items as in the given list afterwards.
     */
    void synchronizeItemsTo(const PlaylistItemList &itemList);

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

    virtual bool eventFilter(QObject *watched, QEvent *e);
427
    virtual void keyPressEvent(QKeyEvent *e);
Tim Beaulen's avatar
Tim Beaulen committed
428
    virtual void decode(const QMimeData *s, PlaylistItem *item = 0);
Kacper Kasper's avatar
Kacper Kasper committed
429 430 431 432 433
    QStringList mimeTypes() const;
    QMimeData* mimeData(const QList<QTreeWidgetItem *> items) const;
    virtual bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action);
    virtual void dropEvent(QDropEvent *e);
    virtual void dragEnterEvent(QDragEnterEvent *e);
Scott Wheeler's avatar
Scott Wheeler committed
434
    virtual void showEvent(QShowEvent *e);
Michael Pyne's avatar
Michael Pyne committed
435
    virtual bool acceptDrag(QDropEvent *e) const;
436 437
    virtual void paintEvent(QPaintEvent *pe);
    virtual void resizeEvent(QResizeEvent *re);
438

439 440
    virtual void insertItem(QTreeWidgetItem *item);
    virtual void takeItem(QTreeWidgetItem *item);
441

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

444
    virtual void addColumn(const QString &label, int width = -1);
Scott Wheeler's avatar
Scott Wheeler committed
445

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

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

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

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

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

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 signalPlaylistItemsDropped(Playlist *p);

494 495
private:
    void setup();
496

497 498 499 500 501 502
    /**
     * This function is called to let the user know that JuK has automatically enabled
     * manual column width adjust mode.
     */
    void notifyUserColumnWidthModeChanged();

503 504 505 506 507 508
    /**
     * 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.
     */
509
    void loadFile(const QString &fileName, const QFileInfo &fileInfo);
510

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

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

524 525 526 527 528 529 530 531
    /**
     * This method is used internally to provide the backend to the other item
     * lists.
     *
     * \see items()
     * \see visibleItems()
     * \see selectedItems()
     */
532
    PlaylistItemList items(QTreeWidgetItemIterator::IteratorFlags flags);
533

534 535 536 537 538
    /**
     * Build the column "weights" for the weighted width mode.
     */
    void calculateColumnWeights();

539
    void addFile(const QString &file, FileHandleList &files, bool importPlaylists,
540
                 PlaylistItem **after);
541
    void addFileHelper(FileHandleList &files, PlaylistItem **after,
542
                       bool ignoreTimer = false);
543 544 545

    void redisplaySearch() { setSearch(m_search); }

546 547 548 549 550
    /**
     * Sets the cover for items to the cover identified by id.
     */
    void refreshAlbums(const PlaylistItemList &items, coverKey id = CoverManager::NoMatch);

551 552
    void refreshAlbum(const QString &artist, const QString &album);

553 554
    void updatePlaying() const;

555 556 557 558 559 560 561
    /**
     * 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);

562 563 564
    /**
     * Used as a helper to implement template<> createItem().  This grabs the
     * CollectionListItem for file if it exists, otherwise it creates a new one and
565 566
     * returns that.  If nullptr is returned then some kind of error occurred,
     * and you should probably do nothing with the FileHandle you have.
567 568 569
     */
    CollectionListItem *collectionListItem(const FileHandle &file);

570 571 572 573 574 575
    /**
     * 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;

576
private slots:
577

578 579 580 581 582 583 584 585 586 587
    /**
     * 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();

588 589
    void slotUpdateColumnWidths();

590 591
    void slotAddToUpcoming();

592
    /**
593
     * Show the RMB menu.  Matches the signature for the signal
594 595
     * QListView::contextMenuRequested().
     */
Kacper Kasper's avatar
Kacper Kasper committed
596
    void slotShowRMBMenu(const QPoint &point);
597 598

    /**
Scott Wheeler's avatar
Scott Wheeler committed
599 600
     * This slot is called when the inline tag editor has completed its editing
     * and starts the process of renaming the values.
601
     *
Scott Wheeler's avatar
Scott Wheeler committed
602
     * \see editTag()
603
     */
604
    void slotInlineEditDone(QTreeWidgetItem *, const QString &, int column);
605 606

    /**
607
     * This starts the renaming process by displaying a line edit if the mouse is in
608 609
     * an appropriate position.
     */
610
    void slotRenameTag();
611

612 613 614 615 616 617
    /**
     * The image fetcher will update the cover asynchronously, this internal
     * slot is called when it happens.
     */
    void slotCoverChanged(int coverId);

618 619 620 621
    /**
     * Moves the column \a from to the position \a to.  This matches the signature
     * for the signal QHeader::indexChange().
     */
622
    void slotColumnOrderChanged(int, int from, int to);
623 624 625 626 627 628 629

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

632 633 634
    /**
     * Prompts the user to create a new playlist with from the selected items.
     */
635
    void slotCreateGroup();
636

637 638 639 640
    /**
     * This slot is called when the user drags the slider in the listview header
     * to manually set the size of the column.
     */
Kacper Kasper's avatar
Kacper Kasper committed
641
    void columnResized(int column, int oldSize, int newSize);
642

643 644 645 646 647 648
    /**
     * 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.
     */
Michael Pyne's avatar
Michael Pyne committed
649
    void slotInlineCompletionModeChanged(KCompletion::CompletionMode mode);
650

651 652
    void slotPlayCurrent();

653
private:
654 655
    friend class PlaylistItem;

656 657
    PlaylistCollection *m_collection;

658
    StringHash m_members;
659

660
    WebImageFetcher *m_fetcher;
661

662
    int m_currentColumn;
Matthias Kretz's avatar
Matthias Kretz committed
663
    QAction *m_rmbEdit;
664

665
    bool m_allowDuplicates;
666
    bool m_applySharedSettings;
667
    bool m_columnWidthModeChanged;
668

669
    QList<int> m_weightDirty;
670
    bool m_disableColumnWidthUpdates;
671

672
    mutable int m_time;
673 674
    mutable PlaylistItemList m_addTime;
    mutable PlaylistItemList m_subtractTime;
675

676
    /**
677
     * The average minimum widths of columns to be used in balancing calculations.
678
     */
679 680
    QVector<int> m_columnWeights;
    QVector<int> m_columnFixedWidths;
681
    bool m_widthsDirty;
682

683
    static PlaylistItemList m_history;
684
    PlaylistSearch m_search;
685

686 687
    bool m_searchEnabled;

688
    /**
689
     * Used to store the text for inline editing before it is changed so that
690 691 692 693
     * we can know if something actually changed and as such if we need to save
     * the tag.
     */
    QString m_editText;
694 695 696 697 698

    /**
     * This is only defined if the playlist name is something other than the
     * file name.
     */
699
    QString m_playlistName;
700
    QString m_fileName;
701

702
    QStringList m_columns;
Kacper Kasper's avatar
Kacper Kasper committed
703
    QMenu *m_rmbMenu;
704
    QMenu *m_headerMenu;
705
    KActionMenu *m_columnVisibleAction;
706
    PlaylistToolTip *m_toolTip;
707

708
    /**
709
     * This is used to indicate if the list of visible items has changed (via a
710 711 712
     * call to setVisibleItems()) while random play is playing.
     */
    static bool m_visibleChanged;
713
    static bool m_shuttingDown;
714
    static int m_leftColumn;
715
    static QVector<PlaylistItem *> m_backMenuItems;
716 717

    bool m_blockDataChanged;
718 719
};

720 721
typedef QList<Playlist *> PlaylistList;

722
bool processEvents();
723

724
class FocusUpEvent : public QEvent
725 726
{
public:
727 728 729 730
    FocusUpEvent() : QEvent(id) {}
    Type type() const { return id; }

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

733
QDataStream &operator<<(QDataStream &s, const Playlist &p);
734 735
QDataStream &operator>>(QDataStream &s, Playlist &p);

736 737
// template method implementations

738
template <class ItemType>
739
ItemType *Playlist::createItem(const FileHandle &file, QTreeWidgetItem *after)
740
{
741
    CollectionListItem *item = collectionListItem(file);
André Wöbbeking's avatar
André Wöbbeking committed
742
    if(item && (!m_members.insert(file.absFilePath()) || m_allowDuplicates)) {
743
        auto i = new ItemType(item, this, after);
744 745
        setupItem(i);
        return i;
746 747
    }
    else
748
        return nullptr;
749 750
}

751 752 753 754
template <class ItemType, class SiblingType>
ItemType *Playlist::createItem(SiblingType *sibling, ItemType *after)
{
    m_disableColumnWidthUpdates = true;
755

756
    if(!m_members.insert(sibling->file().absFilePath()) || m_allowDuplicates) {
757 758
        after = new ItemType(sibling->collectionItem(), this, after);
        setupItem(after);
759 760 761 762 763 764 765
    }

    m_disableColumnWidthUpdates = false;

    return after;
}

766
template <class ItemType, class SiblingType>
767
void Playlist::createItems(const QList<SiblingType *> &siblings, ItemType *after)
768
{
769
    if(siblings.isEmpty())
770
        return;
771

772 773
    foreach(SiblingType *sibling, siblings)
        after = createItem(sibling, after);
774

775
    playlistItemsChanged();
776
    slotWeightDirty();
777 778
}

779
#endif
780 781

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