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"
32 const int DurationRole = Qt::UserRole + 1;
33 const int JobProgressRole = Qt::UserRole + 5;
34 const int JobTypeRole = Qt::UserRole + 6;
35 const int JobStatusMessage = Qt::UserRole + 7;
36 const int itemHeight = 38;
38 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
39 QTreeWidgetItem(parent, PROJECTCLIPTYPE),
41 m_clipId(clip->getId())
46 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
47 QTreeWidgetItem(parent, PROJECTCLIPTYPE),
49 m_clipId(clip->getId())
55 void ProjectItem::buildItem()
57 setSizeHint(0, QSize(itemHeight * 3, itemHeight));
58 if (m_clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
59 else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
60 QString name = m_clip->getProperty("name");
61 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
62 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
64 setText(1, m_clip->description());
65 GenTime duration = m_clip->duration();
67 if (duration != GenTime()) {
68 durationText = Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps());
70 if (m_clipType == PLAYLIST) {
71 // Check if the playlist xml contains a proxy inside, and inform user
72 if (playlistHasProxies(m_clip->fileURL().path())) {
73 durationText.prepend(i18n("Contains proxies") + " / ");
76 if (!durationText.isEmpty()) setData(0, DurationRole, durationText);
79 ProjectItem::~ProjectItem()
84 int ProjectItem::itemDefaultHeight()
89 int ProjectItem::numReferences() const
91 if (!m_clip) return 0;
92 return m_clip->numReferences();
95 const QString &ProjectItem::clipId() const
100 CLIPTYPE ProjectItem::clipType() const
105 int ProjectItem::clipMaxDuration() const
107 return m_clip->getProperty("duration").toInt();
110 QStringList ProjectItem::names() const
113 result.append(text(0));
114 result.append(text(1));
115 result.append(text(2));
119 QDomElement ProjectItem::toXml() const
121 return m_clip->toXML();
124 const KUrl ProjectItem::clipUrl() const
126 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
127 return KUrl(m_clip->getProperty("resource"));
131 void ProjectItem::changeDuration(int frames)
133 QString itemdata = data(0, DurationRole).toString();
134 if (itemdata.contains('/')) itemdata = itemdata.section('/', 0, 0) + "/ ";
135 else itemdata.clear();
136 setData(0, DurationRole, itemdata + Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
139 void ProjectItem::setProperties(QMap <QString, QString> props)
141 if (m_clip == NULL) return;
142 m_clip->setProperties(props);
145 QString ProjectItem::getClipHash() const
147 if (m_clip == NULL) return QString();
148 return m_clip->getClipHash();
151 void ProjectItem::setProperty(const QString &key, const QString &value)
153 if (m_clip == NULL) return;
154 m_clip->setProperty(key, value);
157 void ProjectItem::clearProperty(const QString &key)
159 if (m_clip == NULL) return;
160 m_clip->clearProperty(key);
163 DocClipBase *ProjectItem::referencedClip()
168 void ProjectItem::slotSetToolTip()
171 if (m_clip->isPlaceHolder()) tip.append(i18n("Missing") + " | ");
172 QString jobInfo = data(0, JobStatusMessage).toString();
173 if (!jobInfo.isEmpty()) {
174 tip.append(jobInfo + " | ");
176 if (hasProxy() && data(0, JobTypeRole).toInt() != PROXYJOB) {
177 tip.append(i18n("Proxy clip") + " | ");
180 switch (m_clipType) {
182 tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
185 tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
188 tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
191 tip.append(i18n("Color clip"));
194 tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
197 if (!clipUrl().isEmpty() && m_clip->getProperty("xmldata").isEmpty()) tip.append(i18n("Template text clip") + "</b><br />" + clipUrl().path());
198 else tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
201 tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
204 tip.append(i18n("Virtual clip"));
207 tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
210 tip.append(i18n("Unknown clip"));
217 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
219 if (m_clip == NULL) return;
222 if (m_clipType == UNKNOWN) {
223 QString cliptype = attributes.value("type");
224 if (cliptype == "audio") m_clipType = AUDIO;
225 else if (cliptype == "video") m_clipType = VIDEO;
226 else if (cliptype == "av") m_clipType = AV;
227 else if (cliptype == "playlist") m_clipType = PLAYLIST;
228 else m_clipType = AV;
230 m_clip->setClipType(m_clipType);
232 if (m_clipType == PLAYLIST) {
233 // Check if the playlist xml contains a proxy inside, and inform user
234 if (playlistHasProxies(m_clip->fileURL().path())) {
235 prefix = i18n("Contains proxies") + " / ";
239 if (attributes.contains("duration")) {
240 GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
241 QString itemdata = data(0, DurationRole).toString();
242 if (itemdata.contains('/')) itemdata = itemdata.section('/', 0, 0) + "/ ";
243 else itemdata.clear();
244 if (prefix.isEmpty()) prefix = itemdata;
245 setData(0, DurationRole, prefix + Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
246 m_clip->setDuration(duration);
248 // No duration known, use an arbitrary one until it is.
251 m_clip->setProperties(attributes);
252 m_clip->setMetadata(metadata);
254 if (m_clip->description().isEmpty()) {
255 if (metadata.contains("description")) {
256 m_clip->setProperty("description", metadata.value("description"));
257 setText(1, m_clip->description());
258 } else if (metadata.contains("comment")) {
259 m_clip->setProperty("description", metadata.value("comment"));
260 setText(1, m_clip->description());
265 void ProjectItem::setJobStatus(JOBTYPE jobType, CLIPJOBSTATUS status, int progress, const QString &statusMessage)
267 setData(0, JobTypeRole, jobType);
268 if (progress > 0) setData(0, JobProgressRole, progress);
270 setData(0, JobProgressRole, status);
271 setData(0, JobStatusMessage, statusMessage);
276 void ProjectItem::setConditionalJobStatus(CLIPJOBSTATUS status, JOBTYPE requestedJobType)
278 if (data(0, JobTypeRole).toInt() == requestedJobType) {
279 setData(0, JobProgressRole, status);
283 bool ProjectItem::hasProxy() const
285 if (m_clip == NULL) return false;
286 if (m_clip->getProperty("proxy").size() < 2 || data(0, JobProgressRole).toInt() == JOBCRASHED) return false;
290 bool ProjectItem::isProxyReady() const
292 return (data(0, JobProgressRole).toInt() == JOBDONE);
295 bool ProjectItem::isJobRunning() const
297 int s = data(0, JobProgressRole).toInt();
298 if (s == JOBWAITING || s == JOBWORKING || s > 0) return true;
302 bool ProjectItem::isProxyRunning() const
304 int s = data(0, JobProgressRole).toInt();
305 if ((s == JOBWORKING || s > 0) && data(0, JobTypeRole).toInt() == (int) PROXYJOB) return true;
309 bool ProjectItem::playlistHasProxies(const QString path)
311 kDebug()<<"// CHECKING FOR PROXIES";
314 if (!file.open(QIODevice::ReadOnly))
316 if (!doc.setContent(&file)) {
321 QString root = doc.documentElement().attribute("root");
322 QDomNodeList kdenliveProducers = doc.elementsByTagName("kdenlive_producer");
323 for (int i = 0; i < kdenliveProducers.count(); i++) {
324 QString proxy = kdenliveProducers.at(i).toElement().attribute("proxy");
325 if (!proxy.isEmpty() && proxy != "-") return true;