File indexing completed on 2024-10-13 09:39:19

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000 Reginald Stadlbauer <reggie@kde.org>
0004     SPDX-FileCopyrightText: 1997 Stephan Kulow <coolo@kde.org>
0005     SPDX-FileCopyrightText: 1997-2000 Sven Radej <radej@kde.org>
0006     SPDX-FileCopyrightText: 1997-2000 Matthias Ettrich <ettrich@kde.org>
0007     SPDX-FileCopyrightText: 1999 Chris Schlaeger <cs@kde.org>
0008     SPDX-FileCopyrightText: 2002 Joseph Wenninger <jowenn@kde.org>
0009     SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org>
0010 
0011     SPDX-License-Identifier: LGPL-2.0-only
0012 */
0013 
0014 #ifndef KMAINWINDOW_P_H
0015 #define KMAINWINDOW_P_H
0016 
0017 #include <KConfigGroup>
0018 #include <QEventLoopLocker>
0019 #include <QPointer>
0020 
0021 class QObject;
0022 class QSessionManager;
0023 class QTimer;
0024 class KHelpMenu;
0025 class KMainWindow;
0026 
0027 class KMainWindowPrivate
0028 {
0029 public:
0030     virtual ~KMainWindowPrivate() = default;
0031 
0032     bool autoSaveSettings : 1;
0033     bool settingsDirty : 1;
0034     bool autoSaveWindowSize : 1;
0035     bool sizeApplied : 1;
0036     bool suppressCloseEvent : 1;
0037 
0038     KConfigGroup autoSaveGroup;
0039     // If API consumers opt-in to save the state config separately, we want to save the window sizes in the given config
0040     KConfigGroup &autoSaveStateGroup()
0041     {
0042         return m_stateConfigGroup.isValid() ? m_stateConfigGroup : autoSaveGroup;
0043     }
0044     KConfigGroup m_stateConfigGroup;
0045     inline KConfigGroup getValidStateConfig(KConfigGroup &cg) const
0046     {
0047         return m_stateConfigGroup.isValid() ? m_stateConfigGroup : cg;
0048     }
0049     inline void migrateStateDataIfNeeded(KConfigGroup &cg)
0050     {
0051         if (m_stateConfigGroup.isValid()) {
0052             // The window sizes are written in KWindowSystem and RestorePositionForNextInstance is only temporarely written until
0053             // all instances of the app are closed
0054             cg.moveValuesTo({"State"}, m_stateConfigGroup);
0055         }
0056     }
0057 
0058     QTimer *settingsTimer;
0059     QTimer *sizeTimer;
0060     QRect defaultWindowSize;
0061     KHelpMenu *helpMenu;
0062     KMainWindow *q;
0063     QPointer<QObject> dockResizeListener;
0064     QString dbusName;
0065     bool letDirtySettings;
0066     QEventLoopLocker locker;
0067 
0068     // This slot will be called when the style KCM changes settings that need
0069     // to be set on the already running applications.
0070     void _k_slotSettingsChanged(int category);
0071     void _k_slotSaveAutoSaveSize();
0072     void _k_slotSaveAutoSavePosition();
0073 
0074     void init(KMainWindow *_q);
0075     void polish(KMainWindow *q);
0076     enum CallCompression {
0077         NoCompressCalls = 0,
0078         CompressCalls,
0079     };
0080     void setSettingsDirty(CallCompression callCompression = NoCompressCalls);
0081     void setSizeDirty();
0082 };
0083 
0084 class KMWSessionManager : public QObject
0085 {
0086     Q_OBJECT
0087 public:
0088     KMWSessionManager();
0089     ~KMWSessionManager() override;
0090 
0091 private:
0092     void saveState(QSessionManager &);
0093     void commitData(QSessionManager &);
0094 };
0095 
0096 #endif