| 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 library 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 <QSet> | 
|---|
| 27 | #include <QWidget> | 
|---|
| 28 |  | 
|---|
| 29 | class QPinnableTabWidget; | 
|---|
| 30 | class InitScreen; | 
|---|
| 31 | class ProgressDlg; | 
|---|
| 32 | class GitConfig; | 
|---|
| 33 | class QStackedLayout; | 
|---|
| 34 | class GitQlientSettings; | 
|---|
| 35 | class GitBase; | 
|---|
| 36 |  | 
|---|
| 37 | /*! | 
|---|
| 38 | \brief The GitQlient class is the MainWindow of the GitQlient application. Is the widget that stores all the tabs about | 
|---|
| 39 | the opened repositories and their submodules. Acts as a bridge between the repository actions performed by the | 
|---|
| 40 | ConfigWidget and the GitQlientWidget. | 
|---|
| 41 |  | 
|---|
| 42 | */ | 
|---|
| 43 | class GitQlient : public QWidget | 
|---|
| 44 | { | 
|---|
| 45 | Q_OBJECT | 
|---|
| 46 |  | 
|---|
| 47 | public: | 
|---|
| 48 | /*! | 
|---|
| 49 | \brief Default constructor. Creates an empty GitQlient instance. | 
|---|
| 50 |  | 
|---|
| 51 | \param parent The parent widget if needed. | 
|---|
| 52 | */ | 
|---|
| 53 | explicit GitQlient(QWidget *parent = nullptr); | 
|---|
| 54 |  | 
|---|
| 55 | /*! | 
|---|
| 56 | \brief Destructor. | 
|---|
| 57 |  | 
|---|
| 58 | */ | 
|---|
| 59 | ~GitQlient() override; | 
|---|
| 60 |  | 
|---|
| 61 | /*! | 
|---|
| 62 | \brief Set the repositories that will be shown. | 
|---|
| 63 |  | 
|---|
| 64 | \param repositories | 
|---|
| 65 | */ | 
|---|
| 66 | void setRepositories(const QStringList &repositories); | 
|---|
| 67 | /*! | 
|---|
| 68 | \brief In case that the GitQlient instance it's already initialize, the user can add arguments to be processed. | 
|---|
| 69 |  | 
|---|
| 70 | \param arguments The list of arguments. | 
|---|
| 71 | \return Returns true if application should continue or false if it should quit. | 
|---|
| 72 | */ | 
|---|
| 73 | bool setArgumentsPostInit(const QStringList &arguments); | 
|---|
| 74 |  | 
|---|
| 75 | /** | 
|---|
| 76 | * @brief restorePinnedRepos This method restores the pinned repos from the last session | 
|---|
| 77 | * @param pinnedRepos The list of repos to restore | 
|---|
| 78 | */ | 
|---|
| 79 | void restorePinnedRepos(); | 
|---|
| 80 |  | 
|---|
| 81 | /*! | 
|---|
| 82 | \brief This method parses all the arguments and configures GitQlient settings with them. Part of the arguments can | 
|---|
| 83 | be a list of repositories to be opened. In that case, the method returns the list of repositories to open in the | 
|---|
| 84 | repos out parameter. | 
|---|
| 85 |  | 
|---|
| 86 | \param arguments Arguments from the command prompt. | 
|---|
| 87 | \param repos Output paramter, repositories to open. | 
|---|
| 88 | \return Returns true if application should continue or false if it should quit. | 
|---|
| 89 | */ | 
|---|
| 90 | static bool parseArguments(const QStringList &arguments, QStringList *repos); | 
|---|
| 91 |  | 
|---|
| 92 | protected: | 
|---|
| 93 | bool eventFilter(QObject *obj, QEvent *event) override; | 
|---|
| 94 |  | 
|---|
| 95 | private: | 
|---|
| 96 | QStackedLayout *mStackedLayout = nullptr; | 
|---|
| 97 | QPinnableTabWidget *mRepos = nullptr; | 
|---|
| 98 | InitScreen *mConfigWidget = nullptr; | 
|---|
| 99 | QSet<QString> mCurrentRepos; | 
|---|
| 100 | QSharedPointer<GitConfig> mGit; | 
|---|
| 101 | ProgressDlg *mProgressDlg = nullptr; | 
|---|
| 102 | QString mPathToOpen; | 
|---|
| 103 |  | 
|---|
| 104 | /*! | 
|---|
| 105 | \brief Opens a QFileDialog to select a repository in the local disk. | 
|---|
| 106 | */ | 
|---|
| 107 | void openRepo(); | 
|---|
| 108 |  | 
|---|
| 109 | /** | 
|---|
| 110 | * @brief Opens a QFileDialog to select a repository in the local disk. | 
|---|
| 111 | * @param path The path of the new repo. | 
|---|
| 112 | */ | 
|---|
| 113 | void openRepoWithPath(const QString &path); | 
|---|
| 114 |  | 
|---|
| 115 | /*! | 
|---|
| 116 | \brief Clones a new repository. | 
|---|
| 117 | */ | 
|---|
| 118 | void cloneRepo(); | 
|---|
| 119 |  | 
|---|
| 120 | /*! | 
|---|
| 121 | \brief Initiates a new local repository. | 
|---|
| 122 | */ | 
|---|
| 123 | void initRepo(); | 
|---|
| 124 |  | 
|---|
| 125 | /** | 
|---|
| 126 | * @brief Updates the progress dialog for cloning repos. | 
|---|
| 127 | * | 
|---|
| 128 | * @param stepDescription The description step. | 
|---|
| 129 | * @param value The numeric value. | 
|---|
| 130 | */ | 
|---|
| 131 | void updateProgressDialog(QString stepDescription, int value); | 
|---|
| 132 |  | 
|---|
| 133 | /** | 
|---|
| 134 | * @brief showError Shows an error occurred during any configuration time. | 
|---|
| 135 | * @param error The error code. | 
|---|
| 136 | * @param description The error description. | 
|---|
| 137 | */ | 
|---|
| 138 | void showError(int error, QString description); | 
|---|
| 139 |  | 
|---|
| 140 | /*! | 
|---|
| 141 | \brief Creates a new GitQlientWidget instance or the repository defined in the \p repoPath value. After that, it | 
|---|
| 142 | adds a new tab in the current widget. | 
|---|
| 143 |  | 
|---|
| 144 | \param repoPath The full path of the repository to be opened. | 
|---|
| 145 | */ | 
|---|
| 146 | void addRepoTab(const QString &repoPath); | 
|---|
| 147 |  | 
|---|
| 148 | /*! | 
|---|
| 149 | \brief Creates a new GitQlientWidget instance or the repository defined in the \p repoPath value. After that, it | 
|---|
| 150 | adds a new tab in the current widget. | 
|---|
| 151 |  | 
|---|
| 152 | \param repoPath The full path of the repository to be opened. | 
|---|
| 153 | */ | 
|---|
| 154 | void addNewRepoTab(const QString &repoPath, bool pinned); | 
|---|
| 155 | /*! | 
|---|
| 156 | \brief Closes a tab. This implies to close all child widgets and remove cache and configuration for that repository | 
|---|
| 157 | until it's opened again. | 
|---|
| 158 |  | 
|---|
| 159 | \param tabIndex The tab index that triggered the close action. | 
|---|
| 160 | */ | 
|---|
| 161 | void closeTab(int tabIndex); | 
|---|
| 162 |  | 
|---|
| 163 | /** | 
|---|
| 164 | * @brief onSuccessOpen Refreshes the UI for the most used and most recent projects lists. | 
|---|
| 165 | * @param fullPath The full path of the project successfully opened. | 
|---|
| 166 | */ | 
|---|
| 167 | void onSuccessOpen(const QString &fullPath); | 
|---|
| 168 |  | 
|---|
| 169 | /** | 
|---|
| 170 | * @brief conditionallyOpenPreConfigDlg Opens the pre-config dialog in case that the repo is open for the very first | 
|---|
| 171 | * time. | 
|---|
| 172 | * @param git The git object to perform Git operations. | 
|---|
| 173 | * @param settings The settings object to store the new values. | 
|---|
| 174 | */ | 
|---|
| 175 | void conditionallyOpenPreConfigDlg(const QSharedPointer<GitBase> &git, | 
|---|
| 176 | const QSharedPointer<GitQlientSettings> &settings); | 
|---|
| 177 |  | 
|---|
| 178 | /** | 
|---|
| 179 | * @brief updateWindowTitle Updates the window title of GitQlient appending the branch of the current repository. | 
|---|
| 180 | * @param currentTabIndex The current tab index used to retrieve the repository. | 
|---|
| 181 | */ | 
|---|
| 182 | void updateWindowTitle(); | 
|---|
| 183 | }; | 
|---|
| 184 |  | 
|---|