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 <QPointer>
28#include <QThread>
29
30class GitBase;
31class GitQlientSettings;
32class GitCache;
33class GitRepoLoader;
34class QCloseEvent;
35class QStackedLayout;
36class Controls;
37class HistoryWidget;
38class DiffWidget;
39class BlameWidget;
40class MergeWidget;
41class GitServerWidget;
42class QTimer;
43class WaitingDlg;
44class GitServerCache;
45class GitTags;
46class ConfigWidget;
47
48namespace Jenkins
49{
50class JenkinsWidget;
51}
52
53namespace GitServer
54{
55class IRestApi;
56}
57
58enum class ControlsMainViews;
59
60namespace Ui
61{
62class MainWindow;
63}
64
65/*!
66 \brief The GitQlientRepo class is the main widget that stores all the subwidgets that act over the repository. This
67 class manages the signals between the different big widgets such as the top widget controls, the repository view, diff,
68 merge and blame & history view.
69
70*/
71class GitQlientRepo : public QFrame
72{
73 Q_OBJECT
74
75signals:
76 /*!
77 \brief Signal triggered when the user wants to open a submodule in a new GitQlientRepo view.
78
79 \param submoduleName The submodule name.
80 */
81 void signalOpenSubmodule(const QString &submoduleName);
82
83 /**
84 * @brief signalLoadRepo Signal used to trigger the data update in a different thread.
85 * @param full Requests a full repository refresh: includes commits and references.
86 */
87 void fullReload();
88
89 void referencesReload();
90
91 void logReload();
92
93 /**
94 * @brief repoOpened Signal triggered when the repo was successfully opened.
95 * @param repoPath The absolute path to the repository opened.
96 */
97 void repoOpened(const QString &repoPath);
98
99 /**
100 * @brief currentBranchChanged Signal triggered whenever the current branch changes.
101 */
102 void currentBranchChanged();
103
104public:
105 /*!
106 \brief Default constructor.
107
108 \param repoPath The path in disk where the repository is located.
109 \param parent The parent widget if needed.
110 */
111 explicit GitQlientRepo(const QSharedPointer<GitBase> &git, const QSharedPointer<GitQlientSettings> &settings,
112 QWidget *parent = nullptr);
113 /*!
114 \brief Destructor.
115
116 */
117 ~GitQlientRepo() override;
118
119 /*!
120 \brief Gets the current working dir.
121
122 \return QString The current working dir.
123 */
124 QString currentDir() const { return mCurrentDir; }
125
126 /**
127 * @brief currentBranch Gets the current branch.
128 * @return QString The current branch.
129 */
130 QString currentBranch() const;
131
132 /*!
133 \brief Sets the repository once the widget is created.
134
135 \param newDir The new repository to be opened.
136 */
137 void setRepository(const QString &newDir);
138
139protected:
140 /*!
141 \brief Overload of the close event cancel any pending loading.
142
143 \param ce The close event.
144 */
145 void closeEvent(QCloseEvent *ce) override;
146
147private:
148 QString mCurrentDir;
149 QSharedPointer<GitCache> mGitQlientCache;
150 QSharedPointer<GitServerCache> mGitServerCache;
151 QSharedPointer<GitBase> mGitBase;
152 QSharedPointer<GitQlientSettings> mSettings;
153 QSharedPointer<GitRepoLoader> mGitLoader;
154 HistoryWidget *mHistoryWidget = nullptr;
155 QStackedLayout *mStackedLayout = nullptr;
156 Controls *mControls = nullptr;
157 DiffWidget *mDiffWidget = nullptr;
158 BlameWidget *mBlameWidget = nullptr;
159 MergeWidget *mMergeWidget = nullptr;
160 GitServerWidget *mGitServerWidget = nullptr;
161 Jenkins::JenkinsWidget *mJenkins = nullptr;
162 ConfigWidget *mConfigWidget = nullptr;
163 QTimer *mAutoFetch = nullptr;
164 QTimer *mAutoFilesUpdate = nullptr;
165 QTimer *mAutoPrUpdater = nullptr;
166 QPointer<WaitingDlg> mWaitDlg;
167 QPair<ControlsMainViews, QWidget *> mPreviousView;
168 QSharedPointer<GitServer::IRestApi> mApi;
169 QSharedPointer<GitTags> mGitTags;
170
171 bool mIsInit = false;
172 QThread *m_loaderThread;
173
174 /*!
175 \brief Performs a light UI update triggered by the QFileSystemWatcher.
176
177 */
178 void updateUiFromWatcher();
179 /*!
180 \brief Opens the diff view with the selected commit from the repository view.
181 \param currentSha The current selected commit SHA.
182 */
183 void openCommitDiff(const QString currentSha);
184 /*!
185 \brief Opens the diff view with the selected SHAs to compare between them.
186
187 \param shas The list of shas to compare between.
188 */
189 void openCommitCompareDiff(const QStringList &shas);
190 /*!
191 \brief Method called when changes are commites through the WIP widget.
192
193 \param ok True if the changes are committed, otherwise false.
194 */
195 void onChangesCommitted();
196 /*!
197 \brief Clears the views and its subwidgets.
198
199 */
200 void clearWindow();
201 /*!
202 \brief Enables or disables the subwidgets.
203
204 \param enabled True if enable, otherwise false,
205 */
206 void setWidgetsEnabled(bool enabled);
207 /*!
208 \brief Shows the history of a file.
209
210 \param fileName The path to the file.
211 */
212 void showFileHistory(const QString &fileName);
213
214 /*!
215 \brief Updates the progress dialog when loading a really huge repository.
216 */
217 void createProgressDialog();
218
219 /**
220 * @brief When the loading finishes this method closes and destroys the dialog.
221 * @param fullReload Indicates that the load finished in the full mode (commits + references).
222 */
223 void onRepoLoadFinished(bool fullReload);
224 /*!
225 \brief Loads the view to show the diff of a specific file.
226
227 \param currentSha The current SHA.
228 \param previousSha The SHA to compare to.
229 \param file The file to show the diff.
230 */
231 void loadFileDiff(const QString &currentSha, const QString &previousSha, const QString &file, bool isCached);
232
233 /*!
234 \brief Shows the history/repository view.
235
236 */
237 void showHistoryView();
238 /*!
239 \brief Shows the Gistory & Blame view.
240
241 */
242 void showBlameView();
243 /*!
244 \brief Shows the diff view. Only accessible if there is at least one open diff.
245
246 */
247 void showDiffView();
248 /*!
249 \brief Configures the merge widget to show the conflicts in that view.
250
251 */
252 void showWarningMerge();
253 /*!
254 * \brief Configures the merge widget when a conflict happens and is due to a cherry-pick. The conflicts are shown in
255 * the merge view.
256 */
257 void showCherryPickConflict(const QStringList &shas = QStringList());
258 /*!
259 * \brief Configures the merge widget when a conflict happens and is due to a pull. The conflicts are shown in the
260 * merge view.
261 */
262 void showPullConflict();
263
264 /*!
265 \brief Shows the merge view.
266 */
267 void showMergeView();
268
269 bool configureGitServer() const;
270
271 /**
272 * @brief showGitServerView Shows the configured git server view.
273 */
274 void showGitServerView();
275
276 /**
277 * @brief showGitServerPrView Shows the configured git server view opening the details of the pull request identified
278 * by the given @p prNumber.
279 * @param prNumber The pull request number to show the details.
280 */
281 void showGitServerPrView(int prNumber);
282
283 /**
284 * @brief showBuildSystemView Shows the build system view.
285 */
286 void showBuildSystemView();
287
288 void showConfig();
289
290 /*!
291 \brief Opens the previous view. This method is used when the diff view is closed and GitQlientRepo must return to
292 the previous one.
293
294 */
295 void showPreviousView();
296 /*!
297 \brief Updated the WIP in the internal cache for this repository.
298
299 */
300 void updateWip();
301
302 /**
303 * @brief focusHistoryOnBranch Opens the graph view and focuses on the SHA of the last commit of the given branch.
304 * @param branch The branch.
305 */
306 void focusHistoryOnBranch(const QString &branch);
307
308 /**
309 * @brief focusHistoryOnPr Opens the graph view and focuses on the SHA of the PR number.
310 * @param prNumber The PR to put the focus on.
311 */
312 void focusHistoryOnPr(int prNumber);
313};
314