Add some functions

This commit is contained in:
Victor Tran 2018-07-26 15:39:39 +10:00
parent 8f0ae78fdb
commit 0db229689a
2 changed files with 22 additions and 0 deletions

View file

@ -17,6 +17,8 @@
# define THELIBSSHARED_EXPORT Q_DECL_IMPORT
#endif
#define THE_LIBS_API_VERSION 1
class THELIBSSHARED_EXPORT theLibsGlobal : public QObject {
Q_OBJECT
@ -24,6 +26,7 @@ public:
static theLibsGlobal* instance();
static float getDPIScaling();
static QStringList searchInPath(QString executable);
public slots:
bool powerStretchEnabled();

View file

@ -1,6 +1,8 @@
#include "the-libs_global.h"
#include <QDesktopWidget>
#include <QDir>
#include <QDirIterator>
theLibsGlobal::theLibsGlobal() : QObject(NULL) {
#ifdef Q_OS_UNIX
@ -47,3 +49,20 @@ float theLibsGlobal::getDPIScaling() {
float currentDPI = QApplication::desktop()->logicalDpiX();
return currentDPI / (float) 96;
}
QStringList theLibsGlobal::searchInPath(QString executable) {
QStringList executables;
QStringList pathDirs = QString(qgetenv("PATH")).split(":");
for (QString dir : pathDirs) {
QDir path(dir);
QDirIterator i(path);
while (i.hasNext()) {
i.next();
if (i.fileName() == executable) {
executables.append(i.filePath());
}
}
}
return executables;
}