diff --git a/browsingbackends/metadatabackends/abstractmetadatamodel.cpp b/browsingbackends/metadatabackends/abstractmetadatamodel.cpp index 579d5144..67e3b2d9 100644 --- a/browsingbackends/metadatabackends/abstractmetadatamodel.cpp +++ b/browsingbackends/metadatabackends/abstractmetadatamodel.cpp @@ -1,283 +1,279 @@ /*************************************************************************** * Copyright 2011 Sinny Kumari * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "abstractmetadatamodel.h" #include #include #include #include #include class AbstractMetadataModel::Private { public: Private() { model = 0; } QAbstractItemModel* model; int labelKey; int iconKey; int urlKey; }; AbstractMetadataModel::AbstractMetadataModel (QObject* parent) : QAbstractItemModel (parent) , d (new Private()) { if (metadataModel()) { setSourceModel(metadataModel()); } setRoleNames(MediaCenter::appendAdditionalMediaRoles(roleNames())); } AbstractMetadataModel::~AbstractMetadataModel() { delete d; } QAbstractItemModel* AbstractMetadataModel::sourceModel() const { return d->model; } void AbstractMetadataModel::setSourceModel (QAbstractItemModel* newSourceModel) { if (sourceModel()) { disconnect (sourceModel(), SIGNAL (columnsAboutToBeInserted (QModelIndex, int, int))); disconnect (sourceModel(), SIGNAL (columnsAboutToBeMoved (QModelIndex, int, int, QModelIndex, int))); disconnect (sourceModel(), SIGNAL (columnsAboutToBeRemoved (QModelIndex, int, int))); disconnect (sourceModel(), SIGNAL (columnsInserted (QModelIndex, int, int))); disconnect (sourceModel(), SIGNAL (columnsMoved (QModelIndex, int, int, QModelIndex, int))); disconnect (sourceModel(), SIGNAL (columnsRemoved (QModelIndex, int, int))); disconnect (sourceModel(), SIGNAL (dataChanged (QModelIndex, QModelIndex))); disconnect (sourceModel(), SIGNAL (headerDataChanged (Qt::Orientation, int, int))); disconnect (sourceModel(), SIGNAL (layoutAboutToBeChanged ())); disconnect (sourceModel(), SIGNAL (layoutChanged ())); disconnect (sourceModel(), SIGNAL (modelAboutToBeReset())); disconnect (sourceModel(), SIGNAL (modelReset ())); disconnect (sourceModel(), SIGNAL (rowsAboutToBeInserted (QModelIndex, int, int))); disconnect (sourceModel(), SIGNAL (rowsAboutToBeMoved (QModelIndex, int, int, QModelIndex, int))); disconnect (sourceModel(), SIGNAL (rowsAboutToBeRemoved (QModelIndex, int, int))); disconnect (sourceModel(), SIGNAL (rowsInserted (QModelIndex, int, int))); disconnect (sourceModel(), SIGNAL (rowsMoved (QModelIndex, int, int, QModelIndex, int))); disconnect (sourceModel(), SIGNAL (rowsRemoved (QModelIndex, int, int))); } d->model = newSourceModel; if (sourceModel()) { connect (sourceModel(), SIGNAL (columnsAboutToBeInserted (QModelIndex, int, int)), SLOT (sourceColumnsAboutToBeInserted (QModelIndex, int, int))); connect (sourceModel(), SIGNAL (columnsAboutToBeMoved (QModelIndex, int, int, QModelIndex, int)), SLOT (sourceColumnsAboutToBeMoved (QModelIndex, int, int, QModelIndex, int))); connect (sourceModel(), SIGNAL (columnsAboutToBeRemoved (QModelIndex, int, int)), SLOT (sourceColumnsAboutToBeRemoved (QModelIndex, int, int))); connect (sourceModel(), SIGNAL (columnsInserted (QModelIndex, int, int)), SLOT (sourceColumnsInserted (QModelIndex, int, int))); connect (sourceModel(), SIGNAL (columnsMoved (QModelIndex, int, int, QModelIndex, int)), SLOT (sourceColumnsMoved (QModelIndex, int, int, QModelIndex, int))); connect (sourceModel(), SIGNAL (columnsRemoved (QModelIndex, int, int)), SLOT (sourceColumnsRemoved (QModelIndex, int, int))); connect (sourceModel(), SIGNAL (dataChanged (QModelIndex, QModelIndex)), SLOT (sourceDataChanged (QModelIndex, QModelIndex))); connect (sourceModel(), SIGNAL (headerDataChanged (Qt::Orientation, int, int)), SLOT (sourceHeaderDataChanged (Qt::Orientation, int, int))); connect (sourceModel(), SIGNAL (layoutAboutToBeChanged ()), SLOT (sourceLayoutAboutToBeChanged ())); connect (sourceModel(), SIGNAL (layoutChanged ()), SLOT (sourceLayoutChanged ())); connect (sourceModel(), SIGNAL (modelAboutToBeReset()), SLOT (sourceModelAboutToBeReset ())); connect (sourceModel(), SIGNAL (modelReset ()), SLOT (sourceModelReset ())); connect (sourceModel(), SIGNAL (rowsAboutToBeInserted (QModelIndex, int, int)), SLOT (sourceRowsAboutToBeInserted (QModelIndex, int, int))); connect (sourceModel(), SIGNAL (rowsAboutToBeMoved (QModelIndex, int, int, QModelIndex, int)), SLOT (sourceRowsAboutToBeMoved (QModelIndex, int, int, QModelIndex, int))); connect (sourceModel(), SIGNAL (rowsAboutToBeRemoved (QModelIndex, int, int)), SLOT (sourceRowsAboutToBeRemoved (QModelIndex, int, int))); connect (sourceModel(), SIGNAL (rowsInserted (QModelIndex, int, int)), SLOT (sourceRowsInserted (QModelIndex, int, int))); connect (sourceModel(), SIGNAL (rowsMoved (QModelIndex, int, int, QModelIndex, int)), SLOT (sourceRowsMoved (QModelIndex, int, int, QModelIndex, int))); connect (sourceModel(), SIGNAL (rowsRemoved (QModelIndex, int, int)), SLOT (sourceRowsRemoved (QModelIndex, int, int))); d->labelKey = metadataModel()->roleNames().key("label"); d->iconKey = metadataModel()->roleNames().key("icon"); d->urlKey = metadataModel()->roleNames().key("url"); } } QVariant AbstractMetadataModel::data (const QModelIndex& index, int role) const { if (!metadataModel()) return QVariant(); switch (role) { case Qt::DisplayRole: return metadataModel()->data(index, d->labelKey); - break; case Qt::DecorationRole: return metadataModel()->data(index, d->iconKey); - break; case MediaCenter::MediaUrlRole: return metadataModel()->data(index, d->urlKey); - break; case MediaCenter::IsExpandableRole: return false; - break; } return QVariant(); } int AbstractMetadataModel::columnCount (const QModelIndex& parent) const { return 1; } int AbstractMetadataModel::rowCount (const QModelIndex& parent) const { if (!metadataModel()) return 0; return metadataModel()->rowCount(parent); } QModelIndex AbstractMetadataModel::parent (const QModelIndex& child) const { return QModelIndex(); } QModelIndex AbstractMetadataModel::index (int row, int column, const QModelIndex& parent) const { Q_UNUSED(parent); return metadataModel()->index(row, column, parent); } QAbstractItemModel* AbstractMetadataModel::metadataModel() const { MediaCenter::AbstractBrowsingBackend *backend = static_cast(QObject::parent()); return static_cast(backend->metadataModel()); } void AbstractMetadataModel::sourceColumnsAboutToBeInserted ( const QModelIndex & parent, int start, int end ) { beginInsertColumns(parent, start, end); } void AbstractMetadataModel::sourceColumnsAboutToBeMoved ( const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationColumn ) { beginMoveColumns(sourceParent, sourceStart, sourceEnd, destinationParent, destinationColumn); } void AbstractMetadataModel::sourceColumnsAboutToBeRemoved ( const QModelIndex & parent, int start, int end ) { beginRemoveColumns(parent, start, end); } void AbstractMetadataModel::sourceColumnsInserted ( const QModelIndex & parent, int start, int end ) { insertColumns(start, end, parent); } void AbstractMetadataModel::sourceColumnsMoved ( const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationColumn ) { endMoveColumns(); } void AbstractMetadataModel::sourceColumnsRemoved ( const QModelIndex & parent, int start, int end ) { removeColumns(start, end, parent); } void AbstractMetadataModel::sourceDataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) { emit dataChanged(topLeft, bottomRight); } void AbstractMetadataModel::sourceHeaderDataChanged ( Qt::Orientation orientation, int first, int last ) { emit headerDataChanged(orientation, first, last); } void AbstractMetadataModel::sourceLayoutAboutToBeChanged () { emit layoutAboutToBeChanged(); } void AbstractMetadataModel::sourceLayoutChanged () { emit layoutChanged(); } void AbstractMetadataModel::sourceModelAboutToBeReset () { beginResetModel(); } void AbstractMetadataModel::sourceModelReset () { reset(); } void AbstractMetadataModel::sourceRowsAboutToBeInserted ( const QModelIndex & parent, int start, int end ) { beginInsertRows(parent, start, end); } void AbstractMetadataModel::sourceRowsAboutToBeMoved ( const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationRow ) { beginMoveRows(sourceParent, sourceStart, sourceEnd, destinationParent, destinationRow); } void AbstractMetadataModel::sourceRowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end ) { beginRemoveRows(parent, start, end); } void AbstractMetadataModel::sourceRowsInserted ( const QModelIndex & parent, int start, int end ) { endInsertRows(); } void AbstractMetadataModel::sourceRowsMoved ( const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationRow ) { endMoveRows(); } void AbstractMetadataModel::sourceRowsRemoved ( const QModelIndex & parent, int start, int end ) { removeRows(start, end, parent); } void AbstractMetadataModel::resetMetadataModel() { QDeclarativePropertyMap *map = qobject_cast(metadataModel()->property("extraParameters").value()); metadataModel()->setProperty("resourceType", ""); metadataModel()->setProperty("mimeType", ""); metadataModel()->setProperty("limit", ""); Q_FOREACH(const QString &key, map->keys()) { map->clear(key); } } #include "abstractmetadatamodel.moc" diff --git a/browsingbackends/metadatabackends/metadatapicturebackend/metadatapicturemodel.cpp b/browsingbackends/metadatabackends/metadatapicturebackend/metadatapicturemodel.cpp index 4128af23..75284d25 100644 --- a/browsingbackends/metadatabackends/metadatapicturebackend/metadatapicturemodel.cpp +++ b/browsingbackends/metadatabackends/metadatapicturebackend/metadatapicturemodel.cpp @@ -1,66 +1,65 @@ /*************************************************************************** * Copyright 2011 Sinny Kumari * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "metadatapicturemodel.h" #include #include #include #include - MetadataPictureModel::MetadataPictureModel (QObject* parent) : AbstractMetadataModel (parent) { if (metadataModel()) { resetMetadataModel(); metadataModel()->setProperty("resourceType", "nfo:Image"); metadataModel()->setProperty("mimeType", ""); metadataModel()->setProperty("limit", 500); } else { kDebug() << "WARNING: Constructor called before metadataModel set :/"; } } MetadataPictureModel::~MetadataPictureModel() { } QVariant MetadataPictureModel::data (const QModelIndex& index, int role) const { if (!metadataModel()) { return QVariant(); } - if (role == Qt::DecorationRole) { + if (role == Qt::DecorationRole) { if (!MetadataPictureModel::data(index, MediaCenter::IsExpandableRole).toBool()) return AbstractMetadataModel::data (index, MediaCenter::MediaUrlRole); } if(role == MediaCenter::MediaTypeRole) { return "image"; } else { return AbstractMetadataModel::data(index, role); } } #include "metadatapicturemodel.moc" diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 9aae83ba..4a884152 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -1,8 +1,9 @@ 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) install(DIRECTORY mediainfobar DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/mediacentercomponents) install(DIRECTORY mediaplayer DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/mediacentercomponents) install(DIRECTORY mediawelcome DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/mediacentercomponents) +install(DIRECTORY runtimedata DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/mediacentercomponents) diff --git a/components/backendsmodel/backendsmodel.cpp b/components/backendsmodel/backendsmodel.cpp index b2d07e0e..fc8ad5b8 100644 --- a/components/backendsmodel/backendsmodel.cpp +++ b/components/backendsmodel/backendsmodel.cpp @@ -1,55 +1,63 @@ #include "backendsmodel.h" #include #include BackendsModel::BackendsModel (QObject* parent) : QAbstractListModel (parent) { MediaCenter::AbstractBrowsingBackend *backend; KSharedPtr service; KService::List list = MediaCenter::AbstractBrowsingBackend::availableBackends(); for (int i=0; icreateInstance(0, QVariantList() << service->storageId()); loadBrowsingBackend(backend); } + + QHash roles = roleNames(); + roles[ModelObjectRole] = "modelObject"; + setRoleNames(roles); } bool BackendsModel::loadBrowsingBackend(MediaCenter::AbstractBrowsingBackend *backend) { if (!backend) { kDebug() << "OUCH! Something's wrong with the backend"; return false; } backend->setParent(this); backends.append(backend); return true; } QVariant BackendsModel::data (const QModelIndex& index, int role) const { if (index.row() >= rowCount()) { return QVariant(); } switch (role) { case Qt::DisplayRole: return backends.at(index.row())->name(); case Qt::DecorationRole: return backends.at(index.row())->icon(); + case ModelObjectRole: + QVariant ptr; + ptr.setValue(qobject_cast(backends.at(index.row()))); + return ptr; } return QVariant(); } int BackendsModel::rowCount (const QModelIndex& parent) const { return backends.count(); } #include "backendsmodel.moc" diff --git a/components/backendsmodel/backendsmodel.h b/components/backendsmodel/backendsmodel.h index 8f4050cc..5d061888 100644 --- a/components/backendsmodel/backendsmodel.h +++ b/components/backendsmodel/backendsmodel.h @@ -1,24 +1,27 @@ #ifndef BACKENDSMODEL_H #define BACKENDSMODEL_H #include namespace MediaCenter { class AbstractBrowsingBackend; } class BackendsModel : public QAbstractListModel { Q_OBJECT public: + enum Roles { + ModelObjectRole = Qt::UserRole + 1 + }; explicit BackendsModel (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); QList backends; }; #endif // BACKENDSMODEL_H diff --git a/components/mediabrowser/MediaBrowser.qml b/components/mediabrowser/MediaBrowser.qml index 5af28e96..ad59f33f 100644 --- a/components/mediabrowser/MediaBrowser.qml +++ b/components/mediabrowser/MediaBrowser.qml @@ -1,5 +1,53 @@ +/* + * Copyright 2011 Sinny Kumari + * Copyright 2010 Lukas Appelhans + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + import QtQuick 1.1 +import org.kde.metadatamodels 0.1 as MetadataModels + +Item { + id: mediaBrowser + clip: true + property QtObject currentBrowsingBackend + + MetadataModels.MetadataModel + { + id: metadataModel + } + + GridView { + id: mediaBrowserGridView + anchors.fill: parent + cellWidth: width / 5 + cellHeight: width / 6 + delegate: MediaItemDelegate {} + highlight: MediaItemHighlight {} + focus: true + highlightFollowsCurrentItem: true + flow: GridView.TopToBottom + cacheBuffer: width*10 + } -Text { - text: "hello world" + onCurrentBrowsingBackendChanged: { + console.log("INIT'ing " + currentBrowsingBackend) + currentBrowsingBackend.metadataModel = metadataModel; + currentBrowsingBackend.init(); + mediaBrowserGridView.model = (function() { return currentBrowsingBackend.backendModel; }) + } } diff --git a/components/mediawelcome/MediaWelcome.qml b/components/mediawelcome/MediaWelcome.qml index 41843881..5cee49ba 100644 --- a/components/mediawelcome/MediaWelcome.qml +++ b/components/mediawelcome/MediaWelcome.qml @@ -1,78 +1,77 @@ /*************************************************************************** * Copyright 2010 by Alessandro Diaferia * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ import QtQuick 1.1 import org.kde.qtextracomponents 0.1 as QtExtraComponents PathView { id: view clip: true model: homeModel anchors.fill: parent focus: true preferredHighlightBegin: 0.5 preferredHighlightEnd: 0.5 - signal clicked + signal backendSelected(variant selectedBackend) delegate: Component { Item { id: wrapper width: parent.width/3 height: parent.height/3 scale: PathView.iconScale Column { anchors.fill: parent QtExtraComponents.QIconItem { icon: decoration height: wrapper.height width: wrapper.width } Text { text: display font.pointSize: 30 anchors.horizontalCenter: parent.horizontalCenter color: "white" smooth: true style: Text.Raised font.bold: true font.italic: true } } MouseArea { anchors.fill: parent - onClicked: { - } + onClicked: view.backendSelected(modelObject) } } } path: Path { startX: 0 startY: 10 PathAttribute { name: "iconScale"; value: 0.1 } PathQuad { x: view.width/2; y: view.height/2; controlX: view.width/4; controlY: view.height/4 } PathAttribute { name: "iconScale"; value: 1 } PathQuad { x: view.width; y: 10; controlX: view.width*3/4; controlY: view.height/4 } PathAttribute { name: "iconScale"; value: 0.1 } } } diff --git a/components/qmldir b/components/qmldir index aa9dd4c3..646927be 100644 --- a/components/qmldir +++ b/components/qmldir @@ -1,6 +1,7 @@ MediaBrowser 0.1 mediabrowser/MediaBrowser.qml MediaController 0.1 mediacontroller/MediaController.qml 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/shells/newshell/package/contents/ui/mediacenter.qml b/shells/newshell/package/contents/ui/mediacenter.qml index 5fa6a70e..8d102c8e 100644 --- a/shells/newshell/package/contents/ui/mediacenter.qml +++ b/shells/newshell/package/contents/ui/mediacenter.qml @@ -1,42 +1,63 @@ import QtQuick 1.1 import org.kde.plasma.mediacentercomponents 0.1 as MediaCenterComponents Rectangle { id: mediaCenterRootItem gradient: Gradient { GradientStop { position: 0.0; color: "lightsteelblue" } GradientStop { position: 1.0; color: "black" } } MediaCenterComponents.MediaPlayer { anchors.fill: parent + z: -1 } MediaCenterComponents.BackendsModel { id: backendsModel } - Column { - anchors.fill: parent + MediaCenterComponents.RuntimeData { + id: runtimeData + } - MediaCenterComponents.MediaController { - id: mediaController - height: parent.height*0.1 - width: parent.width + MediaCenterComponents.MediaController { + id: mediaController + height: parent.height*0.1 + width: parent.width + anchors { + left: parent.left; right: parent.left; top: parent.top } + } - MediaCenterComponents.MediaWelcome { - height: parent.height - mediaController.height - mediaInfoBar.height - model: backendsModel + MediaCenterComponents.MediaWelcome { + width: parent.width + model: backendsModel + anchors { + left: parent.left; right: parent.right; top: mediaController.top; bottom: mediaInfoBar.top } - MediaCenterComponents.MediaInfoBar { - id: mediaInfoBar - height: parent.height * 0.1 - width: parent.width + onBackendSelected: { runtimeData.currentBrowsingBackend = selectedBackend; visible = false } + } + + MediaCenterComponents.MediaBrowser { + width: parent.width + anchors { + left: parent.left; right: parent.right; top: mediaController.top; bottom: mediaInfoBar.top } + visible: false + + currentBrowsingBackend: runtimeData.currentBrowsingBackend + onCurrentBrowsingBackendChanged: visible = true + } - z: 1 + MediaCenterComponents.MediaInfoBar { + id: mediaInfoBar + height: parent.height * 0.1 + width: parent.width + anchors { + left: parent.left; right: parent.left; bottom: parent.bottom + } } }