]> git.sesse.net Git - kdenlive/blob - src/clipmanager.h
Improve reloading of externally modified clips (wait for 1.5 second before reloading...
[kdenlive] / src / clipmanager.h
1 /***************************************************************************
2  *   Copyright (C) 2008 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  * @class ClipManager
22  * @brief Manages the list of clips in a document.
23  * @author Jean-Baptiste Mardelle
24  */
25
26 #ifndef CLIPMANAGER_H
27 #define CLIPMANAGER_H
28
29 #include <qdom.h>
30 #include <QPixmap>
31 #include <QObject>
32 #include <QTimer>
33
34 #include <KUrl>
35 #include <KUndoStack>
36 #include <KDirWatch>
37 #include <klocale.h>
38
39 #include "gentime.h"
40 #include "definitions.h"
41
42
43 class KdenliveDoc;
44 class DocClipBase;
45 class AbstractGroupItem;
46
47 namespace Mlt
48 {
49 class Producer;
50 };
51
52 class ClipManager: public QObject
53 {
54 Q_OBJECT public:
55
56     ClipManager(KdenliveDoc *doc);
57     virtual ~ ClipManager();
58     void addClip(DocClipBase *clip);
59     DocClipBase *getClipAt(int pos);
60     void deleteClip(const QString &clipId);
61
62     /** @brief Add a file to the project.
63      * @ref slotAddClipList
64      * @param url file to add
65      * @param group name of the group to insert the file in (can be empty)
66      * @param groupId id of the group (if any) */
67     void slotAddClipFile(const KUrl url, const QString group, const QString &groupId);
68
69     /** @brief Adds a list of files to the project.
70      * @param urls files to add
71      * @param group name of the group to insert the files in (can be empty)
72      * @param groupId id of the group (if any)
73      * It checks for duplicated items and asks to the user for instructions. */
74     void slotAddClipList(const KUrl::List urls, const QString group, const QString &groupId);
75     void slotAddTextClipFile(const QString titleName, int out, const QString xml, const QString group, const QString &groupId);
76     void slotAddTextTemplateClip(QString titleName, const KUrl path, const QString group, const QString &groupId);
77     void slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const QString &groupId);
78     void slotAddSlideshowClipFile(const QString name, const QString path, int count, const QString duration, const bool loop, const bool fade, const QString &luma_duration, const QString &luma_file, const int softness, const QString group, const QString &groupId);
79     DocClipBase *getClipById(QString clipId);
80     const QList <DocClipBase *> getClipByResource(QString resource);
81     void slotDeleteClips(QStringList ids);
82     void setThumbsProgress(const QString &message, int progress);
83     void checkAudioThumbs();
84     QList <DocClipBase*> documentClipList() const;
85     QMap <QString, QString> documentFolderList() const;
86     int getFreeClipId();
87     int getFreeFolderId();
88     int lastClipId() const;
89     void startAudioThumbsGeneration();
90     void endAudioThumbsGeneration(const QString &requestedId);
91     void askForAudioThumb(const QString &id);
92     QString projectFolder() const;
93     void clearUnusedProducers();
94     void resetProducersList(const QList <Mlt::Producer *> prods);
95     void addFolder(const QString&, const QString&);
96     void deleteFolder(const QString&);
97     void clear();
98     AbstractGroupItem *createGroup();
99     void removeGroup(AbstractGroupItem *group);
100     QDomElement groupsXml() const;
101     int clipsCount() const;
102
103 public slots:
104     void updatePreviewSettings();
105
106 private slots:
107     /** A clip was externally modified, monitor for more changes and prepare for reload */
108     void slotClipModified(const QString &path);
109     void slotClipMissing(const QString &path);
110     void slotClipAvailable(const QString &path);
111     /** Check the list of externally modified clips, and process them if they were not modified in the last 1500 milliseconds */
112     void slotProcessModifiedClips();
113
114 private:   // Private attributes
115     /** the list of clips in the document */
116     QList <DocClipBase*> m_clipList;
117     /** the list of groups in the document */
118     QList <AbstractGroupItem *> m_groupsList;
119     QMap <QString, QString> m_folderList;
120     QList <QString> m_audioThumbsQueue;
121     /** the document undo stack*/
122     KdenliveDoc *m_doc;
123     int m_clipIdCounter;
124     int m_folderIdCounter;
125     QString m_generatingAudioId;
126     KDirWatch m_fileWatcher;
127     /** Timer used to reload clips when they have been externally modified */
128     QTimer m_modifiedTimer;
129     /** List of the clip IDs that need to be reloaded after being externally modified */
130     QMap <QString, QTime> m_modifiedClips;
131
132 signals:
133     void reloadClip(const QString &);
134     void modifiedClip(const QString &);
135     void missingClip(const QString &);
136     void availableClip(const QString &);
137     void checkAllClips();
138 };
139
140 #endif