File indexing completed on 2024-05-12 05:00:04

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 KONQINTERFACES_BROWSER_H
0008 #define KONQINTERFACES_BROWSER_H
0009 
0010 #include "libkonq_export.h"
0011 
0012 #include <QObject>
0013 
0014 namespace KParts {
0015     class ReadOnlyPart;
0016 };
0017 
0018 namespace KonqInterfaces {
0019 
0020 class CookieJar;
0021 
0022 /**
0023  * @brief Abstract class representing the Konqueror browser
0024  */
0025 class LIBKONQ_EXPORT Browser : public QObject
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     /**
0031      * Default Constructor
0032      *
0033      * @param parent the parent object
0034      */
0035     Browser(QObject* parent = nullptr);
0036     virtual ~Browser(); ///< Destructor
0037 
0038     /**
0039      * @brief Sets the object to use for cookies management
0040      *
0041      * @note this object *wont't* take ownership of @p jar.
0042      *
0043      * @param jar the object to use for cookie management
0044      */
0045     virtual void setCookieJar(CookieJar *jar) = 0;
0046 
0047     /**
0048      * @brief The object to use for cookie management
0049      * @return the object to use for cookie management
0050      */
0051     virtual CookieJar* cookieJar() const = 0;
0052 
0053     /**
0054      * @brief The standard user agent used by Konqueror
0055      * @return The standard user agent used by Konqueror
0056      */
0057     virtual QString konqUserAgent() const = 0;
0058 
0059     /**
0060      * @brief The default user agent
0061      * @return The default user agent
0062      */
0063     virtual QString defaultUserAgent() const = 0;
0064 
0065     /**
0066      * @brief The user agent currently in use
0067      *
0068      * This can be either defaultUserAgent() or a temporary user agent set with setTemporaryUserAgent()
0069      * @return The user agent currently in use
0070      * @see setTemporaryUserAgent()
0071      */
0072     virtual QString userAgent() const = 0;
0073 
0074     /**
0075      * @brief Sets a temporary user agent to be used instead of the default one
0076      *
0077      * The temporary user agent remains in use until the application is closed or this is called again.
0078      *
0079      * Implementations should emit the userAgentChanged() signal, unless the new user
0080      * agent is effectively equal to to old. If switching from the default user agent to a
0081      * temporary user agent but the two are equal (or vice versa) the signal shouldn't be emitted
0082      * @param newUA the new user agent string.
0083      */
0084     virtual void setTemporaryUserAgent(const QString &newUA) = 0;
0085 
0086     /**
0087      * @brief Stops using a temporary user agent and returns to the default one
0088      */
0089     virtual void clearTemporaryUserAgent() = 0;
0090 
0091     /**
0092      * @brief Casts the given object or one of its children to a Browser
0093      *
0094      * This is similar to
0095      * @code
0096      * obj->findChild<Browser*>();
0097      * @endcode
0098      * except that if @p obj derives from Browser, it will be returned, regardless of whether any
0099      * of its children also derive from it.
0100      * @param obj the object to cast to a Browser
0101      * @return @p obj or one of its children as a Browser* or `nullptr` if neither @p obj nor its children derive from Browser
0102      */
0103     static Browser* browser(QObject* obj);
0104 
0105     /**
0106      * @brief Whether a part has permission to navigate to the given URL
0107      * @param part the part
0108      * @param url the URL the part wants to navigate to
0109      * @return `true` if @p part can navigate to @p url and `false` otherwise.
0110      */
0111     virtual bool canNavigateTo(KParts::ReadOnlyPart *part, const QUrl &url) const = 0;
0112 
0113 signals:
0114     void configurationChanged(); ///< Signal emitted after the configuration has changed
0115 
0116     /**
0117      * @brief Signal emitted when the user agent changes
0118      *
0119      * This signal can be emitted in several situations:
0120      * - the default user agent is in use and the user changes it
0121      * - the user switched from the default user agent to a temporary one (or vice versa) and the two are different
0122      * - the user switched from a temporary user agent to a different temporary user agent
0123      *
0124      * @param currentUA the new current user agent
0125      * @see setTemporaryUserAgent()
0126      */
0127     void userAgentChanged(const QString &currentUA);
0128 };
0129 
0130 }
0131 
0132 #endif // KONQINTERFACES_BROWSER_H