Merge pull request #5885 from nextcloud/bugfix/sharing-api-disabled-share-view

Disable share view completely when server does not support/has disabled file sharing
This commit is contained in:
Claudio Cambra 2023-07-18 15:58:13 +02:00 committed by GitHub
commit 1f9329c4fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 15 deletions

View file

@ -47,13 +47,17 @@ Page {
Connections { Connections {
target: Systray target: Systray
function onShowFileDetailsPage(fileLocalPath, page) { function onShowFileDetailsPage(fileLocalPath, page) {
if(fileLocalPath === root.localPath) { if (!root.fileDetails.sharingAvailable && page == Systray.FileDetailsPage.Sharing) {
return;
}
if (fileLocalPath === root.localPath) {
switch(page) { switch(page) {
case Systray.FileDetailsPage.Activity: case Systray.FileDetailsPage.Activity:
swipeView.currentIndex = fileActivityView.swipeIndex; swipeView.currentIndex = fileActivityView.swipeIndex;
break; break;
case Systray.FileDetailsPage.Sharing: case Systray.FileDetailsPage.Sharing:
swipeView.currentIndex = shareView.swipeIndex; swipeView.currentIndex = shareViewLoader.swipeIndex;
break; break;
} }
} }
@ -218,6 +222,7 @@ Page {
Layout.rightMargin: root.intendedPadding Layout.rightMargin: root.intendedPadding
padding: 0 padding: 0
background: null
NCTabButton { NCTabButton {
svgCustomColorSource: "image://svgimage-custom-color/activity.svg" svgCustomColorSource: "image://svgimage-custom-color/activity.svg"
@ -227,10 +232,13 @@ Page {
} }
NCTabButton { NCTabButton {
width: visible ? implicitWidth : 0
height: visible ? implicitHeight : 0
svgCustomColorSource: "image://svgimage-custom-color/share.svg" svgCustomColorSource: "image://svgimage-custom-color/share.svg"
text: qsTr("Sharing") text: qsTr("Sharing")
checked: swipeView.currentIndex === shareView.swipeIndex checked: swipeView.currentIndex === shareViewLoader.swipeIndex
onClicked: swipeView.currentIndex = shareView.swipeIndex onClicked: swipeView.currentIndex = shareViewLoader.swipeIndex
visible: root.fileDetails.sharingAvailable
} }
} }
} }
@ -244,7 +252,7 @@ Page {
FileActivityView { FileActivityView {
id: fileActivityView id: fileActivityView
property int swipeIndex: SwipeView.index readonly property int swipeIndex: SwipeView.index
delegateHorizontalPadding: root.intendedPadding delegateHorizontalPadding: root.intendedPadding
@ -253,18 +261,28 @@ Page {
iconSize: root.iconSize iconSize: root.iconSize
} }
ShareView { Loader {
id: shareView id: shareViewLoader
property int swipeIndex: SwipeView.index readonly property int swipeIndex: SwipeView.index
accountState: root.accountState width: swipeView.width
localPath: root.localPath height: swipeView.height
fileDetails: root.fileDetails active: root.fileDetails.sharingAvailable
horizontalPadding: root.intendedPadding
iconSize: root.iconSize sourceComponent: ShareView {
rootStackView: root.rootStackView id: shareView
backgroundsVisible: root.backgroundsVisible
anchors.fill: parent
accountState: root.accountState
localPath: root.localPath
fileDetails: root.fileDetails
horizontalPadding: root.intendedPadding
iconSize: root.iconSize
rootStackView: root.rootStackView
backgroundsVisible: root.backgroundsVisible
}
} }
} }
} }

View file

@ -62,6 +62,11 @@ void FileDetails::setLocalPath(const QString &localPath)
connect(&_fileWatcher, &QFileSystemWatcher::fileChanged, this, &FileDetails::refreshFileDetails); connect(&_fileWatcher, &QFileSystemWatcher::fileChanged, this, &FileDetails::refreshFileDetails);
const auto folder = FolderMan::instance()->folderForPath(_localPath); const auto folder = FolderMan::instance()->folderForPath(_localPath);
if (!folder) {
qCWarning(lcFileDetails) << "No folder found for path:" << _localPath << "will not load file details.";
return;
}
const auto file = _localPath.mid(folder->cleanPath().length() + 1); const auto file = _localPath.mid(folder->cleanPath().length() + 1);
if (!folder->journalDb()->getFileRecord(file, &_fileRecord)) { if (!folder->journalDb()->getFileRecord(file, &_fileRecord)) {
@ -74,6 +79,8 @@ void FileDetails::setLocalPath(const QString &localPath)
updateLockExpireString(); updateLockExpireString();
updateFileTagModel(folder); updateFileTagModel(folder);
_sharingAvailable = folder->accountState()->account()->capabilities().shareAPI();
Q_EMIT fileChanged(); Q_EMIT fileChanged();
} }
@ -172,4 +179,9 @@ void FileDetails::updateFileTagModel(const Folder * const folder)
Q_EMIT fileTagModelChanged(); Q_EMIT fileTagModelChanged();
} }
bool FileDetails::sharingAvailable() const
{
return _sharingAvailable;
}
} // namespace OCC } // namespace OCC

View file

@ -38,6 +38,7 @@ class FileDetails : public QObject
Q_PROPERTY(QString lockExpireString READ lockExpireString NOTIFY lockExpireStringChanged) Q_PROPERTY(QString lockExpireString READ lockExpireString NOTIFY lockExpireStringChanged)
Q_PROPERTY(bool isFolder READ isFolder NOTIFY isFolderChanged) Q_PROPERTY(bool isFolder READ isFolder NOTIFY isFolderChanged)
Q_PROPERTY(FileTagModel* fileTagModel READ fileTagModel NOTIFY fileTagModelChanged) Q_PROPERTY(FileTagModel* fileTagModel READ fileTagModel NOTIFY fileTagModelChanged)
Q_PROPERTY(bool sharingAvailable READ sharingAvailable NOTIFY fileChanged)
public: public:
explicit FileDetails(QObject *parent = nullptr); explicit FileDetails(QObject *parent = nullptr);
@ -50,6 +51,7 @@ public:
[[nodiscard]] QString lockExpireString() const; [[nodiscard]] QString lockExpireString() const;
[[nodiscard]] bool isFolder() const; [[nodiscard]] bool isFolder() const;
[[nodiscard]] FileTagModel *fileTagModel() const; [[nodiscard]] FileTagModel *fileTagModel() const;
[[nodiscard]] bool sharingAvailable() const;
public slots: public slots:
void setLocalPath(const QString &localPath); void setLocalPath(const QString &localPath);
@ -80,6 +82,7 @@ private:
QLocale _locale; QLocale _locale;
std::unique_ptr<FileTagModel> _fileTagModel; std::unique_ptr<FileTagModel> _fileTagModel;
bool _sharingAvailable = true;
}; };
} // namespace OCC } // namespace OCC