File indexing completed on 2024-05-05 05:44:47

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 #include "ktranslateurl.h"
0021 
0022 #include "helpers/kdesvn_debug.h"
0023 #include <QFileInfo>
0024 #include <QUrl>
0025 
0026 namespace helpers
0027 {
0028 namespace KTranslateUrl
0029 {
0030 
0031 QString makeKdeUrl(const QString &proto)
0032 {
0033     if (proto.startsWith(QLatin1String("svn+"))) {
0034         return QLatin1Char('k') + proto;
0035     }
0036     if (proto == QLatin1String("svn")) {
0037         return QLatin1String("ksvn");
0038     }
0039     return QLatin1String("ksvn+") + proto;
0040 }
0041 
0042 QUrl string2Uri(const QString &what)
0043 {
0044     // if the file is available in the local fs -> QUrl::fromLocalFile
0045     QFileInfo fi(what);
0046     if (fi.isAbsolute() || fi.exists()) {
0047         return QUrl::fromLocalFile(fi.absoluteFilePath());
0048     }
0049     // not a local file, assume a url (which can also be a local file)
0050     QUrl uri(what);
0051     if (!uri.isLocalFile()) {
0052         uri.setScheme(makeKdeUrl(uri.scheme()));
0053     }
0054     qCDebug(KDESVN_LOG) << "string2Uri(" << what << ") -> " << uri.toString() << ", local: " << uri.isLocalFile();
0055     return uri;
0056 }
0057 
0058 } // namespace KTranslateUrl
0059 
0060 } // namespace helpers