]> git.sesse.net Git - kdenlive/blob - src/clipmanager.cpp
Reindent all source files
[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
27 ClipManager::ClipManager(KdenliveDoc *doc): m_doc(doc) {
28     m_clipIdCounter = 1;
29 }
30
31 ClipManager::~ClipManager() {
32 }
33
34 void ClipManager::setThumbsProgress(KUrl url, int progress) {
35     m_doc->setThumbsProgress(url, progress);
36 }
37
38
39 void ClipManager::addClip(DocClipBase *clip) {
40     m_clipList.append(clip);
41 }
42
43 void ClipManager::slotDeleteClip(uint clipId) {
44     for (int i = 0; i < m_clipList.count(); i++) {
45         if (m_clipList.at(i)->getId() == clipId) {
46             //m_clipList.removeAt(i);
47             AddClipCommand *command = new AddClipCommand(m_doc, m_clipList.at(i)->toXML(), clipId, false);
48             m_doc->commandStack()->push(command);
49             break;
50         }
51     }
52 }
53
54 void ClipManager::deleteClip(uint clipId) {
55     for (int i = 0; i < m_clipList.count(); i++) {
56         if (m_clipList.at(i)->getId() == clipId) {
57             m_clipList.removeAt(i);
58             break;
59         }
60     }
61 }
62
63 DocClipBase *ClipManager::getClipAt(int pos) {
64     return m_clipList.at(pos);
65 }
66
67 DocClipBase *ClipManager::getClipById(int clipId) {
68     kDebug() << "++++  CLIP MAN, LOOKING FOR CLIP ID: " << clipId;
69     for (int i = 0; i < m_clipList.count(); i++) {
70         if (m_clipList.at(i)->getId() == clipId) {
71             kDebug() << "++++  CLIP MAN, FOUND FOR CLIP ID: " << clipId;
72             return m_clipList.at(i);
73         }
74     }
75     return NULL;
76 }
77
78 void ClipManager::slotAddClipFile(const KUrl url, const QString group) {
79     kDebug() << "/////  CLIP MANAGER, ADDING CLIP: " << url;
80     QDomDocument doc;
81     QDomElement prod = doc.createElement("producer");
82     prod.setAttribute("resource", url.path());
83     uint id = m_clipIdCounter++;
84     prod.setAttribute("id", QString::number(id));
85     if (!group.isEmpty()) prod.setAttribute("group", group);
86     KMimeType::Ptr type = KMimeType::findByUrl(url);
87     if (type->name().startsWith("image/")) {
88         prod.setAttribute("type", (int) IMAGE);
89         prod.setAttribute("in", "0");
90         prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration()));
91     }
92     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
93     m_doc->commandStack()->push(command);
94 }
95
96 void ClipManager::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) {
97     QDomDocument doc;
98     QDomElement prod = doc.createElement("producer");
99     prod.setAttribute("mlt_service", "colour");
100     prod.setAttribute("colour", color);
101     prod.setAttribute("type", (int) COLOR);
102     uint id = m_clipIdCounter++;
103     prod.setAttribute("id", QString::number(id));
104     prod.setAttribute("in", "0");
105     prod.setAttribute("out", m_doc->getFramePos(duration));
106     prod.setAttribute("name", name);
107     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
108     m_doc->commandStack()->push(command);
109 }
110