]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.h
448470d7a36e28ab1e9c0e23d34d6cc31c2bd6df
[kdenlive] / src / kdenlivedoc.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #ifndef KDENLIVEDOC_H
22 #define KDENLIVEDOC_H
23
24 #include <QtXml/qdom.h>
25 #include <QMap>
26 #include <QList>
27 #include <QDir>
28 #include <QObject>
29
30 #include <KUrl>
31 #include <kautosavefile.h>
32
33 #include "gentime.h"
34 #include "timecode.h"
35 #include "definitions.h"
36 #include "guide.h"
37
38 class Render;
39 class ClipManager;
40 class DocClipBase;
41 class MainWindow;
42 class TrackInfo;
43
44 class KTextEdit;
45 class KProgressDialog;
46 class QUndoGroup;
47 class QTimer;
48 class QUndoStack;
49
50 class KdenliveDoc: public QObject
51 {
52     Q_OBJECT
53 public:
54
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);
56     ~KdenliveDoc();
57     QDomNodeList producersList();
58     double fps() const;
59     int width() const;
60     int height() const;
61     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;
71     ClipManager *clipManager();
72
73     /** @brief Adds a clip to the project tree.
74      * @return false if the user aborted the operation, true otherwise */
75     bool addClip(QDomElement elem, const QString &clipId, bool createClipItem = true);
76
77     /** @brief Updates information about a clip.
78      * @param elem the <kdenlive_producer />
79      * @param orig the potential <producer />
80      * @param clipId the producer id
81      * @return false if the user aborted the operation (in case the clip wasn't
82      *     there yet), true otherwise
83      *
84      * 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);
86     void slotAddClipList(const KUrl::List &urls, const stringMap &data = stringMap());
87     void deleteClip(const QString &clipId);
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. */
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     /** @brief Updates the project profile.
100      * @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     void setZoom(int horizontal, int vertical);
111     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     int tracksCount() const;
119     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;
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;
127
128     void switchTrackVideo(int ix, bool hide);
129     void switchTrackAudio(int ix, bool hide);
130     void switchTrackLock(int ix, bool lock);
131     bool isTrackLocked(int ix) const;
132
133     /** @brief Sets the duration of track @param ix to @param duration.
134      * This does not! influence the actual track but only the value in its TrackInfo. */
135     void setTrackDuration(int ix, int duration);
136
137     /** @brief Returns the duration of track @param ix.
138      *
139      * The returned duration might differ from the actual track duration!
140      * It is the one stored in the track's TrackInfo. */
141     int trackDuration(int ix);
142     void cacheImage(const QString &fileId, const QImage &img) const;
143     void setProjectFolder(KUrl url);
144     void setZone(int start, int end);
145     QPoint zone() const;
146     int setSceneList();
147     void setDocumentProperty(const QString &name, const QString &value);
148     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     void setTrackEffect(int trackIndex, int effectIndex, QDomElement effect);
155     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     /** @brief Check if a track already contains a specific effect. */
160     int hasTrackEffect(int trackIndex, const QString &tag, const QString &id) const;
161     /** @brief Get a list of folder id's that were opened on last save. */
162     QStringList getExpandedFolders();
163     /** @brief Read the display ratio from an xml project file. */
164     static double getDisplayRatio(const QString &path);
165     /** @brief Backup the project file */
166     void backupLastSavedVersion(const QString &path);
167     /** @brief Returns the document metadata (author, copyright, ...) */
168     const QMap <QString, QString> metadata() const;
169     /** @brief Set the document metadata (author, copyright, ...) */
170     void setMetadata(const QMap <QString, QString>& meta);
171     
172 private:
173     KUrl m_url;
174     QDomDocument m_document;
175     double m_fps;
176     int m_width;
177     int m_height;
178     Timecode m_timecode;
179     Render *m_render;
180     KTextEdit *m_notesWidget;
181     QUndoStack *m_commandStack;
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;
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     /** @brief Saves effects embedded in project file.
205     *   @return True if effects were imported.  */
206     bool saveCustomEffects(const QDomNodeList &customeffects);
207
208     /** @brief Updates the project folder location entry in the kdenlive file dialogs to point to the current project folder. */
209     void updateProjectFolderPlacesEntry();
210     /** @brief Only keep some backup files, delete some */
211     void cleanupBackupFiles();
212
213 public slots:
214     void slotCreateXmlClip(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
215     void slotCreateColorClip(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId);
216     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     /** @brief Sets the document as modified or up to date.
221      * @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);
224     void slotAddClipFile(const KUrl &url, const stringMap &data);
225
226 private slots:
227     void slotAutoSave();
228
229 signals:
230     void resetProjectList();
231     void addProjectClip(DocClipBase *, bool getInfo = true);
232     void signalDeleteProjectClip(const QString &);
233     void updateClipDisplay(const QString&);
234     void progressInfo(const QString &, int);
235
236     /** @brief Informs that the document status has been changed.
237      *
238      * 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);
244 };
245
246 #endif