File: documentmanager.hpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (111 lines) | stat: -rw-r--r-- 3,506 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef CSM_DOC_DOCUMENTMGR_H
#define CSM_DOC_DOCUMENTMGR_H

#include <QObject>
#include <QThread>

#include <filesystem>
#include <string>
#include <vector>

#include <components/files/multidircollection.hpp>
#include <components/toutf8/toutf8.hpp>

#include "loader.hpp"

namespace Files
{
    struct ConfigurationManager;
}

namespace CSMDoc
{
    class Document;

    class DocumentManager : public QObject
    {
        Q_OBJECT

        std::vector<Document*> mDocuments;
        const Files::ConfigurationManager& mConfiguration;
        QThread mLoaderThread;
        Loader mLoader;
        ToUTF8::FromType mEncoding;

        std::filesystem::path mResDir;

        Files::PathContainer mDataPaths;
        std::vector<std::string> mArchives;

        DocumentManager(const DocumentManager&);
        DocumentManager& operator=(const DocumentManager&);

    public:
        DocumentManager(const Files::ConfigurationManager& configuration);

        ~DocumentManager();

        void addDocument(
            const std::vector<std::filesystem::path>& files, const std::filesystem::path& savePath, bool isNew);
        ///< \param isNew Do not load the last content file in \a files and instead create in an
        /// appropriate way.

        /// Create a new document. The ownership of the created document is transferred to
        /// the calling function. The DocumentManager does not manage it. Loading has not
        /// taken place at the point when the document is returned.
        ///
        /// \param isNew Do not load the last content file in \a files and instead create in an
        /// appropriate way.
        Document* makeDocument(
            const std::vector<std::filesystem::path>& files, const std::filesystem::path& savePath, bool isNew);

        void setResourceDir(const std::filesystem::path& parResDir);

        void setEncoding(ToUTF8::FromType encoding);

        /// Sets the file data that gets passed to newly created documents.
        void setFileData(const Files::PathContainer& dataPaths, const std::vector<std::string>& archives);

        bool isEmpty();

    private slots:

        void documentLoaded(Document* document);
        ///< The ownership of \a document is not transferred.

        void documentNotLoaded(Document* document, const std::string& error);
        ///< Document load has been interrupted either because of a call to abortLoading
        /// or a problem during loading). In the former case error will be an empty string.

    public slots:

        void removeDocument(CSMDoc::Document* document);
        ///< Emits the lastDocumentDeleted signal, if applicable.

        /// Hand over document to *this. The ownership is transferred. The DocumentManager
        /// will initiate the load procedure, if necessary
        void insertDocument(CSMDoc::Document* document);

    signals:

        void documentAdded(CSMDoc::Document* document);

        void documentAboutToBeRemoved(CSMDoc::Document* document);

        void loadRequest(CSMDoc::Document* document);

        void lastDocumentDeleted();

        void loadingStopped(CSMDoc::Document* document, bool completed, const std::string& error);

        void nextStage(CSMDoc::Document* document, const std::string& name, int totalRecords);

        void nextRecord(CSMDoc::Document* document, int records);

        void cancelLoading(CSMDoc::Document* document);

        void loadMessage(CSMDoc::Document* document, const std::string& message);
    };
}

#endif