1 #pragma once 2 3 #ifndef VERSION_CONTROL_H 4 #define VERSION_CONTROL_H 5 6 #include <QObject> 7 #include <QThread> 8 #include <QMutex> 9 #include <QWaitCondition> 10 #include <QProcess> 11 12 #include "versioncontrolxmlreader.h" 13 14 // Forward Declarations 15 16 class TXshSimpleLevel; 17 class ToonzScene; 18 class TLevelSet; 19 20 //----------------------------------------------------------------------------- 21 22 class VersionControlThread final : public QThread { 23 Q_OBJECT 24 25 bool m_abort; 26 bool m_restart; 27 bool m_getStatus; 28 29 bool m_readOutputOnDone; 30 31 QString m_workingDir; 32 QString m_binary; 33 QStringList m_args; 34 35 QWaitCondition m_condition; 36 37 QProcess *m_process; 38 39 public: 40 QMutex m_mutex; 41 42 VersionControlThread(QObject *parent = 0); 43 ~VersionControlThread(); 44 45 void executeCommand(const QString &workingDir, const QString &binary, 46 const QStringList &args, bool readOutputOnDone = true); 47 48 void getSVNStatus(const QString &path, bool showUpdates = false, 49 bool nonRecursive = false, bool depthInfinity = false); 50 void getSVNStatus(const QString &path, const QStringList &files, 51 bool showUpdates = false, bool nonRecursive = false, 52 bool depthInfinity = false); 53 54 protected: 55 void run() override; 56 57 protected slots: 58 void onStandardOutputReady(); 59 60 signals: 61 void error(const QString &errorString); 62 void done(const QString &response); 63 void outputRetrieved(const QString &text); 64 void statusRetrieved(const QString &xmlResponse); 65 }; 66 67 //----------------------------------------------------------------------------- 68 69 class VersionControlManager final : public QObject { 70 Q_OBJECT 71 72 VersionControlThread m_thread; 73 74 VersionControlManager(); 75 76 //! For set Frame Range 77 ToonzScene *m_scene; 78 TLevelSet *m_levelSet; 79 80 bool m_isRunning; 81 bool m_deleteLater; 82 83 public: 84 static VersionControlManager *instance(); 85 void setFrameRange(TLevelSet *levelSet, bool deleteLater = false); 86 87 protected slots: 88 void onFrameRangeDone(const QString &text); 89 void onError(const QString &text); 90 }; 91 92 //----------------------------------------------------------------------------- 93 94 class VersionControl final : public QObject { 95 Q_OBJECT 96 97 QString m_userName; 98 QString m_password; 99 100 VersionControl(); 101 102 QList<SVNRepository> m_repositories; 103 104 QString m_executablePath; 105 106 public: 107 static VersionControl *instance(); 108 109 // Read Version Control repositories from config files 110 void init(); 111 112 // Check version control version and config file data, return false if there 113 // is some setup issue 114 bool testSetup(); 115 116 bool isFolderUnderVersionControl(const QString &folderPath); 117 setUserName(const QString & userName)118 void setUserName(const QString &userName) { m_userName = userName; } getUserName()119 QString getUserName() const { return m_userName; } 120 setPassword(const QString & password)121 void setPassword(const QString &password) { m_password = password; } getPassword()122 QString getPassword() const { return m_password; } 123 124 // filesToCommit must have relative path to the working dir 125 // Convert QStringList to TFilePath 126 void commit(QWidget *parent, const QString &workingDir, 127 const QStringList &filesToCommit, bool folderOnly, 128 int sceneIconAdded = 0); 129 130 void update(QWidget *parent, const QString &workingDir, 131 const QStringList &filesToUpdate, int sceneIconsCounts, 132 bool folderOnly = true, bool updateToRevision = false, 133 bool nonRecursive = false); 134 void updateAndLock(QWidget *parent, const QString &workingDir, 135 const QStringList &files, int workingRevision, 136 int sceneIconAdded); 137 138 void revert(QWidget *parent, const QString &workingDir, 139 const QStringList &filesToRevert, bool folderOnly, 140 int sceneIconAdded = 0); 141 142 void lock(QWidget *parent, const QString &workingDir, 143 const QStringList &filesToLock, int sceneIconAdded); 144 void unlock(QWidget *parent, const QString &workingDir, 145 const QStringList &filesToUnlock, int sceneIconAdded); 146 147 void lockFrameRange(QWidget *parent, const QString &workingDir, 148 const QString &file, int frameCount); 149 void lockFrameRange(QWidget *parent, const QString &workingDir, 150 const QStringList &files); 151 152 void unlockFrameRange(QWidget *parent, const QString &workingDir, 153 const QString &file); 154 void unlockFrameRange(QWidget *parent, const QString &workingDir, 155 const QStringList &files); 156 157 void showFrameRangeLockInfo(QWidget *parent, const QString &workingDir, 158 const QString &file); 159 void showFrameRangeLockInfo(QWidget *parent, const QString &workingDir, 160 const QStringList &files); 161 162 void commitFrameRange(QWidget *parent, const QString &workingDir, 163 const QString &file); 164 165 void revertFrameRange(QWidget *parent, const QString &workingDir, 166 const QString &file, const QString &tempFileName); 167 168 void deleteFiles(QWidget *parent, const QString &workingDir, 169 const QStringList &filesToDelete, int sceneIconAdded = 0); 170 171 void deleteFolder(QWidget *parent, const QString &workingDir, 172 const QString &folderName); 173 174 void cleanupFolder(QWidget *parent, const QString &workingDir); 175 176 void purgeFolder(QWidget *parent, const QString &workingDir); 177 178 // Utility methods 179 QStringList getSceneContents(const QString &wokingDir, 180 const QString &sceneFileName); 181 182 QStringList getCurrentSceneContents() const; 183 getRepositories()184 QList<SVNRepository> getRepositories() const { return m_repositories; } 185 getExecutablePath()186 QString getExecutablePath() const { return m_executablePath; } 187 188 signals: 189 void commandDone(const QStringList &files); 190 }; 191 192 #endif // VERSION_CONTROL_H 193