Message info
 
To:kde-commits@kde.org From:Shantanu Tushar Subject:[plasma-mediacenter/plain-containment-shantanu] /: Load backends from C++ Date:Sun, 18 Mar 2012 16:47:52 +0100 (CET)
 

Git commit 29517d7ee96a9a478b6dff564de5dbfe76651222 by Shantanu Tushar.
Committed on 11/03/2012 at 08:04.
Pushed by shantanu into branch 'plain-containment-shantanu'.

Load backends from C++
Play media
Use thumbs from metadatamodel

M +1 -2 browsingbackends/metadatabackends/abstractmetadatamodel.cpp
M +1 -1 browsingbackends/metadatabackends/metadatapicturebackend/metadatapicturemodel.cpp
M +7 -26 browsingbackends/metadatabackends/metadatavideobackend/metadatavideomodel.cpp
M +0 -3 browsingbackends/metadatabackends/metadatavideobackend/metadatavideomodel.h
M +0 -2 components/CMakeLists.txt
D +0 -25 components/backendsmodel/CMakeLists.txt
D +0 -12 components/backendsmodel/backendsmodelplugin.cpp
D +0 -15 components/backendsmodel/backendsmodelplugin.h
M +7 -2 components/mediabrowser/MediaBrowser.qml
M +32 -2 components/mediaplayer/MediaPlayer.qml
M +3 -0 components/mediawelcome/MediaWelcome.qml
M +0 -1 components/qmldir
M +2 -0 libs/mediacenter/CMakeLists.txt
R +4 -5 libs/mediacenter/backendsmodel.cpp [from: components/backendsmodel/backendsmodel.cpp - 085% similarity]
R +8 -3 libs/mediacenter/backendsmodel.h [from: components/backendsmodel/backendsmodel.h - 070% similarity]
M +2 -1 shells/newshell/CMakeLists.txt
M +6 -0 shells/newshell/mainwindow.cpp
M +6 -4 shells/newshell/package/contents/ui/mediacenter.qml

http://commits.kde.org/plasma-mediacenter/29517d7ee96a9a478b6dff564de5dbfe76651222

diff --git a/browsingbackends/metadatabackends/abstractmetadatamodel.cpp b/browsingbackends/metadatabackends/abstractmetadatamodel.cpp
index 67e3b2d..85a0def 100644
--- a/browsingbackends/metadatabackends/abstractmetadatamodel.cpp
+++ b/browsingbackends/metadatabackends/abstractmetadatamodel.cpp
@@ -140,7 +140,7 @@ QVariant AbstractMetadataModel::data (const QModelIndex& index, int role) const
return false;
}

- return QVariant();
+ return metadataModel()->data(index, role);
}

int AbstractMetadataModel::columnCount (const QModelIndex& parent) const
@@ -162,7 +162,6 @@ QModelIndex AbstractMetadataModel::parent (const QModelIndex& child) const

QModelIndex AbstractMetadataModel::index (int row, int column, const QModelIndex& parent) const
{
- Q_UNUSED(parent);
return metadataModel()->index(row, column, parent);
}

