File indexing completed on 2024-04-21 04:58:19
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 1998, 1999, 2010 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "konqmisc.h" 0007 #include "konqsettingsxt.h" 0008 #include "konqmainwindow.h" 0009 #include "konqviewmanager.h" 0010 #include "konqview.h" 0011 #include "konqmainwindowfactory.h" 0012 #include "konqurl.h" 0013 0014 #include "libkonq_utils.h" 0015 0016 #include "konqdebug.h" 0017 #include <kurifilter.h> 0018 #include <KLocalizedString> 0019 0020 #include <kprotocolmanager.h> 0021 #include <kiconloader.h> 0022 #include <kconfiggroup.h> 0023 #include <QList> 0024 #include <QStandardPaths> 0025 0026 /********************************************** 0027 * 0028 * KonqMisc 0029 * 0030 **********************************************/ 0031 KonqMainWindow *KonqMisc::newWindowFromHistory(KonqView *view, int steps) 0032 { 0033 int oldPos = view->historyIndex(); 0034 int newPos = oldPos + steps; 0035 0036 const HistoryEntry *he = view->historyAt(newPos); 0037 if (!he) { 0038 return nullptr; 0039 } 0040 0041 KonqMainWindow *mainwindow = KonqMainWindowFactory::createEmptyWindow(); 0042 if (!mainwindow) { 0043 return nullptr; 0044 } 0045 KonqView *newView = mainwindow->currentView(); 0046 0047 if (!newView) { 0048 return nullptr; 0049 } 0050 0051 newView->copyHistory(view); 0052 newView->setHistoryIndex(newPos); 0053 newView->restoreHistory(); 0054 mainwindow->show(); 0055 return mainwindow; 0056 } 0057 0058 QUrl KonqMisc::konqFilteredURL(KonqMainWindow *parent, const QString &_url, const QUrl ¤tDirectory) 0059 { 0060 Q_UNUSED(parent); // Useful if we want to change the error handling again 0061 0062 if (!KonqUrl::canBeKonqUrl(_url)) { // Don't filter "konq:" URLs 0063 KUriFilterData data(_url); 0064 0065 if (currentDirectory.isLocalFile()) { 0066 data.setAbsolutePath(currentDirectory.toLocalFile()); 0067 } 0068 0069 // We do not want to the filter to check for executables 0070 // from the location bar. 0071 data.setCheckForExecutables(false); 0072 0073 if (KUriFilter::self()->filterUri(data)) { 0074 if (data.uriType() == KUriFilterData::Error) { 0075 if (data.errorMsg().isEmpty()) { 0076 return Konq::makeErrorUrl(KIO::ERR_MALFORMED_URL, _url, QUrl(_url)); 0077 } else { 0078 return Konq::makeErrorUrl(KIO::ERR_WORKER_DEFINED, data.errorMsg(), QUrl(_url)); 0079 } 0080 } else { 0081 return data.uri(); 0082 } 0083 } 0084 0085 // Show an explicit error for an unknown URL scheme, because the 0086 // explanation generated by KIO::rawErrorDetail() gives useful 0087 // information. 0088 const QString scheme = data.uri().scheme(); 0089 if (!scheme.isEmpty() && !KProtocolInfo::isKnownProtocol(scheme)) { 0090 return Konq::makeErrorUrl(KIO::ERR_UNSUPPORTED_PROTOCOL, _url, QUrl(_url)); 0091 } 0092 0093 // NOTE: a valid URL like http://kde.org always passes the filtering test. 0094 // As such, this point could only be reached when _url is NOT a valid URL. 0095 return Konq::makeErrorUrl(KIO::ERR_MALFORMED_URL, _url, QUrl(_url)); 0096 } 0097 0098 const bool isKnownAbout = KonqUrl::hasKnownPathRoot(_url); 0099 0100 return isKnownAbout ? QUrl(_url) : KonqUrl::url(KonqUrl::Type::NoPath); 0101 } 0102 0103 QString KonqMisc::encodeFilename(QString filename) 0104 { 0105 return filename.replace(':', '_'); 0106 } 0107 0108 QString KonqMisc::decodeFilename(QString filename) 0109 { 0110 return filename.replace('_', ':'); 0111 } 0112