kdenlivedoc.h 11.6 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"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
43

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

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

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

63
    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
64 65
    ~KdenliveDoc();
    QDomNodeList producersList();
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
    QDomDocument toXml();
73
    //void setRenderer(Render *render);
74
    QUndoStack *commandStack();
75
    Render *renderer();
76
    QDomDocument m_guidesXml;
77
    QDomElement guidesXml() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
78
    ClipManager *clipManager();
79 80 81

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

    /** @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. */
92
    bool addClipInfo(QDomElement elem, QDomElement orig, const QString &clipId);
93
    void deleteClip(const QString &clipId);
Laurent Montel's avatar
Laurent Montel committed
94
    int getFramePos(const QString &duration);
95
    /** @brief Get a bin's clip from its id. */
96
    ProjectClip *getBinClip(const QString &clipId);
97 98
    /** @brief Get a list of all clip ids that are inside a folder. */
    QStringList getBinFolderClipIds(const QString &folderId) const;
99
    ClipController *getClipController(const QString &clipId);
100
    void updateClip(const QString &id);
101 102

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

    /** @brief Updates the project profile.
     * @return true if frame rate was changed */
111
    bool setProfilePath(QString path);
112 113

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

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

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

137 138
    void switchTrackVideo(int ix, bool hide);
    void switchTrackAudio(int ix, bool hide);
139
    void switchTrackLock(int ix, bool lock);
140 141 142 143 144 145 146 147 148 149 150
    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);
151
    void cacheImage(const QString &fileId, const QImage &img) const;
152
    void setProjectFolder(QUrl url);
153 154
    void setZone(int start, int end);
    QPoint zone() const;
155
    int setSceneList();
156 157
    void setDocumentProperty(const QString &name, const QString &value);
    const QString getDocumentProperty(const QString &name) const;
158 159

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

    /** @brief Tells whether the current document has been changed after being saved. */
209
    bool m_modified;
210 211

    /** @brief The project folder, used to store project files (titles, effects...). */
212
    QUrl m_projectFolder;
213
    QMap <QString, QString> m_documentProperties;
214
    QMap <QString, QString> m_documentMetadata;
215 216

    QList <TrackInfo> m_tracksList;
217
    void setNewClipResource(const QString &id, const QString &path);
218
    QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const;
219
    void moveProjectData(const QUrl &url);
220 221 222 223 224 225
    /**
     * @brief check for issues with the clips in the project
     * Instansiates DocumentChecker objects to do this task.
     * @param infoproducers
     * @return
     */
226
    bool checkDocumentClips(QDomNodeList infoproducers);
227 228

    /** @brief Creates a new project. */
229
    QDomDocument createEmptyDocument(int videotracks, int audiotracks);
230
    QDomDocument createEmptyDocument(const QList<TrackInfo> &tracks);
231 232
    /** @brief Saves effects embedded in project file.
    *   @return True if effects were imported.  */
233
    bool saveCustomEffects(const QDomNodeList &customeffects);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
234

235 236
    /** @brief Updates the project folder location entry in the kdenlive file dialogs to point to the current project folder. */
    void updateProjectFolderPlacesEntry();
237 238
    /** @brief Only keep some backup files, delete some */
    void cleanupBackupFiles();
239

240
public slots:
241
    void slotCreateXmlClip(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
242
    void slotCreateTextTemplateClip(const QString &group, const QString &groupId, QUrl path);
243 244

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

252
private slots:
253
    /** @brief Saves the current project at the autosave location.
254
     * @description The autosave files are in ~/.kde/data/stalefiles/kdenlive/ */
255
    void slotAutoSave();
256 257 258 259
    void slotClipModified(const QString &path);
    void slotClipMissing(const QString &path);
    void slotClipAvailable(const QString &path);
    void slotProcessModifiedClips();
260

261
signals:
262
    void resetProjectList();
263
    //void addProjectClip(DocClipBase *, bool getInfo = true);
264 265
    void signalDeleteProjectClip(const QString &);
    void updateClipDisplay(const QString&);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
266
    void progressInfo(const QString &, int);
267 268 269 270

    /** @brief Informs that the document status has been changed.
     *
     * If the document has been modified, it's called with true as an argument. */
271
    void docModified(bool);
272
    void selectLastAddedClip(const QString &);
273
    void guidesUpdated();
274
    /** @brief When creating a backup file, also save a thumbnail of current timeline */
275
    void saveTimelinePreview(const QString &path);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
276 277 278
};

#endif
Vincent PINON's avatar
Vincent PINON committed
279