-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesktopfileformat.cpp
More file actions
37 lines (33 loc) · 1.46 KB
/
desktopfileformat.cpp
File metadata and controls
37 lines (33 loc) · 1.46 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
#include "desktopfileformat.h"
#include <QDebug>
bool desktopFileRead(QIODevice &device, QSettings::SettingsMap &map)
{
QTextStream stream(&device);
QString currentSection;
bool isValid = false;
for (QString line = stream.readLine(); !line.isNull(); line=stream.readLine())
{
line = line.trimmed();
if (line.isEmpty() && line.startsWith(QLatin1Char('#'))) continue; // If line is empty or is a comment skip it
if (line.startsWith(QLatin1Char('['))) { // Section start
currentSection = line.mid(1, line.size() - 2).trimmed();
if (currentSection == "Desktop Entry") isValid = true;
continue;
}
if (currentSection.isEmpty() || currentSection != "Desktop Entry") continue; // If not in 'Desktop Entry' section yet .. continue
QString key = line.section('=', 0,0).trimmed(); // Key is the part before the first =
QString value = line.section('=', 1, -1).trimmed(); // Value is the part after the first =
if (value.contains(QLatin1Char(';')))
map.insert(key, value.split(QLatin1Char(';'), Qt::SplitBehaviorFlags::SkipEmptyParts)); // If the value contains ; then its an array so split it
else
map.insert(key, value);
}
return isValid;
}
bool desktopFileWrite(QIODevice &device, const QSettings::SettingsMap &map)
{
Q_UNUSED(device);
Q_UNUSED(map);
qInfo() << "Only reading of desktop files in supported!";
return true;
}