diff --git a/browsingbackends/metadatabackends/metadatapicturebackend/metadatapicturemodel.cpp b/browsingbackends/metadatabackends/metadatapicturebackend/metadatapicturemodel.cpp
index 75284d2..4df94c6 100644
--- a/browsingbackends/metadatabackends/metadatapicturebackend/metadatapicturemodel.cpp
+++ b/browsingbackends/metadatabackends/metadatapicturebackend/metadatapicturemodel.cpp
@@ -32,7 +32,7 @@ MetadataPictureModel::MetadataPictureModel (QObject* parent)
resetMetadataModel();
metadataModel()->setProperty("resourceType", "nfo:Image");
metadataModel()->setProperty("mimeType", "");
- metadataModel()->setProperty("limit", 500);
+ metadataModel()->setProperty("limit", 50);
}
else {
kDebug() << "WARNING: Constructor called before metadataModel set :/";
diff --git a/browsingbackends/metadatabackends/metadatavideobackend/metadatavideomodel.cpp b/browsingbackends/metadatabackends/metadatavideobackend/metadatavideomodel.cpp
index b9a011d..397613c 100644
--- a/browsingbackends/metadatabackends/metadatavideobackend/metadatavideomodel.cpp
+++ b/browsingbackends/metadatabackends/metadatavideobackend/metadatavideomodel.cpp
@@ -24,7 +24,8 @@
#include <mediacenter/mediacenter.h>
#include <mediacenter/abstractbrowsingbackend.h>

-#include <KUrl>
+#include <KDebug>
+#include <KDE/KUrl>

#include <QtGui/QIcon>
#include <QtCore/QEvent>
@@ -33,10 +34,7 @@
class MetadataVideoModel::Private
{
public:
- Private()
- : thumbProvider(new MetadataVideoThumbnailProvider(QDeclarativeImageProvider::Pixmap)) {
- }
- MetadataVideoThumbnailProvider* thumbProvider;
+ int thumbnailKey;
};

MetadataVideoModel::MetadataVideoModel(QObject* parent)
@@ -44,17 +42,14 @@ MetadataVideoModel::MetadataVideoModel(QObject* parent)
, d(new Private())
{
if(metadataModel()) {
+ d->thumbnailKey = metadataModel()->roleNames().key("thumbnail");
resetMetadataModel();
metadataModel()->setProperty("resourceType", "nfo:FileDataObject");
metadataModel()->setProperty("mimeType", "video");
- metadataModel()->setProperty("limit", 500);
+ metadataModel()->setProperty("limit", 4);
} else {
kDebug() << "WARNING: Constructor called before metadataModel set :/";
}
-
- connect(d->thumbProvider, SIGNAL(gotThumbnail(QString)), SLOT(gotThumbnail(QString)));
- /*qobject_cast<MediaCenter::AbstractBrowsingBackend*>(parent)->declarativeEngine()->addImageProvider(QLatin1String("metadatavideothumb"),
- d->thumbProvider);*/
}

MetadataVideoModel::~MetadataVideoModel()
@@ -62,15 +57,6 @@ MetadataVideoModel::~MetadataVideoModel()
delete d;
}

