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

/***************************************************************************
 *                                                                         *
 *   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
19
#include <k3listview.h>
Laurent Montel's avatar
Laurent Montel committed
20
#include <k3urldrag.h>
Dirk Mueller's avatar
compile  
Dirk Mueller committed
21
#include <kdebug.h>
22
#include <kglobalsettings.h>
23

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

Laurent Montel's avatar
Laurent Montel committed
27 28 29 30 31 32 33 34 35 36
#include <QPaintEvent>
#include <QKeyEvent>
#include <QEvent>
#include <QDropEvent>
#include <Q3ValueList>
#include <QShowEvent>
#include <QResizeEvent>
#include <QDragEnterEvent>
#include <QMouseEvent>
#include <QCustomEvent>
Tim Beaulen's avatar
Tim Beaulen committed
37
#include <QMimeData>
Tim Beaulen's avatar
Tim Beaulen committed
38
#include <QDrag>
39

40
#include "covermanager.h"
41
#include "stringhash.h"
Scott Wheeler's avatar
Scott Wheeler committed
42
#include "playlistsearch.h"
43
#include "tagguesser.h"
44
#include "playlistinterface.h"
45
#include "playlistitem.h"
46

Laurent Montel's avatar
Laurent Montel committed
47
class KMenu;
48
class KActionMenu;
49 50

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

52
class PlaylistCollection;
Scott Wheeler's avatar
Scott Wheeler committed
53

54
class PlaylistToolTip;
55 56
class UpcomingPlaylist;

Laurent Montel's avatar
Laurent Montel committed
57
typedef Q3ValueList<PlaylistItem *> PlaylistItemList;
58

Laurent Montel's avatar
Laurent Montel committed
59
class Playlist : public K3ListView, public PlaylistInterface
60 61
{
    Q_OBJECT
62

63
public:
64

65
    Playlist(PlaylistCollection *collection, const QString &name = QString::null,
66
             const QString &iconName = "midi");
67
    Playlist(PlaylistCollection *collection, const PlaylistItemList &items,
68
             const QString &name = QString::null, const QString &iconName = "midi");
69
    Playlist(PlaylistCollection *collection, const QFileInfo &playlistFile,
70
             const QString &iconName = "midi");
71

72
    /**
73 74 75
     * 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.
76
     */
77
    Playlist(PlaylistCollection *collection, bool delaySetup);
78

79 80
    virtual ~Playlist();

81 82 83 84 85 86 87 88 89 90 91

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

92 93 94
    /**
     * Plays the top item of the playlist.
     */
95 96
    void playFirst();

97 98 99 100 101 102
    /**
     * Plays the next album in the playlist.  Only useful when in album random
     * play mode.
     */
    void playNextAlbum();

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

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

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

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

134 135 136 137 138 139
    /**
     * 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.
     */
140
    static PlaylistItem *playingItem();
141

142 143
    /**
     * All of the (media) files in the list.
144
     */
145
    QStringList files() const;
146

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

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

157 158 159
    /**
     * Returns a list of the currently selected items.
     */
160
    PlaylistItemList selectedItems();
161

162 163 164 165 166
    /**
     * Returns properly casted first child item in list.
     */
    PlaylistItem *firstChild() const;

167 168
    /**
     * Allow duplicate files in the playlist.
169
     */
170
    void setAllowDuplicates(bool allow) { m_allowDuplicates = allow; }
171

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

Scott Wheeler's avatar
Scott Wheeler committed
181 182 183 184 185
    /**
     * 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
186
     * be the same.
Scott Wheeler's avatar
Scott Wheeler committed
187
     */
188
    template <class ItemType, class CollectionItemType, class CollectionListType>
189
    ItemType *createItem(const FileHandle &file,
190 191
                         Q3ListViewItem *after = 0,
                         bool emitChanged = true);
192

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

195 196 197 198
    /**
     * 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.
199 200 201 202
     *
     * 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.
203
     */
204
    virtual void addFiles(const QStringList &files, PlaylistItem *after = 0);
205

206 207 208 209
    /**
     * Returns the file name associated with this playlist (an m3u file) or
     * QString::null if no such file exists.
     */
210
    QString fileName() const { return m_fileName; }
211 212 213 214 215

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

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

    /**
226
     * Shows column \a c.  If \a updateSearch is true then a signal that the
227 228 229
     * visible columns have changed will be emitted and things like the search
     * will be udated.
     */
