]> git.sesse.net Git - kdenlive/blob - src/projectitem.cpp
Big update to the proxy clips, fixing several issues. They can now be deleted in...
[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 ProxyRole = Qt::UserRole + 5;
32 const int itemHeight = 38;
33
34 ProjectItem::ProjectItem(QTreeWidget * parent, DocClipBase *clip) :
35         QTreeWidgetItem(parent, PROJECTCLIPTYPE),
36         m_clip(clip),
37         m_clipId(clip->getId())
38 {
39     buildItem();
40 }
41
42 ProjectItem::ProjectItem(QTreeWidgetItem * parent, DocClipBase *clip) :
43         QTreeWidgetItem(parent, PROJECTCLIPTYPE),
44         m_clip(clip),
45         m_clipId(clip->getId())
46         
47 {
48     buildItem();
49 }
50
51 void ProjectItem::buildItem()
52 {
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();
59     setText(0, name);
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()));
63 }
64
65 ProjectItem::~ProjectItem()
66 {
67 }
68
69 //static
70 int ProjectItem::itemDefaultHeight()
71 {
72     return itemHeight;
73 }
74
75 int ProjectItem::numReferences() const
76 {
77     if (!m_clip) return 0;
78     return m_clip->numReferences();
79 }
80
81 const QString &ProjectItem::clipId() const
82 {
83     return m_clipId;
84 }
85
86 CLIPTYPE ProjectItem::clipType() const
87 {
88     return m_clipType;
89 }
90
91 int ProjectItem::clipMaxDuration() const
92 {
93     return m_clip->getProperty("duration").toInt();
94 }
95
96 QStringList ProjectItem::names() const
97 {
98     QStringList result;
99     result.append(text(0));
100     result.append(text(1));
101     result.append(text(2));
102     return result;
103 }
104
105 QDomElement ProjectItem::toXml() const
106 {
107     return m_clip->toXML();
108 }
109
110 const KUrl ProjectItem::clipUrl() const
111 {
112     if (m_clipType != COLOR && m_clipType != VIRTUAL && m_clipType != UNKNOWN)
113         return KUrl(m_clip->getProperty("resource"));
114     else return KUrl();
115 }
116
117 void ProjectItem::changeDuration(int frames)
118 {
119     setData(0, DurationRole, Timecode::getEasyTimecode(GenTime(frames, KdenliveSettings::project_fps()), KdenliveSettings::project_fps()));
120 }
121
122 void ProjectItem::setProperties(QMap <QString, QString> props)
123 {
124     if (m_clip == NULL) return;
125     m_clip->setProperties(props);
126 }
127
128 QString ProjectItem::getClipHash() const
129 {
130     if (m_clip == NULL) return QString();
131     return m_clip->getClipHash();
132 }
133
134 void ProjectItem::setProperty(const QString &key, const QString &value)
135 {
136     if (m_clip == NULL) return;
137     m_clip->setProperty(key, value);
138 }
139
140 void ProjectItem::clearProperty(const QString &key)
141 {
142     if (m_clip == NULL) return;
143     m_clip->clearProperty(key);
144 }
145
146 DocClipBase *ProjectItem::referencedClip()
147 {
148     return m_clip;
149 }
150
151 void ProjectItem::slotSetToolTip()
152 {
153     QString tip = "<b>";
154     if (m_clip->isPlaceHolder()) tip.append(i18n("Missing") + " | ");
155     switch (m_clipType) {
156     case AUDIO:
157         tip.append(i18n("Audio clip") + "</b><br />" + clipUrl().path());
158         break;
159     case VIDEO:
160         tip.append(i18n("Mute video clip") + "</b><br />" + clipUrl().path());
161         break;
162     case AV:
163         tip.append(i18n("Video clip") + "</b><br />" + clipUrl().path());
164         break;
165     case COLOR:
166         tip.append(i18n("Color clip"));
167         break;
168     case IMAGE:
169         tip.append(i18n("Image clip") + "</b><br />" + clipUrl().path());
170         break;
171     case TEXT:
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());
174         break;
175     case SLIDESHOW:
176         tip.append(i18n("Slideshow clip") + "</b><br />" + clipUrl().directory());
177         break;
178     case VIRTUAL:
179         tip.append(i18n("Virtual clip"));
180         break;
181     case PLAYLIST:
182         tip.append(i18n("Playlist clip") + "</b><br />" + clipUrl().path());
183         break;
184     default:
185         tip.append(i18n("Unknown clip"));
186         break;
187     }
188
189     setToolTip(0, tip);
190 }
191
192
193 void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
194 {
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);
201     } else  {
202         // No duration known, use an arbitrary one until it is.
203     }
204
205
206     //extend attributes -reh
207
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;
215
216         m_clip->setClipType(m_clipType);
217         slotSetToolTip();
218     }
219     m_clip->setProperties(attributes);
220     m_clip->setMetadata(metadata);
221
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());
229         }
230     }
231 }
232
233 void ProjectItem::setProxyStatus(PROXYSTATUS status)
234 {
235     setData(0, ProxyRole, status);
236 }
237
238 bool ProjectItem::hasProxy() const
239 {
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;
242     return true;
243 }
244
245 bool ProjectItem::isProxyReady() const
246 {
247      return (data(0, ProxyRole).toInt() == PROXYDONE);
248 }
249
250 bool ProjectItem::isProxyRunning() const
251 {
252     PROXYSTATUS s = (PROXYSTATUS) data(0, ProxyRole).toInt();
253     if (s == PROXYWAITING || s == CREATINGPROXY) return true;
254     return false;
255 }
256