[6b6f1ba] | 1 | #include "desktopparser.h" |
---|
| 2 | #include <QDebug> |
---|
| 3 | #include <QtGlobal> |
---|
| 4 | #include <QDir> |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | DesktopParser::DesktopParser() { |
---|
| 9 | _applicationPaths += qgetenv("HOME") + "./local/share/applications"; |
---|
| 10 | |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | void DesktopParser::loadSchemes() { |
---|
| 14 | |
---|
| 15 | qDebug() << "Loading URL schemes"; |
---|
| 16 | _schemes.clear(); |
---|
| 17 | |
---|
| 18 | for(const auto& appdir : _applicationPaths) { |
---|
| 19 | qDebug() << "Looking in" << appdir; |
---|
| 20 | |
---|
| 21 | QDir dir(appdir); |
---|
| 22 | for(const QFileInfo &fi : dir.entryInfoList(QDir::Files)) { |
---|
| 23 | //qDebug() << "File: " << fi; |
---|
| 24 | |
---|
| 25 | QFile file(fi.absoluteFilePath()); |
---|
| 26 | if (file.open(QIODevice::ReadOnly)) { |
---|
| 27 | QTextStream fs(&file); |
---|
| 28 | |
---|
| 29 | QString commandString; |
---|
| 30 | QString mimeTypesString; |
---|
| 31 | |
---|
| 32 | while(!fs.atEnd()) { |
---|
| 33 | QString line = fs.readLine(); |
---|
| 34 | QStringList parts = line.split("="); |
---|
| 35 | |
---|
| 36 | if (!parts.length() > 1) continue; |
---|
| 37 | |
---|
| 38 | if ( parts[0] == "Exec") { |
---|
| 39 | commandString=parts[1]; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | if (parts[0] == "MimeType" ) { |
---|
| 43 | mimeTypesString=parts[1]; |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | if (!commandString.isEmpty() && !mimeTypesString.isEmpty()) { |
---|
| 48 | //qDebug() << "Found MIME handler: " << mimeTypesString << "; " << commandString; |
---|
| 49 | |
---|
| 50 | QStringList handlers = mimeTypesString.split(";"); |
---|
| 51 | |
---|
| 52 | for(const QString &handler : handlers) { |
---|
| 53 | QStringList parts = handler.split("/"); |
---|
| 54 | if (parts.length() > 1 && parts[0] == "x-scheme-handler") { |
---|
| 55 | qInfo() << "Found URL scheme handler: " << parts[1] << " => " << commandString; |
---|
| 56 | _schemes[parts[1]] = commandString; |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | } |
---|
| 62 | } else { |
---|
| 63 | qWarning() << "Failed to open" << fi.absoluteFilePath(); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | } |
---|