2022-10-26 21:13:38 +03:00
/*
* Copyright ( C ) by Claudio Cambra < claudio . cambra @ nextcloud . com >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful , but
* WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License
* for more details .
*/
# pragma once
# include <QObject>
2022-10-28 20:40:06 +03:00
# include "accountstate.h"
2022-11-04 19:38:59 +03:00
# include "syncfileitem.h"
2022-10-26 21:13:38 +03:00
namespace OCC {
2022-10-29 14:21:56 +03:00
class EditLocallyJob ;
using EditLocallyJobPtr = QSharedPointer < EditLocallyJob > ;
2022-10-28 20:40:06 +03:00
class Folder ;
class SyncResult ;
2022-10-29 14:21:56 +03:00
class EditLocallyJob : public QObject
2022-10-26 21:13:38 +03:00
{
Q_OBJECT
public :
2022-10-29 14:21:56 +03:00
explicit EditLocallyJob ( const QString & userId ,
const QString & relPath ,
const QString & token ,
QObject * parent = nullptr ) ;
2022-10-26 21:13:38 +03:00
[ [ nodiscard ] ] static bool isTokenValid ( const QString & token ) ;
[ [ nodiscard ] ] static bool isRelPathValid ( const QString & relPath ) ;
2022-11-04 19:38:59 +03:00
[ [ nodiscard ] ] static OCC : : Folder * findFolderForFile ( const QString & relPath , const QString & userId ) ;
2022-10-26 21:13:38 +03:00
[ [ nodiscard ] ] static QString prefixSlashToPath ( const QString & path ) ;
signals :
2022-10-28 17:42:57 +03:00
void error ( const QString & message , const QString & informativeText ) ;
2022-11-29 21:07:00 +03:00
void finished ( ) ;
2022-12-08 12:58:58 +03:00
void callShowError ( const QString & message , const QString & informativeText ) ;
2023-04-12 12:06:07 +03:00
2022-10-26 21:13:38 +03:00
public slots :
2022-10-28 17:42:57 +03:00
void startSetup ( ) ;
2022-10-26 21:13:38 +03:00
void startEditLocally ( ) ;
private slots :
2022-11-04 19:38:59 +03:00
void fetchRemoteFileParentInfo ( ) ;
void startSyncBeforeOpening ( ) ;
2022-10-28 21:22:27 +03:00
void startTokenRemoteCheck ( ) ;
2022-10-28 17:42:57 +03:00
void proceedWithSetup ( ) ;
2022-11-04 19:38:59 +03:00
void findAfolderAndConstructPaths ( ) ;
2022-10-28 17:42:57 +03:00
void showError ( const QString & message , const QString & informativeText ) ;
2022-10-26 21:13:38 +03:00
void showErrorNotification ( const QString & message , const QString & informativeText ) const ;
void showErrorMessageBox ( const QString & message , const QString & informativeText ) const ;
2022-10-28 17:42:57 +03:00
void remoteTokenCheckResultReceived ( const int statusCode ) ;
2022-11-04 19:38:59 +03:00
void slotItemDiscovered ( const OCC : : SyncFileItemPtr & item ) ;
void slotItemCompleted ( const OCC : : SyncFileItemPtr & item ) ;
void slotLsColJobFinishedWithError ( QNetworkReply * reply ) ;
void slotDirectoryListingIterated ( const QString & name , const QMap < QString , QString > & properties ) ;
2022-10-26 21:13:38 +03:00
2023-01-09 19:11:33 +03:00
void processLocalItem ( ) ;
2022-10-26 21:13:38 +03:00
void openFile ( ) ;
2022-11-29 21:07:00 +03:00
void lockFile ( ) ;
2022-12-06 15:52:36 +03:00
void fileAlreadyLocked ( ) ;
2023-04-07 18:27:14 +03:00
void fileLockSuccess ( const OCC : : SyncFileItemPtr & item ) ;
2022-11-29 21:07:00 +03:00
void fileLockError ( const QString & errorMessage ) ;
2022-12-06 15:52:36 +03:00
void fileLockProcedureComplete ( const QString & notificationTitle ,
const QString & notificationMessage ,
const bool success ) ;
2022-11-29 21:07:00 +03:00
void disconnectFolderSignals ( ) ;
2022-10-26 21:13:38 +03:00
private :
2022-11-04 19:38:59 +03:00
[ [ nodiscard ] ] bool checkIfFileParentSyncIsNeeded ( ) ; // returns true if sync will be needed, false otherwise
2023-04-07 11:11:55 +03:00
[ [ nodiscard ] ] bool eraseBlacklistRecordForItem ( ) ;
2022-11-04 19:38:59 +03:00
[ [ 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 '/'
[ [ nodiscard ] ] const QString getRelativePathParent ( ) const ;
2022-12-07 15:47:48 +03:00
[ [ nodiscard ] ] static int fileLockTimeRemainingMinutes ( const qint64 lockTime , const qint64 lockTimeOut ) ;
2022-12-06 15:52:36 +03:00
2023-05-11 19:29:58 +03:00
[ [ nodiscard ] ] bool isFileParentItemValid ( ) const ;
2022-10-28 17:42:57 +03:00
bool _tokenVerified = false ;
2022-10-26 21:13:38 +03:00
2023-04-07 18:37:50 +03:00
bool _shouldScheduleFolderSyncAfterFileIsOpened = false ;
2022-10-26 21:13:38 +03:00
AccountStatePtr _accountState ;
2022-10-28 17:42:57 +03:00
QString _userId ;
2022-11-04 19:38:59 +03:00
QString _relPath ; // full remote path for a file (as on the server)
QString _relativePathToRemoteRoot ; // (relative path - Folder::remotePath()) for folders pointing to a non-root remote path e.g. '/subfolder' instead of '/'
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)
2022-10-26 21:13:38 +03:00
QString _token ;
2022-11-04 19:38:59 +03:00
SyncFileItemPtr _fileParentItem ;
2022-10-26 21:13:38 +03:00
QString _fileName ;
QString _localFilePath ;
2022-11-29 21:07:00 +03:00
QString _folderRelativePath ;
2022-10-26 21:13:38 +03:00
Folder * _folderForFile = nullptr ;
2022-11-04 19:38:59 +03:00
QMetaObject : : Connection _syncTerminatedConnection = { } ;
2022-11-29 21:07:00 +03:00
QVector < QMetaObject : : Connection > _folderConnections ;
2022-10-26 21:13:38 +03:00
} ;
}