1 | /* |
2 | This file is part of the KDE project |
3 | SPDX-FileCopyrightText: 2000 Dawit Alemayehu <adawit@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #include "sessiondata_p.h" |
9 | |
10 | #include <QDir> |
11 | #include <QStandardPaths> |
12 | |
13 | #include <KConfigGroup> |
14 | #include <KLocalizedString> |
15 | #include <KSharedConfig> |
16 | #include <kprotocolmanager_p.h> |
17 | |
18 | namespace KIO |
19 | { |
20 | /********************************* SessionData ****************************/ |
21 | |
22 | class SessionData::SessionDataPrivate |
23 | { |
24 | public: |
25 | SessionDataPrivate() |
26 | { |
27 | initDone = false; |
28 | } |
29 | |
30 | bool initDone; |
31 | QString charsets; |
32 | }; |
33 | |
34 | SessionData::SessionData() |
35 | : d(new SessionDataPrivate) |
36 | { |
37 | } |
38 | |
39 | SessionData::~SessionData() = default; |
40 | |
41 | void SessionData::configDataFor(MetaData &configData, const QString &proto, const QString &) |
42 | { |
43 | if ((proto.startsWith(s: QLatin1String("http" ), cs: Qt::CaseInsensitive)) || (proto.startsWith(s: QLatin1String("webdav" ), cs: Qt::CaseInsensitive))) { |
44 | if (!d->initDone) { |
45 | reset(); |
46 | } |
47 | |
48 | // These might have already been set so check first |
49 | // to make sure that we do not trumpt settings sent |
50 | // by apps or end-user. |
51 | if (configData[QStringLiteral("Charsets" )].isEmpty()) { |
52 | configData[QStringLiteral("Charsets" )] = d->charsets; |
53 | } |
54 | if (configData[QStringLiteral("CacheDir" )].isEmpty()) { |
55 | const QString httpCacheDir = QStandardPaths::writableLocation(type: QStandardPaths::GenericCacheLocation) + QLatin1String("/kio_http" ); |
56 | QDir().mkpath(dirPath: httpCacheDir); |
57 | configData[QStringLiteral("CacheDir" )] = httpCacheDir; |
58 | } |
59 | if (configData[QStringLiteral("UserAgent" )].isEmpty()) { |
60 | configData[QStringLiteral("UserAgent" )] = KProtocolManagerPrivate::defaultUserAgent(keys: QString()); |
61 | } |
62 | } |
63 | } |
64 | |
65 | void SessionData::reset() |
66 | { |
67 | d->initDone = true; |
68 | |
69 | d->charsets = QStringLiteral("utf-8" ); |
70 | KProtocolManager::reparseConfiguration(); |
71 | } |
72 | |
73 | } |
74 | |
75 | #include "moc_sessiondata_p.cpp" |
76 | |