| 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 test suite of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 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 General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 | |
| 29 | #ifndef MOCKMEDIAPLAYLISTCONTROL_H | 
| 30 | #define MOCKMEDIAPLAYLISTCONTROL_H | 
| 31 | |
| 32 | #include <private/qmediaplaylistcontrol_p.h> | 
| 33 | #include <private/qmediaplaylistnavigator_p.h> | 
| 34 | #include <private/qmedianetworkplaylistprovider_p.h> | 
| 35 | |
| 36 | #include "mockreadonlyplaylistprovider.h" | 
| 37 | |
| 38 | class MockMediaPlaylistControl : public QMediaPlaylistControl | 
| 39 | { | 
| 40 | public: | 
| 41 | MockMediaPlaylistControl(bool readonly = false, QObject *parent = 0) | 
| 42 | : QMediaPlaylistControl(parent) | 
| 43 | , m_navigator(0) | 
| 44 | , m_playlist(0) | 
| 45 | , m_ownsProvider(false) | 
| 46 | , m_readOnly(readonly) | 
| 47 | { | 
| 48 | reset(); | 
| 49 | } | 
| 50 | |
| 51 | ~MockMediaPlaylistControl() | 
| 52 | { | 
| 53 | } | 
| 54 | |
| 55 | void reset() | 
| 56 | { | 
| 57 | delete m_navigator; | 
| 58 | if (m_ownsProvider) | 
| 59 | delete m_playlist; | 
| 60 | |
| 61 | if (m_readOnly) | 
| 62 | m_playlist = new MockReadOnlyPlaylistProvider(this); | 
| 63 | else | 
| 64 | m_playlist = new QMediaNetworkPlaylistProvider(this); | 
| 65 | |
| 66 | m_ownsProvider = true; | 
| 67 | m_navigator = new QMediaPlaylistNavigator(m_playlist, this); | 
| 68 | } | 
| 69 | |
| 70 | void setReadOnly(bool ro) | 
| 71 | { | 
| 72 | if (m_readOnly == ro) | 
| 73 | return; | 
| 74 | |
| 75 | m_readOnly = ro; | 
| 76 | reset(); | 
| 77 | } | 
| 78 | |
| 79 | QMediaPlaylistProvider* playlistProvider() const { return m_playlist; } | 
| 80 | bool setPlaylistProvider(QMediaPlaylistProvider *newProvider) | 
| 81 | { | 
| 82 | bool bMediaContentChanged = false; | 
| 83 | int i = 0; | 
| 84 | for (; i < playlistProvider()->mediaCount(); i++) { | 
| 85 | if (playlistProvider()->media(index: i).request().url().toString() | 
| 86 | != newProvider->media(index: i).request().url().toString()) { | 
| 87 | bMediaContentChanged = true; | 
| 88 | break; | 
| 89 | } | 
| 90 | } | 
| 91 | |
| 92 | if (playlistProvider()->mediaCount() != newProvider->mediaCount() || bMediaContentChanged ) { | 
| 93 | emit playlistProviderChanged(); | 
| 94 | emit currentMediaChanged(newProvider->media(index: i)); | 
| 95 | } | 
| 96 | |
| 97 | if (m_ownsProvider) | 
| 98 | delete m_playlist; | 
| 99 | m_playlist = newProvider; | 
| 100 | m_ownsProvider = false; | 
| 101 | |
| 102 | m_navigator->setPlaylist(newProvider); | 
| 103 | return true; | 
| 104 | } | 
| 105 | |
| 106 | int currentIndex() const { return m_navigator->currentIndex(); } | 
| 107 | void setCurrentIndex(int position) | 
| 108 | { | 
| 109 | if (position != currentIndex()) | 
| 110 | emit currentIndexChanged(position); | 
| 111 | m_navigator->jump(position); | 
| 112 | } | 
| 113 | |
| 114 | int nextIndex(int steps) const { return m_navigator->nextIndex(steps); } | 
| 115 | int previousIndex(int steps) const { return m_navigator->previousIndex(steps); } | 
| 116 | |
| 117 | void next() { m_navigator->next(); } | 
| 118 | void previous() { m_navigator->previous(); } | 
| 119 | |
| 120 | QMediaPlaylist::PlaybackMode playbackMode() const { return m_navigator->playbackMode(); } | 
| 121 | void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) | 
| 122 | { | 
| 123 | if (playbackMode() != mode) | 
| 124 | emit playbackModeChanged(mode); | 
| 125 | |
| 126 | m_navigator->setPlaybackMode(mode); | 
| 127 | } | 
| 128 | |
| 129 | private: | 
| 130 | QMediaPlaylistNavigator *m_navigator; | 
| 131 | QMediaPlaylistProvider *m_playlist; | 
| 132 | bool m_ownsProvider; | 
| 133 | bool m_readOnly; | 
| 134 | }; | 
| 135 | |
| 136 | #endif // MOCKMEDIAPLAYLISTCONTROL_H | 
| 137 | 
