Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Jan 18, 2023
1 parent 90d1bdf commit 97720ee
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 139 deletions.
6 changes: 3 additions & 3 deletions src/gui/filedetails/ShareDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ GridLayout {

readonly property bool isLinkShare: model.shareType === ShareModel.ShareTypeLink
readonly property bool isPlaceholderLinkShare: model.shareType === ShareModel.ShareTypePlaceholderLink
readonly property bool isSecureFileDropLinkShare: model.shareType === ShareModel.ShareTypeSecureFileDropPlaceholderLink
readonly property bool isSecureFileDropPlaceholderLinkShare: model.shareType === ShareModel.ShareTypeSecureFileDropPlaceholderLink
readonly property bool isInternalLinkShare: model.shareType === ShareModel.ShareTypeInternalLink

readonly property string text: model.display ?? ""
Expand Down Expand Up @@ -164,7 +164,7 @@ GridLayout {

imageSource: "image://svgimage-custom-color/add.svg/" + Style.ncTextColor

visible: (root.isPlaceholderLinkShare || root.isSecureFileDropLinkShare) && root.canCreateLinkShares
visible: (root.isPlaceholderLinkShare || root.isSecureFileDropPlaceholderLinkShare) && root.canCreateLinkShares
enabled: visible

onClicked: root.createNewLinkShare()
Expand Down Expand Up @@ -213,7 +213,7 @@ GridLayout {

imageSource: "image://svgimage-custom-color/more.svg/" + Style.ncTextColor

visible: !root.isPlaceholderLinkShare && !root.isSecureFileDropLinkShare && !root.isInternalLinkShare
visible: !root.isPlaceholderLinkShare && !root.isSecureFileDropPlaceholderLinkShare && !root.isInternalLinkShare
enabled: visible

onClicked: root.rootStackView.push(shareDetailsPageComponent, {}, StackView.PushTransition)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/filedetails/ShareDetailsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ Page {
indicator.width: moreMenu.indicatorItemWidth
indicator.height: moreMenu.indicatorItemWidth

checkable: !root.isSecureFileDropLink
checkable: true
checked: root.editingAllowed
text: qsTr("Allow editing")
enabled: !root.waitingForEditingAllowedChange
Expand Down
37 changes: 16 additions & 21 deletions src/gui/filedetails/sharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace {

static const auto placeholderLinkShareId = QStringLiteral("__placeholderLinkShareId__");
static const auto internalLinkShareId = QStringLiteral("__internalLinkShareId__");
static const auto secureFileDropLinkShareId = QStringLiteral("__secureFileDropLinkShareId__");
static const auto secureFileDropPlaceholderLinkShareId = QStringLiteral("__secureFileDropPlaceholderLinkShareId__");

QString createRandomPassword()
{
Expand Down Expand Up @@ -154,7 +154,7 @@ QVariant ShareModel::data(const QModelIndex &index, const int role) const
case EnforcedMaximumExpireDateRole:
return enforcedMaxExpireDateForShare(share);
case IsSecureFileDropLinkRole:
return _isEncryptedRoootFolder && share->getPermissions().testFlag(OCC::SharePermission::SharePermissionCreate);
return _isEncryptedRootFolder && share->getPermissions().testFlag(OCC::SharePermission::SharePermissionCreate);
case PasswordProtectEnabledRole:
return share->isPasswordSet();
case PasswordRole:
Expand Down Expand Up @@ -257,8 +257,8 @@ void ShareModel::updateData()

_numericFileId = fileRecord.numericFileId();

_isEncryptedFile = fileRecord._isE2eEncrypted;
_isEncryptedRoootFolder = fileRecord._isE2eEncrypted && fileRecord.e2eMangledName().isEmpty();
_isEncryptedItem = fileRecord._isE2eEncrypted;
_isEncryptedRootFolder = fileRecord._isE2eEncrypted && fileRecord.e2eMangledName().isEmpty();

// Will get added when shares are fetched if no link shares are fetched
_placeholderLinkShare.reset(new Share(_accountState->account(),
Expand All @@ -275,8 +275,8 @@ void ShareModel::updateData()
_sharePath,
Share::TypeInternalLink));

_secureFileDropLinkShare.reset(new Share(_accountState->account(),
secureFileDropLinkShareId,
_secureFileDropPlaceholderLinkShare.reset(new Share(_accountState->account(),
secureFileDropPlaceholderLinkShareId,
_accountState->account()->id(),
_accountState->account()->davDisplayName(),
_sharePath,
Expand Down Expand Up @@ -337,7 +337,7 @@ void ShareModel::initShareManager()

void ShareModel::handlePlaceholderLinkShare()
{
if (_isEncryptedFile) {
if (_isEncryptedItem) {
return;
}
// We want to add the placeholder if there are no link shares and
Expand Down Expand Up @@ -368,7 +368,7 @@ void ShareModel::handlePlaceholderLinkShare()

void ShareModel::handleSecureFileDropLinkShare()
{
if (!_isEncryptedRoootFolder) {
if (!_isEncryptedRootFolder) {
return;
}
// We want to add the placeholder if there are no link shares and
Expand All @@ -391,9 +391,9 @@ void ShareModel::handleSecureFileDropLinkShare()
}

if (linkSharePresent && secureFileDropLinkSharePresent) {
slotRemoveShareWithId(secureFileDropLinkShareId);
slotRemoveShareWithId(secureFileDropPlaceholderLinkShareId);
} else if (!linkSharePresent && !secureFileDropLinkSharePresent) {
slotAddShare(_secureFileDropLinkShare);
slotAddShare(_secureFileDropPlaceholderLinkShare);
}
}

Expand Down Expand Up @@ -453,7 +453,7 @@ void ShareModel::setupInternalLinkShare()
_accountState->account().isNull() ||
_localPath.isEmpty() ||
_privateLinkUrl.isEmpty() ||
_isEncryptedFile) {
_isEncryptedItem) {
return;
}

Expand Down Expand Up @@ -581,12 +581,7 @@ QString ShareModel::displayStringForShare(const SharePtr &share) const
{
if (const auto linkShare = share.objectCast<LinkShare>()) {

const auto isSecureFileDropShare = [this, linkShare]() {
if (_isEncryptedRoootFolder) {
return linkShare->getPermissions().testFlag(OCC::SharePermission::SharePermissionCreate);
}
return false;
}();
const auto isSecureFileDropShare = _isEncryptedRootFolder && linkShare->getPermissions().testFlag(OCC::SharePermission::SharePermissionCreate);

const auto displayString = isSecureFileDropShare ? tr("Secure filedrop link") : tr("Share link");

Expand Down Expand Up @@ -948,19 +943,19 @@ void ShareModel::setShareNoteFromQml(const QVariant &share, const QString &note)

void ShareModel::createNewLinkShare() const
{
if (_isEncryptedFile && !_isEncryptedFile) {
if (_isEncryptedItem && !_isEncryptedRootFolder) {
qCWarning(lcShareModel) << "Attempt to create a link share for non-root encrypted folder or a file.";
return;
}

if (_manager) {
const auto askOptionalPassword = _accountState->account()->capabilities().sharePublicLinkAskOptionalPassword();
const auto password = askOptionalPassword ? createRandomPassword() : QString();
if (_isEncryptedRoootFolder) {
_manager->createSecureFileDropShare(_sharePath, QString(), password);
if (_isEncryptedRootFolder) {
_manager->createSecureFileDropShare(_sharePath, {}, password);
return;
}
_manager->createLinkShare(_sharePath, QString(), password);
_manager->createLinkShare(_sharePath, {}, password);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/gui/filedetails/sharemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private slots:
bool _hasInitialShareFetchCompleted = false;
SharePtr _placeholderLinkShare;
SharePtr _internalLinkShare;
SharePtr _secureFileDropLinkShare;
SharePtr _secureFileDropPlaceholderLinkShare;

// DO NOT USE QSHAREDPOINTERS HERE.
// QSharedPointers MUST NOT be used with pointers already assigned to other shared pointers.
Expand All @@ -207,8 +207,8 @@ private slots:
QString _sharePath;
SharePermissions _maxSharingPermissions;
QByteArray _numericFileId;
bool _isEncryptedFile = false;
bool _isEncryptedRoootFolder = false;
bool _isEncryptedItem = false;
bool _isEncryptedRootFolder = false;
SyncJournalFileLockInfo _filelockState;
QString _privateLinkUrl;

Expand Down
8 changes: 4 additions & 4 deletions src/gui/sharemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ void ShareManager::createLinkShare(const QString &path,

void ShareManager::createSecureFileDropShare(const QString &path, const QString &name, const QString &password)
{
auto *job = new OcsShareJob(_account);
connect(job, &OcsShareJob::shareJobFinished, this, &ShareManager::slotLinkShareCreated);
connect(job, &OcsJob::ocsError, this, &ShareManager::slotOcsError);
job->createSecureFileDropLinkShare(path, name, password);
const auto createShareJob = new OcsShareJob(_account);
connect(createShareJob, &OcsShareJob::shareJobFinished, this, &ShareManager::slotLinkShareCreated);
connect(createShareJob, &OcsJob::ocsError, this, &ShareManager::slotOcsError);
createShareJob->createSecureFileDropLinkShare(path, name, password);
}

void ShareManager::slotLinkShareCreated(const QJsonDocument &reply)
Expand Down
48 changes: 24 additions & 24 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,35 +871,35 @@ class GetOrCreatePublicLinkShare : public QObject

void SocketApi::command_COPY_SECUREFILEDROP_LINK(const QString &localFile, SocketListener *)
{
auto fileData = FileData::get(localFile);
if (!fileData.folder)
const auto fileData = FileData::get(localFile);
if (!fileData.folder) {
return;
}

AccountPtr account = fileData.folder->accountState()->account();
auto job = new GetOrCreatePublicLinkShare(account, fileData.serverRelativePath, this);
connect(job, &GetOrCreatePublicLinkShare::done, this,
[](const QString &url) { copyUrlToClipboard(url); });
connect(job, &GetOrCreatePublicLinkShare::error, this,
[=]() { emit shareCommandReceived(fileData.localPath); });
job->setIsE2eEncryptedFolder(true);
job->run();
const auto account = fileData.folder->accountState()->account();
const auto getOrCreatePublicLinkShareJob = new GetOrCreatePublicLinkShare(account, fileData.serverRelativePath, this);
connect(getOrCreatePublicLinkShareJob, &GetOrCreatePublicLinkShare::done, this, [](const QString &url) { copyUrlToClipboard(url); });
connect(getOrCreatePublicLinkShareJob, &GetOrCreatePublicLinkShare::error, this, [=]() { emit shareCommandReceived(fileData.localPath); });
getOrCreatePublicLinkShareJob->setIsE2eEncryptedFolder(true);
getOrCreatePublicLinkShareJob->run();
}

void SocketApi::command_COPY_PUBLIC_LINK(const QString &localFile, SocketListener *)
{
auto fileData = FileData::get(localFile);
if (!fileData.folder)
const auto fileData = FileData::get(localFile);
if (!fileData.folder) {
return;
}

AccountPtr account = fileData.folder->accountState()->account();
auto job = new GetOrCreatePublicLinkShare(account, fileData.serverRelativePath, this);
connect(job, &GetOrCreatePublicLinkShare::done, this, [](const QString &url) {
const auto account = fileData.folder->accountState()->account();
const auto getOrCreatePublicLinkShareJob = new GetOrCreatePublicLinkShare(account, fileData.serverRelativePath, this);
connect(getOrCreatePublicLinkShareJob, &GetOrCreatePublicLinkShare::done, this, [](const QString &url) {
copyUrlToClipboard(url);
});
connect(job, &GetOrCreatePublicLinkShare::error, this, [=]() {
connect(getOrCreatePublicLinkShareJob, &GetOrCreatePublicLinkShare::error, this, [=]() {
emit shareCommandReceived(fileData.localPath);
});
job->run();
getOrCreatePublicLinkShareJob->run();
}

// Windows Shell / Explorer pinning fallbacks, see issue: https://github.com/nextcloud/desktop/issues/1599
Expand Down Expand Up @@ -1151,11 +1151,11 @@ void SocketApi::command_GET_STRINGS(const QString &argument, SocketListener *lis
listener->sendMessage(QString("GET_STRINGS:END"));
}

void SocketApi::sendSharingContextMenuOptions(const FileData &fileData, SocketListener *listener, bool isE2eeItem, bool isForRootE2eFolder)
void SocketApi::sendSharingContextMenuOptions(const FileData &fileData, SocketListener *listener, bool isForE2eeItem, bool isForRootE2eeFolder)
{
auto record = fileData.journalRecord();
bool isOnTheServer = record.isValid();
auto flagString = isOnTheServer && (!isE2eeItem || isForRootE2eFolder) ? QLatin1String("::") : QLatin1String(":d:");
const auto record = fileData.journalRecord();
const auto isOnTheServer = record.isValid();
const auto flagString = isOnTheServer && (!isForE2eeItem || isForRootE2eeFolder) ? QLatin1String("::") : QLatin1String(":d:");

auto capabilities = fileData.folder->accountState()->account()->capabilities();
auto theme = Theme::instance();
Expand Down Expand Up @@ -1183,21 +1183,21 @@ void SocketApi::sendSharingContextMenuOptions(const FileData &fileData, SocketLi
&& !capabilities.sharePublicLinkEnforcePassword();

if (canCreateDefaultPublicLink) {
if (isForRootE2eFolder) {
if (isForRootE2eeFolder) {
listener->sendMessage(QLatin1String("MENU_ITEM:COPY_SECUREFILEDROP_LINK") + QLatin1String("::") + tr("Copy secure filedrop link"));
} else {
listener->sendMessage(QLatin1String("MENU_ITEM:COPY_PUBLIC_LINK") + flagString + tr("Copy public link"));
}
} else if (publicLinksEnabled) {
if (isForRootE2eFolder) {
if (isForRootE2eeFolder) {
listener->sendMessage(QLatin1String("MENU_ITEM:MANAGE_PUBLIC_LINKS") + QLatin1String("::") + tr("Copy secure filedrop link"));
} else {
listener->sendMessage(QLatin1String("MENU_ITEM:MANAGE_PUBLIC_LINKS") + flagString + tr("Copy public link"));
}
}
}

if (!isE2eeItem) {
if (!isForE2eeItem) {
listener->sendMessage(QLatin1String("MENU_ITEM:COPY_PRIVATE_LINK") + flagString + tr("Copy internal link"));
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/socketapi/socketapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private slots:
Q_INVOKABLE void command_GET_STRINGS(const QString &argument, OCC::SocketListener *listener);

// Sends the context menu options relating to sharing to listener
void sendSharingContextMenuOptions(const FileData &fileData, SocketListener *listener, bool isE2eeItem, bool isForRootE2eFolder);
void sendSharingContextMenuOptions(const FileData &fileData, SocketListener *listener, bool isForE2eeItem, bool isForRootE2eeFolder);

void sendEncryptFolderCommandMenuEntries(const QFileInfo &fileInfo,
const FileData &fileData,
Expand Down
Loading

0 comments on commit 97720ee

Please sign in to comment.