1#include "GitConfigDlg.h"
2#include "ui_GitConfigDlg.h"
3
4#include <GitBase.h>
5#include <GitConfig.h>
6#include <GitQlientStyles.h>
7
8#include <QCloseEvent>
9#include <QKeyEvent>
10
11GitConfigDlg::GitConfigDlg(const QSharedPointer<GitBase> &gitBase, QWidget *parent)
12 : QDialog(parent)
13 , ui(new Ui::GitConfigDlg)
14 , mGit(gitBase)
15{
16 ui->setupUi(this);
17
18 setWindowFlags(Qt::FramelessWindowHint);
19 setStyleSheet(GitQlientStyles::getStyles());
20
21 QScopedPointer<GitConfig> git(new GitConfig(mGit));
22
23 const auto globalConfig = git->getGlobalUserInfo();
24 ui->leGlobalEmail->setText(globalConfig.mUserEmail);
25 ui->leGlobalName->setText(globalConfig.mUserName);
26
27 const auto localConfig = git->getLocalUserInfo();
28 ui->leLocalEmail->setText(localConfig.mUserEmail);
29 ui->leLocalName->setText(localConfig.mUserName);
30
31 connect(ui->checkBox, &CheckBox::stateChanged, this, &GitConfigDlg::copyGlobalSettings);
32 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &GitConfigDlg::accept);
33}
34
35GitConfigDlg::~GitConfigDlg()
36{
37 delete ui;
38}
39
40void GitConfigDlg::keyPressEvent(QKeyEvent *e)
41{
42 const auto key = e->key();
43
44 if (key == Qt::Key_Escape)
45 return;
46
47 QDialog::keyPressEvent(e);
48}
49
50void GitConfigDlg::closeEvent(QCloseEvent *e)
51{
52 if (!mPrepareToClose)
53 e->ignore();
54 else
55 QDialog::closeEvent(e);
56}
57
58void GitConfigDlg::close()
59{
60 mPrepareToClose = true;
61
62 QDialog::close();
63}
64
65void GitConfigDlg::accept()
66{
67 QScopedPointer<GitConfig> git(new GitConfig(mGit));
68
69 git->setGlobalUserInfo({ ui->leGlobalEmail->text(), ui->leGlobalName->text() });
70 git->setLocalUserInfo({ ui->leLocalEmail->text(), ui->leLocalName->text() });
71
72 close();
73}
74
75void GitConfigDlg::copyGlobalSettings(int checkState)
76{
77 ui->leLocalEmail->setReadOnly(checkState == Qt::Checked);
78 ui->leLocalName->setReadOnly(checkState == Qt::Checked);
79
80 if (checkState == Qt::Checked)
81 {
82 ui->leLocalEmail->setText(ui->leGlobalEmail->text());
83 ui->leLocalName->setText(ui->leGlobalName->text());
84 }
85}
86