]> git.sesse.net Git - kdenlive/blob - src/projectlist.h
Extract clip metadata (camcorder name, aperture, exposure, ...) with exiftool if...
[kdenlive] / src / projectlist.h
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #ifndef PROJECTLIST_H
22 #define PROJECTLIST_H
23
24 #include <QDomNodeList>
25 #include <QHash>
26 #include <QToolBar>
27 #include <QToolButton>
28 #include <QTreeWidget>
29 #include <QPainter>
30 #include <QStyledItemDelegate>
31 #include <QUndoStack>
32 #include <QTimer>
33 #include <QApplication>
34 #include <QFuture>
35 #include <QFutureSynchronizer>
36 #include <QListWidget>
37 #include <QTimeLine>
38 #include <QPushButton>
39
40 #include <KTreeWidgetSearchLine>
41 #include <KUrl>
42 #include <KIcon>
43 #include <kdeversion.h>
44
45 #ifdef NEPOMUK
46 #include <nepomuk/kratingpainter.h>
47 #include <nepomuk/resource.h>
48 #endif
49
50 #include "definitions.h"
51 #include "timecode.h"
52 #include "kdenlivesettings.h"
53 #include "folderprojectitem.h"
54 #include "subprojectitem.h"
55 #include "projecttree/abstractclipjob.h"
56 #include <kdialog.h>
57
58 #if KDE_IS_VERSION(4,7,0)
59 #include <KMessageWidget>
60 #else
61 // Dummy KMessageWidget to allow compilation of MyMessageWidget class since Qt's moc doesn work inside #ifdef
62 #include <QLabel>
63 class KMessageWidget: public QLabel
64 {
65 public:
66     KMessageWidget(QWidget * = 0) {};
67     KMessageWidget(const QString &, QWidget * = 0) {};
68     virtual ~KMessageWidget(){};
69 };
70 #endif
71
72 class MyMessageWidget: public KMessageWidget
73 {
74     Q_OBJECT
75 public:
76     MyMessageWidget(QWidget *parent = 0);
77     MyMessageWidget(const QString &text, QWidget *parent = 0);
78
79 protected:
80     bool event(QEvent* ev);
81
82 signals:
83     void messageClosing();
84 };
85
86 namespace Mlt
87 {
88 class Producer;
89 };
90
91 class ProjectItem;
92 class ProjectListView;
93 class Render;
94 class KdenliveDoc;
95 class DocClipBase;
96 class AbstractClipJob;
97
98 const int NameRole = Qt::UserRole;
99 const int DurationRole = NameRole + 1;
100 const int UsageRole = NameRole + 2;
101
102 class SmallInfoLabel: public QPushButton
103 {
104     Q_OBJECT
105 public:
106     SmallInfoLabel(QWidget *parent = 0);
107     static const QString getStyleSheet(const QPalette &p);
108 private:
109     QTimeLine* m_timeLine;
110
111 public slots:
112     void slotSetJobCount(int jobCount);
113
114 private slots:
115     void slotTimeLineChanged(qreal value);
116     void slotTimeLineFinished();
117 };
118     
119 class InvalidDialog: public KDialog
120 {
121     Q_OBJECT
122 public:
123     InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent = 0);
124     virtual ~InvalidDialog();
125     void addClip(const QString &id, const QString &path);
126     QStringList getIds() const;
127 private:
128     QListWidget *m_clipList;
129 };
130
131
132 class ItemDelegate: public QStyledItemDelegate
133 {
134 public:
135     ItemDelegate(QAbstractItemView* parent = 0): QStyledItemDelegate(parent) {
136     }
137     
138     /*void drawFocus(QPainter *, const QStyleOptionViewItem &, const QRect &) const {
139     }*/
140
141     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
142         if (index.column() == 0 && !index.data(DurationRole).isNull()) {
143             QRect r1 = option.rect;
144             painter->save();
145             QStyleOptionViewItemV4 opt(option);
146             QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
147             style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
148
149             if (option.state & QStyle::State_Selected) {
150                 painter->setPen(option.palette.highlightedText().color());
151             }
152             const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
153             QPixmap pixmap = qVariantValue<QPixmap>(index.data(Qt::DecorationRole));
154             QPoint pixmapPoint(r1.left() + textMargin, r1.top() + (r1.height() - pixmap.height()) / 2);
155             painter->drawPixmap(pixmapPoint, pixmap);
156             int decoWidth = pixmap.width() + 2 * textMargin;
157
158             QFont font = painter->font();
159             font.setBold(true);
160             painter->setFont(font);
161             int mid = (int)((r1.height() / 2));
162             r1.adjust(decoWidth, 0, 0, -mid);
163             QRect r2 = option.rect;
164             r2.adjust(decoWidth, mid, 0, 0);
165             painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom, index.data().toString());
166             font.setBold(false);
167             painter->setFont(font);
168             QString subText = index.data(DurationRole).toString();
169             int usage = index.data(UsageRole).toInt();
170             if (usage != 0) subText.append(QString(" (%1)").arg(usage));
171             QRectF bounding;
172             painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , subText, &bounding);
173             int jobProgress = index.data(Qt::UserRole + 5).toInt();
174             if (jobProgress != 0 && jobProgress != JOBDONE && jobProgress != JOBABORTED) {
175                 if (jobProgress != JOBCRASHED) {
176                     // Draw job progress bar
177                     QColor color = option.palette.alternateBase().color();
178                     color.setAlpha(150);
179                     painter->setPen(option.palette.link().color());
180                     QRect progress(pixmapPoint.x() + 2, pixmapPoint.y() + pixmap.height() - 9, pixmap.width() - 4, 7);
181                     painter->setBrush(QBrush(color));
182                     painter->drawRect(progress);
183                     painter->setBrush(option.palette.link());
184                     progress.adjust(2, 2, -2, -2);
185                     if (jobProgress == JOBWAITING) {
186                         progress.setLeft(progress.right() - 2);
187                         painter->drawRect(progress);
188                         progress.moveLeft(progress.left() - 5);
189                         painter->drawRect(progress);
190                     }
191                     else if (jobProgress > 0) {
192                         progress.setWidth(progress.width() * jobProgress / 100);
193                         painter->drawRect(progress);
194                     }
195                 } else if (jobProgress == JOBCRASHED) {
196                     QString jobText = index.data(Qt::UserRole + 7).toString();
197                     if (!jobText.isEmpty()) {
198                         QRectF txtBounding = painter->boundingRect(r2, Qt::AlignRight | Qt::AlignVCenter, " " + jobText + " ");
199                         painter->setPen(Qt::NoPen);
200                         painter->setBrush(option.palette.highlight());
201                         painter->drawRoundedRect(txtBounding, 2, 2);
202                         painter->setPen(option.palette.highlightedText().color());
203                         painter->drawText(txtBounding, Qt::AlignCenter, jobText);
204                     }
205                 }
206             }
207             
208             painter->restore();
209         } else if (index.column() == 2 && KdenliveSettings::activate_nepomuk()) {
210             if (index.data().toString().isEmpty()) {
211                 QStyledItemDelegate::paint(painter, option, index);
212                 return;
213             }
214             QRect r1 = option.rect;
215             if (option.state & (QStyle::State_Selected)) {
216                 painter->fillRect(r1, option.palette.highlight());
217             }
218 #ifdef NEPOMUK
219             KRatingPainter::paintRating(painter, r1, Qt::AlignCenter, index.data().toInt());
220 #endif
221         } else {
222             QStyledItemDelegate::paint(painter, option, index);
223         }
224     }
225 };
226
227 class ProjectList : public QWidget
228 {
229     Q_OBJECT
230
231 public:
232     ProjectList(QWidget *parent = 0);
233     virtual ~ProjectList();
234
235     QDomElement producersList();
236     void setRenderer(Render *projectRender);
237     void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties);
238     QByteArray headerInfo() const;
239     void setHeaderInfo(const QByteArray &state);
240     void updateProjectFormat(Timecode t);
241     void setupMenu(QMenu *addMenu, QAction *defaultAction);
242     void setupGeneratorMenu(const QHash<QString,QMenu*>& menus);
243     QString currentClipUrl() const;
244     KUrl::List getConditionalUrls(const QString &condition) const;
245     /** @brief Get a list of selected clip Id's that match a condition. */
246     QStringList getConditionalIds(const QString &condition) const;
247     QDomDocument generateTemplateXml(QString data, const QString &replaceString);
248     void cleanup();
249     void trashUnusedClips();
250     QList <DocClipBase*> documentClipList() const;
251     void addClipCut(const QString &id, int in, int out, const QString desc, bool newItem);
252     void removeClipCut(const QString &id, int in, int out);
253     void focusTree() const;
254     SubProjectItem *getSubItem(ProjectItem *clip, QPoint zone);
255     void doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment);
256     bool hasMissingClips();
257     void deleteProjectFolder(QMap <QString, QString> map);
258     void selectItemById(const QString &clipId);
259
260     /** @brief Returns a string list of all supported mime extensions. */
261     static QString getExtensions();
262     /** @brief Returns a list of urls containing original and proxy urls. */
263     QMap <QString, QString> getProxies();
264     /** @brief Enable / disable proxies. */
265     void updateProxyConfig();
266     /** @brief Get a property from the document. */
267     QString getDocumentProperty(const QString &key) const;
268     
269     /** @brief Does this project allow proxies. */
270     bool useProxy() const;
271     /** @brief Should we automatically create proxy clips for newly added clips. */
272     bool generateProxy() const;
273     /** @brief Should we automatically create proxy clips for newly added clips. */
274     bool generateImageProxy() const;
275     /** @brief Returns a list of the expanded folder ids. */
276     QStringList expandedFolders() const;
277     /** @brief Deselect all clips in project tree. */
278     void clearSelection();
279     /** @brief Print required overlays over clip thumb (proxy, stabilized,...). */
280     void processThumbOverlays(ProjectItem *item, QPixmap &pix);
281     /** @brief Start an MLT process job. */
282     void startClipFilterJob(const QString &filterName, const QString &condition);
283     /** @brief Set current document for the project tree. */
284     void setDocument(KdenliveDoc *doc);
285     
286     /** @brief Palette was changed, update style. */
287     void updatePalette();
288
289 public slots:
290     void updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips);
291     void slotReplyGetImage(const QString &clipId, const QImage &img);
292     void slotReplyGetImage(const QString &clipId, const QString &name, int width, int height);
293     void slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace);
294     void slotAddClip(DocClipBase *clip, bool getProperties);
295     void slotDeleteClip(const QString &clipId);
296     void slotUpdateClip(const QString &id);
297     void slotRefreshClipThumbnail(const QString &clipId, bool update = true);
298     void slotRefreshClipThumbnail(QTreeWidgetItem *item, bool update = true);
299     void slotRemoveInvalidClip(const QString &id, bool replace);
300     void slotRemoveInvalidProxy(const QString &id, bool durationError);
301     void slotSelectClip(const QString &ix);
302
303     /** @brief Prepares removing the selected items. */
304     void slotRemoveClip();
305     void slotAddClip(const QString url, const QString &groupName, const QString &groupId);
306     void slotAddClip(const QList <QUrl> givenList = QList <QUrl> (), const QString &groupName = QString(), const QString &groupId = QString());
307
308     /** @brief Adds, edits or deletes a folder item.
309     *
310     * This is triggered by AddFolderCommand and EditFolderCommand. */
311     void slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit = false);
312     void slotResetProjectList();
313     void slotOpenClip();
314     void slotEditClip();
315     void slotReloadClip(const QString &id = QString());
316
317     /** @brief Shows dialog for setting up a color clip. */
318     void slotAddColorClip();
319     void regenerateTemplate(const QString &id);
320     void slotUpdateClipCut(QPoint p);
321     void slotAddClipCut(const QString &id, int in, int out);
322     void slotForceProcessing(const QString &id);
323     /** @brief Remove all instances of a proxy and delete the file. */
324     void slotDeleteProxy(const QString proxyPath);
325     /** @brief Start a hard cut clip job. */
326     void slotCutClipJob(const QString &id, QPoint zone);
327     /** @brief Start transcoding selected clips. */
328     void slotTranscodeClipJob(const QString &condition, QString params, QString desc);
329     /** @brief Start an MLT process job. */
330     void slotStartFilterJob(ItemInfo, const QString&,const QString&,const QString&,const QString&,const QString&,const QMap <QString, QString>&);
331     void slotSetThumbnail(const QString &id, int framePos, QImage img);
332     
333
334 private:
335     ProjectListView *m_listView;
336     Render *m_render;
337     Timecode m_timecode;
338     double m_fps;
339     QMenu *m_menu;
340     QFuture<void> m_queueRunner;
341     QUndoStack *m_commandStack;
342     ProjectItem *getItemById(const QString &id);
343     QTreeWidgetItem *getAnyItemById(const QString &id);
344     FolderProjectItem *getFolderItemById(const QString &id);
345     FolderProjectItem *getFolderItemByName(const QString &name);
346     QAction *m_openAction;
347     QAction *m_reloadAction;
348     QAction *m_discardCurrentClipJobs;
349     QMenu *m_extractAudioAction;
350     QMenu *m_transcodeAction;
351     QMenu *m_clipsActionsMenu;
352     KdenliveDoc *m_doc;
353     ItemDelegate *m_listViewDelegate;
354     /** @brief False if we have not yet finished opening the document. */
355     bool m_refreshed;
356     /** @brief False if we have not yet finished checking all project tree thumbs. */
357     bool m_allClipsProcessed;
358     QToolButton *m_addButton;
359     QToolButton *m_deleteButton;
360     QToolButton *m_editButton;
361     //QMap <QString, QDomElement> m_infoQueue;
362     QMap <QString, QDomElement> m_producerQueue;
363     QList <QString> m_thumbnailQueue;
364     QAction *m_proxyAction;
365     QMutex m_jobMutex;
366     bool m_abortAllJobs;
367     /** @brief We are cleaning up the project list, so stop processing signals. */
368     bool m_closing;
369     QList <AbstractClipJob *> m_jobList;
370     QFutureSynchronizer<void> m_jobThreads;
371     InvalidDialog *m_invalidClipDialog;
372     QMenu *m_jobsMenu;
373     SmallInfoLabel *m_infoLabel;
374     /** @brief A list of strings containing the last error logs for clip jobs. */
375     QStringList m_errorLog;
376
377 #if KDE_IS_VERSION(4,7,0)
378     MyMessageWidget *m_infoMessage;
379     /** @brief The action that will trigger the log dialog. */
380     QAction *m_logAction;
381 #endif
382     
383     void requestClipThumbnail(const QString id);
384
385     /** @brief Creates an EditFolderCommand to change the name of an folder item. */
386     void editFolder(const QString folderName, const QString oldfolderName, const QString &clipId);
387
388     /** @brief Gets the selected folder (or the folder of the selected item). */
389     QStringList getGroup() const;
390     void regenerateTemplate(ProjectItem *clip);
391     void editClipSelection(QList<QTreeWidgetItem *> list);
392
393     /** @brief Enables and disables transcode actions based on the selected clip's type. */
394     void adjustTranscodeActions(ProjectItem *clip) const;
395     /** @brief Enables and disables stabilize actions based on the selected clip's type. */
396     void adjustStabilizeActions(ProjectItem *clip) const;
397     /** @brief Enables and disables proxy action based on the selected clip. */
398     void adjustProxyActions(ProjectItem *clip) const;
399
400     /** @brief Sets the buttons enabled/disabled according to selected item. */
401     void updateButtons() const;
402
403     /** @brief Set the Proxy status on a clip. 
404      * @param item The clip item to set status
405      * @param jobType The job type 
406      * @param status The job status (see definitions.h)
407      * @param progress The job progress (in percents)
408      * @param statusMessage The job info message */
409     void setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress = 0, const QString &statusMessage = QString());
410     void monitorItemEditing(bool enable);
411     /** @brief Get cached thumbnail for a project's clip or create it if no cache. */
412     void getCachedThumbnail(ProjectItem *item);
413     void getCachedThumbnail(SubProjectItem *item);
414     /** @brief The clip is about to be reloaded, cancel thumbnail requests. */
415     void resetThumbsProducer(DocClipBase *clip);
416     /** @brief Check if a clip has a running or pending job process. */
417     bool hasPendingJob(ProjectItem *item, JOBTYPE type);
418     /** @brief Delete pending jobs for a clip. */
419     void deleteJobsForClip(const QString &clipId);
420     /** @brief Discard specific job type for a clip. */
421     void discardJobs(const QString &id, JOBTYPE type = NOJOBTYPE);
422     /** @brief Get the list of job names for current clip. */
423     QStringList getPendingJobs(const QString &id);
424     /** @brief Start an MLT process job. */
425     void processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description, QMap <QString, QString>extraParams = QMap <QString, QString>());
426     /** @brief Create rounded shape pixmap for project tree thumb. */
427     QPixmap roundedPixmap(QImage img);
428     QPixmap roundedPixmap(QPixmap source);
429     void extractMetadata(DocClipBase *clip);
430
431 private slots:
432     void slotClipSelected();
433     void slotAddSlideshowClip();
434     void slotAddTitleClip();
435     void slotAddTitleTemplateClip();
436
437     /** @brief Shows the context menu after enabling and disabling actions based on the item's type.
438     * @param pos The position where the menu should pop up
439     * @param item The item for which the checks should be done */
440     void slotContextMenu(const QPoint &pos, QTreeWidgetItem *item);
441
442     /** @brief Creates an AddFolderCommand. */
443     void slotAddFolder(const QString &name = QString());
444
445     /** @brief This is triggered when a clip description has been modified. */
446     void slotItemEdited(QTreeWidgetItem *item, int column);
447     void slotUpdateClipProperties(ProjectItem *item, QMap <QString, QString> properties);
448     void slotProcessNextThumbnail();
449     void slotCheckForEmptyQueue();
450     void slotPauseMonitor();
451     /** A clip was modified externally, change icon so that user knows it */
452     void slotModifiedClip(const QString &id);
453     void slotMissingClip(const QString &id);
454     void slotAvailableClip(const QString &id);
455     /** @brief Try to find a matching profile for given item. */
456     bool adjustProjectProfileToItem(ProjectItem *item = NULL);
457     /** @brief Add a sequence from the stopmotion widget. */
458     void slotAddOrUpdateSequence(const QString frameName);
459     /** @brief A proxy clip was created, update display. */
460     void slotGotProxy(const QString &proxyPath);
461     void slotGotProxy(ProjectItem *item);
462     /** @brief Enable / disable proxy for current clip. */
463     void slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy = NULL);
464     /** @brief Put clip in the proxy waiting list. */
465     void slotCreateProxy(const QString id);
466     /** @brief Stop creation of this clip's proxy. */
467     void slotAbortProxy(const QString id, const QString path);
468     /** @brief Start creation of clip jobs. */
469     void slotProcessJobs();
470     /** @brief Discard running and pending clip jobs. */
471     void slotCancelJobs();
472     /** @brief Discard a running clip jobs. */
473     void slotCancelRunningJob(const QString id, stringMap);
474     /** @brief Update a clip's job status. */
475     void slotProcessLog(const QString, int progress, int, const QString = QString());
476     /** @brief A clip job crashed, inform user. */
477     void slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details);
478     void slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName = QString(), const QString details = QString());
479     /** @brief Display error log for last failed job. */
480     void slotShowJobLog();
481     /** @brief A proxy clip is ready. */
482     void slotGotProxyForId(const QString);
483     /** @brief Check if it is necessary to start a job thread. */
484     void slotCheckJobProcess();
485     /** @brief Fill the jobs menu with current clip's jobs. */
486     void slotPrepareJobsMenu();
487     /** @brief Discard all jobs for current clip. */
488     void slotDiscardClipJobs();
489     /** @brief Make sure current clip is visible in project tree. */
490     void slotCheckScrolling();
491     /** @brief Reset all text and log data from info message widget. */
492     void slotResetInfoMessage();
493     /** @brief close warning info passive popup. */
494     void slotClosePopup();
495     /** @brief process clip job result. */
496     void slotGotFilterJobResults(QString ,int , int, stringMap, stringMap);
497
498 signals:
499     void clipSelected(DocClipBase *, QPoint zone = QPoint(), bool forceUpdate = false);
500     void receivedClipDuration(const QString &);
501     void showClipProperties(DocClipBase *);
502     void showClipProperties(QList <DocClipBase *>, QMap<QString, QString> commonproperties);
503     void projectModified();
504     void loadingIsOver();
505     void displayMessage(const QString, int progress, MessageType type = DefaultMessage);
506     void clipNameChanged(const QString, const QString);
507     void clipNeedsReload(const QString&);
508     /** @brief A property affecting display was changed, so we need to update monitors and thumbnails
509      *  @param id: The clip's id string
510      *  @param resetThumbs Should we recreate the timeline thumbnails. */
511     void refreshClip(const QString &id, bool resetThumbs);
512     void updateRenderStatus();
513     void deleteProjectClips(QStringList ids, QMap <QString, QString> folderids);
514     void findInTimeline(const QString &clipId);
515     /** @brief Request a profile change for current document. */
516     void updateProfile(const QString &);
517     void processNextThumbnail();
518     /** @brief Activate the clip monitor. */
519     void raiseClipMonitor(bool forceRefresh);
520     /** @brief Set number of running jobs. */
521     void jobCount(int);
522     void cancelRunningJob(const QString, stringMap);
523     void processLog(const QString, int , int, const QString = QString());
524     void addClip(const QString, const QString &, const QString &);
525     void updateJobStatus(const QString, int, int, const QString label = QString(), const QString actionName = QString(), const QString details = QString());
526     void gotProxy(const QString);
527     void checkJobProcess();
528     /** @brief A Filter Job produced results, send them back to the clip. */
529     void gotFilterJobResults(const QString &id, int startPos, int track, stringMap params, stringMap extra);
530     void pauseMonitor();
531     void updateAnalysisData(DocClipBase *);
532     void addMarkers(const QString &, QList <CommentedTime>);
533 };
534
535 #endif
536
537