diff options
-rw-r--r-- | src/gui/sharee.cpp | 25 | ||||
-rw-r--r-- | src/gui/sharee.h | 2 | ||||
-rw-r--r-- | src/gui/shareusergroupwidget.cpp | 11 | ||||
-rw-r--r-- | src/gui/shareusergroupwidget.h | 4 |
4 files changed, 38 insertions, 4 deletions
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<QSharedPointer<Sharee>> &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<QSharedPointer<Sharee>> 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<QSharedPointer<Sharee>> &shareeBlacklist, QObject *parent = 0); void fetch(); @@ -79,6 +80,7 @@ private: QString _type; QVector<QSharedPointer<Sharee>> _sharees; + QVector<QSharedPointer<Sharee>> _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<QSharedPointer<Share>> 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<QSharedPointer<Share>> 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<Sharee> 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 <QVariantMap> #include <QSharedPointer> #include <QList> - +#include <QVector> 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<QSharedPointer<Sharee>> _sharees; }; } |