From 08fbc54ef9b30f5db1eea4ffbb4cbf6e3e52d99f Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 17 Nov 2014 18:53:12 -0500 Subject: Finish up the new Mime type default app usage in lumina-config and lumina-open. The new buttons in lumina config set the backends fine, but the file manager/terminal options will not be respected yet until I update the menu plugins in lumina-desktop. --- libLumina/LuminaXDG.cpp | 14 +++- libLumina/LuminaXDG.h | 2 +- lumina-config/mainUI.cpp | 196 +++++++++++++++++++++++++++++++++++++++++++++-- lumina-config/mainUI.ui | 29 ++++--- lumina-open/main.cpp | 16 +++- 5 files changed, 235 insertions(+), 22 deletions(-) diff --git a/libLumina/LuminaXDG.cpp b/libLumina/LuminaXDG.cpp index 802722d4..057954dd 100644 --- a/libLumina/LuminaXDG.cpp +++ b/libLumina/LuminaXDG.cpp @@ -364,16 +364,26 @@ QIcon LXDG::findMimeIcon(QString extension){ return ico; } -QString LXDG::findAppMimeForFile(QString extension){ +QString LXDG::findAppMimeForFile(QString filename, bool multiple){ QString out; + QString extension = filename.section(".",-1); + if("."+extension == filename){ extension.clear(); } //hidden file without extension int weight = 0; - QStringList mimes = LXDG::loadMimeFileGlobs2().filter(":*."+extension); + QStringList mimefull = LXDG::loadMimeFileGlobs2(); + QStringList mimes; + if(!extension.isEmpty()){ mimes = mimefull.filter(":*."+extension); } + if(mimes.isEmpty()){ mimes = mimefull.filter(":"+filename.left(3)); } //look for the first 3 characters only (FIX WILDCARD DETECTION LATER) + mimes.sort(); + QStringList matches; for(int m=0; m weight ){ out = mime; } } + if(multiple){ out = matches.join("::::"); } return out; } diff --git a/libLumina/LuminaXDG.h b/libLumina/LuminaXDG.h index 079ccd3a..ec994820 100644 --- a/libLumina/LuminaXDG.h +++ b/libLumina/LuminaXDG.h @@ -82,7 +82,7 @@ public: //Find the mime-type icon for a particular file extension static QIcon findMimeIcon(QString extension); //Find the mime-type of a particular file extension - static QString findAppMimeForFile(QString extension); + static QString findAppMimeForFile(QString filename, bool multiple = false); //Find the file extension for a particular mime-type static QStringList findFilesForMime(QString mime); // Simplification function for finding all info regarding current mime defaults diff --git a/lumina-config/mainUI.cpp b/lumina-config/mainUI.cpp index dea72814..84ad4d56 100644 --- a/lumina-config/mainUI.cpp +++ b/lumina-config/mainUI.cpp @@ -186,6 +186,10 @@ void MainUI::setupConnections(){ //Defaults Page //connect(ui->tool_defaults_addextension, SIGNAL(clicked()), this, SLOT(adddefaultextension()) ); //connect(ui->tool_defaults_addgroup, SIGNAL(clicked()), this, SLOT(adddefaultgroup()) ); + connect(ui->tool_default_filemanager, SIGNAL(clicked()), this, SLOT(changeDefaultFileManager()) ); + connect(ui->tool_default_terminal, SIGNAL(clicked()), this, SLOT(changeDefaultTerminal()) ); + connect(ui->tool_default_webbrowser, SIGNAL(clicked()), this, SLOT(changeDefaultBrowser()) ); + connect(ui->tool_default_email, SIGNAL(clicked()), this, SLOT(changeDefaultEmail()) ); connect(ui->tool_defaults_clear, SIGNAL(clicked()), this, SLOT(cleardefaultitem()) ); connect(ui->tool_defaults_set, SIGNAL(clicked()), this, SLOT(setdefaultitem()) ); connect(ui->tool_defaults_setbin, SIGNAL(clicked()), this, SLOT(setdefaultbinary()) ); @@ -1158,26 +1162,208 @@ void MainUI::getKeyPress(){ // Defaults Page //=========== void MainUI::changeDefaultBrowser(){ - + //Prompt for the new app + XDGDesktop desk = getSysApp(); + if(desk.filePath.isEmpty()){ return; }//nothing selected + //save the new app setting and adjust the button appearance + appsettings->setValue("default/webbrowser", desk.filePath); + QString tmp = desk.filePath; + if(tmp.endsWith(".desktop")){ + bool ok = false; + XDGDesktop file = LXDG::loadDesktopFile(tmp, ok); + if(!ok || file.filePath.isEmpty()){ + //Might be a binary - just print out the raw "path" + ui->tool_default_webbrowser->setText(tmp.section("/",-1)); + ui->tool_default_webbrowser->setIcon( LXDG::findIcon("application-x-executable","") ); + }else{ + ui->tool_default_webbrowser->setText(desk.name); + ui->tool_default_webbrowser->setIcon(LXDG::findIcon(desk.icon,"") ); + } + }else if(tmp.isEmpty()){ + ui->tool_default_webbrowser->setText(tr("Click to Set")); + ui->tool_default_webbrowser->setIcon( LXDG::findIcon("system-help","") ); + }else{ + //Might be a binary - just print out the raw "path" + ui->tool_default_webbrowser->setText(tmp.section("/",-1)); + ui->tool_default_webbrowser->setIcon( LXDG::findIcon("application-x-executable","") ); + } } void MainUI::changeDefaultEmail(){ - + //Prompt for the new app + XDGDesktop desk = getSysApp(); + if(desk.filePath.isEmpty()){ return; }//nothing selected + //save the new app setting and adjust the button appearance + appsettings->setValue("default/email", desk.filePath); + QString tmp = desk.filePath; + if(tmp.endsWith(".desktop")){ + bool ok = false; + XDGDesktop file = LXDG::loadDesktopFile(tmp, ok); + if(!ok || file.filePath.isEmpty()){ + //Might be a binary - just print out the raw "path" + ui->tool_default_email->setText(tmp.section("/",-1)); + ui->tool_default_email->setIcon( LXDG::findIcon("application-x-executable","") ); + }else{ + ui->tool_default_email->setText(file.name); + ui->tool_default_email->setIcon(LXDG::findIcon(file.icon,"") ); + } + }else if(tmp.isEmpty()){ + ui->tool_default_email->setText(tr("Click to Set")); + ui->tool_default_email->setIcon( LXDG::findIcon("system-help","") ); + }else{ + //Might be a binary - just print out the raw "path" + ui->tool_default_email->setText(tmp.section("/",-1)); + ui->tool_default_email->setIcon( LXDG::findIcon("application-x-executable","") ); + } } void MainUI::changeDefaultFileManager(){ - + //Prompt for the new app + XDGDesktop desk = getSysApp(); + if(desk.filePath.isEmpty()){ return; }//nothing selected + //save the new app setting and adjust the button appearance + appsettings->setValue("default/directory", desk.filePath); + QString tmp = desk.filePath; + if(tmp.endsWith(".desktop")){ + bool ok = false; + XDGDesktop file = LXDG::loadDesktopFile(tmp, ok); + if(!ok || file.filePath.isEmpty()){ + //Might be a binary - just print out the raw "path" + ui->tool_default_filemanager->setText(tmp.section("/",-1)); + ui->tool_default_filemanager->setIcon( LXDG::findIcon("application-x-executable","") ); + }else{ + ui->tool_default_filemanager->setText(file.name); + ui->tool_default_filemanager->setIcon(LXDG::findIcon(file.icon,"") ); + } + }else if(tmp.isEmpty()){ + ui->tool_default_filemanager->setText(tr("Click to Set")); + ui->tool_default_filemanager->setIcon( LXDG::findIcon("system-help","") ); + }else{ + //Might be a binary - just print out the raw "path" + ui->tool_default_filemanager->setText(tmp.section("/",-1)); + ui->tool_default_filemanager->setIcon( LXDG::findIcon("application-x-executable","") ); + } } void MainUI::changeDefaultTerminal(){ - + //Prompt for the new app + XDGDesktop desk = getSysApp(); + if(desk.filePath.isEmpty()){ return; }//nothing selected + //save the new app setting and adjust the button appearance + appsettings->setValue("default/terminal", desk.filePath); + QString tmp = desk.filePath; + if(tmp.endsWith(".desktop")){ + bool ok = false; + XDGDesktop file = LXDG::loadDesktopFile(tmp, ok); + if(!ok || file.filePath.isEmpty()){ + //Might be a binary - just print out the raw "path" + ui->tool_default_terminal->setText(tmp.section("/",-1)); + ui->tool_default_terminal->setIcon( LXDG::findIcon("application-x-executable","") ); + }else{ + ui->tool_default_terminal->setText(file.name); + ui->tool_default_terminal->setIcon(LXDG::findIcon(file.icon,"") ); + } + }else if(tmp.isEmpty()){ + ui->tool_default_terminal->setText(tr("Click to Set")); + ui->tool_default_terminal->setIcon( LXDG::findIcon("system-help","") ); + }else{ + //Might be a binary - just print out the raw "path" + ui->tool_default_terminal->setText(tmp.section("/",-1)); + ui->tool_default_terminal->setIcon( LXDG::findIcon("application-x-executable","") ); + } } void MainUI::loadDefaultSettings(){ //First load the lumina-open specific defaults + // - Default File Manager QString tmp = appsettings->value("default/directory", "lumina-fm").toString(); + if( !QFile::exists(tmp) && !LUtils::isValidBinary(tmp) ){ qDebug() << "Invalid Settings:" << tmp; tmp.clear(); } //invalid settings + if(tmp.endsWith(".desktop")){ + bool ok = false; + XDGDesktop file = LXDG::loadDesktopFile(tmp, ok); + if(!ok || file.filePath.isEmpty()){ + //Might be a binary - just print out the raw "path" + ui->tool_default_filemanager->setText(tmp.section("/",-1)); + ui->tool_default_filemanager->setIcon( LXDG::findIcon("application-x-executable","") ); + }else{ + ui->tool_default_filemanager->setText(file.name); + ui->tool_default_filemanager->setIcon(LXDG::findIcon(file.icon,"") ); + } + }else if(tmp.isEmpty()){ + ui->tool_default_filemanager->setText(tr("Click to Set")); + ui->tool_default_filemanager->setIcon( LXDG::findIcon("system-help","") ); + }else{ + //Might be a binary - just print out the raw "path" + ui->tool_default_filemanager->setText(tmp.section("/",-1)); + ui->tool_default_filemanager->setIcon( LXDG::findIcon("application-x-executable","") ); + } + // - Default Terminal + tmp = appsettings->value("default/terminal", "xterm").toString(); + if( !QFile::exists(tmp) && !LUtils::isValidBinary(tmp) ){ qDebug() << "Invalid Settings:" << tmp; tmp.clear(); } //invalid settings + if(tmp.endsWith(".desktop")){ + bool ok = false; + XDGDesktop file = LXDG::loadDesktopFile(tmp, ok); + if(!ok || file.filePath.isEmpty()){ + //Might be a binary - just print out the raw "path" + ui->tool_default_terminal->setText(tmp.section("/",-1)); + ui->tool_default_terminal->setIcon( LXDG::findIcon("application-x-executable","") ); + }else{ + ui->tool_default_terminal->setText(file.name); + ui->tool_default_terminal->setIcon(LXDG::findIcon(file.icon,"") ); + } + }else if(tmp.isEmpty()){ + ui->tool_default_terminal->setText(tr("Click to Set")); + ui->tool_default_terminal->setIcon( LXDG::findIcon("system-help","") ); + }else{ + //Might be a binary - just print out the raw "path" + ui->tool_default_terminal->setText(tmp.section("/",-1)); + ui->tool_default_terminal->setIcon( LXDG::findIcon("application-x-executable","") ); + } + // - Default Web Browser + tmp = appsettings->value("default/webbrowser", "").toString(); + if( !QFile::exists(tmp) && !LUtils::isValidBinary(tmp) ){ qDebug() << "Invalid Settings:" << tmp; tmp.clear(); } //invalid settings + if(tmp.endsWith(".desktop")){ + bool ok = false; + XDGDesktop file = LXDG::loadDesktopFile(tmp, ok); + if(!ok || file.filePath.isEmpty()){ + //Might be a binary - just print out the raw "path" + ui->tool_default_webbrowser->setText(tmp.section("/",-1)); + ui->tool_default_webbrowser->setIcon( LXDG::findIcon("application-x-executable","") ); + }else{ + ui->tool_default_webbrowser->setText(file.name); + ui->tool_default_webbrowser->setIcon(LXDG::findIcon(file.icon,"") ); + } + }else if(tmp.isEmpty()){ + ui->tool_default_webbrowser->setText(tr("Click to Set")); + ui->tool_default_webbrowser->setIcon( LXDG::findIcon("system-help","") ); + }else{ + //Might be a binary - just print out the raw "path" + ui->tool_default_webbrowser->setText(tmp.section("/",-1)); + ui->tool_default_webbrowser->setIcon( LXDG::findIcon("application-x-executable","") ); + } + // - Default Email Client + tmp = appsettings->value("default/email", "").toString(); + if( !QFile::exists(tmp) && !LUtils::isValidBinary(tmp) ){ qDebug() << "Invalid Settings:" << tmp; tmp.clear(); } //invalid settings + if(tmp.endsWith("*.desktop")){ + bool ok = false; + XDGDesktop file = LXDG::loadDesktopFile(tmp, ok); + if(!ok || file.filePath.isEmpty()){ + //Might be a binary - just print out the raw "path" + ui->tool_default_email->setText(tmp.section("/",-1)); + ui->tool_default_email->setIcon( LXDG::findIcon("application-x-executable","") ); + }else{ + ui->tool_default_email->setText(file.name); + ui->tool_default_email->setIcon(LXDG::findIcon(file.icon,"") ); + } + }else if(tmp.isEmpty()){ + ui->tool_default_email->setText(tr("Click to Set")); + ui->tool_default_email->setIcon( LXDG::findIcon("system-help","") ); + }else{ + //Might be a binary - just print out the raw "path" + ui->tool_default_email->setText(tmp.section("/",-1)); + ui->tool_default_email->setIcon( LXDG::findIcon("application-x-executable","") ); + } - //Now load the XDG mime defaults ui->tree_defaults->clear(); QStringList defMimeList = LXDG::listFileMimeDefaults(); diff --git a/lumina-config/mainUI.ui b/lumina-config/mainUI.ui index c3ed700a..2e17be03 100644 --- a/lumina-config/mainUI.ui +++ b/lumina-config/mainUI.ui @@ -375,8 +375,8 @@ 0 0 - 181 - 113 + 192 + 115 @@ -464,8 +464,8 @@ 0 0 - 177 - 106 + 191 + 107 @@ -602,8 +602,8 @@ 0 0 - 181 - 113 + 192 + 115 @@ -691,8 +691,8 @@ 0 0 - 177 - 106 + 191 + 107 @@ -1107,6 +1107,9 @@ ... + + Qt::ToolButtonTextBesideIcon + @@ -1114,6 +1117,9 @@ ... + + Qt::ToolButtonTextBesideIcon + @@ -1229,7 +1235,6 @@ tree_defaults - tree_defaults @@ -1530,8 +1535,8 @@ 0 0 - 118 - 16 + 129 + 26 @@ -1638,7 +1643,7 @@ 0 0 579 - 20 + 21 diff --git a/lumina-open/main.cpp b/lumina-open/main.cpp index c3fb5c49..4fcf70b7 100644 --- a/lumina-open/main.cpp +++ b/lumina-open/main.cpp @@ -76,7 +76,16 @@ void showOSD(int argc, char **argv, QString message){ QString cmdFromUser(int argc, char **argv, QString inFile, QString extension, QString& path, bool showDLG=false){ //First check to see if there is a default for this extension - QString defApp = LFileDialog::getDefaultApp(extension); + QString defApp; + if(extension=="mimetype"){ + QStringList matches = LXDG::findAppMimeForFile(inFile, true).split("::::"); //allow multiple matches + for(int i=0; i