1 /* 2 * playlisttab.h 3 * 4 * Copyright (C) 2009-2011 Christoph Pfister <christophpfister@gmail.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License along 17 * with this program; if not, write to the Free Software Foundation, Inc., 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 */ 20 21 #ifndef PLAYLISTTAB_H 22 #define PLAYLISTTAB_H 23 24 #include <QTreeView> 25 #include "../mediawidget.h" 26 #include "../tabbase.h" 27 28 class QSplitter; 29 class Playlist; 30 class PlaylistBrowserView; 31 class PlaylistModel; 32 33 class PlaylistView : public QTreeView 34 { 35 Q_OBJECT 36 public: 37 explicit PlaylistView(QWidget *parent); 38 ~PlaylistView(); 39 40 public slots: 41 void removeSelectedRows(); 42 43 protected: 44 void contextMenuEvent(QContextMenuEvent *event); 45 void keyPressEvent(QKeyEvent *event); 46 }; 47 48 class PlaylistBrowserModel : public QAbstractListModel 49 { 50 Q_OBJECT 51 public: 52 PlaylistBrowserModel(PlaylistModel *playlistModel_, Playlist *temporaryPlaylist, 53 QObject *parent); 54 ~PlaylistBrowserModel(); 55 56 void append(Playlist *playlist); 57 Playlist *getPlaylist(int row) const; 58 void setCurrentPlaylist(Playlist *playlist); 59 Playlist *getCurrentPlaylist() const; 60 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); 61 62 signals: 63 void playTrack(Playlist *playlist, int track); 64 65 private: 66 int rowCount(const QModelIndex &parent) const; 67 QVariant data(const QModelIndex &index, int role) const; 68 Qt::ItemFlags flags(const QModelIndex &index) const; 69 bool setData(const QModelIndex &index, const QVariant &value, int role); 70 71 PlaylistModel *playlistModel; 72 QList<Playlist *> playlists; 73 int currentPlaylist; 74 }; 75 76 class PlaylistTab : public TabBase 77 { 78 Q_OBJECT 79 public: 80 PlaylistTab(QMenu *menu, KActionCollection *collection, MediaWidget *mediaWidget_); 81 ~PlaylistTab(); 82 83 void appendToCurrentPlaylist(const QList<QUrl> &urls, bool playImmediately); 84 void appendToVisiblePlaylist(const QList<QUrl> &urls, bool playImmediately); 85 void removeTrack(int row); 86 void setRandom(bool random); 87 void setRepeat(bool repeat); 88 89 int getCurrentTrack() const; 90 int getTrackCount() const; 91 bool getRandom() const; 92 bool getRepeat() const; 93 94 private slots: 95 void createFileWidget(); 96 void newPlaylist(); 97 void renamePlaylist(); 98 void removePlaylist(); 99 void savePlaylist(); 100 void savePlaylistAs(); 101 void addSubtitle(); 102 void playlistActivated(const QModelIndex &index); 103 void playPreviousTrack(); 104 void playCurrentTrack(); 105 void playNextTrack(); 106 void playTrack(Playlist *playlist, int track); 107 void playTrack(const QModelIndex &index); 108 void appendUrls(const QList<QUrl> &urls); 109 void appendPlaylist(Playlist *playlist, bool playImmediately); 110 void updateTrackLength(int length); 111 void updateTrackMetadata(const QMap<MediaWidget::MetadataType, QString> &metadata); 112 113 private: 114 static QString subtitleExtensionFilter(); // usable for KFileDialog::setFilter() 115 void activate(); 116 void savePlaylist(bool askName); 117 118 MediaWidget *mediaWidget; 119 QLayout *mediaLayout; 120 QSplitter *fileWidgetSplitter; 121 PlaylistBrowserModel *playlistBrowserModel; 122 PlaylistBrowserView *playlistBrowserView; 123 PlaylistModel *playlistModel; 124 PlaylistView *playlistView; 125 QAction *randomAction; 126 QAction *repeatAction; 127 }; 128 129 #endif /* PLAYLISTTAB_H */ 130