File indexing completed on 2024-04-28 04:58:43

0001 // This file is part of the KDE project
0002 // SPDX-FileCopyrightText: <year> Stefano Crocco <stefano.crocco@alice.it>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 #ifndef KONQ_PLACEHOLDERPART_H
0006 #define KONQ_PLACEHOLDERPART_H
0007 
0008 #include <KParts/ReadOnlyPart>
0009 
0010 namespace Konq {
0011 
0012 /**
0013  * @brief A part which displays an empty widget
0014  *
0015  * The only scope of this class is to support delayed loading of views, which is
0016  * used by session loading to avoid having to load many URLs all at once (which
0017  * is especially slow for web pages). In this case, views create instances of
0018  * this part instead of the part they would use. This part provides the same
0019  * interface of a `KParts::ReadOnlyPart`, but both its implementations of openFile()
0020  * and openUrl() do nothing and its widget is an empty `QWidget`
0021 */
0022 class PlaceholderPart : public KParts::ReadOnlyPart
0023 {
0024     Q_OBJECT
0025 public:
0026     /**
0027      * @brief Constructor
0028      * @param parentWidget the part's widget parent widget
0029      * @param parent the part's parent
0030      */
0031     PlaceholderPart(QWidget *parentWidget, QObject *parent=nullptr);
0032 
0033     /**
0034      * @brief Destructor
0035      */
0036     ~PlaceholderPart() override;
0037 
0038     /**
0039      * @brief Struct containing information about delayed loading
0040      *
0041      * This contains all the part-specific information stored in a session config file, so that
0042      * it can be stored away when the session is loaded and used later, when the view becomes visible.
0043      *
0044      * @note History information isn't included here because it's stored in the view itself
0045      */
0046     struct DelayedLoadingData {
0047         QString mimeType; //!< The mimetype of the URL
0048         QString serviceName; //!< serviceName the part plugin id
0049         bool openUrl; //!< Whether to open an URL after creating the part
0050         QUrl url; //!< The URL to load after creating the part
0051         bool lockedLocation; //!Whether the location should be locked
0052     };
0053 
0054     /**
0055      * @brief Stores information about the part the PlaceholderPart stands for
0056      * @param data The data to store
0057      */
0058     void setDelayedLoadingData(const DelayedLoadingData &data){m_delayedLoadingData = data;}
0059 
0060     /**
0061      * @brief information about the part the PlaceholderPart stands for
0062      */
0063     DelayedLoadingData delayedLoadingData() const {return m_delayedLoadingData;}
0064 
0065 public slots:
0066     /**
0067      * @brief Override of `KParts::ReadOnlyPart::openUrl()`
0068      *
0069      * This implementation of `KParts::ReadOnlyPart::openUrl()` doesn't actually open the URL:
0070      * it only calls `setUrl` and emits the `setWindowCaption` signal
0071      * @param url the URL to open
0072      * @return `false` if @p url is invalid and `true` otherwise
0073      */
0074     bool openUrl(const QUrl & url) override;
0075 
0076 protected:
0077     /**
0078      * @brief Override of `KParts::ReadOnlyPart::openFile()`
0079      *
0080      * This function does nothing
0081      * @return `true` if the file exists and `false` otherwise
0082      */
0083     bool openFile() override;
0084 
0085 private:
0086 
0087    static KPluginMetaData defaultMetadata();
0088 
0089     QWidget *m_widget; //!< The part's widget
0090     DelayedLoadingData m_delayedLoadingData; //!< Information about the part the PlaceholderPart stands for
0091 };
0092 
0093 }
0094 
0095 #endif //KONQ_PLACEHOLDERPART_H