From e3fc2e3b7c634df819fa75629233e5f319ae6903 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 27 Feb 2015 13:08:32 -0500 Subject: Update how lumina-open detects applications which are registered on the system for a particular mimetype. Now it uses the manual method (checking each *.desktop file for that particular mimetype - since it has to load all of them anyway), as well as use the results of any matches in the /applications/mimeinfo.cache file. --- libLumina/LuminaXDG.cpp | 29 +++++++++++++++++++++++++++++ libLumina/LuminaXDG.h | 2 ++ lumina-open/LFileDialog.cpp | 14 ++++++++++---- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/libLumina/LuminaXDG.cpp b/libLumina/LuminaXDG.cpp index 3ec16887..27b3b637 100644 --- a/libLumina/LuminaXDG.cpp +++ b/libLumina/LuminaXDG.cpp @@ -569,6 +569,35 @@ QString LXDG::findDefaultAppForMime(QString mime){ return cdefault; } +QStringList LXDG::findAvailableAppsForMime(QString mime){ + QStringList dirs = LXDG::systemApplicationDirs(); + QStringList out; + //Loop over all possible directories that contain *.destop files + // and check for the mimeinfo.cache file + for(int i=0; i -> kde4/ (stupid KDE variations!!) + files[m].replace("-","/"); + if(QFile::exists(dirs[i]+"/"+files[m])){ + out << dirs[i]+"/"+files[m]; + } + } + } + } + } + } + //qDebug() << "Found Apps for Mime:" << mime << out << dirs; + return out; +} + void LXDG::setDefaultAppForMime(QString mime, QString app){ QString filepath = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-mimeapps.list"; QStringList cinfo = LUtils::readFile(filepath); diff --git a/libLumina/LuminaXDG.h b/libLumina/LuminaXDG.h index ad09d490..fe44a4fd 100644 --- a/libLumina/LuminaXDG.h +++ b/libLumina/LuminaXDG.h @@ -91,6 +91,8 @@ public: static QString findMimeComment(QString mime); //Find the default application for a mime-type static QString findDefaultAppForMime(QString mime); + //Fine the available applications for a mime-type + static QStringList findAvailableAppsForMime(QString mime); //Set the default application for a mime-type static void setDefaultAppForMime(QString mime, QString app); //List all the registered audio/video file extensions diff --git a/lumina-open/LFileDialog.cpp b/lumina-open/LFileDialog.cpp index 5214a2f1..d648925b 100644 --- a/lumina-open/LFileDialog.cpp +++ b/lumina-open/LFileDialog.cpp @@ -38,7 +38,7 @@ void LFileDialog::setFileInfo(QString filename, QString extension, bool isFile){ else if(extension=="email"){ ui->label_extension->setText( QString(tr("(Email Link)")) ); } else if(extension=="webbrowser"){ ui->label_extension->setText( QString(tr("(Internet URL)")) ); } else{ui->label_extension->setText("("+extension+" link)"); } - fileEXT = extension; + fileEXT = extension; //NOTE: this is the mime-type for the file now, not the extension generateAppList(); } @@ -66,9 +66,13 @@ void LFileDialog::setDefaultApp(QString extension, QString appFile){ // PRIVATE // ----------- QStringList LFileDialog::getPreferredApplications(){ - //Now search the settings for that extension - QStringList keys = settings->allKeys(); QStringList out; + //First list all the applications registered for that same mimetype + QString mime = fileEXT; + out << LXDG::findAvailableAppsForMime(mime); + + //Now search the internal settings for that extension and find any applications last used + QStringList keys = settings->allKeys(); for(int i=0; icombo_rec->clear(); //Now get the application mimetype for the file extension (if available) - QString mimetype = LXDG::findAppMimeForFile(fileEXT); + QString mimetype = fileEXT; //Now add all the detected applications QHash< QString, QList > hash = LXDG::sortDesktopCats( LXDG::systemDesktopFiles() ); QStringList cat = hash.keys(); -- cgit