diff options
author | Ken Moore <ken@ixsystems.com> | 2017-10-11 10:34:53 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-10-11 10:34:53 -0400 |
commit | dfac324cb6b02d19857f0e5dcced099d31ce957d (patch) | |
tree | b1b389b458c425fd67cbc624841f8bb22b5af13b | |
parent | Write up the new ScreenSaver plugins management class (untested) (diff) | |
download | lumina-dfac324cb6b02d19857f0e5dcced099d31ce957d.tar.gz lumina-dfac324cb6b02d19857f0e5dcced099d31ce957d.tar.bz2 lumina-dfac324cb6b02d19857f0e5dcced099d31ce957d.zip |
Get the Lumina2 screensaver system converted over to the new QML-backed plugin system.
Still need to clean up some old files within the source tree, but it all works right now.
9 files changed, 57 insertions, 67 deletions
diff --git a/src-qt5/OS-detect.pri b/src-qt5/OS-detect.pri index 9f3019e3..8511bd81 100644 --- a/src-qt5/OS-detect.pri +++ b/src-qt5/OS-detect.pri @@ -23,7 +23,7 @@ # ============================================= isEmpty(OS){ message("Build OS Info: $${QMAKE_HOST.os}, $${QMAKE_HOST.arch}, $${QMAKE_HOST.version_string}") - + message(" - Detected Qt Version: $${QT_VERSION}") #Load the initial library/includefile search locations (more can be added in the OS-specific sections below) LIBS = -L$${PWD}/core/libLumina -L$$[QT_INSTALL_LIBS] INCLUDEPATH = $${PWD}/core/libLumina $$[QT_INSTALL_HEADERS] $$[QT_INSTALL_PREFIX] diff --git a/src-qt5/core/lumina-desktop-unified/LSession.cpp b/src-qt5/core/lumina-desktop-unified/LSession.cpp index d70ff973..bace2dbe 100644 --- a/src-qt5/core/lumina-desktop-unified/LSession.cpp +++ b/src-qt5/core/lumina-desktop-unified/LSession.cpp @@ -356,12 +356,12 @@ void LSession::launchStartupApps(){ void LSession::checkUserFiles(){ //internal version conversion examples: // [1.0.0 -> 1000000], [1.2.3 -> 1002003], [0.6.1 -> 6001] - QString OVS = DesktopSettings::instance()->value(DesktopSettings::System,"DesktopVersion","0").toString(); //Old Version String + /*QString OVS = DesktopSettings::instance()->value(DesktopSettings::System,"DesktopVersion","0").toString(); //Old Version String bool changed = LDesktopUtils::checkUserFiles(OVS); if(changed){ //Save the current version of the session to the settings file (for next time) DesktopSettings::instance()->setValue(DesktopSettings::System,"DesktopVersion", this->applicationVersion()); - } + }*/ } diff --git a/src-qt5/core/lumina-desktop-unified/extrafiles/screensavers/Fireflies.json b/src-qt5/core/lumina-desktop-unified/extrafiles/screensavers/Fireflies.json index 8d0d25c4..c09de308 100644 --- a/src-qt5/core/lumina-desktop-unified/extrafiles/screensavers/Fireflies.json +++ b/src-qt5/core/lumina-desktop-unified/extrafiles/screensavers/Fireflies.json @@ -20,7 +20,7 @@ "version" : "1.0" }, "qml" : { - "qml_file" : "qml_scripts/Fireflies.qml", + "exec" : "qml_scripts/Fireflies.qml", "additional_files" : ["qml_scripts/Firefly.qml"] } } diff --git a/src-qt5/core/lumina-desktop-unified/global-includes.h b/src-qt5/core/lumina-desktop-unified/global-includes.h index 184f5b8d..ba1beb06 100644 --- a/src-qt5/core/lumina-desktop-unified/global-includes.h +++ b/src-qt5/core/lumina-desktop-unified/global-includes.h @@ -53,6 +53,7 @@ #include <QJsonObject> #include <QJsonArray> #include <QJsonDocument> +#include <QQuickView> // libLumina includes diff --git a/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro b/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro index 9b0c2fb3..6b9ee876 100644 --- a/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro +++ b/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro @@ -1,8 +1,15 @@ include($${PWD}/../../OS-detect.pri) -QT += core gui network -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets x11extras multimedia multimediawidgets concurrent svg +lessThan(QT_MAJOR_VERSION, 5) { + message("[ERROR] Qt 5.4+ is required to use the Lumina Desktop!") + exit +} +lessThan(QT_MINOR_VERSION, 4){ + message("[ERROR] Qt 5.4+ is required to use the Lumina Desktop!") + exit +} +QT *= core gui network widgets x11extras multimedia multimediawidgets concurrent svg quick qml TARGET = lumina-desktop-unified @@ -22,6 +29,8 @@ include(../libLumina/NativeWindow.pri) include(../libLumina/XDGMime.pri) include(../libLumina/LIconCache.pri) +include(../../src-cpp/plugins-screensaver.pri) + #include all the main individual source groups include(src-screensaver/screensaver.pri) include(src-events/events.pri) diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp b/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp index a6d5be60..227e51ac 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp @@ -12,10 +12,11 @@ // ======== // PUBLIC // ======== -SSBaseWidget::SSBaseWidget(QWidget *parent) : QWidget(parent){ +SSBaseWidget::SSBaseWidget(QWidget *parent) : QQuickView(parent->windowHandle()){ this->setObjectName("LuminaBaseSSWidget"); - ANIM = 0; - this->setMouseTracking(true); + this->setResizeMode(QQuickView::SizeRootObjectToView); + this->setColor(QColor("black")); //default color for the view + //this->setMouseTracking(true); plugType="none"; restartTimer = new QTimer(this); restartTimer->setInterval( DesktopSettings::instance()->value(DesktopSettings::ScreenSaver, "globals/plugin_time_seconds", 60).toInt() * 1000); @@ -24,7 +25,6 @@ SSBaseWidget::SSBaseWidget(QWidget *parent) : QWidget(parent){ } SSBaseWidget::~SSBaseWidget(){ - if(ANIM!=0){ this->stopPainting(); } } void SSBaseWidget::setPlugin(QString plug){ @@ -35,54 +35,27 @@ void SSBaseWidget::setPlugin(QString plug){ // PUBLIC SLOTS // ============= void SSBaseWidget::startPainting(){ - cplug = plugType; //free up any old animation instance - if(ANIM!=0){ - stopPainting(); - } + stopPainting(); //If a random plugin - grab one of the known plugins - if(cplug=="random"){ - QStringList valid = BaseAnimGroup::KnownAnimations(); - valid.removeAll("none"); //they want a screensaver - remove the "none" option from the valid list - if(valid.isEmpty()){ cplug = "none"; } //no known plugins - else{ cplug = valid[ qrand()%valid.length() ]; } //grab a random plugin - } - if(DEBUG){ qDebug() << " - Screen Saver:" << plugType << cplug; } - //Now list all the various plugins and start them appropriately - QString style; - if(cplug=="none"){ - style = "background: black;"; //show the underlying black parent widget - }else{ - style = "background: black;"; + if(plugType=="random"){ + QList<SSPlugin> valid = SSPluginSystem::findAllPlugins(); + if(!valid.isEmpty()){ cplug = valid[ qrand()%valid.length() ]; } //grab a random plugin + }else if(plugType!="none"){ + cplug = SSPluginSystem::findPlugin(plugType); } - this->setStyleSheet("QWidget#LuminaBaseSSWidget{ "+style+"}"); - this->repaint(); - //If not a stylesheet-based plugin - set it here - if(cplug!="none"){ - ANIM = BaseAnimGroup::NewAnimation(cplug, this); - connect(ANIM, SIGNAL(finished()), this, SLOT(startPainting()) ); //repeat the plugin as needed - ANIM->LoadAnimations(); + if(DEBUG){ qDebug() << " - Screen Saver:" << plugType << cplug.scriptURL() << cplug.isValid(); } + if(cplug.isValid()){ + this->setSource( cplug.scriptURL() ); + restartTimer->start(); } - //Now start the animation(s) - if(ANIM!=0){ - if(ANIM->animationCount()>0){ - if(DEBUG){ qDebug() << " - Starting SS Plugin:" << cplug << ANIM->animationCount() << ANIM->duration() << ANIM->loopCount(); } - ANIM->start(); - } - } - restartTimer->start(); + } void SSBaseWidget::stopPainting(){ - if(ANIM!=0){ - if(DEBUG){ qDebug() << "Stopping Animation!!"; } - ANIM->stop(); - //ANIM->clear(); - ANIM->deleteLater(); - ANIM = 0; - //Delete any child widgets of the canvas - QList<QWidget*> widgets = this->findChildren<QWidget*>("",Qt::FindDirectChildrenOnly); - for(int i=0; i<widgets.length(); i++){ widgets[i]->deleteLater(); } + if(!this->source().isEmpty()){ + this->setSource(QUrl()); + cplug = SSPlugin(); //empty structure } if(restartTimer->isActive()){ restartTimer->stop(); } } diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.h b/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.h index af809127..fdb23e66 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.h +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.h @@ -10,9 +10,9 @@ #define _LUMINA_DESKTOP_SCREEN_SAVER_BASE_WIDGET_H #include "global-includes.h" -#include "animations/BaseAnimGroup.h" +#include <plugins-screensaver.h> -class SSBaseWidget : public QWidget{ +class SSBaseWidget : public QQuickView{ Q_OBJECT public: SSBaseWidget(QWidget *parent); @@ -25,8 +25,8 @@ public slots: void stopPainting(); private: - QString plugType, cplug; //type of custom painting to do - BaseAnimGroup *ANIM; + QString plugType; + SSPlugin cplug; QTimer *restartTimer; private slots: @@ -43,12 +43,12 @@ protected: ev->accept(); emit InputDetected(); } - void paintEvent(QPaintEvent*){ + /*void paintEvent(QPaintEvent*){ QStyleOption opt; opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); - } + }*/ }; diff --git a/src-qt5/src-cpp/plugins-screensaver.cpp b/src-qt5/src-cpp/plugins-screensaver.cpp index 8271e7ac..e9ac1330 100644 --- a/src-qt5/src-cpp/plugins-screensaver.cpp +++ b/src-qt5/src-cpp/plugins-screensaver.cpp @@ -6,6 +6,10 @@ //=========================================== #include "plugins-screensaver.h" #include <QJsonDocument> +#include <QJsonArray> +#include <QFile> +#include <QDir> +#include <QDebug> //Relative directory to search along the XDG paths for screensavers #define REL_DIR QString("/lumina-desktop/screensavers") @@ -24,12 +28,10 @@ SSPlugin::~SSPlugin(){ void SSPlugin::loadFile(QString path){ data = QJsonObject(); currentfile = path; - SSPlugin SSP; QFile file(path); - if(!file.exists() || !file.open(QIODevice::ReadOnly)){ return SSP; } - SSP.data = QJsonDocument::fromJson(file.readAll()).object(); + if(!file.exists() || !file.open(QIODevice::ReadOnly)){ return; } + data = QJsonDocument::fromJson(file.readAll()).object(); file.close(); - return SSP; } bool SSPlugin::isLoaded(){ @@ -53,11 +55,13 @@ if(ok){ //go to the next qml level and see if required sub-items exist QJsonObject tmp = data.value("qml").toObject(); QStringList mustexist; - mustexist << tmp.value("exec").toString(); - ok = !mustexist.isEmpty(); //exec file should **always** be listed + QString exec = tmp.value("exec").toString(); + if(exec.isEmpty() || !exec.endsWith(".qml")){ return false; } + mustexist << exec; QJsonArray tmpA = data.value("additional_files").toArray(); for(int i=0; i<tmpA.count(); i++){ mustexist << tmpA[i].toString(); } QString reldir = currentfile.section("/",0,-2) + "/"; + qDebug() << "Got MustExist:" << mustexist << reldir; for(int i=0; i<mustexist.length() && ok; i++){ if(mustexist[i].startsWith("/")){ ok = QFile::exists(mustexist[i]); } else { ok = QFile::exists(reldir+mustexist[i]); } @@ -98,6 +102,7 @@ QString SSPlugin::translatedDescription(){ QUrl SSPlugin::scriptURL(){ QString exec = data.value("qml").toObject().value("exec").toString(); + qDebug() << "got exec:" << exec; if(!exec.startsWith("/")){ exec.prepend( currentfile.section("/",0,-2)+"/" ); } return QUrl::fromLocalFile(exec); } @@ -123,7 +128,7 @@ SSPlugin SSPluginSystem::findPlugin(QString name){ return SSP; } -QList<SSPlugin> SSPluginSystem::findAllPlugins(bool validonly = true){ +QList<SSPlugin> SSPluginSystem::findAllPlugins(bool validonly){ QList<SSPlugin> LIST; //Get the list of directories to search QStringList dirs; @@ -132,10 +137,12 @@ QList<SSPlugin> SSPluginSystem::findAllPlugins(bool validonly = true){ for(int i=0; i<dirs.length(); i++){ if(!QFile::exists(dirs[i]+REL_DIR)){ continue; } QDir dir(dirs[i]+REL_DIR); - QStringList files = dir.entryList(QStringList() << "*.json", QDir::Files, QDir::Names); + QStringList files = dir.entryList(QStringList() << "*.json", QDir::Files, QDir::Name); + qDebug() << "Found Files:" << files; for(int j=0; j<files.length(); j++){ SSPlugin tmp; - tmp.loadFile(dir.canonicalFilePath(files[j])); + tmp.loadFile(dir.absoluteFilePath(files[j])); + qDebug() << "Loaded File:" << files[j] << tmp.isValid(); if(!validonly || tmp.isValid()){ LIST << tmp; } } } diff --git a/src-qt5/src-cpp/plugins-screensaver.pri b/src-qt5/src-cpp/plugins-screensaver.pri index 883a850f..ad03f34c 100644 --- a/src-qt5/src-cpp/plugins-screensaver.pri +++ b/src-qt5/src-cpp/plugins-screensaver.pri @@ -1,4 +1,4 @@ HEADERS *= $${PWD}/plugins-screensaver.h SOURCES *= $${PWD}/plugins-screensaver.cpp -INCLUDEPATH *= ${PWD} +INCLUDEPATH *= $${PWD} |