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

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