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
    QString producerName(const QString &id);
68
    Render *renderer();
69
    QDomDocument m_guidesXml;
70
    QDomElement guidesXml() const;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
71
    ClipManager *clipManager();
72 73 74

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

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

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

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

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

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

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

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

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

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

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

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

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

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

213
public slots:
214 215 216
    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);
217
    void slotCreateTextClip(QString group, const QString &groupId, const QString &templatePath = QString());
218
    void slotCreateTextTemplateClip(const QString &group, const QString &groupId, KUrl path);
219 220 221

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

226 227 228
private slots:
    void slotAutoSave();

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

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

#endif