1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
20 #include <KFileDialog>
22 #include "addclipcommand.h"
23 #include "kdenlivesettings.h"
24 #include "clipmanager.h"
25 #include "docclipbase.h"
26 #include "kdenlivedoc.h"
28 ClipManager::ClipManager(KdenliveDoc *doc): m_doc(doc) {
30 m_audioThumbsEnabled = KdenliveSettings::audiothumbnails();
33 ClipManager::~ClipManager() {
36 void ClipManager::checkAudioThumbs() {
37 if (m_audioThumbsEnabled == KdenliveSettings::audiothumbnails()) return;
38 m_audioThumbsEnabled = KdenliveSettings::audiothumbnails();
39 for (int i = 0; i < m_clipList.count(); i++) {
40 if (m_audioThumbsEnabled) m_clipList.at(i)->slotRequestAudioThumbs();
41 else m_clipList.at(i)->slotClearAudioCache();
45 void ClipManager::setThumbsProgress(KUrl url, int progress) {
46 m_doc->setThumbsProgress(url, progress);
49 QList <DocClipBase*> ClipManager::documentClipList() {
53 void ClipManager::addClip(DocClipBase *clip) {
54 m_clipList.append(clip);
57 void ClipManager::slotDeleteClip(uint clipId) {
58 for (int i = 0; i < m_clipList.count(); i++) {
59 if (m_clipList.at(i)->getId() == clipId) {
60 //m_clipList.removeAt(i);
61 AddClipCommand *command = new AddClipCommand(m_doc, m_clipList.at(i)->toXML(), clipId, false);
62 m_doc->commandStack()->push(command);
68 void ClipManager::deleteClip(uint clipId) {
69 for (int i = 0; i < m_clipList.count(); i++) {
70 if (m_clipList.at(i)->getId() == clipId) {
71 m_clipList.removeAt(i);
77 DocClipBase *ClipManager::getClipAt(int pos) {
78 return m_clipList.at(pos);
81 DocClipBase *ClipManager::getClipById(int clipId) {
82 kDebug() << "++++ CLIP MAN, LOOKING FOR CLIP ID: " << clipId;
83 for (int i = 0; i < m_clipList.count(); i++) {
84 if (m_clipList.at(i)->getId() == clipId) {
85 kDebug() << "++++ CLIP MAN, FOUND FOR CLIP ID: " << clipId;
86 return m_clipList.at(i);
92 void ClipManager::slotAddClipFile(const KUrl url, const QString group) {
93 kDebug() << "///// CLIP MANAGER, ADDING CLIP: " << url;
95 QDomElement prod = doc.createElement("producer");
96 prod.setAttribute("resource", url.path());
97 uint id = m_clipIdCounter++;
98 prod.setAttribute("id", QString::number(id));
99 if (!group.isEmpty()) prod.setAttribute("group", group);
100 KMimeType::Ptr type = KMimeType::findByUrl(url);
101 if (type->name().startsWith("image/")) {
102 prod.setAttribute("type", (int) IMAGE);
103 prod.setAttribute("in", "0");
104 prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration()));
106 AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
107 m_doc->commandStack()->push(command);
110 void ClipManager::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) {
112 QDomElement prod = doc.createElement("producer");
113 prod.setAttribute("mlt_service", "colour");
114 prod.setAttribute("colour", color);
115 prod.setAttribute("type", (int) COLOR);
116 uint id = m_clipIdCounter++;
117 prod.setAttribute("id", QString::number(id));
118 prod.setAttribute("in", "0");
119 prod.setAttribute("out", m_doc->getFramePos(duration));
120 prod.setAttribute("name", name);
121 AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
122 m_doc->commandStack()->push(command);