]> git.sesse.net Git - kdenlive/blob - src/projectlist.cpp
* Small cmake cleanup
[kdenlive] / src / projectlist.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 <QMouseEvent>
22 #include <QStylePainter>
23 #include <QPixmap>
24 #include <QIcon>
25 #include <QDialog>
26 #include <QtGui>
27
28 #include <KDebug>
29 #include <KAction>
30 #include <KLocale>
31 #include <KFileDialog>
32 #include <KInputDialog>
33 #include <KMessageBox>
34
35 #include <nepomuk/global.h>
36 #include <nepomuk/resource.h>
37 #include <nepomuk/tag.h>
38
39 #include "projectlist.h"
40 #include "projectitem.h"
41 #include "kdenlivesettings.h"
42 #include "slideshowclip.h"
43 #include "ui_colorclip_ui.h"
44 #include "titlewidget.h"
45
46
47 #include "definitions.h"
48 #include "clipmanager.h"
49 #include "docclipbase.h"
50 #include "kdenlivedoc.h"
51 #include "renderer.h"
52 #include "kthumb.h"
53 #include "projectlistview.h"
54
55 ProjectList::ProjectList(QWidget *parent)
56         : QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(NULL), m_selectedItem(NULL), m_infoQueue(QMap <QString, QDomElement> ()), m_thumbnailQueue(QList <QString> ()), m_refreshed(false) {
57
58     QWidget *vbox = new QWidget;
59     listView = new ProjectListView(this);;
60     QVBoxLayout *layout = new QVBoxLayout;
61     layout->setContentsMargins(0, 0, 0, 0);
62     m_clipIdCounter = 0;
63     // setup toolbar
64     searchView = new KTreeWidgetSearchLine(this);
65     m_toolbar = new QToolBar("projectToolBar", this);
66     m_toolbar->addWidget(searchView);
67
68     m_addButton = new QToolButton(m_toolbar);
69     m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
70     m_toolbar->addWidget(m_addButton);
71
72     m_deleteAction = m_toolbar->addAction(KIcon("edit-delete"), i18n("Delete Clip"));
73     connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(slotRemoveClip()));
74
75     m_editAction = m_toolbar->addAction(KIcon("document-properties"), i18n("Edit Clip"));
76     connect(m_editAction, SIGNAL(triggered()), this, SLOT(slotEditClip()));
77
78     layout->addWidget(m_toolbar);
79     layout->addWidget(listView);
80     setLayout(layout);
81     //m_toolbar->setEnabled(false);
82
83     searchView->setTreeWidget(listView);
84
85     connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
86     connect(listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
87     connect(listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
88     connect(listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
89     connect(listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
90     connect(listView, SIGNAL(addClip(KUrl, const QString &)), this, SLOT(slotAddClip(KUrl, const QString &)));
91     connect(listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
92     connect(listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
93
94     ItemDelegate *listViewDelegate = new ItemDelegate(listView);
95     listView->setItemDelegate(listViewDelegate);
96 }
97
98 ProjectList::~ProjectList() {
99     delete m_menu;
100     delete m_toolbar;
101 }
102
103 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
104 {
105     m_addButton->setMenu(addMenu);
106     m_addButton->setDefaultAction(defaultAction);
107     m_menu = new QMenu();
108     m_menu->addActions(addMenu->actions());
109 }
110
111 void ProjectList::setupGeneratorMenu(QMenu *addMenu)
112 {
113
114   QMenu *menu = m_addButton->menu();
115   menu->addMenu(addMenu);  
116   m_addButton->setMenu(menu);
117
118   m_menu->addMenu(addMenu);
119   if (addMenu->isEmpty()) addMenu->setEnabled(false);
120   m_menu->addAction(m_editAction);
121   m_menu->addAction(m_deleteAction);
122   m_menu->insertSeparator(m_deleteAction);
123 }
124
125
126 QByteArray ProjectList::headerInfo() {
127     return listView->header()->saveState();
128 }
129
130 void ProjectList::setHeaderInfo(const QByteArray &state) {
131     listView->header()->restoreState(state);
132 }
133
134 void ProjectList::slotEditClip() {
135     ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
136     if (item && !item->isGroup()) {
137         emit clipSelected(item->referencedClip());
138         emit showClipProperties(item->referencedClip());
139     }
140 }
141
142
143
144 void ProjectList::setRenderer(Render *projectRender) {
145     m_render = projectRender;
146 }
147
148 void ProjectList::slotClipSelected() {
149     if (listView->currentItem()) {
150         ProjectItem *clip = static_cast <ProjectItem*>(listView->currentItem());
151         if (!clip->isGroup()) {
152             m_selectedItem = clip;
153             emit clipSelected(clip->referencedClip());
154         }
155         m_editAction->setEnabled(true);
156         m_deleteAction->setEnabled(true);
157     } else {
158         m_editAction->setEnabled(false);
159         m_deleteAction->setEnabled(false);
160     }
161 }
162
163 void ProjectList::slotPauseMonitor() {
164     if (m_render) m_render->pause();
165 }
166
167 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties) {
168     ProjectItem *item = getItemById(id);
169     if (item) {
170         slotUpdateClipProperties(item, properties);
171         if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata")) slotRefreshClipThumbnail(item);
172         if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
173     }
174 }
175
176 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties) {
177     if (!clip) return;
178     if (!clip->isGroup()) clip->setProperties(properties);
179     if (properties.contains("description")) {
180         CLIPTYPE type = clip->clipType();
181         clip->setText(2, properties.value("description"));
182         if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
183             // Use Nepomuk system to store clip description
184             Nepomuk::Resource f(clip->clipUrl().path());
185             if (f.isValid()) {
186                 f.setDescription(properties.value("description"));
187             } else {
188                 KMessageBox::sorry(this, i18n("Cannot access Desktop Search info for %1.\nDisabling Desktop Search integration.", clip->clipUrl().path()));
189                 KdenliveSettings::setActivate_nepomuk(false);
190             }
191         }
192         emit projectModified();
193     }
194 }
195
196 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) {
197     ProjectItem *clip = static_cast <ProjectItem*>(item);
198     if (column == 2) {
199         QMap <QString, QString> props;
200         props["description"] = item->text(2);
201         slotUpdateClipProperties(clip, props);
202     } else if (column == 1 && clip->isGroup()) {
203         m_doc->slotEditFolder(item->text(1), clip->groupName(), clip->clipId());
204         clip->setGroupName(item->text(1));
205         const int children = item->childCount();
206         for (int i = 0; i < children; i++) {
207             ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
208             child->setProperty("groupname", item->text(1));
209         }
210     }
211 }
212
213 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) {
214     bool enable = false;
215     if (item) {
216         enable = true;
217     }
218     m_editAction->setEnabled(enable);
219     m_deleteAction->setEnabled(enable);
220     m_menu->popup(pos);
221 }
222
223 void ProjectList::slotRemoveClip() {
224     if (!listView->currentItem()) return;
225     QList <QString> ids;
226     QMap <QString, QString> folderids;
227     QList<QTreeWidgetItem *> selected = listView->selectedItems();
228     ProjectItem *item;
229     for (int i = 0; i < selected.count(); i++) {
230         item = static_cast <ProjectItem *>(selected.at(i));
231         if (item->isGroup()) folderids[item->groupName()] = item->clipId();
232         else ids << item->clipId();
233         if (item->numReferences() > 0) {
234             if (KMessageBox::questionYesNo(this, i18np("Delete clip <b>%2</b> ?<br>This will also remove the clip in timeline", "Delete clip <b>%2</b> ?<br>This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip")) != KMessageBox::Yes) return;
235         } else if (item->isGroup() && item->childCount() > 0) {
236             int children = item->childCount();
237             if (KMessageBox::questionYesNo(this, i18n("Delete folder <b>%2</b> ?<br>This will also remove the %1 clips in that folder", children, item->names().at(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
238             for (int i = 0; i < children; ++i) {
239                 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
240                 ids << child->clipId();
241             }
242         }
243     }
244     if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
245     if (!folderids.isEmpty()) m_doc->deleteProjectFolder(folderids);
246     if (listView->topLevelItemCount() == 0) {
247         m_editAction->setEnabled(false);
248         m_deleteAction->setEnabled(false);
249     }
250 }
251
252 void ProjectList::selectItemById(const QString &clipId) {
253     ProjectItem *item = getItemById(clipId);
254     if (item) listView->setCurrentItem(item);
255 }
256
257
258 void ProjectList::slotDeleteClip(const QString &clipId) {
259     ProjectItem *item = getItemById(clipId);
260     QTreeWidgetItem *p = item->parent();
261     if (p) {
262         kDebug() << "///////  DELETED CLIP HAS A PARENT... " << p->indexOfChild(item);
263         QTreeWidgetItem *clone = p->takeChild(p->indexOfChild(item));
264     } else if (item) {
265         delete item;
266     }
267 }
268
269 void ProjectList::slotAddFolder() {
270
271     // QString folderName = KInputDialog::getText(i18n("New Folder"), i18n("Enter new folder name: "));
272     // if (folderName.isEmpty()) return;
273     m_doc->slotAddFolder(i18n("Folder")); //folderName);
274 }
275
276 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit) {
277     if (remove) {
278         ProjectItem *item;
279         QTreeWidgetItemIterator it(listView);
280         while (*it) {
281             item = static_cast <ProjectItem *>(*it);
282             if (item->isGroup() && item->clipId() == clipId) {
283                 delete item;
284                 break;
285             }
286             ++it;
287         }
288     } else {
289         if (edit) {
290             listView->blockSignals(true);
291             ProjectItem *item;
292             QTreeWidgetItemIterator it(listView);
293             while (*it) {
294                 item = static_cast <ProjectItem *>(*it);
295                 if (item->isGroup() && item->clipId() == clipId) {
296                     item->setGroupName(foldername);
297                     const int children = item->childCount();
298                     for (int i = 0; i < children; i++) {
299                         ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
300                         child->setProperty("groupname", foldername);
301                     }
302                     break;
303                 }
304                 ++it;
305             }
306             listView->blockSignals(false);
307         } else {
308             QStringList text;
309             text << QString() << foldername;
310             (void) new ProjectItem(listView, text, clipId);
311         }
312     }
313 }
314
315 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) {
316     if (getProperties) listView->setEnabled(false);
317     const QString parent = clip->getProperty("groupid");
318     //kDebug() << "Adding clip with groupid: " << parent;
319     ProjectItem *item = NULL;
320     if (!parent.isEmpty()) {
321         ProjectItem *parentitem = getItemById(parent);
322         if (!parentitem) {
323             QStringList text;
324             QString groupName = clip->getProperty("groupname");
325             //kDebug() << "Adding clip to new group: " << groupName;
326             if (groupName.isEmpty()) groupName = i18n("Folder");
327             text << QString() << groupName;
328             listView->blockSignals(true);
329             parentitem = new ProjectItem(listView, text, parent);
330             listView->blockSignals(false);
331         } else {
332             //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
333         }
334         if (parentitem) item = new ProjectItem(parentitem, clip);
335     }
336     if (item == NULL) item = new ProjectItem(listView, clip);
337
338     KUrl url = clip->fileURL();
339     if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
340         // if file has Nepomuk comment, use it
341         Nepomuk::Resource f(url.path());
342         QString annotation;
343         if (f.isValid()) {
344             annotation = f.description();
345             /*
346             Nepomuk::Tag tag("test");
347             f.addTag(tag);*/
348         } else {
349             KMessageBox::sorry(this, i18n("Cannot access Desktop Search info for %1.\nDisabling Desktop Search integration.", url.path()));
350             KdenliveSettings::setActivate_nepomuk(false);
351         }
352         if (!annotation.isEmpty()) item->setText(2, annotation);
353     }
354 }
355
356 void ProjectList::requestClipInfo(const QDomElement xml, const QString id) {
357     kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
358     m_infoQueue.insert(id, xml);
359     listView->setEnabled(false);
360     if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
361 }
362
363 void ProjectList::slotProcessNextClipInQueue() {
364     if (m_infoQueue.isEmpty()) {        
365         listView->setEnabled(true);
366         return;
367     }
368     QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
369     if (i != m_infoQueue.constEnd()) {
370         const QDomElement dom = i.value();
371         const QString id = i.key();
372         m_infoQueue.remove(i.key());
373         emit getFileProperties(dom, id);
374     }
375     if (m_infoQueue.isEmpty()) listView->setEnabled(true);
376 }
377
378 void ProjectList::slotUpdateClip(const QString &id) {
379     ProjectItem *item = getItemById(id);
380     item->setData(1, UsageRole, QString::number(item->numReferences()));
381 }
382
383 void ProjectList::updateAllClips() {
384     QTreeWidgetItemIterator it(listView);
385     while (*it) {
386         ProjectItem *item = static_cast <ProjectItem *>(*it);
387         if (!item->isGroup()) {
388             if (item->referencedClip()->producer() == NULL) {
389                 DocClipBase *clip = item->referencedClip();
390                 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
391                     // regenerate text clip image if required
392                     TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
393                     QDomDocument doc;
394                     doc.setContent(clip->getProperty("xmldata"));
395                     dia_ui->setXml(doc);
396                     QPixmap pix = dia_ui->renderedPixmap();
397                     pix.save(clip->fileURL().path());
398                     delete dia_ui;
399                 }
400                 requestClipInfo(clip->toXML(), clip->getId());
401             } else {
402                 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
403                 if (QFile::exists(cachedPixmap)) {
404                     //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
405                     item->setIcon(0, QPixmap(cachedPixmap));
406                 } else requestClipThumbnail(item->clipId());
407                 item->changeDuration(item->referencedClip()->producer()->get_playtime());
408             }
409             item->setData(1, UsageRole, QString::number(item->numReferences()));
410             qApp->processEvents();
411         }
412         ++it;
413     }
414     QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
415 }
416
417 void ProjectList::slotAddClip(KUrl givenUrl, QString group) {
418     if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
419     KUrl::List list;
420     if (givenUrl.isEmpty()) {
421         list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), "application/x-kdenlive video/x-flv application/vnd.rn-realmedia video/x-dv video/dv video/x-msvideo video/mpeg video/x-ms-wmv audio/mpeg audio/x-mp3 audio/x-wav application/ogg video/mp4 video/quicktime image/gif image/jpeg image/png image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr video/mlt-playlist audio/x-flac audio/mp4", this);
422     } else list.append(givenUrl);
423     if (list.isEmpty()) return;
424
425     QString groupId = QString();
426     if (group.isEmpty()) {
427         ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
428         if (item && !item->isGroup()) {
429             while (item->parent()) {
430                 item = static_cast <ProjectItem*>(item->parent());
431                 if (item->isGroup()) break;
432             }
433         }
434         if (item && item->isGroup()) {
435             group = item->groupName();
436             groupId = item->clipId();
437         }
438     }
439     m_doc->slotAddClipList(list, group, groupId);
440 }
441
442 void ProjectList::slotRemoveInvalidClip(const QString &id) {
443     ProjectItem *item = getItemById(id);
444     if (item) {
445         const QString path = item->referencedClip()->fileURL().path();
446         if (!path.isEmpty()) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
447         QList <QString> ids;
448         ids << id;
449         m_doc->deleteProjectClip(ids);
450     }
451     if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
452 }
453
454 void ProjectList::slotAddColorClip() {
455     if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
456     QDialog *dia = new QDialog(this);
457     Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
458     dia_ui->setupUi(dia);
459     dia_ui->clip_name->setText(i18n("Color Clip"));
460     dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
461     if (dia->exec() == QDialog::Accepted) {
462         QString color = dia_ui->clip_color->color().name();
463         color = color.replace(0, 1, "0x") + "ff";
464
465         QString group = QString();
466         QString groupId = QString();
467         ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
468         if (item && !item->isGroup()) {
469             while (item->parent()) {
470                 item = static_cast <ProjectItem*>(item->parent());
471                 if (item->isGroup()) break;
472             }
473         }
474         if (item && item->isGroup()) {
475             group = item->groupName();
476             groupId = item->clipId();
477         }
478
479         m_doc->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId);
480     }
481     delete dia_ui;
482     delete dia;
483 }
484
485
486 void ProjectList::slotAddSlideshowClip() {
487     if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
488     SlideshowClip *dia = new SlideshowClip(this);
489
490     if (dia->exec() == QDialog::Accepted) {
491
492         QString group = QString();
493         QString groupId = QString();
494         ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
495         if (item && !item->isGroup()) {
496             while (item->parent()) {
497                 item = static_cast <ProjectItem*>(item->parent());
498                 if (item->isGroup()) break;
499             }
500         }
501         if (item && item->isGroup()) {
502             group = item->groupName();
503             groupId = item->clipId();
504         }
505
506         m_doc->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId);
507     }
508     delete dia;
509 }
510
511 void ProjectList::slotAddTitleClip() {
512     QString group = QString();
513     QString groupId = QString();
514     ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
515     if (item && !item->isGroup()) {
516         while (item->parent()) {
517             item = static_cast <ProjectItem*>(item->parent());
518             if (item->isGroup()) break;
519         }
520     }
521     if (item && item->isGroup()) {
522         group = item->groupName();
523         groupId = item->clipId();
524     }
525
526     m_doc->slotCreateTextClip(group, groupId);
527 }
528
529 void ProjectList::setDocument(KdenliveDoc *doc) {
530     listView->blockSignals(true);
531     listView->clear();
532     m_thumbnailQueue.clear();
533     m_infoQueue.clear();
534     m_refreshed = false;
535     QList <DocClipBase*> list = doc->clipManager()->documentClipList();
536     for (int i = 0; i < list.count(); i++) {
537         slotAddClip(list.at(i), false);
538     }
539
540     m_fps = doc->fps();
541     m_timecode = doc->timecode();
542     m_commandStack = doc->commandStack();
543     m_doc = doc;
544     QTreeWidgetItem *first = listView->topLevelItem(0);
545     if (first) listView->setCurrentItem(first);
546     listView->blockSignals(false);
547     m_toolbar->setEnabled(true);
548 }
549
550 QDomElement ProjectList::producersList() {
551     QDomDocument doc;
552     QDomElement prods = doc.createElement("producerlist");
553     doc.appendChild(prods);
554     kDebug() << "////////////  PRO LISTĀ BUILD PRDSLIST ";
555     QTreeWidgetItemIterator it(listView);
556     while (*it) {
557         if (!((ProjectItem *)(*it))->isGroup())
558             prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
559         ++it;
560     }
561     return prods;
562 }
563
564 void ProjectList::slotCheckForEmptyQueue() {
565     if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
566         m_refreshed = true;
567         emit loadingIsOver();
568     } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
569 }
570
571 void ProjectList::requestClipThumbnail(const QString &id) {
572     m_thumbnailQueue.append(id);
573     if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
574 }
575
576 void ProjectList::slotProcessNextThumbnail() {
577     if (m_thumbnailQueue.isEmpty()) {
578         return;
579     }
580     slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
581 }
582
583 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update) {
584     ProjectItem *item = getItemById(clipId);
585     if (item) slotRefreshClipThumbnail(item, update);
586     else slotProcessNextThumbnail();
587 }
588
589 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update) {
590     if (item) {
591         if (!item->referencedClip()) return;
592         int height = 50;
593         int width = (int)(height  * m_render->dar());
594         DocClipBase *clip = item->referencedClip();
595         if (!clip) slotProcessNextThumbnail();
596         QPixmap pix;
597         if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
598         else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
599         item->setIcon(0, pix);
600         m_doc->cachePixmap(item->getClipHash(), pix);
601         if (update) emit projectModified();
602         if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
603     }
604 }
605
606 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata) {
607     ProjectItem *item = getItemById(clipId);
608     if (item && producer) {
609         item->setProperties(properties, metadata);
610         item->referencedClip()->setProducer(producer);
611         emit receivedClipDuration(clipId, item->clipMaxDuration());
612     } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
613     if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
614     else listView->setEnabled(true);
615 }
616
617 void ProjectList::slotReplyGetImage(const QString &clipId, int pos, const QPixmap &pix, int w, int h) {
618     ProjectItem *item = getItemById(clipId);
619     if (item) {
620         item->setIcon(0, pix);
621         m_doc->cachePixmap(item->getClipHash(), pix);
622     }
623 }
624
625 ProjectItem *ProjectList::getItemById(const QString &id) {
626     QTreeWidgetItemIterator it(listView);
627     while (*it) {
628         if (((ProjectItem *)(*it))->clipId() == id)
629             return static_cast<ProjectItem *>(*it);
630         ++it;
631     }
632     return NULL;
633 #ifdef USED_TO_BE_THIS
634     while (*it) {
635         if (((ProjectItem *)(*it))->clipId() == id)
636             break;
637         ++it;
638     }
639     if (*it) return ((ProjectItem *)(*it));
640     return NULL;
641 #endif
642 }
643
644 void ProjectList::slotSelectClip(const QString &ix) {
645     ProjectItem *p = getItemById(ix);
646     if (p) {
647         listView->setCurrentItem(p);
648         listView->scrollToItem(p);
649         m_editAction->setEnabled(true);
650         m_deleteAction->setEnabled(true);
651     }
652 }
653
654 #include "projectlist.moc"