File indexing completed on 2024-04-28 04:58:29
0001 // /* This file is part of the KDE project 0002 // SPDX-FileCopyrightText: 2023 Stefano Crocco <stefano.crocco@alice.it> 0003 // 0004 // SPDX-License-Identifier: LGPL-2.0-or-later 0005 // */ 0006 0007 #ifndef KONQBROWSER_H 0008 #define KONQBROWSER_H 0009 0010 #include "interfaces/browser.h" 0011 0012 #include <QPointer> 0013 0014 namespace KonqInterfaces 0015 { 0016 class CookieJar; 0017 } 0018 0019 /** 0020 * @brief Implementation of KonqInterfaces::Browser 0021 */ 0022 class KonqBrowser : public KonqInterfaces::Browser 0023 { 0024 Q_OBJECT 0025 0026 public: 0027 /** 0028 * @brief Default constructor 0029 * 0030 * @param parent the parent object 0031 */ 0032 KonqBrowser(QObject* parent = nullptr); 0033 0034 ~KonqBrowser(); ///< Destructor 0035 0036 KonqInterfaces::CookieJar* cookieJar() const override; ///< Implementation of KonqInterfaces::Browser::cookieJar() 0037 0038 void setCookieJar(KonqInterfaces::CookieJar* jar) override; ///< Implementation of KonqInterfaces::Browser::setCookieJar() 0039 0040 QString konqUserAgent() const override; ///< Implementation of Browser::konqUserAgent() 0041 QString defaultUserAgent() const override; ///< Implementation of Browser::defaultUserAgent() 0042 QString userAgent() const override; ///< Implementation of Browser::currentUserAgent() 0043 void setTemporaryUserAgent(const QString & newUA) override; ///< Implementation of Browser::setTemporaryUserAgent() 0044 void clearTemporaryUserAgent() override; ///< Implementation of Browser::clearTemporaryUserAgent() 0045 0046 /** 0047 * @brief Reads the configuration files and applies the necessary changes 0048 * 0049 * This should be called whenever the configuration changes, usually from KonquerorApplication::reparseConfiguration() 0050 */ 0051 void applyConfiguration(); 0052 0053 static QString konquerorUserAgent(); ///< The standard Konqueror user agent string 0054 0055 /** 0056 * @brief Implementation of KonqInterfaces::Browser::canNavigateTo 0057 * @return the value returned by KonqView::canNavigateTo() for the view associated with the part 0058 * or if it isn't possible to find such a view (it should never happen) 0059 * @see KonqView::canNavigateTo() 0060 */ 0061 bool canNavigateTo(KParts::ReadOnlyPart *part, const QUrl &url) const override; 0062 0063 private: 0064 0065 /** 0066 * @brief Struct used to store information about the user agent 0067 */ 0068 struct UserAgentData { 0069 QString defaultUA; ///< The default user agent 0070 QString temporaryUA; ///< The temporary UA, if it has been set 0071 bool usingDefaultUA = true; ///< Whether the default user agent is currently in use 0072 /** 0073 * @brief The user agent currently in use 0074 * 0075 * Depending on the value of #usingDefaultUA, this will either be #defaulUA or #temporaryUA 0076 */ 0077 QString currentUserAgent() const {return usingDefaultUA ? defaultUA : temporaryUA;} 0078 }; 0079 0080 /** 0081 * @brief Reads the default user agent from the configuration file 0082 * 0083 * This method also emits the userAgentChanged() signal, if needed 0084 */ 0085 void readDefaultUserAgent(); 0086 0087 UserAgentData m_userAgent; ///< The user agent data 0088 0089 QPointer<KonqInterfaces::CookieJar> m_cookieJar; ///< Holds the cookie jar 0090 }; 0091 0092 #endif // KONQBROWSER_H