]> git.sesse.net Git - kdenlive/blob - src/clipmanager.cpp
Title clips now really usable (only transparency & duration change still missing)
[kdenlive] / src / clipmanager.cpp
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 #include <KDebug>
20 #include <KFileDialog>
21
22 #include "addclipcommand.h"
23 #include "kdenlivesettings.h"
24 #include "clipmanager.h"
25 #include "docclipbase.h"
26 #include "kdenlivedoc.h"
27
28 ClipManager::ClipManager(KdenliveDoc *doc): m_doc(doc) {
29     m_clipIdCounter = 1;
30     m_audioThumbsEnabled = KdenliveSettings::audiothumbnails();
31 }
32
33 ClipManager::~ClipManager() {
34 }
35
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();
42     }
43 }
44
45 void ClipManager::setThumbsProgress(KUrl url, int progress) {
46     m_doc->setThumbsProgress(url, progress);
47 }
48
49 QList <DocClipBase*> ClipManager::documentClipList() {
50     return m_clipList;
51 }
52
53 void ClipManager::addClip(DocClipBase *clip) {
54     m_clipList.append(clip);
55 }
56
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             AddClipCommand *command = new AddClipCommand(m_doc, m_clipList.at(i)->toXML(), clipId, false);
61             m_doc->commandStack()->push(command);
62             break;
63         }
64     }
65 }
66
67 void ClipManager::deleteClip(uint clipId) {
68     for (int i = 0; i < m_clipList.count(); i++) {
69         if (m_clipList.at(i)->getId() == clipId) {
70             m_clipList.removeAt(i);
71             break;
72         }
73     }
74 }
75
76 DocClipBase *ClipManager::getClipAt(int pos) {
77     return m_clipList.at(pos);
78 }
79
80 DocClipBase *ClipManager::getClipById(int clipId) {
81     kDebug() << "++++  CLIP MAN, LOOKING FOR CLIP ID: " << clipId;
82     for (int i = 0; i < m_clipList.count(); i++) {
83         if (m_clipList.at(i)->getId() == clipId) {
84             kDebug() << "++++  CLIP MAN, FOUND FOR CLIP ID: " << clipId;
85             return m_clipList.at(i);
86         }
87     }
88     return NULL;
89 }
90
91 void ClipManager::slotAddClipFile(const KUrl url, const QString group, const int groupId) {
92     kDebug() << "/////  CLIP MANAGER, ADDING CLIP: " << url;
93     QDomDocument doc;
94     QDomElement prod = doc.createElement("producer");
95     prod.setAttribute("resource", url.path());
96     uint id = m_clipIdCounter++;
97     prod.setAttribute("id", QString::number(id));
98     if (!group.isEmpty()) {
99         prod.setAttribute("groupname", group);
100         prod.setAttribute("groupid", groupId);
101     }
102     KMimeType::Ptr type = KMimeType::findByUrl(url);
103     if (type->name().startsWith("image/")) {
104         prod.setAttribute("type", (int) IMAGE);
105         prod.setAttribute("in", "0");
106         prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration()));
107     }
108     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
109     m_doc->commandStack()->push(command);
110 }
111
112 void ClipManager::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const int groupId) {
113     QDomDocument doc;
114     QDomElement prod = doc.createElement("producer");
115     prod.setAttribute("mlt_service", "colour");
116     prod.setAttribute("colour", color);
117     prod.setAttribute("type", (int) COLOR);
118     uint id = m_clipIdCounter++;
119     prod.setAttribute("id", QString::number(id));
120     prod.setAttribute("in", "0");
121     prod.setAttribute("out", m_doc->getFramePos(duration));
122     prod.setAttribute("name", name);
123     if (!group.isEmpty()) {
124         prod.setAttribute("groupname", group);
125         prod.setAttribute("groupid", groupId);
126     }
127     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
128     m_doc->commandStack()->push(command);
129 }
130
131
132
133 void ClipManager::slotAddTextClipFile(const QString path, const QString group, const int groupId) {
134     kDebug() << "/////  CLIP MANAGER, ADDING CLIP: " << path;
135     QDomDocument doc;
136     QDomElement prod = doc.createElement("producer");
137     prod.setAttribute("resource", path + ".png");
138     prod.setAttribute("xml", path);
139     uint id = m_clipIdCounter++;
140     prod.setAttribute("id", QString::number(id));
141     if (!group.isEmpty()) {
142         prod.setAttribute("groupname", group);
143         prod.setAttribute("groupid", groupId);
144     }
145     prod.setAttribute("type", (int) TEXT);
146     prod.setAttribute("in", "0");
147     prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration()));
148     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
149     m_doc->commandStack()->push(command);
150 }
151
152 int ClipManager::getFreeClipId() {
153     return m_clipIdCounter++;
154 }
155
156