Skip to content

Commit

Permalink
Add API for autocompletion of directories
Browse files Browse the repository at this point in the history
  • Loading branch information
pktiuk committed Jan 24, 2024
1 parent 31d456c commit 54a8b60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QDirIterator>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
Expand Down Expand Up @@ -1083,6 +1085,25 @@ void AppController::defaultSavePathAction()
setResult(BitTorrent::Session::instance()->savePath().toString());
}

void AppController::getDirectoryAutocompletionAction()
{
requireParams({u"path"_s});

const QString path = params().value(u"path"_s);
const QString dir = path.left(path.lastIndexOf(u'/'));

QDirIterator it(dir, QDir::Dirs | QDir::NoDotAndDotDot | QDir::CaseSensitive);
QStringList dirs;
while (it.hasNext())
{
const QString name = it.next();
if (name.startsWith(path, Qt::CaseSensitive))
dirs.append(name);
}

setResult(QJsonArray::fromStringList(dirs));
}

void AppController::networkInterfaceListAction()
{
QJsonArray ifaceList;
Expand Down
1 change: 1 addition & 0 deletions src/webui/api/appcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private slots:
void preferencesAction();
void setPreferencesAction();
void defaultSavePathAction();
void getDirectoryAutocompletionAction();

void networkInterfaceListAction();
void networkInterfaceAddressListAction();
Expand Down

0 comments on commit 54a8b60

Please sign in to comment.