Sharing: feedback when there is no result while searching for an user #4348
authorOlivier Goffart <ogoffart@woboq.com>
Tue, 12 Jan 2016 13:35:35 +0000 (14:35 +0100)
committerOlivier Goffart <ogoffart@woboq.com>
Tue, 12 Jan 2016 13:36:13 +0000 (14:36 +0100)
src/gui/sharee.cpp
src/gui/sharee.h
src/gui/shareusergroupwidget.cpp
src/gui/shareusergroupwidget.h

index 5ff2aff6b28f17f959ffb9fe82cf0038633a7a09..510d4f9f65a4b779af1365aab37d6cced52b12fa 100644 (file)
@@ -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);
 }
 
index 9a99da88d30b8e832fb6200579d45d8f26fe66f9..f91b8acab47f079615a84d7c39de74be122c2225 100644 (file)
@@ -64,8 +64,11 @@ public:
 
     QSharedPointer<Sharee> getSharee(int at);
 
+    QString currentSearch() const { return _search; }
+
 signals:
     void shareesReady();
+    void displayErrorMessage(int code, const QString &);
 
 private slots:
     void shareesFetched(const QVariantMap &reply);
index 898242ee9bd2119944cde855fc9b6d3a909c162c..07b5f473e3eb0e61530fafcd3034719b4d58eda5 100644 (file)
@@ -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<ShareWidget*>()) {
         blacklist << sw->share()->getShareWith();
     }
-
+    _ui->errorLabel->hide();
     _completerModel->fetch(_ui->shareeLineEdit->text(), blacklist);
 
 }
@@ -160,7 +166,6 @@ void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>>
 {
     QScrollArea *scrollArea = _ui->scrollArea;
 
-
     auto newViewPort = new QWidget(scrollArea);
     auto layout = new QVBoxLayout(newViewPort);
 
@@ -190,6 +195,8 @@ void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>>
     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<QSharedPointer<Sharee>>(index.data(Qt::UserRole));
index 0c827d679cd47dfc874d755495a9338b080a81bb..cbe226341f9da6df1c2b6ed6de51358fd368e883 100644 (file)
@@ -123,7 +123,7 @@ private:
 
     bool _resharingAllowed;
     bool _isFile;
-
+    bool _disableCompleterActivated; // in order to avoid that we share the contents twice
     ShareManager *_manager;
 };