kdenlivedoc.h 9.9 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
/*! \class KdenliveDoc
21
    \brief Represents a kdenlive project file
22

23
   Instances of KdeliveDoc classes are created by void MainWindow::newFile(bool showProjectSettings, bool force)
24
*/
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
25 26 27
#ifndef KDENLIVEDOC_H
#define KDENLIVEDOC_H

Laurent Montel's avatar
Laurent Montel committed
28
#include <QtXml/qdom.h>
29
#include <QMap>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
30
#include <QList>
31
#include <QDir>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
32
#include <QObject>
33
#include <QTimer>
34
#include <QUrl>
35

36
#include <kautosavefile.h>
37
#include <KDirWatch>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
38 39

#include "gentime.h"
40
#include "timecode.h"
41
#include "definitions.h"
42
#include "timeline/guide.h"
43
#include "mltcontroller/effectscontroller.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
44

45 46
class Render;
class ClipManager;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
47
class MainWindow;
48
class TrackInfo;
49
class NotesPlugin;
50
class ProjectClip;
51
class ClipController;
52

53
class QTextEdit;
54
class QProgressDialog;
55 56 57
class QUndoGroup;
class QTimer;
class QUndoStack;
58

59 60 61 62
namespace Mlt {
    class Profile;
}

63 64
class KdenliveDoc: public QObject
{
65 66
    Q_OBJECT
public:
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
67

68
    KdenliveDoc(const QUrl &url, const QUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QMap <QString, QString>& properties, const QMap <QString, QString>& metadata, const QPoint &tracks, Render *render, NotesPlugin *notes, bool *openBackup, MainWindow *parent = 0, QProgressDialog *progressDialog = 0);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
69 70
    ~KdenliveDoc();
    QDomNodeList producersList();
71 72 73
    double fps() const;
    int width() const;
    int height() const;
74
    QUrl url() const;
75
    KAutoSaveFile *m_autosave;
76
    Timecode timecode() const;
77
    QDomDocument toXml();
78
    QUndoStack *commandStack();
79
    Render *renderer();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
80
    ClipManager *clipManager();
81
    QString groupsXml() const;
82 83 84

    /** @brief Adds a clip to the project tree.
     * @return false if the user aborted the operation, true otherwise */
85
    bool addClip(QDomElement elem, const QString &clipId);
86 87 88 89 90 91 92 93 94

    /** @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. */
95
    //bool addClipInfo(QDomElement elem, QDomElement orig, const QString &clipId);
96
    void deleteClip(const QString &clipId);
Laurent Montel's avatar
Laurent Montel committed
97
    int getFramePos(const QString &duration);
98
    /** @brief Get a bin's clip from its id. */
99
    ProjectClip *getBinClip(const QString &clipId);
100 101
    /** @brief Get a list of all clip ids that are inside a folder. */
    QStringList getBinFolderClipIds(const QString &folderId) const;
102
    ClipController *getClipController(const QString &clipId);
103
    void updateClip(const QString &id);
104 105

    /** @brief Informs Kdenlive of the audio thumbnails generation progress. */
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
106
    void setThumbsProgress(const QString &message, int progress);
107
    const QString &profilePath() const;
108 109
    /** @brief Returns current project profile. */
    MltVideoProfile mltProfile() const;
110
    ProfileInfo getProfileInfo() const;
111
    const QString description() const;
112
    void setUrl(const QUrl &url);
113 114

    /** @brief Defines whether the document needs to be saved. */
115
    bool isModified() const;
116 117

    /** @brief Returns the project folder, used to store project files. */
118
    QUrl projectFolder() const;
119 120
    void setZoom(int horizontal, int vertical);
    QPoint zoom() const;
121
    double dar() const;
122
    double projectDuration() const;
123
    /** @brief Returns the project file xml. */
124
    QDomDocument xmlSceneList(const QString &scene);
125
    /** @brief Saves the project file xml to a file. */
126
    bool saveSceneList(const QString &path, const QString &scene);
127
    void cacheImage(const QString &fileId, const QImage &img) const;
128
    void setProjectFolder(QUrl url);
129 130
    void setZone(int start, int end);
    QPoint zone() const;
131
    int setSceneList();
132 133
    void setDocumentProperty(const QString &name, const QString &value);
    const QString getDocumentProperty(const QString &name) const;
134 135

