//=========================================== // Lumina-desktop source code // Copyright (c) 2017, Ken Moore // Available under the 3-clause BSD license // 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 // ============ SSPlugin::SSPlugin(){ } 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"); ok &= containsDefault("name"); ok &= containsDefault("description"); if(ok) { QJsonObject tmp = data.value("qml").toObject(); QStringList mustexist; 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 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