-void MetadataVideoModel::gotThumbnail(const QString& url)
-{
- for(int i = 0; i < rowCount(); ++i) {
- if(data(index(i, 0), MediaCenter::MediaUrlRole).toUrl() == QUrl(url)) {
- emit dataChanged(index(i, 0), index(i, 0));
- }
- }
-}
-
QVariant MetadataVideoModel::data(const QModelIndex& index, int role) const
{
if(!metadataModel()) {
@@ -80,13 +66,8 @@ QVariant MetadataVideoModel::data(const QModelIndex& index, int role) const
switch (role) {
case MediaCenter::MediaTypeRole:
return "video";
- case Qt::DecorationRole: {
- QString url = data(index, MediaCenter::MediaUrlRole).toUrl().toString();
- if (d->thumbProvider->hasThumbnail(url)) {
- return QString("image://metadatavideothumb/") + url;
- }
- d->thumbProvider->loadThumbnail(KUrl(url), QSize(256, 256));
- }
+ case Qt::DecorationRole:
+ return AbstractMetadataModel::data(index, d->thumbnailKey);
default:
return AbstractMetadataModel::data(index, role);
}
diff --git a/browsingbackends/metadatabackends/metadatavideobackend/metadatavideomodel.h b/browsingbackends/metadatabackends/metadatavideobackend/metadatavideomodel.h
index 89129ac..c13e1e3 100644
--- a/browsingbackends/metadatabackends/metadatavideobackend/metadatavideomodel.h
+++ b/browsingbackends/metadatabackends/metadatavideobackend/metadatavideomodel.h
@@ -33,9 +33,6 @@ public:

virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;

-private slots:
- void gotThumbnail(const QString& url);
-
private:
class Private;
Private* const d;
diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt
index 4a88415..c02d270 100644
--- a/components/CMakeLists.txt
+++ b/components/CMakeLists.txt
@@ -1,5 +1,3 @@
-add_subdirectory(backendsmodel)
-
install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/mediacentercomponents)
install(DIRECTORY mediabrowser DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/mediacentercomponents)
install(DIRECTORY mediacontroller DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/mediacentercomponents)
diff --git a/components/backendsmodel/CMakeLists.txt b/components/backendsmodel/CMakeLists.txt
deleted file mode 100644
index 0150e94..0000000
--- a/components/backendsmodel/CMakeLists.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-project(backendsmodel)
-include(KDE4Defaults)
-
-include_directories(
- ${CMAKE_SOURCE_DIR}
- ${CMAKE_BINARY_DIR}
- ${KDE4_INCLUDES}
-)
-
-set(backendsmodel_SRCS
- backendsmodel.cpp
- backendsmodelplugin.cpp
-)
-
-qt4_automoc(${backendsmodel_SRCS})
-kde4_add_library(backendsmodelplugin SHARED ${backendsmodel_SRCS})
-
-target_link_libraries(backendsmodelplugin
- ${QT_QTCORE_LIBRARY}
- ${QT_QTDECLARATIVE_LIBRARY}
- ${KDE4_KDECORE_LIBRARY}
- mediacenterlibs
-)
-
-install(TARGETS backendsmodelplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/mediacentercomponents/backendsmodelplugin/)
diff --git a/components/backendsmodel/backendsmodelplugin.cpp b/components/backendsmodel/backendsmodelplugin.cpp
deleted file mode 100644
index ba33f02..0000000
--- a/components/backendsmodel/backendsmodelplugin.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "backendsmodelplugin.h"
-
-#include "backendsmodel.h"
-
-#include <QtDeclarative/qdeclarative.h>
-
-void BackendsModelPlugin::registerTypes (const char* uri)
-{
- qmlRegisterType<BackendsModel>(uri, 0, 1, "BackendsModel");
-}
-
-#include "backendsmodelplugin.moc"
diff --git a/components/backendsmodel/backendsmodelplugin.h b/components/backendsmodel/backendsmodelplugin.h
deleted file mode 100644
index f44700f..0000000
--- a/components/backendsmodel/backendsmodelplugin.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef BACKENDSMODELPLUGIN_H
-#define BACKENDSMODELPLUGIN_H
-
-#include <QtDeclarative/QDeclarativeExtensionPlugin>
-
-class BackendsModelPlugin : public QDeclarativeExtensionPlugin
-{
- Q_OBJECT
-public:
- virtual void registerTypes (const char* uri);
-};
-
-Q_EXPORT_PLUGIN2(backendsmodelplugin, BackendsModelPlugin)
-
-#endif // BACKENDSMODELPLUGIN_H
diff --git a/components/mediabrowser/MediaBrowser.qml b/components/mediabrowser/MediaBrowser.qml
index ad59f33..ac30769 100644
--- a/components/mediabrowser/MediaBrowser.qml
+++ b/components/mediabrowser/MediaBrowser.qml
@@ -26,6 +26,8 @@ Item {
clip: true
property QtObject currentBrowsingBackend

+ signal playRequested(string url)
+
MetadataModels.MetadataModel
{
id: metadataModel
@@ -36,9 +38,12 @@ Item {
anchors.fill: parent
cellWidth: width / 5
cellHeight: width / 6
- delegate: MediaItemDelegate {}
+ delegate: MediaItemDelegate {
+ backend: currentBrowsingBackend
+ onPlayRequested: mediaBrowser.playRequested(url)
+ }
highlight: MediaItemHighlight {}
- focus: true
+ //focus: true
highlightFollowsCurrentItem: true
flow: GridView.TopToBottom
cacheBuffer: width*10
diff --git a/components/mediaplayer/MediaPlayer.qml b/components/mediaplayer/MediaPlayer.qml
index 5af28e9..178fb89 100644
--- a/components/mediaplayer/MediaPlayer.qml
+++ b/components/mediaplayer/MediaPlayer.qml
@@ -1,5 +1,35 @@
import QtQuick 1.1
+import Phonon 1.0 as Phonon

-Text {
- text: "hello world"
+Rectangle {
+ id: mediaPlayerRootRect
+ color: "black"
+
+ property alias url: video.source
+
+ Phonon.Media {
+ id: video
+ anchors.fill: parent
+
+ Phonon.AudioOutput {
+ id: audioPlayer
+ anchors.fill: parent
+ }
+
+ Phonon.Video {
+ id: videoPlayer
+ anchors.fill: parent
+ }
+
+ onTotalTimeChanged: {
+ }
+
+ onTimeChanged: {
+ }
+ }
+
+ function play()
+ {
+ video.play();
+ }
}
diff --git a/components/mediawelcome/MediaWelcome.qml b/components/mediawelcome/MediaWelcome.qml
index 5cee49b..bf351be 100644
--- a/components/mediawelcome/MediaWelcome.qml
+++ b/components/mediawelcome/MediaWelcome.qml
@@ -74,4 +74,7 @@ PathView {
PathQuad { x: view.width; y: 10; controlX: view.width*3/4; controlY: view.height/4 }
PathAttribute { name: "iconScale"; value: 0.1 }
}
+
+ Keys.onLeftPressed: decrementCurrentIndex()
+ Keys.onRightPressed: incrementCurrentIndex()
}
diff --git a/components/qmldir b/components/qmldir
index 646927b..6bf9441 100644
--- a/components/qmldir
+++ b/components/qmldir
@@ -4,4 +4,3 @@ MediaInfoBar 0.1 mediainfobar/MediaInfoBar.qml
MediaPlayer 0.1 mediaplayer/MediaPlayer.qml
MediaWelcome 0.1 mediawelcome/MediaWelcome.qml
RuntimeData 0.1 runtimedata/RuntimeData.qml
-plugin backendsmodelplugin backendsmodelplugin/
diff --git a/libs/mediacenter/CMakeLists.txt b/libs/mediacenter/CMakeLists.txt
index d9efe56..6138007 100644
--- a/libs/mediacenter/CMakeLists.txt
+++ b/libs/mediacenter/CMakeLists.txt
@@ -8,6 +8,7 @@ playlist.cpp
mediacenter.cpp
abstractbrowsingbackend.cpp
homeapplet.cpp
+backendsmodel.cpp

# widgets
widgets/navigationtoolbar.cpp
@@ -29,6 +30,7 @@ set (mediacenterlibs_HDRS
browsergesture.h
abstractbrowsingbackend.h
homeapplet.h
+ backendsmodel.h
)

set (mediacenterlibs_WIDGETS_HDRS
diff --git a/components/backendsmodel/backendsmodel.cpp b/libs/mediacenter/backendsmodel.cpp
similarity index 85%
rename from components/backendsmodel/backendsmodel.cpp
rename to libs/mediacenter/backendsmodel.cpp
index fc8ad5b..093bc0d 100644
--- a/components/backendsmodel/backendsmodel.cpp
+++ b/libs/mediacenter/backendsmodel.cpp
@@ -4,7 +4,7 @@

#include <KDebug>

-BackendsModel::BackendsModel (QObject* parent) : QAbstractListModel (parent)
+BackendsModel::BackendsModel (QDeclarativeEngine* engine, QObject* parent) : QAbstractListModel (parent)
{
MediaCenter::AbstractBrowsingBackend *backend;
KSharedPtr<KService> service;
@@ -14,7 +14,7 @@ BackendsModel::BackendsModel (QObject* parent) : QAbstractListModel (parent)
for (int i=0; i<list.size(); ++i) {
service = list.at(i);
backend = service->createInstance<MediaCenter::AbstractBrowsingBackend>(0, QVariantList() << service->storageId());
- loadBrowsingBackend(backend);
+ loadBrowsingBackend(backend, engine);
}

QHash<int, QByteArray> roles = roleNames();
@@ -22,13 +22,14 @@ BackendsModel::BackendsModel (QObject* parent) : QAbstractListModel (parent)
setRoleNames(roles);
}

-bool BackendsModel::loadBrowsingBackend(MediaCenter::AbstractBrowsingBackend *backend)
+bool BackendsModel::loadBrowsingBackend(MediaCenter::AbstractBrowsingBackend* backend, QDeclarativeEngine* engine)
{
if (!backend) {
kDebug() << "OUCH! Something's wrong with the backend";
return false;
}
backend->setParent(this);
+ backend->setDeclarativeEngine(engine);
backends.append(backend);
return true;
}
@@ -59,5 +60,3 @@ int BackendsModel::rowCount (const QModelIndex& parent) const
}

#include "backendsmodel.moc"
-
-
diff --git a/components/backendsmodel/backendsmodel.h b/libs/mediacenter/backendsmodel.h
similarity index 70%
rename from components/backendsmodel/backendsmodel.h
rename to libs/mediacenter/backendsmodel.h
index 5d06188..824596e 100644
--- a/components/backendsmodel/backendsmodel.h
+++ b/libs/mediacenter/backendsmodel.h
@@ -1,25 +1,30 @@
#ifndef BACKENDSMODEL_H
#define BACKENDSMODEL_H

+#include "mediacenter_export.h"
+
#include <QAbstractItemModel>

+class QDeclarativeEngine;
+
namespace MediaCenter {
class AbstractBrowsingBackend;
}

-class BackendsModel : public QAbstractListModel
+class MEDIACENTER_EXPORT BackendsModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles {
ModelObjectRole = Qt::UserRole + 1
};
- explicit BackendsModel (QObject* parent = 0);
+
+ BackendsModel (QDeclarativeEngine *engine, QObject* parent = 0);
virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual int rowCount (const QModelIndex& parent = QModelIndex()) const;

private:
- bool loadBrowsingBackend(MediaCenter::AbstractBrowsingBackend *backend);
+ bool loadBrowsingBackend(MediaCenter::AbstractBrowsingBackend *backend, QDeclarativeEngine *engine);

QList<MediaCenter::AbstractBrowsingBackend*> backends;
};
diff --git a/shells/newshell/CMakeLists.txt b/shells/newshell/CMakeLists.txt
index fde8e0a..619bc93 100644
--- a/shells/newshell/CMakeLists.txt
+++ b/shells/newshell/CMakeLists.txt
@@ -12,7 +12,8 @@ set(plasma-mediacenter_SRCS
)

kde4_add_executable(plasma-mediacenter-new ${plasma-mediacenter_SRCS})
-target_link_libraries(plasma-mediacenter-new mediacenterlibs
+target_link_libraries(plasma-mediacenter-new
+ mediacenterlibs
${KDE4_KDEUI_LIBS}
${KDE4_PLASMA_LIBS}
${KDE4_KIO_LIBS}
diff --git a/shells/newshell/mainwindow.cpp b/shells/newshell/mainwindow.cpp
index 45925f8..cc34c1d 100644
--- a/shells/newshell/mainwindow.cpp
+++ b/shells/newshell/mainwindow.cpp
@@ -19,11 +19,14 @@

#include "mainwindow.h"

+#include <libs/mediacenter/backendsmodel.h>
+
#include <Plasma/Package>

#include <KDE/KCmdLineArgs>

#include <QtDeclarative/QDeclarativeView>
+#include <QtDeclarative/QDeclarativeContext>
#include <QtOpenGL/QGLWidget>
#include <QDebug>

@@ -53,6 +56,9 @@ MainWindow::MainWindow(QWidget *parent) : KMainWindow(parent)
m_kdeclarative.initialize();
m_kdeclarative.setupBindings();

+ BackendsModel *backendsModel = new BackendsModel(view->engine(), this);
+ view->rootContext()->setContextProperty("backendsModel", backendsModel);
+
m_structure = Plasma::PackageStructure::load("Plasma/Generic");
Plasma::Package *package = new Plasma::Package(QString(), "org.kde.plasma.mediacenter", m_structure);
view->setSource(QUrl(package->filePath("mainscript")));
diff --git a/shells/newshell/package/contents/ui/mediacenter.qml b/shells/newshell/package/contents/ui/mediacenter.qml
index 8d102c8..c5d7133 100644
--- a/shells/newshell/package/contents/ui/mediacenter.qml
+++ b/shells/newshell/package/contents/ui/mediacenter.qml
@@ -10,14 +10,11 @@ Rectangle {
}

MediaCenterComponents.MediaPlayer {
+ id: mediaPlayer
anchors.fill: parent
z: -1
}

- MediaCenterComponents.BackendsModel {
- id: backendsModel
- }
-
MediaCenterComponents.RuntimeData {
id: runtimeData
}
@@ -50,6 +47,11 @@ Rectangle {

currentBrowsingBackend: runtimeData.currentBrowsingBackend
onCurrentBrowsingBackendChanged: visible = true
+ onPlayRequested: {
+ mediaPlayer.url = url
+ mediaPlayer.play()
+ mediaPlayer.z = 2
+ }
}

MediaCenterComponents.MediaInfoBar {