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"
27 ClipManager::ClipManager(KdenliveDoc *doc):m_doc(doc)
32 ClipManager::~ClipManager()
36 void ClipManager::addClip(DocClipBase *clip)
38 m_clipList.append(clip);
41 void ClipManager::deleteClip(uint clipId)
43 for (int i = 0; i < m_clipList.count(); i++) {
44 if (m_clipList.at(i)->getId() == clipId)
45 m_clipList.removeAt(i);
49 DocClipBase *ClipManager::getClipAt(int pos)
51 return m_clipList.at(pos);
54 DocClipBase *ClipManager::getClipById(int clipId)
56 kDebug()<<"++++ CLIP MAN, LOOKING FOR CLIP ID: "<<clipId;
57 for (int i = 0; i < m_clipList.count(); i++) {
58 if (m_clipList.at(i)->getId() == clipId)
60 kDebug()<<"++++ CLIP MAN, FOUND FOR CLIP ID: "<<clipId;
61 return m_clipList.at(i);
67 void ClipManager::slotAddClipFile(const KUrl url, const QString group)
69 kDebug()<<"///// CLIP MANAGER, ADDING CLIP: "<<url;
71 QDomElement prod = doc.createElement("producer");
72 prod.setAttribute("resource", url.path());
73 uint id = m_clipIdCounter++;
74 prod.setAttribute("id", QString::number(id));
75 if (!group.isEmpty()) prod.setAttribute("group", group);
76 KMimeType::Ptr type = KMimeType::findByUrl(url);
77 if (type->name().startsWith("image/")) {
78 prod.setAttribute("type", (int) IMAGE);
79 prod.setAttribute("in", "0");
80 prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration()));
82 AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
83 m_doc->commandStack()->push(command);
86 void ClipManager::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group)
89 QDomElement prod = doc.createElement("producer");
90 prod.setAttribute("mlt_service", "colour");
91 prod.setAttribute("colour", color);
92 prod.setAttribute("type", (int) COLOR);
93 uint id = m_clipIdCounter++;
94 prod.setAttribute("id", QString::number(id));
95 prod.setAttribute("in", "0");
96 prod.setAttribute("out", m_doc->getFramePos(duration));
97 prod.setAttribute("name", name);
98 AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
99 m_doc->commandStack()->push(command);