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