Warning, file /office/tellico/src/utils/urlfieldlogic.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /*************************************************************************** 0002 Copyright (C) 2019 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #include "urlfieldlogic.h" 0026 0027 #include <QDir> 0028 0029 using Tellico::UrlFieldLogic; 0030 0031 UrlFieldLogic::UrlFieldLogic() 0032 : m_isRelative(false) { 0033 } 0034 0035 void UrlFieldLogic::setRelative(bool relative_) { 0036 m_isRelative = relative_; 0037 } 0038 0039 void UrlFieldLogic::setBaseUrl(const QUrl& baseUrl_) { 0040 m_baseUrl = baseUrl_; 0041 } 0042 0043 QString UrlFieldLogic::urlText(const QUrl& url_) const { 0044 // if it's not relative or if the base URL is not set, 0045 // then there's nothing to do. Return the URL as-is. 0046 // Also, if the base URL is not a local file, then ignore it 0047 if(url_.isEmpty() || !m_isRelative || m_baseUrl.isEmpty() || !m_baseUrl.isLocalFile()) { 0048 // normalize the url 0049 return url_.url(QUrl::PrettyDecoded | QUrl::NormalizePathSegments); 0050 } 0051 // BUG 410551: use the directory of the base url, not the file itself, in the QDir c'tor 0052 const QDir dir(m_baseUrl.adjusted(QUrl::RemoveFilename).path()); 0053 // if it's a relative path, don't try to resolve the logic 0054 return dir.isRelative() ? 0055 url_.url(QUrl::PrettyDecoded | QUrl::NormalizePathSegments) : 0056 dir.relativeFilePath(url_.path()); 0057 }