| 1 | #include "toolsgitwidget.h" |
| 2 | #include "ui_toolsgitwidget.h" |
| 3 | #include "../iconsmanager.h" |
| 4 | #include "../settings.h" |
| 5 | #include "../systemconsts.h" |
| 6 | #include "../utils.h" |
| 7 | #include "../mainwindow.h" |
| 8 | |
| 9 | #include <QFileDialog> |
| 10 | |
| 11 | ToolsGitWidget::ToolsGitWidget(const QString& name, const QString& group, QWidget *parent) : |
| 12 | SettingsWidget(name,group,parent), |
| 13 | ui(new Ui::ToolsGitWidget) |
| 14 | { |
| 15 | ui->setupUi(this); |
| 16 | ui->lblGitInfo->setVisible(false); |
| 17 | } |
| 18 | |
| 19 | ToolsGitWidget::~ToolsGitWidget() |
| 20 | { |
| 21 | delete ui; |
| 22 | } |
| 23 | |
| 24 | void ToolsGitWidget::doLoad() |
| 25 | { |
| 26 | ui->txtGitPath->setText(pSettings->vcs().gitPath()); |
| 27 | } |
| 28 | |
| 29 | void ToolsGitWidget::doSave() |
| 30 | { |
| 31 | pSettings->vcs().setGitPath(ui->txtGitPath->text()); |
| 32 | pSettings->vcs().save(); |
| 33 | pMainWindow->applySettings(); |
| 34 | } |
| 35 | |
| 36 | void ToolsGitWidget::updateIcons(const QSize &/*size*/) |
| 37 | { |
| 38 | pIconsManager->setIcon(ui->btnBrowseGit,IconsManager::ACTION_FILE_OPEN_FOLDER); |
| 39 | } |
| 40 | |
| 41 | void ToolsGitWidget::on_btnBrowseGit_clicked() |
| 42 | { |
| 43 | QString filename = QFileDialog::getOpenFileName( |
| 44 | this, |
| 45 | tr("Git Executable" ), |
| 46 | QString(), |
| 47 | tr("All files (%1)" ).arg(ALL_FILE_WILDCARD)); |
| 48 | if (!filename.isEmpty() && fileExists(filename)) { |
| 49 | ui->txtGitPath->setText(filename); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | |
| 54 | void ToolsGitWidget::on_btnTestGit_clicked() |
| 55 | { |
| 56 | QFileInfo fileInfo(ui->txtGitPath->text()); |
| 57 | if (!fileInfo.exists()) { |
| 58 | ui->lblGitInfo->setVisible(false); |
| 59 | return; |
| 60 | } |
| 61 | ui->lblGitInfo->setVisible(true); |
| 62 | ui->lblGitInfo->setText("" ); |
| 63 | QStringList args; |
| 64 | args.append("--version" ); |
| 65 | QString output = runAndGetOutput( |
| 66 | fileInfo.fileName(), |
| 67 | fileInfo.absolutePath(), |
| 68 | args); |
| 69 | ui->lblGitInfo->setText(output); |
| 70 | } |
| 71 | |
| 72 | |