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) :
72 m_listView = new ProjectListView(this);;
73 QVBoxLayout *layout = new QVBoxLayout;
74 layout->setContentsMargins(0, 0, 0, 0);
77 KTreeWidgetSearchLine *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(m_listView);
88 //m_toolbar->setEnabled(false);
91 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
92 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
93 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
94 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
95 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
96 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &)));
97 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
98 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
100 ItemDelegate *listViewDelegate = new ItemDelegate(m_listView);
101 m_listView->setItemDelegate(listViewDelegate);
103 if (KdenliveSettings::activate_nepomuk()) {
104 Nepomuk::ResourceManager::instance()->init();
105 if (!Nepomuk::ResourceManager::instance()->initialized()) {
106 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
107 KdenliveSettings::setActivate_nepomuk(false);
112 ProjectList::~ProjectList()
118 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
120 QList <QAction *> actions = addMenu->actions();
121 for (int i = 0; i < actions.count(); i++) {
122 if (actions.at(i)->data().toString() == "clip_properties") {
123 m_editAction = actions.at(i);
124 m_toolbar->addAction(m_editAction);
127 } else if (actions.at(i)->data().toString() == "delete_clip") {
128 m_deleteAction = actions.at(i);
129 m_toolbar->addAction(m_deleteAction);
132 } else if (actions.at(i)->data().toString() == "edit_clip") {
133 m_openAction = actions.at(i);
136 } else if (actions.at(i)->data().toString() == "reload_clip") {
137 m_reloadAction = actions.at(i);
143 QMenu *m = new QMenu();
144 m->addActions(actions);
145 m_addButton->setMenu(m);
146 m_addButton->setDefaultAction(defaultAction);
147 m_menu = new QMenu();
148 m_menu->addActions(addMenu->actions());
151 void ProjectList::setupGeneratorMenu(QMenu *addMenu)
153 if (!addMenu) return;
154 QMenu *menu = m_addButton->menu();
155 menu->addMenu(addMenu);
156 m_addButton->setMenu(menu);
158 m_menu->addMenu(addMenu);
159 if (addMenu->isEmpty()) addMenu->setEnabled(false);
160 m_menu->addAction(m_reloadAction);
161 m_menu->addAction(m_editAction);
162 m_menu->addAction(m_openAction);
163 m_menu->addAction(m_deleteAction);
164 m_menu->insertSeparator(m_deleteAction);
168 QByteArray ProjectList::headerInfo()
170 return m_listView->header()->saveState();
173 void ProjectList::setHeaderInfo(const QByteArray &state)
175 m_listView->header()->restoreState(state);
178 void ProjectList::slotEditClip()
180 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
181 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
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*>(m_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*>(m_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 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
220 void ProjectList::slotClipSelected()
222 if (m_listView->currentItem()) {
223 ProjectItem *clip = static_cast <ProjectItem*>(m_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 m_listView->blockSignals(true);
268 clip->setText(1, properties.value("name"));
269 m_listView->blockSignals(false);
270 emit clipNameChanged(clip->clipId(), properties.value("name"));
272 if (properties.contains("description")) {
273 CLIPTYPE type = clip->clipType();
274 m_listView->blockSignals(true);
275 clip->setText(2, properties.value("description"));
276 m_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 (!m_listView->currentItem()) return;
350 QMap <QString, QString> folderids;
351 QList<QTreeWidgetItem *> selected = m_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 (m_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) m_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(m_listView);
422 m_listView->blockSignals(true);
423 item->setGroupName(foldername);
424 m_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 m_listView->blockSignals(true);
436 (void) new ProjectItem(m_listView, text, clipId);
437 m_doc->clipManager()->addFolder(clipId, foldername);
438 m_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) m_listView->setEnabled(false);
461 m_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(m_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(m_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 m_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 m_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 m_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()) m_listView->setEnabled(true);
525 void ProjectList::slotUpdateClip(const QString &id)
527 ProjectItem *item = getItemById(id);
528 m_listView->blockSignals(true);
529 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
530 m_listView->blockSignals(false);
533 void ProjectList::updateAllClips()
535 QTreeWidgetItemIterator it(m_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 if (clip->isPlaceHolder() == false) requestClipInfo(clip->toXML(), clip->getId());
552 else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
554 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
555 if (QFile::exists(cachedPixmap)) {
556 //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
557 m_listView->blockSignals(true);
558 item->setIcon(0, QPixmap(cachedPixmap));
559 m_listView->blockSignals(false);
560 } else requestClipThumbnail(item->clipId());
562 if (item->data(1, DurationRole).toString().isEmpty()) {
563 m_listView->blockSignals(true);
564 item->changeDuration(item->referencedClip()->producer()->get_playtime());
565 m_listView->blockSignals(false);
568 m_listView->blockSignals(true);
569 item->setData(1, UsageRole, QString::number(item->numReferences()));
570 m_listView->blockSignals(false);
571 qApp->processEvents();
575 QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
578 void ProjectList::slotAddClip(const QList <QUrl> givenList, QString group)
580 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
582 if (givenList.isEmpty()) {
583 // Build list of mime types
584 QStringList mimeTypes = QStringList() << "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-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";
586 QString allExtensions;
587 foreach(const QString& mimeType, mimeTypes) {
588 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
590 allExtensions.append(mime->patterns().join(" "));
591 allExtensions.append(' ');
594 QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files");
595 dialogFilter.append("\n*" + QLatin1Char('|') + i18n("All Files"));
596 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
599 for (int i = 0; i < givenList.count(); i++)
600 list << givenList.at(i);
602 if (list.isEmpty()) return;
605 if (group.isEmpty()) {
606 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
607 if (item && !item->isGroup()) {
608 while (item->parent()) {
609 item = static_cast <ProjectItem*>(item->parent());
610 if (item->isGroup()) break;
613 if (item && item->isGroup()) {
614 group = item->groupName();
615 groupId = item->clipId();
618 m_doc->slotAddClipList(list, group, groupId);
621 void ProjectList::slotRemoveInvalidClip(const QString &id)
623 ProjectItem *item = getItemById(id);
625 const QString path = item->referencedClip()->fileURL().path();
626 if (!path.isEmpty()) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
629 m_doc->deleteProjectClip(ids);
631 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
632 else m_listView->setEnabled(true);
635 void ProjectList::slotAddColorClip()
637 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
638 QDialog *dia = new QDialog(this);
639 Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
640 dia_ui->setupUi(dia);
641 dia_ui->clip_name->setText(i18n("Color Clip"));
642 dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
643 if (dia->exec() == QDialog::Accepted) {
644 QString color = dia_ui->clip_color->color().name();
645 color = color.replace(0, 1, "0x") + "ff";
649 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
650 if (item && !item->isGroup()) {
651 while (item->parent()) {
652 item = static_cast <ProjectItem*>(item->parent());
653 if (item->isGroup()) break;
656 if (item && item->isGroup()) {
657 group = item->groupName();
658 groupId = item->clipId();
661 m_doc->clipManager()->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId);
662 m_doc->setModified(true);
669 void ProjectList::slotAddSlideshowClip()
671 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
672 SlideshowClip *dia = new SlideshowClip(this);
674 if (dia->exec() == QDialog::Accepted) {
678 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
679 if (item && !item->isGroup()) {
680 while (item->parent()) {
681 item = static_cast <ProjectItem*>(item->parent());
682 if (item->isGroup()) break;
685 if (item && item->isGroup()) {
686 group = item->groupName();
687 groupId = item->clipId();
690 m_doc->clipManager()->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId);
691 m_doc->setModified(true);
696 void ProjectList::slotAddTitleClip()
700 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
701 if (item && !item->isGroup()) {
702 while (item->parent()) {
703 item = static_cast <ProjectItem*>(item->parent());
704 if (item->isGroup()) break;
707 if (item && item->isGroup()) {
708 group = item->groupName();
709 groupId = item->clipId();
712 m_doc->slotCreateTextClip(group, groupId);
715 void ProjectList::setDocument(KdenliveDoc *doc)
717 m_listView->blockSignals(true);
719 emit clipSelected(NULL);
720 m_thumbnailQueue.clear();
723 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
724 QMapIterator<QString, QString> f(flist);
725 while (f.hasNext()) {
727 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
730 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
731 for (int i = 0; i < list.count(); i++) {
732 slotAddClip(list.at(i), false);
736 m_timecode = doc->timecode();
737 m_commandStack = doc->commandStack();
739 QTreeWidgetItem *first = m_listView->topLevelItem(0);
740 if (first) m_listView->setCurrentItem(first);
741 m_listView->blockSignals(false);
742 m_toolbar->setEnabled(true);
745 QDomElement ProjectList::producersList()
748 QDomElement prods = doc.createElement("producerlist");
749 doc.appendChild(prods);
750 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
751 QTreeWidgetItemIterator it(m_listView);
753 if (!((ProjectItem *)(*it))->isGroup())
754 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
760 void ProjectList::slotCheckForEmptyQueue()
762 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
764 emit loadingIsOver();
765 } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
768 void ProjectList::requestClipThumbnail(const QString &id)
770 m_thumbnailQueue.append(id);
771 if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
774 void ProjectList::slotProcessNextThumbnail()
776 if (m_thumbnailQueue.isEmpty()) {
779 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
782 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
784 ProjectItem *item = getItemById(clipId);
785 if (item) slotRefreshClipThumbnail(item, update);
786 else slotProcessNextThumbnail();
789 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
792 if (!item->referencedClip()) return;
794 int width = (int)(height * m_render->dar());
795 DocClipBase *clip = item->referencedClip();
796 if (!clip) slotProcessNextThumbnail();
798 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
799 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
800 m_listView->blockSignals(true);
801 item->setIcon(0, pix);
802 m_listView->blockSignals(false);
803 m_doc->cachePixmap(item->getClipHash(), pix);
804 if (update) emit projectModified();
805 if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
809 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
811 ProjectItem *item = getItemById(clipId);
812 if (item && producer) {
813 m_listView->blockSignals(true);
814 item->setProperties(properties, metadata);
815 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
816 if (replace) item->referencedClip()->setProducer(producer);
817 emit receivedClipDuration(clipId, item->clipMaxDuration());
818 m_listView->blockSignals(false);
819 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
820 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
821 else m_listView->setEnabled(true);
824 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
826 ProjectItem *item = getItemById(clipId);
828 m_listView->blockSignals(true);
829 item->setIcon(0, pix);
830 m_doc->cachePixmap(item->getClipHash(), pix);
831 m_listView->blockSignals(false);
835 ProjectItem *ProjectList::getItemById(const QString &id)
838 QTreeWidgetItemIterator it(m_listView);
840 item = static_cast<ProjectItem *>(*it);
841 if (item->clipId() == id && item->clipType() != FOLDER)
848 ProjectItem *ProjectList::getFolderItemById(const QString &id)
851 QTreeWidgetItemIterator it(m_listView);
853 item = static_cast<ProjectItem *>(*it);
854 if (item->clipId() == id && item->clipType() == FOLDER)
861 void ProjectList::slotSelectClip(const QString &ix)
863 ProjectItem *clip = getItemById(ix);
865 m_listView->setCurrentItem(clip);
866 m_listView->scrollToItem(clip);
867 m_editAction->setEnabled(true);
868 m_deleteAction->setEnabled(true);
869 m_reloadAction->setEnabled(true);
870 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
871 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
872 m_openAction->setEnabled(true);
873 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
874 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
875 m_openAction->setEnabled(true);
876 } else m_openAction->setEnabled(false);
880 #include "projectlist.moc"