mirror of
https://github.com/chylex/Nextcloud-Desktop.git
synced 2025-04-23 05:15:43 +02:00
Fixed slow sharee search in the share dialog
Signed-off-by: allexzander <blackslayer4@gmail.com>
This commit is contained in:
parent
14105d4ec6
commit
9266ecc2e8
@ -28,7 +28,8 @@ OcsShareeJob::OcsShareeJob(AccountPtr account)
|
||||
void OcsShareeJob::getSharees(const QString &search,
|
||||
const QString &itemType,
|
||||
int page,
|
||||
int perPage)
|
||||
int perPage,
|
||||
bool lookup)
|
||||
{
|
||||
setVerb("GET");
|
||||
|
||||
@ -36,6 +37,7 @@ void OcsShareeJob::getSharees(const QString &search,
|
||||
addParam(QString::fromLatin1("itemType"), itemType);
|
||||
addParam(QString::fromLatin1("page"), QString::number(page));
|
||||
addParam(QString::fromLatin1("perPage"), QString::number(perPage));
|
||||
addParam(QString::fromLatin1("lookup"), QVariant(lookup).toString());
|
||||
|
||||
start();
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
*
|
||||
* @param path Path to request shares for (default all shares)
|
||||
*/
|
||||
void getSharees(const QString &search, const QString &itemType, int page = 1, int perPage = 50);
|
||||
void getSharees(const QString &search, const QString &itemType, int page = 1, int perPage = 50, bool lookup = false);
|
||||
signals:
|
||||
/**
|
||||
* Result of the OCS request
|
||||
|
@ -73,14 +73,14 @@ ShareeModel::ShareeModel(const AccountPtr &account, const QString &type, QObject
|
||||
{
|
||||
}
|
||||
|
||||
void ShareeModel::fetch(const QString &search, const ShareeSet &blacklist)
|
||||
void ShareeModel::fetch(const QString &search, const ShareeSet &blacklist, LookupMode lookupMode)
|
||||
{
|
||||
_search = search;
|
||||
_shareeBlacklist = blacklist;
|
||||
auto *job = new OcsShareeJob(_account);
|
||||
connect(job, &OcsShareeJob::shareeJobFinished, this, &ShareeModel::shareesFetched);
|
||||
connect(job, &OcsJob::ocsError, this, &ShareeModel::displayErrorMessage);
|
||||
job->getSharees(_search, _type, 1, 50);
|
||||
job->getSharees(_search, _type, 1, 50, lookupMode == GlobalSearch ? true : false);
|
||||
}
|
||||
|
||||
void ShareeModel::shareesFetched(const QJsonDocument &reply)
|
||||
|
@ -66,10 +66,15 @@ class ShareeModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum LookupMode {
|
||||
LocalSearch = 0,
|
||||
GlobalSearch = 1
|
||||
};
|
||||
|
||||
explicit ShareeModel(const AccountPtr &account, const QString &type, QObject *parent = nullptr);
|
||||
|
||||
using ShareeSet = QVector<QSharedPointer<Sharee>>; // FIXME: make it a QSet<Sharee> when Sharee can be compared
|
||||
void fetch(const QString &search, const ShareeSet &blacklist);
|
||||
void fetch(const QString &search, const ShareeSet &blacklist, LookupMode lookupMode);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "capabilities.h"
|
||||
#include "guiutility.h"
|
||||
#include "thumbnailjob.h"
|
||||
#include "sharee.h"
|
||||
#include "sharemanager.h"
|
||||
#include "theme.h"
|
||||
|
||||
@ -85,6 +84,16 @@ ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account,
|
||||
_completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
|
||||
_ui->shareeLineEdit->setCompleter(_completer);
|
||||
|
||||
auto searchGloballyAction = new QAction(_ui->shareeLineEdit);
|
||||
searchGloballyAction->setIcon(QIcon(":/client/theme/magnifying-glass.svg"));
|
||||
searchGloballyAction->setToolTip(tr("Search globally"));
|
||||
|
||||
connect(searchGloballyAction, &QAction::triggered, this, [this]() {
|
||||
searchForSharees(ShareeModel::GlobalSearch);
|
||||
});
|
||||
|
||||
_ui->shareeLineEdit->addAction(searchGloballyAction, QLineEdit::LeadingPosition);
|
||||
|
||||
_manager = new ShareManager(_account, this);
|
||||
connect(_manager, &ShareManager::sharesFetched, this, &ShareUserGroupWidget::slotSharesFetched);
|
||||
connect(_manager, &ShareManager::shareCreated, this, &ShareUserGroupWidget::getShares);
|
||||
@ -104,7 +113,9 @@ ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account,
|
||||
connect(_ui->shareeLineEdit, &QLineEdit::textEdited,
|
||||
this, &ShareUserGroupWidget::slotLineEditTextEdited, Qt::QueuedConnection);
|
||||
_ui->shareeLineEdit->installEventFilter(this);
|
||||
connect(&_completionTimer, &QTimer::timeout, this, &ShareUserGroupWidget::searchForSharees);
|
||||
connect(&_completionTimer, &QTimer::timeout, this, [this]() {
|
||||
searchForSharees(ShareeModel::LocalSearch);
|
||||
});
|
||||
_completionTimer.setSingleShot(true);
|
||||
_completionTimer.setInterval(600);
|
||||
|
||||
@ -163,9 +174,13 @@ void ShareUserGroupWidget::slotLineEditReturn()
|
||||
_completionTimer.start();
|
||||
}
|
||||
|
||||
|
||||
void ShareUserGroupWidget::searchForSharees()
|
||||
void ShareUserGroupWidget::searchForSharees(ShareeModel::LookupMode lookupMode)
|
||||
{
|
||||
if (_ui->shareeLineEdit->text().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_ui->shareeLineEdit->setEnabled(false);
|
||||
_completionTimer.stop();
|
||||
_pi_sharee.startAnimation();
|
||||
ShareeModel::ShareeSet blacklist;
|
||||
@ -178,7 +193,7 @@ void ShareUserGroupWidget::searchForSharees()
|
||||
blacklist << sw->share()->getShareWith();
|
||||
}
|
||||
_ui->errorLabel->hide();
|
||||
_completerModel->fetch(_ui->shareeLineEdit->text(), blacklist);
|
||||
_completerModel->fetch(_ui->shareeLineEdit->text(), blacklist, lookupMode);
|
||||
}
|
||||
|
||||
void ShareUserGroupWidget::getShares()
|
||||
@ -246,7 +261,7 @@ void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>>
|
||||
scrollArea->setWidget(newViewPort);
|
||||
|
||||
_disableCompleterActivated = false;
|
||||
_ui->shareeLineEdit->setEnabled(true);
|
||||
activateShareeLineEdit();
|
||||
}
|
||||
|
||||
void ShareUserGroupWidget::slotAdjustScrollWidgetSize()
|
||||
@ -275,11 +290,14 @@ void ShareUserGroupWidget::slotPrivateLinkShare()
|
||||
|
||||
void ShareUserGroupWidget::slotShareesReady()
|
||||
{
|
||||
activateShareeLineEdit();
|
||||
|
||||
_pi_sharee.stopAnimation();
|
||||
if (_completerModel->rowCount() == 0) {
|
||||
displayError(0, tr("No results for '%1'").arg(_completerModel->currentSearch()));
|
||||
return;
|
||||
}
|
||||
|
||||
// if no rows are present in the model - complete() will hide the completer
|
||||
_completer->complete();
|
||||
}
|
||||
|
||||
@ -349,7 +367,7 @@ void ShareUserGroupWidget::displayError(int code, const QString &message)
|
||||
qCWarning(lcSharing) << "Sharing error from server" << code << message;
|
||||
_ui->errorLabel->setText(message);
|
||||
_ui->errorLabel->show();
|
||||
_ui->shareeLineEdit->setEnabled(true);
|
||||
activateShareeLineEdit();
|
||||
}
|
||||
|
||||
void ShareUserGroupWidget::slotPrivateLinkOpenBrowser()
|
||||
@ -389,6 +407,12 @@ void ShareUserGroupWidget::customizeStyle()
|
||||
}
|
||||
}
|
||||
|
||||
void ShareUserGroupWidget::activateShareeLineEdit()
|
||||
{
|
||||
_ui->shareeLineEdit->setEnabled(true);
|
||||
_ui->shareeLineEdit->setFocus();
|
||||
}
|
||||
|
||||
ShareUserLine::ShareUserLine(QSharedPointer<Share> share,
|
||||
SharePermissions maxSharingPermissions,
|
||||
bool isFile,
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "accountfwd.h"
|
||||
#include "sharepermissions.h"
|
||||
#include "sharee.h"
|
||||
#include "QProgressIndicator.h"
|
||||
#include <QDialog>
|
||||
#include <QWidget>
|
||||
@ -40,9 +41,7 @@ namespace Ui {
|
||||
class AbstractCredentials;
|
||||
class SyncResult;
|
||||
class Share;
|
||||
class Sharee;
|
||||
class ShareManager;
|
||||
class ShareeModel;
|
||||
|
||||
/**
|
||||
* @brief The ShareDialog (user/group) class
|
||||
@ -73,7 +72,7 @@ private slots:
|
||||
void slotSharesFetched(const QList<QSharedPointer<Share>> &shares);
|
||||
|
||||
void on_shareeLineEdit_textChanged(const QString &text);
|
||||
void searchForSharees();
|
||||
void searchForSharees(ShareeModel::LookupMode lookupMode);
|
||||
void slotLineEditTextEdited(const QString &text);
|
||||
|
||||
void slotLineEditReturn();
|
||||
@ -91,6 +90,8 @@ private slots:
|
||||
private:
|
||||
void customizeStyle();
|
||||
|
||||
void activateShareeLineEdit();
|
||||
|
||||
Ui::ShareUserGroupWidget *_ui;
|
||||
QScrollArea *_parentScrollArea;
|
||||
AccountPtr _account;
|
||||
|
@ -163,5 +163,6 @@
|
||||
<file>theme/add.svg</file>
|
||||
<file>theme/share.svg</file>
|
||||
<file>theme/reply.svg</file>
|
||||
<file>theme/magnifying-glass.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
1
theme/magnifying-glass.svg
Normal file
1
theme/magnifying-glass.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 16 16" height="16" width="16"><g stroke="#000" stroke-width="2" fill="none"><ellipse rx="4" ry="4" cy="6" cx="6"/><path d="m14.3 14.25-5.65-5.65" fill="#fff"/></g></svg>
|
After (image error) Size: 237 B |
Loading…
Reference in New Issue
Block a user