source: ogBrowser-Git/src/desktopparser.cpp

jenkins
Last change on this file was 6b6f1ba, checked in by Vadim Troshchinskiy Shmelev <vtroshchinskiy@…>, 16 months ago

Fix build, missing file in cmake

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include "desktopparser.h"
2#include <QDebug>
3#include <QtGlobal>
4#include <QDir>
5
6
7
8DesktopParser::DesktopParser() {
9    _applicationPaths += qgetenv("HOME") + "./local/share/applications";
10
11}
12
13void 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}
Note: See TracBrowser for help on using the repository browser.