| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QMEDIAPLAYLIST_P_H |
| 41 | #define QMEDIAPLAYLIST_P_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists purely as an |
| 48 | // implementation detail. This header file may change from version to |
| 49 | // version without notice, or even be removed. |
| 50 | // |
| 51 | // We mean it. |
| 52 | // |
| 53 | |
| 54 | #include "qmediaplaylist.h" |
| 55 | #include "qmediaplaylistcontrol_p.h" |
| 56 | #include "qmediaplayer.h" |
| 57 | #include "qmediaplayercontrol.h" |
| 58 | #include "qmedianetworkplaylistprovider_p.h" |
| 59 | #include "qmediaobject_p.h" |
| 60 | |
| 61 | #include <QtCore/qdebug.h> |
| 62 | |
| 63 | #ifdef Q_MOC_RUN |
| 64 | # pragma Q_MOC_EXPAND_MACROS |
| 65 | #endif |
| 66 | |
| 67 | QT_BEGIN_NAMESPACE |
| 68 | |
| 69 | |
| 70 | class QMediaPlaylistControl; |
| 71 | class QMediaPlaylistProvider; |
| 72 | class QMediaPlaylistReader; |
| 73 | class QMediaPlaylistWriter; |
| 74 | class QMediaPlayerControl; |
| 75 | |
| 76 | class QMediaPlaylistPrivate |
| 77 | { |
| 78 | Q_DECLARE_PUBLIC(QMediaPlaylist) |
| 79 | public: |
| 80 | QMediaPlaylistPrivate() |
| 81 | :mediaObject(nullptr), |
| 82 | control(nullptr), |
| 83 | networkPlaylistControl(nullptr), |
| 84 | error(QMediaPlaylist::NoError) |
| 85 | { |
| 86 | } |
| 87 | |
| 88 | virtual ~QMediaPlaylistPrivate() {} |
| 89 | |
| 90 | void _q_loadFailed(QMediaPlaylist::Error error, const QString &errorString) |
| 91 | { |
| 92 | this->error = error; |
| 93 | this->errorString = errorString; |
| 94 | |
| 95 | emit q_ptr->loadFailed(); |
| 96 | } |
| 97 | |
| 98 | void _q_mediaObjectDeleted() |
| 99 | { |
| 100 | Q_Q(QMediaPlaylist); |
| 101 | mediaObject = nullptr; |
| 102 | if (control != networkPlaylistControl) |
| 103 | control = nullptr; |
| 104 | q->setMediaObject(nullptr); |
| 105 | } |
| 106 | |
| 107 | QMediaObject *mediaObject; |
| 108 | |
| 109 | QMediaPlaylistControl *control; |
| 110 | QMediaPlaylistProvider *playlist() const { return control->playlistProvider(); } |
| 111 | |
| 112 | QMediaPlaylistControl *networkPlaylistControl; |
| 113 | |
| 114 | bool readItems(QMediaPlaylistReader *reader); |
| 115 | bool writeItems(QMediaPlaylistWriter *writer); |
| 116 | |
| 117 | void syncControls(QMediaPlaylistControl *oldControl, QMediaPlaylistControl *newControl, |
| 118 | int *removedStart, int *removedEnd, |
| 119 | int *insertedStart, int *insertedEnd); |
| 120 | |
| 121 | QMediaPlaylist::Error error; |
| 122 | QString errorString; |
| 123 | |
| 124 | QMediaPlaylist *q_ptr; |
| 125 | }; |
| 126 | |
| 127 | |
| 128 | class QMediaNetworkPlaylistControl : public QMediaPlaylistControl |
| 129 | { |
| 130 | Q_OBJECT |
| 131 | public: |
| 132 | QMediaNetworkPlaylistControl(QObject *parent) |
| 133 | :QMediaPlaylistControl(parent) |
| 134 | { |
| 135 | QMediaPlaylistProvider *playlist = new QMediaNetworkPlaylistProvider(this); |
| 136 | m_navigator = new QMediaPlaylistNavigator(playlist,this); |
| 137 | m_navigator->setPlaybackMode(QMediaPlaylist::Sequential); |
| 138 | |
| 139 | connect(asender: m_navigator, SIGNAL(currentIndexChanged(int)), SIGNAL(currentIndexChanged(int))); |
| 140 | connect(asender: m_navigator, SIGNAL(activated(QMediaContent)), SIGNAL(currentMediaChanged(QMediaContent))); |
| 141 | connect(asender: m_navigator, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)), SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); |
| 142 | } |
| 143 | |
| 144 | ~QMediaNetworkPlaylistControl() {} |
| 145 | |
| 146 | QMediaPlaylistProvider* playlistProvider() const override { return m_navigator->playlist(); } |
| 147 | bool setPlaylistProvider(QMediaPlaylistProvider *mediaPlaylist) override |
| 148 | { |
| 149 | m_navigator->setPlaylist(mediaPlaylist); |
| 150 | emit playlistProviderChanged(); |
| 151 | return true; |
| 152 | } |
| 153 | |
| 154 | int currentIndex() const override { return m_navigator->currentIndex(); } |
| 155 | void setCurrentIndex(int position) override { m_navigator->jump(position); } |
| 156 | int nextIndex(int steps) const override { return m_navigator->nextIndex(steps); } |
| 157 | int previousIndex(int steps) const override { return m_navigator->previousIndex(steps); } |
| 158 | |
| 159 | void next() override { m_navigator->next(); } |
| 160 | void previous() override { m_navigator->previous(); } |
| 161 | |
| 162 | QMediaPlaylist::PlaybackMode playbackMode() const override { return m_navigator->playbackMode(); } |
| 163 | void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) override { m_navigator->setPlaybackMode(mode); } |
| 164 | |
| 165 | private: |
| 166 | QMediaPlaylistNavigator *m_navigator; |
| 167 | }; |
| 168 | |
| 169 | |
| 170 | QT_END_NAMESPACE |
| 171 | |
| 172 | |
| 173 | #endif // QMEDIAPLAYLIST_P_H |
| 174 | |