| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
|---|---|
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "gitqlientwidget.h" |
| 6 | #include "services/project/projectservice.h" |
| 7 | |
| 8 | #include <QDir> |
| 9 | #include <QTimer> |
| 10 | |
| 11 | using namespace dpfservice; |
| 12 | GitQlientWidget::GitQlientWidget(QWidget *parent) |
| 13 | : GitQlient(parent) |
| 14 | { |
| 15 | |
| 16 | } |
| 17 | |
| 18 | bool GitQlientWidget::isGitDir(const QString &repoPath) |
| 19 | { |
| 20 | if (repoPath.isEmpty()) |
| 21 | return false; |
| 22 | |
| 23 | QDir dir(repoPath + QDir::separator() + ".git"); |
| 24 | return dir.exists(); |
| 25 | } |
| 26 | |
| 27 | QString GitQlientWidget::getRepositoryPath() const |
| 28 | { |
| 29 | auto activeProjInfo = dpfGetService(ProjectService)->getActiveProjectInfo(); |
| 30 | return activeProjInfo.workspaceFolder(); |
| 31 | } |
| 32 | |
| 33 | void GitQlientWidget::showEvent(QShowEvent *event) |
| 34 | { |
| 35 | GitQlient::showEvent(event); |
| 36 | |
| 37 | int delayTimeToAvoidBlock = 1; |
| 38 | QTimer::singleShot(delayTimeToAvoidBlock, this, [this] { |
| 39 | QString repositoryPath = getRepositoryPath(); |
| 40 | if (isGitDir(repositoryPath)) |
| 41 | setRepositories({repositoryPath}); |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | |
| 46 |