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;
33 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, const QString &clipId) :
34 QTreeWidgetItem(parent, strings),
35 m_groupname(strings.at(1)),
40 setSizeHint(0, QSize(65, 45));
41 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
42 setIcon(0, KIcon("folder"));
43 setToolTip(1, "<b>" + i18n("Folder"));
44 //kDebug() << "Constructed as folder, with clipId: " << m_clipId << ", and groupname: " << m_groupname;
47 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
48 QTreeWidgetItem(parent)
50 setSizeHint(0, QSize(65, 45));
51 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
53 m_clipId = clip->getId();
54 QString name = m_clip->getProperty("name");
55 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
56 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
57 if (m_clipType != UNKNOWN) slotSetToolTip();
59 setText(2, m_clip->description());
60 if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
61 GenTime duration = m_clip->duration();
62 if (duration != GenTime()) setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
63 //setFlags(Qt::NoItemFlags);
64 //kDebug() << "Constructed with clipId: " << m_clipId;
67 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
68 QTreeWidgetItem(parent)
70 setSizeHint(0, QSize(65, 45));
71 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
73 m_clipId = clip->getId();
74 QString name = m_clip->getProperty("name");
75 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
76 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
78 setText(2, m_clip->description());
79 if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
80 GenTime duration = m_clip->duration();
81 if (duration != GenTime()) setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
82 //setFlags(Qt::NoItemFlags);
83 //kDebug() << "Constructed with clipId: " << m_clipId;
87 ProjectItem::~ProjectItem()
91 int ProjectItem::numReferences() const
93 if (!m_clip) return 0;
94 return m_clip->numReferences();
97 const QString &ProjectItem::clipId() const
102 CLIPTYPE ProjectItem::clipType() const
107 int ProjectItem::clipMaxDuration() const
109 return m_clip->getProperty("duration").toInt();
112 bool ProjectItem::isGroup() const
114 return m_clipType == FOLDER;
117 QStringList ProjectItem::names() const
120 result.append(text(0));
121 result.append(text(1));
122 result.append(text(2));
126 QDomElement ProjectItem::toXml() const
128 return m_clip->toXML();
131 const KUrl ProjectItem::clipUrl() const
133 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN && m_clipType != FOLDER)
134 return KUrl(m_clip->getProperty("resource"));
138 void ProjectItem::changeDuration(int frames)
140 setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
143 void ProjectItem::setProperties(QMap <QString, QString> props)
145 if (m_clip == NULL) return;
146 m_clip->setProperties(props);
149 QString ProjectItem::getClipHash() const
151 if (m_clip == NULL) return QString();
152 return m_clip->getClipHash();
155 void ProjectItem::setProperty(const QString &key, const QString &value)
157 if (m_clip == NULL) return;
158 m_clip->setProperty(key, value);
161 void ProjectItem::clearProperty(const QString &key)
163 if (m_clip == NULL) return;
164 m_clip->clearProperty(key);
167 const QString ProjectItem::groupName() const
172 void ProjectItem::setGroupName(const QString name)
178 DocClipBase *ProjectItem::referencedClip()
183 void ProjectItem::slotSetToolTip()
186 switch (m_clipType) {
188 tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
191 tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
194 tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
197 tip.append(i18n("Color clip"));
200 tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
203 if (!clipUrl().isEmpty() && m_clip->getProperty("xmldata").isEmpty()) tip.append(i18n("Template text clip") + "</b><br />" + clipUrl().path());
204 else tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
207 tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
210 tip.append(i18n("Virtual clip"));
213 tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
216 tip.append(i18n("Unknown clip"));
224 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
226 if (m_clip == NULL) return;
227 //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
228 if (attributes.contains("duration")) {
229 GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
230 setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
231 m_clip->setDuration(duration);
232 //kDebug() << "//// LOADED CLIP, DURATIONĂ‚Â SET TO: " << duration.frames(KdenliveSettings::project_fps());
234 // No duration known, use an arbitrary one until it is.
238 //extend attributes -reh
240 if (m_clipType == UNKNOWN) {
241 QString cliptype = attributes.value("type");
242 if (cliptype == "audio") m_clipType = AUDIO;
243 else if (cliptype == "video") m_clipType = VIDEO;
244 else if (cliptype == "av") m_clipType = AV;
245 else if (cliptype == "playlist") m_clipType = PLAYLIST;
246 else m_clipType = AV;
248 m_clip->setClipType(m_clipType);
251 m_clip->setProperties(attributes);
252 m_clip->setMetadata(metadata);
253 if ((m_clipType == AV || m_clipType == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
255 if (m_clip->description().isEmpty()) {
256 if (metadata.contains("description")) {
257 m_clip->setProperty("description", metadata.value("description"));
258 setText(2, m_clip->description());
259 } else if (metadata.contains("comment")) {
260 m_clip->setProperty("description", metadata.value("comment"));
261 setText(2, m_clip->description());