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>
45 #if KDE_IS_VERSION(4,7,0)
46 #include <KMessageWidget>
50 #include <nepomuk/kratingpainter.h>
51 #include <nepomuk/resource.h>
54 #include "definitions.h"
56 #include "kdenlivesettings.h"
57 #include "folderprojectitem.h"
58 #include "subprojectitem.h"
59 #include "projecttree/abstractclipjob.h"
68 class ProjectListView;
72 class AbstractClipJob;
74 const int NameRole = Qt::UserRole;
75 const int DurationRole = NameRole + 1;
76 const int UsageRole = NameRole + 2;
78 class SmallInfoLabel: public QPushButton
82 SmallInfoLabel(QWidget *parent = 0);
85 QTimeLine* m_timeLine;
88 void slotSetJobCount(int jobCount);
91 void slotTimeLineChanged(qreal value);
92 void slotTimeLineFinished();
95 class InvalidDialog: public KDialog
99 InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent = 0);
100 virtual ~InvalidDialog();
101 void addClip(const QString &id, const QString &path);
102 QStringList getIds() const;
104 QListWidget *m_clipList;
108 class ItemDelegate: public QStyledItemDelegate
111 ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
114 /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
117 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
118 if (index.column() == 0 && !index.data(DurationRole).isNull()) {
119 QRect r1 = option.rect;
121 QStyleOptionViewItemV4 opt(option);
122 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
123 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
125 if (option.state & QStyle::State_Selected) {
126 painter->setPen(option.palette.highlightedText().color());
128 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
129 QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
130 QPoint pixmapPoint(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2);
131 painter->drawPixmap(pixmapPoint, pixmap);
132 int decoWidth = pixmap.width() + 2 * textMargin;
134 QFont font = painter->font();
136 painter->setFont(font);
137 int mid = (int)((r1.height() / 2));
138 r1.adjust(decoWidth, 0, 0, -mid);
139 QRect r2 = option.rect;
140 r2.adjust(decoWidth, mid, 0, 0);
141 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom, index.data().toString());
143 painter->setFont(font);
144 QString subText = index.data(DurationRole).toString();
145 int usage = index.data(UsageRole).toInt();
146 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
147 if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
149 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
151 int proxy = index.data(Qt::UserRole + 5).toInt();
152 if (proxy != 0 && proxy != JOBDONE) {
155 if (proxy != JOBCRASHED) {
156 // Draw proxy progress bar
157 color = option.palette.alternateBase().color();
158 painter->setPen(Qt::NoPen);
160 painter->setBrush(QBrush(color));
161 QRect progress(pixmapPoint.x() + 1, pixmapPoint.y() + pixmap.height() - 5, pixmap.width() - 2, 4);
162 painter->drawRect(progress);
163 painter->setBrush(option.palette.text());
165 progress.adjust(1, 1, 0, -1);
166 progress.setWidth((pixmap.width() - 4) * proxy / 100);
167 painter->drawRect(progress);
169 else if (proxy == JOBWAITING) {
170 // Draw kind of a pause icon
171 progress.adjust(1, 1, 0, -1);
172 progress.setWidth(2);
173 painter->drawRect(progress);
174 progress.moveLeft(progress.right() + 2);
175 painter->drawRect(progress);
178 else if (proxy == JOBCRASHED) {
179 proxyText = index.data(Qt::UserRole + 7).toString();
180 if (!proxyText.isEmpty()) {
181 QRectF txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + proxyText + " ");
182 painter->setPen(Qt::NoPen);
183 painter->setBrush(option.palette.highlight());
184 painter->drawRoundedRect(txtBounding, 2, 2);
185 painter->setPen(option.palette.highlightedText().color());
186 painter->drawText(txtBounding, Qt::AlignHCenter | Qt::AlignVCenter , proxyText);
192 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
193 if (index.data().toString().isEmpty()) {
194 QStyledItemDelegate::paint(painter, option, index);
197 QRect r1 = option.rect;
198 if (option.state & (QStyle::State_Selected)) {
199 painter->fillRect(r1, option.palette.highlight());
202 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
205 QStyledItemDelegate::paint(painter, option, index);
210 class ProjectList : public QWidget
215 ProjectList(QWidget *parent = 0);
216 virtual ~ProjectList();
218 QDomElement producersList();
219 void setRenderer(Render *projectRender);
220 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
221 QByteArray headerInfo() const;
222 void setHeaderInfo(const QByteArray &state);
223 void updateProjectFormat(Timecode t);
224 void setupMenu(QMenu *addMenu, QAction *defaultAction);
225 void setupGeneratorMenu(const QHash<QString,QMenu*>& menus);
226 QString currentClipUrl() const;
227 KUrl::List getConditionalUrls(const QString &condition) const;
228 /** @brief Get a list of selected clip Id's that match a condition. */
229 QStringList getConditionalIds(const QString &condition) const;
230 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
232 void trashUnusedClips();
233 QList <DocClipBase*> documentClipList() const;
234 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
235 void removeClipCut(const QString &id, int in, int out);
236 void focusTree() const;
237 SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
238 void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
239 bool hasMissingClips();
240 void deleteProjectFolder(QMap <QString, QString> map);
241 void selectItemById(const QString &clipId);
243 /** @brief Returns a string list of all supported mime extensions. */
244 static QString getExtensions();
245 /** @brief Returns a list of urls containing original and proxy urls. */
246 QMap <QString, QString> getProxies();
247 /** @brief Enable / disable proxies. */
248 void updateProxyConfig();
249 /** @brief Get a property from the document. */
250 QString getDocumentProperty(const QString &key) const;
252 /** @brief Does this project allow proxies. */
253 bool useProxy() const;
254 /** @brief Should we automatically create proxy clips for newly added clips. */
255 bool generateProxy() const;
256 /** @brief Should we automatically create proxy clips for newly added clips. */
257 bool generateImageProxy() const;
258 /** @brief Returns a list of the expanded folder ids. */
259 QStringList expandedFolders() const;
260 /** @brief Deselect all clips in project tree. */
261 void clearSelection();
262 /** @brief Print required overlays over clip thumb (proxy, stabilized,...). */
263 void processThumbOverlays(ProjectItem *item, QPixmap &pix);
266 void setDocument(KdenliveDoc *doc);
267 void updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
268 void slotReplyGetImage(const QString &clipId, const QImage &img);
269 void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height);
270 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace);
271 void slotAddClip(DocClipBase *clip, bool getProperties);
272 void slotDeleteClip(const QString &clipId);
273 void slotUpdateClip(const QString &id);
274 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
275 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
276 void slotRemoveInvalidClip(const QString &id, bool replace);
277 void slotRemoveInvalidProxy(const QString &id, bool durationError);
278 void slotSelectClip(const QString &ix);
280 /** @brief Prepares removing the selected items. */
281 void slotRemoveClip();
282 void slotAddClip(const QString url, const QString &groupName, const QString &groupId);
283 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
285 /** @brief Adds, edits or deletes a folder item.
287 * This is triggered by AddFolderCommand and EditFolderCommand. */
288 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
289 void slotResetProjectList();
292 void slotReloadClip(const QString &id = QString());
294 /** @brief Shows dialog for setting up a color clip. */
295 void slotAddColorClip();
296 void regenerateTemplate(const QString &id);
297 void slotUpdateClipCut(QPoint p);
298 void slotAddClipCut(const QString &id, int in, int out);
299 void slotForceProcessing(const QString &id);
300 /** @brief Remove all instances of a proxy and delete the file. */
301 void slotDeleteProxy(const QString proxyPath);
302 /** @brief Start a hard cut clip job. */
303 void slotCutClipJob(const QString &id, QPoint zone);
304 void slotTranscodeClipJob(QStringList ids, QString params, QString desc);
305 /** @brief Start an MLT process job. */
306 void slotStartFilterJob(ItemInfo, const QString&,const QString&,const QString&,const QString&,const QString&,const QString&,const QString&);
309 ProjectListView *m_listView;
314 QFuture<void> m_queueRunner;
315 QUndoStack *m_commandStack;
316 ProjectItem *getItemById(const QString &id);
317 QTreeWidgetItem *getAnyItemById(const QString &id);
318 FolderProjectItem *getFolderItemById(const QString &id);
319 QAction *m_openAction;
320 QAction *m_reloadAction;
321 QAction *m_discardCurrentClipJobs;
322 QMenu *m_extractAudioAction;
323 QMenu *m_transcodeAction;
324 QMenu *m_stabilizeAction;
326 ItemDelegate *m_listViewDelegate;
327 /** @brief False if we have not yet finished opening the document. */
329 /** @brief False if we have not yet finished checking all project tree thumbs. */
330 bool m_allClipsProcessed;
331 QToolButton *m_addButton;
332 QToolButton *m_deleteButton;
333 QToolButton *m_editButton;
334 //QMap <QString, QDomElement> m_infoQueue;
335 QMap <QString, QDomElement> m_producerQueue;
336 QList <QString> m_thumbnailQueue;
337 QAction *m_proxyAction;
340 /** @brief We are cleaning up the project list, so stop processing signals. */
342 QList <AbstractClipJob *> m_jobList;
343 QFutureSynchronizer<void> m_jobThreads;
344 InvalidDialog *m_invalidClipDialog;
346 SmallInfoLabel *m_infoLabel;
347 #if KDE_IS_VERSION(4,7,0)
348 KMessageWidget *m_infoMessage;
349 /** @brief A string containing the last error log for a clip job. */
351 /** @brief The action that will trigger the log dialog. */
352 QAction *m_logAction;
355 void requestClipThumbnail(const QString id);
357 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
358 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
360 /** @brief Gets the selected folder (or the folder of the selected item). */
361 QStringList getGroup() const;
362 void regenerateTemplate(ProjectItem *clip);
363 void editClipSelection(QList<QTreeWidgetItem *> list);
365 /** @brief Enables and disables transcode actions based on the selected clip's type. */
366 void adjustTranscodeActions(ProjectItem *clip) const;
367 /** @brief Enables and disables stabilize actions based on the selected clip's type. */
368 void adjustStabilizeActions(ProjectItem *clip) const;
369 /** @brief Enables and disables proxy action based on the selected clip. */
370 void adjustProxyActions(ProjectItem *clip) const;
372 /** @brief Sets the buttons enabled/disabled according to selected item. */
373 void updateButtons() const;
375 /** @brief Set the Proxy status on a clip.
376 * @param item The clip item to set status
377 * @param jobType The job type
378 * @param status The job status (see definitions.h)
379 * @param progress The job progress (in percents)
380 * @param statusMessage The job info message */
381 void setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress = 0, const QString &statusMessage = QString());
382 void monitorItemEditing(bool enable);
383 /** @brief Get cached thumbnail for a project's clip or create it if no cache. */
384 void getCachedThumbnail(ProjectItem *item);
385 void getCachedThumbnail(SubProjectItem *item);
386 /** @brief The clip is about to be reloaded, cancel thumbnail requests. */
387 void resetThumbsProducer(DocClipBase *clip);
388 /** @brief Check if a clip has a running or pending job process. */
389 bool hasPendingJob(ProjectItem *item, JOBTYPE type);
390 /** @brief Delete pending jobs for a clip. */
391 void deleteJobsForClip(const QString &clipId);
392 /** @brief Discard specific job type for a clip. */
393 void discardJobs(const QString &id, JOBTYPE type = NOJOBTYPE);
394 /** @brief Get the list of job names for current clip. */
395 QStringList getPendingJobs(const QString &id);
398 void slotClipSelected();
399 void slotAddSlideshowClip();
400 void slotAddTitleClip();
401 void slotAddTitleTemplateClip();
403 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
404 * @param pos The position where the menu should pop up
405 * @param item The item for which the checks should be done */
406 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
408 /** @brief Creates an AddFolderCommand. */
409 void slotAddFolder();
411 /** @brief This is triggered when a clip description has been modified. */
412 void slotItemEdited(QTreeWidgetItem *item, int column);
413 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
414 void slotProcessNextThumbnail();
415 void slotCheckForEmptyQueue();
416 void slotPauseMonitor();
417 /** A clip was modified externally, change icon so that user knows it */
418 void slotModifiedClip(const QString &id);
419 void slotMissingClip(const QString &id);
420 void slotAvailableClip(const QString &id);
421 /** @brief Try to find a matching profile for given item. */
422 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
423 /** @brief Add a sequence from the stopmotion widget. */
424 void slotAddOrUpdateSequence(const QString frameName);
425 /** @brief A proxy clip was created, update display. */
426 void slotGotProxy(const QString &proxyPath);
427 void slotGotProxy(ProjectItem *item);
428 /** @brief Enable / disable proxy for current clip. */
429 void slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy = NULL);
430 /** @brief Put clip in the proxy waiting list. */
431 void slotCreateProxy(const QString id);
432 /** @brief Stop creation of this clip's proxy. */
433 void slotAbortProxy(const QString id, const QString path);
434 /** @brief Start creation of clip jobs. */
435 void slotProcessJobs();
436 /** @brief Discard running and pending clip jobs. */
437 void slotCancelJobs();
438 /** @brief Discard a running clip jobs. */
439 void slotCancelRunningJob(const QString id, stringMap);
440 /** @brief Update a clip's job status. */
441 void slotProcessLog(const QString, int progress, int, const QString = QString());
442 /** @brief A clip job crashed, inform user. */
443 void slotUpdateJobStatus(const QString &id, int type, int status, const QString &label, const QString &actionName, const QString details);
444 void slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName = QString(), const QString details = QString());
445 /** @brief Display error log for last failed job. */
446 void slotShowJobLog();
447 /** @brief A proxy clip is ready. */
448 void slotGotProxyForId(const QString);
449 /** @brief Check if it is necessary to start a job thread. */
450 void slotCheckJobProcess();
451 /** @brief Fill the jobs menu with current clip's jobs. */
452 void slotPrepareJobsMenu();
453 /** @brief Discard all jobs for current clip. */
454 void slotDiscardClipJobs();
457 void clipSelected(DocClipBase *, QPoint zone = QPoint(), bool forceUpdate = false);
458 void receivedClipDuration(const QString &);
459 void showClipProperties(DocClipBase *);
460 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
461 void projectModified();
462 void loadingIsOver();
463 void displayMessage(const QString, int progress);
464 void clipNameChanged(const QString, const QString);
465 void clipNeedsReload(const QString&);
466 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
467 * @param id: The clip's id string
468 * @param resetThumbs Should we recreate the timeline thumbnails. */
469 void refreshClip(const QString &id, bool resetThumbs);
470 void updateRenderStatus();
471 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
472 void findInTimeline(const QString &clipId);
473 /** @brief Request a profile change for current document. */
474 void updateProfile(const QString &);
475 void processNextThumbnail();
476 /** @brief Activate the clip monitor. */
477 void raiseClipMonitor();
478 /** @brief Set number of running jobs. */
480 void cancelRunningJob(const QString, stringMap);
481 void processLog(const QString, int , int, const QString = QString());
482 void addClip(const QString, const QString &, const QString &);
483 void updateJobStatus(const QString, int, int, const QString &label = QString(), const QString &actionName = QString(), const QString details = QString());
484 void gotProxy(const QString);
485 void checkJobProcess();
486 /** @brief A Filter Job produced results, send them back to the clip. */
487 void gotFilterJobResults(const QString &id, int startPos, int track, const QString &filterName, stringMap params);