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

Laurent Montel's avatar
Laurent Montel committed
28
#include <QtXml/qdom.h>
29
#include <QMap>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
30
#include <QList>
31
#include <QDir>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
32
#include <QObject>
33
#include <QTimer>
34
#include <QUrl>
35

36
#include <kautosavefile.h>
37
#include <KDirWatch>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
38 39

#include "gentime.h"
40
#include "timecode.h"
41
#include "definitions.h"
42
#include "timeline/guide.h"
43
#include "mltcontroller/effectscontroller.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
44

45 46
class Render;
class ClipManager;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
47
class MainWindow;
48
class TrackInfo;
49
class NotesPlugin;
50
class ProjectClip;
51
class ClipController;
52

53
class QTextEdit;
54 55 56
class QUndoGroup;
class QTimer;
class QUndoStack;
57

58 59 60 61
namespace Mlt {
    class Profile;
}

62 63
class KdenliveDoc: public QObject
{
64 65
    Q_OBJECT
public:
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
66

67
    KdenliveDoc(const QUrl &url, const QUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QMap <QString, QString>& properties, const QMap <QString, QString>& metadata, const QPoint &tracks, Render *render, NotesPlugin *notes, bool *openBackup, MainWindow *parent = 0);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
68 69
    ~KdenliveDoc();
    QDomNodeList producersList();
70 71 72
    double fps() const;
    int width() const;
    int height() const;
73
    QUrl url() const;
74
    KAutoSaveFile *m_autosave;
75
    Timecode timecode() const;
76
    QDomDocument toXml();
77
    QUndoStack *commandStack();
78
    Render *renderer();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
79
    ClipManager *clipManager();
80
    QString groupsXml() const;
81 82 83

    /** @brief Adds a clip to the project tree.
     * @return false if the user aborted the operation, true otherwise */
84
    bool addClip(QDomElement elem, const QString &clipId);
85 86 87 88 89 90 91 92 93

    /** @brief Updates information about a clip.
     * @param elem the <kdenlive_producer />
     * @param orig the potential <producer />
     * @param clipId the producer id
     * @return false if the user aborted the operation (in case the clip wasn't
     *     there yet), true otherwise
     *
     * If the clip wasn't added before, it tries to add it to the project. */
94
    //bool addClipInfo(QDomElement elem, QDomElement orig, const QString &clipId);
95
    void deleteClip(const QString &clipId);
Laurent Montel's avatar
Laurent Montel committed
96
    int getFramePos(const QString &duration);
97
    /** @brief Get a bin's clip from its id. */
98
    ProjectClip *getBinClip(const QString &clipId);
99 100
    /** @brief Get a list of all clip ids that are inside a folder. */
    QStringList getBinFolderClipIds(const QString &folderId) const;
101
    ClipController *getClipController(const QString &clipId);
102 103

    /** @brief Informs Kdenlive of the audio thumbnails generation progress. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
104
    void setThumbsProgress(const QString &message, int progress);
105
    const QString &profilePath() const;
106 107
    /** @brief Returns current project profile. */
    MltVideoProfile mltProfile() const;
108
    ProfileInfo getProfileInfo() const;
109
    const QString description() const;
110
    void setUrl(const QUrl &url);
111 112

    /** @brief Defines whether the document needs to be saved. */
113
    bool isModified() const;
114 115

    /** @brief Returns the project folder, used to store project files. */
116
    QUrl projectFolder() const;
117 118
    void setZoom(int horizontal, int vertical);
    QPoint zoom() const;
119
    double dar() const;
120
    double projectDuration() const;
121
    /** @brief Returns the project file xml. */
122
    QDomDocument xmlSceneList(const QString &scene);
123
    /** @brief Saves the project file xml to a file. */
124
    bool saveSceneList(const QString &path, const QString &scene);
125
    void cacheImage(const QString &fileId, const QImage &img) const;
126
    void setProjectFolder(QUrl url);
127 128
    void setZone(int start, int end);
    QPoint zone() const;
129
    int setSceneList();
130
    void setDocumentProperty(const QString &name, const QString &value);
131
    const QString getDocumentProperty(const QString &name, const QString &defaultValue = QString()) const;
132 133

