]> git.sesse.net Git - kdenlive/blob - src/clipmanager.h
Various changes for getting an OpenGL context (almost) everywhere it is needed.
[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 <QtXml/qdom.h>
30 #include <QPixmap>
31 #include <QObject>
32 #include <QTimer>
33 #include <QMutex>
34 #include <QFuture>
35
36 #include <KUrl>
37 #include <KUndoStack>
38 #include <KDirWatch>
39 #include <klocale.h>
40 #include <kdeversion.h>
41 #include <KIO/CopyJob>
42
43 #if KDE_IS_VERSION(4,5,0)
44 #include <KImageCache>
45 #endif
46
47
48 #include "gentime.h"
49 #include "definitions.h"
50
51
52 class KdenliveDoc;
53 class DocClipBase;
54 class AbstractGroupItem;
55 class QGLWidget;
56
57
58 class SolidVolumeInfo
59 {
60
61 public:
62     QString path; // mount path of volume, with trailing slash
63     QString uuid; // UUID as from Solid
64     QString label; // volume label (think of CDs)
65     bool isRemovable; // may be removed
66     bool isMounted;
67
68     bool isNull() const { return path.isNull(); }
69 };
70
71 namespace Mlt
72 {
73 class Producer;
74 }
75
76 class ClipManager: public QObject
77 {
78 Q_OBJECT public:
79
80     ClipManager(KdenliveDoc *doc, QGLWidget *glContext);
81     virtual ~ ClipManager();
82     void addClip(DocClipBase *clip);
83     DocClipBase *getClipAt(int pos);
84     void deleteClip(const QString &clipId);
85
86     /** @brief Add a file to the project.
87      * @ref slotAddClipList
88      * @param url file to add
89      * @param group name of the group to insert the file in (can be empty)
90      * @param groupId id of the group (if any) */
91     void slotAddClipFile(const KUrl &url, const QMap<QString, QString> &data);
92
93     /** @brief Adds a list of files to the project.
94      * @param urls files to add
95      * @param group name of the group to insert the files in (can be empty)
96      * @param groupId id of the group (if any)
97      * It checks for duplicated items and asks to the user for instructions. */
98     void slotAddClipList(const KUrl::List &urls, const QMap<QString, QString> &data);
99     void slotAddTextClipFile(const QString &titleName, int out, const QString &xml, const QString &group, const QString &groupId);
100     void slotAddTextTemplateClip(QString titleName, const KUrl &path, const QString &group, const QString &groupId);
101     void slotAddXmlClipFile(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
102     void slotAddColorClipFile(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId);
103     void slotAddSlideshowClipFile(QMap <QString, QString> properties, const QString &group, const QString &groupId);
104     DocClipBase *getClipById(QString clipId);
105     const QList <DocClipBase *> getClipByResource(const QString &resource);
106     void slotDeleteClips(QStringList ids);
107     void setThumbsProgress(const QString &message, int progress);
108     void checkAudioThumbs();
109     QList <DocClipBase*> documentClipList() const;
110     QMap <QString, QString> documentFolderList() const;
111     int getFreeClipId();
112     int getFreeFolderId();
113     int lastClipId() const;
114     void askForAudioThumb(const QString &id);
115     QString projectFolder() const;
116     void clearUnusedProducers();
117     void resetProducersList(const QList <Mlt::Producer *> prods, bool displayRatioChanged, bool fpsChanged);
118     void addFolder(const QString&, const QString&);
119     void deleteFolder(const QString&);
120     void clear();
121     void clearCache();
122     AbstractGroupItem *createGroup();
123     void removeGroup(AbstractGroupItem *group);
124     QDomElement groupsXml() const;
125     int clipsCount() const;
126     /** @brief remove a clip id from the queue list. */
127     void stopThumbs(const QString &id);
128     void projectTreeThumbReady(const QString &id, int frame, const QImage &img, int type);
129
130 #if KDE_IS_VERSION(4,5,0)
131     KImageCache* pixmapCache;
132 #endif
133
134 public slots:
135     /** @brief Request creation of a clip thumbnail for specified frames. */
136     void slotRequestThumbs(const QString &id, const QList<int> &frames);
137     
138 private slots:
139     /** A clip was externally modified, monitor for more changes and prepare for reload */
140     void slotClipModified(const QString &path);
141     void slotClipMissing(const QString &path);
142     void slotClipAvailable(const QString &path);
143     /** Check the list of externally modified clips, and process them if they were not modified in the last 1500 milliseconds */
144     void slotProcessModifiedClips();
145     void slotGetThumbs();
146     void slotGetAudioThumbs();
147     /** @brief Clip has been copied, add it now. */
148     void slotAddClip(KIO::Job *job, const KUrl &, const KUrl &dst);
149
150 private:   // Private attributes
151     QGLWidget *m_mainGLContext;
152     /** the list of clips in the document */
153     QList <DocClipBase*> m_clipList;
154     /** the list of groups in the document */
155     QList <AbstractGroupItem *> m_groupsList;
156     QMap <QString, QString> m_folderList;
157     QList <QString> m_audioThumbsQueue;
158     /** the document undo stack*/
159     KdenliveDoc *m_doc;
160     int m_clipIdCounter;
161     int m_folderIdCounter;
162     KDirWatch m_fileWatcher;
163     /** Timer used to reload clips when they have been externally modified */
164     QTimer m_modifiedTimer;
165     /** List of the clip IDs that need to be reloaded after being externally modified */
166     QMap <QString, QTime> m_modifiedClips;
167     /** Struct containing the list of clip thumbnails to request (clip id and frames) */
168     QMap <QString, int> m_requestedThumbs;
169     QMutex m_thumbsMutex;
170     QFuture<void> m_thumbsThread;
171     /** @brief The id of currently processed clip for thumbs creation. */
172     QString m_processingThumbId;
173     /** @brief If true, abort processing of clip thumbs before removing a clip. */
174     bool m_abortThumb;
175     /** @brief We are about to delete the clip producer, stop processing thumbs. */
176     bool m_closing;
177     QFuture<void> m_audioThumbsThread;
178     /** @brief If true, abort processing of audio thumbs. */
179     bool m_abortAudioThumb;
180     /** @brief The id of currently processed clip for audio thumbs creation. */
181     QString m_processingAudioThumbId;
182     /** @brief The list of removable drives. */
183     QList<SolidVolumeInfo> m_removableVolumes;
184
185     QPoint m_projectTreeThumbSize;
186     
187     /** @brief Get a list of drives, to check if we have files on removable media. */
188     void listRemovableVolumes();
189     /** @brief Check if added file is on a removable drive. */
190     bool isOnRemovableDevice(const KUrl &url);
191
192 signals:
193     void reloadClip(const QString &);
194     void modifiedClip(const QString &);
195     void missingClip(const QString &);
196     void availableClip(const QString &);
197     void checkAllClips(bool displayRatioChanged, bool fpsChanged, const QStringList &brokenClips);
198     void displayMessage(const QString &, int);
199     void thumbReady(const QString &id, int, const QImage&);
200     void gotClipPropertyThumbnail(const QString &id, const QImage&);
201 };
202
203 #endif