aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Moore <ken@pcbsd.org>2014-10-08 14:21:05 -0400
committerKen Moore <ken@pcbsd.org>2014-10-08 14:21:05 -0400
commit2a2869aa6e1e673d3a1e29fc3b1dfd9c7d21ba6d (patch)
tree07a6748fd0d2f6199fd799d0e579c42bfc6df9e7
parentClean up the default filemanager/terminal settings. Put them in the main sess... (diff)
downloadlumina-2a2869aa6e1e673d3a1e29fc3b1dfd9c7d21ba6d.tar.gz
lumina-2a2869aa6e1e673d3a1e29fc3b1dfd9c7d21ba6d.tar.bz2
lumina-2a2869aa6e1e673d3a1e29fc3b1dfd9c7d21ba6d.zip
Add better binary detection to LuminaUtils, and setup lumina-open to use it.
-rw-r--r--libLumina/LuminaUtils.cpp14
-rw-r--r--libLumina/LuminaUtils.h5
-rw-r--r--lumina-open/LFileDialog.cpp10
-rw-r--r--lumina-open/LFileDialog.h3
-rw-r--r--lumina-open/main.cpp11
5 files changed, 32 insertions, 11 deletions
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp
index 03b71cc9..46c2e26c 100644
--- a/libLumina/LuminaUtils.cpp
+++ b/libLumina/LuminaUtils.cpp
@@ -64,3 +64,17 @@ bool LUtils::writeFile(QString filepath, QStringList contents, bool overwrite){
}
return ok;
}
+
+bool LUtils::isValidBinary(QString bin){
+ if(!bin.startsWith("/")){
+ //Relative path: search for it on the current "PATH" settings
+ QStringList paths = QString(qgetenv("PATH")).split(":");
+ for(int i=0; i<paths.length(); i++){
+ if(QFile::exists(paths[i]+"/"+bin)){ bin = paths[i]+"/"+bin; break;}
+ }
+ }
+ //bin should be the full path by now
+ if(!bin.startsWith("/")){ return false; }
+ QFileInfo info(bin);
+ return (info.exists() && info.isExecutable());
+}
diff --git a/libLumina/LuminaUtils.h b/libLumina/LuminaUtils.h
index 4fe5475c..a9a107a5 100644
--- a/libLumina/LuminaUtils.h
+++ b/libLumina/LuminaUtils.h
@@ -13,6 +13,8 @@
#include <QFile>
#include <QString>
#include <QStringList>
+#include <QFile>
+#include <QFileInfo>
class LUtils{
public:
@@ -25,6 +27,9 @@ public:
static QStringList readFile(QString filepath);
//Write a text file
static bool writeFile(QString filepath, QStringList contents, bool overwrite=false);
+
+ //Check whether a file/path is a valid binary
+ static bool isValidBinary(QString bin); //full path or name only
};
#endif
diff --git a/lumina-open/LFileDialog.cpp b/lumina-open/LFileDialog.cpp
index e720bd65..dfd70ba2 100644
--- a/lumina-open/LFileDialog.cpp
+++ b/lumina-open/LFileDialog.cpp
@@ -127,10 +127,9 @@ void LFileDialog::updateUI(){
bool good = false;
if(ui->radio_custom->isChecked()){
if(!ui->line_bin->text().isEmpty()){
- good = true;
+ good = LUtils::isValidBinary(ui->line_bin->text());
//Now verify that the file exists and is executable
- QFileInfo FI(ui->line_bin->text());
- if( FI.exists() && FI.isExecutable() && FI.isFile() ){
+ if( good ){
ui->label_goodbin->setPixmap(QPixmap(":/icons/good.png"));
}else{
ui->label_goodbin->setPixmap(QPixmap(":/icons/bad.png"));
@@ -206,7 +205,7 @@ void LFileDialog::radioChanged(){
}else{
ui->stackedWidget->setCurrentWidget(ui->page_custom);
}
- ui->check_default->setEnabled( !ui->radio_custom->isChecked() );
+ //ui->check_default->setEnabled( !ui->radio_custom->isChecked() );
updateUI();
}
@@ -219,6 +218,7 @@ void LFileDialog::radioChanged(){
void LFileDialog::on_tool_ok_clicked(){
appSelected = true;
+ setDefault = ui->check_default->isChecked();
if(ui->radio_custom->isChecked()){
appExec = ui->line_bin->text();
}else if(ui->radio_rec->isChecked()){
@@ -226,7 +226,6 @@ void LFileDialog::on_tool_ok_clicked(){
bool ok = false;
XDGDesktop app = LXDG::loadDesktopFile(PREFAPPS[ui->combo_rec->currentIndex()], ok);
//Set the output variables
- setDefault = ui->check_default->isChecked();
appExec = app.exec;
appPath = app.path;
appFile = app.filePath;
@@ -236,7 +235,6 @@ void LFileDialog::on_tool_ok_clicked(){
bool ok = false;
XDGDesktop app = LXDG::loadDesktopFile(ui->tree_apps->currentItem()->whatsThis(0), ok);
//Set the output variables
- setDefault = ui->check_default->isChecked();
appExec = app.exec;
appPath = app.path;
appFile = app.filePath;
diff --git a/lumina-open/LFileDialog.h b/lumina-open/LFileDialog.h
index e6a8f1fc..27f038d6 100644
--- a/lumina-open/LFileDialog.h
+++ b/lumina-open/LFileDialog.h
@@ -20,7 +20,8 @@
#include <QTextStream>
#include <QTreeWidgetItem>
-#include "LuminaXDG.h" //From libLuminaUtils
+#include <LuminaXDG.h> //From libLuminaUtils
+#include <LuminaUtils.h>
namespace Ui{
class LFileDialog;
diff --git a/lumina-open/main.cpp b/lumina-open/main.cpp
index b0f43a79..46053cef 100644
--- a/lumina-open/main.cpp
+++ b/lumina-open/main.cpp
@@ -27,6 +27,7 @@
#include "LFileDialog.h"
#include <LuminaXDG.h>
+#include <LuminaUtils.h>
#include <LuminaOS.h>
void printUsageInfo(){
@@ -93,7 +94,7 @@ QString cmdFromUser(int argc, char **argv, QString inFile, QString extension, QS
}
}else{
//Only binary given
- if(QFile::exists(defApp)){
+ if(LUtils::isValidBinary(defApp)){
qDebug() << "[lumina-open] Using default application:" << defApp << "File:" << inFile;
return defApp; //just use the binary
}
@@ -137,8 +138,10 @@ QString cmdFromUser(int argc, char **argv, QString inFile, QString extension, QS
if(!w.appPath.isEmpty()){ path = w.appPath; }
//Just do the default application registration here for now
// might move it to the runtime phase later after seeing that the app has successfully started
- if(w.setDefault){ LFileDialog::setDefaultApp(extension, w.appFile); }
- else{ LFileDialog::setDefaultApp(extension, ""); }
+ if(w.setDefault){
+ if(!w.appFile.isEmpty()){ LFileDialog::setDefaultApp(extension, w.appFile); }
+ else{ LFileDialog::setDefaultApp(extension, w.appExec); }
+ }else{ LFileDialog::setDefaultApp(extension, ""); }
//Now return the resulting application command
return w.appExec;
}
@@ -192,7 +195,7 @@ void getCMD(int argc, char ** argv, QString& binary, QString& args, QString& pat
//Make sure that it is a valid file/URL
bool isFile=false; bool isUrl=false;
if(QFile::exists(inFile)){ isFile=true; }
- else if(QUrl(inFile).isValid()){ isUrl=true; }
+ else if(QUrl(inFile).isValid() && !inFile.startsWith("/") ){ isUrl=true; }
if( !isFile && !isUrl ){ qDebug() << "Error: Invalid file or URL"; return;}
//Determing the type of file (extension)
QString extension;
bgstack15