]> git.sesse.net Git - kdenlive/blob - src/kdenlivedoc.h
Move the backup dialog in separate folder, open it automatically when Kdenlive cannot...
[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 <qdom.h>
25 #include <QString>
26 #include <QMap>
27 #include <QList>
28 #include <QDir>
29 #include <QObject>
30 #include <QUndoGroup>
31 #include <QUndoStack>
32 #include <QTimer>
33
34 #include <KUrl>
35 #include <kautosavefile.h>
36
37 #include "gentime.h"
38 #include "timecode.h"
39 #include "definitions.h"
40 #include "guide.h"
41
42 class Render;
43 class ClipManager;
44 class DocClipBase;
45 class MainWindow;
46 class TrackInfo;
47
48 class KTextEdit;
49 class KProgressDialog;
50
51 class KdenliveDoc: public QObject
52 {
53 Q_OBJECT public:
54
55     KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, QMap <QString, QString> properties, 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, 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, QString clipId);
86     void slotAddClipFile(const KUrl url, const QString group, const QString &groupId = QString());
87     void slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId = QString());
88     void deleteClip(const QString &clipId);
89     int getFramePos(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(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(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, TrackInfo type);
122     void deleteTrack(int ix);
123     void setTrackType(int ix, 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
144     void cachePixmap(const QString &fileId, const QPixmap &pix) const;
145     void setProjectFolder(KUrl url);
146     QString getLadspaFile() const;
147     void setZone(int start, int end);
148     QPoint zone() const;
149     int setSceneList();
150     void setDocumentProperty(const QString &name, const QString &value);
151     const QString getDocumentProperty(const QString &name) const;
152
153     /** @brief Gets the list of renderer properties saved into the document. */
154     QMap <QString, QString> getRenderProperties() const;
155     void addTrackEffect(int ix, QDomElement effect);
156     void removeTrackEffect(int ix, QDomElement effect);
157     void setTrackEffect(int trackIndex, int effectIndex, QDomElement effect);
158     const EffectsList getTrackEffects(int ix);
159     QDomElement getTrackEffect(int trackIndex, int effectIndex) const;
160     /** @brief Get a list of folder id's that were opened on last save. */
161     QStringList getExpandedFolders();
162     /** @brief Read the display ratio from an xml project file. */
163     static double getDisplayRatio(const QString &path);
164     /** @brief Backup the project file */
165     void backupLastSavedVersion(const QString &path);
166     
167 private:
168     KUrl m_url;
169     QDomDocument m_document;
170     double m_fps;
171     int m_width;
172     int m_height;
173     Timecode m_timecode;
174     Render *m_render;
175     KTextEdit *m_notesWidget;
176     QUndoStack *m_commandStack;
177     ClipManager *m_clipManager;
178     MltVideoProfile m_profile;
179     QTimer *m_autoSaveTimer;
180     QString m_searchFolder;
181
182     /** @brief Tells whether the current document has been changed after being saved. */
183     bool m_modified;
184
185     /** @brief The project folder, used to store project files (titles, effects...). */
186     KUrl m_projectFolder;
187     QMap <QString, QString> m_documentProperties;
188
189     QList <TrackInfo> m_tracksList;
190     void setNewClipResource(const QString &id, const QString &path);
191     QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const;
192     void moveProjectData(KUrl url);
193     bool checkDocumentClips(QDomNodeList infoproducers);
194
195     /** @brief Creates a new project. */
196     QDomDocument createEmptyDocument(int videotracks, int audiotracks);
197     QDomDocument createEmptyDocument(QList <TrackInfo> tracks);
198     /** @brief Saves effects embedded in project file.
199     *   @return True if effects were imported.  */
200     bool saveCustomEffects(QDomNodeList customeffects);
201
202     /** @brief Updates the project folder location entry in the kdenlive file dialogs to point to the current project folder. */
203     void updateProjectFolderPlacesEntry();
204     /** @brief Only keep some backup files, delete some */
205     void cleanupBackupFiles();
206
207 public slots:
208     void slotCreateXmlClip(const QString &name, const QDomElement xml, QString group, const QString &groupId);
209     void slotCreateColorClip(const QString &name, const QString &color, const QString &duration, QString group, const QString &groupId);
210     void slotCreateSlideshowClipFile(const QString name, const QString path,
211                                      int count, const QString duration,
212                                      const bool loop, const bool crop,
213                                      const bool fade, const QString &luma_duration,
214                                      const QString &luma_file, const int softness,
215                                      const QString &animation, QString group,
216                                      const QString &groupId);
217     void slotCreateTextClip(QString group, const QString &groupId, const QString &templatePath = QString());
218     void slotCreateTextTemplateClip(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);
224
225 private slots:
226     void slotAutoSave();
227
228 signals:
229     void resetProjectList();
230     void addProjectClip(DocClipBase *, bool getInfo = true);
231     void signalDeleteProjectClip(const QString &);
232     void updateClipDisplay(const QString&);
233     void progressInfo(const QString &, int);
234
235     /** @brief Informs that the document status has been changed.
236      *
237      * 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);
243 };
244
245 #endif