    /** @brief Gets the list of renderer properties saved into the document. */
136
    QMap <QString, QString> getRenderProperties() const;
137 138
    /** @brief Get a list of folder id's that were opened on last save. */
    QStringList getExpandedFolders();
139 140
    /** @brief Read the display ratio from an xml project file. */
    static double getDisplayRatio(const QString &path);
141 142
    /** @brief Backup the project file */
    void backupLastSavedVersion(const QString &path);
143 144 145
    /** @brief Returns the document metadata (author, copyright, ...) */
    const QMap <QString, QString> metadata() const;
    /** @brief Set the document metadata (author, copyright, ...) */
146
    void setMetadata(const QMap <QString, QString>& meta);
147 148
    /** @brief Get frame size of the renderer (profile)*/
    const QSize getRenderSize() const;
149 150
    /** @brief Add url to the file watcher so that we monitor changes */
    void watchFile(const QUrl &url);
151 152
    /** @brief Get all document properties that need to be saved */
    const QMap <QString, QString> documentProperties();
153
    bool useProxy() const;
154 155 156
    QString documentNotes() const;
    /** @brief Saves effects embedded in project file. */
    void saveCustomEffects(const QDomNodeList &customeffects);
157
    void resetProfile();
158

159
private:
160
    QUrl m_url;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
161
    QDomDocument m_document;
162 163 164 165 166
    KDirWatch m_fileWatcher;
    /** Timer used to reload clips when they have been externally modified */
    QTimer m_modifiedTimer;
    /** List of the clip IDs that need to be reloaded after being externally modified */
    QMap <QString, QTime> m_modifiedClips;
167 168 169
    int m_width;
    int m_height;
    Timecode m_timecode;
170
    Render *m_render;
171
    QTextEdit *m_notesWidget;
172
    QUndoStack *m_commandStack;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
173
    ClipManager *m_clipManager;
174
    MltVideoProfile m_profile;
175
    QString m_searchFolder;
176 177

    /** @brief Tells whether the current document has been changed after being saved. */
178
    bool m_modified;
179 180

    /** @brief The project folder, used to store project files (titles, effects...). */
181
    QUrl m_projectFolder;
182
    QMap <QString, QString> m_documentProperties;
183
    QMap <QString, QString> m_documentMetadata;
184

185
    void setNewClipResource(const QString &id, const QString &path);
186
    QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash) const;
187
    void moveProjectData(const QUrl &url);
188 189 190 191 192 193
    /**
     * @brief check for issues with the clips in the project
     * Instansiates DocumentChecker objects to do this task.
     * @param infoproducers
     * @return
     */
194
    bool checkDocumentClips();
195 196

    /** @brief Creates a new project. */
197
    QDomDocument createEmptyDocument(int videotracks, int audiotracks);
198
    QDomDocument createEmptyDocument(const QList<TrackInfo> &tracks);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
199

200 201
    /** @brief Updates the project folder location entry in the kdenlive file dialogs to point to the current project folder. */
    void updateProjectFolderPlacesEntry();
202 203
    /** @brief Only keep some backup files, delete some */
    void cleanupBackupFiles();
204 205
    /** @brief Load document properties from the xml file */
    void loadDocumentProperties();
206 207
    /** @brief update document properties to reflect a change in the current profile */
    void updateProjectProfile();
208

209
public slots:
210
    void slotCreateTextTemplateClip(const QString &group, const QString &groupId, QUrl path);
211 212

    /** @brief Sets the document as modified or up to date.
213 214
     * @description  If crash recovery is turned on, a timer calls KdenliveDoc::slotAutoSave() \n
     * Emits docModified conected to MainWindow::slotUpdateDocumentState \n
215
     * @param mod (optional) true if the document has to be saved */
216
    void setModified(bool mod = true);
217
    void slotProxyCurrentItem(bool doProxy);
218
    /** @brief Saves the current project at the autosave location.
219
     * @description The autosave files are in ~/.kde/data/stalefiles/kdenlive/ */
220
    void slotAutoSave();
221 222

private slots:
223 224 225
    void slotClipModified(const QString &path);
    void slotClipMissing(const QString &path);
    void slotProcessModifiedClips();
226
    void slotModified();
227
    void slotSetDocumentNotes(const QString &notes);
228

229
signals:
230
    void resetProjectList();
231
    void updateClipDisplay(const QString&);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
232
    void progressInfo(const QString &, int);
233 234 235 236

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

#endif
Vincent PINON's avatar
Vincent PINON committed
249