File indexing completed on 2025-01-05 05:14:49

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #include "reposettingsdialog.h"
0008 
0009 #include "gitmanager.h"
0010 
0011 RepoSettingsDialog::RepoSettingsDialog(Git::Manager *git, QWidget *parent)
0012     : AppDialog(git, parent)
0013 {
0014     setupUi(this);
0015 
0016     lineEditUserName->setText(git->config(QStringLiteral("user.name")));
0017     lineEditUserEmail->setText(git->config(QStringLiteral("user.email")));
0018 
0019     connect(buttonBox, &QDialogButtonBox::accepted, this, &RepoSettingsDialog::slotAccepted);
0020 
0021     initComboBox<AutoCrlf>(comboBoxAutoCrlf);
0022     initComboBox<FileMode>(comboBoxFileMode);
0023 
0024     auto autoCrlf = git->config(QStringLiteral("core.autocrlf"));
0025     auto fileMode = git->config(QStringLiteral("core.fileMode"));
0026 
0027     if (autoCrlf == QStringLiteral("input"))
0028         setComboboxValue(comboBoxAutoCrlf, AutoCrlf::Input);
0029     else if (autoCrlf == QStringLiteral("true") || autoCrlf == QStringLiteral("yes") || autoCrlf == QStringLiteral("on"))
0030         setComboboxValue(comboBoxAutoCrlf, AutoCrlf::Enable);
0031     else if (autoCrlf == QStringLiteral("false") || autoCrlf == QStringLiteral("no") || autoCrlf == QStringLiteral("off"))
0032         setComboboxValue(comboBoxAutoCrlf, AutoCrlf::Disable);
0033     else
0034         setComboboxValue(comboBoxAutoCrlf, AutoCrlf::Unset);
0035 
0036     if (fileMode == QStringLiteral("true") || fileMode == QStringLiteral("yes") || fileMode == QStringLiteral("on"))
0037         setComboboxValue(comboBoxFileMode, FileMode::Enable);
0038     else if (fileMode == QStringLiteral("false") || fileMode == QStringLiteral("no") || fileMode == QStringLiteral("off"))
0039         setComboboxValue(comboBoxFileMode, FileMode::Disable);
0040     else
0041         setComboboxValue(comboBoxFileMode, FileMode::Unset);
0042 }
0043 
0044 void RepoSettingsDialog::slotAccepted()
0045 {
0046     mGit->setConfig(QStringLiteral("user.name"), lineEditUserName->text());
0047     mGit->setConfig(QStringLiteral("user.email"), lineEditUserEmail->text());
0048 
0049     auto autoCrlf = comboBoxCurrentValue<AutoCrlf>(comboBoxAutoCrlf);
0050     auto fileMode = comboBoxCurrentValue<FileMode>(comboBoxFileMode);
0051 
0052     switch (autoCrlf) {
0053     case AutoCrlf::Unset:
0054         mGit->unsetConfig(QStringLiteral("core.autocrlf"));
0055         break;
0056     case AutoCrlf::Enable:
0057         mGit->setConfig(QStringLiteral("core.autocrlf"), "true");
0058         break;
0059     case AutoCrlf::Disable:
0060         mGit->setConfig(QStringLiteral("core.autocrlf"), "false");
0061         break;
0062     case AutoCrlf::Input:
0063         mGit->setConfig(QStringLiteral("core.autocrlf"), "input");
0064         break;
0065     }
0066 
0067     switch (fileMode) {
0068     case FileMode::Unset:
0069         mGit->unsetConfig(QStringLiteral("core.fileMode"));
0070         break;
0071     case FileMode::Enable:
0072         mGit->setConfig(QStringLiteral("core.fileMode"), "true");
0073         break;
0074     case FileMode::Disable:
0075         mGit->setConfig(QStringLiteral("core.fileMode"), "false");
0076         break;
0077     }
0078 
0079     accept();
0080 }
0081 
0082 #include "moc_reposettingsdialog.cpp"