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>
41 #include <KIO/CopyJob>
43 #if KDE_IS_VERSION(4,5,0)
44 #include <KImageCache>
49 #include "definitions.h"
54 class AbstractGroupItem;
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
68 bool isNull() const { return path.isNull(); }
76 class ClipManager: public QObject
80 ClipManager(KdenliveDoc *doc);
81 virtual ~ ClipManager();
82 void addClip(DocClipBase *clip);
83 DocClipBase *getClipAt(int pos);
84 void deleteClip(const QString &clipId);
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);
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;
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&);
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, QImage img, int type);
130 #if KDE_IS_VERSION(4,5,0)
131 KImageCache* pixmapCache;
135 /** @brief Request creation of a clip thumbnail for specified frames. */
136 void slotRequestThumbs(const QString id, QList <int> frames);
139 /** A clip was externally modified, monitor for more changes and prepare for reload */
140 void slotClipModified(const QString &path);
141 void slotClipMissing(const QString &path);
142 void slotClipAvailable(const QString &path);
143 /** Check the list of externally modified clips, and process them if they were not modified in the last 1500 milliseconds */
144 void slotProcessModifiedClips();
145 void slotGetThumbs();
146 void slotGetAudioThumbs();
147 /** @brief Clip has been copied, add it now. */
148 void slotAddClip(KIO::Job *job, const KUrl &, const KUrl &dst);
150 private: // Private attributes
151 /** the list of clips in the document */
152 QList <DocClipBase*> m_clipList;
153 /** the list of groups in the document */
154 QList <AbstractGroupItem *> m_groupsList;
155 QMap <QString, QString> m_folderList;
156 QList <QString> m_audioThumbsQueue;
157 /** the document undo stack*/
160 int m_folderIdCounter;
161 KDirWatch m_fileWatcher;
162 /** Timer used to reload clips when they have been externally modified */
163 QTimer m_modifiedTimer;
164 /** List of the clip IDs that need to be reloaded after being externally modified */
165 QMap <QString, QTime> m_modifiedClips;
166 /** Struct containing the list of clip thumbnails to request (clip id and frames) */
167 QMap <QString, int> m_requestedThumbs;
168 QMutex m_thumbsMutex;
169 QFuture<void> m_thumbsThread;
170 /** @brief The id of currently processed clip for thumbs creation. */
171 QString m_processingThumbId;
172 /** @brief If true, abort processing of clip thumbs before removing a clip. */
174 /** @brief We are about to delete the clip producer, stop processing thumbs. */
176 QFuture<void> m_audioThumbsThread;
177 /** @brief If true, abort processing of audio thumbs. */
178 bool m_abortAudioThumb;
179 /** @brief The id of currently processed clip for audio thumbs creation. */
180 QString m_processingAudioThumbId;
181 /** @brief The list of removable drives. */
182 QList<SolidVolumeInfo> m_removableVolumes;
184 QPoint m_projectTreeThumbSize;
186 /** @brief Get a list of drives, to check if we have files on removable media. */
187 void listRemovableVolumes();
188 /** @brief Check if added file is on a removable drive. */
189 bool isOnRemovableDevice(const KUrl &url);
192 void reloadClip(const QString &);
193 void modifiedClip(const QString &);
194 void missingClip(const QString &);
195 void availableClip(const QString &);
196 void checkAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
197 void displayMessage(const QString &, int);
198 void thumbReady(const QString &id, int, QImage);
199 void gotClipPropertyThumbnail(const QString &id, QImage);