File indexing completed on 2024-06-23 05:49:21

0001 /*
0002     This file is part of the Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2006-2007, 2009, 2011, 2019 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KASTEN_DOCUMENTMANAGER_HPP
0010 #define KASTEN_DOCUMENTMANAGER_HPP
0011 
0012 // lib
0013 #include "kastencore_export.hpp"
0014 // Qt
0015 #include <QVector>
0016 #include <QObject>
0017 // Std
0018 #include <memory>
0019 
0020 namespace Kasten {
0021 
0022 class AbstractDocument;
0023 
0024 class DocumentCreateManager; // TODO: temporary
0025 class DocumentSyncManager; // TODO: temporary
0026 class ModelCodecManager; // TODO: temporary
0027 
0028 class DocumentManagerPrivate;
0029 
0030 class KASTENCORE_EXPORT DocumentManager : public QObject
0031 {
0032     Q_OBJECT
0033 
0034     friend class DocumentSyncManager;
0035 
0036 public:
0037     DocumentManager();
0038     ~DocumentManager() override;
0039 
0040 public:
0041     void addDocument(AbstractDocument* document);
0042 
0043     void closeDocument(AbstractDocument* document);
0044     void closeDocuments(const QVector<AbstractDocument*>& documents);
0045     void closeAll();
0046 // TODO: think about if a more general close( documentList, theseOrOthers ) is better, same with canCloseAllOther()
0047     void closeAllOther(AbstractDocument* document);
0048 
0049     // TODO: what to do for documents not added?
0050     bool canClose(AbstractDocument* document) const;
0051     bool canClose(const QVector<AbstractDocument*>& documents) const;
0052     bool canCloseAll() const;
0053     bool canCloseAllOther(AbstractDocument* document) const;
0054 
0055     void requestFocus(AbstractDocument* document);
0056 
0057 public:
0058     QVector<AbstractDocument*> documents() const;
0059     bool isEmpty() const;
0060 
0061 public:
0062     DocumentCreateManager* createManager() const;
0063     DocumentSyncManager* syncManager() const;
0064     ModelCodecManager* codecManager() const;
0065 
0066 Q_SIGNALS:
0067     // documents got added
0068     void added(const QVector<Kasten::AbstractDocument*>& documents);
0069     /// documents are about to be closed, cannot be stopped
0070     void closing(const QVector<Kasten::AbstractDocument*>& documents);
0071 
0072 //     void closing( KCloseEvent* event );
0073 // TODO: other than QObject event gets modified by observers, take care of unsetting a close cancel
0074 // problem with a signal is that all(!) observers get notified, even if event is already cancelled
0075 // better a visitor pattern?
0076 
0077     // TODO: or should the document be able to emit this?
0078     void focusRequested(Kasten::AbstractDocument* document);
0079 
0080 private:
0081     const std::unique_ptr<class DocumentManagerPrivate> d_ptr;
0082     Q_DECLARE_PRIVATE(DocumentManager)
0083 };
0084 
0085 }
0086 
0087 #endif