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/core') 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