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 painter->drawPixmap(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2, pixmap);
112 int decoWidth = pixmap.width() + 2 * textMargin;
114 QFont font = painter->font();
116 painter->setFont(font);
117 int mid = (int)((r1.height() / 2));
118 r1.adjust(decoWidth, 0, 0, -mid);
119 QRect r2 = option.rect;
120 r2.adjust(decoWidth, mid, 0, 0);
121 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
123 painter->setFont(font);
124 QString subText = index.data(DurationRole).toString();
125 int usage = index.data(UsageRole).toInt();
126 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
127 if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
129 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
131 int proxy = index.data(Qt::UserRole + 5).toInt();
138 proxyText = QString::number(proxy) + "% ";
139 proxyText.append(i18n("Generating proxy ..."));
140 brush = option.palette.highlight();
141 color = option.palette.color(QPalette::HighlightedText);
144 else if (proxy == PROXYDONE) {
145 proxyText = i18n("Proxy");
146 brush = option.palette.mid();
147 color = option.palette.color(QPalette::WindowText);
152 proxyText = i18n("Generating proxy ...");
155 proxyText = i18n("Waiting proxy ...");
159 proxyText = i18n("Proxy crashed");
161 brush = option.palette.highlight();
162 color = option.palette.color(QPalette::HighlightedText);
165 txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + proxyText + " ");
166 painter->setPen(Qt::NoPen);
167 painter->setBrush(brush);
168 painter->drawRoundedRect(txtBounding, 2, 2);
169 painter->setPen(option.palette.highlightedText().color());
170 painter->drawText(txtBounding, Qt::AlignHCenter | Qt::AlignVCenter , proxyText);
174 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
175 if (index.data().toString().isEmpty()) {
176 QStyledItemDelegate::paint(painter, option, index);
179 QRect r1 = option.rect;
180 if (option.state & (QStyle::State_Selected)) {
181 painter->fillRect(r1, option.palette.highlight());
184 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
187 QStyledItemDelegate::paint(painter, option, index);
192 class ProjectList : public QWidget
197 ProjectList(QWidget *parent = 0);
198 virtual ~ProjectList();
200 QDomElement producersList();
201 void setRenderer(Render *projectRender);
202 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
203 QByteArray headerInfo() const;
204 void setHeaderInfo(const QByteArray &state);
205 void updateProjectFormat(Timecode t);
206 void setupMenu(QMenu *addMenu, QAction *defaultAction);
207 void setupGeneratorMenu(const QHash<QString,QMenu*>& menus);
208 QString currentClipUrl() const;
209 KUrl::List getConditionalUrls(const QString &condition) const;
210 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
212 void trashUnusedClips();
213 QList <DocClipBase*> documentClipList() const;
214 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
215 void removeClipCut(const QString &id, int in, int out);
216 void focusTree() const;
217 SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
218 void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
219 bool hasMissingClips();
220 void deleteProjectFolder(QMap <QString, QString> map);
221 void selectItemById(const QString &clipId);
223 /** @brief Returns a string list of all supported mime extensions. */
224 static QString getExtensions();
225 /** @brief Returns a list of urls containing original and proxy urls. */
226 QMap <QString, QString> getProxies();
227 /** @brief Enable / disable proxies. */
228 void updateProxyConfig();
229 /** @brief Get a property from the document. */
230 QString getDocumentProperty(const QString &key) const;
232 /** @brief Does this project allow proxies. */
233 bool useProxy() const;
234 /** @brief Should we automatically create proxy clips for newly added clips. */
235 bool generateProxy() const;
236 /** @brief Should we automatically create proxy clips for newly added clips. */
237 bool generateImageProxy() const;
238 /** @brief Returns a list of the expanded folder ids. */
239 QStringList expandedFolders() const;
240 /** @brief Deselect all clips in project tree. */
241 void clearSelection();
244 void setDocument(KdenliveDoc *doc);
245 void updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
246 void slotReplyGetImage(const QString &clipId, const QImage &img);
247 void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height);
248 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace);
249 void slotAddClip(DocClipBase *clip, bool getProperties);
250 void slotDeleteClip(const QString &clipId);
251 void slotUpdateClip(const QString &id);
252 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
253 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
254 void slotRemoveInvalidClip(const QString &id, bool replace);
255 void slotRemoveInvalidProxy(const QString &id, bool durationError);
256 void slotSelectClip(const QString &ix);
258 /** @brief Prepares removing the selected items. */
259 void slotRemoveClip();
260 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
262 /** @brief Adds, edits or deletes a folder item.
264 * This is triggered by AddFolderCommand and EditFolderCommand. */
265 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
266 void slotResetProjectList();
269 void slotReloadClip(const QString &id = QString());
271 /** @brief Shows dialog for setting up a color clip. */
272 void slotAddColorClip();
273 void regenerateTemplate(const QString &id);
274 void slotUpdateClipCut(QPoint p);
275 void slotAddClipCut(const QString &id, int in, int out);
276 void slotForceProcessing(const QString &id);
277 /** @brief Remove all instances of a proxy and delete the file. */
278 void slotDeleteProxy(const QString proxyPath);
281 ProjectListView *m_listView;
286 QFuture<void> m_queueRunner;
287 QUndoStack *m_commandStack;
288 ProjectItem *getItemById(const QString &id);
289 QTreeWidgetItem *getAnyItemById(const QString &id);
290 FolderProjectItem *getFolderItemById(const QString &id);
291 QAction *m_openAction;
292 QAction *m_reloadAction;
293 QMenu *m_transcodeAction;
294 QMenu *m_stabilizeAction;
296 ItemDelegate *m_listViewDelegate;
297 /** @brief False if we have not yet finished opening the document. */
299 /** @brief False if we have not yet finished checking all project tree thumbs. */
300 bool m_allClipsProcessed;
301 QToolButton *m_addButton;
302 QToolButton *m_deleteButton;
303 QToolButton *m_editButton;
304 //QMap <QString, QDomElement> m_infoQueue;
305 QMap <QString, QDomElement> m_producerQueue;
306 QList <QString> m_thumbnailQueue;
307 QAction *m_proxyAction;
308 QStringList m_processingClips;
309 /** @brief Holds a list of proxy urls that should be aborted. */
310 QStringList m_abortProxy;
311 /** @brief Holds a list of proxy urls that are currently being created. */
312 QStringList m_processingProxy;
314 bool m_abortAllProxies;
315 QList <PROXYINFO> m_proxyList;
316 QFutureSynchronizer<void> m_proxyThreads;
317 InvalidDialog *m_invalidClipDialog;
319 void requestClipThumbnail(const QString id);
321 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
322 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
324 /** @brief Gets the selected folder (or the folder of the selected item). */
325 QStringList getGroup() const;
326 void regenerateTemplate(ProjectItem *clip);
327 void editClipSelection(QList<QTreeWidgetItem *> list);
329 /** @brief Enables and disables transcode actions based on the selected clip's type. */
330 void adjustTranscodeActions(ProjectItem *clip) const;
331 /** @brief Enables and disables stabilize actions based on the selected clip's type. */
332 void adjustStabilizeActions(ProjectItem *clip) const;
333 /** @brief Enables and disables proxy action based on the selected clip. */
334 void adjustProxyActions(ProjectItem *clip) const;
336 /** @brief Sets the buttons enabled/disabled according to selected item. */
337 void updateButtons() const;
339 /** @brief Set the Proxy status on a clip.
340 * @param item The clip item to set status
341 * @param status The proxy status (see definitions.h) */
342 void setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress = 0);
343 /** @brief Process ffmpeg output to find out process progress. */
344 void processLogInfo(QList <ProjectItem *>items, int *duration, const QString &log);
345 void monitorItemEditing(bool enable);
346 /** @brief Set thumbnail for a project's clip. */
347 void setThumbnail(const QString &clipId, const QPixmap &pix);
348 /** @brief Get cached thumbnail for a project's clip or create it if no cache. */
349 void getCachedThumbnail(ProjectItem *item);
350 void getCachedThumbnail(SubProjectItem *item);
351 /** @brief The clip is about to be reloaded, cancel thumbnail requests. */
352 void resetThumbsProducer(DocClipBase *clip);
355 void slotClipSelected();
356 void slotAddSlideshowClip();
357 void slotAddTitleClip();
358 void slotAddTitleTemplateClip();
360 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
361 * @param pos The position where the menu should pop up
362 * @param item The item for which the checks should be done */
363 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
365 /** @brief Creates an AddFolderCommand. */
366 void slotAddFolder();
368 /** @brief This is triggered when a clip description has been modified. */
369 void slotItemEdited(QTreeWidgetItem *item, int column);
370 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
371 void slotProcessNextThumbnail();
372 void slotCheckForEmptyQueue();
373 void slotPauseMonitor();
374 /** A clip was modified externally, change icon so that user knows it */
375 void slotModifiedClip(const QString &id);
376 void slotMissingClip(const QString &id);
377 void slotAvailableClip(const QString &id);
378 /** @brief Try to find a matching profile for given item. */
379 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
380 /** @brief Add a sequence from the stopmotion widget. */
381 void slotAddOrUpdateSequence(const QString frameName);
382 /** @brief A proxy clip was created, update display. */
383 void slotGotProxy(const QString &proxyPath);
384 void slotGotProxy(ProjectItem *item);
385 /** @brief Enable / disable proxy for current clip. */
386 void slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy = NULL);
387 /** @brief Put clip in the proxy waiting list. */
388 void slotCreateProxy(const QString id);
389 /** @brief Stop creation of this clip's proxy. */
390 void slotAbortProxy(const QString id, const QString path);
391 /** @brief Start creation of proxy clip. */
392 void slotGenerateProxy();
395 void clipSelected(DocClipBase *, QPoint zone = QPoint());
396 void receivedClipDuration(const QString &);
397 void showClipProperties(DocClipBase *);
398 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
399 void projectModified();
400 void loadingIsOver();
401 void displayMessage(const QString, int progress);
402 void clipNameChanged(const QString, const QString);
403 void clipNeedsReload(const QString&);
404 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
405 * @param id: The clip's id string
406 * @param resetThumbs Should we recreate the timeline thumbnails. */
407 void refreshClip(const QString &id, bool resetThumbs);
408 void updateRenderStatus();
409 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
410 void findInTimeline(const QString &clipId);
411 /** @brief Request a profile change for current document. */
412 void updateProfile(const QString &);
413 void processNextThumbnail();
414 /** @brief Activate the clip monitor. */
415 void raiseClipMonitor();