File indexing completed on 2024-04-21 05:41:04

0001 /*
0002     SPDX-FileCopyrightText: 2009-2011 Peter Penz <peter.penz19@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef FILEVIEWSVNPLUGIN_H
0008 #define FILEVIEWSVNPLUGIN_H
0009 
0010 #include <Dolphin/KVersionControlPlugin>
0011 
0012 #include <KFileItem>
0013 
0014 #include <QHash>
0015 #include <QProcess>
0016 #include <QTemporaryFile>
0017 
0018 /**
0019  * @brief Subversion implementation for the KVersionControlPlugin interface.
0020  */
0021 class FileViewSvnPlugin : public KVersionControlPlugin
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     FileViewSvnPlugin(QObject* parent, const QList<QVariant>& args);
0027     ~FileViewSvnPlugin() override;
0028     QString fileName() const override;
0029     QString localRepositoryRoot(const QString& directory) const override;
0030     bool beginRetrieval(const QString& directory) override;
0031     void endRetrieval() override;
0032     ItemVersion itemVersion(const KFileItem& item) const override;
0033     QList<QAction*> versionControlActions(const KFileItemList& items) const override;
0034     QList<QAction*> outOfVersionControlActions(const KFileItemList& items) const override;
0035 
0036 Q_SIGNALS:
0037     /// Invokes m_showUpdatesAction->setChecked(checked) on the UI thread.
0038     void setShowUpdatesChecked(bool checked);
0039 
0040     /**
0041      * Is emitted if current SVN directory status got updated. Not necessarily means
0042      * it's changed. Emitted right after #endRetrieval().
0043      */
0044     void versionInfoUpdated();
0045 
0046 private Q_SLOTS:
0047     void updateFiles();
0048     void showLocalChanges();
0049     void commitDialog();
0050     void addFiles();
0051     void removeFiles();
0052     void revertFiles();
0053     void logDialog();
0054     void checkoutDialog();
0055     void cleanupDialog();
0056 
0057     void slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus);
0058     void slotOperationError();
0059 
0060     void slotShowUpdatesToggled(bool checked);
0061 
0062     void revertFiles(const QStringList& filesPath);
0063     void diffFile(const QString& filePath);
0064     void diffAgainstWorkingCopy(const QString& localFilePath, ulong rev);
0065     void diffBetweenRevs(const QString& remoteFilePath, ulong rev1, ulong rev2);
0066     void addFiles(const QStringList& filesPath);
0067     void commitFiles(const QStringList& context, const QString& msg);
0068 
0069 private:
0070     /**
0071      * Executes the command "svn {svnCommand}" for the files that have been
0072      * set by getting the context menu actions (see contextMenuActions()).
0073      * @param infoMsg     Message that should be shown before the command is executed.
0074      * @param errorMsg    Message that should be shown if the execution of the command
0075      *                    has been failed.
0076      * @param operationCompletedMsg
0077      *                    Message that should be shown if the execution of the command
0078      *                    has been completed successfully.
0079      */
0080     void execSvnCommand(const QString& svnCommand,
0081                         const QStringList& arguments,
0082                         const QString& infoMsg,
0083                         const QString& errorMsg,
0084                         const QString& operationCompletedMsg);
0085 
0086     void startSvnCommandProcess();
0087 
0088     QList<QAction*> directoryActions(const KFileItem &directory) const;
0089 
0090     /**
0091      * Checks #item parent directory (or its parent directory and so on) is unversioned.
0092      * @param item Item to check.
0093      * @return True item is in unversioned directory, false otherwise.
0094      */
0095     bool isInUnversionedDir(const KFileItem& item) const;
0096 
0097 private:
0098     bool m_pendingOperation;
0099     QHash<QString, ItemVersion> m_versionInfoHash;
0100 
0101     QAction* m_updateAction;
0102     QAction* m_showLocalChangesAction;
0103     QAction* m_commitAction;
0104     QAction* m_addAction;
0105     QAction* m_removeAction;
0106     QAction* m_revertAction;
0107     QAction* m_showUpdatesAction;
0108     QAction* m_logAction;
0109     QAction* m_checkoutAction;
0110     QAction* m_cleanupAction;
0111 
0112     QString m_command;
0113     QStringList m_arguments;
0114     QString m_errorMsg;
0115     QString m_operationCompletedMsg;
0116 
0117     QWidget* m_parentWidget;
0118 
0119     mutable QString m_contextDir;
0120     mutable KFileItemList m_contextItems;
0121 
0122     QProcess m_process;
0123     QTemporaryFile m_tempFile;
0124 };
0125 #endif // FILEVIEWSVNPLUGIN_H
0126