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