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)
58 : 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), m_editAction(NULL), m_openAction(NULL), m_deleteAction(NULL), m_reloadAction(NULL)
61 listView = new ProjectListView(this);;
62 QVBoxLayout *layout = new QVBoxLayout;
63 layout->setContentsMargins(0, 0, 0, 0);
66 searchView = new KTreeWidgetSearchLine(this);
67 m_toolbar = new QToolBar("projectToolBar", this);
68 m_toolbar->addWidget(searchView);
70 m_addButton = new QToolButton(m_toolbar);
71 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
72 m_toolbar->addWidget(m_addButton);
74 layout->addWidget(m_toolbar);
75 layout->addWidget(listView);
77 //m_toolbar->setEnabled(false);
79 searchView->setTreeWidget(listView);
81 connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
82 connect(listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
83 connect(listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
84 connect(listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
85 connect(listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
86 connect(listView, SIGNAL(addClip(const QList <QUrl>, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &)));
87 connect(listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
88 connect(listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
90 ItemDelegate *listViewDelegate = new ItemDelegate(listView);
91 listView->setItemDelegate(listViewDelegate);
93 if (KdenliveSettings::activate_nepomuk()) {
94 Nepomuk::ResourceManager::instance()->init();
95 if (!Nepomuk::ResourceManager::instance()->initialized()) {
96 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
97 KdenliveSettings::setActivate_nepomuk(false);
102 ProjectList::~ProjectList()
108 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
110 QList <QAction *> actions = addMenu->actions();
111 for (int i = 0; i < actions.count(); i++) {
112 if (actions.at(i)->data().toString() == "clip_properties") {
113 m_editAction = actions.at(i);
114 m_toolbar->addAction(m_editAction);
117 } else if (actions.at(i)->data().toString() == "delete_clip") {
118 m_deleteAction = actions.at(i);
119 m_toolbar->addAction(m_deleteAction);
122 } else if (actions.at(i)->data().toString() == "edit_clip") {
123 m_openAction = actions.at(i);
126 } else if (actions.at(i)->data().toString() == "reload_clip") {
127 m_reloadAction = actions.at(i);
133 QMenu *m = new QMenu();
134 m->addActions(actions);
135 m_addButton->setMenu(m);
136 m_addButton->setDefaultAction(defaultAction);
137 m_menu = new QMenu();
138 m_menu->addActions(addMenu->actions());
141 void ProjectList::setupGeneratorMenu(QMenu *addMenu)
143 if (!addMenu) return;
144 QMenu *menu = m_addButton->menu();
145 menu->addMenu(addMenu);
146 m_addButton->setMenu(menu);
148 m_menu->addMenu(addMenu);
149 if (addMenu->isEmpty()) addMenu->setEnabled(false);
150 m_menu->addAction(m_reloadAction);
151 m_menu->addAction(m_editAction);
152 m_menu->addAction(m_openAction);
153 m_menu->addAction(m_deleteAction);
154 m_menu->insertSeparator(m_deleteAction);
158 QByteArray ProjectList::headerInfo()
160 return listView->header()->saveState();
163 void ProjectList::setHeaderInfo(const QByteArray &state)
165 listView->header()->restoreState(state);
168 void ProjectList::slotEditClip()
170 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
171 if (item && !item->isGroup()) {
172 emit clipSelected(item->referencedClip());
173 emit showClipProperties(item->referencedClip());
177 void ProjectList::slotOpenClip()
179 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
180 if (item && !item->isGroup()) {
181 if (item->clipType() == IMAGE) {
182 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
183 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
185 if (item->clipType() == AUDIO) {
186 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
187 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
192 void ProjectList::slotReloadClip()
194 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
195 if (item && !item->isGroup()) {
196 if (item->clipType() == IMAGE) {
197 item->referencedClip()->producer()->set("force_reload", 1);
199 emit getFileProperties(item->toXml(), item->clipId(), false);
203 void ProjectList::setRenderer(Render *projectRender)
205 m_render = projectRender;
206 listView->setIconSize(QSize(40 * m_render->dar(), 40));
209 void ProjectList::slotClipSelected()
211 if (listView->currentItem()) {
212 ProjectItem *clip = static_cast <ProjectItem*>(listView->currentItem());
213 if (!clip->isGroup()) {
214 m_selectedItem = clip;
215 emit clipSelected(clip->referencedClip());
217 m_editAction->setEnabled(true);
218 m_deleteAction->setEnabled(true);
219 m_reloadAction->setEnabled(true);
220 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
221 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
222 m_openAction->setEnabled(true);
223 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
224 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
225 m_openAction->setEnabled(true);
226 } else m_openAction->setEnabled(false);
228 emit clipSelected(NULL);
229 m_editAction->setEnabled(false);
230 m_deleteAction->setEnabled(false);
231 m_openAction->setEnabled(false);
232 m_reloadAction->setEnabled(false);
236 void ProjectList::slotPauseMonitor()
238 if (m_render) m_render->pause();
241 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
243 ProjectItem *item = getItemById(id);
245 slotUpdateClipProperties(item, properties);
246 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata")) slotRefreshClipThumbnail(item);
247 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
251 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
254 if (!clip->isGroup()) clip->setProperties(properties);
255 if (properties.contains("name")) {
256 listView->blockSignals(true);
257 clip->setText(1, properties.value("name"));
258 listView->blockSignals(false);
259 emit clipNameChanged(clip->clipId(), properties.value("name"));
261 if (properties.contains("description")) {
262 CLIPTYPE type = clip->clipType();
263 listView->blockSignals(true);
264 clip->setText(2, properties.value("description"));
265 listView->blockSignals(false);
266 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
267 // Use Nepomuk system to store clip description
268 Nepomuk::Resource f(clip->clipUrl().path());
269 f.setDescription(properties.value("description"));
271 emit projectModified();
275 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
277 ProjectItem *clip = static_cast <ProjectItem*>(item);
279 if (clip->referencedClip()) {
280 QMap <QString, QString> oldprops;
281 QMap <QString, QString> newprops;
282 oldprops["description"] = clip->referencedClip()->getProperty("description");
283 newprops["description"] = item->text(2);
284 slotUpdateClipProperties(clip, newprops);
285 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
286 m_commandStack->push(command);
288 } else if (column == 1) {
289 if (clip->isGroup()) {
290 editFolder(item->text(1), clip->groupName(), clip->clipId());
291 clip->setGroupName(item->text(1));
292 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
293 const int children = item->childCount();
294 for (int i = 0; i < children; i++) {
295 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
296 child->setProperty("groupname", item->text(1));
299 if (clip->referencedClip()) {
300 QMap <QString, QString> oldprops;
301 QMap <QString, QString> newprops;
302 oldprops["name"] = clip->referencedClip()->getProperty("name");
303 newprops["name"] = item->text(1);
304 slotUpdateClipProperties(clip, newprops);
305 emit projectModified();
306 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
307 m_commandStack->push(command);
313 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
319 m_editAction->setEnabled(enable);
320 m_deleteAction->setEnabled(enable);
321 m_reloadAction->setEnabled(enable);
323 ProjectItem *clip = static_cast <ProjectItem*>(item);
324 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
325 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
326 m_openAction->setEnabled(true);
327 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
328 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
329 m_openAction->setEnabled(true);
330 } else m_openAction->setEnabled(false);
331 } else m_openAction->setEnabled(false);
335 void ProjectList::slotRemoveClip()
337 if (!listView->currentItem()) return;
339 QMap <QString, QString> folderids;
340 QList<QTreeWidgetItem *> selected = listView->selectedItems();
342 for (int i = 0; i < selected.count(); i++) {
343 item = static_cast <ProjectItem *>(selected.at(i));
344 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
345 else ids << item->clipId();
346 if (item->numReferences() > 0) {
347 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;
348 } else if (item->isGroup() && item->childCount() > 0) {
349 int children = item->childCount();
350 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;
351 for (int i = 0; i < children; ++i) {
352 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
353 ids << child->clipId();
357 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
358 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
359 if (listView->topLevelItemCount() == 0) {
360 m_editAction->setEnabled(false);
361 m_deleteAction->setEnabled(false);
362 m_openAction->setEnabled(false);
363 m_reloadAction->setEnabled(false);
367 void ProjectList::selectItemById(const QString &clipId)
369 ProjectItem *item = getItemById(clipId);
370 if (item) listView->setCurrentItem(item);
374 void ProjectList::slotDeleteClip(const QString &clipId)
376 ProjectItem *item = getItemById(clipId);
378 kDebug() << "/// Cannot find clip to delete";
385 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
387 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
388 m_commandStack->push(command);
389 m_doc->setModified(true);
392 void ProjectList::slotAddFolder()
394 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
395 m_commandStack->push(command);
398 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
401 ProjectItem *item = getFolderItemById(clipId);
403 m_doc->clipManager()->deleteFolder(clipId);
408 ProjectItem *item = getFolderItemById(clipId);
409 QTreeWidgetItemIterator it(listView);
411 listView->blockSignals(true);
412 item->setGroupName(foldername);
413 listView->blockSignals(false);
414 m_doc->clipManager()->addFolder(clipId, foldername);
415 const int children = item->childCount();
416 for (int i = 0; i < children; i++) {
417 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
418 child->setProperty("groupname", foldername);
423 text << QString() << foldername;
424 listView->blockSignals(true);
425 (void) new ProjectItem(listView, text, clipId);
426 m_doc->clipManager()->addFolder(clipId, foldername);
427 listView->blockSignals(false);
434 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
436 QMapIterator<QString, QString> i(map);
437 QUndoCommand *delCommand = new QUndoCommand();
438 delCommand->setText(i18n("Delete Folder"));
439 while (i.hasNext()) {
441 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
443 m_commandStack->push(delCommand);
444 m_doc->setModified(true);
447 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
449 if (getProperties) listView->setEnabled(false);
450 listView->blockSignals(true);
451 const QString parent = clip->getProperty("groupid");
452 kDebug() << "Adding clip with groupid: " << parent;
453 ProjectItem *item = NULL;
454 if (!parent.isEmpty()) {
455 ProjectItem *parentitem = getFolderItemById(parent);
458 QString groupName = clip->getProperty("groupname");
459 //kDebug() << "Adding clip to new group: " << groupName;
460 if (groupName.isEmpty()) groupName = i18n("Folder");
461 text << QString() << groupName;
462 parentitem = new ProjectItem(listView, text, parent);
464 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
466 if (parentitem) item = new ProjectItem(parentitem, clip);
468 if (item == NULL) item = new ProjectItem(listView, clip);
470 KUrl url = clip->fileURL();
471 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
472 // if file has Nepomuk comment, use it
473 Nepomuk::Resource f(url.path());
474 QString annotation = f.description();
475 if (!annotation.isEmpty()) item->setText(2, annotation);
476 item->setText(3, QString::number(f.rating()));
478 listView->blockSignals(false);
481 void ProjectList::slotResetProjectList()
484 emit clipSelected(NULL);
485 m_thumbnailQueue.clear();
490 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
492 kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
493 m_infoQueue.insert(id, xml);
494 listView->setEnabled(false);
495 if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
498 void ProjectList::slotProcessNextClipInQueue()
500 if (m_infoQueue.isEmpty()) {
501 listView->setEnabled(true);
504 QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
505 if (i != m_infoQueue.constEnd()) {
506 const QDomElement dom = i.value();
507 const QString id = i.key();
508 m_infoQueue.remove(i.key());
509 emit getFileProperties(dom, id, true);
511 if (m_infoQueue.isEmpty()) listView->setEnabled(true);
514 void ProjectList::slotUpdateClip(const QString &id)
516 ProjectItem *item = getItemById(id);
517 listView->blockSignals(true);
518 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
519 listView->blockSignals(false);
522 void ProjectList::updateAllClips()
524 QTreeWidgetItemIterator it(listView);
526 ProjectItem *item = static_cast <ProjectItem *>(*it);
527 if (!item->isGroup()) {
528 if (item->referencedClip()->producer() == NULL) {
529 DocClipBase *clip = item->referencedClip();
530 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
531 // regenerate text clip image if required
532 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
534 doc.setContent(clip->getProperty("xmldata"));
536 QImage pix = dia_ui->renderedPixmap();
537 pix.save(clip->fileURL().path());
540 requestClipInfo(clip->toXML(), clip->getId());
542 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
543 if (QFile::exists(cachedPixmap)) {
544 //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
545 listView->blockSignals(true);
546 item->setIcon(0, QPixmap(cachedPixmap));
547 listView->blockSignals(false);
548 } else requestClipThumbnail(item->clipId());
550 if (item->data(1, DurationRole).toString().isEmpty()) {
551 listView->blockSignals(true);
552 item->changeDuration(item->referencedClip()->producer()->get_playtime());
553 listView->blockSignals(false);
556 listView->blockSignals(true);
557 item->setData(1, UsageRole, QString::number(item->numReferences()));
558 listView->blockSignals(false);
559 qApp->processEvents();
563 QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
566 void ProjectList::slotAddClip(const QList <QUrl> givenList, QString group)
568 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
570 if (givenList.isEmpty()) {
571 // Build list of mime types
572 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";
574 QString allExtensions;
575 foreach(const QString& mimeType, mimeTypes) {
576 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
578 allExtensions.append(mime->patterns().join(" "));
579 allExtensions.append(' ');
582 QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files");
583 dialogFilter.append("\n*" + QLatin1Char('|') + i18n("All Files"));
584 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
587 for (int i = 0; i < givenList.count(); i++)
588 list << givenList.at(i);
590 if (list.isEmpty()) return;
593 if (group.isEmpty()) {
594 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
595 if (item && !item->isGroup()) {
596 while (item->parent()) {
597 item = static_cast <ProjectItem*>(item->parent());
598 if (item->isGroup()) break;
601 if (item && item->isGroup()) {
602 group = item->groupName();
603 groupId = item->clipId();
606 m_doc->slotAddClipList(list, group, groupId);
609 void ProjectList::slotRemoveInvalidClip(const QString &id)
611 ProjectItem *item = getItemById(id);
613 const QString path = item->referencedClip()->fileURL().path();
614 if (!path.isEmpty()) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
617 m_doc->deleteProjectClip(ids);
619 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
620 else listView->setEnabled(true);
623 void ProjectList::slotAddColorClip()
625 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
626 QDialog *dia = new QDialog(this);
627 Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
628 dia_ui->setupUi(dia);
629 dia_ui->clip_name->setText(i18n("Color Clip"));
630 dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
631 if (dia->exec() == QDialog::Accepted) {
632 QString color = dia_ui->clip_color->color().name();
633 color = color.replace(0, 1, "0x") + "ff";
637 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
638 if (item && !item->isGroup()) {
639 while (item->parent()) {
640 item = static_cast <ProjectItem*>(item->parent());
641 if (item->isGroup()) break;
644 if (item && item->isGroup()) {
645 group = item->groupName();
646 groupId = item->clipId();
649 m_doc->clipManager()->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId);
650 m_doc->setModified(true);
657 void ProjectList::slotAddSlideshowClip()
659 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
660 SlideshowClip *dia = new SlideshowClip(this);
662 if (dia->exec() == QDialog::Accepted) {
666 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
667 if (item && !item->isGroup()) {
668 while (item->parent()) {
669 item = static_cast <ProjectItem*>(item->parent());
670 if (item->isGroup()) break;
673 if (item && item->isGroup()) {
674 group = item->groupName();
675 groupId = item->clipId();
678 m_doc->clipManager()->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId);
679 m_doc->setModified(true);
684 void ProjectList::slotAddTitleClip()
688 ProjectItem *item = static_cast <ProjectItem*>(listView->currentItem());
689 if (item && !item->isGroup()) {
690 while (item->parent()) {
691 item = static_cast <ProjectItem*>(item->parent());
692 if (item->isGroup()) break;
695 if (item && item->isGroup()) {
696 group = item->groupName();
697 groupId = item->clipId();
700 m_doc->slotCreateTextClip(group, groupId);
703 void ProjectList::setDocument(KdenliveDoc *doc)
705 listView->blockSignals(true);
707 emit clipSelected(NULL);
708 m_thumbnailQueue.clear();
711 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
712 QMapIterator<QString, QString> f(flist);
713 while (f.hasNext()) {
715 (void) new ProjectItem(listView, QStringList() << QString() << f.value(), f.key());
718 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
719 for (int i = 0; i < list.count(); i++) {
720 slotAddClip(list.at(i), false);
724 m_timecode = doc->timecode();
725 m_commandStack = doc->commandStack();
727 QTreeWidgetItem *first = listView->topLevelItem(0);
728 if (first) listView->setCurrentItem(first);
729 listView->blockSignals(false);
730 m_toolbar->setEnabled(true);
733 QDomElement ProjectList::producersList()
736 QDomElement prods = doc.createElement("producerlist");
737 doc.appendChild(prods);
738 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
739 QTreeWidgetItemIterator it(listView);
741 if (!((ProjectItem *)(*it))->isGroup())
742 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
748 void ProjectList::slotCheckForEmptyQueue()
750 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
752 emit loadingIsOver();
753 } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
756 void ProjectList::requestClipThumbnail(const QString &id)
758 m_thumbnailQueue.append(id);
759 if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
762 void ProjectList::slotProcessNextThumbnail()
764 if (m_thumbnailQueue.isEmpty()) {
767 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
770 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
772 ProjectItem *item = getItemById(clipId);
773 if (item) slotRefreshClipThumbnail(item, update);
774 else slotProcessNextThumbnail();
777 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
780 if (!item->referencedClip()) return;
782 int width = (int)(height * m_render->dar());
783 DocClipBase *clip = item->referencedClip();
784 if (!clip) slotProcessNextThumbnail();
786 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
787 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
788 listView->blockSignals(true);
789 item->setIcon(0, pix);
790 listView->blockSignals(false);
791 m_doc->cachePixmap(item->getClipHash(), pix);
792 if (update) emit projectModified();
793 if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
797 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
799 ProjectItem *item = getItemById(clipId);
800 if (item && producer) {
801 listView->blockSignals(true);
802 item->setProperties(properties, metadata);
803 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
804 if (replace) item->referencedClip()->setProducer(producer);
805 emit receivedClipDuration(clipId, item->clipMaxDuration());
806 listView->blockSignals(false);
807 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
808 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
809 else listView->setEnabled(true);
812 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
814 ProjectItem *item = getItemById(clipId);
816 listView->blockSignals(true);
817 item->setIcon(0, pix);
818 m_doc->cachePixmap(item->getClipHash(), pix);
819 listView->blockSignals(false);
823 ProjectItem *ProjectList::getItemById(const QString &id)
826 QTreeWidgetItemIterator it(listView);
828 item = static_cast<ProjectItem *>(*it);
829 if (item->clipId() == id && item->clipType() != FOLDER)
836 ProjectItem *ProjectList::getFolderItemById(const QString &id)
839 QTreeWidgetItemIterator it(listView);
841 item = static_cast<ProjectItem *>(*it);
842 if (item->clipId() == id && item->clipType() == FOLDER)
849 void ProjectList::slotSelectClip(const QString &ix)
851 ProjectItem *clip = getItemById(ix);
853 listView->setCurrentItem(clip);
854 listView->scrollToItem(clip);
855 m_editAction->setEnabled(true);
856 m_deleteAction->setEnabled(true);
857 m_reloadAction->setEnabled(true);
858 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
859 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
860 m_openAction->setEnabled(true);
861 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
862 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
863 m_openAction->setEnabled(true);
864 } else m_openAction->setEnabled(false);
868 #include "projectlist.moc"