From 980010174826e952fcc90cd831d574ecf6292c87 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 12 Jan 2016 14:35:35 +0100 Subject: [PATCH] Sharing: feedback when there is no result while searching for an user #4348 --- src/gui/sharee.cpp | 1 + src/gui/sharee.h | 3 +++ src/gui/shareusergroupwidget.cpp | 24 ++++++++++++++++++------ src/gui/shareusergroupwidget.h | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/gui/sharee.cpp b/src/gui/sharee.cpp index 5ff2aff6b..510d4f9f6 100644 --- a/src/gui/sharee.cpp +++ b/src/gui/sharee.cpp @@ -63,6 +63,7 @@ void ShareeModel::fetch(const QString &search, const ShareeSet &blacklist) _shareeBlacklist = blacklist; OcsShareeJob *job = new OcsShareeJob(_account); connect(job, SIGNAL(shareeJobFinished(QVariantMap)), SLOT(shareesFetched(QVariantMap))); + connect(job, SIGNAL(ocsError(int,QString)), SIGNAL(displayErrorMessage(int,QString))); job->getSharees(_search, _type, 1, 50); } diff --git a/src/gui/sharee.h b/src/gui/sharee.h index 9a99da88d..f91b8acab 100644 --- a/src/gui/sharee.h +++ b/src/gui/sharee.h @@ -64,8 +64,11 @@ public: QSharedPointer getSharee(int at); + QString currentSearch() const { return _search; } + signals: void shareesReady(); + void displayErrorMessage(int code, const QString &); private slots: void shareesFetched(const QVariantMap &reply); diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index 898242ee9..07b5f473e 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -48,7 +48,8 @@ ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account, const QString &sh _account(account), _sharePath(sharePath), _localPath(localPath), - _resharingAllowed(resharingAllowed) + _resharingAllowed(resharingAllowed), + _disableCompleterActivated(false) { setAttribute(Qt::WA_DeleteOnClose); setObjectName("SharingDialogUG"); // required as group for saveGeometry call @@ -63,6 +64,7 @@ ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account, const QString &sh _isFile ? QLatin1String("file") : QLatin1String("folder"), _completer); connect(_completerModel, SIGNAL(shareesReady()), this, SLOT(slotShareesReady())); + connect(_completerModel, SIGNAL(displayErrorMessage(int,QString)), this, SLOT(displayError(int,QString))); _completer->setModel(_completerModel); _completer->setCaseSensitivity(Qt::CaseInsensitive); @@ -107,6 +109,7 @@ void ShareUserGroupWidget::on_shareeLineEdit_textChanged(const QString &) void ShareUserGroupWidget::slotLineEditTextEdited(const QString& text) { + _disableCompleterActivated = false; // First textChanged is called first and we stopped the timer when the text is changed, programatically or not // Then we restart the timer here if the user touched a key if (!text.isEmpty()) { @@ -116,6 +119,7 @@ void ShareUserGroupWidget::slotLineEditTextEdited(const QString& text) void ShareUserGroupWidget::slotLineEditReturn() { + _disableCompleterActivated = false; // did the user type in one of the options? const auto text = _ui->shareeLineEdit->text(); for (int i = 0; i < _completerModel->rowCount(); ++i) { @@ -124,9 +128,11 @@ void ShareUserGroupWidget::slotLineEditReturn() || sharee->displayName() == text || sharee->shareWith() == text) { slotCompleterActivated(_completerModel->index(i)); - break; + // make sure we do not send the same item twice (because return is called when we press + // return to activate an item inthe completer) + _disableCompleterActivated = true; + return; } - } // nothing found? try to refresh completion @@ -146,7 +152,7 @@ void ShareUserGroupWidget::searchForSharees() foreach (auto sw, _ui->scrollArea->findChildren()) { blacklist << sw->share()->getShareWith(); } - + _ui->errorLabel->hide(); _completerModel->fetch(_ui->shareeLineEdit->text(), blacklist); } @@ -160,7 +166,6 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> { QScrollArea *scrollArea = _ui->scrollArea; - auto newViewPort = new QWidget(scrollArea); auto layout = new QVBoxLayout(newViewPort); @@ -190,6 +195,8 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> scrollArea->setMinimumSize(minimumSize); scrollArea->setVisible(!shares.isEmpty()); scrollArea->setWidget(newViewPort); + + _disableCompleterActivated = false; } void ShareUserGroupWidget::slotAdjustScrollWidgetSize() @@ -204,14 +211,19 @@ void ShareUserGroupWidget::slotAdjustScrollWidgetSize() } } - void ShareUserGroupWidget::slotShareesReady() { + if (_completerModel->rowCount() == 0) { + displayError(0, tr("No results for '%1'").arg(_completerModel->currentSearch())); + return; + } _completer->complete(); } void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex & index) { + if (_disableCompleterActivated) + return; // The index is an index from the QCompletion model which is itelf a proxy // model proxying the _completerModel auto sharee = qvariant_cast>(index.data(Qt::UserRole)); diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h index 0c827d679..cbe226341 100644 --- a/src/gui/shareusergroupwidget.h +++ b/src/gui/shareusergroupwidget.h @@ -123,7 +123,7 @@ private: bool _resharingAllowed; bool _isFile; - + bool _disableCompleterActivated; // in order to avoid that we share the contents twice ShareManager *_manager; };