File indexing completed on 2024-04-14 03:53:00
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2000 Dawit Alemayehu <adawit@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "sessiondata_p.h" 0009 0010 #include <QDir> 0011 #include <QStandardPaths> 0012 0013 #include <KConfigGroup> 0014 #include <KLocalizedString> 0015 #include <KSharedConfig> 0016 #include <kprotocolmanager_p.h> 0017 0018 namespace KIO 0019 { 0020 /********************************* SessionData ****************************/ 0021 0022 class SessionData::SessionDataPrivate 0023 { 0024 public: 0025 SessionDataPrivate() 0026 { 0027 initDone = false; 0028 } 0029 0030 bool initDone; 0031 QString charsets; 0032 }; 0033 0034 SessionData::SessionData() 0035 : d(new SessionDataPrivate) 0036 { 0037 } 0038 0039 SessionData::~SessionData() = default; 0040 0041 void SessionData::configDataFor(MetaData &configData, const QString &proto, const QString &) 0042 { 0043 if ((proto.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) || (proto.startsWith(QLatin1String("webdav"), Qt::CaseInsensitive))) { 0044 if (!d->initDone) { 0045 reset(); 0046 } 0047 0048 // These might have already been set so check first 0049 // to make sure that we do not trumpt settings sent 0050 // by apps or end-user. 0051 if (configData[QStringLiteral("Charsets")].isEmpty()) { 0052 configData[QStringLiteral("Charsets")] = d->charsets; 0053 } 0054 if (configData[QStringLiteral("CacheDir")].isEmpty()) { 0055 const QString httpCacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/kio_http"); 0056 QDir().mkpath(httpCacheDir); 0057 configData[QStringLiteral("CacheDir")] = httpCacheDir; 0058 } 0059 if (configData[QStringLiteral("UserAgent")].isEmpty()) { 0060 configData[QStringLiteral("UserAgent")] = KProtocolManagerPrivate::defaultUserAgent(QString()); 0061 } 0062 } 0063 } 0064 0065 void SessionData::reset() 0066 { 0067 d->initDone = true; 0068 0069 d->charsets = QStringLiteral("utf-8"); 0070 KProtocolManager::reparseConfiguration(); 0071 } 0072 0073 } 0074 0075 #include "moc_sessiondata_p.cpp"