230
    void showColumn(int c, bool updateSearch = true);
231 232
    bool isColumnVisible(int c) const;

233 234 235 236
    /**
     * This sets a name for the playlist that is \e different from the file name.
     */
    void setName(const QString &n);
237

238 239 240 241
    /**
     * Returns the KActionMenu that allows this to be embedded in menus outside
     * of the playlist.
     */
242
    KActionMenu *columnVisibleAction() const { return m_columnVisibleAction; }
243

244
    /**
245 246
     * Set item to be the playing item.  If \a item is null then this will clear
     * the playing indicator.
247
     */
248
    static void setPlaying(PlaylistItem *item, bool addToHistory = true);
249 250 251 252

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

Scott Wheeler's avatar
Scott Wheeler committed
255 256 257
    /**
     * This forces an update of the left most visible column, but does not save
     * the settings for this.
258
     */
Scott Wheeler's avatar
Scott Wheeler committed
259
    void updateLeftColumn();
260

261 262 263 264 265
    /**
     * Returns the leftmost visible column of the listview.
     */
    int leftColumn() const { return m_leftColumn; }

266 267 268 269
    /**
     * Sets the items in the list to be either visible based on the value of
     * visible.  This is useful for search operations and such.
     */
270 271
    static void setItemsVisible(const PlaylistItemList &items, bool visible = true);

272 273 274 275
    /**
     * 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
276
    PlaylistSearch search() const { return m_search; }
277 278 279 280

    /**
     * Set the search associtated with this playlist.
     */
281 282 283 284 285 286 287
    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
288

Scott Wheeler's avatar
Scott Wheeler committed
289 290 291
    /**
     * Marks \a item as either selected or deselected based.
     */
292 293
    void markItemSelected(PlaylistItem *item, bool selected);

Scott Wheeler's avatar
Scott Wheeler committed
294 295 296 297 298 299
    /**
     * 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.
     */
300
    virtual int columnOffset() const { return 0; }
Scott Wheeler's avatar
Scott Wheeler committed
301 302 303 304 305 306

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

309 310 311 312 313
    /**
     * Returns true if it's possible to reload this playlist.
     */
    virtual bool canReload() const { return !m_fileName.isNull(); }

314 315 316 317 318 319
    /**
     * Returns true if the playlist is a search playlist and the search should be
     * editable.
     */
    virtual bool searchIsEditable() const { return false; }

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

327 328 329 330 331 332 333
    /**
     * 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();

334 335
    void read(QDataStream &s);

336 337
    static void setShuttingDown() { m_shuttingDown = true; }

338
public slots:
339
    /**
340
     * Remove the currently selected items from the playlist and disk.
341
     */
342
    void slotRemoveSelectedItems() { removeFromDisk(selectedItems()); };
Scott Wheeler's avatar
Scott Wheeler committed
343

344 345 346 347
    /*
     * The edit slots are required to use the canonical names so that they are
     * detected by the application wide framework.
     */
348
    virtual void cut() { copy(); clear(); }
Scott Wheeler's avatar
Scott Wheeler committed
349 350 351 352 353

    /**
     * Puts a list of URLs pointing to the files in the current selection on the
     * clipboard.
     */
354
    virtual void copy();
Scott Wheeler's avatar
Scott Wheeler committed
355 356 357 358

    /**
     * Checks the clipboard for local URLs to be inserted into this playlist.
     */
359
    virtual void paste();
Scott Wheeler's avatar
Scott Wheeler committed
360 361 362 363 364 365 366

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

370 371 372 373 374 375
    /**
     * Refreshes the tags of the selection from disk, or all of the files in the
     * list if there is no selection.
     */
    virtual void slotRefresh();

376
    void slotGuessTagInfo(TagGuesser::Type type);
Scott Wheeler's avatar
Scott Wheeler committed
377 378 379 380 381 382

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

385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
    /**
     * 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();

401 402 403 404 405
    /**
     * Shows the cover manager GUI dialog
     */
    void slotShowCoverManager();

406 407 408
    /**
     * Reload the playlist contents from the m3u file.
     */
409
    virtual void slotReload();
410

411 412 413 414 415
    /**
     * 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.
     */
416
    void slotWeightDirty(int column = -1);
417

418 419
    void slotShowPlaying();

420 421
    void slotColumnResizeModeChanged();

422 423
    virtual void dataChanged();

424
protected:
425 426 427 428
    /**
     * Remove \a items from the playlist and disk.  This will ignore items that
     * are not actually in the list.
     */
