2023-07-12 15:58:41 +08:00
|
|
|
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
#include "desktopentry.h"
|
2023-08-10 14:32:09 +08:00
|
|
|
#include "global.h"
|
2023-07-12 15:58:41 +08:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDir>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QDirIterator>
|
|
|
|
#include <QStringView>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <iostream>
|
2023-08-20 18:25:59 +08:00
|
|
|
#include <chrono>
|
2023-07-12 15:58:41 +08:00
|
|
|
|
|
|
|
auto DesktopEntry::parserGroupHeader(const QString &str) noexcept
|
|
|
|
{
|
|
|
|
auto groupHeader = str.sliced(1, str.size() - 2);
|
2023-08-10 14:32:09 +08:00
|
|
|
auto it = m_entryMap.find(groupHeader);
|
|
|
|
if (it == m_entryMap.cend()) {
|
2023-07-12 15:58:41 +08:00
|
|
|
return m_entryMap.insert(groupHeader, {});
|
|
|
|
}
|
2023-08-10 14:32:09 +08:00
|
|
|
return it;
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
|
|
|
|
2023-08-21 16:02:26 +08:00
|
|
|
QString DesktopFile::sourcePath() const noexcept
|
|
|
|
{
|
|
|
|
QFileInfo info(*m_fileSource);
|
|
|
|
return info.absoluteFilePath();
|
|
|
|
}
|
2023-08-20 18:25:59 +08:00
|
|
|
|
2023-08-11 17:46:46 +08:00
|
|
|
DesktopErrorCode DesktopEntry::parseEntry(const QString &str, decltype(m_entryMap)::iterator ¤tGroup) noexcept
|
2023-07-12 15:58:41 +08:00
|
|
|
{
|
2023-07-24 14:12:59 +08:00
|
|
|
if (str.startsWith("#")) {
|
2023-08-11 17:46:46 +08:00
|
|
|
return DesktopErrorCode::NoError;
|
2023-07-24 14:12:59 +08:00
|
|
|
}
|
|
|
|
|
2023-07-12 15:58:41 +08:00
|
|
|
auto splitCharIndex = str.indexOf(']');
|
2023-07-21 14:47:40 +08:00
|
|
|
if (splitCharIndex != -1) {
|
2023-07-12 15:58:41 +08:00
|
|
|
for (; splitCharIndex < str.size(); ++splitCharIndex) {
|
2023-08-10 14:32:09 +08:00
|
|
|
if (str.at(splitCharIndex) == '=') {
|
2023-07-12 15:58:41 +08:00
|
|
|
break;
|
2023-08-10 14:32:09 +08:00
|
|
|
}
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
splitCharIndex = str.indexOf('=');
|
|
|
|
}
|
|
|
|
auto keyStr = str.first(splitCharIndex).trimmed();
|
|
|
|
auto valueStr = str.sliced(splitCharIndex + 1).trimmed();
|
2023-08-10 14:32:09 +08:00
|
|
|
QString key;
|
|
|
|
QString valueKey{defaultKeyStr};
|
2023-07-12 15:58:41 +08:00
|
|
|
|
2023-07-21 14:47:40 +08:00
|
|
|
constexpr auto MainKey = R"re((?<MainKey>[0-9a-zA-Z-]+))re"; // main key. eg.(Name, X-CUSTOM-KEY).
|
|
|
|
constexpr auto Language = R"re((?:[a-z]+))re"; // language of locale postfix. eg.(en, zh)
|
|
|
|
constexpr auto Country = R"re((?:_[A-Z]+))re"; // country of locale postfix. eg.(US, CN)
|
|
|
|
constexpr auto Encoding = R"re((?:\.[0-9A-Z-]+))re"; // encoding of locale postfix. eg.(UFT-8)
|
|
|
|
constexpr auto Modifier = R"re((?:@[a-z=;]+))re"; // modifier of locale postfix. eg(euro;collation=traditional)
|
2023-07-12 15:58:41 +08:00
|
|
|
const static auto validKey =
|
|
|
|
QString("^%1(?:\\[(?<LOCALE>%2%3?%4?%5?)\\])?$").arg(MainKey).arg(Language).arg(Country).arg(Encoding).arg(Modifier);
|
|
|
|
// example: https://regex101.com/r/hylOay/1
|
2023-08-21 18:38:27 +08:00
|
|
|
static QRegularExpression re = []() -> QRegularExpression {
|
|
|
|
QRegularExpression tmp{validKey};
|
|
|
|
tmp.optimize();
|
|
|
|
return tmp;
|
|
|
|
}();
|
|
|
|
|
2023-07-12 15:58:41 +08:00
|
|
|
auto matcher = re.match(keyStr);
|
|
|
|
if (!matcher.hasMatch()) {
|
2023-08-16 17:44:56 +08:00
|
|
|
#ifdef DEBUG_MODE
|
2023-07-12 15:58:41 +08:00
|
|
|
qWarning() << "invalid key: " << keyStr;
|
2023-08-16 17:44:56 +08:00
|
|
|
#endif
|
2023-08-11 17:46:46 +08:00
|
|
|
return DesktopErrorCode::EntryKeyInvalid;
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
key = matcher.captured("MainKey");
|
|
|
|
|
|
|
|
if (auto locale = matcher.captured("LOCALE"); !locale.isEmpty()) {
|
2023-07-21 14:47:40 +08:00
|
|
|
valueKey = locale;
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
2023-08-10 14:32:09 +08:00
|
|
|
|
|
|
|
auto cur = currentGroup->find(key);
|
|
|
|
if (cur == currentGroup->end()) {
|
2023-07-12 15:58:41 +08:00
|
|
|
currentGroup->insert(keyStr, {{valueKey, valueStr}});
|
2023-08-11 17:46:46 +08:00
|
|
|
return DesktopErrorCode::NoError;
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
2023-08-10 14:32:09 +08:00
|
|
|
|
|
|
|
auto value = cur->find(valueKey);
|
|
|
|
if (value == cur->end()) {
|
|
|
|
cur->insert(valueKey, valueStr);
|
2023-08-11 17:46:46 +08:00
|
|
|
return DesktopErrorCode::NoError;
|
2023-08-10 14:32:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
qWarning() << "duplicated postfix and this line will be aborted, maybe format is invalid.\n"
|
|
|
|
<< "exist: " << value.key() << "[" << value.value() << "]"
|
|
|
|
<< "current: " << str;
|
|
|
|
|
2023-08-11 17:46:46 +08:00
|
|
|
return DesktopErrorCode::NoError;
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
|
|
|
|
2023-08-21 16:02:26 +08:00
|
|
|
std::optional<DesktopFile> DesktopFile::createTemporaryDesktopFile(std::unique_ptr<QFile> temporaryFile) noexcept
|
2023-08-20 18:25:59 +08:00
|
|
|
{
|
2023-08-21 16:02:26 +08:00
|
|
|
auto mtime = getFileModifiedTime(*temporaryFile);
|
|
|
|
if (mtime == 0) {
|
|
|
|
qWarning() << "create temporary file failed.";
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
return DesktopFile{std::move(temporaryFile), "", mtime};
|
2023-08-20 18:25:59 +08:00
|
|
|
}
|
|
|
|
|
2023-08-11 17:46:46 +08:00
|
|
|
std::optional<DesktopFile> DesktopFile::searchDesktopFileByPath(const QString &desktopFile, DesktopErrorCode &err) noexcept
|
2023-07-12 15:58:41 +08:00
|
|
|
{
|
2023-08-14 16:30:16 +08:00
|
|
|
constexpr decltype(auto) desktopSuffix = ".desktop";
|
2023-08-10 14:32:09 +08:00
|
|
|
|
2023-08-14 16:30:16 +08:00
|
|
|
if (!desktopFile.endsWith(desktopSuffix)) {
|
2023-08-11 17:46:46 +08:00
|
|
|
qWarning() << "file isn't a desktop file:" << desktopFile;
|
|
|
|
err = DesktopErrorCode::MismatchedFile;
|
|
|
|
return std::nullopt;
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
|
|
|
|
2023-08-11 17:46:46 +08:00
|
|
|
QFileInfo fileinfo{desktopFile};
|
|
|
|
if (!fileinfo.isAbsolute() or !fileinfo.exists()) {
|
2023-07-12 15:58:41 +08:00
|
|
|
qWarning() << "desktop file not found.";
|
2023-08-11 17:46:46 +08:00
|
|
|
err = DesktopErrorCode::NotFound;
|
2023-07-12 15:58:41 +08:00
|
|
|
return std::nullopt;
|
|
|
|
}
|
2023-08-11 17:46:46 +08:00
|
|
|
|
|
|
|
QString path{desktopFile};
|
|
|
|
QString id;
|
|
|
|
|
|
|
|
const auto &XDGDataDirs = getXDGDataDirs();
|
|
|
|
auto idGen = std::any_of(XDGDataDirs.cbegin(), XDGDataDirs.cend(), [&desktopFile](const QString &suffixPath) {
|
|
|
|
return desktopFile.startsWith(suffixPath);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (idGen) {
|
2023-08-14 16:30:16 +08:00
|
|
|
auto tmp = path.chopped(sizeof(desktopSuffix) - 1);
|
2023-08-11 17:46:46 +08:00
|
|
|
auto components = tmp.split(QDir::separator()).toList();
|
|
|
|
auto it = std::find(components.cbegin(), components.cend(), "applications");
|
2023-07-19 17:56:45 +08:00
|
|
|
QString FileId;
|
|
|
|
++it;
|
2023-08-11 17:46:46 +08:00
|
|
|
while (it != components.cend()) {
|
2023-07-19 17:56:45 +08:00
|
|
|
FileId += (*(it++) + "-");
|
2023-08-11 17:46:46 +08:00
|
|
|
}
|
2023-07-24 14:12:59 +08:00
|
|
|
id = FileId.chopped(1); // remove extra "-""
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
2023-08-10 14:32:09 +08:00
|
|
|
|
2023-08-21 16:02:26 +08:00
|
|
|
auto filePtr = std::make_unique<QFile>(std::move(path));
|
|
|
|
|
|
|
|
auto mtime = getFileModifiedTime(*filePtr);
|
|
|
|
|
|
|
|
if (mtime == 0) {
|
2023-08-11 17:46:46 +08:00
|
|
|
err = DesktopErrorCode::OpenFailed;
|
2023-08-10 14:32:09 +08:00
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
2023-08-11 17:46:46 +08:00
|
|
|
err = DesktopErrorCode::NoError;
|
2023-08-21 16:02:26 +08:00
|
|
|
return DesktopFile{std::move(filePtr), std::move(id), mtime};
|
2023-08-10 14:32:09 +08:00
|
|
|
}
|
|
|
|
|
2023-08-11 17:46:46 +08:00
|
|
|
std::optional<DesktopFile> DesktopFile::searchDesktopFileById(const QString &appId, DesktopErrorCode &err) noexcept
|
|
|
|
{
|
|
|
|
auto XDGDataDirs = getXDGDataDirs();
|
2023-08-14 16:30:16 +08:00
|
|
|
constexpr auto desktopSuffix = u8".desktop";
|
2023-08-11 17:46:46 +08:00
|
|
|
|
|
|
|
for (const auto &dir : XDGDataDirs) {
|
2023-08-14 16:30:16 +08:00
|
|
|
auto app = QFileInfo{dir + QDir::separator() + appId + desktopSuffix};
|
2023-08-11 17:46:46 +08:00
|
|
|
while (!app.exists()) {
|
|
|
|
auto filePath = app.absoluteFilePath();
|
|
|
|
auto hyphenIndex = filePath.indexOf('-');
|
|
|
|
if (hyphenIndex == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
filePath.replace(hyphenIndex, 1, QDir::separator());
|
|
|
|
app.setFile(filePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (app.exists()) {
|
|
|
|
return searchDesktopFileByPath(app.absoluteFilePath(), err);
|
|
|
|
}
|
|
|
|
}
|
2023-08-14 16:30:16 +08:00
|
|
|
|
|
|
|
err = DesktopErrorCode::NotFound;
|
2023-08-11 17:46:46 +08:00
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
2023-08-10 14:32:09 +08:00
|
|
|
bool DesktopFile::modified(std::size_t time) const noexcept
|
|
|
|
{
|
|
|
|
return time != m_mtime;
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
|
|
|
|
2023-08-21 16:02:26 +08:00
|
|
|
DesktopErrorCode DesktopEntry::parse(DesktopFile &file) noexcept
|
2023-07-24 14:12:59 +08:00
|
|
|
{
|
2023-08-21 16:02:26 +08:00
|
|
|
DesktopFileGuard guard{file};
|
|
|
|
|
|
|
|
if (!guard.try_open()) {
|
|
|
|
qWarning() << file.sourcePath() << "can't open.";
|
|
|
|
return DesktopErrorCode::OpenFailed;
|
2023-07-24 14:12:59 +08:00
|
|
|
}
|
|
|
|
|
2023-08-21 16:02:26 +08:00
|
|
|
QTextStream stream;
|
|
|
|
stream.setDevice(file.sourceFile());
|
|
|
|
return parse(stream);
|
2023-07-24 14:12:59 +08:00
|
|
|
}
|
|
|
|
|
2023-08-11 17:46:46 +08:00
|
|
|
DesktopErrorCode DesktopEntry::parse(QTextStream &stream) noexcept
|
2023-07-12 15:58:41 +08:00
|
|
|
{
|
2023-08-10 14:32:09 +08:00
|
|
|
if (stream.atEnd()) {
|
2023-08-11 17:46:46 +08:00
|
|
|
return DesktopErrorCode::OpenFailed;
|
2023-08-10 14:32:09 +08:00
|
|
|
}
|
2023-07-12 15:58:41 +08:00
|
|
|
|
|
|
|
stream.setEncoding(QStringConverter::Utf8);
|
|
|
|
decltype(m_entryMap)::iterator currentGroup;
|
|
|
|
|
2023-08-11 17:46:46 +08:00
|
|
|
DesktopErrorCode err{DesktopErrorCode::NoError};
|
2023-07-12 15:58:41 +08:00
|
|
|
while (!stream.atEnd()) {
|
|
|
|
auto line = stream.readLine().trimmed();
|
|
|
|
|
2023-07-24 14:12:59 +08:00
|
|
|
if (line.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-08-21 18:38:27 +08:00
|
|
|
if (line[0] == '[') {
|
|
|
|
if (!(line[line.size() - 1] == ']')) {
|
2023-08-11 17:46:46 +08:00
|
|
|
return DesktopErrorCode::GroupHeaderInvalid;
|
2023-08-10 14:32:09 +08:00
|
|
|
}
|
2023-07-12 15:58:41 +08:00
|
|
|
currentGroup = parserGroupHeader(line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-08-11 17:46:46 +08:00
|
|
|
if (auto error = parseEntry(line, currentGroup); error != DesktopErrorCode::NoError) {
|
2023-08-10 14:32:09 +08:00
|
|
|
err = error;
|
2023-08-16 17:44:56 +08:00
|
|
|
#ifdef DEBUG_MODE
|
2023-07-21 14:47:40 +08:00
|
|
|
qWarning() << "an error occurred,this line will be skipped:" << line;
|
2023-08-16 17:44:56 +08:00
|
|
|
#endif
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2023-07-24 14:12:59 +08:00
|
|
|
std::optional<QMap<QString, DesktopEntry::Value>> DesktopEntry::group(const QString &key) const noexcept
|
2023-07-12 15:58:41 +08:00
|
|
|
{
|
2023-08-10 14:32:09 +08:00
|
|
|
if (auto group = m_entryMap.find(key); group != m_entryMap.cend()) {
|
2023-07-12 15:58:41 +08:00
|
|
|
return *group;
|
2023-08-10 14:32:09 +08:00
|
|
|
}
|
2023-07-24 14:12:59 +08:00
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<DesktopEntry::Value> DesktopEntry::value(const QString &groupKey, const QString &valueKey) const noexcept
|
|
|
|
{
|
|
|
|
const auto &destGroup = group(groupKey);
|
|
|
|
if (!destGroup) {
|
2023-08-16 17:44:56 +08:00
|
|
|
#ifdef DEBUG_MODE
|
2023-07-24 14:12:59 +08:00
|
|
|
qWarning() << "group " << groupKey << " can't be found.";
|
2023-08-16 17:44:56 +08:00
|
|
|
#endif
|
2023-07-24 14:12:59 +08:00
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto it = destGroup->find(valueKey);
|
|
|
|
if (it == destGroup->cend()) {
|
2023-08-16 17:44:56 +08:00
|
|
|
#ifdef DEBUG_MODE
|
2023-07-24 14:12:59 +08:00
|
|
|
qWarning() << "value " << valueKey << " can't be found.";
|
2023-08-16 17:44:56 +08:00
|
|
|
#endif
|
2023-07-24 14:12:59 +08:00
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
return *it;
|
2023-07-12 15:58:41 +08:00
|
|
|
}
|
|
|
|
|
2023-08-10 14:32:09 +08:00
|
|
|
QString DesktopEntry::Value::unescape(const QString &str) noexcept
|
2023-07-12 15:58:41 +08:00
|
|
|
{
|
|
|
|
QString unescapedStr;
|
|
|
|
for (qsizetype i = 0; i < str.size(); ++i) {
|
|
|
|
auto c = str.at(i);
|
|
|
|
if (c != '\\') {
|
|
|
|
unescapedStr.append(c);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (str.at(i + 1).toLatin1()) {
|
|
|
|
default:
|
|
|
|
unescapedStr.append(c);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
unescapedStr.append('\n');
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
unescapedStr.append('\t');
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
unescapedStr.append('\r');
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
unescapedStr.append('\\');
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
case ';':
|
|
|
|
unescapedStr.append(';');
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
unescapedStr.append(' ');
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return unescapedStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DesktopEntry::Value::toString(bool &ok) const noexcept
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
auto str = this->find(defaultKeyStr);
|
2023-08-10 14:32:09 +08:00
|
|
|
if (str == this->end()) {
|
2023-07-12 15:58:41 +08:00
|
|
|
return {};
|
2023-08-10 14:32:09 +08:00
|
|
|
}
|
2023-07-12 15:58:41 +08:00
|
|
|
auto unescapedStr = unescape(*str);
|
|
|
|
constexpr auto controlChars = "\\p{Cc}";
|
|
|
|
constexpr auto asciiChars = "[^\x00-\x7f]";
|
2023-08-10 14:32:09 +08:00
|
|
|
if (unescapedStr.contains(QRegularExpression{controlChars}) and unescapedStr.contains(QRegularExpression{asciiChars})) {
|
2023-07-12 15:58:41 +08:00
|
|
|
return {};
|
2023-08-10 14:32:09 +08:00
|
|
|
}
|
2023-07-12 15:58:41 +08:00
|
|
|
|
|
|
|
ok = true;
|
|
|
|
return unescapedStr;
|
|
|
|
}
|
|
|
|
|
2023-07-21 14:47:40 +08:00
|
|
|
QString DesktopEntry::Value::toLocaleString(const QLocale &locale, bool &ok) const noexcept
|
2023-07-12 15:58:41 +08:00
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
for (auto it = this->constKeyValueBegin(); it != this->constKeyValueEnd(); ++it) {
|
|
|
|
auto [a, b] = *it;
|
|
|
|
if (QLocale{a}.name() == locale.name()) {
|
|
|
|
ok = true;
|
|
|
|
return unescape(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toString(ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DesktopEntry::Value::toIconString(bool &ok) const noexcept
|
|
|
|
{
|
|
|
|
return toString(ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DesktopEntry::Value::toBoolean(bool &ok) const noexcept
|
|
|
|
{
|
2023-07-19 17:56:45 +08:00
|
|
|
ok = false;
|
2023-07-21 14:47:40 +08:00
|
|
|
const auto &str = (*this)[defaultKeyStr];
|
2023-07-19 17:56:45 +08:00
|
|
|
if (str == "true") {
|
|
|
|
ok = true;
|
2023-07-12 15:58:41 +08:00
|
|
|
return true;
|
2023-07-19 17:56:45 +08:00
|
|
|
}
|
|
|
|
if (str == "false") {
|
|
|
|
ok = true;
|
2023-07-12 15:58:41 +08:00
|
|
|
return false;
|
2023-07-19 17:56:45 +08:00
|
|
|
}
|
2023-07-12 15:58:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
float DesktopEntry::Value::toNumeric(bool &ok) const noexcept
|
|
|
|
{
|
2023-07-21 14:47:40 +08:00
|
|
|
const auto &str = (*this)[defaultKeyStr];
|
2023-07-12 15:58:41 +08:00
|
|
|
QVariant v{str};
|
|
|
|
return v.toFloat(&ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDebug operator<<(QDebug debug, const DesktopEntry::Value &v)
|
|
|
|
{
|
|
|
|
QDebugStateSaver saver{debug};
|
2023-07-21 14:47:40 +08:00
|
|
|
debug << static_cast<const QMap<QString, QString> &>(v);
|
2023-07-12 15:58:41 +08:00
|
|
|
return debug;
|
|
|
|
}
|
2023-07-19 17:56:45 +08:00
|
|
|
|
2023-08-11 17:46:46 +08:00
|
|
|
QDebug operator<<(QDebug debug, const DesktopErrorCode &v)
|
2023-07-19 17:56:45 +08:00
|
|
|
{
|
|
|
|
QDebugStateSaver saver{debug};
|
|
|
|
QString errMsg;
|
|
|
|
switch (v) {
|
2023-08-11 17:46:46 +08:00
|
|
|
case DesktopErrorCode::NoError: {
|
2023-07-19 17:56:45 +08:00
|
|
|
errMsg = "no error.";
|
|
|
|
break;
|
|
|
|
}
|
2023-08-11 17:46:46 +08:00
|
|
|
case DesktopErrorCode::NotFound: {
|
2023-07-19 17:56:45 +08:00
|
|
|
errMsg = "file not found.";
|
|
|
|
break;
|
|
|
|
}
|
2023-08-11 17:46:46 +08:00
|
|
|
case DesktopErrorCode::MismatchedFile: {
|
2023-07-19 17:56:45 +08:00
|
|
|
errMsg = "file type is mismatched.";
|
|
|
|
break;
|
|
|
|
}
|
2023-08-11 17:46:46 +08:00
|
|
|
case DesktopErrorCode::InvalidLocation: {
|
2023-07-19 17:56:45 +08:00
|
|
|
errMsg = "file location is invalid, please check $XDG_DATA_DIRS.";
|
|
|
|
break;
|
|
|
|
}
|
2023-08-11 17:46:46 +08:00
|
|
|
case DesktopErrorCode::OpenFailed: {
|
2023-07-19 17:56:45 +08:00
|
|
|
errMsg = "couldn't open the file.";
|
|
|
|
break;
|
|
|
|
}
|
2023-08-11 17:46:46 +08:00
|
|
|
case DesktopErrorCode::GroupHeaderInvalid: {
|
2023-07-19 17:56:45 +08:00
|
|
|
errMsg = "groupHead syntax is invalid.";
|
|
|
|
break;
|
|
|
|
}
|
2023-08-11 17:46:46 +08:00
|
|
|
case DesktopErrorCode::EntryKeyInvalid: {
|
2023-07-19 17:56:45 +08:00
|
|
|
errMsg = "key syntax is invalid.";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug << errMsg;
|
|
|
|
return debug;
|
|
|
|
}
|