diff options
author | Ken Moore <ken@ixsystems.com> | 2017-08-31 21:59:44 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-08-31 21:59:44 -0400 |
commit | aa64ef84cd104cc9364ebf480117174540f69a88 (patch) | |
tree | 756030b17e2df6995875283ba144dd3d308f2a9f /src-qt5/core/lumina-desktop-unified | |
parent | A bit more cleanup. Nothing too special. (diff) | |
download | lumina-aa64ef84cd104cc9364ebf480117174540f69a88.tar.gz lumina-aa64ef84cd104cc9364ebf480117174540f69a88.tar.bz2 lumina-aa64ef84cd104cc9364ebf480117174540f69a88.zip |
Some more cleanup on Lumina2:
1) Get the JsonMenu plugin up and running again for the context menu
2) Get the LIconCache integrated into the context menu (replacing the old LXDG::findIcon calls).
3) Get the window property events working!!! (finally)
4) Start getting some automatic window-verification put in place (for snapping windows to various places and such).
Diffstat (limited to 'src-qt5/core/lumina-desktop-unified')
5 files changed, 107 insertions, 15 deletions
diff --git a/src-qt5/core/lumina-desktop-unified/JsonMenu.h b/src-qt5/core/lumina-desktop-unified/JsonMenu.h new file mode 100644 index 00000000..2624153d --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/JsonMenu.h @@ -0,0 +1,71 @@ +//=========================================== +// Lumina Desktop source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This menu is used to automatically generate menu contents +// based on the JSON output of an external script/utility +//=========================================== +#ifndef _LUMINA_DESKTOP_JSON_MENU_H +#define _LUMINA_DESKTOP_JSON_MENU_H + +#include <global-objects.h> + +class JsonMenu : public QMenu{ + Q_OBJECT +private: + QString exec; + +public: + JsonMenu(QString execpath, QWidget *parent = 0) : QMenu(parent){ + exec = execpath; + connect(this, SIGNAL(aboutToShow()), this, SLOT(updateMenu()) ); + connect(this, SIGNAL(triggered(QAction*)), this, SLOT(itemTriggered(QAction*)) ); + } + +private slots: + void parseObject(QString label, QJsonObject obj){ + if( label.isEmpty() || !obj.contains("type") ){ return; } + QString type = obj.value("type").toString(); + if(type.toLower()=="item"){ + QAction *act = this->addAction(label); + if(obj.contains("icon")){ LIconCache::instance()->loadIcon(act, obj.value("icon").toString()); } + if(obj.contains("action")){ act->setWhatsThis( obj.value("action").toString() ); } + else{ act->setEnabled(false); } //not interactive + }else if(type.toLower()=="menu"){ + + }else if(type.toLower()=="jsonmenu"){ + //This is a recursive JSON menu object + if(!obj.contains("exec")){ return; } + JsonMenu *menu = new JsonMenu(obj.value("exec").toString(), this); + menu->setTitle(label); + if(obj.contains("icon")){ LIconCache::instance()->loadIcon(menu, obj.value("icon").toString()); } + this->addMenu(menu); + } + } + + void updateMenu(){ + this->clear(); + QJsonDocument doc = QJsonDocument::fromJson( LUtils::getCmdOutput(exec).join(" ").toLocal8Bit() ); + if(doc.isNull() || !doc.isObject()){ + this->addAction( QString(tr("Error parsing script output: %1")).arg("\n"+exec) )->setEnabled(false); + }else{ + QStringList keys = doc.object().keys(); + for(int i=0; i<keys.length(); i++){ + if(doc.object().value(keys[i]).isObject()){ + parseObject(keys[i], doc.object().value(keys[i]).toObject()); + } + } + } + } + + void itemTriggered(QAction *act){ + if(act->parent()!=this || act->whatsThis().isEmpty() ){ return; } //only handle direct child actions - needed for recursive nature of menu + QString cmd = act->whatsThis(); + QString bin = cmd.section(" ",0,0); + if( !LUtils::isValidBinary(bin) ){ cmd.prepend("lumina-open "); } + LSession::instance()->LaunchApplication(cmd); + } +}; +#endif diff --git a/src-qt5/core/lumina-desktop-unified/LSession.cpp b/src-qt5/core/lumina-desktop-unified/LSession.cpp index 05575b27..d70ff973 100644 --- a/src-qt5/core/lumina-desktop-unified/LSession.cpp +++ b/src-qt5/core/lumina-desktop-unified/LSession.cpp @@ -39,9 +39,9 @@ LSession::LSession(int &argc, char ** argv) : LSingleApplication(argc, argv, "lu this->setOrganizationName("LuminaDesktopEnvironment"); this->setQuitOnLastWindowClosed(false); //since the LDesktop's are not necessarily "window"s //Enable a few of the simple effects by default - //this->setEffectEnabled( Qt::UI_AnimateMenu, true); - //this->setEffectEnabled( Qt::UI_AnimateCombo, true); - //this->setEffectEnabled( Qt::UI_AnimateTooltip, true); + this->setEffectEnabled( Qt::UI_AnimateMenu, true); + this->setEffectEnabled( Qt::UI_AnimateCombo, true); + this->setEffectEnabled( Qt::UI_AnimateTooltip, true); this->setAttribute(Qt::AA_UseDesktopOpenGL); this->setAttribute(Qt::AA_UseHighDpiPixmaps); //allow pixmaps to be scaled up as well as down @@ -51,8 +51,8 @@ LSession::LSession(int &argc, char ** argv) : LSingleApplication(argc, argv, "lu Lumina::SS = new LScreenSaver(); //Now put the Native Window System into it's own thread to keep things snappy Lumina::EVThread = new QThread(); - Lumina::NWS->moveToThread(Lumina::EVThread); - Lumina::EVThread->start(); + //Lumina::NWS->moveToThread(Lumina::EVThread); + //Lumina::EVThread->start(); Lumina::APPLIST = XDGDesktopList::instance(); Lumina::ROOTWIN = new RootWindow(); Lumina::SHORTCUTS = new LShortcutEvents(); //this can be moved to it's own thread eventually as well diff --git a/src-qt5/core/lumina-desktop-unified/global-includes.h b/src-qt5/core/lumina-desktop-unified/global-includes.h index 8b8cd16c..184f5b8d 100644 --- a/src-qt5/core/lumina-desktop-unified/global-includes.h +++ b/src-qt5/core/lumina-desktop-unified/global-includes.h @@ -50,6 +50,10 @@ #include <QMediaPlayer> #include <QVideoWidget> #include <QMediaPlaylist> +#include <QJsonObject> +#include <QJsonArray> +#include <QJsonDocument> + // libLumina includes #include <LuminaX11.h> @@ -66,6 +70,7 @@ #include <NativeWindowSystem.h> #include <NativeEventFilter.h> #include <XDGMime.h> +#include <LIconCache.h> // Standard C includes #include <unistd.h> diff --git a/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro b/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro index 04d5b602..e8cf2f28 100644 --- a/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro +++ b/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro @@ -20,6 +20,7 @@ include(../libLumina/RootWindow.pri) include(../libLumina/ExternalProcess.pri) include(../libLumina/NativeWindow.pri) include(../libLumina/XDGMime.pri) +include(../libLumina/LIconCache.pri) #include all the main individual source groups include(src-screensaver/screensaver.pri) @@ -35,7 +36,8 @@ SOURCES += main.cpp \ HEADERS += global-includes.h \ global-objects.h \ LSession.h \ - BootSplash.h + BootSplash.h \ + JsonMenu.h FORMS += BootSplash.ui diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/ContextMenu.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/ContextMenu.cpp index 143a3667..47f0e3d7 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/ContextMenu.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/ContextMenu.cpp @@ -6,6 +6,7 @@ //=========================================== #include "ContextMenu.h" #include <global-objects.h> +#include <JsonMenu.h> void DesktopContextMenu::SettingsChanged(DesktopSettings::File file){ if(file == DesktopSettings::ContextMenu){ UpdateMenu(false); } @@ -24,13 +25,25 @@ void DesktopContextMenu::UpdateMenu(bool fast){ QStringList items = DesktopSettings::instance()->value(DesktopSettings::ContextMenu, "itemlist", QStringList()<< "terminal" << "filemanager" << "line" << "applications" << "windowlist" << "settings" << "lockdesktop").toStringList(); usewinmenu=false; for(int i=0; i<items.length(); i++){ - if(items[i]=="terminal"){ this->addAction(LXDG::findIcon("utilities-terminal",""), tr("Terminal"))->setWhatsThis("--terminal"); } - else if(items[i]=="lockdesktop"){ this->addAction(LXDG::findIcon("system-lock-screen",""), tr("Lock Session"), this, SIGNAL(LockSession()) ); } - else if(items[i]=="filemanager"){ this->addAction( LXDG::findIcon("user-home",""), tr("Browse Files"))->setWhatsThis(QDir::homePath()); } + if(items[i]=="terminal"){ + QAction *act = this->addAction( tr("Terminal")); + LIconCache::instance()->loadIcon(act, "utilities-terminal"); + act->setWhatsThis("--terminal"); + } + else if(items[i]=="lockdesktop"){ + QAction *act = this->addAction( tr("Lock Session"), this, SIGNAL(LockSession()) ); + LIconCache::instance()->loadIcon(act, "system-lock-screen"); + } + else if(items[i]=="filemanager"){ + QAction *act = this->addAction( tr("Browse Files")); + LIconCache::instance()->loadIcon(act, "user-home"); + act->setWhatsThis(QDir::homePath()); + } else if(items[i]=="applications"){ if(appMenu==0){ updateAppMenu(); } this->addMenu( appMenu ); - }else if(items[i]=="line"){ this->addSeparator(); } + } + else if(items[i]=="line"){ this->addSeparator(); } //else if(items[i]=="settings"){ this->addMenu( LSession::handle()->settingsMenu() ); } else if(items[i]=="windowlist"){ if(winMenu==0){ updateWinMenu(); } @@ -46,18 +59,18 @@ void DesktopContextMenu::UpdateMenu(bool fast){ XDGDesktop xdgf(file);// = LXDG::loadDesktopFile(file, ok); if(xdgf.type!=XDGDesktop::BAD){ xdgf.addToMenu(this); } } - }/*else if(items[i].startsWith("jsonmenu::::")){ + }else if(items[i].startsWith("jsonmenu::::")){ //Custom JSON menu system (populated on demand via external scripts/tools QStringList info = items[i].split("::::"); //FORMAT:[ "jsonmenu",exec,name, icon(optional)] if(info.length()>=3){ - qDebug() << "Custom JSON Menu Loaded:" << info; - JsonMenu *tmp = new JsonMenu(info[1], deskMenu); + //qDebug() << "Custom JSON Menu Loaded:" << info; + JsonMenu *tmp = new JsonMenu(info[1], this); tmp->setTitle(info[2]); connect(tmp, SIGNAL(triggered(QAction*)), this, SLOT(SystemApplication(QAction*)) ); if(info.length()>=4){ tmp->setIcon( LXDG::findIcon(info[3],"") ); } this->addMenu(tmp); } - }*/ + } } //Now add the system quit options this->addSeparator(); @@ -148,7 +161,7 @@ void DesktopContextMenu::updateAppMenu(){ if(appMenu==0){ appMenu = new QMenu(this); appMenu->setTitle( tr("Applications")); - appMenu->setIcon( LXDG::findIcon("system-run","") ); + LIconCache::instance()->loadIcon( appMenu, "system-run"); connect(appMenu, SIGNAL(triggered(QAction*)), this, SLOT(LaunchApp(QAction*)) ); } //qDebug() << "Populate App Menu"; @@ -160,6 +173,7 @@ void DesktopContextMenu::updateWinMenu(){ if(winMenu==0){ winMenu = new QMenu(this); winMenu->setTitle( tr("Task Manager") ); + LIconCache::instance()->loadIcon( winMenu, "preferences-system-windows"); } winMenu->clear(); QList<NativeWindow*> wins = Lumina::NWS->currentWindows(); |