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
29 #include <QtXml/qdom.h>
40 #include <kdeversion.h>
41 #include <KIO/CopyJob>
43 #if KDE_IS_VERSION(4,5,0)
44 #include <KImageCache>
49 #include "definitions.h"
54 class AbstractGroupItem;
61 QString path; // mount path of volume, with trailing slash
62 QString uuid; // UUID as from Solid
63 QString label; // volume label (think of CDs)
64 bool isRemovable; // may be removed
67 bool isNull() const { return path.isNull(); }
75 class ClipManager: public QObject
79 ClipManager(KdenliveDoc *doc);
80 virtual ~ ClipManager();
81 void addClip(DocClipBase *clip);
82 DocClipBase *getClipAt(int pos);
83 void deleteClip(const QString &clipId);
85 /** @brief Add a file to the project.
86 * @ref slotAddClipList
87 * @param url file to add
88 * @param group name of the group to insert the file in (can be empty)
89 * @param groupId id of the group (if any) */
90 void slotAddClipFile(const KUrl &url, const QMap<QString, QString> &data);
92 /** @brief Adds a list of files to the project.
93 * @param urls files to add
94 * @param group name of the group to insert the files in (can be empty)
95 * @param groupId id of the group (if any)
96 * It checks for duplicated items and asks to the user for instructions. */
97 void slotAddClipList(const KUrl::List &urls, const QMap<QString, QString> &data);
98 void slotAddTextClipFile(const QString &titleName, int out, const QString &xml, const QString &group, const QString &groupId);
99 void slotAddTextTemplateClip(QString titleName, const KUrl &path, const QString &group, const QString &groupId);
100 void slotAddXmlClipFile(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
101 void slotAddColorClipFile(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId);
102 void slotAddSlideshowClipFile(QMap <QString, QString> properties, const QString &group, const QString &groupId);
103 DocClipBase *getClipById(QString clipId);
104 const QList <DocClipBase *> getClipByResource(const QString &resource);
105 void slotDeleteClips(QStringList ids);
106 void setThumbsProgress(const QString &message, int progress);
107 void checkAudioThumbs();
108 QList <DocClipBase*> documentClipList() const;
109 QMap <QString, QString> documentFolderList() const;
111 int getFreeFolderId();
112 int lastClipId() const;
113 void askForAudioThumb(const QString &id);
114 QString projectFolder() const;
115 void clearUnusedProducers();
116 void resetProducersList(const QList <Mlt::Producer *> prods, bool displayRatioChanged, bool fpsChanged);
117 void addFolder(const QString&, const QString&);
118 void deleteFolder(const QString&);
121 AbstractGroupItem *createGroup();
122 void removeGroup(AbstractGroupItem *group);
123 QDomElement groupsXml() const;
124 int clipsCount() const;
125 /** @brief remove a clip id from the queue list. */
126 void stopThumbs(const QString &id);
127 void projectTreeThumbReady(const QString &id, int frame, const QImage &img, int type);
129 #if KDE_IS_VERSION(4,5,0)
130 KImageCache* pixmapCache;
134 /** @brief Request creation of a clip thumbnail for specified frames. */
135 void slotRequestThumbs(const QString &id, const QList<int> &frames);
138 /** A clip was externally modified, monitor for more changes and prepare for reload */
139 void slotClipModified(const QString &path);
140 void slotClipMissing(const QString &path);
141 void slotClipAvailable(const QString &path);
142 /** Check the list of externally modified clips, and process them if they were not modified in the last 1500 milliseconds */
143 void slotProcessModifiedClips();
144 void slotGetThumbs();
145 void slotGetAudioThumbs();
146 /** @brief Clip has been copied, add it now. */
147 void slotAddClip(KIO::Job *job, const KUrl &, const KUrl &dst);
149 private: // Private attributes
150 /** the list of clips in the document */
151 QList <DocClipBase*> m_clipList;
152 /** the list of groups in the document */
153 QList <AbstractGroupItem *> m_groupsList;
154 QMap <QString, QString> m_folderList;
155 QList <QString> m_audioThumbsQueue;
156 /** the document undo stack*/
159 int m_folderIdCounter;
160 KDirWatch m_fileWatcher;
161 /** Timer used to reload clips when they have been externally modified */
162 QTimer m_modifiedTimer;
163 /** List of the clip IDs that need to be reloaded after being externally modified */
164 QMap <QString, QTime> m_modifiedClips;
165 /** Struct containing the list of clip thumbnails to request (clip id and frames) */
166 QMap <QString, int> m_requestedThumbs;
167 QMutex m_thumbsMutex;
168 QFuture<void> m_thumbsThread;
169 /** @brief The id of currently processed clip for thumbs creation. */
170 QString m_processingThumbId;
171 /** @brief If true, abort processing of clip thumbs before removing a clip. */
173 /** @brief We are about to delete the clip producer, stop processing thumbs. */
175 QFuture<void> m_audioThumbsThread;
176 /** @brief If true, abort processing of audio thumbs. */
177 bool m_abortAudioThumb;
178 /** @brief The id of currently processed clip for audio thumbs creation. */
179 QString m_processingAudioThumbId;
180 /** @brief The list of removable drives. */
181 QList<SolidVolumeInfo> m_removableVolumes;
183 QPoint m_projectTreeThumbSize;
185 /** @brief Get a list of drives, to check if we have files on removable media. */
186 void listRemovableVolumes();
187 /** @brief Check if added file is on a removable drive. */
188 bool isOnRemovableDevice(const KUrl &url);
191 void reloadClip(const QString &);
192 void modifiedClip(const QString &);
193 void missingClip(const QString &);
194 void availableClip(const QString &);
195 void checkAllClips(bool displayRatioChanged, bool fpsChanged, const QStringList &brokenClips);
196 void displayMessage(const QString &, int);
197 void thumbReady(const QString &id, int, const QImage&);
198 void gotClipPropertyThumbnail(const QString &id, const QImage&);