From 70a35d68f5db7abd57210bc289a334df8dbc1dd2 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 30 Jun 2016 15:05:54 -0400 Subject: Add the new jsonmenu menu plugin to lumina-config, with a new dialog for setting it up. --- src-qt5/core-utils/lumina-config/AppDialog.h | 6 +- src-qt5/core-utils/lumina-config/ColorDialog.cpp | 9 +- .../core-utils/lumina-config/GetPluginDialog.cpp | 10 +- src-qt5/core-utils/lumina-config/LPlugins.cpp | 10 ++ src-qt5/core-utils/lumina-config/ScriptDialog.cpp | 90 +++++++++++++ src-qt5/core-utils/lumina-config/ScriptDialog.h | 41 ++++++ src-qt5/core-utils/lumina-config/ScriptDialog.ui | 143 +++++++++++++++++++++ src-qt5/core-utils/lumina-config/lumina-config.pro | 3 + .../lumina-config/pages/page_interface_menu.cpp | 25 +++- 9 files changed, 327 insertions(+), 10 deletions(-) create mode 100644 src-qt5/core-utils/lumina-config/ScriptDialog.cpp create mode 100644 src-qt5/core-utils/lumina-config/ScriptDialog.h create mode 100644 src-qt5/core-utils/lumina-config/ScriptDialog.ui (limited to 'src-qt5/core-utils/lumina-config') diff --git a/src-qt5/core-utils/lumina-config/AppDialog.h b/src-qt5/core-utils/lumina-config/AppDialog.h index 8c35d9b7..392dbe4d 100644 --- a/src-qt5/core-utils/lumina-config/AppDialog.h +++ b/src-qt5/core-utils/lumina-config/AppDialog.h @@ -4,7 +4,7 @@ // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== -// This is the dialog for catching keyboard events and converting them to X11 keycodes +// This is the dialog for selecting an installed application //=========================================== #ifndef _LUMINA_FILE_MANAGER_APP_SELECT_DIALOG_H #define _LUMINA_FILE_MANAGER_APP_SELECT_DIALOG_H @@ -40,7 +40,9 @@ public: } this->setWindowIcon( LXDG::findIcon("system-search","") ); if(parent!=0){ - QPoint center = parent->geometry().center(); + QWidget *top = parent; + while(!top->isWindow()){ top = top->parentWidget(); } + QPoint center = top->geometry().center(); this->move(center.x()-(this->width()/2), center.y()-(this->height()/2) ); } } diff --git a/src-qt5/core-utils/lumina-config/ColorDialog.cpp b/src-qt5/core-utils/lumina-config/ColorDialog.cpp index f984cf0d..860f6069 100644 --- a/src-qt5/core-utils/lumina-config/ColorDialog.cpp +++ b/src-qt5/core-utils/lumina-config/ColorDialog.cpp @@ -27,8 +27,12 @@ ColorDialog::ColorDialog(QWidget *parent, LPlugins *plugs, QString colorFilePath //Now load the given file loadColors(); //Now center the window on the parent - QPoint cen = parent->geometry().center(); - this->move( cen.x() - (this->width()/2) , cen.y() - (this->height()/2) ); +if(parent!=0){ + QWidget *top = parent; + while(!top->isWindow()){ top = top->parentWidget(); } + QPoint center = top->geometry().center(); + this->move(center.x()-(this->width()/2), center.y()-(this->height()/2) ); + } } void ColorDialog::loadColors(){ @@ -139,4 +143,3 @@ void ColorDialog::on_tool_editcolor_clicked(){ if(!ok || value.isEmpty()){ return; } //cancelled updateItem(it, value); } - diff --git a/src-qt5/core-utils/lumina-config/GetPluginDialog.cpp b/src-qt5/core-utils/lumina-config/GetPluginDialog.cpp index 08359e2d..51ff718a 100644 --- a/src-qt5/core-utils/lumina-config/GetPluginDialog.cpp +++ b/src-qt5/core-utils/lumina-config/GetPluginDialog.cpp @@ -13,8 +13,12 @@ GetPluginDialog::GetPluginDialog(QWidget *parent) : QDialog(parent), ui(new Ui:: ui->setupUi(this); selected = false; //nothing selected by default //Now center the window on the parent - QPoint cen = parent->geometry().center(); - this->move( cen.x() - (this->width()/2) , cen.y() - (this->height()/2) ); + if(parent!=0){ + QWidget *top = parent; + while(!top->isWindow()){ top = top->parentWidget(); } + QPoint center = top->geometry().center(); + this->move(center.x()-(this->width()/2), center.y()-(this->height()/2) ); + } //Load the icons ui->push_cancel->setIcon( LXDG::findIcon("dialog-cancel","") ); ui->push_accept->setIcon( LXDG::findIcon("dialog-ok","") ); @@ -74,4 +78,4 @@ void GetPluginDialog::accept(){ plugID = ui->combo_list->currentData().toString().section("::::",1,1); selected = true; this->close(); -} \ No newline at end of file +} diff --git a/src-qt5/core-utils/lumina-config/LPlugins.cpp b/src-qt5/core-utils/lumina-config/LPlugins.cpp index 03490216..cf0c11ac 100644 --- a/src-qt5/core-utils/lumina-config/LPlugins.cpp +++ b/src-qt5/core-utils/lumina-config/LPlugins.cpp @@ -58,6 +58,7 @@ LPI LPlugins::colorInfo(QString item){ //=================== // PLUGINS //=================== +// PANEL PLUGINS void LPlugins::LoadPanelPlugins(){ PANEL.clear(); //User Button @@ -167,6 +168,7 @@ void LPlugins::LoadPanelPlugins(){ PANEL.insert(info.ID, info); } +// DESKTOP PLUGINS void LPlugins::LoadDesktopPlugins(){ DESKTOP.clear(); //Calendar Plugin @@ -232,6 +234,7 @@ void LPlugins::LoadDesktopPlugins(){ }*/ } +// MENU PLUGINS void LPlugins::LoadMenuPlugins(){ MENU.clear(); //Terminal @@ -283,6 +286,13 @@ void LPlugins::LoadMenuPlugins(){ info.ID = "app"; info.icon = "application-x-desktop"; MENU.insert(info.ID, info); + //Custom Apps + info = LPI(); //clear it + info.name = QObject::tr("Menu Script"); + info.description = QObject::tr("Run an external script to generate a menu"); + info.ID = "jsonmenu"; + info.icon = "text-x-script"; + MENU.insert(info.ID, info); } void LPlugins::LoadColorItems(){ diff --git a/src-qt5/core-utils/lumina-config/ScriptDialog.cpp b/src-qt5/core-utils/lumina-config/ScriptDialog.cpp new file mode 100644 index 00000000..3453486e --- /dev/null +++ b/src-qt5/core-utils/lumina-config/ScriptDialog.cpp @@ -0,0 +1,90 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "ScriptDialog.h" +#include "ui_ScriptDialog.h" + +//=========== +// PUBLIC +//=========== +ScriptDialog::ScriptDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ScriptDialog){ + ui->setupUi(this); + ok = false; + connect(ui->line_name, SIGNAL(textEdited(QString)), this, SLOT(checkItems()) ); + connect(ui->line_exec, SIGNAL(textEdited(QString)), this, SLOT(checkItems()) ); + connect(ui->line_icon, SIGNAL(textEdited(QString)), this, SLOT(checkItems()) ); + checkItems(true); +} + +ScriptDialog::~ScriptDialog(){ + +} + +//Main interaction functions +bool ScriptDialog::isValid(){ + return ok; +} + +QString ScriptDialog::icon(){ + return ui->line_icon->text(); +} + +QString ScriptDialog::name(){ + return ui->line_name->text(); +} + +QString ScriptDialog::command(){ + return ui->line_exec->text(); +} + +//============== +// PRIVATE SLOTS +//============== +void ScriptDialog::on_pushApply_clicked(){ + ok = true; + this->close(); +} + +void ScriptDialog::on_pushCancel_clicked(){ + ok = false; + this->close(); +} + +void ScriptDialog::on_tool_getexec_clicked(){ + QString file = QFileDialog::getOpenFileName( this, tr("Select a menu script"), QDir::homePath() ); + if(file.isEmpty()){ return; } //cancelled + ui->line_exec->setText(file); + checkItems(); +} + +void ScriptDialog::on_tool_geticon_clicked(){ + QString file = QFileDialog::getOpenFileName( this, tr("Select an icon file"), QDir::homePath() ); + if(file.isEmpty()){ return; } //cancelled + ui->line_icon->setText(file); + checkItems(); +} + +void ScriptDialog::checkItems(bool firstrun){ + if(firstrun){ + ui->line_name->setFocus(); + ui->label_sample->setPixmap( LXDG::findIcon("text-x-script","").pixmap(32,32) ); + ui->tool_geticon->setIcon( LXDG::findIcon("system-search","") ); + ui->tool_getexec->setIcon( LXDG::findIcon("system-search","") ); + } + //Update the icon sample if needed + if(icon()!=ui->label_sample->whatsThis()){ + ui->label_sample->setPixmap( LXDG::findIcon(icon(),"text-x-script").pixmap(32,32) ); + ui->label_sample->setWhatsThis(icon()); + } + bool good = true; + if(name().isEmpty()){ good = false; ui->line_name->setStyleSheet("color: red;"); } + else{ ui->line_name->setStyleSheet(""); } + QString cmd = command().section(" ",0,0).simplified(); + if( !LUtils::isValidBinary(cmd) || cmd.isEmpty() ){ good = false; ui->line_exec->setStyleSheet("color: red;"); } + else{ ui->line_exec->setStyleSheet(""); } + + ui->pushApply->setEnabled(good); +} diff --git a/src-qt5/core-utils/lumina-config/ScriptDialog.h b/src-qt5/core-utils/lumina-config/ScriptDialog.h new file mode 100644 index 00000000..07ac15d4 --- /dev/null +++ b/src-qt5/core-utils/lumina-config/ScriptDialog.h @@ -0,0 +1,41 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This is the dialog for selecting an installed application +//=========================================== +#ifndef _LUMINA_FILE_MANAGER_SCRIPT_SELECT_DIALOG_H +#define _LUMINA_FILE_MANAGER_SCRIPT_SELECT_DIALOG_H + +#include "globals.h" + +namespace Ui{ + class ScriptDialog; +}; + +class ScriptDialog : public QDialog{ + Q_OBJECT +public: + ScriptDialog(QWidget *parent = 0); + ~ScriptDialog(); + + //Main interaction functions + bool isValid(); + QString icon(); + QString name(); + QString command(); + +private: + Ui::ScriptDialog *ui; + bool ok; + +private slots: + void on_pushApply_clicked(); + void on_pushCancel_clicked(); + void on_tool_getexec_clicked(); + void on_tool_geticon_clicked(); + void checkItems(bool firstrun = false); +}; +#endif diff --git a/src-qt5/core-utils/lumina-config/ScriptDialog.ui b/src-qt5/core-utils/lumina-config/ScriptDialog.ui new file mode 100644 index 00000000..a675f2bf --- /dev/null +++ b/src-qt5/core-utils/lumina-config/ScriptDialog.ui @@ -0,0 +1,143 @@ + + + ScriptDialog + + + + 0 + 0 + 404 + 168 + + + + Setup a JSON Menu Script + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + Visible Name: + + + + + + + Executable: + + + + + + + Icon: + + + + + + + + + + + + + + + ... + + + + + + + + + + + + 0 + 0 + + + + + 32 + 32 + + + + + + + + + + + + + + ... + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + Apply + + + + + + + + + + diff --git a/src-qt5/core-utils/lumina-config/lumina-config.pro b/src-qt5/core-utils/lumina-config/lumina-config.pro index 2e950fe1..5d6e8db9 100644 --- a/src-qt5/core-utils/lumina-config/lumina-config.pro +++ b/src-qt5/core-utils/lumina-config/lumina-config.pro @@ -16,6 +16,7 @@ SOURCES += main.cpp \ ColorDialog.cpp \ ThemeDialog.cpp \ GetPluginDialog.cpp \ + ScriptDialog.cpp \ PanelWidget.cpp HEADERS += mainWindow.h \ @@ -24,6 +25,7 @@ HEADERS += mainWindow.h \ ColorDialog.h \ ThemeDialog.h \ GetPluginDialog.h \ + ScriptDialog.h \ PanelWidget.h FORMS += mainWindow.ui \ @@ -31,6 +33,7 @@ FORMS += mainWindow.ui \ ColorDialog.ui \ ThemeDialog.ui \ GetPluginDialog.ui \ + ScriptDialog.ui \ PanelWidget.ui include("pages/pages.pri") diff --git a/src-qt5/core-utils/lumina-config/pages/page_interface_menu.cpp b/src-qt5/core-utils/lumina-config/pages/page_interface_menu.cpp index 742c5728..d211d380 100644 --- a/src-qt5/core-utils/lumina-config/pages/page_interface_menu.cpp +++ b/src-qt5/core-utils/lumina-config/pages/page_interface_menu.cpp @@ -9,7 +9,7 @@ #include "getPage.h" #include "../AppDialog.h" #include "../GetPluginDialog.h" - +#include "../ScriptDialog.h" //========== // PUBLIC //========== @@ -52,7 +52,6 @@ QStringList items = settings.value("menu/itemlist", QStringList() ).toStringList //qDebug() << "Menu Items:" << items; ui->list_menu->clear(); for(int i=0; imenuPluginInfo(items[i]); if(items[i].startsWith("app::::")){ bool ok = false; XDGDesktop desk = LXDG::loadDesktopFile(items[i].section("::::",1,1), ok); @@ -64,7 +63,20 @@ QStringList items = settings.value("menu/itemlist", QStringList() ).toStringList item->setToolTip( desk.comment ); ui->list_menu->addItem(item); continue; //now go to the next item + }else if(items[i].startsWith("jsonmenu::::")){ + LPI info = PINFO->menuPluginInfo( items[i].section("::::",0,0) ); + if(info.ID.isEmpty()){ continue; } //invalid plugin type (no longer available?) + QString exec = items[i].section("::::",1,1); + + QListWidgetItem *item = new QListWidgetItem(); + item->setWhatsThis( items[i] ); + item->setIcon( LXDG::findIcon(items[i].section("::::",3,3),info.icon) ); + item->setText( items[i].section("::::",2,2) +" ("+info.name+")" ); + item->setToolTip( info.description ); + ui->list_menu->addItem(item); + continue; //now go to the next item } + LPI info = PINFO->menuPluginInfo(items[i]); if(info.ID.isEmpty()){ continue; } //invalid plugin //qDebug() << "Add Menu Item:" << info.ID; QListWidgetItem *item = new QListWidgetItem(); @@ -121,6 +133,15 @@ void page_interface_menu::addmenuplugin(){ it = new QListWidgetItem(LXDG::findIcon(desk.icon,""), desk.name ); it->setWhatsThis(info.ID+"::::"+desk.filePath); it->setToolTip( desk.comment ); + }else if(info.ID=="jsonmenu"){ + //Need to prompt for the script file, name, and icon to use + //new ID format: "jsonmenu":::::::::::: + ScriptDialog SD(this); + SD.exec(); + if(!SD.isValid()){ return; } + it = new QListWidgetItem( LXDG::findIcon(SD.icon(),"text-x-script"), SD.name()+" ("+info.ID+")" ); + it->setWhatsThis(info.ID+"::::"+SD.command()+"::::"+SD.name()+"::::"+SD.icon()); + it->setToolTip( info.description ); }else{ it = new QListWidgetItem( LXDG::findIcon(info.icon,""), info.name ); it->setWhatsThis(info.ID); -- cgit