File indexing completed on 2024-04-28 09:36:04

0001 /*
0002     SPDX-FileCopyrightText: 2009-2010 Peter Penz <peter.penz@gmx.at>
0003     SPDX-FileCopyrightText: 2011 Canonical Ltd.
0004     SPDX-FileContributor: Jonathan Riddell <jriddell@ubuntu.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef FILEVIEWBAZAARPLUGIN_H
0010 #define FILEVIEWBAZAARPLUGIN_H
0011 
0012 #include <Dolphin/KVersionControlPlugin>
0013 
0014 #include <KFileItem>
0015 
0016 #include <QHash>
0017 #include <QProcess>
0018 #include <QTemporaryFile>
0019 
0020 /**
0021  * @brief Bazaar (bzr) implementation for the KVersionControlPlugin interface.
0022  */
0023 class FileViewBazaarPlugin : public KVersionControlPlugin
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     FileViewBazaarPlugin(QObject* parent, const QList<QVariant>& args);
0029     ~FileViewBazaarPlugin() override;
0030     QString fileName() const  override;
0031     bool beginRetrieval(const QString& directory)  override;
0032     void endRetrieval() override;
0033     KVersionControlPlugin::ItemVersion itemVersion(const KFileItem& item) const override;
0034     QList<QAction*> versionControlActions(const KFileItemList& items) const override;
0035     QList<QAction*> outOfVersionControlActions(const KFileItemList& items) const override;
0036 
0037 
0038 
0039 private Q_SLOTS:
0040     void updateFiles();
0041     void pullFiles();
0042     void pushFiles();
0043     void showLocalChanges();
0044     void commitFiles();
0045     void addFiles();
0046     void removeFiles();
0047     void log();
0048 
0049     void slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus);
0050     void slotOperationError();
0051 
0052 private:
0053     /**
0054      * Executes the command "bzr {bzrCommand}" for the files that have been
0055      * set by getting the context menu actions (see contextMenuActions()).
0056      * @param infoMsg     Message that should be shown before the command is executed.
0057      * @param errorMsg    Message that should be shown if the execution of the command
0058      *                    has been failed.
0059      * @param operationCompletedMsg
0060      *                    Message that should be shown if the execution of the command
0061      *                    has been completed successfully.
0062      */
0063     void execBazaarCommand(const QString& bzrCommand,
0064                         const QStringList& arguments,
0065                         const QString& infoMsg,
0066                         const QString& errorMsg,
0067                         const QString& operationCompletedMsg);
0068 
0069     void startBazaarCommandProcess();
0070 
0071     QList<QAction*> contextMenuFilesActions(const KFileItemList& items) const;
0072     QList<QAction*> contextMenuDirectoryActions(const QString& directory) const;
0073 
0074     bool m_pendingOperation;
0075     QHash<QString, ItemVersion> m_versionInfoHash;
0076 
0077     QAction* m_updateAction;
0078     QAction* m_pullAction;
0079     QAction* m_pushAction;
0080     QAction* m_showLocalChangesAction;
0081     QAction* m_commitAction;
0082     QAction* m_addAction;
0083     QAction* m_removeAction;
0084     QAction* m_logAction;
0085 
0086     QString m_command;
0087     QStringList m_arguments;
0088     QString m_errorMsg;
0089     QString m_operationCompletedMsg;
0090 
0091     mutable QString m_contextDir;
0092     mutable KFileItemList m_contextItems;
0093 
0094     QProcess m_process;
0095     QTemporaryFile m_tempFile;
0096 };
0097 #endif // FILEVIEWBAZAARPLUGIN_H
0098