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 QRectF txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + proxyText + " ");
174 painter->setPen(Qt::NoPen);
175 painter->setBrush(option.palette.highlight());
176 painter->drawRoundedRect(txtBounding, 2, 2);
177 painter->setPen(option.palette.highlightedText().color());
178 painter->drawText(txtBounding, Qt::AlignHCenter | Qt::AlignVCenter , proxyText);
183 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
184 if (index.data().toString().isEmpty()) {
185 QStyledItemDelegate::paint(painter, option, index);
188 QRect r1 = option.rect;
189 if (option.state & (QStyle::State_Selected)) {
190 painter->fillRect(r1, option.palette.highlight());
193 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
196 QStyledItemDelegate::paint(painter, option, index);
201 class ProjectList : public QWidget
206 ProjectList(QWidget *parent = 0);
207 virtual ~ProjectList();
209 QDomElement producersList();
210 void setRenderer(Render *projectRender);
211 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
212 QByteArray headerInfo() const;
213 void setHeaderInfo(const QByteArray &state);
214 void updateProjectFormat(Timecode t);
215 void setupMenu(QMenu *addMenu, QAction *defaultAction);
216 void setupGeneratorMenu(const QHash<QString,QMenu*>& menus);
217 QString currentClipUrl() const;
218 KUrl::List getConditionalUrls(const QString &condition) const;
219 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
221 void trashUnusedClips();
222 QList <DocClipBase*> documentClipList() const;
223 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
224 void removeClipCut(const QString &id, int in, int out);
225 void focusTree() const;
226 SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
227 void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
228 bool hasMissingClips();
229 void deleteProjectFolder(QMap <QString, QString> map);
230 void selectItemById(const QString &clipId);
232 /** @brief Returns a string list of all supported mime extensions. */
233 static QString getExtensions();
234 /** @brief Returns a list of urls containing original and proxy urls. */
235 QMap <QString, QString> getProxies();
236 /** @brief Enable / disable proxies. */
237 void updateProxyConfig();
238 /** @brief Get a property from the document. */
239 QString getDocumentProperty(const QString &key) const;
241 /** @brief Does this project allow proxies. */
242 bool useProxy() const;
243 /** @brief Should we automatically create proxy clips for newly added clips. */
244 bool generateProxy() const;
245 /** @brief Should we automatically create proxy clips for newly added clips. */
246 bool generateImageProxy() const;
247 /** @brief Returns a list of the expanded folder ids. */
248 QStringList expandedFolders() const;
249 /** @brief Deselect all clips in project tree. */
250 void clearSelection();
251 /** @brief Print required overlays over clip thumb (proxy, stabilized,...). */
252 void processThumbOverlays(ProjectItem *item, QPixmap &pix);
255 void setDocument(KdenliveDoc *doc);
256 void updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
257 void slotReplyGetImage(const QString &clipId, const QImage &img);
258 void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height);
259 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace);
260 void slotAddClip(DocClipBase *clip, bool getProperties);
261 void slotDeleteClip(const QString &clipId);
262 void slotUpdateClip(const QString &id);
263 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
264 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
265 void slotRemoveInvalidClip(const QString &id, bool replace);
266 void slotRemoveInvalidProxy(const QString &id, bool durationError);
267 void slotSelectClip(const QString &ix);
269 /** @brief Prepares removing the selected items. */
270 void slotRemoveClip();
271 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
273 /** @brief Adds, edits or deletes a folder item.
275 * This is triggered by AddFolderCommand and EditFolderCommand. */
276 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
277 void slotResetProjectList();
280 void slotReloadClip(const QString &id = QString());
282 /** @brief Shows dialog for setting up a color clip. */
283 void slotAddColorClip();
284 void regenerateTemplate(const QString &id);
285 void slotUpdateClipCut(QPoint p);
286 void slotAddClipCut(const QString &id, int in, int out);
287 void slotForceProcessing(const QString &id);
288 /** @brief Remove all instances of a proxy and delete the file. */
289 void slotDeleteProxy(const QString proxyPath);
292 ProjectListView *m_listView;
297 QFuture<void> m_queueRunner;
298 QUndoStack *m_commandStack;
299 ProjectItem *getItemById(const QString &id);
300 QTreeWidgetItem *getAnyItemById(const QString &id);
301 FolderProjectItem *getFolderItemById(const QString &id);
302 QAction *m_openAction;
303 QAction *m_reloadAction;
304 QMenu *m_transcodeAction;
305 QMenu *m_stabilizeAction;
307 ItemDelegate *m_listViewDelegate;
308 /** @brief False if we have not yet finished opening the document. */
310 /** @brief False if we have not yet finished checking all project tree thumbs. */
311 bool m_allClipsProcessed;
312 QToolButton *m_addButton;
313 QToolButton *m_deleteButton;
314 QToolButton *m_editButton;
315 //QMap <QString, QDomElement> m_infoQueue;
316 QMap <QString, QDomElement> m_producerQueue;
317 QList <QString> m_thumbnailQueue;
318 QAction *m_proxyAction;
319 QStringList m_processingClips;
320 /** @brief Holds a list of proxy urls that should be aborted. */
321 QStringList m_abortProxy;
322 /** @brief Holds a list of proxy urls that are currently being created. */
323 QStringList m_processingProxy;
326 /** @brief We are cleaning up the project list, so stop processing signals. */
328 QList <AbstractClipJob *> m_jobList;
329 QFutureSynchronizer<void> m_proxyThreads;
330 InvalidDialog *m_invalidClipDialog;
332 SmallInfoLabel *m_infoLabel;
334 void requestClipThumbnail(const QString id);
336 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
337 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
339 /** @brief Gets the selected folder (or the folder of the selected item). */
340 QStringList getGroup() const;
341 void regenerateTemplate(ProjectItem *clip);
342 void editClipSelection(QList<QTreeWidgetItem *> list);
344 /** @brief Enables and disables transcode actions based on the selected clip's type. */
345 void adjustTranscodeActions(ProjectItem *clip) const;
346 /** @brief Enables and disables stabilize actions based on the selected clip's type. */
347 void adjustStabilizeActions(ProjectItem *clip) const;
348 /** @brief Enables and disables proxy action based on the selected clip. */
349 void adjustProxyActions(ProjectItem *clip) const;
351 /** @brief Sets the buttons enabled/disabled according to selected item. */
352 void updateButtons() const;
354 /** @brief Set the Proxy status on a clip.
355 * @param item The clip item to set status
356 * @param status The proxy status (see definitions.h) */
357 void setProxyStatus(ProjectItem *item, CLIPJOBSTATUS status, int progress = 0);
358 /** @brief Process ffmpeg output to find out process progress. */
359 void processLogInfo(QList <ProjectItem *>items, int *duration, const QString &log);
360 void monitorItemEditing(bool enable);
361 /** @brief Get cached thumbnail for a project's clip or create it if no cache. */
362 void getCachedThumbnail(ProjectItem *item);
363 void getCachedThumbnail(SubProjectItem *item);
364 /** @brief The clip is about to be reloaded, cancel thumbnail requests. */
365 void resetThumbsProducer(DocClipBase *clip);
368 void slotClipSelected();
369 void slotAddSlideshowClip();
370 void slotAddTitleClip();
371 void slotAddTitleTemplateClip();
373 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
374 * @param pos The position where the menu should pop up
375 * @param item The item for which the checks should be done */
376 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
378 /** @brief Creates an AddFolderCommand. */
379 void slotAddFolder();
381 /** @brief This is triggered when a clip description has been modified. */
382 void slotItemEdited(QTreeWidgetItem *item, int column);
383 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
384 void slotProcessNextThumbnail();
385 void slotCheckForEmptyQueue();
386 void slotPauseMonitor();
387 /** A clip was modified externally, change icon so that user knows it */
388 void slotModifiedClip(const QString &id);
389 void slotMissingClip(const QString &id);
390 void slotAvailableClip(const QString &id);
391 /** @brief Try to find a matching profile for given item. */
392 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
393 /** @brief Add a sequence from the stopmotion widget. */
394 void slotAddOrUpdateSequence(const QString frameName);
395 /** @brief A proxy clip was created, update display. */
396 void slotGotProxy(const QString &proxyPath);
397 void slotGotProxy(ProjectItem *item);
398 /** @brief Enable / disable proxy for current clip. */
399 void slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy = NULL);
400 /** @brief Put clip in the proxy waiting list. */
401 void slotCreateProxy(const QString id);
402 /** @brief Stop creation of this clip's proxy. */
403 void slotAbortProxy(const QString id, const QString path);
404 /** @brief Start creation of proxy clip. */
405 void slotGenerateProxy();
406 /** @brief Discard running and pending clip jobs. */
407 void slotCancelJobs();
408 /** @brief Discard a running clip jobs. */
409 void slotCancelRunningJob(const QString id, stringMap);
412 void clipSelected(DocClipBase *, QPoint zone = QPoint(), bool forceUpdate = false);
413 void receivedClipDuration(const QString &);
414 void showClipProperties(DocClipBase *);
415 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
416 void projectModified();
417 void loadingIsOver();
418 void displayMessage(const QString, int progress);
419 void clipNameChanged(const QString, const QString);
420 void clipNeedsReload(const QString&);
421 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
422 * @param id: The clip's id string
423 * @param resetThumbs Should we recreate the timeline thumbnails. */
424 void refreshClip(const QString &id, bool resetThumbs);
425 void updateRenderStatus();
426 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
427 void findInTimeline(const QString &clipId);
428 /** @brief Request a profile change for current document. */
429 void updateProfile(const QString &);
430 void processNextThumbnail();
431 /** @brief Activate the clip monitor. */
432 void raiseClipMonitor();
433 /** @brief Set number of running jobs. */
435 void cancelRunningJob(const QString, stringMap);