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 "subprojectitem.h"
23 #include "addfoldercommand.h"
24 #include "kdenlivesettings.h"
25 #include "slideshowclip.h"
26 #include "ui_colorclip_ui.h"
27 #include "titlewidget.h"
28 #include "definitions.h"
29 #include "clipmanager.h"
30 #include "docclipbase.h"
31 #include "kdenlivedoc.h"
34 #include "projectlistview.h"
35 #include "editclipcommand.h"
36 #include "editfoldercommand.h"
37 #include "addclipcutcommand.h"
39 #include "ui_templateclip_ui.h"
44 #include <KFileDialog>
45 #include <KInputDialog>
46 #include <KMessageBox>
47 #include <KIO/NetAccess>
50 #include <nepomuk/global.h>
51 #include <nepomuk/resourcemanager.h>
52 //#include <nepomuk/tag.h>
54 #include <QMouseEvent>
55 #include <QStylePainter>
60 #include <QHeaderView>
62 ProjectList::ProjectList(QWidget *parent) :
71 m_transcodeAction(NULL),
78 m_listView = new ProjectListView(this);;
79 QVBoxLayout *layout = new QVBoxLayout;
80 layout->setContentsMargins(0, 0, 0, 0);
83 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
84 m_toolbar = new QToolBar("projectToolBar", this);
85 m_toolbar->addWidget(searchView);
86 searchView->setTreeWidget(m_listView);
88 m_addButton = new QToolButton(m_toolbar);
89 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
90 m_toolbar->addWidget(m_addButton);
92 layout->addWidget(m_toolbar);
93 layout->addWidget(m_listView);
96 m_queueTimer.setInterval(100);
97 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
98 m_queueTimer.setSingleShot(true);
102 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
103 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
104 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
105 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
106 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
107 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
108 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
109 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
110 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
112 m_listViewDelegate = new ItemDelegate(m_listView);
113 m_listView->setItemDelegate(m_listViewDelegate);
115 if (KdenliveSettings::activate_nepomuk()) {
116 Nepomuk::ResourceManager::instance()->init();
117 if (!Nepomuk::ResourceManager::instance()->initialized()) {
118 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
119 KdenliveSettings::setActivate_nepomuk(false);
124 ProjectList::~ProjectList()
128 m_listView->blockSignals(true);
130 delete m_listViewDelegate;
133 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
135 QList <QAction *> actions = addMenu->actions();
136 for (int i = 0; i < actions.count(); i++) {
137 if (actions.at(i)->data().toString() == "clip_properties") {
138 m_editAction = actions.at(i);
139 m_toolbar->addAction(m_editAction);
142 } else if (actions.at(i)->data().toString() == "delete_clip") {
143 m_deleteAction = actions.at(i);
144 m_toolbar->addAction(m_deleteAction);
147 } else if (actions.at(i)->data().toString() == "edit_clip") {
148 m_openAction = actions.at(i);
151 } else if (actions.at(i)->data().toString() == "reload_clip") {
152 m_reloadAction = actions.at(i);
158 QMenu *m = new QMenu();
159 m->addActions(actions);
160 m_addButton->setMenu(m);
161 m_addButton->setDefaultAction(defaultAction);
162 m_menu = new QMenu();
163 m_menu->addActions(addMenu->actions());
166 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
168 if (!addMenu) return;
169 QMenu *menu = m_addButton->menu();
170 menu->addMenu(addMenu);
171 m_addButton->setMenu(menu);
173 m_menu->addMenu(addMenu);
174 if (addMenu->isEmpty()) addMenu->setEnabled(false);
175 m_menu->addMenu(transcodeMenu);
176 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
177 m_transcodeAction = transcodeMenu;
178 m_menu->addAction(m_reloadAction);
179 m_menu->addAction(m_editAction);
180 m_menu->addAction(m_openAction);
181 m_menu->addAction(m_deleteAction);
182 m_menu->insertSeparator(m_deleteAction);
186 QByteArray ProjectList::headerInfo() const
188 return m_listView->header()->saveState();
191 void ProjectList::setHeaderInfo(const QByteArray &state)
193 m_listView->header()->restoreState(state);
196 void ProjectList::slotEditClip()
199 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
200 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
201 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
202 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
203 if (item && !item->isGroup()) {
204 emit clipSelected(item->referencedClip());
205 emit showClipProperties(item->referencedClip());
209 void ProjectList::slotOpenClip()
212 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
213 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
214 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
215 if (item && !item->isGroup()) {
216 if (item->clipType() == IMAGE) {
217 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
218 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
220 if (item->clipType() == AUDIO) {
221 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
222 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
227 void ProjectList::cleanup()
229 m_listView->clearSelection();
230 QTreeWidgetItemIterator it(m_listView);
233 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
237 item = static_cast <ProjectItem *>(*it);
238 if (!item->isGroup() && item->numReferences() == 0) item->setSelected(true);
244 void ProjectList::trashUnusedClips()
246 QTreeWidgetItemIterator it(m_listView);
251 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
255 item = static_cast <ProjectItem *>(*it);
256 if (!item->isGroup() && item->numReferences() == 0) {
257 ids << item->clipId();
258 KUrl url = item->clipUrl();
259 if (!url.isEmpty()) urls << url.path();
263 urls.removeDuplicates();
264 // Check that we don't use the URL in another clip
265 QTreeWidgetItemIterator it2(m_listView);
267 if ((*it2)->type() == QTreeWidgetItem::UserType + 1) {
271 item = static_cast <ProjectItem *>(*it2);
272 if (item->numReferences() > 0) {
273 KUrl url = item->clipUrl();
274 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
279 m_doc->deleteProjectClip(ids);
280 for (int i = 0; i < urls.count(); i++) {
281 KIO::NetAccess::del(KUrl(urls.at(i)), this);
285 void ProjectList::slotReloadClip(const QString &id)
287 QList<QTreeWidgetItem *> selected;
288 if (id.isEmpty()) selected = m_listView->selectedItems();
289 else selected.append(getItemById(id));
291 for (int i = 0; i < selected.count(); i++) {
292 if (selected.at(i)->type() == QTreeWidgetItem::UserType + 1) continue;
293 item = static_cast <ProjectItem *>(selected.at(i));
294 if (item && !item->isGroup()) {
295 if (item->clipType() == IMAGE) {
296 item->referencedClip()->producer()->set("force_reload", 1);
297 } else if (item->clipType() == TEXT) {
298 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
300 //requestClipInfo(item->toXml(), item->clipId(), true);
301 // Clear the file_hash value, which will cause a complete reload of the clip
302 emit getFileProperties(item->toXml(), item->clipId(), true);
307 void ProjectList::setRenderer(Render *projectRender)
309 m_render = projectRender;
310 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
313 void ProjectList::slotClipSelected()
315 if (m_listView->currentItem()) {
317 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
318 // this is a sub item, use base clip
319 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
320 if (clip == NULL) kDebug() << "-----------ERROR";
321 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
322 emit clipSelected(clip->referencedClip(), sub->zone());
325 clip = static_cast <ProjectItem*>(m_listView->currentItem());
326 if (!clip->isGroup()) {
327 emit clipSelected(clip->referencedClip());
329 m_editAction->setEnabled(true);
330 m_deleteAction->setEnabled(true);
331 m_reloadAction->setEnabled(true);
332 m_transcodeAction->setEnabled(true);
333 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
334 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
335 m_openAction->setEnabled(true);
336 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
337 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
338 m_openAction->setEnabled(true);
339 } else m_openAction->setEnabled(false);
341 emit clipSelected(NULL);
342 m_editAction->setEnabled(false);
343 m_deleteAction->setEnabled(false);
344 m_openAction->setEnabled(false);
345 m_reloadAction->setEnabled(false);
346 m_transcodeAction->setEnabled(false);
350 void ProjectList::slotPauseMonitor()
352 if (m_render) m_render->pause();
355 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
357 ProjectItem *item = getItemById(id);
359 slotUpdateClipProperties(item, properties);
360 if (properties.contains("out")) {
362 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
363 slotRefreshClipThumbnail(item);
369 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
372 if (!clip->isGroup()) clip->setProperties(properties);
373 if (properties.contains("name")) {
374 m_listView->blockSignals(true);
375 clip->setText(1, properties.value("name"));
376 m_listView->blockSignals(false);
377 emit clipNameChanged(clip->clipId(), properties.value("name"));
379 if (properties.contains("description")) {
380 CLIPTYPE type = clip->clipType();
381 m_listView->blockSignals(true);
382 clip->setText(2, properties.value("description"));
383 m_listView->blockSignals(false);
384 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
385 // Use Nepomuk system to store clip description
386 Nepomuk::Resource f(clip->clipUrl().path());
387 f.setDescription(properties.value("description"));
389 emit projectModified();
393 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
395 if (item->type() == QTreeWidgetItem::UserType + 1) {
396 // this is a sub-item
400 ProjectItem *clip = static_cast <ProjectItem*>(item);
402 if (clip->referencedClip()) {
403 QMap <QString, QString> oldprops;
404 QMap <QString, QString> newprops;
405 oldprops["description"] = clip->referencedClip()->getProperty("description");
406 newprops["description"] = item->text(2);
408 if (clip->clipType() == TEXT) {
409 // This is a text template clip, update the image
410 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
411 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
412 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
413 newprops.insert("templatetext", item->text(2));
415 slotUpdateClipProperties(clip->clipId(), newprops);
416 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
417 m_commandStack->push(command);
419 } else if (column == 1) {
420 if (clip->isGroup()) {
421 editFolder(item->text(1), clip->groupName(), clip->clipId());
422 clip->setGroupName(item->text(1));
423 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
424 const int children = item->childCount();
425 for (int i = 0; i < children; i++) {
426 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
427 child->setProperty("groupname", item->text(1));
430 if (clip->referencedClip()) {
431 QMap <QString, QString> oldprops;
432 QMap <QString, QString> newprops;
433 oldprops["name"] = clip->referencedClip()->getProperty("name");
434 newprops["name"] = item->text(1);
435 slotUpdateClipProperties(clip, newprops);
436 emit projectModified();
437 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
438 m_commandStack->push(command);
444 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
450 m_editAction->setEnabled(enable);
451 m_deleteAction->setEnabled(enable);
452 m_reloadAction->setEnabled(enable);
453 m_transcodeAction->setEnabled(enable);
456 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
457 clip = static_cast <ProjectItem*>(item->parent());
458 } else clip = static_cast <ProjectItem*>(item);
459 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
460 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
461 m_openAction->setEnabled(true);
462 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
463 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
464 m_openAction->setEnabled(true);
465 } else m_openAction->setEnabled(false);
466 } else m_openAction->setEnabled(false);
470 void ProjectList::slotRemoveClip()
472 if (!m_listView->currentItem()) return;
474 QMap <QString, QString> folderids;
475 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
477 QUndoCommand *delCommand = new QUndoCommand();
478 delCommand->setText(i18n("Delete Clip Zone"));
480 for (int i = 0; i < selected.count(); i++) {
481 if (selected.at(i)->type() == QTreeWidgetItem::UserType + 1) {
483 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
484 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
485 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), true, delCommand);
488 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
489 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
490 else ids << item->clipId();
491 if (item->numReferences() > 0) {
492 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;
493 } else if (item->isGroup() && item->childCount() > 0) {
494 int children = item->childCount();
495 if (KMessageBox::questionYesNo(this, i18np("Delete folder <b>%2</b>?<br>This will also remove the clip in that folder", "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;
496 for (int i = 0; i < children; ++i) {
497 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
498 ids << child->clipId();
502 if (delCommand->childCount() == 0) delete delCommand;
503 else m_commandStack->push(delCommand);
504 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
505 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
506 if (m_listView->topLevelItemCount() == 0) {
507 m_editAction->setEnabled(false);
508 m_deleteAction->setEnabled(false);
509 m_openAction->setEnabled(false);
510 m_reloadAction->setEnabled(false);
511 m_transcodeAction->setEnabled(false);
515 void ProjectList::selectItemById(const QString &clipId)
517 ProjectItem *item = getItemById(clipId);
518 if (item) m_listView->setCurrentItem(item);
522 void ProjectList::slotDeleteClip(const QString &clipId)
524 ProjectItem *item = getItemById(clipId);
526 kDebug() << "/// Cannot find clip to delete";
529 m_listView->blockSignals(true);
531 m_doc->clipManager()->deleteClip(clipId);
532 m_listView->blockSignals(false);
537 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
539 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
540 m_commandStack->push(command);
541 m_doc->setModified(true);
544 void ProjectList::slotAddFolder()
546 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
547 m_commandStack->push(command);
550 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
553 ProjectItem *item = getFolderItemById(clipId);
555 m_doc->clipManager()->deleteFolder(clipId);
560 ProjectItem *item = getFolderItemById(clipId);
562 m_listView->blockSignals(true);
563 item->setGroupName(foldername);
564 m_listView->blockSignals(false);
565 m_doc->clipManager()->addFolder(clipId, foldername);
566 const int children = item->childCount();
567 for (int i = 0; i < children; i++) {
568 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
569 child->setProperty("groupname", foldername);
574 text << QString() << foldername;
575 m_listView->blockSignals(true);
576 m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId));
577 m_doc->clipManager()->addFolder(clipId, foldername);
578 m_listView->blockSignals(false);
585 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
587 QMapIterator<QString, QString> i(map);
588 QUndoCommand *delCommand = new QUndoCommand();
589 delCommand->setText(i18n("Delete Folder"));
590 while (i.hasNext()) {
592 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
594 m_commandStack->push(delCommand);
595 m_doc->setModified(true);
598 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
600 m_listView->setEnabled(false);
602 m_listView->blockSignals(true);
604 // remove file_hash so that we load all properties for the clip
605 QDomElement e = clip->toXML().cloneNode().toElement();
606 e.removeAttribute("file_hash");
607 m_infoQueue.insert(clip->getId(), e);
608 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
610 const QString parent = clip->getProperty("groupid");
611 ProjectItem *item = NULL;
612 if (!parent.isEmpty()) {
613 ProjectItem *parentitem = getFolderItemById(parent);
616 QString groupName = clip->getProperty("groupname");
617 //kDebug() << "Adding clip to new group: " << groupName;
618 if (groupName.isEmpty()) groupName = i18n("Folder");
619 text << QString() << groupName;
620 parentitem = new ProjectItem(m_listView, text, parent);
622 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
624 if (parentitem) item = new ProjectItem(parentitem, clip);
626 if (item == NULL) item = new ProjectItem(m_listView, clip);
627 KUrl url = clip->fileURL();
629 if (getProperties == false && !clip->getClipHash().isEmpty()) {
630 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
631 if (QFile::exists(cachedPixmap)) {
632 item->setIcon(0, QPixmap(cachedPixmap));
636 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
637 // if file has Nepomuk comment, use it
638 Nepomuk::Resource f(url.path());
639 QString annotation = f.description();
640 if (!annotation.isEmpty()) item->setText(2, annotation);
641 item->setText(3, QString::number(f.rating()));
645 QList <QPoint> cuts = clip->cutZones();
646 if (!cuts.isEmpty()) {
647 m_listView->blockSignals(true);
648 for (int i = 0; i < cuts.count(); i++) {
649 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).x(), cuts.at(i).y());
650 if (!clip->getClipHash().isEmpty()) {
651 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).x()) + ".png";
652 if (QFile::exists(cachedPixmap)) {
653 sub->setIcon(0, QPixmap(cachedPixmap));
657 m_listView->blockSignals(false);
660 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
661 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
664 void ProjectList::slotResetProjectList()
667 emit clipSelected(NULL);
668 m_thumbnailQueue.clear();
673 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
676 m_infoQueue.insert(id, xml);
677 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
680 void ProjectList::slotProcessNextClipInQueue()
682 if (m_infoQueue.isEmpty()) {
683 slotProcessNextThumbnail();
687 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
688 if (j != m_infoQueue.constEnd()) {
689 const QDomElement dom = j.value();
690 const QString id = j.key();
691 m_infoQueue.remove(j.key());
692 emit getFileProperties(dom, id, false);
696 void ProjectList::slotUpdateClip(const QString &id)
698 ProjectItem *item = getItemById(id);
699 m_listView->blockSignals(true);
700 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
701 m_listView->blockSignals(false);
704 void ProjectList::updateAllClips()
706 m_listView->setSortingEnabled(false);
708 QTreeWidgetItemIterator it(m_listView);
711 m_listView->blockSignals(true);
713 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
715 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
716 if (sub->icon(0).isNull()) {
717 item = static_cast <ProjectItem *>((*it)->parent());
718 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
723 item = static_cast <ProjectItem *>(*it);
724 if (!item->isGroup()) {
725 clip = item->referencedClip();
726 if (item->referencedClip()->producer() == NULL) {
727 if (clip->isPlaceHolder() == false) {
728 requestClipInfo(clip->toXML(), clip->getId());
729 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
731 if (item->icon(0).isNull()) {
732 requestClipThumbnail(clip->getId());
734 if (item->data(1, DurationRole).toString().isEmpty()) {
735 item->changeDuration(item->referencedClip()->producer()->get_playtime());
738 item->setData(1, UsageRole, QString::number(item->numReferences()));
739 //qApp->processEvents();
743 qApp->processEvents();
744 if (!m_queueTimer.isActive()) m_queueTimer.start();
746 if (m_listView->isEnabled()) m_listView->blockSignals(false);
747 m_listView->setSortingEnabled(true);
748 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
751 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
753 if (!m_commandStack) {
754 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
757 if (givenList.isEmpty()) {
758 // Build list of mime types
759 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mlt-playlist" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "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";
761 QString allExtensions;
762 foreach(const QString& mimeType, mimeTypes) {
763 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
765 allExtensions.append(mime->patterns().join(" "));
766 allExtensions.append(' ');
769 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
770 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
773 for (int i = 0; i < givenList.count(); i++)
774 list << givenList.at(i);
776 if (list.isEmpty()) return;
778 if (givenList.isEmpty()) {
779 QStringList groupInfo = getGroup();
780 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
781 } else m_doc->slotAddClipList(list, groupName, groupId);
784 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
786 ProjectItem *item = getItemById(id);
787 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
789 const QString path = item->referencedClip()->fileURL().path();
790 if (!path.isEmpty()) {
791 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
793 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;
798 if (replace) m_doc->deleteProjectClip(ids);
802 void ProjectList::slotAddColorClip()
804 if (!m_commandStack) {
805 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
807 QDialog *dia = new QDialog(this);
808 Ui::ColorClip_UI dia_ui;
810 dia_ui.clip_name->setText(i18n("Color Clip"));
811 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
812 if (dia->exec() == QDialog::Accepted) {
813 QString color = dia_ui.clip_color->color().name();
814 color = color.replace(0, 1, "0x") + "ff";
815 QStringList groupInfo = getGroup();
816 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
822 void ProjectList::slotAddSlideshowClip()
824 if (!m_commandStack) {
825 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
827 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
829 if (dia->exec() == QDialog::Accepted) {
830 QStringList groupInfo = getGroup();
831 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), groupInfo.at(0), groupInfo.at(1));
836 void ProjectList::slotAddTitleClip()
838 QStringList groupInfo = getGroup();
839 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
842 void ProjectList::slotAddTitleTemplateClip()
844 QStringList groupInfo = getGroup();
845 if (!m_commandStack) {
846 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
849 // Get the list of existing templates
851 filter << "*.kdenlivetitle";
852 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
853 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
855 QDialog *dia = new QDialog(this);
856 Ui::TemplateClip_UI dia_ui;
858 for (int i = 0; i < templateFiles.size(); ++i) {
859 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
861 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
862 //warning: setting base directory doesn't work??
864 dia_ui.template_list->fileDialog()->setUrl(startDir);
865 dia_ui.text_box->setHidden(true);
866 if (dia->exec() == QDialog::Accepted) {
867 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
868 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
869 // Create a cloned template clip
870 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
875 QStringList ProjectList::getGroup() const
878 ProjectItem *item = NULL;
879 if (m_listView->currentItem() && m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
881 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
882 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
883 if (item && !item->isGroup()) {
884 while (item->parent()) {
885 item = static_cast <ProjectItem*>(item->parent());
886 if (item->isGroup()) break;
889 if (item && item->isGroup()) {
890 result << item->groupName();
891 result << item->clipId();
892 } else result << QString() << QString();
896 void ProjectList::setDocument(KdenliveDoc *doc)
898 m_listView->blockSignals(true);
900 m_listView->setSortingEnabled(false);
901 emit clipSelected(NULL);
902 m_thumbnailQueue.clear();
906 m_timecode = doc->timecode();
907 m_commandStack = doc->commandStack();
910 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
911 QMapIterator<QString, QString> f(flist);
912 while (f.hasNext()) {
914 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
917 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
918 for (int i = 0; i < list.count(); i++) {
919 slotAddClip(list.at(i), false);
922 m_listView->blockSignals(false);
923 m_toolbar->setEnabled(true);
924 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
925 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
928 QList <DocClipBase*> ProjectList::documentClipList() const
930 if (m_doc == NULL) return QList <DocClipBase*> ();
931 return m_doc->clipManager()->documentClipList();
934 QDomElement ProjectList::producersList()
937 QDomElement prods = doc.createElement("producerlist");
938 doc.appendChild(prods);
939 kDebug() << "//////////// PRO LISTÂ BUILD PRDSLIST ";
940 QTreeWidgetItemIterator it(m_listView);
942 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
947 if (!((ProjectItem *)(*it))->isGroup())
948 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
954 void ProjectList::slotCheckForEmptyQueue()
956 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
958 emit loadingIsOver();
959 emit displayMessage(QString(), -1);
960 m_listView->blockSignals(false);
961 m_listView->setEnabled(true);
962 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
965 void ProjectList::reloadClipThumbnails()
967 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
968 m_thumbnailQueue.clear();
969 QTreeWidgetItemIterator it(m_listView);
971 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
976 if (!((ProjectItem *)(*it))->isGroup())
977 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
980 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
983 void ProjectList::requestClipThumbnail(const QString id)
985 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
988 void ProjectList::slotProcessNextThumbnail()
990 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
991 slotCheckForEmptyQueue();
994 if (!m_infoQueue.isEmpty()) {
995 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
998 if (m_thumbnailQueue.count() > 1) {
999 int max = m_doc->clipManager()->clipsCount();
1000 emit displayMessage(i18n("Loading thumbnails"), (int)(100 * (max - m_thumbnailQueue.count()) / max));
1002 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1005 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1007 QTreeWidgetItem *item = getAnyItemById(clipId);
1008 if (item) slotRefreshClipThumbnail(item, update);
1009 else slotProcessNextThumbnail();
1012 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1014 if (it == NULL) return;
1015 ProjectItem *item = NULL;
1016 bool isSubItem = false;
1018 if (it->type() == QTreeWidgetItem::UserType + 1) {
1019 item = static_cast <ProjectItem *>(it->parent());
1020 frame = static_cast <SubProjectItem *>(it)->zone().x();
1023 item = static_cast <ProjectItem *>(it);
1024 frame = item->referencedClip()->getClipThumbFrame();
1028 DocClipBase *clip = item->referencedClip();
1030 slotProcessNextThumbnail();
1034 int height = it->sizeHint(0).height();
1035 int width = (int)(height * m_render->dar());
1036 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1037 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1038 else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1040 if (!pix.isNull()) {
1041 m_listView->blockSignals(true);
1042 it->setIcon(0, pix);
1043 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1044 if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix);
1045 else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1047 if (update) emit projectModified();
1048 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1052 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1054 ProjectItem *item = getItemById(clipId);
1055 if (item && producer) {
1056 m_listView->blockSignals(true);
1057 item->setProperties(properties, metadata);
1058 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1059 item->referencedClip()->setProducer(producer, replace);
1060 //emit receivedClipDuration(clipId);
1061 if (m_listView->isEnabled() && replace) {
1062 // update clip in clip monitor
1063 emit clipSelected(NULL);
1064 emit clipSelected(item->referencedClip());
1067 // Check if duration changed.
1068 emit receivedClipDuration(clipId);
1071 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1072 if (item->icon(0).isNull()) {
1073 requestClipThumbnail(clipId);
1075 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1076 int max = m_doc->clipManager()->clipsCount();
1077 emit displayMessage(i18n("Loading clips"), (int)(100 * (max - m_infoQueue.count()) / max));
1078 // small delay so that the app can display the progress info
1079 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1080 m_listView->setCurrentItem(item);
1081 emit clipSelected(item->referencedClip());
1083 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1086 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1088 ProjectItem *item = getItemById(clipId);
1089 if (item && !pix.isNull()) {
1090 m_listView->blockSignals(true);
1091 item->setIcon(0, pix);
1092 m_doc->cachePixmap(item->getClipHash(), pix);
1093 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1097 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1099 QTreeWidgetItemIterator it(m_listView);
1100 QString lookId = id;
1101 if (id.contains('#')) {
1102 lookId = id.section('#', 0, 0);
1105 ProjectItem *result = NULL;
1107 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
1112 ProjectItem *item = static_cast<ProjectItem *>(*it);
1113 if (item->clipId() == lookId && item->clipType() != FOLDER) {
1119 if (!id.contains('#')) return result;
1120 else for (int i = 0; i < result->childCount(); i++) {
1121 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1122 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) {
1131 ProjectItem *ProjectList::getItemById(const QString &id)
1134 QTreeWidgetItemIterator it(m_listView);
1136 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
1141 item = static_cast<ProjectItem *>(*it);
1142 if (item->clipId() == id && item->clipType() != FOLDER)
1149 ProjectItem *ProjectList::getFolderItemById(const QString &id)
1152 QTreeWidgetItemIterator it(m_listView);
1154 item = static_cast<ProjectItem *>(*it);
1155 if (item->clipId() == id && item->clipType() == FOLDER)
1162 void ProjectList::slotSelectClip(const QString &ix)
1164 ProjectItem *clip = getItemById(ix);
1166 m_listView->setCurrentItem(clip);
1167 m_listView->scrollToItem(clip);
1168 m_editAction->setEnabled(true);
1169 m_deleteAction->setEnabled(true);
1170 m_reloadAction->setEnabled(true);
1171 m_transcodeAction->setEnabled(true);
1172 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1173 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1174 m_openAction->setEnabled(true);
1175 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1176 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1177 m_openAction->setEnabled(true);
1178 } else m_openAction->setEnabled(false);
1182 QString ProjectList::currentClipUrl() const
1185 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
1187 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1188 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
1189 if (item == NULL) return QString();
1190 return item->clipUrl().path();
1193 void ProjectList::regenerateTemplate(const QString &id)
1195 ProjectItem *clip = getItemById(id);
1196 if (clip) regenerateTemplate(clip);
1199 void ProjectList::regenerateTemplate(ProjectItem *clip)
1201 //TODO: remove this unused method, only force_reload is necessary
1202 clip->referencedClip()->producer()->set("force_reload", 1);
1205 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1209 if (!file.open(QIODevice::ReadOnly)) {
1210 kWarning() << "ERROR, CANNOT READ: " << path;
1213 if (!doc.setContent(&file)) {
1214 kWarning() << "ERROR, CANNOT READ: " << path;
1219 QDomNodeList texts = doc.elementsByTagName("content");
1220 for (int i = 0; i < texts.count(); i++) {
1221 QString data = texts.item(i).firstChild().nodeValue();
1222 data.replace("%s", replaceString);
1223 texts.item(i).firstChild().setNodeValue(data);
1229 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1231 ProjectItem *clip = getItemById(id);
1232 if (clip == NULL) return;
1233 if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return;
1234 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, false);
1235 m_commandStack->push(command);
1238 void ProjectList::addClipCut(const QString &id, int in, int out)
1240 //m_doc->slotAddClipCut(id, in, out, groupName, groupId);
1241 ProjectItem *clip = getItemById(id);
1243 DocClipBase *base = clip->referencedClip();
1244 base->addCutZone(in, out);
1245 m_listView->blockSignals(true);
1246 SubProjectItem *sub = new SubProjectItem(clip, in, out);
1248 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height());
1250 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1251 m_listView->blockSignals(false);
1255 void ProjectList::removeClipCut(const QString &id, int in, int out)
1257 //m_doc->slotAddClipCut(id, in, out, groupName, groupId);
1258 ProjectItem *clip = getItemById(id);
1260 DocClipBase *base = clip->referencedClip();
1261 base->removeCutZone(in, out);
1262 for (int i = 0; i < clip->childCount(); i++) {
1263 QTreeWidgetItem *it = clip->child(i);
1264 if (it->type() != QTreeWidgetItem::UserType + 1) continue;
1265 SubProjectItem *sub = static_cast <SubProjectItem*>(it);
1266 if (sub->zone() == QPoint(in, out)) {
1267 m_listView->blockSignals(true);
1269 m_listView->blockSignals(false);
1276 #include "projectlist.moc"