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>
30 #include <QStyledItemDelegate>
33 #include <QApplication>
35 #include <QFutureSynchronizer>
36 #include <QListWidget>
38 #include <QPushButton>
40 #include <KTreeWidgetSearchLine>
43 #include <kdeversion.h>
46 #include <nepomuk/kratingpainter.h>
47 #include <nepomuk/resource.h>
50 #include "definitions.h"
52 #include "kdenlivesettings.h"
53 #include "folderprojectitem.h"
54 #include "subprojectitem.h"
55 #include "projecttree/abstractclipjob.h"
58 #if KDE_IS_VERSION(4,7,0)
59 #include <KMessageWidget>
61 // Dummy KMessageWidget to allow compilation of MyMessageWidget class since Qt's moc doesn work inside #ifdef
63 class KMessageWidget: public QLabel
66 KMessageWidget(QWidget * = 0) {};
67 KMessageWidget(const QString &, QWidget * = 0) {};
68 virtual ~KMessageWidget(){};
72 class MyMessageWidget: public KMessageWidget
76 MyMessageWidget(QWidget *parent = 0);
77 MyMessageWidget(const QString &text, QWidget *parent = 0);
80 bool event(QEvent* ev);
83 void messageClosing();
92 class ProjectListView;
96 class AbstractClipJob;
98 const int NameRole = Qt::UserRole;
99 const int DurationRole = NameRole + 1;
100 const int UsageRole = NameRole + 2;
102 class SmallInfoLabel: public QPushButton
106 SmallInfoLabel(QWidget *parent = 0);
107 static const QString getStyleSheet(const QPalette &p);
109 QTimeLine* m_timeLine;
112 void slotSetJobCount(int jobCount);
115 void slotTimeLineChanged(qreal value);
116 void slotTimeLineFinished();
119 class InvalidDialog: public KDialog
123 InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent = 0);
124 virtual ~InvalidDialog();
125 void addClip(const QString &id, const QString &path);
126 QStringList getIds() const;
128 QListWidget *m_clipList;
132 class ItemDelegate: public QStyledItemDelegate
135 ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
138 /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
141 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
142 if (index.column() == 0 && !index.data(DurationRole).isNull()) {
143 QRect r1 = option.rect;
145 QStyleOptionViewItemV4 opt(option);
146 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
147 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
149 if (option.state & QStyle::State_Selected) {
150 painter->setPen(option.palette.highlightedText().color());
152 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
153 QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
154 QPoint pixmapPoint(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2);
155 painter->drawPixmap(pixmapPoint, pixmap);
156 int decoWidth = pixmap.width() + 2 * textMargin;
158 QFont font = painter->font();
160 painter->setFont(font);
161 int mid = (int)((r1.height() / 2));
162 r1.adjust(decoWidth, 0, 0, -mid);
163 QRect r2 = option.rect;
164 r2.adjust(decoWidth, mid, 0, 0);
165 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom, index.data().toString());
167 painter->setFont(font);
168 QString subText = index.data(DurationRole).toString();
169 int usage = index.data(UsageRole).toInt();
170 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
172 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
173 int jobProgress = index.data(Qt::UserRole + 5).toInt();
174 if (jobProgress != 0 && jobProgress != JOBDONE && jobProgress != JOBABORTED) {
175 if (jobProgress != JOBCRASHED) {
176 // Draw job progress bar
177 QColor color = option.palette.alternateBase().color();
179 painter->setPen(option.palette.link().color());
180 QRect progress(pixmapPoint.x() + 2, pixmapPoint.y() + pixmap.height() - 9, pixmap.width() - 4, 7);
181 painter->setBrush(QBrush(color));
182 painter->drawRect(progress);
183 painter->setBrush(option.palette.link());
184 progress.adjust(2, 2, -2, -2);
185 if (jobProgress == JOBWAITING) {
186 progress.setLeft(progress.right() - 2);
187 painter->drawRect(progress);
188 progress.moveLeft(progress.left() - 5);
189 painter->drawRect(progress);
191 else if (jobProgress > 0) {
192 progress.setWidth(progress.width() * jobProgress / 100);
193 painter->drawRect(progress);
195 } else if (jobProgress == JOBCRASHED) {
196 QString jobText = index.data(Qt::UserRole + 7).toString();
197 if (!jobText.isEmpty()) {
198 QRectF txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + jobText + " ");
199 painter->setPen(Qt::NoPen);
200 painter->setBrush(option.palette.highlight());
201 painter->drawRoundedRect(txtBounding, 2, 2);
202 painter->setPen(option.palette.highlightedText().color());
203 painter->drawText(txtBounding, Qt::AlignCenter, jobText);
209 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
210 if (index.data().toString().isEmpty()) {
211 QStyledItemDelegate::paint(painter, option, index);
214 QRect r1 = option.rect;
215 if (option.state & (QStyle::State_Selected)) {
216 painter->fillRect(r1, option.palette.highlight());
219 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
222 QStyledItemDelegate::paint(painter, option, index);
227 class ProjectList : public QWidget
232 ProjectList(QWidget *parent = 0);
233 virtual ~ProjectList();
235 QDomElement producersList();
236 void setRenderer(Render *projectRender);
237 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
238 QByteArray headerInfo() const;
239 void setHeaderInfo(const QByteArray &state);
240 void updateProjectFormat(Timecode t);
241 void setupMenu(QMenu *addMenu, QAction *defaultAction);
242 void setupGeneratorMenu(const QHash<QString,QMenu*>& menus);
243 QString currentClipUrl() const;
244 KUrl::List getConditionalUrls(const QString &condition) const;
245 /** @brief Get a list of selected clip Id's that match a condition. */
246 QStringList getConditionalIds(const QString &condition) const;
247 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
249 void trashUnusedClips();
250 QList <DocClipBase*> documentClipList() const;
251 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
252 void removeClipCut(const QString &id, int in, int out);
253 void focusTree() const;
254 SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
255 void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
256 bool hasMissingClips();
257 void deleteProjectFolder(QMap <QString, QString> map);
258 void selectItemById(const QString &clipId);
260 /** @brief Returns a string list of all supported mime extensions. */
261 static QString getExtensions();
262 /** @brief Returns a list of urls containing original and proxy urls. */
263 QMap <QString, QString> getProxies();
264 /** @brief Enable / disable proxies. */
265 void updateProxyConfig();
266 /** @brief Get a property from the document. */
267 QString getDocumentProperty(const QString &key) const;
269 /** @brief Does this project allow proxies. */
270 bool useProxy() const;
271 /** @brief Should we automatically create proxy clips for newly added clips. */
272 bool generateProxy() const;
273 /** @brief Should we automatically create proxy clips for newly added clips. */
274 bool generateImageProxy() const;
275 /** @brief Returns a list of the expanded folder ids. */
276 QStringList expandedFolders() const;
277 /** @brief Deselect all clips in project tree. */
278 void clearSelection();
279 /** @brief Print required overlays over clip thumb (proxy, stabilized,...). */
280 void processThumbOverlays(ProjectItem *item, QPixmap &pix);
281 /** @brief Start an MLT process job. */
282 void startClipFilterJob(const QString &filterName, const QString &condition);
283 /** @brief Set current document for the project tree. */
284 void setDocument(KdenliveDoc *doc);
286 /** @brief Palette was changed, update style. */
287 void updatePalette();
290 void updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
291 void slotReplyGetImage(const QString &clipId, const QImage &img);
292 void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height);
293 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace);
294 void slotAddClip(DocClipBase *clip, bool getProperties);
295 void slotDeleteClip(const QString &clipId);
296 void slotUpdateClip(const QString &id);
297 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
298 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
299 void slotRemoveInvalidClip(const QString &id, bool replace);
300 void slotRemoveInvalidProxy(const QString &id, bool durationError);
301 void slotSelectClip(const QString &ix);
303 /** @brief Prepares removing the selected items. */
304 void slotRemoveClip();
305 void slotAddClip(const QString url, const QString &groupName, const QString &groupId);
306 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
308 /** @brief Adds, edits or deletes a folder item.
310 * This is triggered by AddFolderCommand and EditFolderCommand. */
311 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
312 void slotResetProjectList();
315 void slotReloadClip(const QString &id = QString());
317 /** @brief Shows dialog for setting up a color clip. */
318 void slotAddColorClip();
319 void regenerateTemplate(const QString &id);
320 void slotUpdateClipCut(QPoint p);
321 void slotAddClipCut(const QString &id, int in, int out);
322 void slotForceProcessing(const QString &id);
323 /** @brief Remove all instances of a proxy and delete the file. */
324 void slotDeleteProxy(const QString proxyPath);
325 /** @brief Start a hard cut clip job. */
326 void slotCutClipJob(const QString &id, QPoint zone);
327 /** @brief Start transcoding selected clips. */
328 void slotTranscodeClipJob(const QString &condition, QString params, QString desc);
329 /** @brief Start an MLT process job. */
330 void slotStartFilterJob(ItemInfo, const QString&,const QString&,const QString&,const QString&,const QString&,const QMap <QString, QString>&);
331 void slotSetThumbnail(const QString &id, int framePos, QImage img);
335 ProjectListView *m_listView;
340 QFuture<void> m_queueRunner;
341 QUndoStack *m_commandStack;
342 ProjectItem *getItemById(const QString &id);
343 QTreeWidgetItem *getAnyItemById(const QString &id);
344 FolderProjectItem *getFolderItemById(const QString &id);
345 FolderProjectItem *getFolderItemByName(const QString &name);
346 QAction *m_openAction;
347 QAction *m_reloadAction;
348 QAction *m_discardCurrentClipJobs;
349 QMenu *m_extractAudioAction;
350 QMenu *m_transcodeAction;
351 QMenu *m_clipsActionsMenu;
353 ItemDelegate *m_listViewDelegate;
354 /** @brief False if we have not yet finished opening the document. */
356 /** @brief False if we have not yet finished checking all project tree thumbs. */
357 bool m_allClipsProcessed;
358 QToolButton *m_addButton;
359 QToolButton *m_deleteButton;
360 QToolButton *m_editButton;
361 //QMap <QString, QDomElement> m_infoQueue;
362 QMap <QString, QDomElement> m_producerQueue;
363 QList <QString> m_thumbnailQueue;
364 QAction *m_proxyAction;
367 /** @brief We are cleaning up the project list, so stop processing signals. */
369 QList <AbstractClipJob *> m_jobList;
370 QFutureSynchronizer<void> m_jobThreads;
371 InvalidDialog *m_invalidClipDialog;
373 SmallInfoLabel *m_infoLabel;
374 /** @brief A list of strings containing the last error logs for clip jobs. */
375 QStringList m_errorLog;
377 #if KDE_IS_VERSION(4,7,0)
378 MyMessageWidget *m_infoMessage;
379 /** @brief The action that will trigger the log dialog. */
380 QAction *m_logAction;
383 void requestClipThumbnail(const QString id);
385 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
386 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
388 /** @brief Gets the selected folder (or the folder of the selected item). */
389 QStringList getGroup() const;
390 void regenerateTemplate(ProjectItem *clip);
391 void editClipSelection(QList<QTreeWidgetItem *> list);
393 /** @brief Enables and disables transcode actions based on the selected clip's type. */
394 void adjustTranscodeActions(ProjectItem *clip) const;
395 /** @brief Enables and disables stabilize actions based on the selected clip's type. */
396 void adjustStabilizeActions(ProjectItem *clip) const;
397 /** @brief Enables and disables proxy action based on the selected clip. */
398 void adjustProxyActions(ProjectItem *clip) const;
400 /** @brief Sets the buttons enabled/disabled according to selected item. */
401 void updateButtons() const;
403 /** @brief Set the Proxy status on a clip.
404 * @param item The clip item to set status
405 * @param jobType The job type
406 * @param status The job status (see definitions.h)
407 * @param progress The job progress (in percents)
408 * @param statusMessage The job info message */
409 void setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress = 0, const QString &statusMessage = QString());
410 void monitorItemEditing(bool enable);
411 /** @brief Get cached thumbnail for a project's clip or create it if no cache. */
412 void getCachedThumbnail(ProjectItem *item);
413 void getCachedThumbnail(SubProjectItem *item);
414 /** @brief The clip is about to be reloaded, cancel thumbnail requests. */
415 void resetThumbsProducer(DocClipBase *clip);
416 /** @brief Check if a clip has a running or pending job process. */
417 bool hasPendingJob(ProjectItem *item, JOBTYPE type);
418 /** @brief Delete pending jobs for a clip. */
419 void deleteJobsForClip(const QString &clipId);
420 /** @brief Discard specific job type for a clip. */
421 void discardJobs(const QString &id, JOBTYPE type = NOJOBTYPE);
422 /** @brief Get the list of job names for current clip. */
423 QStringList getPendingJobs(const QString &id);
424 /** @brief Start an MLT process job. */
425 void processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description, QMap <QString, QString>extraParams = QMap <QString, QString>());
426 /** @brief Create rounded shape pixmap for project tree thumb. */
427 QPixmap roundedPixmap(QImage img);
428 QPixmap roundedPixmap(QPixmap source);
431 void slotClipSelected();
432 void slotAddSlideshowClip();
433 void slotAddTitleClip();
434 void slotAddTitleTemplateClip();
436 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
437 * @param pos The position where the menu should pop up
438 * @param item The item for which the checks should be done */
439 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
441 /** @brief Creates an AddFolderCommand. */
442 void slotAddFolder(const QString &name = QString());
444 /** @brief This is triggered when a clip description has been modified. */
445 void slotItemEdited(QTreeWidgetItem *item, int column);
446 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
447 void slotProcessNextThumbnail();
448 void slotCheckForEmptyQueue();
449 void slotPauseMonitor();
450 /** A clip was modified externally, change icon so that user knows it */
451 void slotModifiedClip(const QString &id);
452 void slotMissingClip(const QString &id);
453 void slotAvailableClip(const QString &id);
454 /** @brief Try to find a matching profile for given item. */
455 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
456 /** @brief Add a sequence from the stopmotion widget. */
457 void slotAddOrUpdateSequence(const QString frameName);
458 /** @brief A proxy clip was created, update display. */
459 void slotGotProxy(const QString &proxyPath);
460 void slotGotProxy(ProjectItem *item);
461 /** @brief Enable / disable proxy for current clip. */
462 void slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy = NULL);
463 /** @brief Put clip in the proxy waiting list. */
464 void slotCreateProxy(const QString id);
465 /** @brief Stop creation of this clip's proxy. */
466 void slotAbortProxy(const QString id, const QString path);
467 /** @brief Start creation of clip jobs. */
468 void slotProcessJobs();
469 /** @brief Discard running and pending clip jobs. */
470 void slotCancelJobs();
471 /** @brief Discard a running clip jobs. */
472 void slotCancelRunningJob(const QString id, stringMap);
473 /** @brief Update a clip's job status. */
474 void slotProcessLog(const QString, int progress, int, const QString = QString());
475 /** @brief A clip job crashed, inform user. */
476 void slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details);
477 void slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName = QString(), const QString details = QString());
478 /** @brief Display error log for last failed job. */
479 void slotShowJobLog();
480 /** @brief A proxy clip is ready. */
481 void slotGotProxyForId(const QString);
482 /** @brief Check if it is necessary to start a job thread. */
483 void slotCheckJobProcess();
484 /** @brief Fill the jobs menu with current clip's jobs. */
485 void slotPrepareJobsMenu();
486 /** @brief Discard all jobs for current clip. */
487 void slotDiscardClipJobs();
488 /** @brief Make sure current clip is visible in project tree. */
489 void slotCheckScrolling();
490 /** @brief Reset all text and log data from info message widget. */
491 void slotResetInfoMessage();
492 /** @brief close warning info passive popup. */
493 void slotClosePopup();
494 /** @brief process clip job result. */
495 void slotGotFilterJobResults(QString ,int , int, stringMap, stringMap);
498 void clipSelected(DocClipBase *, QPoint zone = QPoint(), bool forceUpdate = false);
499 void receivedClipDuration(const QString &);
500 void showClipProperties(DocClipBase *);
501 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
502 void projectModified();
503 void loadingIsOver();
504 void displayMessage(const QString, int progress, MessageType type = DefaultMessage);
505 void clipNameChanged(const QString, const QString);
506 void clipNeedsReload(const QString&);
507 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
508 * @param id: The clip's id string
509 * @param resetThumbs Should we recreate the timeline thumbnails. */
510 void refreshClip(const QString &id, bool resetThumbs);
511 void updateRenderStatus();
512 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
513 void findInTimeline(const QString &clipId);
514 /** @brief Request a profile change for current document. */
515 void updateProfile(const QString &);
516 void processNextThumbnail();
517 /** @brief Activate the clip monitor. */
518 void raiseClipMonitor(bool forceRefresh);
519 /** @brief Set number of running jobs. */
521 void cancelRunningJob(const QString, stringMap);
522 void processLog(const QString, int , int, const QString = QString());
523 void addClip(const QString, const QString &, const QString &);
524 void updateJobStatus(const QString, int, int, const QString label = QString(), const QString actionName = QString(), const QString details = QString());
525 void gotProxy(const QString);
526 void checkJobProcess();
527 /** @brief A Filter Job produced results, send them back to the clip. */
528 void gotFilterJobResults(const QString &id, int startPos, int track, stringMap params, stringMap extra);
530 void updateAnalysisData(DocClipBase *);
531 void addMarkers(const QString &, QList <CommentedTime>);