kdenlivedoc.h 11 KB
Newer Older
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
1
/***************************************************************************
2
 *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
3
4
5
6
7
8
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
9
10
11
12
13
14
15
16
17
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
18
19
 ***************************************************************************/

20
/*! \class KdenliveDoc
21
    \brief Represents a kdenlive project file
22

23
   Instances of KdeliveDoc classes are created by void MainWindow::newFile(bool showProjectSettings, bool force)
24
*/
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
25
26
27
#ifndef KDENLIVEDOC_H
#define KDENLIVEDOC_H

28
#include <QDir>
Nicolas Carion's avatar
Nicolas Carion committed
29
30
#include <QList>
#include <QMap>
Nicolas Carion's avatar
Nicolas Carion committed
31
#include <memory>
Nicolas Carion's avatar
Nicolas Carion committed
32
#include <qdom.h>
33

Nicolas Carion's avatar
Nicolas Carion committed
34
#include <kautosavefile.h>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
35

Nicolas Carion's avatar
Nicolas Carion committed
36
#include "definitions.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
37
#include "gentime.h"
38
#include "timecode.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
39

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
40
class MainWindow;
41
class TrackInfo;
42
class ProjectClip;
43
class MarkerListModel;
44
class Render;
45
class ProfileParam;
46

47
class QUndoGroup;
48
49
class QUndoCommand;
class DocUndoStack;
50

Nicolas Carion's avatar
Nicolas Carion committed
51
namespace Mlt {
Laurent Montel's avatar
Laurent Montel committed
52
class Profile;
53
54
}

