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>
45 #include <nepomuk/kratingpainter.h>
46 #include <nepomuk/resource.h>
49 #include "definitions.h"
51 #include "kdenlivesettings.h"
52 #include "folderprojectitem.h"
53 #include "subprojectitem.h"
62 class ProjectListView;
66 class AbstractClipJob;
68 const int NameRole = Qt::UserRole;
69 const int DurationRole = NameRole + 1;
70 const int UsageRole = NameRole + 2;
72 class SmallInfoLabel: public QPushButton
76 SmallInfoLabel(QWidget *parent = 0);
79 QTimeLine* m_timeLine;
82 void slotSetJobCount(int jobCount);
85 void slotTimeLineChanged(qreal value);
86 void slotTimeLineFinished();
89 class InvalidDialog: public KDialog
93 InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent = 0);
94 virtual ~InvalidDialog();
95 void addClip(const QString &id, const QString &path);
96 QStringList getIds() const;
98 QListWidget *m_clipList;
102 class ItemDelegate: public QStyledItemDelegate
105 ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
108 /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
111 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
112 if (index.column() == 0 && !index.data(DurationRole).isNull()) {
113 QRect r1 = option.rect;
115 QStyleOptionViewItemV4 opt(option);
116 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
117 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
119 if (option.state & QStyle::State_Selected) {
120 painter->setPen(option.palette.highlightedText().color());
122 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
123 QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
124 QPoint pixmapPoint(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2);
125 painter->drawPixmap(pixmapPoint, pixmap);
126 int decoWidth = pixmap.width() + 2 * textMargin;
128 QFont font = painter->font();
130 painter->setFont(font);
131 int mid = (int)((r1.height() / 2));
132 r1.adjust(decoWidth, 0, 0, -mid);
133 QRect r2 = option.rect;
134 r2.adjust(decoWidth, mid, 0, 0);
135 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom, index.data().toString());
137 painter->setFont(font);
138 QString subText = index.data(DurationRole).toString();
139 int usage = index.data(UsageRole).toInt();
140 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
141 if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
143 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
145 int proxy = index.data(Qt::UserRole + 5).toInt();
146 if (proxy != 0 && proxy != JOBDONE) {
149 if (proxy != JOBCRASHED) {
150 // Draw proxy progress bar
151 color = option.palette.alternateBase().color();
152 painter->setPen(Qt::NoPen);
154 painter->setBrush(QBrush(color));
155 QRect progress(pixmapPoint.x() + 1, pixmapPoint.y() + pixmap.height() - 5, pixmap.width() - 2, 4);
156 painter->drawRect(progress);
157 painter->setBrush(option.palette.text());
159 progress.adjust(1, 1, 0, -1);
160 progress.setWidth((pixmap.width() - 4) * proxy / 100);
161 painter->drawRect(progress);
163 else if (proxy == JOBWAITING) {
164 // Draw kind of a pause icon
165 progress.adjust(1, 1, 0, -1);
166 progress.setWidth(2);
167 painter->drawRect(progress);
168 progress.moveLeft(progress.right() + 2);
169 painter->drawRect(progress);
172 else if (proxy == JOBCRASHED) {
173 proxyText = i18n("Proxy crashed");
174 QRectF txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + proxyText + " ");
175 painter->setPen(Qt::NoPen);
176 painter->setBrush(option.palette.highlight());
177 painter->drawRoundedRect(txtBounding, 2, 2);
178 painter->setPen(option.palette.highlightedText().color());
179 painter->drawText(txtBounding, Qt::AlignHCenter | Qt::AlignVCenter , proxyText);
184 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
185 if (index.data().toString().isEmpty()) {
186 QStyledItemDelegate::paint(painter, option, index);
189 QRect r1 = option.rect;
190 if (option.state & (QStyle::State_Selected)) {
191 painter->fillRect(r1, option.palette.highlight());
194 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
197 QStyledItemDelegate::paint(painter, option, index);
202 class ProjectList : public QWidget
207 ProjectList(QWidget *parent = 0);
208 virtual ~ProjectList();
210 QDomElement producersList();
211 void setRenderer(Render *projectRender);
212 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
213 QByteArray headerInfo() const;
214 void setHeaderInfo(const QByteArray &state);
215 void updateProjectFormat(Timecode t);
216 void setupMenu(QMenu *addMenu, QAction *defaultAction);
217 void setupGeneratorMenu(const QHash<QString,QMenu*>& menus);
218 QString currentClipUrl() const;
219 KUrl::List getConditionalUrls(const QString &condition) const;
220 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
222 void trashUnusedClips();
223 QList <DocClipBase*> documentClipList() const;
224 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
225 void removeClipCut(const QString &id, int in, int out);
226 void focusTree() const;
227 SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
228 void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
229 bool hasMissingClips();
230 void deleteProjectFolder(QMap <QString, QString> map);
231 void selectItemById(const QString &clipId);
233 /** @brief Returns a string list of all supported mime extensions. */
234 static QString getExtensions();
235 /** @brief Returns a list of urls containing original and proxy urls. */
236 QMap <QString, QString> getProxies();
237 /** @brief Enable / disable proxies. */
238 void updateProxyConfig();
239 /** @brief Get a property from the document. */
240 QString getDocumentProperty(const QString &key) const;
242 /** @brief Does this project allow proxies. */
243 bool useProxy() const;
244 /** @brief Should we automatically create proxy clips for newly added clips. */
245 bool generateProxy() const;
246 /** @brief Should we automatically create proxy clips for newly added clips. */
247 bool generateImageProxy() const;
248 /** @brief Returns a list of the expanded folder ids. */
249 QStringList expandedFolders() const;
250 /** @brief Deselect all clips in project tree. */
251 void clearSelection();
252 /** @brief Print required overlays over clip thumb (proxy, stabilized,...). */
253 void processThumbOverlays(ProjectItem *item, QPixmap &pix);
256 void setDocument(KdenliveDoc *doc);
257 void updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
258 void slotReplyGetImage(const QString &clipId, const QImage &img);
259 void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height);
260 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace);
261 void slotAddClip(DocClipBase *clip, bool getProperties);
262 void slotDeleteClip(const QString &clipId);
263 void slotUpdateClip(const QString &id);
264 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
265 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
266 void slotRemoveInvalidClip(const QString &id, bool replace);
267 void slotRemoveInvalidProxy(const QString &id, bool durationError);
268 void slotSelectClip(const QString &ix);
270 /** @brief Prepares removing the selected items. */
271 void slotRemoveClip();
272 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
274 /** @brief Adds, edits or deletes a folder item.
276 * This is triggered by AddFolderCommand and EditFolderCommand. */
277 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
278 void slotResetProjectList();
281 void slotReloadClip(const QString &id = QString());
283 /** @brief Shows dialog for setting up a color clip. */
284 void slotAddColorClip();
285 void regenerateTemplate(const QString &id);
286 void slotUpdateClipCut(QPoint p);
287 void slotAddClipCut(const QString &id, int in, int out);
288 void slotForceProcessing(const QString &id);
289 /** @brief Remove all instances of a proxy and delete the file. */
290 void slotDeleteProxy(const QString proxyPath);
293 ProjectListView *m_listView;
298 QFuture<void> m_queueRunner;
299 QUndoStack *m_commandStack;
300 ProjectItem *getItemById(const QString &id);
301 QTreeWidgetItem *getAnyItemById(const QString &id);
302 FolderProjectItem *getFolderItemById(const QString &id);
303 QAction *m_openAction;
304 QAction *m_reloadAction;
305 QMenu *m_transcodeAction;
306 QMenu *m_stabilizeAction;
308 ItemDelegate *m_listViewDelegate;
309 /** @brief False if we have not yet finished opening the document. */
311 /** @brief False if we have not yet finished checking all project tree thumbs. */
312 bool m_allClipsProcessed;
313 QToolButton *m_addButton;
314 QToolButton *m_deleteButton;
315 QToolButton *m_editButton;
316 //QMap <QString, QDomElement> m_infoQueue;
317 QMap <QString, QDomElement> m_producerQueue;
318 QList <QString> m_thumbnailQueue;
319 QAction *m_proxyAction;
320 QStringList m_processingClips;
321 /** @brief Holds a list of proxy urls that should be aborted. */
322 QStringList m_abortProxy;
323 /** @brief Holds a list of proxy urls that are currently being created. */
324 QStringList m_processingProxy;
327 /** @brief We are cleaning up the project list, so stop processing signals. */
329 QList <AbstractClipJob *> m_jobList;
330 QFutureSynchronizer<void> m_proxyThreads;
331 InvalidDialog *m_invalidClipDialog;
333 SmallInfoLabel *m_infoLabel;
335 void requestClipThumbnail(const QString id);
337 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
338 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
340 /** @brief Gets the selected folder (or the folder of the selected item). */
341 QStringList getGroup() const;
342 void regenerateTemplate(ProjectItem *clip);
343 void editClipSelection(QList<QTreeWidgetItem *> list);
345 /** @brief Enables and disables transcode actions based on the selected clip's type. */
346 void adjustTranscodeActions(ProjectItem *clip) const;
347 /** @brief Enables and disables stabilize actions based on the selected clip's type. */
348 void adjustStabilizeActions(ProjectItem *clip) const;
349 /** @brief Enables and disables proxy action based on the selected clip. */
350 void adjustProxyActions(ProjectItem *clip) const;
352 /** @brief Sets the buttons enabled/disabled according to selected item. */
353 void updateButtons() const;
355 /** @brief Set the Proxy status on a clip.
356 * @param item The clip item to set status
357 * @param status The proxy status (see definitions.h) */
358 void setProxyStatus(ProjectItem *item, CLIPJOBSTATUS status, int progress = 0);
359 /** @brief Process ffmpeg output to find out process progress. */
360 void processLogInfo(QList <ProjectItem *>items, int progress);
361 void monitorItemEditing(bool enable);
362 /** @brief Get cached thumbnail for a project's clip or create it if no cache. */
363 void getCachedThumbnail(ProjectItem *item);
364 void getCachedThumbnail(SubProjectItem *item);
365 /** @brief The clip is about to be reloaded, cancel thumbnail requests. */
366 void resetThumbsProducer(DocClipBase *clip);
369 void slotClipSelected();
370 void slotAddSlideshowClip();
371 void slotAddTitleClip();
372 void slotAddTitleTemplateClip();
374 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
375 * @param pos The position where the menu should pop up
376 * @param item The item for which the checks should be done */
377 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
379 /** @brief Creates an AddFolderCommand. */
380 void slotAddFolder();
382 /** @brief This is triggered when a clip description has been modified. */
383 void slotItemEdited(QTreeWidgetItem *item, int column);
384 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
385 void slotProcessNextThumbnail();
386 void slotCheckForEmptyQueue();
387 void slotPauseMonitor();
388 /** A clip was modified externally, change icon so that user knows it */
389 void slotModifiedClip(const QString &id);
390 void slotMissingClip(const QString &id);
391 void slotAvailableClip(const QString &id);
392 /** @brief Try to find a matching profile for given item. */
393 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
394 /** @brief Add a sequence from the stopmotion widget. */
395 void slotAddOrUpdateSequence(const QString frameName);
396 /** @brief A proxy clip was created, update display. */
397 void slotGotProxy(const QString &proxyPath);
398 void slotGotProxy(ProjectItem *item);
399 /** @brief Enable / disable proxy for current clip. */
400 void slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy = NULL);
401 /** @brief Put clip in the proxy waiting list. */
402 void slotCreateProxy(const QString id);
403 /** @brief Stop creation of this clip's proxy. */
404 void slotAbortProxy(const QString id, const QString path);
405 /** @brief Start creation of proxy clip. */
406 void slotGenerateProxy();
407 /** @brief Discard running and pending clip jobs. */
408 void slotCancelJobs();
409 /** @brief Discard a running clip jobs. */
410 void slotCancelRunningJob(const QString id, stringMap);
413 void clipSelected(DocClipBase *, QPoint zone = QPoint(), bool forceUpdate = false);
414 void receivedClipDuration(const QString &);
415 void showClipProperties(DocClipBase *);
416 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
417 void projectModified();
418 void loadingIsOver();
419 void displayMessage(const QString, int progress);
420 void clipNameChanged(const QString, const QString);
421 void clipNeedsReload(const QString&);
422 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
423 * @param id: The clip's id string
424 * @param resetThumbs Should we recreate the timeline thumbnails. */
425 void refreshClip(const QString &id, bool resetThumbs);
426 void updateRenderStatus();
427 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
428 void findInTimeline(const QString &clipId);
429 /** @brief Request a profile change for current document. */
430 void updateProfile(const QString &);
431 void processNextThumbnail();
432 /** @brief Activate the clip monitor. */
433 void raiseClipMonitor();
434 /** @brief Set number of running jobs. */
436 void cancelRunningJob(const QString, stringMap);