File indexing completed on 2024-05-05 04:41:02

0001 /*
0002     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "svnremovejob.h"
0008 #include "svnremovejob_p.h"
0009 
0010 #include <QMutexLocker>
0011 
0012 #include <KLocalizedString>
0013 
0014 #include "kdevsvncpp/client.hpp"
0015 #include "kdevsvncpp/path.hpp"
0016 #include "kdevsvncpp/targets.hpp"
0017 
0018 SvnInternalRemoveJob::SvnInternalRemoveJob( SvnJobBase* parent )
0019     : SvnInternalJobBase( parent )
0020 {
0021 }
0022 
0023 void SvnInternalRemoveJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*thread*/)
0024 {
0025     initBeforeRun();
0026 
0027     svn::Client cli(m_ctxt);
0028     std::vector<svn::Path> targets;
0029     const QList<QUrl> l = locations();
0030     for (const QUrl& url : l) {
0031         QByteArray ba = url.toString( QUrl::PreferLocalFile | QUrl::StripTrailingSlash ).toUtf8();
0032         targets.push_back( svn::Path( ba.data() ) );
0033     }
0034     try
0035     {
0036         cli.remove( svn::Targets( targets ), force() );
0037 
0038     }catch( const svn::ClientException& ce )
0039     {
0040         qCDebug(PLUGIN_SVN) << "Exception while removing files: "
0041                 << m_locations
0042                 << QString::fromUtf8( ce.message() );
0043         setErrorMessage( QString::fromUtf8( ce.message() ) );
0044         m_success = false;
0045     }
0046 }
0047 
0048 void SvnInternalRemoveJob::setLocations( const QList<QUrl>& urls )
0049 {
0050     QMutexLocker l( &m_mutex );
0051     m_locations = urls;
0052 }
0053 
0054 QList<QUrl> SvnInternalRemoveJob::locations() const
0055 {
0056     QMutexLocker l( &m_mutex );
0057     return m_locations;
0058 }
0059 
0060 void SvnInternalRemoveJob::setForce( bool force )
0061 {
0062     QMutexLocker l( &m_mutex );
0063     m_force = force;
0064 }
0065 
0066 bool SvnInternalRemoveJob::force() const
0067 {
0068     QMutexLocker l( &m_mutex );
0069     return m_force;
0070 }
0071 
0072 SvnRemoveJob::SvnRemoveJob( KDevSvnPlugin* parent )
0073     : SvnJobBaseImpl( parent, KDevelop::OutputJob::Silent )
0074 {
0075     setType( KDevelop::VcsJob::Add );
0076     setObjectName(i18n("Subversion Remove"));
0077 }
0078 
0079 QVariant SvnRemoveJob::fetchResults()
0080 {
0081     return QVariant();
0082 }
0083 
0084 void SvnRemoveJob::start()
0085 {
0086     if( m_job->locations().isEmpty() ) {
0087         internalJobFailed();
0088         setErrorText( i18n( "Not enough information to execute remove job" ) );
0089     } else {
0090         qCDebug(PLUGIN_SVN) << "removing urls:" << m_job->locations();
0091         startInternalJob();
0092     }
0093 }
0094 
0095 void SvnRemoveJob::setLocations( const QList<QUrl>& urls )
0096 {
0097     if( status() == KDevelop::VcsJob::JobNotStarted )
0098         m_job->setLocations( urls );
0099 }
0100 
0101 void SvnRemoveJob::setForce( bool force )
0102 {
0103     if( status() == KDevelop::VcsJob::JobNotStarted )
0104         m_job->setForce( force );
0105 }
0106 
0107 #include "moc_svnremovejob.cpp"
0108 #include "moc_svnremovejob_p.cpp"