File indexing completed on 2024-05-12 04:38:55

0001 /*
0002     SPDX-FileCopyrightText: 2007 Dukju Ahn <dukjuahn@gmail.com>
0003     SPDX-FileCopyrightText: 2008 Evgeniy Ivanov <powerfox@kde.ru>
0004     SPDX-FileCopyrightText: 2011 Andrey Batyiev <batyiev@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #include "vcscommitdialog.h"
0010 
0011 #include <QDialogButtonBox>
0012 #include <QPushButton>
0013 
0014 #include <interfaces/iproject.h>
0015 #include <interfaces/iplugin.h>
0016 #include <interfaces/ipatchsource.h>
0017 
0018 #include "../vcsstatusinfo.h"
0019 #include "../models/vcsfilechangesmodel.h"
0020 
0021 #include "ui_vcscommitdialog.h"
0022 
0023 namespace KDevelop
0024 {
0025 
0026 class VcsCommitDialogPrivate
0027 {
0028 public:
0029     Ui::VcsCommitDialog ui;
0030     IPatchSource* m_patchSource;
0031     VcsFileChangesModel* m_model;
0032 };
0033 
0034 VcsCommitDialog::VcsCommitDialog( IPatchSource *patchSource, QWidget *parent )
0035     : QDialog(parent)
0036     , d_ptr(new VcsCommitDialogPrivate())
0037 {
0038     Q_D(VcsCommitDialog);
0039 
0040     auto mainWidget = new QWidget(this);
0041     d->ui.setupUi(mainWidget);
0042 
0043     QWidget *customWidget = patchSource->customWidget();
0044     if( customWidget )
0045     {
0046         d->ui.gridLayout->addWidget( customWidget, 0, 0, 1, 2 );
0047     }
0048 
0049     auto okButton = d->ui.buttonBox->button(QDialogButtonBox::Ok);
0050     okButton->setDefault(true);
0051     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0052     connect(d->ui.buttonBox, &QDialogButtonBox::accepted, this, &VcsCommitDialog::accept);
0053     connect(d->ui.buttonBox, &QDialogButtonBox::rejected, this, &VcsCommitDialog::reject);
0054 
0055     d->m_patchSource = patchSource;
0056     d->m_model = new VcsFileChangesModel( this, true );
0057     d->ui.files->setModel( d->m_model );
0058 }
0059 
0060 VcsCommitDialog::~VcsCommitDialog() = default;
0061 
0062 void VcsCommitDialog::setRecursive( bool recursive )
0063 {
0064     Q_D(VcsCommitDialog);
0065 
0066     d->ui.recursiveChk->setChecked( recursive );
0067 }
0068 
0069 void VcsCommitDialog::setCommitCandidates( const QList<KDevelop::VcsStatusInfo>& statuses )
0070 {
0071     Q_D(VcsCommitDialog);
0072 
0073     for (const VcsStatusInfo& info : statuses) {
0074         d->m_model->updateState( info );
0075     }
0076 }
0077 
0078 bool VcsCommitDialog::recursive() const
0079 {
0080     Q_D(const VcsCommitDialog);
0081 
0082     return d->ui.recursiveChk->isChecked();
0083 }
0084 
0085 void VcsCommitDialog::ok()
0086 {
0087     Q_D(VcsCommitDialog);
0088 
0089     if( d->m_patchSource->finishReview( d->m_model->checkedUrls() ) )
0090     {
0091         deleteLater();
0092     }
0093 }
0094 
0095 void VcsCommitDialog::cancel()
0096 {
0097     Q_D(VcsCommitDialog);
0098 
0099     d->m_patchSource->cancelReview();
0100 }
0101 
0102 }
0103 
0104 #include "moc_vcscommitdialog.cpp"