kdenlivedoc.h 11.3 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

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

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

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

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

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

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

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

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

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

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

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

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

147
148
149
    /** @brief Returns a pointer to the guide model */
    std::shared_ptr<MarkerListModel> getGuideModel() const;

150
151
    // TODO REFAC: delete */
    Render *renderer();
152
153
    /** @brief Returns MLT's root (base path) */
    const QString documentRoot() const;
154
155
    /** @brief Returns true if timeline preview settings changed*/
    bool updatePreviewSettings(const QString &profile);
156
    /** @brief Returns the recommended proxy profile parameters */
157
    QString getAutoProxyProfile();
158
159
    /** @brief Returns the number of clips in this project (useful to show loading progress) */
    int clipsCount() const;
160
161
    /** @brief Returns a list of project tags (color / description) */
    QMap <QString, QString> getProjectTags();
162

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

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

176
    /** @brief The default recommended proxy extension */
177
178
    QString m_proxyExtension;

179
    /** @brief The default recommended proxy params */
180
181
    QString m_proxyParams;

182
    /** @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
183
    enum DOCSTATUS { CleanProject, ModifiedProject, UpgradedProject };
184
185
    DOCSTATUS m_documentOpenStatus;

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

193
    QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const;
194
195

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

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

210
public slots:
211
    void slotCreateTextTemplateClip(const QString &group, const QString &groupId, QUrl path);
212
213

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

private slots:
227
    void slotModified();
228
    void switchProfile(std::unique_ptr<ProfileParam> &profile, const QString &id, const QDomElement &xml);
229
    void slotSwitchProfile(const QString &profile_path, bool reloadThumbs);
230
    /** @brief Check if we did a new action invalidating more recent undo items. */
231
    void checkPreviewStack(int ix);
232
233
    /** @brief Guides were changed, save to MLT. */
    void guidesChanged();
234

235
signals:
236
    void resetProjectList();
237
238
239
240

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

#endif