diff options
author | ZackaryWelch <welch.zackary@gmail.com> | 2018-01-02 15:09:49 -0500 |
---|---|---|
committer | ZackaryWelch <welch.zackary@gmail.com> | 2018-01-02 15:09:49 -0500 |
commit | 2287ab5e5edad3e843c4dac1c10ed6f43bc9f32d (patch) | |
tree | 9765373240926d103df307518b746c428af3b3a6 /src-qt5/src-cpp/plugins-base.cpp | |
parent | Improved some of the code in the screensaver plugins file (diff) | |
download | lumina-2287ab5e5edad3e843c4dac1c10ed6f43bc9f32d.tar.gz lumina-2287ab5e5edad3e843c4dac1c10ed6f43bc9f32d.tar.bz2 lumina-2287ab5e5edad3e843c4dac1c10ed6f43bc9f32d.zip |
Started a framework for desktop plugins and modified the screensaver plugins to inherit from a base plugin system
Diffstat (limited to 'src-qt5/src-cpp/plugins-base.cpp')
-rw-r--r-- | src-qt5/src-cpp/plugins-base.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src-qt5/src-cpp/plugins-base.cpp b/src-qt5/src-cpp/plugins-base.cpp new file mode 100644 index 00000000..f38374df --- /dev/null +++ b/src-qt5/src-cpp/plugins-base.cpp @@ -0,0 +1,50 @@ +//=========================================== +// 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-base.h" + +// ============ +// Base PLUGIN +// ============ +BasePlugin::BasePlugin(){ + +} + +BasePlugin::~BasePlugin(){ + +} + +void BasePlugin::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(); +} + +QString BasePlugin::translatedObject(QString obj){ + QJsonObject tmp = data.value(obj).toObject(); + //Get the current locale + QString locale = getenv("LC_ALL"); + if(locale.isEmpty()){ locale = getenv("LC_MEBaseAGES"); } + 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 BasePlugin::scriptURL(){ + QString exec = data.value("qml").toObject().value("exec").toString(); + if(!exec.startsWith("/")){ exec.prepend( currentfile.section("/",0,-2)+"/" ); } + return QUrl::fromLocalFile(exec); +} + |