File indexing completed on 2024-05-12 04:19:37

0001 /*
0002 Gwenview: an image viewer
0003 Copyright 2007 Aurélien Gâteau <agateau@kde.org>
0004 
0005 This program is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU General Public License
0007 as published by the Free Software Foundation; either version 2
0008 of the License, or (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018 
0019 */
0020 #ifndef DOCUMENTFACTORY_H
0021 #define DOCUMENTFACTORY_H
0022 
0023 // Qt
0024 #include <QObject>
0025 
0026 #include <lib/document/document.h>
0027 
0028 class QUndoGroup;
0029 
0030 class QUrl;
0031 
0032 namespace Gwenview
0033 {
0034 struct DocumentFactoryPrivate;
0035 
0036 /**
0037  * This class holds all instances of Document.
0038  *
0039  * It keeps a cache of recently accessed documents to avoid reloading them.
0040  * To do so it keeps a last-access timestamp, which is updated to the
0041  * current time every time DocumentFactory::load() is called.
0042  */
0043 class GWENVIEWLIB_EXPORT DocumentFactory : public QObject
0044 {
0045     Q_OBJECT
0046 public:
0047     static DocumentFactory *instance();
0048     ~DocumentFactory() override;
0049 
0050     /**
0051      * Loads the document associated with url, or returns an already cached
0052      * instance of Document::Ptr if there is any.
0053      * This method updates the last-access timestamp.
0054      */
0055     Document::Ptr load(const QUrl &url);
0056 
0057     /**
0058      * Returns a document if it has already been loaded once with load().
0059      * This method does not update the last-access timestamp.
0060      */
0061     Document::Ptr getCachedDocument(const QUrl &) const;
0062 
0063     QList<QUrl> modifiedDocumentList() const;
0064 
0065     bool hasUrl(const QUrl &) const;
0066 
0067     void clearCache();
0068 
0069     QUndoGroup *undoGroup();
0070 
0071     /**
0072      * Do not keep document whose url is @url in cache even if it has been
0073      * modified
0074      */
0075     void forget(const QUrl &url);
0076 
0077 Q_SIGNALS:
0078     void modifiedDocumentListChanged();
0079     void documentChanged(const QUrl &);
0080     void documentBusyStateChanged(const QUrl &, bool);
0081     void readyForDirListerStart(const QUrl &url);
0082 
0083 private Q_SLOTS:
0084     void slotLoaded(const QUrl &);
0085     void slotSaved(const QUrl &, const QUrl &);
0086     void slotModified(const QUrl &);
0087     void slotBusyChanged(const QUrl &, bool);
0088 
0089 private:
0090     DocumentFactory();
0091 
0092     DocumentFactoryPrivate *const d;
0093 };
0094 
0095 } // namespace
0096 #endif /* DOCUMENTFACTORY_H */