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