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