diff --git a/src/gui/sharee.cpp b/src/gui/sharee.cpp index 0fb98d0de..7f2980622 100644 --- a/src/gui/sharee.cpp +++ b/src/gui/sharee.cpp @@ -56,11 +56,13 @@ Sharee::Type Sharee::type() const ShareeModel::ShareeModel(AccountPtr account, const QString search, const QString type, + const QVector> &shareeBlacklist, QObject *parent) : QAbstractListModel(parent), _account(account), _search(search), - _type(type) + _type(type), + _shareeBlacklist(shareeBlacklist) { } @@ -116,8 +118,25 @@ void ShareeModel::shareesFetched(const QVariantMap &reply) } } - beginInsertRows(QModelIndex(), _sharees.size(), newSharees.size()); - _sharees += newSharees; + // Filter sharees that we have already shared with + QVector> filteredSharees; + foreach(const auto &sharee, newSharees) { + bool found = false; + foreach(const auto &blacklistSharee, _shareeBlacklist) { + if (sharee->type() == blacklistSharee->type() && + sharee->shareWith() == blacklistSharee->shareWith()) { + found = true; + break; + } + } + + if (found == false) { + filteredSharees.append(sharee); + } + } + + beginInsertRows(QModelIndex(), _sharees.size(), filteredSharees.size()); + _sharees += filteredSharees; endInsertRows(); shareesReady(); diff --git a/src/gui/sharee.h b/src/gui/sharee.h index 33a308bdc..ec955441a 100644 --- a/src/gui/sharee.h +++ b/src/gui/sharee.h @@ -57,6 +57,7 @@ public: explicit ShareeModel(AccountPtr account, const QString search, const QString type, + const QVector> &shareeBlacklist, QObject *parent = 0); void fetch(); @@ -79,6 +80,7 @@ private: QString _type; QVector> _sharees; + QVector> _shareeBlacklist; }; } diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index d359fe91f..68f495044 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -83,6 +83,7 @@ void ShareUserGroupWidget::on_searchPushButton_clicked() _completerModel = new ShareeModel(_account, _ui->shareeLineEdit->text(), _isFile ? QLatin1String("file") : QLatin1String("folder"), + _sharees, _completer); connect(_completerModel, SIGNAL(shareesReady()), SLOT(slotUpdateCompletion())); _completerModel->fetch(); @@ -104,11 +105,14 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> const QString versionString = _account->serverVersion(); qDebug() << Q_FUNC_INFO << versionString << "Fetched" << shares.count() << "shares"; + //FIXME QLayoutItem *child; while ((child = _ui->sharesLayout->takeAt(0)) != 0) { delete child; } + _sharees.clear(); + foreach(const auto &share, shares) { if (share->getShareType() == Share::TypeLink) { @@ -117,7 +121,14 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> ShareWidget *s = new ShareWidget(share, this); _ui->sharesLayout->addWidget(s); + + _sharees.append(share->getShareWith()); } + + // Add the current user to _sharees since we can't share with ourself + QSharedPointer currentUser(new Sharee(_account->credentials()->user(), "", Sharee::Type::User)); + _sharees.append(currentUser); + _ui->sharesLayout->invalidate(); } diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h index b14896afc..5da18bce4 100644 --- a/src/gui/shareusergroupwidget.h +++ b/src/gui/shareusergroupwidget.h @@ -21,7 +21,7 @@ #include #include #include - +#include class QCompleter; @@ -36,6 +36,7 @@ class AbstractCredentials; class QuotaInfo; class SyncResult; class Share; +class Sharee; class ShareManager; class ShareeModel; @@ -104,6 +105,7 @@ private: bool _isFile; ShareManager *_manager; + QVector> _sharees; }; }