Changeset View
Changeset View
Standalone View
Standalone View
src/sessionmodel.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 45 | SessionModel::SessionModel(QObject *parent) : QAbstractListModel(parent), d(new SessionModelPrivate()) { | |||
---|---|---|---|---|---|
48 | dir.setNameFilters(QStringList() << "*.desktop"); | 48 | dir.setNameFilters(QStringList() << "*.desktop"); | ||
49 | dir.setFilter(QDir::Files); | 49 | dir.setFilter(QDir::Files); | ||
50 | // read session | 50 | // read session | ||
51 | foreach(const QString &session, dir.entryList()) { | 51 | foreach(const QString &session, dir.entryList()) { | ||
52 | QFile inputFile(dir.absoluteFilePath(session)); | 52 | QFile inputFile(dir.absoluteFilePath(session)); | ||
53 | if (!inputFile.open(QIODevice::ReadOnly)) | 53 | if (!inputFile.open(QIODevice::ReadOnly)) | ||
54 | continue; | 54 | continue; | ||
55 | SessionPtr si { new Session { session, "", "", "" } }; | 55 | SessionPtr si { new Session { session, "", "", "" } }; | ||
56 | bool isHidden = false; | ||||
57 | QString current_section; | ||||
56 | QTextStream in(&inputFile); | 58 | QTextStream in(&inputFile); | ||
57 | while (!in.atEnd()) { | 59 | while (!in.atEnd()) { | ||
58 | QString line = in.readLine(); | 60 | QString line = in.readLine(); | ||
61 | | ||||
62 | if (line.startsWith(QLatin1String("["))) { | ||||
63 | // The section name ends before the last ] before the start of a comment | ||||
64 | int end = line.lastIndexOf(QLatin1Char(']'), line.indexOf(QLatin1Char('#'))); | ||||
65 | if (end != -1) | ||||
66 | current_section = line.mid(1, end - 1); | ||||
67 | } | ||||
68 | | ||||
69 | if (current_section != QLatin1String("Desktop Entry")) | ||||
70 | continue; // We are only interested in the "Desktop Entry" section | ||||
71 | | ||||
59 | if (line.startsWith("Name=")) | 72 | if (line.startsWith("Name=")) | ||
60 | si->name = line.mid(5); | 73 | si->name = line.mid(5); | ||
61 | if (line.startsWith("Exec=")) | 74 | if (line.startsWith("Exec=")) | ||
62 | si->exec = line.mid(5); | 75 | si->exec = line.mid(5); | ||
63 | if (line.startsWith("Comment=")) | 76 | if (line.startsWith("Comment=")) | ||
64 | si->comment = line.mid(8); | 77 | si->comment = line.mid(8); | ||
78 | if (line.startsWith(QLatin1String("Hidden="))) | ||||
79 | isHidden = line.mid(7).toLower() == QLatin1String("true"); | ||||
65 | } | 80 | } | ||
81 | if (!isHidden) { | ||||
66 | // add to sessions list | 82 | // add to sessions list | ||
67 | d->sessions.push_back(si); | 83 | d->sessions.push_back(si); | ||
84 | } | ||||
85 | | ||||
68 | // close file | 86 | // close file | ||
69 | inputFile.close(); | 87 | inputFile.close(); | ||
70 | } | 88 | } | ||
71 | } | 89 | } | ||
72 | 90 | | |||
73 | SessionModel::~SessionModel() { | 91 | SessionModel::~SessionModel() { | ||
74 | delete d; | 92 | delete d; | ||
75 | } | 93 | } | ||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |