1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
22 * @brief Manages the list of clips in a document.
23 * @author Jean-Baptiste Mardelle
40 #include <kdeversion.h>
42 #if KDE_IS_VERSION(4,5,0)
43 #include <KImageCache>
48 #include "definitions.h"
53 class AbstractGroupItem;
60 class ClipManager: public QObject
64 ClipManager(KdenliveDoc *doc);
65 virtual ~ ClipManager();
66 void addClip(DocClipBase *clip);
67 DocClipBase *getClipAt(int pos);
68 void deleteClip(const QString &clipId);
70 /** @brief Add a file to the project.
71 * @ref slotAddClipList
72 * @param url file to add
73 * @param group name of the group to insert the file in (can be empty)
74 * @param groupId id of the group (if any) */
75 void slotAddClipFile(const KUrl &url, const QString &group, const QString &groupId, const QString &comment = QString());
77 /** @brief Adds a list of files to the project.
78 * @param urls files to add
79 * @param group name of the group to insert the files in (can be empty)
80 * @param groupId id of the group (if any)
81 * It checks for duplicated items and asks to the user for instructions. */
82 void slotAddClipList(const KUrl::List urls, const QString &group, const QString &groupId, const QString &comment = QString());
83 void slotAddTextClipFile(const QString &titleName, int out, const QString &xml, const QString &group, const QString &groupId);
84 void slotAddTextTemplateClip(QString titleName, const KUrl &path, const QString &group, const QString &groupId);
85 void slotAddXmlClipFile(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
86 void slotAddColorClipFile(const QString &name, const QString &color, QString duration, const QString &group, const QString &groupId);
87 void slotAddSlideshowClipFile(QMap <QString, QString> properties, const QString &group, const QString &groupId);
88 DocClipBase *getClipById(QString clipId);
89 const QList <DocClipBase *> getClipByResource(QString resource);
90 void slotDeleteClips(QStringList ids);
91 void setThumbsProgress(const QString &message, int progress);
92 void checkAudioThumbs();
93 QList <DocClipBase*> documentClipList() const;
94 QMap <QString, QString> documentFolderList() const;
96 int getFreeFolderId();
97 int lastClipId() const;
98 void askForAudioThumb(const QString &id);
99 QString projectFolder() const;
100 void clearUnusedProducers();
101 void resetProducersList(const QList <Mlt::Producer *> prods, bool displayRatioChanged, bool fpsChanged);
102 void addFolder(const QString&, const QString&);
103 void deleteFolder(const QString&);
106 AbstractGroupItem *createGroup();
107 void removeGroup(AbstractGroupItem *group);
108 QDomElement groupsXml() const;
109 int clipsCount() const;
110 /** @brief Request creation of a clip thumbnail for specified frames. */
111 void requestThumbs(const QString id, QList <int> frames);
112 /** @brief remove a clip id from the queue list. */
113 void stopThumbs(const QString &id);
115 #if KDE_IS_VERSION(4,5,0)
116 KImageCache* pixmapCache;
120 /** A clip was externally modified, monitor for more changes and prepare for reload */
121 void slotClipModified(const QString &path);
122 void slotClipMissing(const QString &path);
123 void slotClipAvailable(const QString &path);
124 /** Check the list of externally modified clips, and process them if they were not modified in the last 1500 milliseconds */
125 void slotProcessModifiedClips();
126 void slotGetThumbs();
127 void slotGetAudioThumbs();
129 private: // Private attributes
130 /** the list of clips in the document */
131 QList <DocClipBase*> m_clipList;
132 /** the list of groups in the document */
133 QList <AbstractGroupItem *> m_groupsList;
134 QMap <QString, QString> m_folderList;
135 QList <QString> m_audioThumbsQueue;
136 /** the document undo stack*/
139 int m_folderIdCounter;
140 KDirWatch m_fileWatcher;
141 /** Timer used to reload clips when they have been externally modified */
142 QTimer m_modifiedTimer;
143 /** List of the clip IDs that need to be reloaded after being externally modified */
144 QMap <QString, QTime> m_modifiedClips;
145 /** Struct containing the list of clip thumbnails to request (clip id and frames) */
146 QMap <QString, int> m_requestedThumbs;
147 QMutex m_thumbsMutex;
148 QFuture<void> m_thumbsThread;
149 /** @brief The id of currently processed clip for thumbs creation. */
150 QString m_processingThumbId;
151 /** @brief If true, abort processing of clip thumbs before removing a clip. */
153 /** @brief We are about to delete the clip producer, stop processing thumbs. */
155 QFuture<void> m_audioThumbsThread;
156 /** @brief If true, abort processing of audio thumbs. */
157 bool m_abortAudioThumb;
158 /** @brief The id of currently processed clip for audio thumbs creation. */
159 QString m_processingAudioThumbId;
162 void reloadClip(const QString &);
163 void modifiedClip(const QString &);
164 void missingClip(const QString &);
165 void availableClip(const QString &);
166 void checkAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
167 void displayMessage(const QString &, int);