1 //===========================================
2 //  Lumina-DE source code
3 //  Copyright (c) 2015, Ken Moore
4 //  Available under the 3-clause BSD license
5 //  See the LICENSE file for full details
6 //===========================================
7 #include "GetPluginDialog.h"
8 #include "ui_GetPluginDialog.h"
9 
10 #include <LuminaXDG.h>
11 
GetPluginDialog(QWidget * parent)12 GetPluginDialog::GetPluginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::GetPluginDialog()){
13   ui->setupUi(this);
14   selected = false; //nothing selected by default
15   //Now center the window on the parent
16   if(parent!=0){
17     QWidget *top = parent;
18     while(!top->isWindow()){ top = top->parentWidget(); }
19     QPoint center = top->geometry().center();
20     this->move(center.x()-(this->width()/2), center.y()-(this->height()/2) );
21   }
22   //Load the icons
23   ui->push_cancel->setIcon( LXDG::findIcon("dialog-cancel","") );
24   ui->push_accept->setIcon( LXDG::findIcon("dialog-ok","") );
25   this->setWindowIcon( LXDG::findIcon("preferences-plugin") );
26   //Connect the signals/slots
27   connect(ui->combo_list, SIGNAL(currentIndexChanged(int)), this, SLOT(pluginchanged()) );
28   connect(ui->push_cancel, SIGNAL(clicked()), this, SLOT(close()) );
29   connect(ui->push_accept, SIGNAL(clicked()), this, SLOT(accept()) );
30 }
31 
~GetPluginDialog()32 GetPluginDialog::~GetPluginDialog(){
33 
34 }
35 
LoadPlugins(QString type,LPlugins * DB)36 void GetPluginDialog::LoadPlugins(QString type, LPlugins *DB){
37   //Special data format: <Visible Name>::::<ID>::::<icon>::::<description>
38   QStringList data;
39   if(type.toLower()=="menu"){
40     QStringList plugs = DB->menuPlugins();
41     for(int i=0; i<plugs.length(); i++){
42       LPI dat = DB->menuPluginInfo(plugs[i]);
43       data << dat.name+"::::"+dat.ID+"::::"+dat.icon+"::::"+dat.description;
44     }
45   }else if(type.toLower()=="desktop"){
46     QStringList plugs = DB->desktopPlugins();
47     for(int i=0; i<plugs.length(); i++){
48       LPI dat = DB->desktopPluginInfo(plugs[i]);
49       data << dat.name+"::::"+dat.ID+"::::"+dat.icon+"::::"+dat.description;
50     }
51   }else if(type.toLower()=="panel"){
52     QStringList plugs = DB->panelPlugins();
53     for(int i=0; i<plugs.length(); i++){
54       LPI dat = DB->panelPluginInfo(plugs[i]);
55       data << dat.name+"::::"+dat.ID+"::::"+dat.icon+"::::"+dat.description;
56     }
57   }
58   data.sort(); //this will sort them according to visible name
59   ui->combo_list->clear();
60   for(int i=0; i<data.length(); i++){
61     ui->combo_list->addItem( LXDG::findIcon(data[i].section("::::",2,2),""), data[i].section("::::",0,0) , data[i]);
62   }
63   if(!data.isEmpty()){
64     ui->combo_list->setCurrentIndex(0);
65   }
66 }
67 
pluginchanged()68 void GetPluginDialog::pluginchanged(){
69  //Load the description of the currently selected plugin
70   if(ui->combo_list->count() < 1){ ui->label_desc->clear(); }
71   else{
72     ui->label_desc->setText( ui->combo_list->currentData().toString().section("::::",3,50) );
73   }
74   ui->push_accept->setEnabled(ui->combo_list->currentIndex()>=0);
75 }
76 
accept()77 void GetPluginDialog::accept(){
78   plugID = ui->combo_list->currentData().toString().section("::::",1,1);
79   selected = true;
80   this->close();
81 }
82