429
    void removeFromDisk(const PlaylistItemList &items);
430

431 432 433
    // the following are all reimplemented from base classes

    virtual bool eventFilter(QObject *watched, QEvent *e);
434
    virtual void keyPressEvent(QKeyEvent *e);
Tim Beaulen's avatar
Tim Beaulen committed
435 436
    virtual QDrag *drag(QWidget *parent);
    virtual QDrag *drag() { return drag(this); }
437
    virtual bool canDecode(QMimeSource *s);
Tim Beaulen's avatar
Tim Beaulen committed
438
    virtual void decode(const QMimeData *s, PlaylistItem *item = 0);
439
    virtual void contentsDropEvent(QDropEvent *e);
440
    virtual void contentsMouseDoubleClickEvent(QMouseEvent *e);
Michael Pyne's avatar
Michael Pyne committed
441
    virtual void contentsDragEnterEvent(QDragEnterEvent *e);
Scott Wheeler's avatar
Scott Wheeler committed
442
    virtual void showEvent(QShowEvent *e);
Michael Pyne's avatar
Michael Pyne committed
443
    virtual bool acceptDrag(QDropEvent *e) const;
444 445 446
    virtual void viewportPaintEvent(QPaintEvent *pe);
    virtual void viewportResizeEvent(QResizeEvent *re);

Laurent Montel's avatar
Laurent Montel committed
447 448
    virtual void insertItem(Q3ListViewItem *item);
    virtual void takeItem(Q3ListViewItem *item);
449

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

452
    void addColumn(const QString &label);
Scott Wheeler's avatar
Scott Wheeler committed
453 454 455 456 457 458 459 460

    /**
     * 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.
     */
461
    virtual void polish();
462

463 464 465 466 467 468 469 470
    /**
     * 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);

471 472 473 474
    /**
     * Forwards the call to the parent to enable or disable automatic deletion
     * of tree view playlists.  Used by CollectionListItem.
     */
475
    void setDynamicListsFrozen(bool frozen);
476

477 478 479
    template <class ItemType, class SiblingType>
    ItemType *createItem(SiblingType *sibling, ItemType *after = 0);

480 481 482 483 484 485
    /**
     * 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>
Laurent Montel's avatar
Laurent Montel committed
486
    void createItems(const Q3ValueList<SiblingType *> &siblings, ItemType *after = 0);
487

488 489 490 491
protected slots:
    void slotPopulateBackMenu() const;
    void slotPlayFromBackMenu(int number) const;

492
signals:
493

494
    /**
495
     * This is connected to the PlaylistBox::Item to let it know when the
496 497
     * playlist's name has changed.
     */
498
    void signalNameChanged(const QString &name);
499

500
    /**
501
     * This signal is emitted just before a playlist item is removed from the
502 503 504
     * 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.
505
     */
506
    void signalAboutToRemove(PlaylistItem *item);
507

508 509
    void signalEnableDirWatch(bool enable);

510 511
    void coverChanged();

512 513
    void signalPlaylistItemsDropped(Playlist *p);

514 515
private:
    void setup();
516

517 518 519 520 521 522
    /**
     * This function is called to let the user know that JuK has automatically enabled
     * manual column width adjust mode.
     */
    void notifyUserColumnWidthModeChanged();

523 524 525 526 527 528
    /**
     * 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.
     */
529
    void loadFile(const QString &fileName, const QFileInfo &fileInfo);
530

531
    /**
Scott Wheeler's avatar
Scott Wheeler committed
532
     * Writes \a text to \a item in \a column.  This is used by the inline tag
533
     * editor.  Returns false if the tag update failed.
534
     */
535
    bool editTag(PlaylistItem *item, const QString &text, int column);
536 537 538 539 540 541

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

544 545 546 547 548 549 550 551
    /**
     * 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
552
    PlaylistItemList items(Q3ListViewItemIterator::IteratorFlag flags);
553

554 555 556 557 558
    /**
     * Build the column "weights" for the weighted width mode.
     */
    void calculateColumnWeights();

559
    void addFile(const QString &file, FileHandleList &files, bool importPlaylists,
560
                 PlaylistItem **after);
561
    void addFileHelper(FileHandleList &files, PlaylistItem **after,
562
                       bool ignoreTimer = false);
563 564 565

    void redisplaySearch() { setSearch(m_search); }

