]> git.sesse.net Git - kdenlive/blob - src/clipmanager.h
Integrate with the required MLT hooks for getting Movit to work.
[kdenlive] / src / clipmanager.h
1 /***************************************************************************
2  *   Copyright (C) 2008 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  * @class ClipManager
22  * @brief Manages the list of clips in a document.
23  * @author Jean-Baptiste Mardelle
24  */
25
26 #ifndef CLIPMANAGER_H
27 #define CLIPMANAGER_H
28
29 #include <QtXml/qdom.h>
30 #include <QPixmap>
31 #include <QObject>
32 #include <QTimer>
33 #include <QMutex>
34 #include <QFuture>
35
36 #include <KUrl>
37 #include <KUndoStack>
38 #include <KDirWatch>
39 #include <klocale.h>
40 #include <kdeversion.h>
41 #include <KIO/CopyJob>
42
43 #if KDE_IS_VERSION(4,5,0)
44 #include <KImageCache>
45 #endif
46
47
48 #include "gentime.h"
49 #include "definitions.h"
50
51
52 class KdenliveDoc;
53 class DocClipBase;
54 class AbstractGroupItem;
55 class QGLWidget;
56
57
58 class SolidVolumeInfo
59 {
60
61 public:
62     QString path; // mount path of volume, with trailing slash
63     QString uuid; // UUID as from Solid
64     QString label; // volume label (think of CDs)
65     bool isRemovable; // may be removed
66     bool isMounted;
67
68     bool isNull() const { return path.isNull(); }
69 };
70
71 namespace Mlt
72 {
73 class Producer;
74 }
75
76 class ClipManager: public QObject
77 {
78 Q_OBJECT public:
79
80     ClipManager(KdenliveDoc *doc, QGLWidget *glContext);
81     virtual ~ ClipManager();
82     void addClip(DocClipBase *clip);
83     DocClipBase *getClipAt(int pos);
84     void deleteClip(const QString &clipId);
85
86     /** @brief Add a file to the project.
87      * @ref slotAddClipList
88      * @param url file to add
89      * @param group name of the group to insert the file in (can be empty)
90      * @param groupId id of the group (if any) */
91     void slotAddClipFile(const KUrl &url, const QMap<QString, QString> &data);
92
93     /** @brief Adds a list of files to the project.
94      * @param urls files to add
95      * @param group name of the group to insert the files in (can be empty)
96      * @param groupId id of the group (if any)
97      * It checks for duplicated items and asks to the user for instructions. */
98     void slotAddClipList(const KUrl::List &urls, const QMap<QString, QString> &data);
99     void slotAddTextClipFile(const QString &titleName, int out, const QString &xml, const QString &group, const QString &groupId);
100     void slotAddTextTemplateClip(QString titleName, const KUrl &path, const QString &group, const QString &groupId);
101     void slotAddXmlClipFile(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
102     void slotAddColorClipFile(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId);
103     void slotAddSlideshowClipFile(QMap <QString, QString> properties, const QString &group, const QString &groupId);
104     DocClipBase *getClipById(QString clipId);
105     const QList <DocClipBase *> getClipByResource(const QString &resource);
106     void slotDeleteClips(QStringList ids);
107     void setThumbsProgress(const QString &message, int progress);
108     void checkAudioThumbs();
109     QList <DocClipBase*> documentClipList() const;
110     QMap <QString, QString> documentFolderList() const;
111     int getFreeClipId();
112     int getFreeFolderId();
113     int lastClipId() const;
114     void askForAudioThumb(const QString &id);
115     QString projectFolder() const;
116     void clearUnusedProducers();
117     void resetProducersList(const QList <Mlt::Producer *> prods, bool displayRatioChanged, bool fpsChanged);
118     void addFolder(const QString&, const QString&);
119     void deleteFolder(const QString&);
120     void clear();
121     void clearCache();
122     AbstractGroupItem *createGroup();
123     void removeGroup(AbstractGroupItem *group);
124     QDomElement groupsXml() const;
125     int clipsCount() const;
126     /** @brief remove a clip id from the queue list. */
127     void stopThumbs(const QString &id);
128     void projectTreeThumbReady(const QString &id, int frame, const QImage &img, int type);
129     QGLWidget *getMainContext() const { return m_mainGLContext; }
130
131 #if KDE_IS_VERSION(4,5,0)
132     KImageCache* pixmapCache;
133 #endif
134
135 public slots:
136     /** @brief Request creation of a clip thumbnail for specified frames. */
137     void slotRequestThumbs(const QString &id, const QList<int> &frames);
138     
139 private slots:
140     /** A clip was externally modified, monitor for more changes and prepare for reload */
141     void slotClipModified(const QString &path);
142     void slotClipMissing(const QString &path);
143     void slotClipAvailable(const QString &path);
144     /** Check the list of externally modified clips, and process them if they were not modified in the last 1500 milliseconds */
145     void slotProcessModifiedClips();
146     void slotGetThumbs();
147     void slotGetAudioThumbs();
148     /** @brief Clip has been copied, add it now. */
149     void slotAddClip(KIO::Job *job, const KUrl &, const KUrl &dst);
150
151 private:   // Private attributes
152     QGLWidget *m_mainGLContext;
153     /** the list of clips in the document */
154     QList <DocClipBase*> m_clipList;
155     /** the list of groups in the document */
156     QList <AbstractGroupItem *> m_groupsList;
157     QMap <QString, QString> m_folderList;
158     QList <QString> m_audioThumbsQueue;
159     /** the document undo stack*/
160     KdenliveDoc *m_doc;
161     int m_clipIdCounter;
162     int m_folderIdCounter;
163     KDirWatch m_fileWatcher;
164     /** Timer used to reload clips when they have been externally modified */
165     QTimer m_modifiedTimer;
166     /** List of the clip IDs that need to be reloaded after being externally modified */
167     QMap <QString, QTime> m_modifiedClips;
168     /** Struct containing the list of clip thumbnails to request (clip id and frames) */
169     QMap <QString, int> m_requestedThumbs;
170     QMutex m_thumbsMutex;
171     QFuture<void> m_thumbsThread;
172     /** @brief The id of currently processed clip for thumbs creation. */
173     QString m_processingThumbId;
174     /** @brief If true, abort processing of clip thumbs before removing a clip. */
175     bool m_abortThumb;
176     /** @brief We are about to delete the clip producer, stop processing thumbs. */
177     bool m_closing;
178     QFuture<void> m_audioThumbsThread;
179     /** @brief If true, abort processing of audio thumbs. */
180     bool m_abortAudioThumb;
181     /** @brief The id of currently processed clip for audio thumbs creation. */
182     QString m_processingAudioThumbId;
183     /** @brief The list of removable drives. */
184     QList<SolidVolumeInfo> m_removableVolumes;
185
186     QPoint m_projectTreeThumbSize;
187     
188     /** @brief Get a list of drives, to check if we have files on removable media. */
189     void listRemovableVolumes();
190     /** @brief Check if added file is on a removable drive. */
191     bool isOnRemovableDevice(const KUrl &url);
192
193 signals:
194     void reloadClip(const QString &);
195     void modifiedClip(const QString &);
196     void missingClip(const QString &);
197     void availableClip(const QString &);
198     void checkAllClips(bool displayRatioChanged, bool fpsChanged, const QStringList &brokenClips);
199     void displayMessage(const QString &, int);
200     void thumbReady(const QString &id, int, const QImage&);
201     void gotClipPropertyThumbnail(const QString &id, const QImage&);
202 };
203
204 #endif