File indexing completed on 2024-05-05 04:35:30

0001 /***************************************************************************
0002  *   Copyright 2011 Andrey Batyiev <batyiev@gmail.com>                     *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or         *
0005  *   modify it under the terms of the GNU General Public License as        *
0006  *   published by the Free Software Foundation; either version 2 of        *
0007  *   the License or (at your option) version 3 or any later version        *
0008  *   accepted by the membership of KDE e.V. (or its successor approved     *
0009  *   by the membership of KDE e.V.), which shall act as a proxy            *
0010  *   defined in Section 14 of version 3 of the license.                    *
0011  *                                                                         *
0012  *   This program is distributed in the hope that it will be useful,       *
0013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0015  *   GNU General Public License for more details.                          *
0016  *                                                                         *
0017  *   You should have received a copy of the GNU General Public License     *
0018  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0019  ***************************************************************************/
0020 
0021 #include "mercurialheadswidget.h"
0022 
0023 #include <vcs/vcsjob.h>
0024 #include <vcs/vcsevent.h>
0025 
0026 #include <interfaces/icore.h>
0027 #include <interfaces/iruncontroller.h>
0028 
0029 #include <models/mercurialheadsmodel.h>
0030 #include <mercurialplugin.h>
0031 
0032 using namespace KDevelop;
0033 
0034 MercurialHeadsWidget::MercurialHeadsWidget(MercurialPlugin *plugin, const QUrl &url)
0035     : QDialog(), m_ui(new Ui::MercurialHeadsWidget), m_plugin(plugin), m_url(url)
0036 {
0037     m_ui->setupUi(this);
0038     m_headsModel = new MercurialHeadsModel(plugin, url, this);
0039     m_ui->headsTableView->setModel(static_cast<QAbstractItemModel *>(m_headsModel));
0040 
0041     connect(m_ui->checkoutPushButton, &QPushButton::clicked, this,  &MercurialHeadsWidget::checkoutRequested);
0042     connect(m_ui->mergePushButton, &QPushButton::clicked, this, &MercurialHeadsWidget::mergeRequested);
0043 
0044     setWindowTitle(i18n("Mercurial Heads (%1)", m_url.toLocalFile()));
0045 
0046     updateModel();
0047 }
0048 
0049 void MercurialHeadsWidget::updateModel()
0050 {
0051     m_headsModel->update();
0052 }
0053 
0054 void MercurialHeadsWidget::checkoutRequested()
0055 {
0056     const QModelIndex &selection = m_ui->headsTableView->currentIndex();
0057     if (!selection.isValid()) {
0058         return;
0059     }
0060 
0061     VcsJob *job = m_plugin->checkoutHead(m_url, m_headsModel->eventForIndex(selection).revision());
0062     connect(job, &VcsJob::resultsReady, this, &MercurialHeadsWidget::updateModel);
0063     ICore::self()->runController()->registerJob(job);
0064 }
0065 
0066 void MercurialHeadsWidget::mergeRequested()
0067 {
0068     const QModelIndex &selection = m_ui->headsTableView->currentIndex();
0069     if (!selection.isValid()) {
0070         return;
0071     }
0072 
0073     VcsJob *job = m_plugin->mergeWith(m_url, m_headsModel->eventForIndex(selection).revision());
0074     connect(job, &VcsJob::resultsReady, this, &MercurialHeadsWidget::updateModel);
0075     ICore::self()->runController()->registerJob(job);
0076 }