editlocallyjob.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) by Claudio Cambra <claudio.cambra@nextcloud.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #pragma once
  15. #include <QObject>
  16. #include "accountstate.h"
  17. #include "syncfileitem.h"
  18. namespace OCC {
  19. class EditLocallyJob;
  20. using EditLocallyJobPtr = QSharedPointer<EditLocallyJob>;
  21. class Folder;
  22. class SyncResult;
  23. class EditLocallyJob : public QObject
  24. {
  25. Q_OBJECT
  26. public:
  27. explicit EditLocallyJob(const QString &userId,
  28. const QString &relPath,
  29. const QString &token,
  30. QObject *parent = nullptr);
  31. [[nodiscard]] static bool isTokenValid(const QString &token);
  32. [[nodiscard]] static bool isRelPathValid(const QString &relPath);
  33. [[nodiscard]] static OCC::Folder *findFolderForFile(const QString &relPath, const QString &userId);
  34. [[nodiscard]] static QString prefixSlashToPath(const QString &path);
  35. signals:
  36. void setupFinished();
  37. void error(const QString &message, const QString &informativeText);
  38. void fileOpened();
  39. public slots:
  40. void startSetup();
  41. void startEditLocally();
  42. private slots:
  43. void fetchRemoteFileParentInfo();
  44. void startSyncBeforeOpening();
  45. void eraseBlacklistRecordForItem();
  46. void startTokenRemoteCheck();
  47. void proceedWithSetup();
  48. void findAfolderAndConstructPaths();
  49. void showError(const QString &message, const QString &informativeText);
  50. void showErrorNotification(const QString &message, const QString &informativeText) const;
  51. void showErrorMessageBox(const QString &message, const QString &informativeText) const;
  52. void remoteTokenCheckResultReceived(const int statusCode);
  53. void slotItemDiscovered(const OCC::SyncFileItemPtr &item);
  54. void slotItemCompleted(const OCC::SyncFileItemPtr &item);
  55. void slotLsColJobFinishedWithError(QNetworkReply *reply);
  56. void slotDirectoryListingIterated(const QString &name, const QMap<QString, QString> &properties);
  57. void openFile();
  58. private:
  59. [[nodiscard]] bool checkIfFileParentSyncIsNeeded(); // returns true if sync will be needed, false otherwise
  60. [[nodiscard]] const QString getRelativePathToRemoteRootForFile() const; // returns either '/' or a (relative path - Folder::remotePath()) for folders pointing to a non-root remote path e.g. '/subfolder' instead of '/'
  61. [[nodiscard]] const QString getRelativePathParent() const;
  62. bool _tokenVerified = false;
  63. AccountStatePtr _accountState;
  64. QString _userId;
  65. QString _relPath; // full remote path for a file (as on the server)
  66. QString _relativePathToRemoteRoot; // (relative path - Folder::remotePath()) for folders pointing to a non-root remote path e.g. '/subfolder' instead of '/'
  67. QString _relPathParent; // a folder where the file resides ('/' if it is in the first level of a remote root, or e.g. a '/subfolder/a/b/c if it resides in a nested folder)
  68. QString _token;
  69. SyncFileItemPtr _fileParentItem;
  70. QString _fileName;
  71. QString _localFilePath;
  72. Folder *_folderForFile = nullptr;
  73. std::unique_ptr<SimpleApiJob> _checkTokenJob;
  74. QMetaObject::Connection _syncTerminatedConnection = {};
  75. };
  76. }