]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
Fetch audio thumbs one after another, so that we don't create hundreds of threads:
[kdenlive] / src / projectitem.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 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
20
21 #include "projectitem.h"
22 #include "timecode.h"
23 #include "kdenlivesettings.h"
24 #include "docclipbase.h"
25
26 #include <KDebug>
27 #include <KLocale>
28 #include <KIcon>
29
30 const int DurationRole = Qt::UserRole + 1;
31 const int itemHeight = 38;
32
33 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
34         QTreeWidgetItem(parent, PROJECTCLIPTYPE)
35 {
36     setSizeHint(0, QSize(itemHeight * 3, itemHeight));
37     if (clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
38     else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
39     m_clip = clip;
40     m_clipId = clip->getId();
41     QString name = m_clip->getProperty("name");
42     if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
43     m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
44     if (m_clipType != UNKNOWN) slotSetToolTip();
45     setText(0, name);
46     setText(1, m_clip->description());
47     GenTime duration = m_clip->duration();
48     if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
49     //setFlags(Qt::NoItemFlags);
50     //kDebug() << "Constructed with clipId: " << m_clipId;
51 }
52
53 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
54         QTreeWidgetItem(parent, PROJECTCLIPTYPE)
55 {
56     setSizeHint(0, QSize(itemHeight * 3, itemHeight));
57     if (clip->isPlaceHolder()) setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
58     else setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
59     m_clip = clip;
60     m_clipId = clip->getId();
61     QString name = m_clip->getProperty("name");
62     if (name.isEmpty()) name = KUrl(m_clip->getProperty("resource")).fileName();
63     m_clipType = (CLIPTYPE) m_clip->getProperty("type").toInt();
64     setText(0, name);
65     setText(1, m_clip->description());
66     GenTime duration = m_clip->duration();
67     if (duration != GenTime()) setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
68     //setFlags(Qt::NoItemFlags);
69     //kDebug() << "Constructed with clipId: " << m_clipId;
70 }
71
72
73 ProjectItem::~ProjectItem()
74 {
75 }
76
77 //static
78 int ProjectItem::itemDefaultHeight()
79 {
80     return itemHeight;
81 }
82
83 int ProjectItem::numReferences() const
84 {
85     if (!m_clip) return 0;
86     return m_clip->numReferences();
87 }
88
89 const QString &ProjectItem::clipId() const
90 {
91     return m_clipId;
92 }
93
94 CLIPTYPE ProjectItem::clipType() const
95 {
96     return m_clipType;
97 }
98
99 int ProjectItem::clipMaxDuration() const
100 {
101     return m_clip->getProperty("duration").toInt();
102 }
103
104 QStringList ProjectItem::names() const
105 {
106     QStringList result;
107     result.append(text(0));
108     result.append(text(1));
109     result.append(text(2));
110     return result;
111 }
112
113 QDomElement ProjectItem::toXml() const
114 {
115     return m_clip->toXML();
116 }
117
118 const KUrl ProjectItem::clipUrl() const
119 {
120     if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
121         return KUrl(m_clip->getProperty("resource"));
122     else return KUrl();
123 }
124
125 void ProjectItem::changeDuration(int frames)
126 {
127     setData(0, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
128 }
129
130 void ProjectItem::setProperties(QMap <QString, QString> props)
131 {
132     if (m_clip == NULL) return;
133     m_clip->setProperties(props);
134 }
135
136 QString ProjectItem::getClipHash() const
137 {
138     if (m_clip == NULL) return QString();
139     return m_clip->getClipHash();
140 }
141
142 void ProjectItem::setProperty(const QString &key, const QString &value)
143 {
144     if (m_clip == NULL) return;
145     m_clip->setProperty(key, value);
146 }
147
148 void ProjectItem::clearProperty(const QString &key)
149 {
150     if (m_clip == NULL) return;
151     m_clip->clearProperty(key);
152 }
153
154 DocClipBase *ProjectItem::referencedClip()
155 {
156     return m_clip;
157 }
158
159 void ProjectItem::slotSetToolTip()
160 {
161     QString tip = "<b>";
162     if (m_clip->isPlaceHolder()) tip.append(i18n("Missing") + " | ");
163     switch (m_clipType) {
164     case AUDIO:
165         tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
166         break;
167     case VIDEO:
168         tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
169         break;
170     case AV:
171         tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
172         break;
173     case COLOR:
174         tip.append(i18n("Color clip"));
175         break;
176     case IMAGE:
177         tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
178         break;
179     case TEXT:
180         if (!clipUrl().isEmpty() && m_clip->getProperty("xmldata").isEmpty()) tip.append(i18n("Template text clip") + "</b><br />" + clipUrl().path());
181         else tip.append(i18n("Text clip") + "</b><br />" + clipUrl().path());
182         break;
183     case SLIDESHOW:
184         tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
185         break;
186     case VIRTUAL:
187         tip.append(i18n("Virtual clip"));
188         break;
189     case PLAYLIST:
190         tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
191         break;
192     default:
193         tip.append(i18n("Unknown clip"));
194         break;
195     }
196
197     setToolTip(0, tip);
198 }
199
200
201 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
202 {
203     if (m_clip == NULL) return;
204     //setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
205     if (attributes.contains("duration")) {
206         GenTime duration = GenTime(attributes.value("duration").toInt(), KdenliveSettings::project_fps());
207         setData(0, DurationRole, Timecode::getEasyTimecode(duration, KdenliveSettings::project_fps()));
208         m_clip->setDuration(duration);
209     } else  {
210         // No duration known, use an arbitrary one until it is.
211     }
212
213
214     //extend attributes -reh
215
216     if (m_clipType == UNKNOWN) {
217         QString cliptype = attributes.value("type");
218         if (cliptype == "audio") m_clipType = AUDIO;
219         else if (cliptype == "video") m_clipType = VIDEO;
220         else if (cliptype == "av") m_clipType = AV;
221         else if (cliptype == "playlist") m_clipType = PLAYLIST;
222         else m_clipType = AV;
223
224         m_clip->setClipType(m_clipType);
225         slotSetToolTip();
226     }
227     m_clip->setProperties(attributes);
228     m_clip->setMetadata(metadata);
229
230     if (m_clip->description().isEmpty()) {
231         if (metadata.contains("description")) {
232             m_clip->setProperty("description", metadata.value("description"));
233             setText(1, m_clip->description());
234         } else if (metadata.contains("comment")) {
235             m_clip->setProperty("description", metadata.value("comment"));
236             setText(1, m_clip->description());
237         }
238     }
239 }
240