File indexing completed on 2024-04-28 04:34:31
0001 /* 0002 This file is part of KDevelop 0003 0004 Copyright 2011 Andrey Batyiev <batyiev@gmail.com> 0005 Copyright 2017 Sergey Kalinichev <kalinichev.so.0@gmail.com> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library 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 GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #include "mercurialheadsmodel.h" 0024 0025 #include "../mercurialplugin.h" 0026 0027 #include <QIcon> 0028 0029 #include <interfaces/icore.h> 0030 #include <interfaces/iruncontroller.h> 0031 0032 #include <vcs/vcsjob.h> 0033 #include <vcs/vcsevent.h> 0034 #include <vcs/vcsrevision.h> 0035 0036 using namespace KDevelop; 0037 0038 MercurialHeadsModel::MercurialHeadsModel(MercurialPlugin* plugin, const QUrl& url, QObject* parent) 0039 : VcsBasicEventModel(parent) 0040 , m_updating(false) 0041 , m_plugin(plugin) 0042 , m_url(url) 0043 { 0044 } 0045 0046 QVariant MercurialHeadsModel::headerData(int section, Qt::Orientation orientation, int role) const 0047 { 0048 if (orientation == Qt::Vertical && role == Qt::DecorationRole) { 0049 const VcsRevision &rev = eventForIndex(index(section, 0)).revision(); 0050 if (m_currentHeads.contains(rev)) { 0051 return QVariant(QIcon("arrow-right")); 0052 } else { 0053 return QVariant(); 0054 } 0055 } else { 0056 return VcsBasicEventModel::headerData(section, orientation, role); 0057 } 0058 } 0059 0060 void MercurialHeadsModel::update() 0061 { 0062 VcsJob *identifyJob = m_plugin->identify(m_url); 0063 connect(identifyJob, &VcsJob::resultsReady, this, &MercurialHeadsModel::identifyReceived); 0064 ICore::self()->runController()->registerJob(identifyJob); 0065 0066 VcsJob *headsJob = m_plugin->heads(m_url); 0067 connect(headsJob, &VcsJob::resultsReady, this, &MercurialHeadsModel::headsReceived); 0068 ICore::self()->runController()->registerJob(headsJob); 0069 } 0070 0071 void MercurialHeadsModel::identifyReceived(VcsJob *job) 0072 { 0073 QList<VcsRevision> currentHeads; 0074 foreach (const QVariant& value, job->fetchResults().toList()) { 0075 currentHeads << value.value<VcsRevision>(); 0076 } 0077 m_currentHeads = currentHeads; 0078 if (m_updating) { 0079 emit updateComplete(); 0080 m_updating = false; 0081 } else { 0082 m_updating = true; 0083 } 0084 } 0085 0086 void MercurialHeadsModel::headsReceived(VcsJob *job) 0087 { 0088 QList<VcsEvent> events; 0089 foreach (const QVariant& value, job->fetchResults().toList()) { 0090 events << value.value<VcsEvent>(); 0091 } 0092 addEvents(events); 0093 if (m_updating) { 0094 emit updateComplete(); 0095 m_updating = false; 0096 } else { 0097 m_updating = true; 0098 } 0099 }