File indexing completed on 2024-05-12 17:16:25

0001 /*
0002  * Port for usage with qt-framework and development for kdesvn
0003  * Copyright (C) 2005-2009 by Rajko Albrecht (ral@alwins-world.de)
0004  * http://kdesvn.alwins-world.de
0005  */
0006 /*
0007  * ====================================================================
0008  * Copyright (c) 2002-2005 The RapidSvn Group.  All rights reserved.
0009  * dev@rapidsvn.tigris.org
0010  *
0011  * This library is free software; you can redistribute it and/or
0012  * modify it under the terms of the GNU Lesser General Public
0013  * License as published by the Free Software Foundation; either
0014  * version 2.1 of the License, or (at your option) any later version.
0015  *
0016  * This library is distributed in the hope that it will be useful,
0017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0019  * Lesser General Public License for more details.
0020  *
0021  * You should have received a copy of the GNU Lesser General Public
0022  * License along with this library (in the file LGPL.txt); if not,
0023  * write to the Free Software Foundation, Inc., 51 Franklin St,
0024  * Fifth Floor, Boston, MA  02110-1301  USA
0025  *
0026  * This software consists of voluntary contributions made by many
0027  * individuals.  For exact contribution history, see the revision
0028  * history and logs, available at http://rapidsvn.tigris.org/.
0029  * ====================================================================
0030  */
0031 
0032 #include "targets.h"
0033 
0034 // subversion api
0035 #include <svn_types.h>
0036 
0037 // apr api
0038 #include <apr_pools.h>
0039 #include <apr_strings.h>
0040 
0041 // svncpp
0042 #include "path.h"
0043 #include "pool.h"
0044 #include "svnqt_defines.h"
0045 
0046 #include <QStringList>
0047 #include <QUrl>
0048 
0049 namespace svn
0050 {
0051 Targets::Targets(const svn::Paths &targets)
0052     : m_targets(targets)
0053 {
0054 }
0055 
0056 Targets::Targets(const QString &target)
0057 {
0058     if (!target.isEmpty()) {
0059         m_targets.push_back(target);
0060     }
0061 }
0062 
0063 Targets::Targets(const Path &target)
0064 {
0065     if (!target.cstr().isEmpty()) {
0066         m_targets.push_back(target);
0067     }
0068 }
0069 
0070 apr_array_header_t *
0071 Targets::array(const Pool &pool) const
0072 {
0073     Paths::const_iterator it;
0074 
0075     apr_pool_t *apr_pool = pool.pool();
0076     apr_array_header_t *apr_targets =
0077         apr_array_make(apr_pool,
0078                        m_targets.size(),
0079                        sizeof(const char *));
0080 
0081     for (it = m_targets.begin(); it != m_targets.end(); ++it) {
0082         QByteArray s = (*it).path().toUtf8();
0083 
0084         char *t2 =
0085             apr_pstrndup(apr_pool, s, s.size());
0086 
0087         (*((const char **) apr_array_push(apr_targets))) = t2;
0088     }
0089 
0090     return apr_targets;
0091 }
0092 
0093 const Path Targets::target(Paths::size_type which) const
0094 {
0095     if (m_targets.size() > which) {
0096         return m_targets[which];
0097     } else {
0098         return Path();
0099     }
0100 }
0101 
0102 svn::Targets Targets::fromStringList(const QStringList &paths)
0103 {
0104     svn::Paths ret;
0105     ret.reserve(paths.size());
0106     for (const QString &path : paths)
0107         ret.push_back(svn::Path(path));
0108     return svn::Targets(ret);
0109 }
0110 
0111 svn::Targets Targets::fromUrlList(const QList<QUrl> &urls, UrlConversion conversion)
0112 {
0113     svn::Paths ret;
0114     ret.reserve(urls.size());
0115     const bool preferLocalFile = conversion == UrlConversion::PreferLocalPath;
0116     for (const QUrl &url : urls)
0117         ret.push_back(svn::Path((preferLocalFile && url.isLocalFile()) ? url.toLocalFile() : url.url()));
0118     return svn::Targets(ret);
0119 }
0120 
0121 }