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