| 1 | #pragma once |
| 2 | |
| 3 | /**************************************************************************************** |
| 4 | ** GitQlient is an application to manage and operate one or several Git repositories. With |
| 5 | ** GitQlient you will be able to add commits, branches and manage all the options Git provides. |
| 6 | ** Copyright (C) 2021 Francesc Martinez |
| 7 | ** |
| 8 | ** LinkedIn: www.linkedin.com/in/cescmm/ |
| 9 | ** Web: www.francescmm.com |
| 10 | ** |
| 11 | ** This program is free software; you can redistribute it and/or |
| 12 | ** modify it under the terms of the GNU Lesser General Public |
| 13 | ** License as published by the Free Software Foundation; either |
| 14 | ** version 2 of the License, or (at your option) any later version. |
| 15 | ** |
| 16 | ** This program is distributed in the hope that it will be useful, |
| 17 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | ** Lesser General Public License for more details. |
| 20 | ** |
| 21 | ** You should have received a copy of the GNU Lesser General Public |
| 22 | ** License along with this library; if not, write to the Free Software |
| 23 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 | ***************************************************************************************/ |
| 25 | |
| 26 | #include <QFrame> |
| 27 | #include <QMap> |
| 28 | |
| 29 | class CommitInfoPanel; |
| 30 | class GitBase; |
| 31 | class QPinnableTabWidget; |
| 32 | class IDiffWidget; |
| 33 | class QVBoxLayout; |
| 34 | class FileListWidget; |
| 35 | class GitCache; |
| 36 | class QListWidgetItem; |
| 37 | |
| 38 | /*! |
| 39 | \brief The DiffWidget class creates the layout to display the dif information for both files and commits. |
| 40 | |
| 41 | */ |
| 42 | class DiffWidget : public QFrame |
| 43 | { |
| 44 | Q_OBJECT |
| 45 | |
| 46 | signals: |
| 47 | /*! |
| 48 | \brief Signal triggered when the user wants to see the history and blame of a given file. |
| 49 | |
| 50 | \param fileName The full file name. |
| 51 | */ |
| 52 | void signalShowFileHistory(const QString &fileName); |
| 53 | /*! |
| 54 | \brief Signal triggered when the user close the last diff opened. This signal is used to disable the button in the |
| 55 | Controls widget and return to the last view. |
| 56 | |
| 57 | */ |
| 58 | void signalDiffEmpty(); |
| 59 | |
| 60 | public: |
| 61 | /*! |
| 62 | \brief Default constructor. |
| 63 | |
| 64 | \param git The git object to perform Git operations. |
| 65 | \param cache The internal repository cache for the repository. |
| 66 | \param parent The parent wiget if needed. |
| 67 | */ |
| 68 | explicit DiffWidget(const QSharedPointer<GitBase> git, QSharedPointer<GitCache> cache, QWidget *parent = nullptr); |
| 69 | /*! |
| 70 | \brief Destructor |
| 71 | |
| 72 | */ |
| 73 | ~DiffWidget() override; |
| 74 | |
| 75 | /*! |
| 76 | \brief Reloads the information currently shown in the diff. |
| 77 | |
| 78 | */ |
| 79 | void reload(); |
| 80 | |
| 81 | /*! |
| 82 | \brief Clears the information in the current diff. |
| 83 | |
| 84 | */ |
| 85 | void clear() const; |
| 86 | /*! |
| 87 | \brief Loads a file diff. |
| 88 | |
| 89 | \param sha The current SHA as base. |
| 90 | \param previousSha The SHA to compare to. |
| 91 | \param file The file to show the diff of. |
| 92 | \return bool Returns true if the file diff was loaded correctly. |
| 93 | */ |
| 94 | bool loadFileDiff(const QString &sha, const QString &previousSha, const QString &file, bool isCached); |
| 95 | /*! |
| 96 | \brief Loads a full commit diff. |
| 97 | |
| 98 | \param sha The base SHA. |
| 99 | \param parentSha The SHA to compare to. |
| 100 | \return True if the load was successful, otherwise false. |
| 101 | */ |
| 102 | bool loadCommitDiff(const QString &sha, const QString &parentSha); |
| 103 | |
| 104 | private: |
| 105 | QSharedPointer<GitBase> mGit; |
| 106 | QSharedPointer<GitCache> mCache; |
| 107 | CommitInfoPanel *mInfoPanelBase = nullptr; |
| 108 | CommitInfoPanel *mInfoPanelParent = nullptr; |
| 109 | QPinnableTabWidget *mCenterStackedWidget = nullptr; |
| 110 | QMap<QString, IDiffWidget *> mDiffWidgets; |
| 111 | FileListWidget *fileListWidget = nullptr; |
| 112 | QString mCurrentSha; |
| 113 | QString mParentSha; |
| 114 | |
| 115 | /*! |
| 116 | \brief When the user selects a different diff from a different tab, it changes the information in the commit info |
| 117 | panel. |
| 118 | |
| 119 | \param index The new selected index. |
| 120 | */ |
| 121 | void changeSelection(int index); |
| 122 | |
| 123 | /** |
| 124 | * @brief onTabClosed Removes the IDiffWidget from the map. |
| 125 | * @param index The index to be closed. |
| 126 | */ |
| 127 | void onTabClosed(int index); |
| 128 | |
| 129 | void onDoubleClick(QListWidgetItem *item); |
| 130 | }; |
| 131 | |