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

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 33
#include <QObject>

34
#include <QUrl>
35
#include <kautosavefile.h>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
36 37

#include "gentime.h"
38
#include "timecode.h"
39
#include "definitions.h"
40
#include "timeline/guide.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
41

42 43
class Render;
class ClipManager;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
44
class MainWindow;
45
class TrackInfo;
46
class NotesPlugin;
47
class ProjectClip;
48
class ClipController;
49

50
class QTextEdit;
51
class QProgressDialog;
52 53 54
class QUndoGroup;
class QTimer;
class QUndoStack;
55

56 57
class KdenliveDoc: public QObject
{
58 59
    Q_OBJECT
public:
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
60

61
    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, QProgressDialog *progressDialog = 0);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
62 63
    ~KdenliveDoc();
    QDomNodeList producersList();
64 65 66
    double fps() const;
    int width() const;
    int height() const;
67
    QUrl url() const;
68
    KAutoSaveFile *m_autosave;
69
    Timecode timecode() const;
70
    QDomDocument toXml();
71
    //void setRenderer(Render *render);
72
    QUndoStack *commandStack();
73
    Render *renderer();
74
    QDomDocument m_guidesXml;
75
    QDomElement guidesXml() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
76
    ClipManager *clipManager();
77 78 79

    /** @brief Adds a clip to the project tree.
     * @return false if the user aborted the operation, true otherwise */
80
    bool addClip(QDomElement elem, const QString &clipId, bool createClipItem = true);
81 82 83 84 85 86 87 88 89

    /** @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. */
90
    bool addClipInfo(QDomElement elem, QDomElement orig, const QString &clipId);
91
    void deleteClip(const QString &clipId);
Laurent Montel's avatar
Laurent Montel committed
92
    int getFramePos(const QString &duration);
93
    ProjectClip *getBinClip(const QString &clipId);
94
    ClipController *getClipController(const QString &clipId);
95
    void updateClip(const QString &id);
96 97

    /** @brief Informs Kdenlive of the audio thumbnails generation progress. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
98
    void setThumbsProgress(const QString &message, int progress);
99
    const QString &profilePath() const;
100
    MltVideoProfile mltProfile() const;
101
    const QString description() const;
102
    void setUrl(const QUrl &url);
103 104 105

    /** @brief Updates the project profile.
     * @return true if frame rate was changed */
106
    bool setProfilePath(QString path);
107 108

    /** @brief Defines whether the document needs to be saved. */
109
    bool isModified() const;
110 111

    /** @brief Returns the project folder, used to store project files. */
112
    QUrl projectFolder() const;
113
    void syncGuides(const QList <Guide *> &guides);
114 115
    void setZoom(int horizontal, int vertical);
    QPoint zoom() const;
116
    double dar() const;
117
    double projectDuration() const;
118
    /** @brief Returns the project file xml. */
119
    QDomDocument xmlSceneList(const QString &scene, const QStringList &expandedFolders);
120
    /** @brief Saves the project file xml to a file. */
121
    bool saveSceneList(const QString &path, const QString &scene, const QStringList &expandedFolders, bool autosave = false);
122 123
    int tracksCount() const;
    TrackInfo trackInfoAt(int ix) const;
124
    void insertTrack(int ix, const TrackInfo &type);
125
    void deleteTrack(int ix);
126
    void setTrackType(int ix, const TrackInfo &type);
127
    const QList <TrackInfo> tracksList() const;
Till Theato's avatar
Till Theato committed
128 129

    /** @brief Gets the number of audio and video tracks and returns them as a QPoint with x = video, y = audio. */
130
    QPoint getTracksCount() const;
Till Theato's avatar
Till Theato committed
131

132 133
    void switchTrackVideo(int ix, bool hide);
    void switchTrackAudio(int ix, bool hide);
134
    void switchTrackLock(int ix, bool lock);
135 136 137 138 139 140 141 142 143 144 145
    bool isTrackLocked(int ix) const;

    /** @brief Sets the duration of track @param ix to @param duration.
     * This does not! influence the actual track but only the value in its TrackInfo. */
    void setTrackDuration(int ix, int duration);

    /** @brief Returns the duration of track @param ix.
     *
     * The returned duration might differ from the actual track duration!
     * It is the one stored in the track's TrackInfo. */
    int trackDuration(int ix);
146
    void cacheImage(const QString &fileId, const QImage &img) const;
147
    void setProjectFolder(QUrl url);
148 149
    void setZone(int start, int end);
    QPoint zone() const;
150
    int setSceneList();
151 152
    void setDocumentProperty(const QString &name, const QString &value);
    const QString getDocumentProperty(const QString &name) const;
153
    void addClipList(const QList<QUrl> &urls, const QMap<QString, QString> &data = QMap<QString, QString>());
154 155

    /** @brief Gets the list of renderer properties saved into the document. */
156
    QMap <QString, QString> getRenderProperties() const;
