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 QImage &img);
229 void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height);
230 void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace, bool refreshThumbnail);
231 void slotAddClip(DocClipBase *clip, bool getProperties);
232 void slotDeleteClip(const QString &clipId);
233 void slotUpdateClip(const QString &id);
234 void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
235 void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
236 void slotRemoveInvalidClip(const QString &id, bool replace);
237 void slotRemoveInvalidProxy(const QString &id, bool durationError);
238 void slotSelectClip(const QString &ix);
240 /** @brief Prepares removing the selected items. */
241 void slotRemoveClip();
242 void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
244 /** @brief Adds, edits or deletes a folder item.
246 * This is triggered by AddFolderCommand and EditFolderCommand. */
247 void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
248 void slotResetProjectList();
251 void slotReloadClip(const QString &id = QString());
253 /** @brief Shows dialog for setting up a color clip. */
254 void slotAddColorClip();
255 void regenerateTemplate(const QString &id);
256 void slotUpdateClipCut(QPoint p);
257 void slotAddClipCut(const QString &id, int in, int out);
258 void slotForceProcessing(const QString &id);
259 /** @brief Remove all instances of a proxy and delete the file. */
260 void slotDeleteProxy(const QString proxyPath);
263 ProjectListView *m_listView;
268 QFuture<void> m_queueRunner;
269 QUndoStack *m_commandStack;
270 ProjectItem *getItemById(const QString &id);
271 QTreeWidgetItem *getAnyItemById(const QString &id);
272 FolderProjectItem *getFolderItemById(const QString &id);
273 QAction *m_openAction;
274 QAction *m_reloadAction;
275 QMenu *m_transcodeAction;
277 ItemDelegate *m_listViewDelegate;
278 /** @brief False if we have not yet finished opening the document. */
280 QToolButton *m_addButton;
281 QToolButton *m_deleteButton;
282 QToolButton *m_editButton;
283 //QMap <QString, QDomElement> m_infoQueue;
284 QMap <QString, QDomElement> m_producerQueue;
285 QList <QString> m_thumbnailQueue;
286 QAction *m_proxyAction;
287 QStringList m_processingClips;
288 /** @brief Holds a list of proxy urls that should be aborted. */
289 QStringList m_abortProxy;
290 /** @brief Holds a list of proxy urls that are currently being created. */
291 QStringList m_processingProxy;
293 bool m_abortAllProxies;
294 QList <PROXYINFO> m_proxyList;
295 QFutureSynchronizer<void> m_proxyThreads;
297 void requestClipThumbnail(const QString id);
299 /** @brief Creates an EditFolderCommand to change the name of an folder item. */
300 void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
302 /** @brief Gets the selected folder (or the folder of the selected item). */
303 QStringList getGroup() const;
304 void regenerateTemplate(ProjectItem *clip);
305 void editClipSelection(QList<QTreeWidgetItem *> list);
307 /** @brief Enables and disables transcode actions based on the selected clip's type. */
308 void adjustTranscodeActions(ProjectItem *clip) const;
309 /** @brief Enables and disables proxy action based on the selected clip. */
310 void adjustProxyActions(ProjectItem *clip) const;
312 /** @brief Sets the buttons enabled/disabled according to selected item. */
313 void updateButtons() const;
315 /** @brief Set the Proxy status on a clip.
316 * @param item The clip item to set status
317 * @param status The proxy status (see definitions.h) */
318 void setProxyStatus(const QString proxyPath, PROXYSTATUS status, int progress = 0);
319 void setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress = 0);
320 /** @brief Process ffmpeg output to find out process progress. */
321 void processLogInfo(const QString &path, int *duration, const QString &log);
322 void monitorItemEditing(bool enable);
323 /** @brief Set thumbnail for a project's clip. */
324 void setThumbnail(const QString &clipId, const QPixmap &pix);
327 void slotClipSelected();
328 void slotAddSlideshowClip();
329 void slotAddTitleClip();
330 void slotAddTitleTemplateClip();
332 /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
333 * @param pos The position where the menu should pop up
334 * @param item The item for which the checks should be done */
335 void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
337 /** @brief Creates an AddFolderCommand. */
338 void slotAddFolder();
340 /** @brief This is triggered when a clip description has been modified. */
341 void slotItemEdited(QTreeWidgetItem *item, int column);
342 void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
343 void slotProcessNextThumbnail();
344 void slotCheckForEmptyQueue();
345 void slotPauseMonitor();
346 /** A clip was modified externally, change icon so that user knows it */
347 void slotModifiedClip(const QString &id);
348 void slotMissingClip(const QString &id);
349 void slotAvailableClip(const QString &id);
350 /** @brief Try to find a matching profile for given item. */
351 bool adjustProjectProfileToItem(ProjectItem *item = NULL);
352 /** @brief Add a sequence from the stopmotion widget. */
353 void slotAddOrUpdateSequence(const QString frameName);
354 /** @brief A proxy clip was created, update display. */
355 void slotGotProxy(const QString &proxyPath);
356 void slotGotProxy(ProjectItem *item);
357 /** @brief Enable / disable proxy for current clip. */
358 void slotProxyCurrentItem(bool doProxy);
359 /** @brief Put clip in the proxy waiting list. */
360 void slotCreateProxy(const QString id);
361 /** @brief Stop creation of this clip's proxy. */
362 void slotAbortProxy(const QString id, const QString path);
363 /** @brief Start creation of proxy clip. */
364 void slotGenerateProxy();//const QString destPath, const QString sourcePath, int clipType, int exif);
367 void clipSelected(DocClipBase *, QPoint zone = QPoint());
368 void getFileProperties(const QDomElement, const QString &, int pixHeight, bool);
369 void receivedClipDuration(const QString &);
370 void showClipProperties(DocClipBase *);
371 void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
372 void projectModified();
373 void loadingIsOver();
374 void displayMessage(const QString, int progress);
375 void clipNameChanged(const QString, const QString);
376 void clipNeedsReload(const QString&, bool);
377 /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
378 * @param id: The clip's id string
379 * @param resetThumbs Should we recreate the timeline thumbnails. */
380 void refreshClip(const QString &id, bool resetThumbs);
381 void updateRenderStatus();
382 void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
383 void findInTimeline(const QString &clipId);
384 /** @brief Request a profile change for current document. */
385 void updateProfile(const QString &);
386 void processNextThumbnail();