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

0001 /***************************************************************************
0002  *   Copyright 2009 Sandro Andrade <sandroandrade@kde.org>                 *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU Library General Public License as       *
0006  *   published by the Free Software Foundation; either version 2 of the    *
0007  *   License, or (at your option) any later version.                       *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU Library General Public     *
0015  *   License along with this program; if not, write to the                 *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0018  ***************************************************************************/
0019 
0020 #include "duchaincontrolflowjob.h"
0021 
0022 #include <KLocale>
0023 
0024 #include <ThreadWeaver/Weaver>
0025 
0026 #include <interfaces/icore.h>
0027 #include <interfaces/iuicontroller.h>
0028 #include <interfaces/iruncontroller.h>
0029 
0030 #include <KDebug>
0031 
0032 DUChainControlFlowJob::DUChainControlFlowJob(const QString &jobName, DUChainControlFlow *duchainControlFlow)
0033  : m_duchainControlFlow(duchainControlFlow),
0034    m_plugin(0),
0035    m_internalJob(0),
0036    m_controlFlowJobType(DUChainControlFlowInternalJob::ControlFlowJobInteractive)
0037 {
0038     init(jobName);
0039 }
0040 
0041 DUChainControlFlowJob::DUChainControlFlowJob(const QString &jobName, KDevControlFlowGraphViewPlugin *plugin)
0042  : m_duchainControlFlow(0),
0043    m_plugin(plugin),
0044    m_internalJob(0),
0045    m_controlFlowJobType(DUChainControlFlowInternalJob::ControlFlowJobInteractive)
0046 {
0047     init(jobName);
0048 }
0049 
0050 void DUChainControlFlowJob::init(const QString &jobName)
0051 {
0052     setObjectName(i18n("Generating control flow graph for %1", jobName));
0053     setCapabilities(Killable);    
0054     setAutoDelete(false);
0055     ICore::self()->uiController()->registerStatus(this);
0056 }
0057 
0058 DUChainControlFlowJob::~DUChainControlFlowJob()
0059 {
0060 }
0061 
0062 QString DUChainControlFlowJob::statusName() const
0063 {
0064     return i18n("Control Flow Graph");
0065 }
0066 
0067 void DUChainControlFlowJob::setControlFlowJobType(DUChainControlFlowInternalJob::ControlFlowJobType controlFlowJobType)
0068 {
0069     m_controlFlowJobType = controlFlowJobType;   
0070 }
0071 
0072 void DUChainControlFlowJob::start()
0073 {
0074     emit showProgress(this, 0, 0, 0);
0075     emit showMessage(this, objectName());
0076 
0077     m_internalJob = new DUChainControlFlowInternalJob(m_duchainControlFlow, m_plugin);
0078     m_internalJob->setControlFlowJobType(m_controlFlowJobType);
0079     connect(m_internalJob, SIGNAL(done(ThreadWeaver::Job*)), SLOT(done(ThreadWeaver::Job*)));
0080     ThreadWeaver::Weaver::instance()->enqueue(m_internalJob);
0081 }
0082 
0083 bool DUChainControlFlowJob::doKill()
0084 {
0085     m_internalJob->requestAbort();
0086     return false;
0087 }
0088 
0089 void DUChainControlFlowJob::done(ThreadWeaver::Job *job)
0090 {
0091     job->deleteLater();
0092     emit hideProgress(this);
0093     emit clearMessage(this);
0094 
0095     emitResult();
0096 }