-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplicationfinder.cpp
More file actions
49 lines (44 loc) · 1.67 KB
/
applicationfinder.cpp
File metadata and controls
49 lines (44 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "applicationfinder.h"
#include <QDebug>
void ApplicationFinder::work()
{
QStringList appdirs = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation); // XDG Default applications location, user local folder first
appdirs.append(QStandardPaths::standardLocations(QStandardPaths::DesktopLocation)); // Add Desktop to search path
QStringList loadedFiles;
static QRegularExpression removeKey("^.*applications/");
for(const auto& appdir : qAsConst(appdirs))
{
QDirIterator appdirIterator(appdir, QStringList(APPLICATIONS_FILES_GLOB), QDir::Files, QDirIterator::Subdirectories|QDirIterator::FollowSymlinks);
while(!appdirIterator.next().isEmpty())
{
QString fileKey = appdirIterator.filePath().remove(removeKey);
if (!loadedFiles.contains(fileKey)) {
Application* app = new Application(appdirIterator.filePath());
if (app->parse()) {
// qDebug() << "App Found: " << appdirIterator.filePath() << " Name: " << app->name();
emit appFound(app);
loadedFiles.append(fileKey);
} else delete app;
}
}
}
appdirs.clear();
}
ApplicationFinder::ApplicationFinder(QObject *parent) :
QObject(parent)
{}
ApplicationFinder::~ApplicationFinder()
{
if (m_thread.isRunning())
m_thread.cancel();
}
void ApplicationFinder::run()
{
m_thread = QtConcurrent::run(this, &ApplicationFinder::work);
m_thread_watcher.setFuture(m_thread);
connect(&m_thread_watcher, SIGNAL(finished()), this, SLOT(workFinished()));
}
void ApplicationFinder::workFinished()
{
emit isReady();
}