566 567 568 569 570
    /**
     * Sets the cover for items to the cover identified by id.
     */
    void refreshAlbums(const PlaylistItemList &items, coverKey id = CoverManager::NoMatch);

571 572
    void refreshAlbum(const QString &artist, const QString &album);

573 574 575 576 577
    /**
     * 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.
     */
578
    unsigned int eligibleCoverItems(const PlaylistItemList &items);
579

580 581
    void updatePlaying() const;

582 583 584 585 586 587
    /**
     * 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;

588
private slots:
589

590 591
    void slotUpdateColumnWidths();

592 593
    void slotAddToUpcoming();

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

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

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

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

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

628 629 630
    /**
     * Prompts the user to create a new playlist with from the selected items.
     */
631
    void slotCreateGroup();
632

633 634 635 636 637 638
    /**
     * 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);

639 640 641 642 643 644 645 646
    /**
     * 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);

647 648
    void slotPlayCurrent();

649
private:
650 651
    PlaylistCollection *m_collection;

652
    StringHash m_members;
653

654
    int m_currentColumn;
655
    int m_processed;
656
    int m_rmbEditID;
657
    int m_rmbUpcomingID;
658 659
    int m_selectedCount;

660
    bool m_allowDuplicates;
661
    bool m_polished;
662
    bool m_applySharedSettings;
663
    bool m_columnWidthModeChanged;
664

Laurent Montel's avatar
Laurent Montel committed
665
    Q3ValueList<int> m_weightDirty;
666
    bool m_disableColumnWidthUpdates;
667

668
    mutable int m_time;
669 670
    mutable PlaylistItemList m_addTime;
    mutable PlaylistItemList m_subtractTime;
671

672
    /**
673
     * The average minimum widths of columns to be used in balancing calculations.
674
     */
Laurent Montel's avatar
Laurent Montel committed
675 676
    Q3ValueVector<int> m_columnWeights;
    Q3ValueVector<int> m_columnFixedWidths;
677
    bool m_widthsDirty;
678

679
    static PlaylistItemList m_history;
680
    PlaylistSearch m_search;
681

682 683
    bool m_searchEnabled;

684
    PlaylistItem *m_lastSelected;
685

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

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

Laurent Montel's avatar
Laurent Montel committed
700 701
    KMenu *m_rmbMenu;
    KMenu *m_headerMenu;
702
    KActionMenu *m_columnVisibleAction;
703
    PlaylistToolTip *m_toolTip;
704

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

    bool m_blockDataChanged;
715 716
};

717
bool processEvents();
718

719
class FocusUpEvent : public QEvent
720 721
{
public:
722 723 724 725
    FocusUpEvent() : QEvent(id) {}
    Type type() const { return id; }

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

728
QDataStream &operator<<(QDataStream &s, const Playlist &p);
729 730
QDataStream &operator>>(QDataStream &s, Playlist &p);

731 732
// template method implementations

733
template <class ItemType, class CollectionItemType, class CollectionListType>
Laurent Montel's avatar
Laurent Montel committed
734
ItemType *Playlist::createItem(const FileHandle &file, Q3ListViewItem *after,
735
                               bool emitChanged)
736
{
737
    CollectionItemType *item = CollectionListType::instance()->lookup(file.absFilePath());
738 739

    if(!item) {
740 741
        item = new CollectionItemType(file);
        setupItem(item);
742

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

745 746 747 748 749 750
        if(!item->isValid()) {
            kError(65432) << "Playlist::createItem() -- A valid tag was not created for \""
                           << file.absFilePath() << "\"" << endl;
            delete item;
            return 0;
        }
751 752
    }

753
    if(item && !m_members.insert(file.absFilePath()) || m_allowDuplicates) {
754

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

758 759
        if(emitChanged)
            dataChanged();
760

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

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

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

    m_disableColumnWidthUpdates = false;

    return after;
}

782
template <class CollectionItemType, class ItemType, class SiblingType>
Laurent Montel's avatar
Laurent Montel committed
783
void Playlist::createItems(const Q3ValueList<SiblingType *> &siblings, ItemType *after)
784
{
785
    if(siblings.isEmpty())
786
        return;
787

Laurent Montel's avatar
Laurent Montel committed
788
    Q3ValueListConstIterator<SiblingType *> it = siblings.begin();
789
    for(; it != siblings.end(); ++it)
790
        after = createItem(*it, after);
791

792
    dataChanged();
793
    slotWeightDirty();
794 795
}

796
#endif
797 798

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