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"
31 const int NameRole = Qt::UserRole;
32 const int DurationRole = NameRole + 1;
33 const int UsageRole = NameRole + 2;
37 ProjectItem::ProjectItem(QTreeWidget * parent, const QStringList & strings, const QString &clipId) :
38 QTreeWidgetItem(parent, strings),
39 m_groupname(strings.at(1)),
44 setSizeHint(0, QSize(65, 45));
45 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
46 setIcon(0, KIcon("folder"));
47 setToolTip(1, "<b>" + i18n("Folder"));
48 //kDebug() << "Constructed as folder, with clipId: " << m_clipId << ", and groupname: " << m_groupname;
51 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
52 QTreeWidgetItem(parent)
54 setSizeHint(0, QSize(65, 45));
55 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
57 m_clipId = clip->getId();
58 QString name = m_clip->getProperty("name");
59 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
60 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
61 if (m_clipType != UNKNOWN) slotSetToolTip();
63 setText(2, m_clip->description());
64 if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
65 GenTime duration = m_clip->duration();
66 if (duration != GenTime()) setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
67 //setFlags(Qt::NoItemFlags);
68 //kDebug() << "Constructed with clipId: " << m_clipId;
71 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
72 QTreeWidgetItem(parent)
74 setSizeHint(0, QSize(65, 45));
75 setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
77 m_clipId = clip->getId();
78 QString name = m_clip->getProperty("name");
79 if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
80 m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
82 setText(2, m_clip->description());
83 if ((m_clip->clipType() == AV || m_clip->clipType() == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
84 GenTime duration = m_clip->duration();
85 if (duration != GenTime()) setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
86 //setFlags(Qt::NoItemFlags);
87 //kDebug() << "Constructed with clipId: " << m_clipId;
91 ProjectItem::~ProjectItem()
95 int ProjectItem::numReferences() const
97 if (!m_clip) return 0;
98 return m_clip->numReferences();
101 const QString &ProjectItem::clipId() const
106 CLIPTYPE ProjectItem::clipType() const
111 int ProjectItem::clipMaxDuration() const
113 return m_clip->getProperty("duration").toInt();
116 bool ProjectItem::isGroup() const
118 return m_clipType == FOLDER;
121 QStringList ProjectItem::names() const
124 result.append(text(0));
125 result.append(text(1));
126 result.append(text(2));
130 QDomElement ProjectItem::toXml() const
132 return m_clip->toXML();
135 const KUrl ProjectItem::clipUrl() const
137 if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN && m_clipType != FOLDER)
138 return KUrl(m_clip->getProperty("resource"));
142 void ProjectItem::changeDuration(int frames)
144 setData(1, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
147 void ProjectItem::setProperties(QMap <QString, QString> props)
149 if (m_clip == NULL) return;
150 m_clip->setProperties(props);
153 QString ProjectItem::getClipHash() const
155 if (m_clip == NULL) return QString();
156 return m_clip->getClipHash();
159 void ProjectItem::setProperty(const QString &key, const QString &value)
161 if (m_clip == NULL) return;
162 m_clip->setProperty(key, value);
165 void ProjectItem::clearProperty(const QString &key)
167 if (m_clip == NULL) return;
168 m_clip->clearProperty(key);
171 const QString ProjectItem::groupName() const
176 void ProjectItem::setGroupName(const QString name)
182 DocClipBase *ProjectItem::referencedClip()
187 void ProjectItem::slotSetToolTip()
190 switch (m_clipType) {
192 tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
195 tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
198 tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
201 tip.append(i18n("Color clip"));
204 tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
207 tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
210 tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
213 tip.append(i18n("Virtual clip"));
216 tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
219 tip.append(i18n("Unknown clip"));
227 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
229 if (m_clip == NULL) return;
230 //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
231 if (attributes.contains("duration")) {
232 GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
233 setData(1, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
234 m_clip->setDuration(duration);
235 //kDebug() << "//// LOADED CLIP, DURATIONĂ‚Â SET TO: " << duration.frames(KdenliveSettings::project_fps());
237 // No duration known, use an arbitrary one until it is.
241 //extend attributes -reh
243 if (m_clipType == UNKNOWN) {
244 QString cliptype = attributes.value("type");
245 if (cliptype == "audio") m_clipType = AUDIO;
246 else if (cliptype == "video") m_clipType = VIDEO;
247 else if (cliptype == "av") m_clipType = AV;
248 else if (cliptype == "playlist") m_clipType = PLAYLIST;
249 else m_clipType = AV;
251 m_clip->setClipType(m_clipType);
254 m_clip->setProperties(attributes);
255 m_clip->setMetadata(metadata);
256 if ((m_clipType == AV || m_clipType == AUDIO) && KdenliveSettings::audiothumbnails()) m_clip->askForAudioThumbs();
258 if (m_clip->description().isEmpty()) {
259 if (metadata.contains("description")) {
260 m_clip->setProperty("description", metadata.value("description"));
261 setText(2, m_clip->description());
262 } else if (metadata.contains("comment")) {
263 m_clip->setProperty("description", metadata.value("comment"));
264 setText(2, m_clip->description());