From 56fbc43e0e8f1820679b58196b0cae4d2973f3d3 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 078e3ccb4a396..f184d1c146624 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 694f0d37eeb33..e3b8dffe7fff1 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 5d0924c5ab66028169ac0bf6ade78d11d95974d0 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 f184d1c146624..b1e60f84f53cd 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 e3b8dffe7fff1..7fe2187170159 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 e43b7c938a13bf92f4172bd4c1e5c776c19649f3 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 b1e60f84f53cd..df275c2daa738 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 396aeddb0343cf6c40b516c2598d2e1934432174 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 df275c2daa738..96640e51e3ba3 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 37a09aad5ff557f0cd7b1554b45ab5b689c08270 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 96640e51e3ba3..c864993f9ec0a 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 cd1d1f583328fdac494dea8a4e8980c62fe78ea5 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 c864993f9ec0a..23f03edf2da5b 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 7fe2187170159..09d136f1ea0f9 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 e36604271f731ecaa08b66088704b76c2724dae8 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 23f03edf2da5b..2a314c3faec65 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();