Skip to content

Commit

Permalink
Fix Matthieu's comments.
Browse files Browse the repository at this point in the history
Signed-off-by: allexzander <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Oct 7, 2022
1 parent a8686d0 commit 816eba4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
38 changes: 16 additions & 22 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
static const char versionC[] = "version";
static const int maxFoldersVersion = 1;

namespace {
static constexpr auto editFileLocallyName = "editFileLocallyName";
}

namespace OCC {

Q_LOGGING_CATEGORY(lcFolderMan, "nextcloud.gui.folder.manager", QtInfoMsg)
Expand Down Expand Up @@ -1492,9 +1488,23 @@ void FolderMan::editFileLocally(const QString &accountDisplayName, const QString
showError(accountFound, tr("Could not find a file for local editing. Make sure its path is valid and it is synced locally."), relPath);
return;
}
folderForFile->setProperty(editFileLocallyName, localFilePath);
folderForFile->startSync();
QObject::connect(folderForFile, &Folder::syncFinished, this, &FolderMan::slotSyncFinishedBeforeOpeningForLocalEditing);
_localFileEditingSyncFinishedConnections.insert(localFilePath, QObject::connect(folderForFile, &Folder::syncFinished, this,
[this, localFilePath](const OCC::SyncResult &result) {
Q_UNUSED(result);
const auto foundConnectionIt = _localFileEditingSyncFinishedConnections.find(localFilePath);
if (foundConnectionIt.value()) {
QObject::disconnect(foundConnectionIt.value());
_localFileEditingSyncFinishedConnections.erase(foundConnectionIt);
}
// In case the VFS mode is enabled and a file is not yet hydrated, we must call QDesktopServices::openUrl
// from a separate thread, or, there will be a freeze. To avoid searching for a specific folder and checking
// if the VFS is enabled - we just always call it from a separate thread.
QtConcurrent::run([localFilePath]() {
QDesktopServices::openUrl(QUrl::fromLocalFile(localFilePath));
Systray::instance()->destroyEditFileLocallyLoadingDialog();
});
}));
}

void FolderMan::trayOverallStatus(const QList<Folder *> &folders,
Expand Down Expand Up @@ -1859,20 +1869,4 @@ void FolderMan::slotConnectToPushNotifications(Account *account)
}
}

void FolderMan::slotSyncFinishedBeforeOpeningForLocalEditing(const OCC::SyncResult &result)
{
Q_UNUSED(result);
const auto folderForFile = qobject_cast<Folder *>(sender());
QObject::disconnect(folderForFile, &Folder::syncFinished, this, &FolderMan::slotSyncFinishedBeforeOpeningForLocalEditing);
const auto localFilePath = folderForFile->property(editFileLocallyName).toString();
folderForFile->setProperty(editFileLocallyName, {});
// In case the VFS mode is enabled and a file is not yet hydrated, we must call QDesktopServices::openUrl from a
// separate thread, or, there will be a freeze. To avoid searching for a specific folder and checking if the VFS is
// enabled - we just always call it from a separate thread.
QtConcurrent::run([localFilePath]() {
QDesktopServices::openUrl(QUrl::fromLocalFile(localFilePath));
Systray::instance()->destroyEditFileLocallyLoadingDialog();
});
}

} // namespace OCC
4 changes: 2 additions & 2 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ private slots:
void slotProcessFilesPushNotification(Account *account);
void slotConnectToPushNotifications(Account *account);

void slotSyncFinishedBeforeOpeningForLocalEditing(const OCC::SyncResult &result);

private:
/** Adds a new folder, does not add it to the account settings and
* does not set an account on the new folder.
Expand Down Expand Up @@ -377,6 +375,8 @@ private slots:

bool _appRestartRequired = false;

QMap<QString, QMetaObject::Connection> _localFileEditingSyncFinishedConnections;

static FolderMan *_instance;
explicit FolderMan(QObject *parent = nullptr);
friend class OCC::Application;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/systray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void Systray::destroyEditFileLocallyLoadingDialog()
return;
}
qCDebug(lcSystray) << "Closing a file local editing dialog...";
QMetaObject::invokeMethod(_editFileLocallyLoadingDialog, "closeDialog");
_editFileLocallyLoadingDialog->deleteLater();
_editFileLocallyLoadingDialog = nullptr;
}

Expand Down
5 changes: 0 additions & 5 deletions src/gui/tray/EditFileLocallyLoadingDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ Window {
readonly property real fontPixelSize: Style.topLinePixelSize * 1.5
readonly property real iconWidth: fontPixelSize * 2

function closeDialog() {
root.close();
Systray.destroyDialog(root);
}

Component.onCompleted: {
Systray.forceWindowInit(root);
x = Screen.width / 2 - width / 2
Expand Down

0 comments on commit 816eba4

Please sign in to comment.