Skip to content

Commit

Permalink
Merge pull request #37 from lxqt/fix_cur_path
Browse files Browse the repository at this point in the history
Fixed the initial path
  • Loading branch information
tsujan committed May 3, 2024
2 parents 049dc42 + 6e62a0d commit 8937c5c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/filechooser.cpp
Expand Up @@ -164,6 +164,22 @@ namespace LXQt
{
}

// The portal may send us null terminated strings. Make sure to strip the extranous \0
// in favor of the implicit \0.
// QByteArrays are implicitly terminated already.
static QUrl decodeFileName(const QByteArray &name)
{
QByteArray decodedName = name;
while (decodedName.endsWith('\0')) {
decodedName.chop(1);
}
QString str = QFile::decodeName(decodedName);
if (!str.isEmpty()) {
return QUrl::fromLocalFile(str);
}
return QUrl();
}

uint FileChooserPortal::OpenFile(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
Expand Down Expand Up @@ -203,7 +219,7 @@ namespace LXQt
}

if (options.contains(QStringLiteral("current_folder"))) {
currentFolder = QUrl::fromLocalFile(options.value(QStringLiteral("current_folder")).toString());
currentFolder = decodeFileName(options.value(QStringLiteral("current_folder")).toByteArray());
}

ExtractFilters(options, nameFilters, allFilters, selectedNameFilter);
Expand Down Expand Up @@ -314,11 +330,11 @@ namespace LXQt
}

if (options.contains(QStringLiteral("current_folder"))) {
currentFolder = QUrl::fromLocalFile(options.value(QStringLiteral("current_folder")).toString());
currentFolder = decodeFileName(options.value(QStringLiteral("current_folder")).toByteArray());
}

if (options.contains(QStringLiteral("current_file"))) {
currentFile = QUrl::fromLocalFile(options.value(QStringLiteral("current_file")).toString());
currentFile = decodeFileName(options.value(QStringLiteral("current_file")).toByteArray());
}

ExtractFilters(options, nameFilters, allFilters, selectedNameFilter);
Expand Down

0 comments on commit 8937c5c

Please sign in to comment.