1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
20 #include "projectlist.h"
21 #include "projectitem.h"
22 #include "addfoldercommand.h"
23 #include "kdenlivesettings.h"
24 #include "slideshowclip.h"
25 #include "ui_colorclip_ui.h"
26 #include "titlewidget.h"
27 #include "definitions.h"
28 #include "clipmanager.h"
29 #include "docclipbase.h"
30 #include "kdenlivedoc.h"
33 #include "projectlistview.h"
34 #include "editclipcommand.h"
35 #include "editfoldercommand.h"
41 #include <KFileDialog>
42 #include <KInputDialog>
43 #include <KMessageBox>
45 #include <nepomuk/global.h>
46 #include <nepomuk/resourcemanager.h>
47 //#include <nepomuk/tag.h>
49 #include <QMouseEvent>
50 #include <QStylePainter>
55 #include <QHeaderView>
57 ProjectList::ProjectList(QWidget *parent) :
68 m_infoQueue(QMap <QString, QDomElement> ()),
69 m_thumbnailQueue(QList <QString> ())
72 listView = new ProjectListView(this);;
73 QVBoxLayout *layout = new QVBoxLayout;
74 layout->setContentsMargins(0, 0, 0, 0);
77 searchView = new KTreeWidgetSearchLine(this);
78 m_toolbar = new QToolBar("projectToolBar", this);
79 m_toolbar->addWidget(searchView);
81 m_addButton = new QToolButton(m_toolbar);
82 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
83 m_toolbar->addWidget(m_addButton);
85 layout->addWidget(m_toolbar);
86 layout->addWidget(listView);
88 //m_toolbar->setEnabled(false);
90 searchView->setTreeWidget(listView);
92 connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
93 connect(listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
94 connect(listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
95 connect(listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
96 connect(listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
97 connect(listView, SIGNAL(addClip(const QList <QUrl>, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &)));
98 connect(listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
99 connect(listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
101 ItemDelegate *listViewDelegate = new ItemDelegate(listView);
102 listView->setItemDelegate(listViewDelegate);
104 if (KdenliveSettings::activate_nepomuk()) {
105 Nepomuk::ResourceManager::instance()->init();
106 if (!Nepomuk::ResourceManager::instance()->initialized()) {
107 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
108 KdenliveSettings::setActivate_nepomuk(false);
113 ProjectList::~ProjectList()
119 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
121 QList <QAction *> actions = addMenu->actions();
122 for (int i = 0; i < actions.count(); i++) {
123 if (actions.at(i)->data().toString() == "clip_properties") {
124 m_editAction = actions.at(i);
125 m_toolbar->addAction(m_editAction);
128 } else if (actions.at(i)->data().toString() == "delete_clip") {
129 m_deleteAction = actions.at(i);
130 m_toolbar->addAction(m_deleteAction);
133 } else if (actions.at(i)->data().toString() == "edit_clip") {
134 m_openAction = actions.at(i);
137 } else if (actions.at(i)->data().toString() == "reload_clip") {
138 m_reloadAction = actions.at(i);
144 QMenu *m = new QMenu();
145 m->addActions(actions);
146 m_addButton->setMenu(m);
147 m_addButton->setDefaultAction(defaultAction);
148 m_menu = new QMenu();
149 m_menu->addActions(addMenu->actions());
152 void ProjectList::setupGeneratorMenu(QMenu *addMenu)
154 if (!addMenu) return;
155 QMenu *menu = m_addButton->menu();
156 menu->addMenu(addMenu);
157 m_addButton->setMenu(menu);
159 m_menu->addMenu(addMenu);
160 if (addMenu->isEmpty()) addMenu->setEnabled(false);
161 m_menu->addAction(m_reloadAction);
162 m_menu->addAction(m_editAction);
163 m_menu->addAction(m_openAction);
164 m_menu->addAction(m_deleteAction);
165 m_menu->insertSeparator(m_deleteAction);
169 QByteArray ProjectList::headerInfo()
171 return listView->header()->saveState();
174 void ProjectList::setHeaderInfo(const QByteArray &state)
176 listView->header()->restoreState(state);
179 void ProjectList::slotEditClip()
181 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
182 if (item && !item->isGroup()) {
183 emit clipSelected(item->referencedClip());
184 emit showClipProperties(item->referencedClip());
188 void ProjectList::slotOpenClip()
190 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
191 if (item && !item->isGroup()) {
192 if (item->clipType() == IMAGE) {
193 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
194 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
196 if (item->clipType() == AUDIO) {
197 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
198 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
203 void ProjectList::slotReloadClip()
205 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
206 if (item && !item->isGroup()) {
207 if (item->clipType() == IMAGE) {
208 item->referencedClip()->producer()->set("force_reload", 1);
210 emit getFileProperties(item->toXml(), item->clipId(), false);
214 void ProjectList::setRenderer(Render *projectRender)
216 m_render = projectRender;
217 listView->setIconSize(QSize(40 * m_render->dar(), 40));
220 void ProjectList::slotClipSelected()
222 if (listView->currentItem()) {
223 ProjectItem *clip = static_cast <ProjectItem*>(listView->currentItem());
224 if (!clip->isGroup()) {
225 m_selectedItem = clip;
226 emit clipSelected(clip->referencedClip());
228 m_editAction->setEnabled(true);
229 m_deleteAction->setEnabled(true);
230 m_reloadAction->setEnabled(true);
231 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
232 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
233 m_openAction->setEnabled(true);
234 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
235 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
236 m_openAction->setEnabled(true);
237 } else m_openAction->setEnabled(false);
239 emit clipSelected(NULL);
240 m_editAction->setEnabled(false);
241 m_deleteAction->setEnabled(false);
242 m_openAction->setEnabled(false);
243 m_reloadAction->setEnabled(false);
247 void ProjectList::slotPauseMonitor()
249 if (m_render) m_render->pause();
252 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
254 ProjectItem *item = getItemById(id);
256 slotUpdateClipProperties(item, properties);
257 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata")) slotRefreshClipThumbnail(item);
258 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
262 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
265 if (!clip->isGroup()) clip->setProperties(properties);
266 if (properties.contains("name")) {
267 listView->blockSignals(true);
268 clip->setText(1, properties.value("name"));
269 listView->blockSignals(false);
270 emit clipNameChanged(clip->clipId(), properties.value("name"));
272 if (properties.contains("description")) {
273 CLIPTYPE type = clip->clipType();
274 listView->blockSignals(true);
275 clip->setText(2, properties.value("description"));
276 listView->blockSignals(false);
277 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
278 // Use Nepomuk system to store clip description
279 Nepomuk::Resource f(clip->clipUrl().path());
280 f.setDescription(properties.value("description"));
282 emit projectModified();
286 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
288 ProjectItem *clip = static_cast <ProjectItem*>(item);
290 if (clip->referencedClip()) {
291 QMap <QString, QString> oldprops;
292 QMap <QString, QString> newprops;
293 oldprops["description"] = clip->referencedClip()->getProperty("description");
294 newprops["description"] = item->text(2);
295 slotUpdateClipProperties(clip, newprops);
296 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
297 m_commandStack->push(command);
299 } else if (column == 1) {
300 if (clip->isGroup()) {
301 editFolder(item->text(1), clip->groupName(), clip->clipId());
302 clip->setGroupName(item->text(1));
303 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
304 const int children = item->childCount();
305 for (int i = 0; i < children; i++) {
306 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
307 child->setProperty("groupname", item->text(1));
310 if (clip->referencedClip()) {
311 QMap <QString, QString> oldprops;
312 QMap <QString, QString> newprops;
313 oldprops["name"] = clip->referencedClip()->getProperty("name");
314 newprops["name"] = item->text(1);
315 slotUpdateClipProperties(clip, newprops);
316 emit projectModified();
317 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
318 m_commandStack->push(command);
324 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
330 m_editAction->setEnabled(enable);
331 m_deleteAction->setEnabled(enable);
332 m_reloadAction->setEnabled(enable);
334 ProjectItem *clip = static_cast <ProjectItem*>(item);
335 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
336 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
337 m_openAction->setEnabled(true);
338 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
339 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
340 m_openAction->setEnabled(true);
341 } else m_openAction->setEnabled(false);
342 } else m_openAction->setEnabled(false);
346 void ProjectList::slotRemoveClip()
348 if (!listView->currentItem()) return;
350 QMap <QString, QString> folderids;
351 QList<QTreeWidgetItem *> selected = listView->selectedItems();
353 for (int i = 0; i < selected.count(); i++) {
354 item = static_cast <ProjectItem *>(selected.at(i));
355 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
356 else ids << item->clipId();
357 if (item->numReferences() > 0) {
358 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;
359 } else if (item->isGroup() && item->childCount() > 0) {
360 int children = item->childCount();
361 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;
362 for (int i = 0; i < children; ++i) {
363 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
364 ids << child->clipId();
368 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
369 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
370 if (listView->topLevelItemCount() == 0) {
371 m_editAction->setEnabled(false);
372 m_deleteAction->setEnabled(false);
373 m_openAction->setEnabled(false);
374 m_reloadAction->setEnabled(false);
378 void ProjectList::selectItemById(const QString &clipId)
380 ProjectItem *item = getItemById(clipId);
381 if (item) listView->setCurrentItem(item);
385 void ProjectList::slotDeleteClip(const QString &clipId)
387 ProjectItem *item = getItemById(clipId);
389 kDebug() << "/// Cannot find clip to delete";
396 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
398 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
399 m_commandStack->push(command);
400 m_doc->setModified(true);
403 void ProjectList::slotAddFolder()
405 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
406 m_commandStack->push(command);
409 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
412 ProjectItem *item = getFolderItemById(clipId);
414 m_doc->clipManager()->deleteFolder(clipId);
419 ProjectItem *item = getFolderItemById(clipId);
420 QTreeWidgetItemIterator it(listView);
422 listView->blockSignals(true);
423 item->setGroupName(foldername);
424 listView->blockSignals(false);
425 m_doc->clipManager()->addFolder(clipId, foldername);
426 const int children = item->childCount();
427 for (int i = 0; i < children; i++) {
428 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
429 child->setProperty("groupname", foldername);
434 text << QString() << foldername;
435 listView->blockSignals(true);
436 (void) new ProjectItem(listView, text, clipId);
437 m_doc->clipManager()->addFolder(clipId, foldername);
438 listView->blockSignals(false);
445 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
447 QMapIterator<QString, QString> i(map);
448 QUndoCommand *delCommand = new QUndoCommand();
449 delCommand->setText(i18n("Delete Folder"));
450 while (i.hasNext()) {
452 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
454 m_commandStack->push(delCommand);
455 m_doc->setModified(true);
458 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
460 if (getProperties) listView->setEnabled(false);
461 listView->blockSignals(true);
462 const QString parent = clip->getProperty("groupid");
463 kDebug() << "Adding clip with groupid: " << parent;
464 ProjectItem *item = NULL;
465 if (!parent.isEmpty()) {
466 ProjectItem *parentitem = getFolderItemById(parent);
469 QString groupName = clip->getProperty("groupname");
470 //kDebug() << "Adding clip to new group: " << groupName;
471 if (groupName.isEmpty()) groupName = i18n("Folder");
472 text << QString() << groupName;
473 parentitem = new ProjectItem(listView, text, parent);
475 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
477 if (parentitem) item = new ProjectItem(parentitem, clip);
479 if (item == NULL) item = new ProjectItem(listView, clip);
481 KUrl url = clip->fileURL();
482 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
483 // if file has Nepomuk comment, use it
484 Nepomuk::Resource f(url.path());
485 QString annotation = f.description();
486 if (!annotation.isEmpty()) item->setText(2, annotation);
487 item->setText(3, QString::number(f.rating()));
489 listView->blockSignals(false);
492 void ProjectList::slotResetProjectList()
495 emit clipSelected(NULL);
496 m_thumbnailQueue.clear();
501 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
503 kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
504 m_infoQueue.insert(id, xml);
505 listView->setEnabled(false);
506 if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
509 void ProjectList::slotProcessNextClipInQueue()
511 if (m_infoQueue.isEmpty()) {
512 listView->setEnabled(true);
515 QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
516 if (i != m_infoQueue.constEnd()) {
517 const QDomElement dom = i.value();
518 const QString id = i.key();
519 m_infoQueue.remove(i.key());
520 emit getFileProperties(dom, id, true);
522 if (m_infoQueue.isEmpty()) listView->setEnabled(true);
525 void ProjectList::slotUpdateClip(const QString &id)
527 ProjectItem *item = getItemById(id);
528 listView->blockSignals(true);
529 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
530 listView->blockSignals(false);
533 void ProjectList::updateAllClips()
535 QTreeWidgetItemIterator it(listView);
537 ProjectItem *item = static_cast <ProjectItem *>(*it);
538 if (!item->isGroup()) {
539 if (item->referencedClip()->producer() == NULL) {
540 DocClipBase *clip = item->referencedClip();
541 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
542 // regenerate text clip image if required
543 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
545 doc.setContent(clip->getProperty("xmldata"));
547 QImage pix = dia_ui->renderedPixmap();
548 pix.save(clip->fileURL().path());
551 requestClipInfo(clip->toXML(), clip->getId());
553 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
554 if (QFile::exists(cachedPixmap)) {
555 //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
556 listView->blockSignals(true);
557 item->setIcon(0, QPixmap(cachedPixmap));
558 listView->blockSignals(false);
559 } else requestClipThumbnail(item->clipId());
561 if (item->data(1, DurationRole).toString().isEmpty()) {
562 listView->blockSignals(true);
563 item->changeDuration(item->referencedClip()->producer()->get_playtime());
564 listView->blockSignals(false);
567 listView->blockSignals(true);
568 item->setData(1, UsageRole, QString::number(item->numReferences()));
569 listView->blockSignals(false);
570 qApp->processEvents();
574 QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
577 void ProjectList::slotAddClip(const QList <QUrl> givenList, QString group)
579 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
581 if (givenList.isEmpty()) {
582 // Build list of mime types
583 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "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-tga" << "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" << "video/x-matroska" << "audio/x-matroska";
585 QString allExtensions;
586 foreach(const QString& mimeType, mimeTypes) {
587 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
589 allExtensions.append(mime->patterns().join(" "));
590 allExtensions.append(' ');
593 QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files");
594 dialogFilter.append("\n*" + QLatin1Char('|') + i18n("All Files"));
595 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
598 for (int i = 0; i < givenList.count(); i++)
599 list << givenList.at(i);
601 if (list.isEmpty()) return;
604 if (group.isEmpty()) {
605 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
606 if (item && !item->isGroup()) {
607 while (item->parent()) {
608 item = static_cast <ProjectItem*>(item->parent());
609 if (item->isGroup()) break;
612 if (item && item->isGroup()) {
613 group = item->groupName();
614 groupId = item->clipId();
617 m_doc->slotAddClipList(list, group, groupId);
620 void ProjectList::slotRemoveInvalidClip(const QString &id)
622 ProjectItem *item = getItemById(id);
624 const QString path = item->referencedClip()->fileURL().path();
625 if (!path.isEmpty()) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
628 m_doc->deleteProjectClip(ids);
630 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
631 else listView->setEnabled(true);
634 void ProjectList::slotAddColorClip()
636 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
637 QDialog *dia = new QDialog(this);
638 Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
639 dia_ui->setupUi(dia);
640 dia_ui->clip_name->setText(i18n("Color Clip"));
641 dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
642 if (dia->exec() == QDialog::Accepted) {
643 QString color = dia_ui->clip_color->color().name();
644 color = color.replace(0, 1, "0x") + "ff";
648 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
649 if (item && !item->isGroup()) {
650 while (item->parent()) {
651 item = static_cast <ProjectItem*>(item->parent());
652 if (item->isGroup()) break;
655 if (item && item->isGroup()) {
656 group = item->groupName();
657 groupId = item->clipId();
660 m_doc->clipManager()->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId);
661 m_doc->setModified(true);
668 void ProjectList::slotAddSlideshowClip()
670 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
671 SlideshowClip *dia = new SlideshowClip(this);
673 if (dia->exec() == QDialog::Accepted) {
677 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
678 if (item && !item->isGroup()) {
679 while (item->parent()) {
680 item = static_cast <ProjectItem*>(item->parent());
681 if (item->isGroup()) break;
684 if (item && item->isGroup()) {
685 group = item->groupName();
686 groupId = item->clipId();
689 m_doc->clipManager()->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId);
690 m_doc->setModified(true);
695 void ProjectList::slotAddTitleClip()
699 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
700 if (item && !item->isGroup()) {
701 while (item->parent()) {
702 item = static_cast <ProjectItem*>(item->parent());
703 if (item->isGroup()) break;
706 if (item && item->isGroup()) {
707 group = item->groupName();
708 groupId = item->clipId();
711 m_doc->slotCreateTextClip(group, groupId);
714 void ProjectList::setDocument(KdenliveDoc *doc)
716 listView->blockSignals(true);
718 emit clipSelected(NULL);
719 m_thumbnailQueue.clear();
722 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
723 QMapIterator<QString, QString> f(flist);
724 while (f.hasNext()) {
726 (void) new ProjectItem(listView, QStringList() << QString() << f.value(), f.key());
729 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
730 for (int i = 0; i < list.count(); i++) {
731 slotAddClip(list.at(i), false);
735 m_timecode = doc->timecode();
736 m_commandStack = doc->commandStack();
738 QTreeWidgetItem *first = listView->topLevelItem(0);
739 if (first) listView->setCurrentItem(first);
740 listView->blockSignals(false);
741 m_toolbar->setEnabled(true);
744 QDomElement ProjectList::producersList()
747 QDomElement prods = doc.createElement("producerlist");
748 doc.appendChild(prods);
749 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
750 QTreeWidgetItemIterator it(listView);
752 if (!((ProjectItem *)(*it))->isGroup())
753 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
759 void ProjectList::slotCheckForEmptyQueue()
761 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
763 emit loadingIsOver();
764 } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
767 void ProjectList::requestClipThumbnail(const QString &id)
769 m_thumbnailQueue.append(id);
770 if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
773 void ProjectList::slotProcessNextThumbnail()
775 if (m_thumbnailQueue.isEmpty()) {
778 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
781 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
783 ProjectItem *item = getItemById(clipId);
784 if (item) slotRefreshClipThumbnail(item, update);
785 else slotProcessNextThumbnail();
788 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
791 if (!item->referencedClip()) return;
793 int width = (int)(height * m_render->dar());
794 DocClipBase *clip = item->referencedClip();
795 if (!clip) slotProcessNextThumbnail();
797 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
798 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
799 listView->blockSignals(true);
800 item->setIcon(0, pix);
801 listView->blockSignals(false);
802 m_doc->cachePixmap(item->getClipHash(), pix);
803 if (update) emit projectModified();
804 if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
808 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
810 ProjectItem *item = getItemById(clipId);
811 if (item && producer) {
812 listView->blockSignals(true);
813 item->setProperties(properties, metadata);
814 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
815 if (replace) item->referencedClip()->setProducer(producer);
816 emit receivedClipDuration(clipId, item->clipMaxDuration());
817 listView->blockSignals(false);
818 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
819 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
820 else listView->setEnabled(true);
823 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
825 ProjectItem *item = getItemById(clipId);
827 listView->blockSignals(true);
828 item->setIcon(0, pix);
829 m_doc->cachePixmap(item->getClipHash(), pix);
830 listView->blockSignals(false);
834 ProjectItem *ProjectList::getItemById(const QString &id)
837 QTreeWidgetItemIterator it(listView);
839 item = static_cast<ProjectItem *>(*it);
840 if (item->clipId() == id && item->clipType() != FOLDER)
847 ProjectItem *ProjectList::getFolderItemById(const QString &id)
850 QTreeWidgetItemIterator it(listView);
852 item = static_cast<ProjectItem *>(*it);
853 if (item->clipId() == id && item->clipType() == FOLDER)
860 void ProjectList::slotSelectClip(const QString &ix)
862 ProjectItem *clip = getItemById(ix);
864 listView->setCurrentItem(clip);
865 listView->scrollToItem(clip);
866 m_editAction->setEnabled(true);
867 m_deleteAction->setEnabled(true);
868 m_reloadAction->setEnabled(true);
869 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
870 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
871 m_openAction->setEnabled(true);
872 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
873 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
874 m_openAction->setEnabled(true);
875 } else m_openAction->setEnabled(false);
879 #include "projectlist.moc"