File indexing completed on 2024-04-28 04:38:20
0001 /* 0002 SPDX-FileCopyrightText: 2013 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "prunejob.h" 0008 #include <cmakeutils.h> 0009 #include <outputview/outputmodel.h> 0010 #include <interfaces/iproject.h> 0011 0012 #include <KLocalizedString> 0013 #include <KIO/DeleteJob> 0014 0015 #include <QDir> 0016 0017 using namespace KDevelop; 0018 0019 PruneJob::PruneJob(KDevelop::IProject* project) 0020 : OutputJob(project, Verbose) 0021 , m_project(project) 0022 , m_job(nullptr) 0023 { 0024 setCapabilities( Killable ); 0025 setToolTitle( i18n("CMake") ); 0026 setStandardToolView( KDevelop::IOutputView::BuildView ); 0027 setBehaviours(KDevelop::IOutputView::AllowUserClose | KDevelop::IOutputView::AutoScroll ); 0028 } 0029 0030 void PruneJob::start() 0031 { 0032 auto* output = new OutputModel(this); 0033 setModel(output); 0034 startOutput(); 0035 0036 Path builddir = CMake::currentBuildDir( m_project ); 0037 if( builddir.isEmpty() ) 0038 { 0039 output->appendLine(i18n("No build directory configured, cannot clear the build directory")); 0040 emitResult(); 0041 return; 0042 } 0043 else if (!builddir.isLocalFile() || QDir(builddir.toLocalFile()).exists(QStringLiteral("CMakeLists.txt"))) 0044 { 0045 output->appendLine(i18n("Wrong build directory, cannot clear the build directory")); 0046 emitResult(); 0047 return; 0048 } 0049 0050 QDir d( builddir.toLocalFile() ); 0051 QList<QUrl> urls; 0052 const auto entries = d.entryList(QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden); 0053 urls.reserve(entries.size()); 0054 for (const auto& entry : entries) { 0055 urls << Path(builddir, entry).toUrl(); 0056 } 0057 output->appendLine(i18n("%1> rm -rf %2", m_project->path().pathOrUrl(), builddir.toLocalFile())); 0058 m_job = KIO::del( urls ); 0059 m_job->start(); 0060 connect(m_job, &KJob::finished, this, &PruneJob::jobFinished); 0061 } 0062 0063 bool PruneJob::doKill() 0064 { 0065 return m_job->kill(); 0066 } 0067 0068 void PruneJob::jobFinished(KJob* job) 0069 { 0070 auto* output = qobject_cast<OutputModel*>(model()); 0071 if(job->error()==0) 0072 output->appendLine(i18n("** Prune successful **")); 0073 else 0074 output->appendLine(i18n("** Prune failed: %1 **", job->errorString())); 0075 emitResult(); 0076 m_job = nullptr; 0077 } 0078 0079 #include "moc_prunejob.cpp"