From 194222afcd5e3fe8f7afe87f3c666b77a64ddc72 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 17 Oct 2024 13:59:23 +0800 Subject: [PATCH 1/7] Add ability to make share sharee displayname more verbose Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 5 +++-- src/gui/filedetails/sharemodel.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index 078e3ccb4a39..f184d1c14662 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -642,7 +642,7 @@ void ShareModel::slotRemoveSharee(const ShareePtr &sharee) Q_EMIT shareesChanged(); } -QString ShareModel::displayStringForShare(const SharePtr &share) const +QString ShareModel::displayStringForShare(const SharePtr &share, const bool verbose) const { if (const auto linkShare = share.objectCast()) { @@ -662,7 +662,8 @@ QString ShareModel::displayStringForShare(const SharePtr &share) const } else if (share->getShareType() == Share::TypeSecureFileDropPlaceholderLink) { return tr("Secure file drop"); } else if (share->getShareWith()) { - return share->getShareWith()->format(); + const auto sharee = share->getShareWith(); + return verbose ? QString{"%1 (%2)"}.arg(sharee->format(), sharee->shareWith()) : sharee->format(); } qCWarning(lcShareModel) << "Unable to provide good display string for share"; diff --git a/src/gui/filedetails/sharemodel.h b/src/gui/filedetails/sharemodel.h index 694f0d37eeb3..e3b8dffe7fff 100644 --- a/src/gui/filedetails/sharemodel.h +++ b/src/gui/filedetails/sharemodel.h @@ -217,7 +217,7 @@ private slots: void slotDeleteE2EeShare(const SharePtr &share) const; private: - [[nodiscard]] QString displayStringForShare(const SharePtr &share) const; + [[nodiscard]] QString displayStringForShare(const SharePtr &share, bool verbose = false) const; [[nodiscard]] QString iconUrlForShare(const SharePtr &share) const; [[nodiscard]] QString avatarUrlForShare(const SharePtr &share) const; [[nodiscard]] long long enforcedMaxExpireDateForShare(const SharePtr &share) const; From 1169c0ba3dc5fcf6451e8d18c2625115f1142976 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 17 Oct 2024 14:00:15 +0800 Subject: [PATCH 2/7] Check for and store indices of shares with duplicate display names Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 32 ++++++++++++++++++++++++++++++ src/gui/filedetails/sharemodel.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index f184d1c14662..b1e60f84f53c 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -486,6 +486,38 @@ void ShareModel::slotSharesFetched(const QList &shares) slotAddShare(share); } + // Perform forward pass on shares and check for duplicate display names; store these indeces so + // we can check for these and display the specific user identifier in the display string later + _duplicateDisplayNameShareIndices.clear(); + const auto shareCount = _shares.count(); + for (auto i = 0; i < shareCount; ++i) { + if (_duplicateDisplayNameShareIndices.contains(i)) { + continue; + } + + const auto sharee = _shares.at(i)->getShareWith(); + if (sharee == nullptr) { + continue; + } + + auto hasDuplicates = false; + for (auto j = i + 1; j < shareCount; ++j) { + const auto otherSharee = _shares.at(j)->getShareWith(); + if (otherSharee == nullptr) { + continue; + } + + if (sharee->format() == otherSharee->format()) { + hasDuplicates = true; // Reassign is faster + _duplicateDisplayNameShareIndices.insert(j); + } + } + + if (hasDuplicates) { + _duplicateDisplayNameShareIndices.insert(i); + } + } + handleLinkShare(); } diff --git a/src/gui/filedetails/sharemodel.h b/src/gui/filedetails/sharemodel.h index e3b8dffe7fff..7fe218717015 100644 --- a/src/gui/filedetails/sharemodel.h +++ b/src/gui/filedetails/sharemodel.h @@ -253,6 +253,7 @@ private slots: QHash _shareIdIndexHash; QHash _shareIdRecentlySetPasswords; QVector _sharees; + QSet _duplicateDisplayNameShareIndices; }; } // namespace OCC From 6d88f04f2e5c98f04d4ad5d56501dcd219f5d8dd Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 17 Oct 2024 14:00:58 +0800 Subject: [PATCH 3/7] Display more verbose share display names for shares that have sharees with identical display names Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index b1e60f84f53c..df275c2daa73 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -90,7 +90,8 @@ QVariant ShareModel::data(const QModelIndex &index, const int role) const { Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid | QAbstractItemModel::CheckIndexOption::ParentIsInvalid)); - const auto share = _shares.at(index.row()); + const auto shareIdx = index.row(); + const auto share = _shares.at(shareIdx); if (!share) { return {}; @@ -138,7 +139,7 @@ QVariant ShareModel::data(const QModelIndex &index, const int role) const switch (role) { case Qt::DisplayRole: - return displayStringForShare(share); + return displayStringForShare(share, _duplicateDisplayNameShareIndices.contains(shareIdx)); case ShareRole: return QVariant::fromValue(share); case ShareTypeRole: From c42617c2f878699bbcdeb82a3b91d7c264452932 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 17 Oct 2024 14:17:12 +0800 Subject: [PATCH 4/7] Make sure to update display of all duplicate display name shares Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index df275c2daa73..96640e51e3ba 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -511,11 +511,15 @@ void ShareModel::slotSharesFetched(const QList &shares) if (sharee->format() == otherSharee->format()) { hasDuplicates = true; // Reassign is faster _duplicateDisplayNameShareIndices.insert(j); + const auto targetIndex = index(j); + dataChanged(targetIndex, targetIndex, {Qt::DisplayRole}); } } if (hasDuplicates) { _duplicateDisplayNameShareIndices.insert(i); + const auto targetIndex = index(i); + dataChanged(targetIndex, targetIndex, {Qt::DisplayRole}); } } From cc4e2591ecb15894d169cc8572c696d7708c584e Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 17 Oct 2024 14:19:37 +0800 Subject: [PATCH 5/7] Clean up check for equality between sharee display names Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index 96640e51e3ba..c864993f9ec0 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -504,16 +504,14 @@ void ShareModel::slotSharesFetched(const QList &shares) auto hasDuplicates = false; for (auto j = i + 1; j < shareCount; ++j) { const auto otherSharee = _shares.at(j)->getShareWith(); - if (otherSharee == nullptr) { + if (otherSharee == nullptr || sharee->format() != otherSharee->format()) { continue; } - if (sharee->format() == otherSharee->format()) { - hasDuplicates = true; // Reassign is faster - _duplicateDisplayNameShareIndices.insert(j); - const auto targetIndex = index(j); - dataChanged(targetIndex, targetIndex, {Qt::DisplayRole}); - } + hasDuplicates = true; // Reassign is faster + _duplicateDisplayNameShareIndices.insert(j); + const auto targetIndex = index(j); + dataChanged(targetIndex, targetIndex, {Qt::DisplayRole}); } if (hasDuplicates) { From 10ff7dddbd4e8c2b81832d406ed99a57ccf7eae0 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 17 Oct 2024 14:48:58 +0800 Subject: [PATCH 6/7] Store duplicate indices as key-value pair with value storing bucket of all duplicates Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 21 +++++++++++---------- src/gui/filedetails/sharemodel.h | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index c864993f9ec0..23f03edf2da5 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -501,23 +501,24 @@ void ShareModel::slotSharesFetched(const QList &shares) continue; } - auto hasDuplicates = false; + const auto duplicateIndices = QSharedPointer>::create(); + const auto handleDuplicateIndex = [this, duplicateIndices](const unsigned int idx) { + duplicateIndices->insert(idx); + _duplicateDisplayNameShareIndices[idx] = duplicateIndices; + const auto targetIdx = index(idx); + dataChanged(targetIdx, targetIdx, {Qt::DisplayRole}); + }; + for (auto j = i + 1; j < shareCount; ++j) { const auto otherSharee = _shares.at(j)->getShareWith(); if (otherSharee == nullptr || sharee->format() != otherSharee->format()) { continue; } - - hasDuplicates = true; // Reassign is faster - _duplicateDisplayNameShareIndices.insert(j); - const auto targetIndex = index(j); - dataChanged(targetIndex, targetIndex, {Qt::DisplayRole}); + handleDuplicateIndex(j); } - if (hasDuplicates) { - _duplicateDisplayNameShareIndices.insert(i); - const auto targetIndex = index(i); - dataChanged(targetIndex, targetIndex, {Qt::DisplayRole}); + if (!duplicateIndices->isEmpty()) { + handleDuplicateIndex(i); } } diff --git a/src/gui/filedetails/sharemodel.h b/src/gui/filedetails/sharemodel.h index 7fe218717015..09d136f1ea0f 100644 --- a/src/gui/filedetails/sharemodel.h +++ b/src/gui/filedetails/sharemodel.h @@ -253,7 +253,8 @@ private slots: QHash _shareIdIndexHash; QHash _shareIdRecentlySetPasswords; QVector _sharees; - QSet _duplicateDisplayNameShareIndices; + // Buckets of sharees with the same display name + QHash>> _duplicateDisplayNameShareIndices; }; } // namespace OCC From d07cb2c69f902cea48ef7b40a6b31deb750b69c9 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 17 Oct 2024 14:49:35 +0800 Subject: [PATCH 7/7] Ensure on removal of share that display string is updated for last (now non-)duplicate share Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index 23f03edf2da5..2a314c3faec6 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -647,10 +647,26 @@ void ShareModel::slotRemoveShareWithId(const QString &shareId) const auto sharee = share->getShareWith(); slotRemoveSharee(sharee); - beginRemoveRows({}, shareIndex.row(), shareIndex.row()); - _shares.removeAt(shareIndex.row()); + const auto shareRow = shareIndex.row(); + beginRemoveRows({}, shareRow, shareRow); + _shares.removeAt(shareRow); endRemoveRows(); + // Handle display name duplicates now. First remove the index from the bucket it was in; then, + // check if this removal means the remaining index in the bucket is no longer a duplicate. + // If this is the case then handle the update for this item too. + const auto duplicateShares = _duplicateDisplayNameShareIndices.value(shareRow); + if (duplicateShares) { + duplicateShares->remove(shareRow); + if (duplicateShares->count() == 1) { + const auto noLongerDuplicateIndex = *(duplicateShares->begin()); + _duplicateDisplayNameShareIndices.remove(noLongerDuplicateIndex); + const auto noLongerDuplicateModelIndex = index(noLongerDuplicateIndex); + Q_EMIT dataChanged(noLongerDuplicateModelIndex, noLongerDuplicateModelIndex, {Qt::DisplayRole}); + } + _duplicateDisplayNameShareIndices.remove(shareRow); + } + handleLinkShare(); Q_EMIT sharesChanged();