diff options
author | Ken Moore <moorekou@gmail.com> | 2014-11-17 18:53:12 -0500 |
---|---|---|
committer | Ken Moore <moorekou@gmail.com> | 2014-11-17 18:53:12 -0500 |
commit | 08fbc54ef9b30f5db1eea4ffbb4cbf6e3e52d99f (patch) | |
tree | fac7027b2a0b413f3e7b8662dd95f0aa96ef4341 | |
parent | Update the XDG MIME inplementation to support the draft standards for registe... (diff) | |
download | lumina-08fbc54ef9b30f5db1eea4ffbb4cbf6e3e52d99f.tar.gz lumina-08fbc54ef9b30f5db1eea4ffbb4cbf6e3e52d99f.tar.bz2 lumina-08fbc54ef9b30f5db1eea4ffbb4cbf6e3e52d99f.zip |
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.
-rw-r--r-- | libLumina/LuminaXDG.cpp | 14 | ||||
-rw-r--r-- | libLumina/LuminaXDG.h | 2 | ||||
-rw-r--r-- | lumina-config/mainUI.cpp | 196 | ||||
-rw-r--r-- | lumina-config/mainUI.ui | 29 | ||||
-rw-r--r-- | 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<mimes.length(); m++){ QString mime = mimes[m].section(":",1,1,QString::SectionSkipEmpty); + if(mime.endsWith("/"+extension)){ matches.prepend(mime); } //exact match + else{ matches << mime; } if(mimes[m].section(":",0,0,QString::SectionSkipEmpty).toInt() > 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 @@ <rect> <x>0</x> <y>0</y> - <width>181</width> - <height>113</height> + <width>192</width> + <height>115</height> </rect> </property> <attribute name="label"> @@ -464,8 +464,8 @@ <rect> <x>0</x> <y>0</y> - <width>177</width> - <height>106</height> + <width>191</width> + <height>107</height> </rect> </property> <attribute name="label"> @@ -602,8 +602,8 @@ <rect> <x>0</x> <y>0</y> - <width>181</width> - <height>113</height> + <width>192</width> + <height>115</height> </rect> </property> <attribute name="label"> @@ -691,8 +691,8 @@ <rect> <x>0</x> <y>0</y> - <width>177</width> - <height>106</height> + <width>191</width> + <height>107</height> </rect> </property> <attribute name="label"> @@ -1107,6 +1107,9 @@ <property name="text"> <string>...</string> </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonTextBesideIcon</enum> + </property> </widget> </item> <item row="1" column="1"> @@ -1114,6 +1117,9 @@ <property name="text"> <string>...</string> </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonTextBesideIcon</enum> + </property> </widget> </item> </layout> @@ -1229,7 +1235,6 @@ </item> </layout> <zorder>tree_defaults</zorder> - <zorder>tree_defaults</zorder> <zorder></zorder> </widget> </item> @@ -1530,8 +1535,8 @@ <rect> <x>0</x> <y>0</y> - <width>118</width> - <height>16</height> + <width>129</width> + <height>26</height> </rect> </property> <property name="sizePolicy"> @@ -1638,7 +1643,7 @@ <x>0</x> <y>0</y> <width>579</width> - <height>20</height> + <height>21</height> </rect> </property> </widget> 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<matches.length(); i++){ + defApp = LXDG::findDefaultAppForMime(matches[i]); + if(!defApp.isEmpty()){ extension = matches[i]; break; } + else if(i+1==matches.length()){ extension = matches[0]; } + } + }else{ defApp = LFileDialog::getDefaultApp(extension); } + if( !defApp.isEmpty() && !showDLG ){ bool ok = false; if(defApp.endsWith(".desktop")){ @@ -204,7 +213,10 @@ void getCMD(int argc, char ** argv, QString& binary, QString& args, QString& pat extension=info.completeSuffix(); if(info.isDir()){ extension="directory"; } else if(info.isExecutable() && extension.isEmpty()){ extension="binary"; } - }else if(isUrl){ extension = inFile.section(":",0,0); } + else if(extension!="desktop"){ extension="mimetype"; } //flag to check for mimetype default based on file + } + else if(isUrl && inFile.startsWith("mailto:")){ extension = "email"; } + else if(isUrl){ extension = "webbrowser"; } //if not an application - find the right application to open the file QString cmd; bool useInputFile = false; |