1 /***************************************************************************
2 * Copyright (C) 2007 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 ***************************************************************************/
21 #include "projectitem.h"
23 #include "kdenlivesettings.h"
24 #include "docclipbase.h"
30 const int DurationRole = Qt::UserRole + 1;
31 const int ProxyRole = Qt::UserRole + 5;
32 const int itemHeight = 38;
34 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
35 QTreeWidgetItem(parent, PROJECTCLIPTYPE),
37 m_clipId(clip->getId())
42 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
43 QTreeWidgetItem(parent, PROJECTCLIPTYPE),
45 m_clipId(clip->getId())
51 void ProjectItem::buildItem()
53 setSizeHint(0, QSize(itemHeight * 3, itemHeight));
54 if (m_clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
55 else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
56 QString name = m_clip->getProperty("name");
57 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
58 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
60 setText(1, m_clip->description());
61 GenTime duration = m_clip->duration();
62 if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
65 ProjectItem::~ProjectItem()
70 int ProjectItem::itemDefaultHeight()
75 int ProjectItem::numReferences() const
77 if (!m_clip) return 0;
78 return m_clip->numReferences();
81 const QString &ProjectItem::clipId() const
86 CLIPTYPE ProjectItem::clipType() const
91 int ProjectItem::clipMaxDuration() const
93 return m_clip->getProperty("duration").toInt();
96 QStringList ProjectItem::names() const
99 result.append(text(0));
100 result.append(text(1));
101 result.append(text(2));
105 QDomElement ProjectItem::toXml() const
107 return m_clip->toXML();
110 const KUrl ProjectItem::clipUrl() const
112 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
113 return KUrl(m_clip->getProperty("resource"));
117 void ProjectItem::changeDuration(int frames)
119 setData(0, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
122 void ProjectItem::setProperties(QMap <QString, QString> props)
124 if (m_clip == NULL) return;
125 m_clip->setProperties(props);
128 QString ProjectItem::getClipHash() const
130 if (m_clip == NULL) return QString();
131 return m_clip->getClipHash();
134 void ProjectItem::setProperty(const QString &key, const QString &value)
136 if (m_clip == NULL) return;
137 m_clip->setProperty(key, value);
140 void ProjectItem::clearProperty(const QString &key)
142 if (m_clip == NULL) return;
143 m_clip->clearProperty(key);
146 DocClipBase *ProjectItem::referencedClip()
151 void ProjectItem::slotSetToolTip()
154 if (m_clip->isPlaceHolder()) tip.append(i18n("Missing") + " | ");
155 switch (m_clipType) {
157 tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
160 tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
163 tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
166 tip.append(i18n("Color clip"));
169 tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
172 if (!clipUrl().isEmpty() && m_clip->getProperty("xmldata").isEmpty()) tip.append(i18n("Template text clip") + "</b><br />" + clipUrl().path());
173 else tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
176 tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
179 tip.append(i18n("Virtual clip"));
182 tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
185 tip.append(i18n("Unknown clip"));
193 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
195 if (m_clip == NULL) return;
196 //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
197 if (attributes.contains("duration")) {
198 GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
199 setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
200 m_clip->setDuration(duration);
202 // No duration known, use an arbitrary one until it is.
206 //extend attributes -reh
208 if (m_clipType == UNKNOWN) {
209 QString cliptype = attributes.value("type");
210 if (cliptype == "audio") m_clipType = AUDIO;
211 else if (cliptype == "video") m_clipType = VIDEO;
212 else if (cliptype == "av") m_clipType = AV;
213 else if (cliptype == "playlist") m_clipType = PLAYLIST;
214 else m_clipType = AV;
216 m_clip->setClipType(m_clipType);
219 m_clip->setProperties(attributes);
220 m_clip->setMetadata(metadata);
222 if (m_clip->description().isEmpty()) {
223 if (metadata.contains("description")) {
224 m_clip->setProperty("description", metadata.value("description"));
225 setText(1, m_clip->description());
226 } else if (metadata.contains("comment")) {
227 m_clip->setProperty("description", metadata.value("comment"));
228 setText(1, m_clip->description());
233 void ProjectItem::setProxyStatus(PROXYSTATUS status)
235 setData(0, ProxyRole, status);
238 bool ProjectItem::hasProxy() const
240 if (m_clip == NULL) return false;
241 if (m_clip->getProperty("proxy").isEmpty() || m_clip->getProperty("proxy") == "-" || data(0, ProxyRole).toInt() == PROXYCRASHED) return false;
245 bool ProjectItem::isProxyReady() const
247 return (data(0, ProxyRole).toInt() == PROXYDONE);
250 bool ProjectItem::isProxyRunning() const
252 PROXYSTATUS s = (PROXYSTATUS) data(0, ProxyRole).toInt();
253 if (s == PROXYWAITING || s == CREATINGPROXY) return true;