Commit 71b5e8df authored by Jonah Brüchert's avatar Jonah Brüchert Committed by Jan Grulich
Browse files

mobile filechooser: Move more logic to c++

parent ee375e8a
......@@ -43,9 +43,8 @@ Kirigami.ScrollablePage {
onCurrentFileChanged: {
if (root.currentFile) {
// Switch into directory of preselected file
var elements = root.currentFile.split("/")
fileNameField.text = elements.pop()
dirModel.folder = "file://" + elements.join("/")
fileNameField.text = DirModelUtils.fileNameOfUrl(root.currentFile)
dirModel.folder = DirModelUtils.directoryOfUrl(root.currentFile)
}
}
......
......@@ -35,6 +35,18 @@ QUrl DirModelUtils::partialUrlForIndex(QUrl url, int index) const
return url;
}
QUrl DirModelUtils::directoryOfUrl(const QString &path) const
{
const int index = path.lastIndexOf(QLatin1Char('/'));
return QUrl::fromLocalFile(path.mid(0, index));
}
QString DirModelUtils::fileNameOfUrl(const QString &path) const
{
const int index = path.lastIndexOf(QLatin1Char('/'));
return path.mid(index + 1);
}
void DirModelUtils::mkdir(const QUrl path) const
{
KIO::mkdir(path);
......
......@@ -15,6 +15,8 @@ public:
Q_INVOKABLE QStringList getUrlParts(const QUrl &url) const;
Q_INVOKABLE QUrl partialUrlForIndex(QUrl url, int index) const;
Q_INVOKABLE QUrl directoryOfUrl(const QString &path) const;
Q_INVOKABLE QString fileNameOfUrl(const QString &path) const;
Q_INVOKABLE void mkdir(const QUrl path) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment