File indexing completed on 2025-01-05 05:14:50
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 "submoduleinfodialog.h" 0008 0009 #include "commands/addsubmodulecommand.h" 0010 #include "gitmanager.h" 0011 #include "qdebug.h" 0012 0013 #include <KLocalizedString> 0014 #include <KMessageBox> 0015 0016 #include <QFileDialog> 0017 0018 SubmoduleInfoDialog::SubmoduleInfoDialog(Git::Manager *git, QWidget *parent) 0019 : AppDialog(git, parent) 0020 { 0021 setupUi(this); 0022 lineEditPath->setStartDir(QUrl::fromLocalFile(mGit->path())); 0023 lineEditPath->setMode(KFile::Directory); 0024 connect(lineEditPath, &KUrlRequester::urlSelected, this, &SubmoduleInfoDialog::slotLineEditPathUrlSelected); 0025 } 0026 0027 bool SubmoduleInfoDialog::force() const 0028 { 0029 return checkBoxForce->isChecked(); 0030 } 0031 0032 void SubmoduleInfoDialog::setForce(bool newForce) 0033 { 0034 checkBoxForce->setChecked(newForce); 0035 } 0036 0037 QString SubmoduleInfoDialog::url() const 0038 { 0039 return lineEditUrl->text(); 0040 } 0041 0042 void SubmoduleInfoDialog::setUrl(const QString &newUrl) 0043 { 0044 lineEditUrl->setText(newUrl); 0045 } 0046 0047 QString SubmoduleInfoDialog::path() const 0048 { 0049 return lineEditPath->text(); 0050 } 0051 0052 void SubmoduleInfoDialog::setPath(const QString &newPath) 0053 { 0054 lineEditPath->setText(newPath); 0055 } 0056 0057 QString SubmoduleInfoDialog::branch() const 0058 { 0059 if (checkBoxBranch->isChecked()) 0060 return lineEditBranch->text(); 0061 return {}; 0062 } 0063 0064 void SubmoduleInfoDialog::setBranch(const QString &newBranch) 0065 { 0066 if (newBranch.isEmpty()) { 0067 checkBoxBranch->setChecked(true); 0068 lineEditBranch->setText(newBranch); 0069 } else { 0070 checkBoxBranch->setChecked(false); 0071 lineEditBranch->clear(); 0072 } 0073 } 0074 0075 Git::AddSubmoduleCommand *SubmoduleInfoDialog::command() const 0076 { 0077 auto cmd = new Git::AddSubmoduleCommand(mGit); 0078 cmd->setForce(checkBoxForce->isChecked()); 0079 0080 if (checkBoxBranch->isChecked()) 0081 cmd->setbranch(lineEditBranch->text()); 0082 0083 cmd->setUrl(lineEditUrl->text()); 0084 cmd->setLocalPath(lineEditPath->text()); 0085 0086 return cmd; 0087 } 0088 0089 void SubmoduleInfoDialog::slotLineEditPathUrlSelected(const QUrl &url) 0090 { 0091 auto text = url.toLocalFile(); 0092 if (text.isEmpty()) 0093 return; 0094 qDebug() << text << mGit->path(); 0095 if (text.startsWith(mGit->path())) { 0096 auto t = text; 0097 t.remove(0, mGit->path().size()); 0098 if (t.startsWith("/")) 0099 t.remove(0, 1); 0100 lineEditPath->setText(t); 0101 } else { 0102 KMessageBox::error(this, i18n("The path is not inside of git directory")); 0103 lineEditPath->setText(QString{}); 0104 } 0105 } 0106 0107 #include "moc_submoduleinfodialog.cpp"