157
    void addTrackEffect(int ix, QDomElement effect);
158
    void removeTrackEffect(int ix, const QDomElement &effect);
159 160
    void setTrackEffect(int trackIndex, int effectIndex, QDomElement effect);
    const EffectsList getTrackEffects(int ix);
161
    /** @brief Enable / disable an effect in Kdenlive's xml list. */
162
    void enableTrackEffects(int trackIndex, const QList<int> &effectIndexes, bool disable);
163
    QDomElement getTrackEffect(int trackIndex, int effectIndex) const;
164 165
    /** @brief Check if a track already contains a specific effect. */
    int hasTrackEffect(int trackIndex, const QString &tag, const QString &id) const;
166 167
    /** @brief Get a list of folder id's that were opened on last save. */
    QStringList getExpandedFolders();
168 169
    /** @brief Read the display ratio from an xml project file. */
    static double getDisplayRatio(const QString &path);
170 171
    /** @brief Backup the project file */
    void backupLastSavedVersion(const QString &path);
172 173 174
    /** @brief Returns the document metadata (author, copyright, ...) */
    const QMap <QString, QString> metadata() const;
    /** @brief Set the document metadata (author, copyright, ...) */
175
    void setMetadata(const QMap <QString, QString>& meta);
176 177 178
    void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
    /** @brief Get frame size of the renderer */
    const QSize getRenderSize();
179
    
180
private:
181
    QUrl m_url;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
182
    QDomDocument m_document;
183 184 185 186
    double m_fps;
    int m_width;
    int m_height;
    Timecode m_timecode;
187
    Render *m_render;
188
    QTextEdit *m_notesWidget;
189
    QUndoStack *m_commandStack;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
190
    ClipManager *m_clipManager;
191
    MltVideoProfile m_profile;
192
    QTimer *m_autoSaveTimer;
193
    QString m_searchFolder;
194 195

    /** @brief Tells whether the current document has been changed after being saved. */
196
    bool m_modified;
197 198

    /** @brief The project folder, used to store project files (titles, effects...). */
199
    QUrl m_projectFolder;
200
    QMap <QString, QString> m_documentProperties;
201
    QMap <QString, QString> m_documentMetadata;
202 203

    QList <TrackInfo> m_tracksList;
204
    void setNewClipResource(const QString &id, const QString &path);
205
    QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const;
206
    void moveProjectData(const QUrl &url);
207 208 209 210 211 212
    /**
     * @brief check for issues with the clips in the project
     * Instansiates DocumentChecker objects to do this task.
     * @param infoproducers
     * @return
     */
213
    bool checkDocumentClips(QDomNodeList infoproducers);
214 215

    /** @brief Creates a new project. */
216
    QDomDocument createEmptyDocument(int videotracks, int audiotracks);
217
    QDomDocument createEmptyDocument(const QList<TrackInfo> &tracks);
218 219
    /** @brief Saves effects embedded in project file.
    *   @return True if effects were imported.  */
220
    bool saveCustomEffects(const QDomNodeList &customeffects);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
221

222 223
    /** @brief Updates the project folder location entry in the kdenlive file dialogs to point to the current project folder. */
    void updateProjectFolderPlacesEntry();
224 225
    /** @brief Only keep some backup files, delete some */
    void cleanupBackupFiles();
226

227
public slots:
228
    void slotCreateXmlClip(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
229
    void slotCreateTextTemplateClip(const QString &group, const QString &groupId, QUrl path);
230 231

    /** @brief Sets the document as modified or up to date.
232 233
     * @description  If crash recovery is turned on, a timer calls KdenliveDoc::slotAutoSave() \n
     * Emits docModified conected to MainWindow::slotUpdateDocumentState \n
234
     * @param mod (optional) true if the document has to be saved */
235
    void setModified(bool mod = true);
236
    void checkProjectClips(bool displayRatioChanged = false, bool fpsChanged = false);
237
    void slotProxyCurrentItem(bool doProxy);
238

239
private slots:
240
    /** @brief Saves the current project at the autosave location.
241
     * @description The autosave files are in ~/.kde/data/stalefiles/kdenlive/ */
242 243
    void slotAutoSave();

244
signals:
245
    void resetProjectList();
246
    //void addProjectClip(DocClipBase *, bool getInfo = true);
247 248
    void signalDeleteProjectClip(const QString &);
    void updateClipDisplay(const QString&);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
249
    void progressInfo(const QString &, int);
250 251 252 253

    /** @brief Informs that the document status has been changed.
     *
     * If the document has been modified, it's called with true as an argument. */
254
    void docModified(bool);
255
    void selectLastAddedClip(const QString &);
256
    void guidesUpdated();
257
    /** @brief When creating a backup file, also save a thumbnail of current timeline */
258
    void saveTimelinePreview(const QString &path);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
259 260 261
};

#endif
Vincent PINON's avatar
Vincent PINON committed
262