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);
80 searchView->setTreeWidget(m_listView);
82 m_addButton = new QToolButton(m_toolbar);
83 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
84 m_toolbar->addWidget(m_addButton);
86 layout->addWidget(m_toolbar);
87 layout->addWidget(m_listView);
92 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
93 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
94 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
95 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
96 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
97 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &)));
98 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
99 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
101 ItemDelegate *listViewDelegate = new ItemDelegate(m_listView);
102 m_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 m_listView->header()->saveState();
174 void ProjectList::setHeaderInfo(const QByteArray &state)
176 m_listView->header()->restoreState(state);
179 void ProjectList::slotEditClip()
181 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
182 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
183 if (item && !item->isGroup()) {
184 emit clipSelected(item->referencedClip());
185 emit showClipProperties(item->referencedClip());
189 void ProjectList::slotOpenClip()
191 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
192 if (item && !item->isGroup()) {
193 if (item->clipType() == IMAGE) {
194 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
195 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
197 if (item->clipType() == AUDIO) {
198 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
199 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
204 void ProjectList::slotReloadClip()
206 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
207 if (item && !item->isGroup()) {
208 if (item->clipType() == IMAGE) {
209 item->referencedClip()->producer()->set("force_reload", 1);
211 emit getFileProperties(item->toXml(), item->clipId(), false);
215 void ProjectList::setRenderer(Render *projectRender)
217 m_render = projectRender;
218 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
221 void ProjectList::slotClipSelected()
223 if (m_listView->currentItem()) {
224 ProjectItem *clip = static_cast <ProjectItem*>(m_listView->currentItem());
225 if (!clip->isGroup()) {
226 m_selectedItem = clip;
227 emit clipSelected(clip->referencedClip());
229 m_editAction->setEnabled(true);
230 m_deleteAction->setEnabled(true);
231 m_reloadAction->setEnabled(true);
232 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
233 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
234 m_openAction->setEnabled(true);
235 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
236 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
237 m_openAction->setEnabled(true);
238 } else m_openAction->setEnabled(false);
240 emit clipSelected(NULL);
241 m_editAction->setEnabled(false);
242 m_deleteAction->setEnabled(false);
243 m_openAction->setEnabled(false);
244 m_reloadAction->setEnabled(false);
248 void ProjectList::slotPauseMonitor()
250 if (m_render) m_render->pause();
253 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
255 ProjectItem *item = getItemById(id);
257 slotUpdateClipProperties(item, properties);
258 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata")) slotRefreshClipThumbnail(item);
259 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
263 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
266 if (!clip->isGroup()) clip->setProperties(properties);
267 if (properties.contains("name")) {
268 m_listView->blockSignals(true);
269 clip->setText(1, properties.value("name"));
270 m_listView->blockSignals(false);
271 emit clipNameChanged(clip->clipId(), properties.value("name"));
273 if (properties.contains("description")) {
274 CLIPTYPE type = clip->clipType();
275 m_listView->blockSignals(true);
276 clip->setText(2, properties.value("description"));
277 m_listView->blockSignals(false);
278 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
279 // Use Nepomuk system to store clip description
280 Nepomuk::Resource f(clip->clipUrl().path());
281 f.setDescription(properties.value("description"));
283 emit projectModified();
287 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
289 ProjectItem *clip = static_cast <ProjectItem*>(item);
291 if (clip->referencedClip()) {
292 QMap <QString, QString> oldprops;
293 QMap <QString, QString> newprops;
294 oldprops["description"] = clip->referencedClip()->getProperty("description");
295 newprops["description"] = item->text(2);
296 slotUpdateClipProperties(clip, newprops);
297 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
298 m_commandStack->push(command);
300 } else if (column == 1) {
301 if (clip->isGroup()) {
302 editFolder(item->text(1), clip->groupName(), clip->clipId());
303 clip->setGroupName(item->text(1));
304 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
305 const int children = item->childCount();
306 for (int i = 0; i < children; i++) {
307 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
308 child->setProperty("groupname", item->text(1));
311 if (clip->referencedClip()) {
312 QMap <QString, QString> oldprops;
313 QMap <QString, QString> newprops;
314 oldprops["name"] = clip->referencedClip()->getProperty("name");
315 newprops["name"] = item->text(1);
316 slotUpdateClipProperties(clip, newprops);
317 emit projectModified();
318 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
319 m_commandStack->push(command);
325 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
331 m_editAction->setEnabled(enable);
332 m_deleteAction->setEnabled(enable);
333 m_reloadAction->setEnabled(enable);
335 ProjectItem *clip = static_cast <ProjectItem*>(item);
336 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
337 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
338 m_openAction->setEnabled(true);
339 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
340 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
341 m_openAction->setEnabled(true);
342 } else m_openAction->setEnabled(false);
343 } else m_openAction->setEnabled(false);
347 void ProjectList::slotRemoveClip()
349 if (!m_listView->currentItem()) return;
351 QMap <QString, QString> folderids;
352 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
354 for (int i = 0; i < selected.count(); i++) {
355 item = static_cast <ProjectItem *>(selected.at(i));
356 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
357 else ids << item->clipId();
358 if (item->numReferences() > 0) {
359 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;
360 } else if (item->isGroup() && item->childCount() > 0) {
361 int children = item->childCount();
362 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;
363 for (int i = 0; i < children; ++i) {
364 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
365 ids << child->clipId();
369 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
370 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
371 if (m_listView->topLevelItemCount() == 0) {
372 m_editAction->setEnabled(false);
373 m_deleteAction->setEnabled(false);
374 m_openAction->setEnabled(false);
375 m_reloadAction->setEnabled(false);
379 void ProjectList::selectItemById(const QString &clipId)
381 ProjectItem *item = getItemById(clipId);
382 if (item) m_listView->setCurrentItem(item);
386 void ProjectList::slotDeleteClip(const QString &clipId)
388 ProjectItem *item = getItemById(clipId);
390 kDebug() << "/// Cannot find clip to delete";
397 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
399 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
400 m_commandStack->push(command);
401 m_doc->setModified(true);
404 void ProjectList::slotAddFolder()
406 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
407 m_commandStack->push(command);
410 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
413 ProjectItem *item = getFolderItemById(clipId);
415 m_doc->clipManager()->deleteFolder(clipId);
420 ProjectItem *item = getFolderItemById(clipId);
421 QTreeWidgetItemIterator it(m_listView);
423 m_listView->blockSignals(true);
424 item->setGroupName(foldername);
425 m_listView->blockSignals(false);
426 m_doc->clipManager()->addFolder(clipId, foldername);
427 const int children = item->childCount();
428 for (int i = 0; i < children; i++) {
429 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
430 child->setProperty("groupname", foldername);
435 text << QString() << foldername;
436 m_listView->blockSignals(true);
437 (void) new ProjectItem(m_listView, text, clipId);
438 m_doc->clipManager()->addFolder(clipId, foldername);
439 m_listView->blockSignals(false);
446 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
448 QMapIterator<QString, QString> i(map);
449 QUndoCommand *delCommand = new QUndoCommand();
450 delCommand->setText(i18n("Delete Folder"));
451 while (i.hasNext()) {
453 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
455 m_commandStack->push(delCommand);
456 m_doc->setModified(true);
459 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
461 if (getProperties) m_listView->setEnabled(false);
462 m_listView->blockSignals(true);
463 const QString parent = clip->getProperty("groupid");
464 kDebug() << "Adding clip with groupid: " << parent;
465 ProjectItem *item = NULL;
466 if (!parent.isEmpty()) {
467 ProjectItem *parentitem = getFolderItemById(parent);
470 QString groupName = clip->getProperty("groupname");
471 //kDebug() << "Adding clip to new group: " << groupName;
472 if (groupName.isEmpty()) groupName = i18n("Folder");
473 text << QString() << groupName;
474 parentitem = new ProjectItem(m_listView, text, parent);
476 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
478 if (parentitem) item = new ProjectItem(parentitem, clip);
480 if (item == NULL) item = new ProjectItem(m_listView, clip);
482 KUrl url = clip->fileURL();
483 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
484 // if file has Nepomuk comment, use it
485 Nepomuk::Resource f(url.path());
486 QString annotation = f.description();
487 if (!annotation.isEmpty()) item->setText(2, annotation);
488 item->setText(3, QString::number(f.rating()));
490 m_listView->blockSignals(false);
493 void ProjectList::slotResetProjectList()
496 emit clipSelected(NULL);
497 m_thumbnailQueue.clear();
502 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
504 kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
505 m_infoQueue.insert(id, xml);
506 m_listView->setEnabled(false);
507 if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
510 void ProjectList::slotProcessNextClipInQueue()
512 if (m_infoQueue.isEmpty()) {
513 m_listView->setEnabled(true);
516 QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
517 if (i != m_infoQueue.constEnd()) {
518 const QDomElement dom = i.value();
519 const QString id = i.key();
520 m_infoQueue.remove(i.key());
521 emit getFileProperties(dom, id, true);
523 if (m_infoQueue.isEmpty()) m_listView->setEnabled(true);
526 void ProjectList::slotUpdateClip(const QString &id)
528 ProjectItem *item = getItemById(id);
529 m_listView->blockSignals(true);
530 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
531 m_listView->blockSignals(false);
534 void ProjectList::updateAllClips()
536 QTreeWidgetItemIterator it(m_listView);
538 ProjectItem *item = static_cast <ProjectItem *>(*it);
539 if (!item->isGroup()) {
540 if (item->referencedClip()->producer() == NULL) {
541 DocClipBase *clip = item->referencedClip();
542 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
543 // regenerate text clip image if required
544 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
546 doc.setContent(clip->getProperty("xmldata"));
548 QImage pix = dia_ui->renderedPixmap();
549 pix.save(clip->fileURL().path());
552 if (clip->isPlaceHolder() == false) requestClipInfo(clip->toXML(), clip->getId());
553 else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
555 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
556 if (QFile::exists(cachedPixmap)) {
557 //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
558 m_listView->blockSignals(true);
559 item->setIcon(0, QPixmap(cachedPixmap));
560 m_listView->blockSignals(false);
561 } else requestClipThumbnail(item->clipId());
563 if (item->data(1, DurationRole).toString().isEmpty()) {
564 m_listView->blockSignals(true);
565 item->changeDuration(item->referencedClip()->producer()->get_playtime());
566 m_listView->blockSignals(false);
569 m_listView->blockSignals(true);
570 item->setData(1, UsageRole, QString::number(item->numReferences()));
571 m_listView->blockSignals(false);
572 qApp->processEvents();
576 QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
579 void ProjectList::slotAddClip(const QList <QUrl> givenList, QString group)
581 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
583 if (givenList.isEmpty()) {
584 // Build list of mime types
585 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";
587 QString allExtensions;
588 foreach(const QString& mimeType, mimeTypes) {
589 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
591 allExtensions.append(mime->patterns().join(" "));
592 allExtensions.append(' ');
595 QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files");
596 dialogFilter.append("\n*" + QLatin1Char('|') + i18n("All Files"));
597 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
600 for (int i = 0; i < givenList.count(); i++)
601 list << givenList.at(i);
603 if (list.isEmpty()) return;
606 if (group.isEmpty()) {
607 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
608 if (item && !item->isGroup()) {
609 while (item->parent()) {
610 item = static_cast <ProjectItem*>(item->parent());
611 if (item->isGroup()) break;
614 if (item && item->isGroup()) {
615 group = item->groupName();
616 groupId = item->clipId();
619 m_doc->slotAddClipList(list, group, groupId);
622 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
624 ProjectItem *item = getItemById(id);
626 const QString path = item->referencedClip()->fileURL().path();
627 if (!path.isEmpty()) {
628 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
630 if (KMessageBox::questionYesNo(this, i18n("Clip <b>%1</b><br>is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes) replace = true;
635 if (replace) m_doc->deleteProjectClip(ids);
637 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
638 else m_listView->setEnabled(true);
641 void ProjectList::slotAddColorClip()
643 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
644 QDialog *dia = new QDialog(this);
645 Ui::ColorClip_UI *dia_ui = new Ui::ColorClip_UI();
646 dia_ui->setupUi(dia);
647 dia_ui->clip_name->setText(i18n("Color Clip"));
648 dia_ui->clip_duration->setText(KdenliveSettings::color_duration());
649 if (dia->exec() == QDialog::Accepted) {
650 QString color = dia_ui->clip_color->color().name();
651 color = color.replace(0, 1, "0x") + "ff";
655 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
656 if (item && !item->isGroup()) {
657 while (item->parent()) {
658 item = static_cast <ProjectItem*>(item->parent());
659 if (item->isGroup()) break;
662 if (item && item->isGroup()) {
663 group = item->groupName();
664 groupId = item->clipId();
667 m_doc->clipManager()->slotAddColorClipFile(dia_ui->clip_name->text(), color, dia_ui->clip_duration->text(), group, groupId);
668 m_doc->setModified(true);
675 void ProjectList::slotAddSlideshowClip()
677 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
678 SlideshowClip *dia = new SlideshowClip(this);
680 if (dia->exec() == QDialog::Accepted) {
684 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
685 if (item && !item->isGroup()) {
686 while (item->parent()) {
687 item = static_cast <ProjectItem*>(item->parent());
688 if (item->isGroup()) break;
691 if (item && item->isGroup()) {
692 group = item->groupName();
693 groupId = item->clipId();
696 m_doc->clipManager()->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), group, groupId);
697 m_doc->setModified(true);
702 void ProjectList::slotAddTitleClip()
706 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
707 if (item && !item->isGroup()) {
708 while (item->parent()) {
709 item = static_cast <ProjectItem*>(item->parent());
710 if (item->isGroup()) break;
713 if (item && item->isGroup()) {
714 group = item->groupName();
715 groupId = item->clipId();
718 m_doc->slotCreateTextClip(group, groupId);
721 void ProjectList::setDocument(KdenliveDoc *doc)
723 m_listView->blockSignals(true);
725 emit clipSelected(NULL);
726 m_thumbnailQueue.clear();
729 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
730 QMapIterator<QString, QString> f(flist);
731 while (f.hasNext()) {
733 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
736 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
737 for (int i = 0; i < list.count(); i++) {
738 slotAddClip(list.at(i), false);
742 m_timecode = doc->timecode();
743 m_commandStack = doc->commandStack();
745 QTreeWidgetItem *first = m_listView->topLevelItem(0);
746 if (first) m_listView->setCurrentItem(first);
747 m_listView->blockSignals(false);
748 m_toolbar->setEnabled(true);
751 QDomElement ProjectList::producersList()
754 QDomElement prods = doc.createElement("producerlist");
755 doc.appendChild(prods);
756 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
757 QTreeWidgetItemIterator it(m_listView);
759 if (!((ProjectItem *)(*it))->isGroup())
760 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
766 void ProjectList::slotCheckForEmptyQueue()
768 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
770 emit loadingIsOver();
771 } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
774 void ProjectList::requestClipThumbnail(const QString &id)
776 m_thumbnailQueue.append(id);
777 if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
780 void ProjectList::slotProcessNextThumbnail()
782 if (m_thumbnailQueue.isEmpty()) {
785 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
788 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
790 ProjectItem *item = getItemById(clipId);
791 if (item) slotRefreshClipThumbnail(item, update);
792 else slotProcessNextThumbnail();
795 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
798 if (!item->referencedClip()) return;
800 int width = (int)(height * m_render->dar());
801 DocClipBase *clip = item->referencedClip();
802 if (!clip) slotProcessNextThumbnail();
804 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
805 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
806 m_listView->blockSignals(true);
807 item->setIcon(0, pix);
808 m_listView->blockSignals(false);
809 m_doc->cachePixmap(item->getClipHash(), pix);
810 if (update) emit projectModified();
811 if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
815 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
817 ProjectItem *item = getItemById(clipId);
818 if (item && producer) {
819 m_listView->blockSignals(true);
820 item->setProperties(properties, metadata);
821 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
822 if (replace) item->referencedClip()->setProducer(producer);
824 // Check if duration changed.
825 emit receivedClipDuration(clipId);
828 m_listView->blockSignals(false);
829 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
830 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
831 else m_listView->setEnabled(true);
834 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
836 ProjectItem *item = getItemById(clipId);
838 m_listView->blockSignals(true);
839 item->setIcon(0, pix);
840 m_doc->cachePixmap(item->getClipHash(), pix);
841 m_listView->blockSignals(false);
845 ProjectItem *ProjectList::getItemById(const QString &id)
848 QTreeWidgetItemIterator it(m_listView);
850 item = static_cast<ProjectItem *>(*it);
851 if (item->clipId() == id && item->clipType() != FOLDER)
858 ProjectItem *ProjectList::getFolderItemById(const QString &id)
861 QTreeWidgetItemIterator it(m_listView);
863 item = static_cast<ProjectItem *>(*it);
864 if (item->clipId() == id && item->clipType() == FOLDER)
871 void ProjectList::slotSelectClip(const QString &ix)
873 ProjectItem *clip = getItemById(ix);
875 m_listView->setCurrentItem(clip);
876 m_listView->scrollToItem(clip);
877 m_editAction->setEnabled(true);
878 m_deleteAction->setEnabled(true);
879 m_reloadAction->setEnabled(true);
880 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
881 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
882 m_openAction->setEnabled(true);
883 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
884 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
885 m_openAction->setEnabled(true);
886 } else m_openAction->setEnabled(false);
890 #include "projectlist.moc"