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();
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
    /** @brief Get a bin's clip from its id. */
94
    ProjectClip *getBinClip(const QString &clipId);
95 96
    /** @brief Get a list of all clip ids that are inside a folder. */
    QStringList getBinFolderClipIds(const QString &folderId) const;
97
    ClipController *getClipController(const QString &clipId);
98
    void updateClip(const QString &id);
99 100

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

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

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

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

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

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

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

    /** @brief Tells whether the current document has been changed after being saved. */
205
    bool m_modified;
206 207

    /** @brief The project folder, used to store project files (titles, effects...). */
208
    QUrl m_projectFolder;
209
    QMap <QString, QString> m_documentProperties;
210
    QMap <QString, QString> m_documentMetadata;
211 212

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

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

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

236
public slots:
237
    void slotCreateXmlClip(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
238
    void slotCreateTextTemplateClip(const QString &group, const QString &groupId, QUrl path);
239 240

    /** @brief Sets the document as modified or up to date.
241 242
     * @description  If crash recovery is turned on, a timer calls KdenliveDoc::slotAutoSave() \n
     * Emits docModified conected to MainWindow::slotUpdateDocumentState \n
243
     * @param mod (optional) true if the document has to be saved */
244
    void setModified(bool mod = true);
245
    void checkProjectClips(bool displayRatioChanged = false, bool fpsChanged = false);
246
    void slotProxyCurrentItem(bool doProxy);
247
    /** @brief Saves the current project at the autosave location.
248
     * @description The autosave files are in ~/.kde/data/stalefiles/kdenlive/ */
249 250 251
    void slotAutoSave(QMap <double, QString> guidesData);

private slots:
252 253 254 255
    void slotClipModified(const QString &path);
    void slotClipMissing(const QString &path);
    void slotClipAvailable(const QString &path);
    void slotProcessModifiedClips();
256

257
signals:
258
    void resetProjectList();
259
    void updateClipDisplay(const QString&);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
260
    void progressInfo(const QString &, int);
261 262 263 264

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

#endif
Vincent PINON's avatar
Vincent PINON committed
275