From 31f117788d47ea31bbb8ae0a9babaf5382d56fb1 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 12 Jul 2017 09:04:58 -0400 Subject: Update the "open-with" menu for lumina-fm so that is shows recommendations directly in the menu. --- .../desktop-utils/lumina-fm/widgets/DirWidget2.cpp | 94 +++++++++++++++------- .../desktop-utils/lumina-fm/widgets/DirWidget2.h | 2 +- 2 files changed, 65 insertions(+), 31 deletions(-) (limited to 'src-qt5/desktop-utils') diff --git a/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp b/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp index 7214dba9..3790d145 100644 --- a/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp +++ b/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.cpp @@ -295,35 +295,15 @@ void DirWidget::createMenus(){ */ //---------------------------------------------------// - /* - if(cOpenWithMenu==0){ cOpenWithMenu = new QMenu(this); } - else{ cOpenWithMenu->clear(); } - cOpenWithMenu->setTitle(tr("Open with...")); - cOpenWithMenu->setIcon( LXDG::findIcon("run-build-configure","") ); - XDGDesktopList applist; - applist.updateList(); - PREFAPPS = getPreferredApplications(); - //qDebug() << "Preferred Apps:" << PREFAPPS; - cOpenWithMenu->clear(); - //Now get the application mimetype for the file extension (if available) - QStringList mimetypes = LXDG::findAppMimeForFile(filePath, true).split("::::"); //use all mimetypes - //Now add all the detected applications - QHash< QString, QList > hash = LXDG::sortDesktopCats( applist.apps(false,true) ); - QStringList cat = hash.keys(); - cat.sort(); //sort alphabetically - for(int c=0; c app = hash[cat[c]]; - if(app.length()<1){ cOpenWithMenu =0; continue; } - for(int a=0; afilePath; - QStringList arguments; - arguments << "%u"; - QProcess *p = new QProcess(); - p->start(program, arguments); - - cOpenWithMenu->addAction(LXDG::findIcon(app[a]->icon), (app[a]->name), this, SLOT(p->start(program, arguments)) );}} - cOpenWithMenu->addAction(LXDG::findIcon("run-build-configure",""), tr("Other..."), this, SLOT(runWithFiles()) ); -*/ + + if(cOpenWithMenu==0){ + cOpenWithMenu = new QMenu(this); + connect(cOpenWithMenu, SIGNAL(triggered(QAction*)), this, SLOT(OpenWithApp(QAction*)) ); + } + else{ cOpenWithMenu->clear(); } + cOpenWithMenu->setTitle(tr("Open with...")); + cOpenWithMenu->setIcon( LXDG::findIcon("system-run-with","") ); + //---------------------------------------------------// if(cFViewMenu==0){ cFViewMenu = new QMenu(this); } else{ cFViewMenu->clear(); } @@ -560,7 +540,8 @@ void DirWidget::UpdateContextMenu(){ if(!sel.isEmpty()){ contextMenu->addAction(LXDG::findIcon("system-run",""), tr("Open"), this, SLOT(runFiles()) ); - contextMenu->addAction(LXDG::findIcon("system-run-with",""), tr("Open With..."), this, SLOT(runWithFiles()) ); + //contextMenu->addAction(LXDG::findIcon("system-run-with",""), tr("Open With..."), this, SLOT(runWithFiles()) ); + contextMenu->addMenu(cOpenWithMenu); } contextMenu->addSection(LXDG::findIcon("unknown",""), tr("File Operations")); // contextMenu->addMenu(cFModMenu); @@ -589,6 +570,50 @@ void DirWidget::UpdateContextMenu(){ contextMenu->addMenu(cNewMenu); } contextMenu->addMenu(cOpenMenu); + //===================== + //PREFAPPS = getPreferredApplications(); + //qDebug() << "Preferred Apps:" << PREFAPPS; + cOpenWithMenu->clear(); + //Now get the application mimetype for the file extension (if available) + QStringList mimetypes; + for(int i=0; i0){ mimetypes = test; } + else{ + //Bad match - incompatible file types are selected - disable the recommendations + mimetypes.clear(); + break; + } + } + } + //Now add all the detected applications + if(!mimetypes.isEmpty()){ + static XDGDesktopList applist; + applist.updateList(); + QList apps = applist.apps(false,true); + QList found; + for(int a=0; amimeList.isEmpty()){ continue; } //no corresponding mime types for this app + QStringList test; test << mimetypes << apps[a]->mimeList; + if(test.removeDuplicates()>0){ found << apps[a]; } + } + if(!found.isEmpty()){ + //sort the apps by name + found = LXDG::sortDesktopNames(found); + //add apps to the menu + for(int i=0; iaddAction( LXDG::findIcon(found[i]->icon, ""), found[i]->name ); + act->setToolTip(found[i]->comment); + act->setWhatsThis(found[i]->filePath); + } + cOpenWithMenu->addSeparator(); + } + } + cOpenWithMenu->addAction(LXDG::findIcon("system-run-with",""), tr("Other..."), this, SLOT(runWithFiles()) ); } void DirWidget::currentDirectoryChanged(bool widgetonly){ @@ -844,6 +869,15 @@ void DirWidget::openMultimedia(){ if(!list.isEmpty()){ emit PlayFiles(list); } } +void DirWidget::OpenWithApp(QAction* act){ + if(act->whatsThis().isEmpty()){ return; } + QStringList sel = currentBrowser()->currentSelection(); + //Now we need to open the app file, and create the process + XDGDesktop desk(act->whatsThis()); + QString exec = desk.generateExec(sel); + ExternalProcess::launch(exec); +} + void DirWidget::autoExtractFiles(){ QStringList files = currentBrowser()->currentSelection(); qDebug() << "Starting auto-extract:" << files; diff --git a/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.h b/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.h index 284bf337..e1dafaa8 100644 --- a/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.h +++ b/src-qt5/desktop-utils/lumina-fm/widgets/DirWidget2.h @@ -162,7 +162,7 @@ private slots: // - Context-specific operations void openInSlideshow(); void openMultimedia(); - + void OpenWithApp(QAction*); signals: //Directory loading/finding signals -- cgit