1 //===========================================
2 //  Lumina-desktop source code
3 //  Copyright (c) 2017, Ken Moore
4 //  Available under the 3-clause BSD license
5 //  See the LICENSE file for full details
6 //===========================================
7 #include "plugins-desktop.h"
8 
9 #include <LuminaXDG.h>
10 
11 // ============
12 //    DT PLUGIN
13 // ============
DTPlugin()14 DTPlugin::DTPlugin(){
15 }
16 
~DTPlugin()17 DTPlugin::~DTPlugin(){
18 }
19 
isValid()20 bool DTPlugin::isValid(){
21   if(data.isEmpty()){ return false; }
22   bool ok = data.contains("name") && data.contains("qml") && data.contains("description");
23   ok &= containsDefault("name");
24   ok &= containsDefault("description");
25   ok &= containsDefault("data");
26   if(ok) {
27     QJsonObject tmp = data.value("qml").toObject();
28 
29     QStringList mustexist;
30     QString exec = tmp.value("exec").toString();
31     if(exec.isEmpty() || !exec.endsWith(".qml")){ return false; }
32     mustexist << exec;
33     QJsonArray tmpA = data.value("additional_files").toArray();
34     for(int i=0; i<tmpA.count(); i++){ mustexist << tmpA[i].toString(); }
35     QString reldir = currentfile.section("/",0,-2) + "/";
36     for(int i=0; i<mustexist.length() && ok; i++){
37       if(mustexist[i].startsWith("/")){ ok = QFile::exists(mustexist[i]); }
38       else { ok = QFile::exists(reldir+mustexist[i]); }
39     }
40   }
41   return ok;
42 }
43 
getSize()44 QSize DTPlugin::getSize(){
45   QString gridS = data.value("data").toObject().value("grid_size").toString();
46   QSize gridSize(0,0);
47   if(!gridS.isEmpty()) {
48     QStringList gridList = gridS.split("x");
49     if(gridList.size() == 2) {
50       int width = gridList[0].toInt();
51       int height = gridList[1].toInt();
52       if(width > 0 && height > 0)
53         gridSize = QSize(width, height);
54     }
55   }
56   return gridSize;
57 }
58 
supportsPanel()59 bool DTPlugin::supportsPanel(){
60   QString possibleS = data.value("data").toObject().value("panel_possible").toString().toLower();
61   bool panelPossible = false;
62   if(!possibleS.isEmpty() && (possibleS == "yes" || possibleS == "true")){
63     panelPossible = true;
64   }
65   return panelPossible;
66 }
67 
getIcon()68 QString DTPlugin::getIcon(){
69     QString iconS = data.value("data").toObject().value("plugin_icon").toString();
70     if(iconS.isEmpty()){ iconS = "preferences-plugin"; }
71     return iconS;
72 }
73