From e22ce7dfc13348560af6b1d04d935dbc1358e2ce Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 21 Jul 2017 13:52:32 -0400 Subject: Start adding the application launch functionality to the session (untested) --- src-qt5/core/libLumina/ExternalProcess.h | 6 ++-- src-qt5/core/lumina-desktop-unified/LSession.cpp | 41 ++++++++++++++++++++-- src-qt5/core/lumina-desktop-unified/LSession.h | 4 +-- .../defaults/desktop/keys.conf | 4 +-- .../core/lumina-desktop-unified/global-includes.h | 1 + .../core/lumina-desktop-unified/lumina-desktop.pro | 1 + .../src-desktop/ContextMenu.h | 2 ++ 7 files changed, 49 insertions(+), 10 deletions(-) (limited to 'src-qt5') diff --git a/src-qt5/core/libLumina/ExternalProcess.h b/src-qt5/core/libLumina/ExternalProcess.h index a8a5e605..b1e56af8 100644 --- a/src-qt5/core/libLumina/ExternalProcess.h +++ b/src-qt5/core/libLumina/ExternalProcess.h @@ -44,7 +44,7 @@ private slots: } public: - ExternalProcess(QString logfile = "", bool manageCursors = true) : QProcess(){ + ExternalProcess(QString logfile = "", bool manageCursors = false) : QProcess(){ this->setProcessChannelMode(QProcess::MergedChannels); cursorRestored = !manageCursors; if(logfile.isEmpty()){ @@ -62,9 +62,9 @@ public: }*/ } - static void launch(QString program, QStringList args = QStringList()){ + static void launch(QString program, QStringList args = QStringList(), bool manageCursors = false){ //Quick launch of a process with logging disabled and automatic cleanup - ExternalProcess *tmp = new ExternalProcess(); + ExternalProcess *tmp = new ExternalProcess("", manageCursors); if(args.isEmpty()){ tmp->start(program); } else{ tmp->start(program, args); } } diff --git a/src-qt5/core/lumina-desktop-unified/LSession.cpp b/src-qt5/core/lumina-desktop-unified/LSession.cpp index 60ed1a39..c6f79584 100644 --- a/src-qt5/core/lumina-desktop-unified/LSession.cpp +++ b/src-qt5/core/lumina-desktop-unified/LSession.cpp @@ -381,11 +381,46 @@ void LSession::StartReboot(bool skipupdates){ QCoreApplication::exit(0); } -void LSession::LaunchApplication(QString app){ - +void LSession::LaunchApplication(QString exec){ + ExternalProcess::launch(exec); } -void LSession::LaunchStandardApplication(QString app){ +void LSession::LaunchStandardApplication(QString app, QStringList args){ + //Find/replace standardized apps with thier mimetypes + if(app.startsWith("--")){ app = "application/"+app.section("--",-1).simplified(); } + //First see if this is a mimetype with a default application + if(app.count("/")==1 && !app.startsWith("/")){ + QString mimeapp = XDGMime::findDefaultAppForMime(app); + if(!mimeapp.isEmpty()){ app = mimeapp; } + } + if(app.endsWith(".desktop")){ + //Get the XDGDesktop structure + XDGDesktop *desk = 0; bool cleanup = false; + if(app.startsWith("/") && QFile::exists(app)){ desk = new XDGDesktop(app); cleanup = true; } + if(!desk->isValid()){ + //Need to find the app within the current list + QHashapplist = Lumina::APPLIST->files; + if(cleanup){ desk->deleteLater(); desk = 0; cleanup = false; } + app = app.section("/",-1); //make sure this is a relative path + QStringList list = applist.keys().filter("/"+app); + if(!list.filter(QDir::homePath()).isEmpty()){ desk = applist[list.filter(QDir::homePath()).first()]; } //prefer user-override files + if(desk==0 || !desk->isValid()){ + desk = 0; + for(int i=0; iisValid()){ desk = tmp; } + } + } + } + if(desk!=0 && desk->isValid()){ + //Got the application - go ahead and assemble the startup command + QString exec = desk->generateExec(args); //args are embedded into the exec command as needed + ExternalProcess::launch(exec, QStringList(), desk->startupNotify); + } + if(cleanup){ desk->deleteLater(); } + }else{ + ExternalProcess::launch(app, args, false); // do not use startup notify cursor + } } diff --git a/src-qt5/core/lumina-desktop-unified/LSession.h b/src-qt5/core/lumina-desktop-unified/LSession.h index 0d666bfa..85cc050c 100644 --- a/src-qt5/core/lumina-desktop-unified/LSession.h +++ b/src-qt5/core/lumina-desktop-unified/LSession.h @@ -32,8 +32,8 @@ public slots: void StartLogout(); void StartShutdown(bool skipupdates = false); void StartReboot(bool skipupdates = false); - void LaunchApplication(QString app); - void LaunchStandardApplication(QString app); + void LaunchApplication(QString exec); + void LaunchStandardApplication(QString app, QStringList args = QStringList()); void reloadIconTheme(); //will emit the IconThemeChanged signal when ready void switchLocale(QString localeCode); //will emit the LocaleChanged signal when ready diff --git a/src-qt5/core/lumina-desktop-unified/defaults/desktop/keys.conf b/src-qt5/core/lumina-desktop-unified/defaults/desktop/keys.conf index c1417b85..59959194 100644 --- a/src-qt5/core/lumina-desktop-unified/defaults/desktop/keys.conf +++ b/src-qt5/core/lumina-desktop-unified/defaults/desktop/keys.conf @@ -4,5 +4,5 @@ Pause=Lockscreen Alt+L=Lockscreen [desktop] -Alt+F1=Launch: terminal -Print=Launch: screenshot +Alt+F1=Launch: --terminal +Print=Launch: --screenshot diff --git a/src-qt5/core/lumina-desktop-unified/global-includes.h b/src-qt5/core/lumina-desktop-unified/global-includes.h index 1d0ab068..92f895c2 100644 --- a/src-qt5/core/lumina-desktop-unified/global-includes.h +++ b/src-qt5/core/lumina-desktop-unified/global-includes.h @@ -62,6 +62,7 @@ #include #include #include +#include // Standard C includes #include diff --git a/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro b/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro index defa66f4..79f2ba6f 100644 --- a/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro +++ b/src-qt5/core/lumina-desktop-unified/lumina-desktop.pro @@ -19,6 +19,7 @@ include(../libLumina/DesktopSettings.pri) include(../libLumina/RootWindow.pri) include(../libLumina/ExternalProcess.pri) include(../libLumina/NativeWindow.pri) +include(../libLumina/XDGMime.pri) #include all the main individual source groups include(src-screensaver/screensaver.pri) diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/ContextMenu.h b/src-qt5/core/lumina-desktop-unified/src-desktop/ContextMenu.h index 1e3165ec..7fd21967 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/ContextMenu.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/ContextMenu.h @@ -32,6 +32,8 @@ private slots: signals: void LockSession(); void showLeaveDialog(); + void LaunchStandardApplication(QString); + void LaunchApplication(QString); }; #endif -- cgit From 003e1374d38ccd1a1ebb2296f191ac9a3b7efa48 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 21 Jul 2017 13:53:07 -0400 Subject: Add a new "XDGMime" class/files which can be used for non-graphical mimetype interactions --- src-qt5/core/libLumina/XDGMime.cpp | 362 +++++++++++++++++++++++++++++++++++++ src-qt5/core/libLumina/XDGMime.h | 57 ++++++ src-qt5/core/libLumina/XDGMime.pri | 10 + 3 files changed, 429 insertions(+) create mode 100644 src-qt5/core/libLumina/XDGMime.cpp create mode 100644 src-qt5/core/libLumina/XDGMime.h create mode 100644 src-qt5/core/libLumina/XDGMime.pri (limited to 'src-qt5') diff --git a/src-qt5/core/libLumina/XDGMime.cpp b/src-qt5/core/libLumina/XDGMime.cpp new file mode 100644 index 00000000..3983f6b5 --- /dev/null +++ b/src-qt5/core/libLumina/XDGMime.cpp @@ -0,0 +1,362 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2013-2017, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "XDGMime.h" +#include +#include + +static QStringList mimeglobs; +static qint64 mimechecktime; + +QString XDGMime::fromFileName(QString filename){ + //Convert a filename into a mimetype + return findAppMimeForFile(filename.section("/",-1),false); +} + +QStringList XDGMime::listFromFileName(QString filename){ + //Convert a filename into a list of mimetypes (arranged in descending priority) + return findAppMimeForFile(filename.section("/",-1),true).split("::::"); +} +QString XDGMime::toIconName(QString mime){ + if(!mime.contains("/") || mime.isEmpty() ){ return "unknown"; } //not a mime type + //Mime type to icon name + mime.replace("/","-"); //translate to icon mime name + return mime; +} + + +QStringList XDGMime::toFileExtensions(QString mime){ + QStringList out; + QStringList mimes = XDGMime::loadMimeFileGlobs2().filter(mime); + for(int i=0; i" + } + //qDebug() << "Mime to Files:" << mime << out; + return out; +} + +// ==================== +// BACKEND FUNCTIONS +// ==================== +QStringList XDGMime::systemMimeDirs(){ + //Returns a list of all the directories where *.xml MIME files can be found + QStringList appDirs = QString(getenv("XDG_DATA_HOME")).split(":"); + appDirs << QString(getenv("XDG_DATA_DIRS")).split(":"); + if(appDirs.isEmpty()){ appDirs << "/usr/local/share" << "/usr/share"; } + //Now create a valid list + QStringList out; + for(int i=0; i