File indexing completed on 2024-04-28 05:42:01

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2009 by Rajko Albrecht                             *
0003  *   ral@alwins-world.de                                                   *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0019  ***************************************************************************/
0020 
0021 #include "itemdisplay.h"
0022 #include "settings/kdesvnsettings.h"
0023 #include "svnitem.h"
0024 #include "svnqt/status.h"
0025 
0026 ItemDisplay::ItemDisplay()
0027     : m_isWorkingCopy(false)
0028     , m_isNetworked(false)
0029 {
0030 }
0031 
0032 bool ItemDisplay::isWorkingCopy() const
0033 {
0034     return m_isWorkingCopy;
0035 }
0036 
0037 QString ItemDisplay::baseUri() const
0038 {
0039     return m_baseUri;
0040 }
0041 
0042 QUrl ItemDisplay::baseUriAsUrl() const
0043 {
0044     return m_isWorkingCopy ? QUrl::fromLocalFile(m_baseUri) : QUrl(m_baseUri);
0045 }
0046 
0047 /*!
0048     \fn ItemDisplay::isNetworked()const
0049  */
0050 bool ItemDisplay::isNetworked() const
0051 {
0052     return m_isNetworked;
0053 }
0054 
0055 void ItemDisplay::setWorkingCopy(bool how)
0056 {
0057     m_isWorkingCopy = how;
0058 }
0059 
0060 void ItemDisplay::setNetworked(bool how)
0061 {
0062     m_isNetworked = how;
0063 }
0064 
0065 void ItemDisplay::setBaseUri(const QString &uri)
0066 {
0067     m_baseUri = uri;
0068     /* otherwise subversion lib asserts! */
0069     while (m_baseUri.endsWith(QLatin1Char('/'))) {
0070         m_baseUri.chop(1);
0071     }
0072 }
0073 
0074 QString ItemDisplay::lastError() const
0075 {
0076     return m_LastException;
0077 }
0078 
0079 /*!
0080     \fn ItemDisplay::filterOut(const SvnItem*)
0081  */
0082 bool ItemDisplay::filterOut(const SvnItem *item)
0083 {
0084     if (!item->stat()->validReposStatus()) {
0085         if ((item->isIgnored() && !Kdesvnsettings::display_ignored_files())
0086             || (Kdesvnsettings::hide_unchanged_files() && item->isRealVersioned() && !item->isModified() && !item->isChildModified())
0087             || (!Kdesvnsettings::display_unknown_files() && !item->stat()->isVersioned())) {
0088             return true;
0089         }
0090     }
0091     return false;
0092 }
0093 
0094 /*!
0095     \fn ItemDisplay::relativePath(const SvnItem*item)
0096  */
0097 QString ItemDisplay::relativePath(const SvnItem *item) const
0098 {
0099     if (!isWorkingCopy() || !item->fullName().startsWith(baseUri())) {
0100         return item->fullName();
0101     }
0102     QString name = item->fullName();
0103     if (name == baseUri()) {
0104         name = QLatin1Char('.');
0105     } else {
0106         name = name.right(name.length() - baseUri().length() - 1);
0107     }
0108     if (name.isEmpty()) {
0109         name = QLatin1Char('.');
0110     }
0111     return name;
0112 }