Nicolas Carion's avatar
Nicolas Carion committed
55
class KdenliveDoc : public QObject
56
{
57
58
    Q_OBJECT
public:
Nicolas Carion's avatar
Nicolas Carion committed
59
    KdenliveDoc(const QUrl &url, QString projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QMap<QString, QString> &properties,
60
                const QMap<QString, QString> &metadata, const QPoint &tracks, bool *openBackup, MainWindow *parent = nullptr);
Nicolas Carion's avatar
Nicolas Carion committed
61
    ~KdenliveDoc() override;
62
    friend class LoadJob;
63
    /** @brief Get current document's producer. */
64
    const QByteArray getProjectXml();
65
66
67
    double fps() const;
    int width() const;
    int height() const;
68
    QUrl url() const;
69
    KAutoSaveFile *m_autosave;
70
    Timecode timecode() const;
71
    std::shared_ptr<DocUndoStack> commandStack();
72

Laurent Montel's avatar
Laurent Montel committed
73
    int getFramePos(const QString &duration);
74
75
    /** @brief Get a list of all clip ids that are inside a folder. */
    QStringList getBinFolderClipIds(const QString &folderId) const;
76

77
    const QString description() const;
78
    void setUrl(const QUrl &url);
79
80

    /** @brief Defines whether the document needs to be saved. */
81
    bool isModified() const;
82

83
84
85
86
    /** @brief Returns the project folder, used to store project temporary files. */
    QString projectTempFolder() const;
    /** @brief Returns the folder used to store project data files (titles, etc). */
    QString projectDataFolder() const;
87
    void setZoom(int horizontal, int vertical = -1);
88
    QPoint zoom() const;
89
    double dar() const;
90
    /** @brief Returns the project file xml. */
91
    QDomDocument xmlSceneList(const QString &scene);
92
    /** @brief Saves the project file xml to a file. */
93
    bool saveSceneList(const QString &path, const QString &scene);
94
    /** @brief Saves only the MLT xml to a file for preview rendering. */
Laurent Montel's avatar
Laurent Montel committed
95
    void saveMltPlaylist(const QString &fileName);
96
    void cacheImage(const QString &fileId, const QImage &img) const;
Laurent Montel's avatar
Laurent Montel committed
97
    void setProjectFolder(const QUrl &url);
98
99
    void setZone(int start, int end);
    QPoint zone() const;
100
101
    /** @brief Returns target tracks (video, audio). */
    QPair<int, int> targetTracks() const;
102
    void setDocumentProperty(const QString &name, const QString &value);
Nicolas Carion's avatar
Nicolas Carion committed
103
    virtual const QString getDocumentProperty(const QString &name, const QString &defaultValue = QString()) const;
104
105

    /** @brief Gets the list of renderer properties saved into the document. */
Laurent Montel's avatar
Laurent Montel committed
106
    QMap<QString, QString> getRenderProperties() const;
107
108
    /** @brief Read the display ratio from an xml project file. */
    static double getDisplayRatio(const QString &path);
109
110
    /** @brief Backup the project file */
    void backupLastSavedVersion(const QString &path);
111
    /** @brief Returns the document metadata (author, copyright, ...) */
Laurent Montel's avatar
Laurent Montel committed
112
    const QMap<QString, QString> metadata() const;
113
    /** @brief Set the document metadata (author, copyright, ...) */
Laurent Montel's avatar
Laurent Montel committed
114
    void setMetadata(const QMap<QString, QString> &meta);
115
    /** @brief Get all document properties that need to be saved */
Laurent Montel's avatar
Laurent Montel committed
116
    QMap<QString, QString> documentProperties();
117
    bool useProxy() const;
118
    bool useExternalProxy() const;
119
120
    bool autoGenerateProxy(int width) const;
    bool autoGenerateImageProxy(int width) const;
121
122
    /** @brief Saves effects embedded in project file. */
    void saveCustomEffects(const QDomNodeList &customeffects);
123
    void resetProfile();
124
125
    /** @brief Returns true if the profile file has changed. */
    bool profileChanged(const QString &profile) const;
126
127
128
    /** @brief Get an action from main actioncollection. */
    QAction *getAction(const QString &name);
    /** @brief Add an action to main actioncollection. */
Laurent Montel's avatar
Laurent Montel committed
129
    void doAddAction(const QString &name, QAction *a, const QKeySequence &shortcut);
Laurent Montel's avatar
Laurent Montel committed
130
    void invalidatePreviews(QList<int> chunks);
131
    void previewProgress(int p);
132
133
    /** @brief Select most appropriate rendering profile for timeline preview based on fps / size. */
    void selectPreviewProfile();
Laurent Montel's avatar
Laurent Montel committed
134
    void displayMessage(const QString &text, MessageType type = DefaultMessage, int timeOut = 0);
135
136
    /** @brief Get a cache directory for this project. */
    QDir getCacheDir(CacheType type, bool *ok) const;
Laurent Montel's avatar
Laurent Montel committed
137
    /** @brief Create standard cache dirs for the project */
138
    void initCacheDirs();
Laurent Montel's avatar
Laurent Montel committed
139
    /** @brief Get a list of all proxy hash used in this project */
140
    QStringList getProxyHashList();
Laurent Montel's avatar
Laurent Montel committed
141
    /** @brief Move project data files to new url */
Jean-Baptiste Mardelle's avatar
cleanup    
Jean-Baptiste Mardelle committed
142
    void moveProjectData(const QString &src, const QString &dest);
143

144
145
146
    /** @brief Returns a pointer to the guide model */
    std::shared_ptr<MarkerListModel> getGuideModel() const;

147
148
    // TODO REFAC: delete */
    Render *renderer();
149
150
    /** @brief Returns MLT's root (base path) */
    const QString documentRoot() const;
151
152
    /** @brief Returns true if timeline preview settings changed*/
    bool updatePreviewSettings(const QString &profile);
153
    /** @brief Returns the recommended proxy profile parameters */
154
    QString getAutoProxyProfile();
155
156
    /** @brief Returns the number of clips in this project (useful to show loading progress) */
    int clipsCount() const;
157

158
private:
159
    QUrl m_url;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
160
    QDomDocument m_document;
161
    int m_clipsCount;
162
163
    /** @brief MLT's root (base path) that is stripped from urls in saved xml */
    QString m_documentRoot;
164
    Timecode m_timecode;
165
    std::shared_ptr<DocUndoStack> m_commandStack;
166
    QString m_searchFolder;
167
168

    /** @brief Tells whether the current document has been changed after being saved. */
169
    bool m_modified;
170

171
    /** @brief The default recommended proxy extension */
172
173
    QString m_proxyExtension;

174
    /** @brief The default recommended proxy params */
175
176
    QString m_proxyParams;

177
    /** @brief Tells whether the current document was modified by Kdenlive on opening, and a backup should be created on save. */
Nicolas Carion's avatar
Nicolas Carion committed
178
    enum DOCSTATUS { CleanProject, ModifiedProject, UpgradedProject };
179
180
    DOCSTATUS m_documentOpenStatus;

181
    /** @brief The project folder, used to store project files (titles, effects...). */
182
    QString m_projectFolder;
Laurent Montel's avatar
Laurent Montel committed
183
    QList<int> m_undoChunks;
Laurent Montel's avatar
Laurent Montel committed
184
185
    QMap<QString, QString> m_documentProperties;
    QMap<QString, QString> m_documentMetadata;
186
    std::shared_ptr<MarkerListModel> m_guideModel;
187

188
    QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const;
189
190

    /** @brief Creates a new project. */
191
    QDomDocument createEmptyDocument(int videotracks, int audiotracks);
192
    QDomDocument createEmptyDocument(const QList<TrackInfo> &tracks, int audiotracks);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
193

194
195
    /** @brief Updates the project folder location entry in the kdenlive file dialogs to point to the current project folder. */
    void updateProjectFolderPlacesEntry();
196
197
    /** @brief Only keep some backup files, delete some */
    void cleanupBackupFiles();
198
199
    /** @brief Load document properties from the xml file */
    void loadDocumentProperties();
200
    /** @brief update document properties to reflect a change in the current profile */
201
    void updateProjectProfile(bool reloadProducers = false);
202
203
    /** @brief initialize proxy settings based on hw status */
    void initProxySettings();
204

205
public slots:
206
    void slotCreateTextTemplateClip(const QString &group, const QString &groupId, QUrl path);
207
208

    /** @brief Sets the document as modified or up to date.
209
     * @description  If crash recovery is turned on, a timer calls KdenliveDoc::slotAutoSave() \n
210
     * Emits docModified connected to MainWindow::slotUpdateDocumentState \n
211
     * @param mod (optional) true if the document has to be saved */
212
    void setModified(bool mod = true);
213
214
    void slotProxyCurrentItem(bool doProxy, QList<std::shared_ptr<ProjectClip>> clipList = QList<std::shared_ptr<ProjectClip>>(), bool force = false,
                              QUndoCommand *masterCommand = nullptr);
215
    /** @brief Saves the current project at the autosave location.
216
     * @description The autosave files are in ~/.kde/data/stalefiles/kdenlive/ */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
217
    void slotAutoSave(const QString &scene);
218
219
    /** @brief Groups were changed, save to MLT. */
    void groupsChanged(const QString &groups);
220
221

private slots:
222
    void slotModified();
223
224
    void switchProfile(std::unique_ptr<ProfileParam> &profile, const QString &id, const QDomElement &xml);
    void slotSwitchProfile(const QString &profile_path);
225
226
    /** @brief Check if we did a new action invalidating more recent undo items. */
    void checkPreviewStack();
227
228
    /** @brief Guides were changed, save to MLT. */
    void guidesChanged();
229

230
signals:
231
    void resetProjectList();
232
233
234
235

    /** @brief Informs that the document status has been changed.
     *
     * If the document has been modified, it's called with true as an argument. */
236
    void docModified(bool);
237
    void selectLastAddedClip(const QString &);
238
    /** @brief When creating a backup file, also save a thumbnail of current timeline */
239
    void saveTimelinePreview(const QString &path);
240
241
    /** @brief Trigger the autosave timer start */
    void startAutoSave();
242
    /** @brief Current doc created effects, reload list */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
243
    void reloadEffects(const QStringList &paths);
244
245
    /** @brief Fps was changed, update timeline (changed = 1 means no change) */
    void updateFps(double changed);
246
247
    /** @brief If a command is pushed when we are in the middle of undo stack, invalidate further undo history */
    void removeInvalidUndo(int ix);
248
249
    /** @brief Update compositing info */
    void updateCompositionMode(int);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
250
251
252
};

#endif