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 <KTreeWidgetSearchLine>
43 #include <nepomuk/kratingpainter.h>
44 #include <nepomuk/resource.h>
47 #include "definitions.h"
49 #include "kdenlivesettings.h"
50 #include "folderprojectitem.h"
51 #include "subprojectitem.h"
67 class ProjectListView;
72 const int NameRole = Qt::UserRole;
73 const int DurationRole = NameRole + 1;
74 const int UsageRole = NameRole + 2;
76 class InvalidDialog: public KDialog
80 InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent = 0);
81 virtual ~InvalidDialog();
82 void addClip(const QString &id, const QString &path);
83 QStringList getIds() const;
85 QListWidget *m_clipList;
89 class ItemDelegate: public QStyledItemDelegate
92 ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
95 /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
98 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
99 if (index.column() == 0 && !index.data(DurationRole).isNull()) {
100 QRect r1 = option.rect;
102 QStyleOptionViewItemV4 opt(option);
103 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
104 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
106 if (option.state & QStyle::State_Selected) {
107 painter->setPen(option.palette.highlightedText().color());
109 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
110 QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
111 QPoint pixmapPoint(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2);
112 painter->drawPixmap(pixmapPoint, pixmap);
113 int decoWidth = pixmap.width() + 2 * textMargin;
115 QFont font = painter->font();
117 painter->setFont(font);
118 int mid = (int)((r1.height() / 2));
119 r1.adjust(decoWidth, 0, 0, -mid);
120 QRect r2 = option.rect;
121 r2.adjust(decoWidth, mid, 0, 0);
122 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom, index.data().toString());
124 painter->setFont(font);
125 QString subText = index.data(DurationRole).toString();
126 int usage = index.data(UsageRole).toInt();
127 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
128 if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
130 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
132 int proxy = index.data(Qt::UserRole + 5).toInt();
133 if (proxy != 0 && proxy != PROXYDONE) {
136 if (proxy != PROXYCRASHED) {
137 // Draw proxy progress bar
138 color = option.palette.alternateBase().color();
139 painter->setPen(Qt::NoPen);
141 painter->setBrush(QBrush(color));
142 QRect progress(pixmapPoint.x() + 1, pixmapPoint.y() + pixmap.height() - 5, pixmap.width() - 2, 4);
143 painter->drawRect(progress);
144 painter->setBrush(option.palette.text());
146 progress.adjust(1, 1, 0, -1);
147 progress.setWidth((pixmap.width() - 4) * proxy / 100);
148 painter->drawRect(progress);
150 else if (proxy == PROXYWAITING) {
151 // Draw kind of a pause icon
152 progress.adjust(1, 1, 0, -1);
153 progress.setWidth(2);
154 painter->drawRect(progress);
155 progress.moveLeft(progress.right() + 2);
156 painter->drawRect(progress);
159 else if (proxy == PROXYCRASHED) {
160 QRectF txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + proxyText + " ");
161 painter->setPen(Qt::NoPen);
162 painter->setBrush(option.palette.highlight());
163 painter->drawRoundedRect(txtBounding, 2, 2);
164 painter->setPen(option.palette.highlightedText().color());
165 painter->drawText(txtBounding, Qt::AlignHCenter | Qt::AlignVCenter , proxyText);
170 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
171 if (index.data().toString().isEmpty()) {
172 QStyledItemDelegate::paint(painter, option, index);
175 QRect r1 = option.rect;
176 if (option.state & (QStyle::State_Selected)) {
177 painter->fillRect(r1, option.palette.highlight());
180 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
183 QStyledItemDelegate::paint(painter, option, index);
188 class ProjectList : public QWidget
193 ProjectList(QWidget *parent = 0);
194 virtual ~ProjectList();
196 QDomElement producersList();
197 void setRenderer(Render *projectRender);
198 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
199 QByteArray headerInfo() const;
200 void setHeaderInfo(const QByteArray &state);
201 void updateProjectFormat(Timecode t);
202 void setupMenu(QMenu *addMenu, QAction *defaultAction);
203 void setupGeneratorMenu(const QHash<QString,QMenu*>& menus);
204 QString currentClipUrl() const;
205 KUrl::List getConditionalUrls(const QString &condition) const;
206 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
208 void trashUnusedClips();
209 QList <DocClipBase*> documentClipList() const;
210 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
211 void removeClipCut(const QString &id, int in, int out);
212 void focusTree() const;
213 SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
214 void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
215 bool hasMissingClips();
216 void deleteProjectFolder(QMap <QString, QString> map);
217 void selectItemById(const QString &clipId);
219 /** @brief Returns a string list of all supported mime extensions. */
220 static QString getExtensions();
221 /** @brief Returns a list of urls containing original and proxy urls. */
222 QMap <QString, QString> getProxies();
223 /** @brief Enable / disable proxies. */
224 void updateProxyConfig();
225 /** @brief Get a property from the document. */
226 QString getDocumentProperty(const QString &key) const;
228 /** @brief Does this project allow proxies. */
229 bool useProxy() const;
230 /** @brief Should we automatically create proxy clips for newly added clips. */
231 bool generateProxy() const;
232 /** @brief Should we automatically create proxy clips for newly added clips. */
233 bool generateImageProxy() const;
234 /** @brief Returns a list of the expanded folder ids. */
235 QStringList expandedFolders() const;
236 /** @brief Deselect all clips in project tree. */
237 void clearSelection();
238 /** @brief Print required overlays over clip thumb (proxy, stabilized,...). */
239 void processThumbOverlays(ProjectItem *item, QPixmap &pix);
242 void setDocument(KdenliveDoc *doc);
243 void updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
244 void slotReplyGetImage(const QString &clipId, const QImage &img);
245 void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height);
246 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace);
247 void slotAddClip(DocClipBase *clip, bool getProperties);
248 void slotDeleteClip(const QString &clipId);
249 void slotUpdateClip(const QString &id);
250 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
251 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
252 void slotRemoveInvalidClip(const QString &id, bool replace);
253 void slotRemoveInvalidProxy(const QString &id, bool durationError);
254 void slotSelectClip(const QString &ix);
256 /** @brief Prepares removing the selected items. */
257 void slotRemoveClip();
258 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
260 /** @brief Adds, edits or deletes a folder item.
262 * This is triggered by AddFolderCommand and EditFolderCommand. */
263 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
264 void slotResetProjectList();
267 void slotReloadClip(const QString &id = QString());
269 /** @brief Shows dialog for setting up a color clip. */
270 void slotAddColorClip();
271 void regenerateTemplate(const QString &id);
272 void slotUpdateClipCut(QPoint p);
273 void slotAddClipCut(const QString &id, int in, int out);
274 void slotForceProcessing(const QString &id);
275 /** @brief Remove all instances of a proxy and delete the file. */
276 void slotDeleteProxy(const QString proxyPath);
279 ProjectListView *m_listView;
284 QFuture<void> m_queueRunner;
285 QUndoStack *m_commandStack;
286 ProjectItem *getItemById(const QString &id);
287 QTreeWidgetItem *getAnyItemById(const QString &id);
288 FolderProjectItem *getFolderItemById(const QString &id);
289 QAction *m_openAction;
290 QAction *m_reloadAction;
291 QMenu *m_transcodeAction;
292 QMenu *m_stabilizeAction;
294 ItemDelegate *m_listViewDelegate;
295 /** @brief False if we have not yet finished opening the document. */
297 /** @brief False if we have not yet finished checking all project tree thumbs. */
298 bool m_allClipsProcessed;
299 QToolButton *m_addButton;
300 QToolButton *m_deleteButton;
301 QToolButton *m_editButton;
302 //QMap <QString, QDomElement> m_infoQueue;
303 QMap <QString, QDomElement> m_producerQueue;
304 QList <QString> m_thumbnailQueue;
305 QAction *m_proxyAction;
306 QStringList m_processingClips;
307 /** @brief Holds a list of proxy urls that should be aborted. */
308 QStringList m_abortProxy;
309 /** @brief Holds a list of proxy urls that are currently being created. */
310 QStringList m_processingProxy;
312 bool m_abortAllProxies;
313 QList <PROXYINFO> m_proxyList;
314 QFutureSynchronizer<void> m_proxyThreads;
315 InvalidDialog *m_invalidClipDialog;
317 void requestClipThumbnail(const QString id);
319 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
320 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
322 /** @brief Gets the selected folder (or the folder of the selected item). */
323 QStringList getGroup() const;
324 void regenerateTemplate(ProjectItem *clip);
325 void editClipSelection(QList<QTreeWidgetItem *> list);
327 /** @brief Enables and disables transcode actions based on the selected clip's type. */
328 void adjustTranscodeActions(ProjectItem *clip) const;
329 /** @brief Enables and disables stabilize actions based on the selected clip's type. */
330 void adjustStabilizeActions(ProjectItem *clip) const;
331 /** @brief Enables and disables proxy action based on the selected clip. */
332 void adjustProxyActions(ProjectItem *clip) const;
334 /** @brief Sets the buttons enabled/disabled according to selected item. */
335 void updateButtons() const;
337 /** @brief Set the Proxy status on a clip.
338 * @param item The clip item to set status
339 * @param status The proxy status (see definitions.h) */
340 void setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress = 0);
341 /** @brief Process ffmpeg output to find out process progress. */
342 void processLogInfo(QList <ProjectItem *>items, int *duration, const QString &log);
343 void monitorItemEditing(bool enable);
344 /** @brief Get cached thumbnail for a project's clip or create it if no cache. */
345 void getCachedThumbnail(ProjectItem *item);
346 void getCachedThumbnail(SubProjectItem *item);
347 /** @brief The clip is about to be reloaded, cancel thumbnail requests. */
348 void resetThumbsProducer(DocClipBase *clip);
351 void slotClipSelected();
352 void slotAddSlideshowClip();
353 void slotAddTitleClip();
354 void slotAddTitleTemplateClip();
356 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
357 * @param pos The position where the menu should pop up
358 * @param item The item for which the checks should be done */
359 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
361 /** @brief Creates an AddFolderCommand. */
362 void slotAddFolder();
364 /** @brief This is triggered when a clip description has been modified. */
365 void slotItemEdited(QTreeWidgetItem *item, int column);
366 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
367 void slotProcessNextThumbnail();
368 void slotCheckForEmptyQueue();
369 void slotPauseMonitor();
370 /** A clip was modified externally, change icon so that user knows it */
371 void slotModifiedClip(const QString &id);
372 void slotMissingClip(const QString &id);
373 void slotAvailableClip(const QString &id);
374 /** @brief Try to find a matching profile for given item. */
375 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
376 /** @brief Add a sequence from the stopmotion widget. */
377 void slotAddOrUpdateSequence(const QString frameName);
378 /** @brief A proxy clip was created, update display. */
379 void slotGotProxy(const QString &proxyPath);
380 void slotGotProxy(ProjectItem *item);
381 /** @brief Enable / disable proxy for current clip. */
382 void slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy = NULL);
383 /** @brief Put clip in the proxy waiting list. */
384 void slotCreateProxy(const QString id);
385 /** @brief Stop creation of this clip's proxy. */
386 void slotAbortProxy(const QString id, const QString path);
387 /** @brief Start creation of proxy clip. */
388 void slotGenerateProxy();
391 void clipSelected(DocClipBase *, QPoint zone = QPoint(), bool forceUpdate = false);
392 void receivedClipDuration(const QString &);
393 void showClipProperties(DocClipBase *);
394 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
395 void projectModified();
396 void loadingIsOver();
397 void displayMessage(const QString, int progress);
398 void clipNameChanged(const QString, const QString);
399 void clipNeedsReload(const QString&);
400 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
401 * @param id: The clip's id string
402 * @param resetThumbs Should we recreate the timeline thumbnails. */
403 void refreshClip(const QString &id, bool resetThumbs);
404 void updateRenderStatus();
405 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
406 void findInTimeline(const QString &clipId);
407 /** @brief Request a profile change for current document. */
408 void updateProfile(const QString &);
409 void processNextThumbnail();
410 /** @brief Activate the clip monitor. */
411 void raiseClipMonitor();