| 1 | #include "InitialRepoConfig.h" | 
|---|
| 2 | #include "ui_InitialRepoConfig.h" | 
|---|
| 3 |  | 
|---|
| 4 | #include <CredentialsDlg.h> | 
|---|
| 5 | #include <GitConfig.h> | 
|---|
| 6 | #include <GitCredentials.h> | 
|---|
| 7 | #include <GitQlientSettings.h> | 
|---|
| 8 | #include <GitQlientStyles.h> | 
|---|
| 9 |  | 
|---|
| 10 | InitialRepoConfig::InitialRepoConfig(const QSharedPointer<GitBase> &git, | 
|---|
| 11 | const QSharedPointer<GitQlientSettings> &settings, QWidget *parent) | 
|---|
| 12 | : QDialog(parent) | 
|---|
| 13 | , ui(new Ui::InitialRepoConfig) | 
|---|
| 14 | , mGit(git) | 
|---|
| 15 | , mSettings(settings) | 
|---|
| 16 | { | 
|---|
| 17 | setAttribute(Qt::WA_DeleteOnClose); | 
|---|
| 18 |  | 
|---|
| 19 | ui->setupUi(this); | 
|---|
| 20 |  | 
|---|
| 21 | setStyleSheet(GitQlientStyles::getInstance()->getStyles()); | 
|---|
| 22 |  | 
|---|
| 23 | ui->autoFetch->setValue(mSettings->localValue( "AutoFetch", 5).toInt()); | 
|---|
| 24 | ui->pruneOnFetch->setChecked(settings->localValue( "PruneOnFetch", true).toBool()); | 
|---|
| 25 | ui->updateOnPull->setChecked(settings->localValue( "UpdateOnPull", false).toBool()); | 
|---|
| 26 | ui->sbMaxCommits->setValue(settings->localValue( "MaxCommits", 0).toInt()); | 
|---|
| 27 |  | 
|---|
| 28 | QScopedPointer<GitConfig> gitConfig(new GitConfig(git)); | 
|---|
| 29 |  | 
|---|
| 30 | const auto url = gitConfig->getServerUrl(); | 
|---|
| 31 | ui->credentialsFrames->setVisible(url.startsWith( "https")); | 
|---|
| 32 |  | 
|---|
| 33 | connect(ui->buttonGroup, SIGNAL(buttonClicked(QAbstractButton *)), this, | 
|---|
| 34 | SLOT(onCredentialsOptionChanged(QAbstractButton *))); | 
|---|
| 35 | } | 
|---|
| 36 |  | 
|---|
| 37 | InitialRepoConfig::~InitialRepoConfig() | 
|---|
| 38 | { | 
|---|
| 39 | mSettings->setLocalValue( "AutoFetch", ui->autoFetch->value()); | 
|---|
| 40 | mSettings->setLocalValue( "PruneOnFetch", ui->pruneOnFetch->isChecked()); | 
|---|
| 41 | mSettings->setLocalValue( "UpdateOnPull", ui->updateOnPull->isChecked()); | 
|---|
| 42 | mSettings->setLocalValue( "MaxCommits", ui->sbMaxCommits->value()); | 
|---|
| 43 |  | 
|---|
| 44 | delete ui; | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | void InitialRepoConfig::accept() | 
|---|
| 48 | { | 
|---|
| 49 | // Store credentials if allowed and the user checked the box | 
|---|
| 50 | if (ui->credentialsFrames->isVisible() && ui->chbCredentials->isChecked()) | 
|---|
| 51 | { | 
|---|
| 52 | if (ui->rbCache->isChecked()) | 
|---|
| 53 | GitCredentials::configureCache(ui->sbTimeout->value(), mGit); | 
|---|
| 54 | else | 
|---|
| 55 | { | 
|---|
| 56 | CredentialsDlg dlg(mGit, this); | 
|---|
| 57 | dlg.exec(); | 
|---|
| 58 | } | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | QDialog::accept(); | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | void InitialRepoConfig::onCredentialsOptionChanged(QAbstractButton *button) | 
|---|
| 65 | { | 
|---|
| 66 | ui->sbTimeout->setEnabled(button == ui->rbCache); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|