kdenlivedoc.h 10.3 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
    Q_DECL_DEPRECATED MltVideoProfile mltProfile() const;
109 110
    ProfileInfo getProfileInfo() const;
    //Mlt::Profile *profile();
111
    const QString description() const;
112
    void setUrl(const QUrl &url);
113 114 115

    /** @brief Updates the project profile.
     * @return true if frame rate was changed */
116
    bool setProfilePath(QString path);
117 118

    /** @brief Defines whether the document needs to be saved. */
119
    bool isModified() const;
120 121

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

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

163
private:
164
    QUrl m_url;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
165
    QDomDocument m_document;
166 167 168 169 170
    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;
171 172 173
    int m_width;
    int m_height;
    Timecode m_timecode;
174
    Render *m_render;
175
    QTextEdit *m_notesWidget;
176
    QUndoStack *m_commandStack;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
177
    ClipManager *m_clipManager;
178
    MltVideoProfile m_profile;
179
    QString m_searchFolder;
180 181

    /** @brief Tells whether the current document has been changed after being saved. */
182
    bool m_modified;
183 184

    /** @brief The project folder, used to store project files (titles, effects...). */
185
    QUrl m_projectFolder;
186
    QMap <QString, QString> m_documentProperties;
187
    QMap <QString, QString> m_documentMetadata;
188

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

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

204 205
    /** @brief Updates the project folder location entry in the kdenlive file dialogs to point to the current project folder. */
    void updateProjectFolderPlacesEntry();
206 207
    /** @brief Only keep some backup files, delete some */
    void cleanupBackupFiles();
208 209
    /** @brief Load document properties from the xml file */
    void loadDocumentProperties();
210

211
public slots:
212
    void slotCreateXmlClip(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
213
    void slotCreateTextTemplateClip(const QString &group, const QString &groupId, QUrl path);
214 215

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

private slots:
227 228 229 230
    void slotClipModified(const QString &path);
    void slotClipMissing(const QString &path);
    void slotClipAvailable(const QString &path);
    void slotProcessModifiedClips();
231
    void slotModified();
232
    void slotSetDocumentNotes(const QString &notes);
233

234
signals:
235
    void resetProjectList();
236
    void updateClipDisplay(const QString&);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
237
    void progressInfo(const QString &, int);
238 239 240 241

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

#endif
Vincent PINON's avatar
Vincent PINON committed
254