shared: common: On first start, try to set a rasonable pdfviewer value
May not be users default, but better than nothing for now. Issue: #27
This commit is contained in:
parent
0d01fa977d
commit
def766ba67
@ -16,6 +16,7 @@
|
||||
#define SETTINGS_KEY_DBPATH "dbpath"
|
||||
#define SETTINGS_KEY_FIRSTRUN "firstrun"
|
||||
#define SETTINGS_KEY_IPCSOCKETPATH "ipcsocketpath"
|
||||
#define SETTINGS_KEY_PDFVIEWER "pdfviewer"
|
||||
|
||||
inline void initResources()
|
||||
{
|
||||
@ -38,6 +39,52 @@ bool Common::initSqliteDatabase(QString path)
|
||||
return true;
|
||||
}
|
||||
|
||||
QString Common::findInPath(QString needle)
|
||||
{
|
||||
QStringList results;
|
||||
QString pathVar = QProcessEnvironment::systemEnvironment().value("PATH", "/usr/bin/:/bin/:");
|
||||
QStringList paths = pathVar.split(":");
|
||||
for(const QString &path : paths)
|
||||
{
|
||||
// TODO: can pass ../ but so be it for now.
|
||||
|
||||
QFileInfo info{path + "/" + needle};
|
||||
if(info.exists())
|
||||
{
|
||||
return info.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void Common::setPdfViewer()
|
||||
{
|
||||
QString value;
|
||||
|
||||
/* TODO: well, we should query this probably from xdg*/
|
||||
QString okularPath = findInPath("okular");
|
||||
QString evincePath = findInPath("evince");
|
||||
QString qpdfviewPath = findInPath("qpdfview");
|
||||
|
||||
if(okularPath != "")
|
||||
{
|
||||
value = okularPath + " %f -p %p";
|
||||
}
|
||||
else if(evincePath != "")
|
||||
{
|
||||
value = evincePath + "-i %p %f";
|
||||
}
|
||||
else if(qpdfviewPath != "")
|
||||
{
|
||||
value = qpdfviewPath + "%f#%p";
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
if(value != "")
|
||||
{
|
||||
settings.setValue(SETTINGS_KEY_PDFVIEWER, value);
|
||||
}
|
||||
}
|
||||
void Common::ensureConfigured()
|
||||
{
|
||||
QSettings settings;
|
||||
@ -58,8 +105,10 @@ void Common::ensureConfigured()
|
||||
{
|
||||
throw LooqsGeneralException("Failed to initialize sqlite database");
|
||||
}
|
||||
|
||||
settings.setValue(SETTINGS_KEY_FIRSTRUN, false);
|
||||
settings.setValue(SETTINGS_KEY_DBPATH, dbpath);
|
||||
setPdfViewer();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -7,6 +7,8 @@ namespace Common
|
||||
void setupAppInfo();
|
||||
QString databasePath();
|
||||
QString ipcSocketPath();
|
||||
void setPdfViewer();
|
||||
QString findInPath(QString needle);
|
||||
bool initSqliteDatabase(QString path);
|
||||
void ensureConfigured();
|
||||
} // namespace Common
|
||||
|
Loading…
Reference in New Issue
Block a user