File indexing completed on 2024-04-28 04:34:31

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 "mercurialqueueseriesmodel.h"
0022 
0023 #include <QStringList>
0024 #include <QIcon>
0025 
0026 #include <mercurialplugin.h>
0027 #include <vcs/vcsjob.h>
0028 
0029 using namespace KDevelop;
0030 
0031 void MercurialQueueSeriesModel::update()
0032 {
0033     beginResetModel();
0034     VcsJob *job = m_plugin->mqApplied(m_repoLocation);
0035     if (job->exec() && job->status() == VcsJob::JobSucceeded) {
0036         m_appliedPatches = job->fetchResults().toStringList();
0037     }
0038     delete job;
0039 
0040     job = m_plugin->mqUnapplied(m_repoLocation);
0041     if (job->exec() && job->status() == VcsJob::JobSucceeded) {
0042         m_unappliedPatches = job->fetchResults().toStringList();
0043     }
0044     delete job;
0045     endResetModel();
0046 }
0047 
0048 QVariant MercurialQueueSeriesModel::data(const QModelIndex &index, int role) const
0049 {
0050     int row = index.row();
0051     if (row >= 0 && row < m_appliedPatches.size()) {
0052         if (role == Qt::DisplayRole) {
0053             return m_appliedPatches[row];
0054         } else if (role == Qt::DecorationRole) {
0055             // FIXME
0056             return QVariant(QIcon("dialog-ok-apply"));
0057         } else {
0058             return QVariant();
0059         }
0060     } else {
0061         row -= m_appliedPatches.size();
0062     }
0063 
0064     if (row >= 0 && row < m_unappliedPatches.size()) {
0065         if (role == Qt::DisplayRole) {
0066             return m_unappliedPatches[row];
0067         } else {
0068             return QVariant();
0069         }
0070     }
0071     return QVariant();
0072 }
0073 
0074 int MercurialQueueSeriesModel::rowCount(const QModelIndex &/*parent*/) const
0075 {
0076     return m_unappliedPatches.size() + m_appliedPatches.size();
0077 }