File indexing completed on 2024-05-05 04:39:01
0001 /* 0002 SPDX-FileCopyrightText: 2013-2014 Maciej Poleski 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "copyjob.h" 0008 0009 #include <QVariant> 0010 0011 #include <KIO/CopyJob> 0012 0013 #include <interfaces/iplugin.h> 0014 0015 #include "bazaarplugin.h" 0016 0017 using namespace KDevelop; 0018 0019 CopyJob::CopyJob(const QUrl& localLocationSrc, const QUrl& localLocationDstn, BazaarPlugin* parent, KDevelop::OutputJob::OutputJobVerbosity verbosity) 0020 : VcsJob(parent, verbosity), m_plugin(parent), m_source(localLocationSrc), 0021 m_destination(localLocationDstn), m_status(KDevelop::VcsJob::JobNotStarted) 0022 { 0023 setType(JobType::Copy); 0024 setCapabilities(Killable); 0025 } 0026 0027 0028 KDevelop::IPlugin* CopyJob::vcsPlugin() const 0029 { 0030 return m_plugin; 0031 } 0032 0033 KDevelop::VcsJob::JobStatus CopyJob::status() const 0034 { 0035 return m_status; 0036 } 0037 0038 QVariant CopyJob::fetchResults() 0039 { 0040 return QVariant(); 0041 } 0042 0043 void CopyJob::start() 0044 { 0045 if (m_status != KDevelop::VcsJob::JobNotStarted) 0046 return; 0047 KIO::CopyJob* job = KIO::copy(m_source, m_destination, KIO::HideProgressInfo); 0048 connect(job, &KIO::CopyJob::copyingDone, this, &CopyJob::addToVcs); 0049 m_status = KDevelop::VcsJob::JobRunning; 0050 m_job = job; 0051 job->start(); 0052 } 0053 0054 bool CopyJob::doKill() 0055 { 0056 m_status = KDevelop::VcsJob::JobCanceled; 0057 if (m_job) 0058 return m_job->kill(KJob::Quietly); 0059 else 0060 return true; 0061 } 0062 0063 void CopyJob::addToVcs(KIO::Job* job, const QUrl& from, const QUrl& to, const QDateTime& mtime, bool directory, bool renamed) 0064 { 0065 Q_UNUSED(job); 0066 Q_UNUSED(from); 0067 Q_UNUSED(mtime); 0068 Q_UNUSED(directory); 0069 Q_UNUSED(renamed); 0070 if (m_status != KDevelop::VcsJob::JobRunning) 0071 return; 0072 KDevelop::VcsJob* job2 = m_plugin->add(QList<QUrl>() << to, KDevelop::IBasicVersionControl::Recursive); 0073 connect(job2, &VcsJob::result, this, &CopyJob::finish); 0074 m_job = job2; 0075 job2->start(); 0076 } 0077 0078 void CopyJob::finish(KJob*) 0079 { 0080 m_status = KDevelop::VcsJob::JobSucceeded; 0081 emitResult(); 0082 emit resultsReady(this); 0083 } 0084 0085 #include "moc_copyjob.cpp"