    /** @brief Gets the list of renderer properties saved into the document. */
134
    QMap <QString, QString> getRenderProperties() const;
135 136
    /** @brief Read the display ratio from an xml project file. */
    static double getDisplayRatio(const QString &path);
137 138
    /** @brief Backup the project file */
    void backupLastSavedVersion(const QString &path);
139 140 141
    /** @brief Returns the document metadata (author, copyright, ...) */
    const QMap <QString, QString> metadata() const;
    /** @brief Set the document metadata (author, copyright, ...) */
142
    void setMetadata(const QMap <QString, QString>& meta);
143 144
    /** @brief Get frame size of the renderer (profile)*/
    const QSize getRenderSize() const;
145 146
    /** @brief Add url to the file watcher so that we monitor changes */
    void watchFile(const QUrl &url);
147
    /** @brief Get all document properties that need to be saved */
148
    QMap <QString, QString> documentProperties();
149
    bool useProxy() const;
150 151
    bool autoGenerateProxy(int width) const;
    bool autoGenerateImageProxy(int width) const;
152 153 154
    QString documentNotes() const;
    /** @brief Saves effects embedded in project file. */
    void saveCustomEffects(const QDomNodeList &customeffects);
155
    void resetProfile();
156 157 158
    /** @brief Force processing of clip id in producer queue. */
    void forceProcessing(const QString &id);
    void getFileProperties(const QDomElement &xml, const QString &clipId, int imageHeight, bool replaceProducer = true);
159 160
    /** @brief Returns true if the profile file has changed. */
    bool profileChanged(const QString &profile) const;
161
    void doAddAction(const QString &name, QAction *a);
162

163
private:
164
    QUrl m_url;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
165
    QDomDocument m_document;
166 167 168 169 170
    KDirWatch m_fileWatcher;
    /** Timer used to reload clips when they have been externally modified */
    QTimer m_modifiedTimer;
    /** List of the clip IDs that need to be reloaded after being externally modified */
    QMap <QString, QTime> m_modifiedClips;
171 172 173
    int m_width;
    int m_height;
    Timecode m_timecode;
174
    Render *m_render;
175
    QTextEdit *m_notesWidget;
176
    QUndoStack *m_commandStack;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
177
    ClipManager *m_clipManager;
178
    MltVideoProfile m_profile;
179
    QString m_searchFolder;
180 181

    /** @brief Tells whether the current document has been changed after being saved. */
182
    bool m_modified;
183 184

    /** @brief The project folder, used to store project files (titles, effects...). */
185
    QUrl m_projectFolder;
186
    QMap <QString, QString> m_documentProperties;
187
    QMap <QString, QString> m_documentMetadata;
188

189
    QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const;
190
    void moveProjectData(const QUrl &url);
191 192

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

196 197
    /** @brief Updates the project folder location entry in the kdenlive file dialogs to point to the current project folder. */
    void updateProjectFolderPlacesEntry();
198 199
    /** @brief Only keep some backup files, delete some */
    void cleanupBackupFiles();
200 201
    /** @brief Load document properties from the xml file */
    void loadDocumentProperties();
202
    /** @brief update document properties to reflect a change in the current profile */
203
    void updateProjectProfile(bool reloadProducers = false);
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 210
     * @description  If crash recovery is turned on, a timer calls KdenliveDoc::slotAutoSave() \n
     * Emits docModified conected to MainWindow::slotUpdateDocumentState \n
211
     * @param mod (optional) true if the document has to be saved */
212
    void setModified(bool mod = true);
213
    void slotProxyCurrentItem(bool doProxy, QList<ProjectClip *> clipList = QList<ProjectClip *>());
214
    /** @brief Saves the current project at the autosave location.
215
     * @description The autosave files are in ~/.kde/data/stalefiles/kdenlive/ */
216
    void slotAutoSave();
217 218

private slots:
219 220 221
    void slotClipModified(const QString &path);
    void slotClipMissing(const QString &path);
    void slotProcessModifiedClips();
222
    void slotModified();
223
    void slotSetDocumentNotes(const QString &notes);
224
    void switchProfile(MltVideoProfile profile, const QString &id, const QDomElement &xml);
225
    void slotSwitchProfile();
226

227
signals:
228
    void resetProjectList();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
229
    void progressInfo(const QString &, int);
230 231 232 233

    /** @brief Informs that the document status has been changed.
     *
     * If the document has been modified, it's called with true as an argument. */
234
    void docModified(bool);
235
    void selectLastAddedClip(const QString &);
236
    void guidesUpdated();
237
    /** @brief When creating a backup file, also save a thumbnail of current timeline */
238
    void saveTimelinePreview(const QString &path);
239 240
    /** @brief Trigger the autosave timer start */
    void startAutoSave();
241 242
    /** @brief Current doc created effects, reload list */
    void reloadEffects();
243
    /** @brief Fps was changed, update timeline */
244
    void updateFps(bool changed);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
245 246 247
};

#endif
Vincent PINON's avatar
Vincent PINON committed
248