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>
26 #include <QToolButton>
27 #include <QTreeWidget>
29 #include <QStyledItemDelegate>
32 #include <QApplication>
34 #include <QFutureSynchronizer>
36 #include <KTreeWidgetSearchLine>
41 #include <nepomuk/kratingpainter.h>
42 #include <nepomuk/resource.h>
45 #include "definitions.h"
47 #include "kdenlivesettings.h"
48 #include "folderprojectitem.h"
49 #include "subprojectitem.h"
64 class ProjectListView;
69 const int NameRole = Qt::UserRole;
70 const int DurationRole = NameRole + 1;
71 const int UsageRole = NameRole + 2;
73 class ItemDelegate: public QStyledItemDelegate
76 ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
79 /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
82 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
83 if (index.column() == 0 && !index.data(DurationRole).isNull()) {
84 QRect r1 = option.rect;
86 QStyleOptionViewItemV4 opt(option);
87 QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
88 style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
90 if (option.state & QStyle::State_Selected) {
91 painter->setPen(option.palette.highlightedText().color());
93 const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
94 QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
95 painter->drawPixmap(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2, pixmap);
96 int decoWidth = pixmap.width() + 2 * textMargin;
98 QFont font = painter->font();
100 painter->setFont(font);
101 int mid = (int)((r1.height() / 2));
102 r1.adjust(decoWidth, 0, 0, -mid);
103 QRect r2 = option.rect;
104 r2.adjust(decoWidth, mid, 0, 0);
105 painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
107 painter->setFont(font);
108 QString subText = index.data(DurationRole).toString();
109 int usage = index.data(UsageRole).toInt();
110 if (usage != 0) subText.append(QString(" (%1)").arg(usage));
111 if (option.state & (QStyle::State_Selected)) painter->setPen(option.palette.color(QPalette::Mid));
113 painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
115 int proxy = index.data(Qt::UserRole + 5).toInt();
122 proxyText = QString::number(proxy) + "% ";
123 proxyText.append(i18n("Generating proxy ..."));
124 brush = option.palette.highlight();
125 color = option.palette.color(QPalette::HighlightedText);
128 else if (proxy == PROXYDONE) {
129 proxyText = i18n("Proxy");
130 brush = option.palette.mid();
131 color = option.palette.color(QPalette::WindowText);
136 proxyText = i18n("Generating proxy ...");
139 proxyText = i18n("Waiting proxy ...");
143 proxyText = i18n("Proxy crashed");
145 brush = option.palette.highlight();
146 color = option.palette.color(QPalette::HighlightedText);
149 txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + proxyText + " ");
150 painter->setPen(Qt::NoPen);
151 painter->setBrush(brush);
152 painter->drawRoundedRect(txtBounding, 2, 2);
153 painter->setPen(option.palette.highlightedText().color());
154 painter->drawText(txtBounding, Qt::AlignHCenter | Qt::AlignVCenter , proxyText);
158 } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
159 if (index.data().toString().isEmpty()) {
160 QStyledItemDelegate::paint(painter, option, index);
163 QRect r1 = option.rect;
164 if (option.state & (QStyle::State_Selected)) {
165 painter->fillRect(r1, option.palette.highlight());
168 KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
171 QStyledItemDelegate::paint(painter, option, index);
176 class ProjectList : public QWidget
181 ProjectList(QWidget *parent = 0);
182 virtual ~ProjectList();
184 QDomElement producersList();
185 void setRenderer(Render *projectRender);
186 void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
187 QByteArray headerInfo() const;
188 void setHeaderInfo(const QByteArray &state);
189 void updateProjectFormat(Timecode t);
190 void setupMenu(QMenu *addMenu, QAction *defaultAction);
191 void setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu);
192 QString currentClipUrl() const;
193 KUrl::List getConditionalUrls(const QString &condition) const;
194 QDomDocument generateTemplateXml(QString data, const QString &replaceString);
196 void trashUnusedClips();
197 QList <DocClipBase*> documentClipList() const;
198 void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
199 void removeClipCut(const QString &id, int in, int out);
200 void focusTree() const;
201 SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
202 void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
203 bool hasMissingClips();
204 void deleteProjectFolder(QMap <QString, QString> map);
205 void selectItemById(const QString &clipId);
207 /** @brief Returns a string list of all supported mime extensions. */
208 static QString getExtensions();
209 /** @brief Returns a list of urls containing original and proxy urls. */
210 QMap <QString, QString> getProxies();
211 /** @brief Enable / disable proxies. */
212 void updateProxyConfig();
213 /** @brief Get a property from the document. */
214 QString getDocumentProperty(const QString &key) const;
216 /** @brief Does this project allow proxies. */
217 bool useProxy() const;
218 /** @brief Should we automatically create proxy clips for newly added clips. */
219 bool generateProxy() const;
220 /** @brief Should we automatically create proxy clips for newly added clips. */
221 bool generateImageProxy() const;
222 /** @brief Returns a list of the expanded folder ids. */
223 QStringList expandedFolders() const;
226 void setDocument(KdenliveDoc *doc);
227 void updateAllClips(bool displayRatioChanged, bool fpsChanged);
228 void slotReplyGetImage(const QString &clipId, const QPixmap &pix);
229 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace, bool selectClip);
230 void slotAddClip(DocClipBase *clip, bool getProperties);
231 void slotDeleteClip(const QString &clipId);
232 void slotUpdateClip(const QString &id);
233 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
234 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
235 void slotRemoveInvalidClip(const QString &id, bool replace);
236 void slotRemoveInvalidProxy(const QString &id, bool durationError);
237 void slotSelectClip(const QString &ix);
239 /** @brief Prepares removing the selected items. */
240 void slotRemoveClip();
241 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
243 /** @brief Adds, edits or deletes a folder item.
245 * This is triggered by AddFolderCommand and EditFolderCommand. */
246 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
247 void slotResetProjectList();
250 void slotReloadClip(const QString &id = QString());
252 /** @brief Shows dialog for setting up a color clip. */
253 void slotAddColorClip();
254 void regenerateTemplate(const QString &id);
255 void slotUpdateClipCut(QPoint p);
256 void slotAddClipCut(const QString &id, int in, int out);
257 void slotForceProcessing(const QString &id);
258 /** @brief Remove all instances of a proxy and delete the file. */
259 void slotDeleteProxy(const QString proxyPath);
262 ProjectListView *m_listView;
267 QFuture<void> m_queueRunner;
268 QUndoStack *m_commandStack;
269 ProjectItem *getItemById(const QString &id);
270 QTreeWidgetItem *getAnyItemById(const QString &id);
271 FolderProjectItem *getFolderItemById(const QString &id);
272 QAction *m_openAction;
273 QAction *m_reloadAction;
274 QMenu *m_transcodeAction;
276 ItemDelegate *m_listViewDelegate;
277 /** @brief False if we have not yet finished opening the document. */
279 QToolButton *m_addButton;
280 QToolButton *m_deleteButton;
281 QToolButton *m_editButton;
282 QMap <QString, QDomElement> m_infoQueue;
283 QMap <QString, QDomElement> m_producerQueue;
284 QList <QString> m_thumbnailQueue;
285 QAction *m_proxyAction;
286 QStringList m_processingClips;
287 /** @brief Holds a list of proxy urls that should be aborted. */
288 QStringList m_abortProxy;
289 /** @brief Holds a list of proxy urls that are currently being created. */
290 QStringList m_processingProxy;
292 bool m_abortAllProxies;
293 QList <PROXYINFO> m_proxyList;
294 QFutureSynchronizer<void> m_proxyThreads;
296 void requestClipThumbnail(const QString id);
298 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
299 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
301 /** @brief Gets the selected folder (or the folder of the selected item). */
302 QStringList getGroup() const;
303 void regenerateTemplate(ProjectItem *clip);
304 void editClipSelection(QList<QTreeWidgetItem *> list);
306 /** @brief Enables and disables transcode actions based on the selected clip's type. */
307 void adjustTranscodeActions(ProjectItem *clip) const;
308 /** @brief Enables and disables proxy action based on the selected clip. */
309 void adjustProxyActions(ProjectItem *clip) const;
311 /** @brief Sets the buttons enabled/disabled according to selected item. */
312 void updateButtons() const;
314 /** @brief Set the Proxy status on a clip.
315 * @param item The clip item to set status
316 * @param status The proxy status (see definitions.h) */
317 void setProxyStatus(const QString proxyPath, PROXYSTATUS status, int progress = 0);
318 void setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress = 0);
319 /** @brief Process ffmpeg output to find out process progress. */
320 void processLogInfo(const QString &path, int *duration, const QString &log);
321 void monitorItemEditing(bool enable);
324 void slotClipSelected();
325 void slotAddSlideshowClip();
326 void slotAddTitleClip();
327 void slotAddTitleTemplateClip();
329 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
330 * @param pos The position where the menu should pop up
331 * @param item The item for which the checks should be done */
332 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
334 /** @brief Creates an AddFolderCommand. */
335 void slotAddFolder();
337 /** @brief This is triggered when a clip description has been modified. */
338 void slotItemEdited(QTreeWidgetItem *item, int column);
339 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
340 void slotProcessNextClipInQueue();
341 void slotProcessNextThumbnail();
342 void slotCheckForEmptyQueue();
343 void slotPauseMonitor();
344 /** A clip was modified externally, change icon so that user knows it */
345 void slotModifiedClip(const QString &id);
346 void slotMissingClip(const QString &id);
347 void slotAvailableClip(const QString &id);
348 /** @brief Try to find a matching profile for given item. */
349 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
350 /** @brief Add a sequence from the stopmotion widget. */
351 void slotAddOrUpdateSequence(const QString frameName);
352 /** @brief A proxy clip was created, update display. */
353 void slotGotProxy(const QString &proxyPath);
354 void slotGotProxy(ProjectItem *item);
355 /** @brief Enable / disable proxy for current clip. */
356 void slotProxyCurrentItem(bool doProxy);
357 /** @brief Put clip in the proxy waiting list. */
358 void slotCreateProxy(const QString id);
359 /** @brief Stop creation of this clip's proxy. */
360 void slotAbortProxy(const QString id, const QString path);
361 /** @brief Start creation of proxy clip. */
362 void slotGenerateProxy();//const QString destPath, const QString sourcePath, int clipType, int exif);
365 void clipSelected(DocClipBase *, QPoint zone = QPoint());
366 void getFileProperties(const QDomElement, const QString &, int pixHeight, bool, bool);
367 void receivedClipDuration(const QString &);
368 void showClipProperties(DocClipBase *);
369 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
370 void projectModified();
371 void loadingIsOver();
372 void displayMessage(const QString, int progress);
373 void clipNameChanged(const QString, const QString);
374 void clipNeedsReload(const QString&, bool);
375 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
376 * @param id: The clip's id string
377 * @param resetThumbs Should we recreate the timeline thumbnails. */
378 void refreshClip(const QString &id, bool resetThumbs);
379 void updateRenderStatus();
380 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
381 void findInTimeline(const QString &clipId);
382 /** @brief Request a profile change for current document. */
383 void updateProfile(const QString &);
384 void processNextThumbnail();