From f85701602031a8eb522576ba6486b28559427ec4 Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Tue, 2 Jan 2018 12:46:46 -0500 Subject: Improved some of the code in the screensaver plugins file --- src-qt5/src-cpp/plugins-screensaver.cpp | 41 ++++++++------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) (limited to 'src-qt5/src-cpp/plugins-screensaver.cpp') diff --git a/src-qt5/src-cpp/plugins-screensaver.cpp b/src-qt5/src-cpp/plugins-screensaver.cpp index 50796a52..0ceed8e8 100644 --- a/src-qt5/src-cpp/plugins-screensaver.cpp +++ b/src-qt5/src-cpp/plugins-screensaver.cpp @@ -39,21 +39,17 @@ bool SSPlugin::isLoaded(){ return !data.isEmpty(); } +/** + * Check if the plugin is valid as long as the JSON is not empty, + * it contains at least a "name", "qml", and "description" object, + * and the "name" and "description" objects contain a "default" key. +**/ bool SSPlugin::isValid(){ if(data.isEmpty()){ return false; } bool ok = data.contains("name") && data.contains("qml") && data.contains("description"); - if(ok){ - //go to the next name level and see if required sub-items exist - QJsonObject tmp = data.value("name").toObject(); - ok = tmp.contains("default"); - } - if(ok){ - //go to the next description level and see if required sub-items exist - QJsonObject tmp = data.value("description").toObject(); - ok = tmp.contains("default"); - } -if(ok){ - //go to the next qml level and see if required sub-items exist + ok &= containsDefault("name"); + ok &= containsDefault("description"); + if(ok) { QJsonObject tmp = data.value("qml").toObject(); QStringList mustexist; QString exec = tmp.value("exec").toString(); @@ -62,7 +58,6 @@ if(ok){ QJsonArray tmpA = data.value("additional_files").toArray(); for(int i=0; i Date: Tue, 2 Jan 2018 15:09:49 -0500 Subject: Started a framework for desktop plugins and modified the screensaver plugins to inherit from a base plugin system --- src-qt5/src-cpp/plugins-screensaver.cpp | 91 --------------------------------- 1 file changed, 91 deletions(-) (limited to 'src-qt5/src-cpp/plugins-screensaver.cpp') diff --git a/src-qt5/src-cpp/plugins-screensaver.cpp b/src-qt5/src-cpp/plugins-screensaver.cpp index 0ceed8e8..6370b068 100644 --- a/src-qt5/src-cpp/plugins-screensaver.cpp +++ b/src-qt5/src-cpp/plugins-screensaver.cpp @@ -5,14 +5,6 @@ // See the LICENSE file for full details //=========================================== #include "plugins-screensaver.h" -#include -#include -#include -#include -#include - -//Relative directory to search along the XDG paths for screensavers -#define REL_DIR QString("/lumina-desktop/screensavers") // ============ // SS PLUGIN @@ -25,25 +17,6 @@ SSPlugin::~SSPlugin(){ } -void SSPlugin::loadFile(QString path){ - data = QJsonObject(); - currentfile = path; - QFile file(path); - if(!file.exists() || !file.open(QIODevice::ReadOnly)){ return; } - data = QJsonDocument::fromJson(file.readAll()).object(); - //qDebug() << "Loaded ScreenSaver Data:" << currentfile << data; - file.close(); -} - -bool SSPlugin::isLoaded(){ - return !data.isEmpty(); -} - -/** - * Check if the plugin is valid as long as the JSON is not empty, - * it contains at least a "name", "qml", and "description" object, - * and the "name" and "description" objects contain a "default" key. -**/ bool SSPlugin::isValid(){ if(data.isEmpty()){ return false; } bool ok = data.contains("name") && data.contains("qml") && data.contains("description"); @@ -65,67 +38,3 @@ bool SSPlugin::isValid(){ } return ok; } - -QString SSPlugin::translatedObject(QString obj){ - QJsonObject tmp = data.value(obj).toObject(); - //Get the current locale - QString locale = getenv("LC_ALL"); - if(locale.isEmpty()){ locale = getenv("LC_MESSAGES"); } - if(locale.isEmpty()){ locale = getenv("LANG"); } - if(locale.isEmpty()){ locale = "default"; } - if(locale.contains(".")){ locale = locale.section(".",0,0); } //chop any charset code off the end - //Now find which localized string is available and return it - if(tmp.contains(locale)){ return tmp.value(locale).toString(); } - locale = locale.section("_",0,0); //full locale not found - look for shortened form - if(tmp.contains(locale)){ return tmp.value(locale).toString(); } - return tmp.value("default").toString(); //use the default version -} - -QUrl SSPlugin::scriptURL(){ - QString exec = data.value("qml").toObject().value("exec").toString(); - if(!exec.startsWith("/")){ exec.prepend( currentfile.section("/",0,-2)+"/" ); } - return QUrl::fromLocalFile(exec); -} - -// =================== -// SS PLUGIN SYSTEM -// =================== -SSPlugin SSPluginSystem::findPlugin(QString name){ - //qDebug() << "FindPlugin:" << name; - SSPlugin SSP; - if(name.startsWith("/") && QFile::exists(name)){ SSP.loadFile(name); return SSP;} //absolute path give - just load that one - //Cleanup the input name and ensure it has the right suffix - name = name.section("/",-1); - if(!name.endsWith(".json")){ name.append(".json"); } - //Get the list of directories to search - QStringList dirs; - dirs << QString(getenv("XDG_DATA_HOME")) << QString(getenv("XDG_DATA_DIRS")).split(":"); - //Look for that file within these directories and return the first one found - for(int i=0; i SSPluginSystem::findAllPlugins(bool validonly){ - QList LIST; - //Get the list of directories to search - QStringList dirs; - dirs << QString(getenv("XDG_DATA_HOME")) << QString(getenv("XDG_DATA_DIRS")).split(":"); - //Look for that file within these directories and return the first one found - for(int i=0; i