kdenlivedoc.h 11.7 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
class QProgressDialog;
55 56 57
class QUndoGroup;
class QTimer;
class QUndoStack;
58

59 60 61 62
namespace Mlt {
    class Profile;
}

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

68
    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
69 70
    ~KdenliveDoc();
    QDomNodeList producersList();
71 72 73
    double fps() const;
    int width() const;
    int height() const;
74
    QUrl url() const;
75
    KAutoSaveFile *m_autosave;
76
    Timecode timecode() const;
77
    QDomDocument toXml();
78
    QUndoStack *commandStack();
79
    Render *renderer();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
80
    ClipManager *clipManager();
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, bool createClipItem = true);
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
    void updateClip(const QString &id);
103 104

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

    /** @brief Updates the project profile.
     * @return true if frame rate was changed */
115
    bool setProfilePath(QString path);
116 117

    /** @brief Defines whether the document needs to be saved. */
118
    bool isModified() const;
119 120

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

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

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

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

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

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

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

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

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

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

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

private slots:
258 259 260 261
    void slotClipModified(const QString &path);
    void slotClipMissing(const QString &path);
    void slotClipAvailable(const QString &path);
    void slotProcessModifiedClips();
262

263
signals:
264
    void resetProjectList();
265
    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);
276 277
    /** @brief Trigger the autosave timer start */
    void startAutoSave();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
278 279 280
};

#endif
Vincent PINON's avatar
Vincent PINON committed
281