File indexing completed on 2024-05-12 04:52:23

0001 /*
0002  * playlisttab.h
0003  *
0004  * Copyright (C) 2009-2011 Christoph Pfister <christophpfister@gmail.com>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License along
0017  * with this program; if not, write to the Free Software Foundation, Inc.,
0018  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0019  */
0020 
0021 #ifndef PLAYLISTTAB_H
0022 #define PLAYLISTTAB_H
0023 
0024 #include <QTreeView>
0025 #include "../mediawidget.h"
0026 #include "../tabbase.h"
0027 
0028 class QSplitter;
0029 class Playlist;
0030 class PlaylistBrowserView;
0031 class PlaylistModel;
0032 
0033 class PlaylistView : public QTreeView
0034 {
0035     Q_OBJECT
0036 public:
0037     explicit PlaylistView(QWidget *parent);
0038     ~PlaylistView();
0039 
0040 public slots:
0041     void removeSelectedRows();
0042 
0043 protected:
0044     void contextMenuEvent(QContextMenuEvent *event) override;
0045     void keyPressEvent(QKeyEvent *event) override;
0046 };
0047 
0048 class PlaylistBrowserModel : public QAbstractListModel
0049 {
0050     Q_OBJECT
0051 public:
0052     PlaylistBrowserModel(PlaylistModel *playlistModel_, Playlist *temporaryPlaylist,
0053         QObject *parent);
0054     ~PlaylistBrowserModel();
0055 
0056     void append(Playlist *playlist);
0057     Playlist *getPlaylist(int row) const;
0058     void setCurrentPlaylist(Playlist *playlist);
0059     Playlist *getCurrentPlaylist() const;
0060     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
0061 
0062 signals:
0063     void playTrack(Playlist *playlist, int track);
0064 
0065 private:
0066     int rowCount(const QModelIndex &parent) const override;
0067     QVariant data(const QModelIndex &index, int role) const override;
0068     Qt::ItemFlags flags(const QModelIndex &index) const override;
0069     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0070 
0071     PlaylistModel *playlistModel;
0072     QList<Playlist *> playlists;
0073     int currentPlaylist;
0074 };
0075 
0076 class PlaylistTab : public TabBase
0077 {
0078     Q_OBJECT
0079 public:
0080     PlaylistTab(QMenu *menu, KActionCollection *collection, MediaWidget *mediaWidget_);
0081     ~PlaylistTab();
0082 
0083     void appendToCurrentPlaylist(const QList<QUrl> &urls, bool playImmediately);
0084     void appendToVisiblePlaylist(const QList<QUrl> &urls, bool playImmediately);
0085     void removeTrack(int row);
0086     void setRandom(bool random);
0087     void setRepeat(bool repeat);
0088 
0089     int getCurrentTrack() const;
0090     int getTrackCount() const;
0091     bool getRandom() const;
0092     bool getRepeat() const;
0093 
0094 private slots:
0095     void createFileWidget();
0096     void newPlaylist();
0097     void renamePlaylist();
0098     void removePlaylist();
0099     void savePlaylist();
0100     void savePlaylistAs();
0101     void addSubtitle();
0102     void playlistActivated(const QModelIndex &index);
0103     void playPreviousTrack();
0104     void playCurrentTrack();
0105     void playNextTrack();
0106     void playTrack(Playlist *playlist, int track);
0107     void playTrack(const QModelIndex &index);
0108     void appendUrls(const QList<QUrl> &urls);
0109     void appendPlaylist(Playlist *playlist, bool playImmediately);
0110     void updateTrackLength(int length);
0111     void updateTrackMetadata(const QMap<MediaWidget::MetadataType, QString> &metadata);
0112 
0113 private:
0114     static QString subtitleExtensionFilter(); // usable for KFileDialog::setFilter()
0115     void activate() override;
0116     void savePlaylist(bool askName);
0117 
0118     MediaWidget *mediaWidget;
0119     QLayout *mediaLayout;
0120     QSplitter *fileWidgetSplitter;
0121     PlaylistBrowserModel *playlistBrowserModel;
0122     PlaylistBrowserView *playlistBrowserView;
0123     PlaylistModel *playlistModel;
0124     PlaylistView *playlistView;
0125     QAction *randomAction;
0126     QAction *repeatAction;
0127 };
0128 
0129 #endif /* PLAYLISTTAB_H */