From: Claudio Cambra Date: Thu, 13 Oct 2022 21:16:10 +0000 (+0200) Subject: Improve server error handling in the ShareModel X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~11^2~169^2~7 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=0826e8d6baeb9e1ebbcdc5a01662de7a1a655a46;p=nextcloud-desktop.git Improve server error handling in the ShareModel Signed-off-by: Claudio Cambra --- diff --git a/src/gui/filedetails/ShareView.qml b/src/gui/filedetails/ShareView.qml index 43ada6d72..e28019c07 100644 --- a/src/gui/filedetails/ShareView.qml +++ b/src/gui/filedetails/ShareView.qml @@ -56,6 +56,7 @@ ColumnLayout { } errorBox.visible = true; + root.waitingForSharesToChange = false; } onPasswordSetError: if(root.stopWaitingForSharesToChangeOnPasswordError) { diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index c1e38e45b..cb6d97b3a 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -245,13 +245,13 @@ void ShareModel::updateData() _numericFileId = fileRecord.numericFileId(); + // Will get added when shares are fetched if no link shares are fetched _placeholderLinkShare.reset(new Share(_accountState->account(), placeholderLinkShareId, _accountState->account()->id(), _accountState->account()->davDisplayName(), _sharePath, Share::TypePlaceholderLink)); - slotAddShare(_placeholderLinkShare); auto job = new PropfindJob(_accountState->account(), _sharePath); job->setProperties( @@ -261,10 +261,11 @@ void ShareModel::updateData() << "https://owncloud.org/ns:privatelink"); job->setTimeout(10 * 1000); connect(job, &PropfindJob::result, this, &ShareModel::slotPropfindReceived); - connect(job, &PropfindJob::finishedWithError, this, [&]{ + connect(job, &PropfindJob::finishedWithError, this, [&](const QNetworkReply *reply) { qCWarning(lcShareModel) << "Propfind for" << _sharePath << "failed"; _fetchOngoing = false; Q_EMIT fetchOngoingChanged(); + Q_EMIT serverError(reply->error(), reply->errorString()); }); _fetchOngoing = true; @@ -295,11 +296,44 @@ void ShareModel::initShareManager() connect(_manager.data(), &ShareManager::shareCreated, this, [&]{ _manager->fetchShares(_sharePath); }); connect(_manager.data(), &ShareManager::linkShareCreated, this, &ShareModel::slotAddShare); connect(_manager.data(), &ShareManager::linkShareRequiresPassword, this, &ShareModel::requestPasswordForLinkShare); + connect(_manager.data(), &ShareManager::serverError, this, [this](const int code, const QString &message){ + _hasInitialShareFetchCompleted = true; + Q_EMIT hasInitialShareFetchCompletedChanged(); + serverError(code, message); + }); _manager->fetchShares(_sharePath); } } +void ShareModel::handlePlaceholderLinkShare() +{ + // We want to add the placeholder if there are no link shares and + // if we are not already showing the placeholder link share + auto linkSharePresent = false; + auto placeholderLinkSharePresent = false; + + for (const auto &share : _shares) { + const auto shareType = share->getShareType(); + + if (!linkSharePresent && shareType == Share::TypeLink) { + linkSharePresent = true; + } else if (!placeholderLinkSharePresent && shareType == Share::TypePlaceholderLink) { + placeholderLinkSharePresent = true; + } + + if(linkSharePresent && placeholderLinkSharePresent) { + break; + } + } + + if (linkSharePresent && placeholderLinkSharePresent) { + slotRemoveShareWithId(placeholderLinkShareId); + } else if (!linkSharePresent && !placeholderLinkSharePresent) { + slotAddShare(_placeholderLinkShare); + } +} + void ShareModel::slotPropfindReceived(const QVariantMap &result) { _fetchOngoing = false; @@ -341,6 +375,8 @@ void ShareModel::slotSharesFetched(const QList &shares) slotAddShare(share); } + + handlePlaceholderLinkShare(); } void ShareModel::slotAddShare(const SharePtr &share) @@ -350,12 +386,6 @@ void ShareModel::slotAddShare(const SharePtr &share) } const auto shareId = share->getId(); - - // Remove placeholder link share if this is a link share - if(share->getShareType() == Share::TypeLink) { - slotRemoveShareWithId(placeholderLinkShareId); - } - QModelIndex shareModelIndex; if (_shareIdIndexHash.contains(shareId)) { @@ -405,6 +435,7 @@ void ShareModel::slotAddShare(const SharePtr &share) connect(_manager.data(), &ShareManager::serverError, this, &ShareModel::slotServerError); } + handlePlaceholderLinkShare(); Q_EMIT sharesChanged(); } @@ -427,18 +458,7 @@ void ShareModel::slotRemoveShareWithId(const QString &shareId) _shares.removeAt(shareIndex.row()); endRemoveRows(); - // If no link shares then re-add placeholder link share - if (shareIndex.data(ShareModel::ShareTypeRole).toInt() == Share::TypeLink) { - - // Early return if we find another link share - for(const auto &share : _shares) { - if(share->getShareType() == Share::TypeLink) { - return; - } - } - - slotAddShare(_placeholderLinkShare); - } + handlePlaceholderLinkShare(); Q_EMIT sharesChanged(); } diff --git a/src/gui/filedetails/sharemodel.h b/src/gui/filedetails/sharemodel.h index 5262bdf4b..ca431dc32 100644 --- a/src/gui/filedetails/sharemodel.h +++ b/src/gui/filedetails/sharemodel.h @@ -152,6 +152,7 @@ private slots: void resetData(); void updateData(); void initShareManager(); + void handlePlaceholderLinkShare(); void slotPropfindReceived(const QVariantMap &result); void slotServerError(const int code, const QString &message);