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

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
21 22 23
#ifndef KDENLIVEDOC_H
#define KDENLIVEDOC_H

Laurent Montel's avatar
Laurent Montel committed
24
#include <QtXml/qdom.h>
25
#include <QMap>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
26
#include <QList>
27
#include <QDir>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
28 29
#include <QObject>

30
#include <KUrl>
31
#include <kautosavefile.h>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
32 33

#include "gentime.h"
34
#include "timecode.h"
35
#include "definitions.h"
36
#include "timeline/guide.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
37

38 39 40
class Render;
class ClipManager;
class DocClipBase;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
41
class MainWindow;
42
class TrackInfo;
43

44
class KTextEdit;
45
class KProgressDialog;
46 47 48
class QUndoGroup;
class QTimer;
class QUndoStack;
49

50 51
class KdenliveDoc: public QObject
{
52 53
    Q_OBJECT
public:
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
54

Laurent Montel's avatar
Laurent Montel committed
55
    KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QMap <QString, QString>& properties, const QMap <QString, QString>& metadata, const QPoint &tracks, Render *render, KTextEdit *notes, bool *openBackup, MainWindow *parent = 0, KProgressDialog *progressDialog = 0);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
56 57
    ~KdenliveDoc();
    QDomNodeList producersList();
58 59 60 61
    double fps() const;
    int width() const;
    int height() const;
    KUrl url() const;
62
    KAutoSaveFile *m_autosave;
63
    Timecode timecode() const;
64
    QDomDocument toXml();
65
    //void setRenderer(Render *render);
66
    QUndoStack *commandStack();
67
    Render *renderer();
68
    QDomDocument m_guidesXml;
69
    QDomElement guidesXml() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
70
    ClipManager *clipManager();
71 72 73

    /** @brief Adds a clip to the project tree.
     * @return false if the user aborted the operation, true otherwise */
74
    bool addClip(QDomElement elem, const QString &clipId, bool createClipItem = true);
75 76 77 78 79 80 81 82 83

    /** @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. */
84
    bool addClipInfo(QDomElement elem, QDomElement orig, const QString &clipId);
Laurent Montel's avatar
Laurent Montel committed
85
    void slotAddClipList(const KUrl::List &urls, const stringMap &data = stringMap());
86
    void deleteClip(const QString &clipId);
Laurent Montel's avatar
Laurent Montel committed
87
    int getFramePos(const QString &duration);
88
    DocClipBase *getBaseClip(const QString &clipId);
89
    void updateClip(const QString &id);
90 91

    /** @brief Informs Kdenlive of the audio thumbnails generation progress. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
92
    void setThumbsProgress(const QString &message, int progress);
93
    const QString &profilePath() const;
94
    MltVideoProfile mltProfile() const;
95
    const QString description() const;
96
    void setUrl(const KUrl &url);
97 98 99

    /** @brief Updates the project profile.
     * @return true if frame rate was changed */
100
    bool setProfilePath(QString path);
101
    const QString getFreeClipId();
102 103

    /** @brief Defines whether the document needs to be saved. */
104
    bool isModified() const;
105 106

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

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

127 128
    void switchTrackVideo(int ix, bool hide);
    void switchTrackAudio(int ix, bool hide);
129
    void switchTrackLock(int ix, bool lock);
130 131 132 133 134 135 136 137 138 139 140
    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);
141
    void cacheImage(const QString &fileId, const QImage &img) const;
142
    void setProjectFolder(KUrl url);
143 144
    void setZone(int start, int end);
    QPoint zone() const;
145
    int setSceneList();
146 147
    void setDocumentProperty(const QString &name, const QString &value);
    const QString getDocumentProperty(const QString &name) const;
148 149

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

    /** @brief Tells whether the current document has been changed after being saved. */
187
    bool m_modified;
188 189

    /** @brief The project folder, used to store project files (titles, effects...). */
190
    KUrl m_projectFolder;
191
    QMap <QString, QString> m_documentProperties;
192
    QMap <QString, QString> m_documentMetadata;
193 194

    QList <TrackInfo> m_tracksList;
195
    void setNewClipResource(const QString &id, const QString &path);
196
    QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const;
Laurent Montel's avatar
Laurent Montel committed
197
    void moveProjectData(const KUrl &url);
198
    bool checkDocumentClips(QDomNodeList infoproducers);
199 200

    /** @brief Creates a new project. */
201
    QDomDocument createEmptyDocument(int videotracks, int audiotracks);
202
    QDomDocument createEmptyDocument(const QList<TrackInfo> &tracks);
203 204
    /** @brief Saves effects embedded in project file.
    *   @return True if effects were imported.  */
205
    bool saveCustomEffects(const QDomNodeList &customeffects);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
206

207 208
    /** @brief Updates the project folder location entry in the kdenlive file dialogs to point to the current project folder. */
    void updateProjectFolderPlacesEntry();
209 210
    /** @brief Only keep some backup files, delete some */
    void cleanupBackupFiles();
211

212
public slots:
213 214 215
    void slotCreateXmlClip(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
    void slotCreateColorClip(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId);
    void slotCreateSlideshowClipFile(const QMap<QString, QString> &properties, const QString &group, const QString &groupId);
216
    void slotCreateTextClip(QString group, const QString &groupId, const QString &templatePath = QString());
217
    void slotCreateTextTemplateClip(const QString &group, const QString &groupId, KUrl path);
218 219 220

    /** @brief Sets the document as modified or up to date.
     * @param mod (optional) true if the document has to be saved */
221
    void setModified(bool mod = true);
222
    void checkProjectClips(bool displayRatioChanged = false, bool fpsChanged = false);
Laurent Montel's avatar
Laurent Montel committed
223
    void slotAddClipFile(const KUrl &url, const stringMap &data);
224

225 226 227
private slots:
    void slotAutoSave();

228
signals:
229
    void resetProjectList();
230
    void addProjectClip(DocClipBase *, bool getInfo = true);
231 232
    void signalDeleteProjectClip(const QString &);
    void updateClipDisplay(const QString&);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
233
    void progressInfo(const QString &, int);
234 235 236 237

    /** @brief Informs that the document status has been changed.
     *
     * If the document has been modified, it's called with true as an argument. */
238
    void docModified(bool);
239
    void selectLastAddedClip(const QString &);
240
    void guidesUpdated();
241
    /** @brief When creating a backup file, also save a thumbnail of current timeline */
242
    void saveTimelinePreview(const QString &path);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
243 244 245
};

#endif
Vincent PINON's avatar
Vincent PINON committed
246