]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.h
Various changes for getting an OpenGL context (almost) everywhere it is needed.
[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 QGLWidget;
47 class QUndoGroup;
48 class QTimer;
49 class QUndoStack;
50
51 class KdenliveDoc: public QObject
52 {
53     Q_OBJECT
54 public:
55
56     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, QGLWidget *glContext, MainWindow *parent = 0, KProgressDialog *progressDialog = 0);
57     ~KdenliveDoc();
58     QDomNodeList producersList();
59     double fps() const;
60     int width() const;
61     int height() const;
62     KUrl url() const;
63     KAutoSaveFile *m_autosave;
64     Timecode timecode() const;
65     QDomDocument toXml();
66     //void setRenderer(Render *render);
67     QUndoStack *commandStack();
68     QString producerName(const QString &id);
69     Render *renderer();
70     QDomDocument m_guidesXml;
71     QDomElement guidesXml() const;
72     ClipManager *clipManager();
73
74     /** @brief Adds a clip to the project tree.
75      * @return false if the user aborted the operation, true otherwise */
76     bool addClip(QDomElement elem, const QString &clipId, bool createClipItem = true);
77
78     /** @brief Updates information about a clip.
79      * @param elem the <kdenlive_producer />
80      * @param orig the potential <producer />
81      * @param clipId the producer id
82      * @return false if the user aborted the operation (in case the clip wasn't
83      *     there yet), true otherwise
84      *
85      * If the clip wasn't added before, it tries to add it to the project. */
86     bool addClipInfo(QDomElement elem, QDomElement orig, const QString &clipId);
87     void slotAddClipList(const KUrl::List &urls, const stringMap &data = stringMap());
88     void deleteClip(const QString &clipId);
89     int getFramePos(const QString &duration);
90     DocClipBase *getBaseClip(const QString &clipId);
91     void updateClip(const QString &id);
92
93     /** @brief Informs Kdenlive of the audio thumbnails generation progress. */
94     void setThumbsProgress(const QString &message, int progress);
95     const QString &profilePath() const;
96     MltVideoProfile mltProfile() const;
97     const QString description() const;
98     void setUrl(const KUrl &url);
99
100     /** @brief Updates the project profile.
101      * @return true if frame rate was changed */
102     bool setProfilePath(QString path);
103     const QString getFreeClipId();
104
105     /** @brief Defines whether the document needs to be saved. */
106     bool isModified() const;
107
108     /** @brief Returns the project folder, used to store project files. */
109     KUrl projectFolder() const;
110     void syncGuides(const QList <Guide *> &guides);
111     void setZoom(int horizontal, int vertical);
112     QPoint zoom() const;
113     double dar() const;
114     double projectDuration() const;
115     /** @brief Returns the project file xml. */
116     QDomDocument xmlSceneList(const QString &scene, const QStringList &expandedFolders);
117     /** @brief Saves the project file xml to a file. */
118     bool saveSceneList(const QString &path, const QString &scene, const QStringList &expandedFolders, bool autosave = false);
119     int tracksCount() const;
120     TrackInfo trackInfoAt(int ix) const;
121     void insertTrack(int ix, const TrackInfo &type);
122     void deleteTrack(int ix);
123     void setTrackType(int ix, const TrackInfo &type);
124     const QList <TrackInfo> tracksList() const;
125
126     /** @brief Gets the number of audio and video tracks and returns them as a QPoint with x = video, y = audio. */
127     QPoint getTracksCount() const;
128
129     void switchTrackVideo(int ix, bool hide);
130     void switchTrackAudio(int ix, bool hide);
131     void switchTrackLock(int ix, bool lock);
132     bool isTrackLocked(int ix) const;
133
134     /** @brief Sets the duration of track @param ix to @param duration.
135      * This does not! influence the actual track but only the value in its TrackInfo. */
136     void setTrackDuration(int ix, int duration);
137
138     /** @brief Returns the duration of track @param ix.
139      *
140      * The returned duration might differ from the actual track duration!
141      * It is the one stored in the track's TrackInfo. */
142     int trackDuration(int ix);
143     void cacheImage(const QString &fileId, const QImage &img) const;
144     void setProjectFolder(KUrl url);
145     void setZone(int start, int end);
146     QPoint zone() const;
147     int setSceneList();
148     void setDocumentProperty(const QString &name, const QString &value);
149     const QString getDocumentProperty(const QString &name) const;
150
151     /** @brief Gets the list of renderer properties saved into the document. */
152     QMap <QString, QString> getRenderProperties() const;
153     void addTrackEffect(int ix, QDomElement effect);
154     void removeTrackEffect(int ix, const QDomElement &effect);
155     void setTrackEffect(int trackIndex, int effectIndex, QDomElement effect);
156     const EffectsList getTrackEffects(int ix);
157     /** @brief Enable / disable an effect in Kdenlive's xml list. */
158     void enableTrackEffects(int trackIndex, const QList<int> &effectIndexes, bool disable);
159     QDomElement getTrackEffect(int trackIndex, int effectIndex) const;
160     /** @brief Check if a track already contains a specific effect. */
161     int hasTrackEffect(int trackIndex, const QString &tag, const QString &id) const;
162     /** @brief Get a list of folder id's that were opened on last save. */
163     QStringList getExpandedFolders();
164     /** @brief Read the display ratio from an xml project file. */
165     static double getDisplayRatio(const QString &path);
166     /** @brief Backup the project file */
167     void backupLastSavedVersion(const QString &path);
168     /** @brief Returns the document metadata (author, copyright, ...) */
169     const QMap <QString, QString> metadata() const;
170     /** @brief Set the document metadata (author, copyright, ...) */
171     void setMetadata(const QMap <QString, QString>& meta);
172     
173 private:
174     KUrl m_url;
175     QDomDocument m_document;
176     double m_fps;
177     int m_width;
178     int m_height;
179     Timecode m_timecode;
180     Render *m_render;
181     KTextEdit *m_notesWidget;
182     QUndoStack *m_commandStack;
183     ClipManager *m_clipManager;
184     MltVideoProfile m_profile;
185     QTimer *m_autoSaveTimer;
186     QString m_searchFolder;
187
188     /** @brief Tells whether the current document has been changed after being saved. */
189     bool m_modified;
190
191     /** @brief The project folder, used to store project files (titles, effects...). */
192     KUrl m_projectFolder;
193     QMap <QString, QString> m_documentProperties;
194     QMap <QString, QString> m_documentMetadata;
195
196     QList <TrackInfo> m_tracksList;
197     void setNewClipResource(const QString &id, const QString &path);
198     QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const;
199     void moveProjectData(const KUrl &url);
200     bool checkDocumentClips(QDomNodeList infoproducers);
201
202     /** @brief Creates a new project. */
203     QDomDocument createEmptyDocument(int videotracks, int audiotracks);
204     QDomDocument createEmptyDocument(const QList<TrackInfo> &tracks);
205     /** @brief Saves effects embedded in project file.
206     *   @return True if effects were imported.  */
207     bool saveCustomEffects(const QDomNodeList &customeffects);
208
209     /** @brief Updates the project folder location entry in the kdenlive file dialogs to point to the current project folder. */
210     void updateProjectFolderPlacesEntry();
211     /** @brief Only keep some backup files, delete some */
212     void cleanupBackupFiles();
213
214 public slots:
215     void slotCreateXmlClip(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
216     void slotCreateColorClip(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId);
217     void slotCreateSlideshowClipFile(const QMap<QString, QString> &properties, const QString &group, const QString &groupId);
218     void slotCreateTextClip(QString group, const QString &groupId, const QString &templatePath = QString());
219     void slotCreateTextTemplateClip(const QString &group, const QString &groupId, KUrl path);
220
221     /** @brief Sets the document as modified or up to date.
222      * @param mod (optional) true if the document has to be saved */
223     void setModified(bool mod = true);
224     void checkProjectClips(bool displayRatioChanged = false, bool fpsChanged = false);
225     void slotAddClipFile(const KUrl &url, const stringMap &data);
226
227 private slots:
228     void slotAutoSave();
229
230 signals:
231     void resetProjectList();
232     void addProjectClip(DocClipBase *, bool getInfo = true);
233     void signalDeleteProjectClip(const QString &);
234     void updateClipDisplay(const QString&);
235     void progressInfo(const QString &, int);
236
237     /** @brief Informs that the document status has been changed.
238      *
239      * If the document has been modified, it's called with true as an argument. */
240     void docModified(bool);
241     void selectLastAddedClip(const QString &);
242     void guidesUpdated();
243     /** @brief When creating a backup file, also save a thumbnail of current timeline */
244     void saveTimelinePreview(const QString &path);
245 };
246
247 #endif