on a628251 help sign in
unity8/tests/mocks/QtMultimedia/declarativeplaylist.cpp
73 lines 1.7 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
18#include "declarativeplaylist.h"
20DeclarativePlaylist::DeclarativePlaylist(QObject *parent)
21 : QObject(parent)
22 , m_currentIndex(-1)
26QUrl DeclarativePlaylist::currentItemSource() const
28 return itemSource(currentIndex());
31int DeclarativePlaylist::currentIndex() const
33 return m_currentIndex;
36void DeclarativePlaylist::setCurrentIndex(int index)
38 if (currentIndex() == index)
39 return;
41 m_currentIndex = index;
42 Q_EMIT currentIndexChanged();
43 Q_EMIT currentItemSourceChanged();
46QUrl DeclarativePlaylist::itemSource(int index) const
48 if (index < 0 || index >= m_medias.count())
49 return QUrl();
50 return m_medias[index];
53bool DeclarativePlaylist::addItem(const QUrl &source)
55 m_medias << source;
56 setCurrentIndex(0);
57 return true;
60bool DeclarativePlaylist::addItems(const QList<QUrl> &sources)
62 m_medias << sources;
63 if (!sources.isEmpty())
64 setCurrentIndex(0);
65 return true;
68bool DeclarativePlaylist::clear()
70 m_medias.clear();
71 setCurrentIndex(-1);
72 return true;