]> git.sesse.net Git - kdenlive/blob - src/clipmanager.h
Improve support for multi-stream clips:
[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 <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
56
57 class SolidVolumeInfo
58 {
59
60 public:
61
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);
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, 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, 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, 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(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 Request creation of a clip thumbnail for specified frames. */
127     void requestThumbs(const QString id, QList <int> frames);
128     /** @brief remove a clip id from the queue list. */
129     void stopThumbs(const QString &id);
130
131 #if KDE_IS_VERSION(4,5,0)
132     KImageCache* pixmapCache;
133 #endif
134
135 private slots:
136     /** A clip was externally modified, monitor for more changes and prepare for reload */
137     void slotClipModified(const QString &path);
138     void slotClipMissing(const QString &path);
139     void slotClipAvailable(const QString &path);
140     /** Check the list of externally modified clips, and process them if they were not modified in the last 1500 milliseconds */
141     void slotProcessModifiedClips();
142     void slotGetThumbs();
143     void slotGetAudioThumbs();
144     /** @brief Clip has been copied, add it now. */
145     void slotAddClip(KIO::Job *job, const KUrl &, const KUrl &dst);
146
147 private:   // Private attributes
148     /** the list of clips in the document */
149     QList <DocClipBase*> m_clipList;
150     /** the list of groups in the document */
151     QList <AbstractGroupItem *> m_groupsList;
152     QMap <QString, QString> m_folderList;
153     QList <QString> m_audioThumbsQueue;
154     /** the document undo stack*/
155     KdenliveDoc *m_doc;
156     int m_clipIdCounter;
157     int m_folderIdCounter;
158     KDirWatch m_fileWatcher;
159     /** Timer used to reload clips when they have been externally modified */
160     QTimer m_modifiedTimer;
161     /** List of the clip IDs that need to be reloaded after being externally modified */
162     QMap <QString, QTime> m_modifiedClips;
163     /** Struct containing the list of clip thumbnails to request (clip id and frames) */
164     QMap <QString, int> m_requestedThumbs;
165     QMutex m_thumbsMutex;
166     QFuture<void> m_thumbsThread;
167     /** @brief The id of currently processed clip for thumbs creation. */
168     QString m_processingThumbId;
169     /** @brief If true, abort processing of clip thumbs before removing a clip. */
170     bool m_abortThumb;
171     /** @brief We are about to delete the clip producer, stop processing thumbs. */
172     bool m_closing;
173     QFuture<void> m_audioThumbsThread;
174     /** @brief If true, abort processing of audio thumbs. */
175     bool m_abortAudioThumb;
176     /** @brief The id of currently processed clip for audio thumbs creation. */
177     QString m_processingAudioThumbId;
178     /** @brief The list of removable drives. */
179     QList<SolidVolumeInfo> m_removableVolumes;
180     
181     /** @brief Get a list of drives, to check if we have files on removable media. */
182     void listRemovableVolumes();
183     /** @brief Check if added file is on a removable drive. */
184     bool isOnRemovableDevice(const KUrl &url);
185
186 signals:
187     void reloadClip(const QString &);
188     void modifiedClip(const QString &);
189     void missingClip(const QString &);
190     void availableClip(const QString &);
191     void checkAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
192     void displayMessage(const QString &, int);
193 };
194
195 #endif