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));
171 if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
173 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
175 int jobProgress = index.data(Qt::UserRole + 5).toInt();
176 if (jobProgress != 0 && jobProgress != JOBDONE && jobProgress != JOBABORTED) {
177 if (jobProgress != JOBCRASHED) {
178 // Draw job progress bar
179 QColor color = option.palette.alternateBase().color();
180 painter->setPen(Qt::NoPen);
182 painter->setBrush(QBrush(color));
183 QRect progress(pixmapPoint.x() + 1, pixmapPoint.y() + pixmap.height() - 9, pixmap.width() - 2, 8);
184 painter->drawRect(progress);
185 painter->setBrush(option.palette.text());
186 if (jobProgress > 0) {
187 progress.adjust(1, 1, 0, -1);
188 progress.setWidth((pixmap.width() - 4) * jobProgress / 100);
189 painter->drawRect(progress);
190 } else if (jobProgress == JOBWAITING) {
191 // Draw kind of a pause icon
192 progress.adjust(1, 1, 0, -1);
193 progress.setWidth(2);
194 painter->drawRect(progress);
195 progress.moveLeft(progress.right() + 2);
196 painter->drawRect(progress);
198 } else if (jobProgress == JOBCRASHED) {
199 QString jobText = index.data(Qt::UserRole + 7).toString();
200 if (!jobText.isEmpty()) {
201 QRectF txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + jobText + " ");
202 painter->setPen(Qt::NoPen);
203 painter->setBrush(option.palette.highlight());
204 painter->drawRoundedRect(txtBounding, 2, 2);
205 painter->setPen(option.palette.highlightedText().color());
206 painter->drawText(txtBounding, Qt::AlignCenter, jobText);
212 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
213 if (index.data().toString().isEmpty()) {
214 QStyledItemDelegate::paint(painter, option, index);
217 QRect r1 = option.rect;
218 if (option.state & (QStyle::State_Selected)) {
219 painter->fillRect(r1, option.palette.highlight());
222 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
225 QStyledItemDelegate::paint(painter, option, index);
230 class ProjectList : public QWidget
235 ProjectList(QWidget *parent = 0);
236 virtual ~ProjectList();
238 QDomElement producersList();
239 void setRenderer(Render *projectRender);
240 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
241 QByteArray headerInfo() const;
242 void setHeaderInfo(const QByteArray &state);
243 void updateProjectFormat(Timecode t);
244 void setupMenu(QMenu *addMenu, QAction *defaultAction);
245 void setupGeneratorMenu(const QHash<QString,QMenu*>& menus);
246 QString currentClipUrl() const;
247 KUrl::List getConditionalUrls(const QString &condition) const;
248 /** @brief Get a list of selected clip Id's that match a condition. */
249 QStringList getConditionalIds(const QString &condition) const;
250 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
252 void trashUnusedClips();
253 QList <DocClipBase*> documentClipList() const;
254 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
255 void removeClipCut(const QString &id, int in, int out);
256 void focusTree() const;
257 SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
258 void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
259 bool hasMissingClips();
260 void deleteProjectFolder(QMap <QString, QString> map);
261 void selectItemById(const QString &clipId);
263 /** @brief Returns a string list of all supported mime extensions. */
264 static QString getExtensions();
265 /** @brief Returns a list of urls containing original and proxy urls. */
266 QMap <QString, QString> getProxies();
267 /** @brief Enable / disable proxies. */
268 void updateProxyConfig();
269 /** @brief Get a property from the document. */
270 QString getDocumentProperty(const QString &key) const;
272 /** @brief Does this project allow proxies. */
273 bool useProxy() const;
274 /** @brief Should we automatically create proxy clips for newly added clips. */
275 bool generateProxy() const;
276 /** @brief Should we automatically create proxy clips for newly added clips. */
277 bool generateImageProxy() const;
278 /** @brief Returns a list of the expanded folder ids. */
279 QStringList expandedFolders() const;
280 /** @brief Deselect all clips in project tree. */
281 void clearSelection();
282 /** @brief Print required overlays over clip thumb (proxy, stabilized,...). */
283 void processThumbOverlays(ProjectItem *item, QPixmap &pix);
284 /** @brief Start an MLT process job. */
285 void startClipFilterJob(const QString &filterName, const QString &condition);
286 /** @brief Set current document for the project tree. */
287 void setDocument(KdenliveDoc *doc);
289 /** @brief Palette was changed, update style. */
290 void updatePalette();
293 void updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
294 void slotReplyGetImage(const QString &clipId, const QImage &img);
295 void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height);
296 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace);
297 void slotAddClip(DocClipBase *clip, bool getProperties);
298 void slotDeleteClip(const QString &clipId);
299 void slotUpdateClip(const QString &id);
300 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
301 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
302 void slotRemoveInvalidClip(const QString &id, bool replace);
303 void slotRemoveInvalidProxy(const QString &id, bool durationError);
304 void slotSelectClip(const QString &ix);
306 /** @brief Prepares removing the selected items. */
307 void slotRemoveClip();
308 void slotAddClip(const QString url, const QString &groupName, const QString &groupId);
309 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
311 /** @brief Adds, edits or deletes a folder item.
313 * This is triggered by AddFolderCommand and EditFolderCommand. */
314 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
315 void slotResetProjectList();
318 void slotReloadClip(const QString &id = QString());
320 /** @brief Shows dialog for setting up a color clip. */
321 void slotAddColorClip();
322 void regenerateTemplate(const QString &id);
323 void slotUpdateClipCut(QPoint p);
324 void slotAddClipCut(const QString &id, int in, int out);
325 void slotForceProcessing(const QString &id);
326 /** @brief Remove all instances of a proxy and delete the file. */
327 void slotDeleteProxy(const QString proxyPath);
328 /** @brief Start a hard cut clip job. */
329 void slotCutClipJob(const QString &id, QPoint zone);
330 /** @brief Start transcoding selected clips. */
331 void slotTranscodeClipJob(const QString &condition, QString params, QString desc);
332 /** @brief Start an MLT process job. */
333 void slotStartFilterJob(ItemInfo, const QString&,const QString&,const QString&,const QString&,const QString&,const QString&,const QStringList&);
337 ProjectListView *m_listView;
342 QFuture<void> m_queueRunner;
343 QUndoStack *m_commandStack;
344 ProjectItem *getItemById(const QString &id);
345 QTreeWidgetItem *getAnyItemById(const QString &id);
346 FolderProjectItem *getFolderItemById(const QString &id);
347 FolderProjectItem *getFolderItemByName(const QString &name);
348 QAction *m_openAction;
349 QAction *m_reloadAction;
350 QAction *m_discardCurrentClipJobs;
351 QMenu *m_extractAudioAction;
352 QMenu *m_transcodeAction;
353 QMenu *m_stabilizeAction;
355 ItemDelegate *m_listViewDelegate;
356 /** @brief False if we have not yet finished opening the document. */
358 /** @brief False if we have not yet finished checking all project tree thumbs. */
359 bool m_allClipsProcessed;
360 QToolButton *m_addButton;
361 QToolButton *m_deleteButton;
362 QToolButton *m_editButton;
363 //QMap <QString, QDomElement> m_infoQueue;
364 QMap <QString, QDomElement> m_producerQueue;
365 QList <QString> m_thumbnailQueue;
366 QAction *m_proxyAction;
369 /** @brief We are cleaning up the project list, so stop processing signals. */
371 QList <AbstractClipJob *> m_jobList;
372 QFutureSynchronizer<void> m_jobThreads;
373 InvalidDialog *m_invalidClipDialog;
375 SmallInfoLabel *m_infoLabel;
376 /** @brief A list of strings containing the last error logs for clip jobs. */
377 QStringList m_errorLog;
379 #if KDE_IS_VERSION(4,7,0)
380 MyMessageWidget *m_infoMessage;
381 /** @brief The action that will trigger the log dialog. */
382 QAction *m_logAction;
385 void requestClipThumbnail(const QString id);
387 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
388 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
390 /** @brief Gets the selected folder (or the folder of the selected item). */
391 QStringList getGroup() const;
392 void regenerateTemplate(ProjectItem *clip);
393 void editClipSelection(QList<QTreeWidgetItem *> list);
395 /** @brief Enables and disables transcode actions based on the selected clip's type. */
396 void adjustTranscodeActions(ProjectItem *clip) const;
397 /** @brief Enables and disables stabilize actions based on the selected clip's type. */
398 void adjustStabilizeActions(ProjectItem *clip) const;
399 /** @brief Enables and disables proxy action based on the selected clip. */
400 void adjustProxyActions(ProjectItem *clip) const;
402 /** @brief Sets the buttons enabled/disabled according to selected item. */
403 void updateButtons() const;
405 /** @brief Set the Proxy status on a clip.
406 * @param item The clip item to set status
407 * @param jobType The job type
408 * @param status The job status (see definitions.h)
409 * @param progress The job progress (in percents)
410 * @param statusMessage The job info message */
411 void setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress = 0, const QString &statusMessage = QString());
412 void monitorItemEditing(bool enable);
413 /** @brief Get cached thumbnail for a project's clip or create it if no cache. */
414 void getCachedThumbnail(ProjectItem *item);
415 void getCachedThumbnail(SubProjectItem *item);
416 /** @brief The clip is about to be reloaded, cancel thumbnail requests. */
417 void resetThumbsProducer(DocClipBase *clip);
418 /** @brief Check if a clip has a running or pending job process. */
419 bool hasPendingJob(ProjectItem *item, JOBTYPE type);
420 /** @brief Delete pending jobs for a clip. */
421 void deleteJobsForClip(const QString &clipId);
422 /** @brief Discard specific job type for a clip. */
423 void discardJobs(const QString &id, JOBTYPE type = NOJOBTYPE);
424 /** @brief Get the list of job names for current clip. */
425 QStringList getPendingJobs(const QString &id);
426 /** @brief Start an MLT process job. */
427 void processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description, QStringList extraParams = QStringList());
430 void slotClipSelected();
431 void slotAddSlideshowClip();
432 void slotAddTitleClip();
433 void slotAddTitleTemplateClip();
435 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
436 * @param pos The position where the menu should pop up
437 * @param item The item for which the checks should be done */
438 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
440 /** @brief Creates an AddFolderCommand. */
441 void slotAddFolder(const QString &name = QString());
443 /** @brief This is triggered when a clip description has been modified. */
444 void slotItemEdited(QTreeWidgetItem *item, int column);
445 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
446 void slotProcessNextThumbnail();
447 void slotCheckForEmptyQueue();
448 void slotPauseMonitor();
449 /** A clip was modified externally, change icon so that user knows it */
450 void slotModifiedClip(const QString &id);
451 void slotMissingClip(const QString &id);
452 void slotAvailableClip(const QString &id);
453 /** @brief Try to find a matching profile for given item. */
454 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
455 /** @brief Add a sequence from the stopmotion widget. */
456 void slotAddOrUpdateSequence(const QString frameName);
457 /** @brief A proxy clip was created, update display. */
458 void slotGotProxy(const QString &proxyPath);
459 void slotGotProxy(ProjectItem *item);
460 /** @brief Enable / disable proxy for current clip. */
461 void slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy = NULL);
462 /** @brief Put clip in the proxy waiting list. */
463 void slotCreateProxy(const QString id);
464 /** @brief Stop creation of this clip's proxy. */
465 void slotAbortProxy(const QString id, const QString path);
466 /** @brief Start creation of clip jobs. */
467 void slotProcessJobs();
468 /** @brief Discard running and pending clip jobs. */
469 void slotCancelJobs();
470 /** @brief Discard a running clip jobs. */
471 void slotCancelRunningJob(const QString id, stringMap);
472 /** @brief Update a clip's job status. */
473 void slotProcessLog(const QString, int progress, int, const QString = QString());
474 /** @brief A clip job crashed, inform user. */
475 void slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details);
476 void slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName = QString(), const QString details = QString());
477 /** @brief Display error log for last failed job. */
478 void slotShowJobLog();
479 /** @brief A proxy clip is ready. */
480 void slotGotProxyForId(const QString);
481 /** @brief Check if it is necessary to start a job thread. */
482 void slotCheckJobProcess();
483 /** @brief Fill the jobs menu with current clip's jobs. */
484 void slotPrepareJobsMenu();
485 /** @brief Discard all jobs for current clip. */
486 void slotDiscardClipJobs();
487 /** @brief Make sure current clip is visible in project tree. */
488 void slotCheckScrolling();
489 /** @brief Reset all text and log data from info message widget. */
490 void slotResetInfoMessage();
491 /** @brief close warning info passive popup. */
492 void slotClosePopup();
493 /** @brief process clip job result. */
494 void slotGotFilterJobResults(QString ,int , int, QString, stringMap, QStringList);
497 void clipSelected(DocClipBase *, QPoint zone = QPoint(), bool forceUpdate = false);
498 void receivedClipDuration(const QString &);
499 void showClipProperties(DocClipBase *);
500 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
501 void projectModified();
502 void loadingIsOver();
503 void displayMessage(const QString, int progress);
504 void clipNameChanged(const QString, const QString);
505 void clipNeedsReload(const QString&);
506 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
507 * @param id: The clip's id string
508 * @param resetThumbs Should we recreate the timeline thumbnails. */
509 void refreshClip(const QString &id, bool resetThumbs);
510 void updateRenderStatus();
511 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
512 void findInTimeline(const QString &clipId);
513 /** @brief Request a profile change for current document. */
514 void updateProfile(const QString &);
515 void processNextThumbnail();
516 /** @brief Activate the clip monitor. */
517 void raiseClipMonitor();
518 /** @brief Set number of running jobs. */
520 void cancelRunningJob(const QString, stringMap);
521 void processLog(const QString, int , int, const QString = QString());
522 void addClip(const QString, const QString &, const QString &);
523 void updateJobStatus(const QString, int, int, const QString label = QString(), const QString actionName = QString(), const QString details = QString());
524 void gotProxy(const QString);
525 void checkJobProcess();
526 /** @brief A Filter Job produced results, send them back to the clip. */
527 void gotFilterJobResults(const QString &id, int startPos, int track, const QString &filterName, stringMap params, QStringList extre);
529 void updateAnalysisData(DocClipBase *);
530 void addMarkers(const QString &, QList <CommentedTime>);