File indexing completed on 2024-04-21 04:58:13

0001 /* This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
0003     SPDX-FileCopyrightText: 2007 Eduardo Robles Elvira <edulix@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KONQCLOSEDWINDOWSMANAGER_H
0009 #define KONQCLOSEDWINDOWSMANAGER_H
0010 
0011 #include "konqprivate_export.h"
0012 #include <QList>
0013 #include <QObject>
0014 class KonqClosedRemoteWindowItem;
0015 class KonqUndoManager;
0016 class KConfig;
0017 class QDBusMessage;
0018 class KonqClosedWindowItem;
0019 class QString;
0020 class KonqClosedWindowsManagerPrivate;
0021 
0022 /**
0023  * Provides a shared singleton for all Konq window instances.
0024  * This class is a singleton, use self() to access its only instance.
0025  *
0026  *  - it synchronizes the closed window list with other
0027  * Konqueror instances via DBUS.
0028  *
0029  */
0030 class KONQ_TESTS_EXPORT KonqClosedWindowsManager : public QObject
0031 {
0032     Q_OBJECT
0033 public:
0034     friend class KonqClosedWindowsManagerPrivate;
0035 
0036     KonqClosedWindowsManager();
0037     ~KonqClosedWindowsManager() override;
0038 
0039     static KonqClosedWindowsManager *self();
0040     static void destroy();
0041 
0042     const QList<KonqClosedWindowItem *> &closedWindowItemList();
0043 
0044     /**
0045      * When a window is closed it's added with this function to
0046      * m_closedWindowItemList.
0047      */
0048     void addClosedWindowItem(KonqUndoManager *real_sender, KonqClosedWindowItem
0049                              *closedWindowItem, bool propagate = true);
0050 
0051     void removeClosedWindowItem(KonqUndoManager *real_sender, const
0052 
0053                                 KonqClosedWindowItem *closedWindowItem, bool propagate = true);
0054 
0055     /**
0056      * Returns an anonymous config (which exists only in memory). Only used by
0057      * KonqClosedItems for storing in memory closed items.
0058      */
0059     KConfig *memoryStore();
0060 
0061     /**
0062      * Called by the KonqUndoManager when a local window is being closed.
0063      * Saves the closed windows list to disk inside a config file.
0064      */
0065     void saveConfig();
0066 
0067     bool undoAvailable() const;
0068 
0069 public Q_SLOTS:
0070     void readSettings();
0071 
0072     /**
0073      * Reads the list of closed window from the configuration file if it couldn't
0074      * be retrieved from running konqueror windows and if it hasn't been read
0075      * already. By default the closeditems_list file is not read, so each
0076      * function which needs that file to be read first must call this function
0077      * to ensure the closeditems list is filled.
0078      */
0079     void readConfig();
0080 
0081 Q_SIGNALS:
0082     /**
0083      * Notifies the addition the closed window list in all the konqueror windows of
0084      * this konqueror instance.
0085      */
0086     void addWindowInOtherInstances(KonqUndoManager *real_sender,
0087                                    KonqClosedWindowItem *closedWindowItem);
0088 
0089     /**
0090      * Notifies the removal the closed window list in all the konqueror windows of
0091      * this konqueror instance.
0092      */
0093     void removeWindowInOtherInstances(KonqUndoManager *real_sender, const
0094                                       KonqClosedWindowItem *closedWindowItem);
0095 private:
0096 
0097     KonqClosedRemoteWindowItem *findClosedRemoteWindowItem(const QString &configFileName,
0098             const QString &configGroup);
0099 
0100     KonqClosedWindowItem *findClosedLocalWindowItem(const QString &configFileName,
0101             const QString &configGroup);
0102 
0103     /**
0104      * This function removes all the closed items temporary files. Only done if
0105      * there's no other konqueror process running than us, otherwise that process
0106      * might want to use that temporary file.
0107      */
0108     void removeClosedItemsConfigFiles();
0109 private:
0110     QList<KonqClosedWindowItem *> m_closedWindowItemList;
0111     int m_numUndoClosedItems;
0112     KConfig *m_konqClosedItemsConfig, *m_konqClosedItemsStore;
0113     int m_maxNumClosedItems;
0114     /**
0115      * This bool var is used internally to allow delayed initialization of the
0116      * closed items list. When active, this flag prevents addClosedWindowItem()
0117      * from emitting addWindowInOtherInstances() as the windows are already
0118      * being dealt with inside KonqUndoManager::populate().
0119      */
0120     bool m_blockClosedItems;
0121 Q_SIGNALS: // DBUS signals
0122     /**
0123      * Every konqueror instance broadcasts new closed windows to other
0124      * konqueror instances.
0125      */
0126     void notifyClosedWindowItem(const QString &title, const int &numTabs,
0127                                 const QString &configFileName, const QString &configGroup);
0128 
0129     /**
0130      * Every konqueror instance broadcasts removed closed windows to other
0131      * konqueror instances.
0132      */
0133     void notifyRemove(const QString &configFileName,
0134                       const QString &configGroup);
0135 
0136 private Q_SLOTS:// connected to DBUS signals
0137     void slotNotifyClosedWindowItem(const QString &title, int numTabs,
0138                                     const QString &configFileName, const QString &configGroup,
0139                                     const QString &service);
0140 
0141     void slotNotifyClosedWindowItem(const QString &title, int numTabs,
0142                                     const QString &configFileName, const QString &configGroup,
0143                                     const QDBusMessage &msg);
0144 
0145     void slotNotifyRemove(const QString &configFileName,
0146                           const QString &configGroup, const QDBusMessage &msg);
0147 
0148 private:
0149     void emitNotifyClosedWindowItem(const KonqClosedWindowItem *closedWindowItem);
0150 
0151     void emitNotifyRemove(const KonqClosedWindowItem *closedWindowItem);
0152 };
0153 
0154 #endif /* KONQCLOSEDWINDOWSMANAGER_H */
0155