1 /***************************************************************************
2 * Copyright (C) 2007 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 ***************************************************************************/
24 #include <QDomNodeList>
27 #include <QToolButton>
28 #include <QTreeWidget>
32 #include <QApplication>
34 #include <QFutureSynchronizer>
35 #include <QListWidget>
37 #include <QPushButton>
39 #include <KTreeWidgetSearchLine>
42 #include <kdeversion.h>
45 #include <nepomuk/kratingpainter.h>
46 #include <nepomuk/resource.h>
50 #include <nepomuk2/kratingpainter.h>
51 #include <nepomuk2/resource.h>
54 #include "definitions.h"
56 #include "kdenlivesettings.h"
57 #include "folderprojectitem.h"
58 #include "subprojectitem.h"
59 #include "projecttree/abstractclipjob.h"
60 #include "widgets/invaliddialog.h"
62 #if KDE_IS_VERSION(4,7,0)
63 #include <KMessageWidget>
65 // Dummy KMessageWidget to allow compilation of MyMessageWidget class since Qt's moc doesn work inside #ifdef
68 class KMessageWidget: public QLabel
71 KMessageWidget(QWidget * = 0) {};
72 KMessageWidget(const QString &, QWidget * = 0) {};
73 virtual ~KMessageWidget(){};
77 class MyMessageWidget: public KMessageWidget
81 MyMessageWidget(QWidget *parent = 0);
82 MyMessageWidget(const QString &text, QWidget *parent = 0);
85 bool event(QEvent* ev);
88 void messageClosing();
97 class ProjectListView;
101 class AbstractClipJob;
104 class SmallInfoLabel: public QPushButton
108 SmallInfoLabel(QWidget *parent = 0);
109 static const QString getStyleSheet(const QPalette &p);
112 NameRole = Qt::UserRole,
117 QTimeLine* m_timeLine;
120 void slotSetJobCount(int jobCount);
123 void slotTimeLineChanged(qreal value);
124 void slotTimeLineFinished();
127 class ProjectList : public QWidget
132 ProjectList(QWidget *parent = 0);
133 virtual ~ProjectList();
135 QDomElement producersList();
136 void setRenderer(Render *projectRender);
137 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
138 QByteArray headerInfo() const;
139 void setHeaderInfo(const QByteArray &state);
140 void updateProjectFormat(Timecode t);
141 void setupMenu(QMenu *addMenu, QAction *defaultAction);
142 void setupGeneratorMenu(const QHash<QString,QMenu*>& menus);
143 QString currentClipUrl() const;
144 KUrl::List getConditionalUrls(const QString &condition) const;
145 /** @brief Get a list of selected clip Id's and url's that match a condition. */
146 QMap <QString, QString> getConditionalIds(const QString &condition) const;
147 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
149 void trashUnusedClips();
150 QList <DocClipBase*> documentClipList() const;
151 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
152 void removeClipCut(const QString &id, int in, int out);
153 void focusTree() const;
154 SubProjectItem *getSubItem(ProjectItem *clip, const QPoint &zone);
155 void doUpdateClipCut(const QString &id, const QPoint &oldzone, const QPoint &zone, const QString &comment);
156 bool hasMissingClips();
157 void deleteProjectFolder(QMap <QString, QString> map);
158 void selectItemById(const QString &clipId);
160 /** @brief Returns a string list of all supported mime extensions. */
161 static QString getExtensions();
162 /** @brief Returns a list of urls containing original and proxy urls. */
163 QMap <QString, QString> getProxies();
164 /** @brief Enable / disable proxies. */
165 void updateProxyConfig();
166 /** @brief Get a property from the document. */
167 QString getDocumentProperty(const QString &key) const;
169 /** @brief Does this project allow proxies. */
170 bool useProxy() const;
171 /** @brief Should we automatically create proxy clips for newly added clips. */
172 bool generateProxy() const;
173 /** @brief Should we automatically create proxy clips for newly added clips. */
174 bool generateImageProxy() const;
175 /** @brief Returns a list of the expanded folder ids. */
176 QStringList expandedFolders() const;
177 /** @brief Deselect all clips in project tree. */
178 void clearSelection();
179 /** @brief Print required overlays over clip thumb (proxy, stabilized,...). */
180 void processThumbOverlays(ProjectItem *item, QPixmap &pix);
181 /** @brief Start an MLT process job. */
182 void startClipFilterJob(const QString &filterName, const QString &condition);
183 /** @brief Set current document for the project tree. */
184 void setDocument(KdenliveDoc *doc);
186 /** @brief Palette was changed, update style. */
187 void updatePalette();
190 void updateAllClips(bool displayRatioChanged, bool fpsChanged, const QStringList &brokenClips);
191 void slotReplyGetImage(const QString &clipId, const QImage &img);
192 void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height);
193 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace);
194 void slotAddClip(DocClipBase *clip, bool getProperties);
195 void slotDeleteClip(const QString &clipId);
196 void slotUpdateClip(const QString &id);
197 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
198 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
199 void slotRemoveInvalidClip(const QString &id, bool replace);
200 void slotRemoveInvalidProxy(const QString &id, bool durationError);
201 void slotSelectClip(const QString &ix);
203 /** @brief Prepares removing the selected items. */
204 void slotRemoveClip();
205 void slotAddClip(const QString &url, const QString &groupName, const QString &groupId);
206 void slotAddClip(const QList <QUrl> &givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
208 /** @brief Adds, edits or deletes a folder item.
210 * This is triggered by AddFolderCommand and EditFolderCommand. */
211 void slotAddFolder(const QString &foldername, const QString &clipId, bool remove, bool edit = false);
212 void slotResetProjectList();
215 void slotReloadClip(const QString &id = QString());
217 /** @brief Shows dialog for setting up a color clip. */
218 void slotAddColorClip();
219 void regenerateTemplate(const QString &id);
220 void slotUpdateClipCut(QPoint p);
221 void slotAddClipCut(const QString &id, int in, int out);
222 void slotForceProcessing(const QString &id);
223 /** @brief Remove all instances of a proxy and delete the file. */
224 void slotDeleteProxy(const QString proxyPath);
225 /** @brief Start a hard cut clip job. */
226 void slotCutClipJob(const QString &id, QPoint zone);
227 /** @brief Start transcoding selected clips. */
228 void slotTranscodeClipJob(const QString &condition, QString params, QString desc);
229 /** @brief Start an MLT process job. */
230 void slotStartFilterJob(ItemInfo, const QString&,const QString&,const QString&,const QString&,const QString&,const QMap <QString, QString>&);
231 void slotSetThumbnail(const QString &id, int framePos, QImage img);
235 ProjectListView *m_listView;
240 QFuture<void> m_queueRunner;
241 QUndoStack *m_commandStack;
242 ProjectItem *getItemById(const QString &id);
243 QTreeWidgetItem *getAnyItemById(const QString &id);
244 FolderProjectItem *getFolderItemById(const QString &id);
245 FolderProjectItem *getFolderItemByName(const QString &name);
246 QAction *m_openAction;
247 QAction *m_reloadAction;
248 QAction *m_discardCurrentClipJobs;
249 QMenu *m_extractAudioAction;
250 QMenu *m_transcodeAction;
251 QMenu *m_clipsActionsMenu;
253 ItemDelegate *m_listViewDelegate;
254 /** @brief False if we have not yet finished opening the document. */
256 /** @brief False if we have not yet finished checking all project tree thumbs. */
257 bool m_allClipsProcessed;
258 QToolButton *m_addButton;
259 QToolButton *m_deleteButton;
260 QToolButton *m_editButton;
261 //QMap <QString, QDomElement> m_infoQueue;
262 QMap <QString, QDomElement> m_producerQueue;
263 QList <QString> m_thumbnailQueue;
264 QAction *m_proxyAction;
266 QMutex m_processMutex;
268 /** @brief We are cleaning up the project list, so stop processing signals. */
270 QList <AbstractClipJob *> m_jobList;
271 QFutureSynchronizer<void> m_jobThreads;
272 InvalidDialog *m_invalidClipDialog;
274 SmallInfoLabel *m_infoLabel;
275 /** @brief A list of strings containing the last error logs for clip jobs. */
276 QStringList m_errorLog;
278 #if KDE_IS_VERSION(4,7,0)
279 MyMessageWidget *m_infoMessage;
280 /** @brief The action that will trigger the log dialog. */
281 QAction *m_logAction;
284 void requestClipThumbnail(const QString &id);
286 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
287 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
289 /** @brief Gets the selected folder (or the folder of the selected item). */
290 QStringList getGroup() const;
291 void regenerateTemplate(ProjectItem *clip);
292 void editClipSelection(QList<QTreeWidgetItem *> list);
294 /** @brief Enables and disables transcode actions based on the selected clip's type. */
295 void adjustTranscodeActions(ProjectItem *clip) const;
296 /** @brief Enables and disables stabilize actions based on the selected clip's type. */
297 void adjustStabilizeActions(ProjectItem *clip) const;
298 /** @brief Enables and disables proxy action based on the selected clip. */
299 void adjustProxyActions(ProjectItem *clip) const;
301 /** @brief Sets the buttons enabled/disabled according to selected item. */
302 void updateButtons() const;
304 /** @brief Set the Proxy status on a clip.
305 * @param item The clip item to set status
306 * @param jobType The job type
307 * @param status The job status (see definitions.h)
308 * @param progress The job progress (in percents)
309 * @param statusMessage The job info message */
310 void setJobStatus(ProjectItem *item, JOBTYPE jobType, ClipJobStatus status, int progress = 0, const QString &statusMessage = QString());
311 void monitorItemEditing(bool enable);
312 /** @brief Get cached thumbnail for a project's clip or create it if no cache. */
313 void getCachedThumbnail(ProjectItem *item);
314 void getCachedThumbnail(SubProjectItem *item);
315 /** @brief The clip is about to be reloaded, cancel thumbnail requests. */
316 void resetThumbsProducer(DocClipBase *clip);
317 /** @brief Check if a clip has a running or pending job process. */
318 bool hasPendingJob(ProjectItem *item, JOBTYPE type);
319 /** @brief Delete pending jobs for a clip. */
320 void deleteJobsForClip(const QString &clipId);
321 /** @brief Discard specific job type for a clip. */
322 void discardJobs(const QString &id, JOBTYPE type = NOJOBTYPE);
323 /** @brief Get the list of job names for current clip. */
324 QStringList getPendingJobs(const QString &id);
325 /** @brief Start an MLT process job. */
326 void processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description, stringMap extraParams = stringMap());
327 /** @brief Create rounded shape pixmap for project tree thumb. */
328 QPixmap roundedPixmap(const QImage &img);
329 QPixmap roundedPixmap(const QPixmap &source);
330 /** @brief Extract a clip's metadata with the exiftool program. */
331 void extractMetadata(DocClipBase *clip);
332 /** @brief Add a special FFmpeg tag if clip matches some properties (for example set full_luma for Sony NEX camcorders. */
333 //void checkCamcorderFilters(DocClipBase *clip, QMap <QString, QString> meta);
336 void slotClipSelected();
337 void slotAddSlideshowClip();
338 void slotAddTitleClip();
339 void slotAddTitleTemplateClip();
341 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
342 * @param pos The position where the menu should pop up
343 * @param item The item for which the checks should be done */
344 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
346 /** @brief Creates an AddFolderCommand. */
347 void slotAddFolder(const QString &name = QString());
349 /** @brief This is triggered when a clip description has been modified. */
350 void slotItemEdited(QTreeWidgetItem *item, int column);
351 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
352 void slotProcessNextThumbnail();
353 void slotCheckForEmptyQueue();
354 void slotPauseMonitor();
355 /** A clip was modified externally, change icon so that user knows it */
356 void slotModifiedClip(const QString &id);
357 void slotMissingClip(const QString &id);
358 void slotAvailableClip(const QString &id);
359 /** @brief Try to find a matching profile for given item. */
360 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
361 /** @brief Add a sequence from the stopmotion widget. */
362 void slotAddOrUpdateSequence(const QString &frameName);
363 /** @brief A proxy clip was created, update display. */
364 void slotGotProxy(const QString &proxyPath);
365 void slotGotProxy(ProjectItem *item);
366 /** @brief Enable / disable proxy for current clip. */
367 void slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy = NULL);
368 /** @brief Put clip in the proxy waiting list. */
369 void slotCreateProxy(const QString &id);
370 /** @brief Stop creation of this clip's proxy. */
371 void slotAbortProxy(const QString &id, const QString& path);
372 /** @brief Start creation of clip jobs. */
373 void slotProcessJobs();
374 /** @brief Discard running and pending clip jobs. */
375 void slotCancelJobs();
376 /** @brief Discard a running clip jobs. */
377 void slotCancelRunningJob(const QString id, stringMap);
378 /** @brief Update a clip's job status. */
379 void slotProcessLog(const QString&, int progress, int, const QString & tmp= QString());
380 /** @brief A clip job crashed, inform user. */
381 void slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details);
382 void slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName = QString(), const QString details = QString());
383 /** @brief Display error log for last failed job. */
384 void slotShowJobLog();
385 /** @brief A proxy clip is ready. */
386 void slotGotProxyForId(const QString);
387 /** @brief Check if it is necessary to start a job thread. */
388 void slotCheckJobProcess();
389 /** @brief Fill the jobs menu with current clip's jobs. */
390 void slotPrepareJobsMenu();
391 /** @brief Discard all jobs for current clip. */
392 void slotDiscardClipJobs();
393 /** @brief Make sure current clip is visible in project tree. */
394 void slotCheckScrolling();
395 /** @brief Reset all text and log data from info message widget. */
396 void slotResetInfoMessage();
397 /** @brief close warning info passive popup. */
398 void slotClosePopup();
399 /** @brief process clip job result. */
400 void slotGotFilterJobResults(QString ,int , int, stringMap, stringMap);
403 void clipSelected(DocClipBase *, const QPoint &zone = QPoint(), bool forceUpdate = false);
404 void receivedClipDuration(const QString &);
405 void showClipProperties(DocClipBase *);
406 void showClipProperties(const QList <DocClipBase *>&, const QMap<QString, QString> &commonproperties);
407 void projectModified();
408 void loadingIsOver();
409 void displayMessage(const QString&, int progress, MessageType type = DefaultMessage);
410 void clipNameChanged(const QString&, const QString&);
411 void clipNeedsReload(const QString&);
412 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
413 * @param id: The clip's id string
414 * @param resetThumbs Should we recreate the timeline thumbnails. */
415 void refreshClip(const QString &id, bool resetThumbs);
416 void updateRenderStatus();
417 void deleteProjectClips(const QStringList &ids, const QMap <QString, QString> &folderids);
418 void findInTimeline(const QString &clipId);
419 /** @brief Request a profile change for current document. */
420 void updateProfile(const QString &);
421 void processNextThumbnail();
422 /** @brief Activate the clip monitor. */
423 void raiseClipMonitor(bool forceRefresh);
424 /** @brief Set number of running jobs. */
426 void cancelRunningJob(const QString&, const stringMap&);
427 void processLog(const QString&, int , int, const QString & = QString());
428 void addClip(const QString, const QString &, const QString &);
429 void updateJobStatus(const QString&, int, int, const QString &label = QString(), const QString &actionName = QString(), const QString &details = QString());
430 void gotProxy(const QString&);
431 void checkJobProcess();
432 /** @brief A Filter Job produced results, send them back to the clip. */
433 void gotFilterJobResults(const QString &id, int startPos, int track, const stringMap ¶ms, const stringMap &extra);
435 void updateAnalysisData(DocClipBase *);
436 void addMarkers(const QString &, const QList <CommentedTime>&);