diff --git a/shells/newshell/mainwindow.cpp b/shells/newshell/mainwindow.cpp index cffae3b9..807d1fe5 100644 --- a/shells/newshell/mainwindow.cpp +++ b/shells/newshell/mainwindow.cpp @@ -1,223 +1,228 @@ /*************************************************************************** * Copyright 2009 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 . * ***************************************************************************/ #include "mainwindow.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include MainWindow::MainWindow(QWidget *parent) : KMainWindow(parent) , m_mousePointerAutoHide(false) { KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); const int argsCount = args->count(); QList urls; for (int i = 0; i < argsCount; ++i) { const KUrl url = args->url(i); if (url.isValid()) { urls.append(url); } } if (args->isSet("fullscreen")) { toggleFullScreen(); } KConfigGroup cfgGroup = KGlobal::config()->group("General"); bool toggleCheck = cfgGroup.readEntry("fullscreen",false); if (toggleCheck) { toggleFullScreen(); } view = new QDeclarativeView(this); if (!args->isSet("disable-opengl")) { QGLWidget *glWidget = new QGLWidget; glWidget->setAutoFillBackground(false); view->setViewport(glWidget); } else { #ifdef QT_MULTIMEDIA_KIT_FOUND QVideoWidget *widget = new QVideoWidget; widget->show(); view->setViewport(widget); #endif } args->clear(); view->setAttribute(Qt::WA_OpaquePaintEvent); view->setAttribute(Qt::WA_NoSystemBackground); view->viewport()->setAttribute(Qt::WA_OpaquePaintEvent); view->viewport()->setAttribute(Qt::WA_NoSystemBackground); view->setResizeMode(QDeclarativeView::SizeRootObjectToView); setCentralWidget(view); m_kdeclarative.setDeclarativeEngine(view->engine()); m_kdeclarative.initialize(); m_kdeclarative.setupBindings(); qmlRegisterType("org.kde.plasma.mediacenter.elements", 0, 1, "FilteredBackendsModel"); qmlRegisterType("org.kde.plasma.mediacenter.elements", 0, 1, "SubtitleProvider"); qmlRegisterType("org.kde.plasma.mediacenter.elements", 0, 1, "FilterPlaylistModel"); BackendsModel *backendsModel = new BackendsModel(view->engine(), this); view->rootContext()->setContextProperty("backendsModel", backendsModel); PlaylistModel *playlistModel = new PlaylistModel(this); if (urls.length() > 0) { playlistModel->clearPlaylist(); foreach (const KUrl &url, urls) { playlistModel->addToPlaylist(url.prettyUrl()); } } view->rootContext()->setContextProperty("playlistModel", playlistModel); view->rootContext()->setContextProperty("_pmc_mainwindow", this); view->rootContext()->setContextProperty("startedFullScreen", isFullScreen()); view->engine()->addImageProvider(PmcImageProvider::identificationString, new PmcImageProvider()); view->engine()->addImageProvider(PmcCoverArtProvider::identificationString, new PmcCoverArtProvider()); Plasma::Theme::defaultTheme()->setUseGlobalSettings(false); Plasma::Theme::defaultTheme()->setThemeName("oxygen"); m_structure = Plasma::PackageStructure::load("Plasma/Generic"); Plasma::Package *package = new Plasma::Package(QString(), "org.kde.plasma.mediacenter", m_structure); view->rootContext()->setContextProperty("_pmc_background_image_path", QUrl(package->filePath("images", "noiselight.png"))); view->rootContext()->setContextProperty("_pmc_gradient_image_path", QUrl(package->filePath("images", "gradient.png"))); view->rootContext()->setContextProperty("_pmc_shadow_image_path", QUrl(package->filePath("images", "shadow.png"))); cfgGroup = KGlobal::config()->group("MediaBrowsing"); view->rootContext()->setContextProperty("_pmc_is_desktop", cfgGroup.readEntry("isDesktop",false)); view->setSource(QUrl(package->filePath("mainscript"))); if (view->rootObject() && urls.count() > 0) { - view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "play"); + QTimer::singleShot(500, this, SLOT(playPlaylist())); } resize(1366, 768); installEventFilter(this); centralWidget()->installEventFilter(this); m_mousePointerAutoHideTimer.setInterval(2000); connect(this, SIGNAL(mousePointerAutoHideChanged()), SLOT(enableMousePointerAutoHideIfNeeded())); connect(&m_mousePointerAutoHideTimer, SIGNAL(timeout()), SLOT(hideMousePointer())); if (view->errors().isEmpty()) { qreal volumeRead = cfgGroup.readEntry("volumelevel",1.0); view->rootObject()->findChild("runtimeData")->setProperty("volume",volumeRead); } } bool MainWindow::toggleFullScreen() { if (windowState() & Qt::WindowFullScreen) { setWindowState(windowState() & ~Qt::WindowFullScreen); } else { setWindowState(windowState() | Qt::WindowFullScreen); } return (windowState() & Qt::WindowFullScreen); } MainWindow::~MainWindow() { KConfigGroup cfgGroup = KGlobal::config()->group("General"); windowState() & Qt::WindowFullScreen ? cfgGroup.writeEntry("fullscreen",true) : cfgGroup.writeEntry("fullscreen",false); QObject *volumeLevel = view->rootObject()->findChild("runtimeData"); if (volumeLevel) { cfgGroup.writeEntry("volumelevel",QDeclarativeProperty::read(volumeLevel,"volume").toReal()); } cfgGroup.sync(); } void MainWindow::closeMediaCenter() { QApplication::quit(); } void MainWindow::hideMousePointer() { kapp->setOverrideCursor(Qt::BlankCursor); m_mousePointerHidden = true; } void MainWindow::showMousePointer() { kapp->setOverrideCursor(Qt::ArrowCursor); m_mousePointerHidden = false; } bool MainWindow::mousePointerAutoHide() const { return m_mousePointerAutoHide; } void MainWindow::setMousePointerAutoHide(bool value) { m_mousePointerAutoHide = value; emit mousePointerAutoHideChanged(); } void MainWindow::enableMousePointerAutoHideIfNeeded() { if (m_mousePointerAutoHide) { m_mousePointerAutoHideTimer.start(); } else { m_mousePointerAutoHideTimer.stop(); showMousePointer(); } } bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::HoverMove) { if (m_mousePointerHidden) { showMousePointer(); enableMousePointerAutoHideIfNeeded(); } } return false; } + +void MainWindow::playPlaylist() +{ + view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "play"); +} diff --git a/shells/newshell/mainwindow.h b/shells/newshell/mainwindow.h index afaae661..2ba45cb2 100644 --- a/shells/newshell/mainwindow.h +++ b/shells/newshell/mainwindow.h @@ -1,71 +1,72 @@ /*************************************************************************** * Copyright 2009 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 . * ***************************************************************************/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include #include #include #include #include class QKeyEvent; class QMouseEvent; class MainWindow : public KMainWindow { Q_OBJECT Q_PROPERTY(bool mousePointerAutoHide READ mousePointerAutoHide WRITE setMousePointerAutoHide NOTIFY mousePointerAutoHideChanged) public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); bool mousePointerAutoHide() const; void setMousePointerAutoHide(bool value); public Q_SLOTS: void closeMediaCenter(); bool toggleFullScreen(); void hideMousePointer(); void showMousePointer(); + void playPlaylist(); Q_SIGNALS: void mousePointerAutoHideChanged(); private Q_SLOTS: void enableMousePointerAutoHideIfNeeded(); protected: bool eventFilter(QObject *obj, QEvent *event); private: Plasma::PackageStructure::Ptr m_structure; KDeclarative m_kdeclarative; bool m_mousePointerAutoHide; bool m_mousePointerHidden; QTimer m_mousePointerAutoHideTimer; QDeclarativeView *view; }; #endif // MAINWINDOW_H diff --git a/shells/newshell/package/contents/ui/mediacenter.qml b/shells/newshell/package/contents/ui/mediacenter.qml index 1dbb6c1d..57e39796 100644 --- a/shells/newshell/package/contents/ui/mediacenter.qml +++ b/shells/newshell/package/contents/ui/mediacenter.qml @@ -1,274 +1,277 @@ /*************************************************************************** * Copyright 2012 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 . * ***************************************************************************/ import QtQuick 1.1 import org.kde.plasma.mediacenter.elements 0.1 as MediaCenterElements import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.components 0.1 as PlasmaComponents import org.kde.plasma.extras 0.1 as PlasmaExtraComponents Image { id: root property QtObject mediaWelcomeInstance property QtObject mediaBrowserInstance property QtObject mediaPlayerInstance property QtObject playlistInstance property QtObject imageViewerInstance source: _pmc_background_image_path fillMode: Image.Tile Image { anchors.fill: parent source: _pmc_gradient_image_path MediaCenterElements.RuntimeData { id: runtimeData objectName: "runtimeData" } PlasmaExtraComponents.ResourceInstance { id: resourceInstance - uri: imageViewerInstance && imageViewerInstance.visible && imageViewerInstance.source !== "" && !(mediaBrowserInstance && mediaBrowserInstance.visible) ? imageViewerInstance.source : mediaPlayerInstance.url + uri: imageViewerInstance && imageViewerInstance.visible && imageViewerInstance.source !== "" && !(mediaBrowserInstance && mediaBrowserInstance.visible) + ? imageViewerInstance.source + : mediaPlayerInstance ? mediaPlayerInstance.url : "" } MediaCenterElements.MediaController { id: mediaController property bool hideFlag: false anchors { top: parent.top; right: parent.right; left: parent.left } height: visible ? parent.height * 0.08 : 0 runtimeDataObject: runtimeData z: 1; opacity: 0.8 visible: pmcPageStack.currentPage.hideMediaController ? false : true state: hideFlag && ((mediaPlayerInstance && mediaPlayerInstance.visible) || (imageViewerInstance && imageViewerInstance.visible)) ? "hidden" : "" currentMediaTime: runtimeData.currentTime totalMediaTime: runtimeData.totalTime onPlaylistButtonClicked: pmcPageStack.pushAndFocus(getPlaylist()) onBackButtonClicked: pmcPageStack.popAndFocus() onPlayNext: playlistInstance.playNext() onPlayPrevious: playlistInstance.playPrevious() onSeekRequested: if (mediaPlayerInstance) mediaPlayerInstance.currentTime = newPosition states: [ State { name: "hidden" AnchorChanges { target: mediaController; anchors.top: undefined; anchors.bottom: parent.top } } ] transitions: [ Transition { AnchorAnimation { duration: 200 } } ] } Item { id: pmcPageStackParentItem anchors { top: pmcPageStack.currentPage == mediaPlayerInstance || pmcPageStack.currentPage == imageViewerInstance ? parent.top : mediaController.bottom right: parent.right; left: parent.left; bottom: parent.bottom } PlasmaComponents.PageStack { id: pmcPageStack anchors.fill: parent function pushAndFocus(page) { push(page); focusCurrentPage(); } function popAndFocus() { pop(); focusCurrentPage(); } function focusCurrentPage() { currentPage.focus = true; } } } Component { id: pmcMediaWelcomeComponent MediaCenterElements.MediaWelcome { property bool hideMediaController: true model: backendsModel onBackendSelected: { if (!selectedBackend.init()) return; runtimeData.currentBrowsingBackend = selectedBackend; pmcPageStack.pushAndFocus(getMediaBrowser()); } onEmptyAreaClicked: if (mediaPlayerInstance) pmcPageStack.pushAndFocus(getMediaPlayer()); onStatusChanged: { switch (status) { case PlasmaComponents.PageStatus.Active: if (mediaPlayerInstance && mediaPlayerInstance.hasVideo) { videoBackdropTimer.start(); } case PlasmaComponents.PageStatus.Deactivating: if (mediaPlayerInstance) { mediaPlayerInstance.visible = false; mediaPlayerInstance.z = 0; mediaPlayerInstance.dimVideo = false; } } } Timer { id: videoBackdropTimer; interval: 250 onTriggered: { mediaPlayerInstance.parent = pmcPageStackParentItem; mediaPlayerInstance.visible = true; mediaPlayerInstance.z = -1; mediaPlayerInstance.dimVideo = true; } } } } Component { id: pmcMediaBrowserComponent MediaCenterElements.MediaBrowser { currentBrowsingBackend: runtimeData.currentBrowsingBackend onPlayRequested: { if (currentMediaType == "image") { var mediaImageViewer = getMediaImageViewer(); mediaImageViewer.stripModel = runtimeData.currentBrowsingBackend.backendModel; mediaImageViewer.stripCurrentIndex = index; mediaImageViewer.source = url; pmcPageStack.pushAndFocus(mediaImageViewer); } else { pmcPageStack.pushAndFocus(getMediaPlayer()); if (playlistInstance) playlistInstance.active = false; runtimeData.playUrl(url); } } onBackRequested: pmcPageStack.popAndFocus() } } Component { id: pmcMediaPlayerComponent MediaCenterElements.MediaPlayer { runtimeDataObject: runtimeData url: runtimeData.url volume: runtimeData.volume onEscapePressed: pmcPageStack.popAndFocus() onClicked: toggleController(mediaPlayerInstance) onMediaStarted: _pmc_mainwindow.mousePointerAutoHide = hasVideo onMediaFinished: { if (playlistInstance && playlistInstance.active && totalTime != -1 && !runtimeData.userTrigerredStop) { playlistInstance.playRequested(playlistModel.getNextUrl()); } else { runtimeData.stopped = true; if (!runtimeData.userTrigerredStop) { //FIXME:This breaks playback from runtimeData.playUrl //pmcPageStack.pushAndFocus(getMediaBrowser()) } } } Component.onCompleted: bindRuntimeData() function bindRuntimeData() { runtimeData.currentTime = function() { return currentTime } runtimeData.totalTime = function() { return totalTime } } } } Component { id: pmcPlaylistComponent MediaCenterElements.Playlist { backend: runtimeData.currentBrowsingBackend onPlayRequested: { if (!mediaPlayerInstance) { pmcPageStack.pushAndFocus(getMediaPlayer()); } runtimeData.playUrl(url); } Keys.onEscapePressed: pmcPageStack.popAndFocus() } } Component { id: pmcImageViewerComponent MediaCenterElements.ImageViewer { Keys.onEscapePressed: pmcPageStack.popAndFocus() onClicked: toggleController(imageViewerInstance) } } } function getMediaWelcome() { if (!mediaWelcomeInstance) { mediaWelcomeInstance = pmcMediaWelcomeComponent.createObject(pmcPageStack); } return mediaWelcomeInstance; } function getMediaBrowser() { if (!mediaBrowserInstance) { mediaBrowserInstance = pmcMediaBrowserComponent.createObject(pmcPageStack); } return mediaBrowserInstance; } function getMediaPlayer() { if (!mediaPlayerInstance) { mediaPlayerInstance = pmcMediaPlayerComponent.createObject(pmcPageStack); } return mediaPlayerInstance; } function getPlaylist() { if (!playlistInstance) { playlistInstance = pmcPlaylistComponent.createObject(pmcPageStack); } return playlistInstance; } function getMediaImageViewer() { if (!imageViewerInstance) { imageViewerInstance = pmcImageViewerComponent.createObject(pmcPageStack); } return imageViewerInstance; } function init() { pmcPageStack.pushAndFocus(getMediaWelcome()); } //FIXME: Hack to play params passed from the command line function play() { - playlist.playRequested(playlistModel.getNextUrl()); + pmcPageStack.pushAndFocus(getPlaylist()); + getPlaylist().playRequested(playlistModel.getNextUrl()); } function toggleController(itemToFocus) { mediaController.hideFlag = !mediaController.hideFlag; itemToFocus.focus = true; } Component.onCompleted: init() }