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::focusTree() const
135 m_listView->setFocus();
138 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
140 QList <QAction *> actions = addMenu->actions();
141 for (int i = 0; i < actions.count(); i++) {
142 if (actions.at(i)->data().toString() == "clip_properties") {
143 m_editAction = actions.at(i);
144 m_toolbar->addAction(m_editAction);
147 } else if (actions.at(i)->data().toString() == "delete_clip") {
148 m_deleteAction = actions.at(i);
149 m_toolbar->addAction(m_deleteAction);
152 } else if (actions.at(i)->data().toString() == "edit_clip") {
153 m_openAction = actions.at(i);
156 } else if (actions.at(i)->data().toString() == "reload_clip") {
157 m_reloadAction = actions.at(i);
163 QMenu *m = new QMenu();
164 m->addActions(actions);
165 m_addButton->setMenu(m);
166 m_addButton->setDefaultAction(defaultAction);
167 m_menu = new QMenu();
168 m_menu->addActions(addMenu->actions());
171 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
173 if (!addMenu) return;
174 QMenu *menu = m_addButton->menu();
175 menu->addMenu(addMenu);
176 m_addButton->setMenu(menu);
178 m_menu->addMenu(addMenu);
179 if (addMenu->isEmpty()) addMenu->setEnabled(false);
180 m_menu->addMenu(transcodeMenu);
181 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
182 m_transcodeAction = transcodeMenu;
183 m_menu->addAction(m_reloadAction);
184 m_menu->addAction(m_editAction);
185 m_menu->addAction(m_openAction);
186 m_menu->addAction(m_deleteAction);
187 m_menu->insertSeparator(m_deleteAction);
191 QByteArray ProjectList::headerInfo() const
193 return m_listView->header()->saveState();
196 void ProjectList::setHeaderInfo(const QByteArray &state)
198 m_listView->header()->restoreState(state);
201 void ProjectList::slotEditClip()
204 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
205 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
206 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
207 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
208 if (item && !item->isGroup()) {
209 emit clipSelected(item->referencedClip());
210 emit showClipProperties(item->referencedClip());
214 void ProjectList::slotOpenClip()
217 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
218 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
219 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
220 if (item && !item->isGroup()) {
221 if (item->clipType() == IMAGE) {
222 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
223 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
225 if (item->clipType() == AUDIO) {
226 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
227 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
232 void ProjectList::cleanup()
234 m_listView->clearSelection();
235 QTreeWidgetItemIterator it(m_listView);
238 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
242 item = static_cast <ProjectItem *>(*it);
243 if (!item->isGroup() && item->numReferences() == 0) item->setSelected(true);
249 void ProjectList::trashUnusedClips()
251 QTreeWidgetItemIterator it(m_listView);
256 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
260 item = static_cast <ProjectItem *>(*it);
261 if (!item->isGroup() && item->numReferences() == 0) {
262 ids << item->clipId();
263 KUrl url = item->clipUrl();
264 if (!url.isEmpty() && !urls.contains(url.path())) urls << url.path();
269 // Check that we don't use the URL in another clip
270 QTreeWidgetItemIterator it2(m_listView);
272 if ((*it2)->type() == QTreeWidgetItem::UserType + 1) {
276 item = static_cast <ProjectItem *>(*it2);
277 if (item->numReferences() > 0) {
278 KUrl url = item->clipUrl();
279 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
284 m_doc->deleteProjectClip(ids);
285 for (int i = 0; i < urls.count(); i++) {
286 KIO::NetAccess::del(KUrl(urls.at(i)), this);
290 void ProjectList::slotReloadClip(const QString &id)
292 QList<QTreeWidgetItem *> selected;
293 if (id.isEmpty()) selected = m_listView->selectedItems();
294 else selected.append(getItemById(id));
296 for (int i = 0; i < selected.count(); i++) {
297 if (selected.at(i)->type() == QTreeWidgetItem::UserType + 1) continue;
298 item = static_cast <ProjectItem *>(selected.at(i));
299 if (item && !item->isGroup()) {
300 if (item->clipType() == IMAGE) {
301 item->referencedClip()->producer()->set("force_reload", 1);
302 } else if (item->clipType() == TEXT) {
303 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
305 //requestClipInfo(item->toXml(), item->clipId(), true);
306 // Clear the file_hash value, which will cause a complete reload of the clip
307 emit getFileProperties(item->toXml(), item->clipId(), true);
312 void ProjectList::setRenderer(Render *projectRender)
314 m_render = projectRender;
315 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
318 void ProjectList::slotClipSelected()
320 if (m_listView->currentItem()) {
322 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
323 // this is a sub item, use base clip
324 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
325 if (clip == NULL) kDebug() << "-----------ERROR";
326 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
327 emit clipSelected(clip->referencedClip(), sub->zone());
330 clip = static_cast <ProjectItem*>(m_listView->currentItem());
331 if (!clip->isGroup()) {
332 emit clipSelected(clip->referencedClip());
334 m_editAction->setEnabled(true);
335 m_deleteAction->setEnabled(true);
336 m_reloadAction->setEnabled(true);
337 m_transcodeAction->setEnabled(true);
338 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
339 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
340 m_openAction->setEnabled(true);
341 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
342 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
343 m_openAction->setEnabled(true);
344 } else m_openAction->setEnabled(false);
346 emit clipSelected(NULL);
347 m_editAction->setEnabled(false);
348 m_deleteAction->setEnabled(false);
349 m_openAction->setEnabled(false);
350 m_reloadAction->setEnabled(false);
351 m_transcodeAction->setEnabled(false);
355 void ProjectList::slotPauseMonitor()
357 if (m_render) m_render->pause();
360 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
362 ProjectItem *item = getItemById(id);
364 slotUpdateClipProperties(item, properties);
365 if (properties.contains("out")) {
367 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
368 slotRefreshClipThumbnail(item);
374 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
377 if (!clip->isGroup()) clip->setProperties(properties);
378 if (properties.contains("name")) {
379 m_listView->blockSignals(true);
380 clip->setText(1, properties.value("name"));
381 m_listView->blockSignals(false);
382 emit clipNameChanged(clip->clipId(), properties.value("name"));
384 if (properties.contains("description")) {
385 CLIPTYPE type = clip->clipType();
386 m_listView->blockSignals(true);
387 clip->setText(2, properties.value("description"));
388 m_listView->blockSignals(false);
389 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
390 // Use Nepomuk system to store clip description
391 Nepomuk::Resource f(clip->clipUrl().path());
392 f.setDescription(properties.value("description"));
394 emit projectModified();
398 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
400 if (item->type() == QTreeWidgetItem::UserType + 1) {
401 // this is a sub-item
405 ProjectItem *clip = static_cast <ProjectItem*>(item);
407 if (clip->referencedClip()) {
408 QMap <QString, QString> oldprops;
409 QMap <QString, QString> newprops;
410 oldprops["description"] = clip->referencedClip()->getProperty("description");
411 newprops["description"] = item->text(2);
413 if (clip->clipType() == TEXT) {
414 // This is a text template clip, update the image
415 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
416 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
417 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
418 newprops.insert("templatetext", item->text(2));
420 slotUpdateClipProperties(clip->clipId(), newprops);
421 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
422 m_commandStack->push(command);
424 } else if (column == 1) {
425 if (clip->isGroup()) {
426 editFolder(item->text(1), clip->groupName(), clip->clipId());
427 clip->setGroupName(item->text(1));
428 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
429 const int children = item->childCount();
430 for (int i = 0; i < children; i++) {
431 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
432 child->setProperty("groupname", item->text(1));
435 if (clip->referencedClip()) {
436 QMap <QString, QString> oldprops;
437 QMap <QString, QString> newprops;
438 oldprops["name"] = clip->referencedClip()->getProperty("name");
439 newprops["name"] = item->text(1);
440 slotUpdateClipProperties(clip, newprops);
441 emit projectModified();
442 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
443 m_commandStack->push(command);
449 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
455 m_editAction->setEnabled(enable);
456 m_deleteAction->setEnabled(enable);
457 m_reloadAction->setEnabled(enable);
458 m_transcodeAction->setEnabled(enable);
461 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
462 clip = static_cast <ProjectItem*>(item->parent());
463 } else clip = static_cast <ProjectItem*>(item);
464 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
465 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
466 m_openAction->setEnabled(true);
467 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
468 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
469 m_openAction->setEnabled(true);
470 } else m_openAction->setEnabled(false);
471 } else m_openAction->setEnabled(false);
475 void ProjectList::slotRemoveClip()
477 if (!m_listView->currentItem()) return;
479 QMap <QString, QString> folderids;
480 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
482 QUndoCommand *delCommand = new QUndoCommand();
483 delCommand->setText(i18n("Delete Clip Zone"));
485 for (int i = 0; i < selected.count(); i++) {
486 if (selected.at(i)->type() == QTreeWidgetItem::UserType + 1) {
488 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
489 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
490 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), true, delCommand);
493 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
494 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
495 else ids << item->clipId();
496 if (item->numReferences() > 0) {
497 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;
498 } else if (item->isGroup() && item->childCount() > 0) {
499 int children = item->childCount();
500 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;
501 for (int i = 0; i < children; ++i) {
502 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
503 ids << child->clipId();
507 if (delCommand->childCount() == 0) delete delCommand;
508 else m_commandStack->push(delCommand);
509 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
510 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
511 if (m_listView->topLevelItemCount() == 0) {
512 m_editAction->setEnabled(false);
513 m_deleteAction->setEnabled(false);
514 m_openAction->setEnabled(false);
515 m_reloadAction->setEnabled(false);
516 m_transcodeAction->setEnabled(false);
520 void ProjectList::selectItemById(const QString &clipId)
522 ProjectItem *item = getItemById(clipId);
523 if (item) m_listView->setCurrentItem(item);
527 void ProjectList::slotDeleteClip(const QString &clipId)
529 ProjectItem *item = getItemById(clipId);
531 kDebug() << "/// Cannot find clip to delete";
534 m_listView->blockSignals(true);
536 m_doc->clipManager()->deleteClip(clipId);
537 m_listView->blockSignals(false);
542 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
544 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
545 m_commandStack->push(command);
546 m_doc->setModified(true);
549 void ProjectList::slotAddFolder()
551 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
552 m_commandStack->push(command);
555 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
558 ProjectItem *item = getFolderItemById(clipId);
560 m_doc->clipManager()->deleteFolder(clipId);
565 ProjectItem *item = getFolderItemById(clipId);
567 m_listView->blockSignals(true);
568 item->setGroupName(foldername);
569 m_listView->blockSignals(false);
570 m_doc->clipManager()->addFolder(clipId, foldername);
571 const int children = item->childCount();
572 for (int i = 0; i < children; i++) {
573 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
574 child->setProperty("groupname", foldername);
579 text << QString() << foldername;
580 m_listView->blockSignals(true);
581 m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId));
582 m_doc->clipManager()->addFolder(clipId, foldername);
583 m_listView->blockSignals(false);
590 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
592 QMapIterator<QString, QString> i(map);
593 QUndoCommand *delCommand = new QUndoCommand();
594 delCommand->setText(i18n("Delete Folder"));
595 while (i.hasNext()) {
597 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
599 m_commandStack->push(delCommand);
600 m_doc->setModified(true);
603 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
605 m_listView->setEnabled(false);
607 m_listView->blockSignals(true);
609 // remove file_hash so that we load all properties for the clip
610 QDomElement e = clip->toXML().cloneNode().toElement();
611 e.removeAttribute("file_hash");
612 m_infoQueue.insert(clip->getId(), e);
613 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
615 const QString parent = clip->getProperty("groupid");
616 ProjectItem *item = NULL;
617 if (!parent.isEmpty()) {
618 ProjectItem *parentitem = getFolderItemById(parent);
621 QString groupName = clip->getProperty("groupname");
622 //kDebug() << "Adding clip to new group: " << groupName;
623 if (groupName.isEmpty()) groupName = i18n("Folder");
624 text << QString() << groupName;
625 parentitem = new ProjectItem(m_listView, text, parent);
627 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
629 if (parentitem) item = new ProjectItem(parentitem, clip);
631 if (item == NULL) item = new ProjectItem(m_listView, clip);
632 KUrl url = clip->fileURL();
634 if (getProperties == false && !clip->getClipHash().isEmpty()) {
635 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
636 if (QFile::exists(cachedPixmap)) {
637 item->setIcon(0, QPixmap(cachedPixmap));
641 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
642 // if file has Nepomuk comment, use it
643 Nepomuk::Resource f(url.path());
644 QString annotation = f.description();
645 if (!annotation.isEmpty()) item->setText(2, annotation);
646 item->setText(3, QString::number(f.rating()));
650 QList <QPoint> cuts = clip->cutZones();
651 if (!cuts.isEmpty()) {
652 for (int i = 0; i < cuts.count(); i++) {
653 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).x(), cuts.at(i).y());
654 if (!clip->getClipHash().isEmpty()) {
655 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).x()) + ".png";
656 if (QFile::exists(cachedPixmap)) {
657 sub->setIcon(0, QPixmap(cachedPixmap));
663 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
664 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
667 void ProjectList::slotResetProjectList()
670 emit clipSelected(NULL);
671 m_thumbnailQueue.clear();
676 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
679 m_infoQueue.insert(id, xml);
680 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
683 void ProjectList::slotProcessNextClipInQueue()
685 if (m_infoQueue.isEmpty()) {
686 slotProcessNextThumbnail();
690 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
691 if (j != m_infoQueue.constEnd()) {
692 const QDomElement dom = j.value();
693 const QString id = j.key();
694 m_infoQueue.remove(j.key());
695 emit getFileProperties(dom, id, false);
699 void ProjectList::slotUpdateClip(const QString &id)
701 ProjectItem *item = getItemById(id);
702 m_listView->blockSignals(true);
703 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
704 m_listView->blockSignals(false);
707 void ProjectList::updateAllClips()
709 m_listView->setSortingEnabled(false);
711 QTreeWidgetItemIterator it(m_listView);
714 m_listView->blockSignals(true);
716 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
718 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
719 if (sub->icon(0).isNull()) {
720 item = static_cast <ProjectItem *>((*it)->parent());
721 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
726 item = static_cast <ProjectItem *>(*it);
727 if (!item->isGroup()) {
728 clip = item->referencedClip();
729 if (item->referencedClip()->producer() == NULL) {
730 if (clip->isPlaceHolder() == false) {
731 requestClipInfo(clip->toXML(), clip->getId());
732 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
734 if (item->icon(0).isNull()) {
735 requestClipThumbnail(clip->getId());
737 if (item->data(1, DurationRole).toString().isEmpty()) {
738 item->changeDuration(item->referencedClip()->producer()->get_playtime());
741 item->setData(1, UsageRole, QString::number(item->numReferences()));
742 //qApp->processEvents();
746 qApp->processEvents();
747 if (!m_queueTimer.isActive()) m_queueTimer.start();
749 if (m_listView->isEnabled()) m_listView->blockSignals(false);
750 m_listView->setSortingEnabled(true);
751 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
754 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
756 if (!m_commandStack) {
757 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
760 if (givenList.isEmpty()) {
761 // Build list of mime types
762 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";
764 QString allExtensions;
765 foreach(const QString& mimeType, mimeTypes) {
766 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
768 allExtensions.append(mime->patterns().join(" "));
769 allExtensions.append(' ');
772 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
773 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
776 for (int i = 0; i < givenList.count(); i++)
777 list << givenList.at(i);
779 if (list.isEmpty()) return;
781 if (givenList.isEmpty()) {
782 QStringList groupInfo = getGroup();
783 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
784 } else m_doc->slotAddClipList(list, groupName, groupId);
787 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
789 ProjectItem *item = getItemById(id);
790 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
792 const QString path = item->referencedClip()->fileURL().path();
793 if (!path.isEmpty()) {
794 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
796 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;
801 if (replace) m_doc->deleteProjectClip(ids);
805 void ProjectList::slotAddColorClip()
807 if (!m_commandStack) {
808 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
810 QDialog *dia = new QDialog(this);
811 Ui::ColorClip_UI dia_ui;
813 dia_ui.clip_name->setText(i18n("Color Clip"));
814 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
815 if (dia->exec() == QDialog::Accepted) {
816 QString color = dia_ui.clip_color->color().name();
817 color = color.replace(0, 1, "0x") + "ff";
818 QStringList groupInfo = getGroup();
819 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
825 void ProjectList::slotAddSlideshowClip()
827 if (!m_commandStack) {
828 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
830 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
832 if (dia->exec() == QDialog::Accepted) {
833 QStringList groupInfo = getGroup();
834 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));
839 void ProjectList::slotAddTitleClip()
841 QStringList groupInfo = getGroup();
842 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
845 void ProjectList::slotAddTitleTemplateClip()
847 QStringList groupInfo = getGroup();
848 if (!m_commandStack) {
849 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
852 // Get the list of existing templates
854 filter << "*.kdenlivetitle";
855 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
856 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
858 QDialog *dia = new QDialog(this);
859 Ui::TemplateClip_UI dia_ui;
861 for (int i = 0; i < templateFiles.size(); ++i) {
862 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
864 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
865 //warning: setting base directory doesn't work??
867 dia_ui.template_list->fileDialog()->setUrl(startDir);
868 dia_ui.text_box->setHidden(true);
869 if (dia->exec() == QDialog::Accepted) {
870 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
871 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
872 // Create a cloned template clip
873 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
878 QStringList ProjectList::getGroup() const
881 ProjectItem *item = NULL;
882 if (m_listView->currentItem() && m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
884 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
885 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
886 if (item && !item->isGroup()) {
887 while (item->parent()) {
888 item = static_cast <ProjectItem*>(item->parent());
889 if (item->isGroup()) break;
892 if (item && item->isGroup()) {
893 result << item->groupName();
894 result << item->clipId();
895 } else result << QString() << QString();
899 void ProjectList::setDocument(KdenliveDoc *doc)
901 m_listView->blockSignals(true);
903 m_listView->setSortingEnabled(false);
904 emit clipSelected(NULL);
905 m_thumbnailQueue.clear();
909 m_timecode = doc->timecode();
910 m_commandStack = doc->commandStack();
913 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
914 QMapIterator<QString, QString> f(flist);
915 while (f.hasNext()) {
917 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
920 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
921 for (int i = 0; i < list.count(); i++) {
922 slotAddClip(list.at(i), false);
925 m_listView->blockSignals(false);
926 m_toolbar->setEnabled(true);
927 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
928 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
931 QList <DocClipBase*> ProjectList::documentClipList() const
933 if (m_doc == NULL) return QList <DocClipBase*> ();
934 return m_doc->clipManager()->documentClipList();
937 QDomElement ProjectList::producersList()
940 QDomElement prods = doc.createElement("producerlist");
941 doc.appendChild(prods);
942 kDebug() << "//////////// PRO LISTÂ BUILD PRDSLIST ";
943 QTreeWidgetItemIterator it(m_listView);
945 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
950 if (!((ProjectItem *)(*it))->isGroup())
951 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
957 void ProjectList::slotCheckForEmptyQueue()
959 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
961 emit loadingIsOver();
962 emit displayMessage(QString(), -1);
963 m_listView->blockSignals(false);
964 m_listView->setEnabled(true);
965 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
968 void ProjectList::reloadClipThumbnails()
970 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
971 m_thumbnailQueue.clear();
972 QTreeWidgetItemIterator it(m_listView);
974 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
979 if (!((ProjectItem *)(*it))->isGroup())
980 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
983 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
986 void ProjectList::requestClipThumbnail(const QString id)
988 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
991 void ProjectList::slotProcessNextThumbnail()
993 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
994 slotCheckForEmptyQueue();
997 if (!m_infoQueue.isEmpty()) {
998 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1001 if (m_thumbnailQueue.count() > 1) {
1002 int max = m_doc->clipManager()->clipsCount();
1003 emit displayMessage(i18n("Loading thumbnails"), (int)(100 * (max - m_thumbnailQueue.count()) / max));
1005 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1008 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1010 QTreeWidgetItem *item = getAnyItemById(clipId);
1011 if (item) slotRefreshClipThumbnail(item, update);
1012 else slotProcessNextThumbnail();
1015 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1017 if (it == NULL) return;
1018 ProjectItem *item = NULL;
1019 bool isSubItem = false;
1021 if (it->type() == QTreeWidgetItem::UserType + 1) {
1022 item = static_cast <ProjectItem *>(it->parent());
1023 frame = static_cast <SubProjectItem *>(it)->zone().x();
1026 item = static_cast <ProjectItem *>(it);
1027 frame = item->referencedClip()->getClipThumbFrame();
1031 DocClipBase *clip = item->referencedClip();
1033 slotProcessNextThumbnail();
1037 int height = it->sizeHint(0).height();
1038 int width = (int)(height * m_render->dar());
1039 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1040 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1041 else pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1043 if (!pix.isNull()) {
1044 m_listView->blockSignals(true);
1045 it->setIcon(0, pix);
1046 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1047 if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix);
1048 else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1050 if (update) emit projectModified();
1051 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1055 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1057 ProjectItem *item = getItemById(clipId);
1058 if (item && producer) {
1059 m_listView->blockSignals(true);
1060 item->setProperties(properties, metadata);
1061 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1062 item->referencedClip()->setProducer(producer, replace);
1063 //emit receivedClipDuration(clipId);
1064 if (m_listView->isEnabled() && replace) {
1065 // update clip in clip monitor
1066 emit clipSelected(NULL);
1067 emit clipSelected(item->referencedClip());
1070 // Check if duration changed.
1071 emit receivedClipDuration(clipId);
1074 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1075 if (item->icon(0).isNull()) {
1076 requestClipThumbnail(clipId);
1078 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1079 int max = m_doc->clipManager()->clipsCount();
1080 emit displayMessage(i18n("Loading clips"), (int)(100 * (max - m_infoQueue.count()) / max));
1081 // small delay so that the app can display the progress info
1082 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1083 m_listView->setCurrentItem(item);
1084 emit clipSelected(item->referencedClip());
1086 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1089 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1091 ProjectItem *item = getItemById(clipId);
1092 if (item && !pix.isNull()) {
1093 m_listView->blockSignals(true);
1094 item->setIcon(0, pix);
1095 m_doc->cachePixmap(item->getClipHash(), pix);
1096 if (m_listView->isEnabled()) m_listView->blockSignals(false);
1100 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1102 QTreeWidgetItemIterator it(m_listView);
1103 QString lookId = id;
1104 if (id.contains('#')) {
1105 lookId = id.section('#', 0, 0);
1108 ProjectItem *result = NULL;
1110 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
1115 ProjectItem *item = static_cast<ProjectItem *>(*it);
1116 if (item->clipId() == lookId && item->clipType() != FOLDER) {
1122 if (!id.contains('#')) return result;
1123 else for (int i = 0; i < result->childCount(); i++) {
1124 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1125 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) {
1134 ProjectItem *ProjectList::getItemById(const QString &id)
1137 QTreeWidgetItemIterator it(m_listView);
1139 if ((*it)->type() == QTreeWidgetItem::UserType + 1) {
1144 item = static_cast<ProjectItem *>(*it);
1145 if (item->clipId() == id && item->clipType() != FOLDER)
1152 ProjectItem *ProjectList::getFolderItemById(const QString &id)
1155 QTreeWidgetItemIterator it(m_listView);
1157 item = static_cast<ProjectItem *>(*it);
1158 if (item->clipId() == id && item->clipType() == FOLDER)
1165 void ProjectList::slotSelectClip(const QString &ix)
1167 ProjectItem *clip = getItemById(ix);
1169 m_listView->setCurrentItem(clip);
1170 m_listView->scrollToItem(clip);
1171 m_editAction->setEnabled(true);
1172 m_deleteAction->setEnabled(true);
1173 m_reloadAction->setEnabled(true);
1174 m_transcodeAction->setEnabled(true);
1175 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1176 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1177 m_openAction->setEnabled(true);
1178 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1179 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1180 m_openAction->setEnabled(true);
1181 } else m_openAction->setEnabled(false);
1185 QString ProjectList::currentClipUrl() const
1188 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) {
1190 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1191 } else item = static_cast <ProjectItem*>(m_listView->currentItem());
1192 if (item == NULL) return QString();
1193 return item->clipUrl().path();
1196 void ProjectList::regenerateTemplate(const QString &id)
1198 ProjectItem *clip = getItemById(id);
1199 if (clip) regenerateTemplate(clip);
1202 void ProjectList::regenerateTemplate(ProjectItem *clip)
1204 //TODO: remove this unused method, only force_reload is necessary
1205 clip->referencedClip()->producer()->set("force_reload", 1);
1208 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1212 if (!file.open(QIODevice::ReadOnly)) {
1213 kWarning() << "ERROR, CANNOT READ: " << path;
1216 if (!doc.setContent(&file)) {
1217 kWarning() << "ERROR, CANNOT READ: " << path;
1222 QDomNodeList texts = doc.elementsByTagName("content");
1223 for (int i = 0; i < texts.count(); i++) {
1224 QString data = texts.item(i).firstChild().nodeValue();
1225 data.replace("%s", replaceString);
1226 texts.item(i).firstChild().setNodeValue(data);
1232 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1234 ProjectItem *clip = getItemById(id);
1235 if (clip == NULL) return;
1236 if (clip->referencedClip()->hasCutZone(QPoint(in, out))) return;
1237 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, false);
1238 m_commandStack->push(command);
1241 void ProjectList::addClipCut(const QString &id, int in, int out)
1243 ProjectItem *clip = getItemById(id);
1245 DocClipBase *base = clip->referencedClip();
1246 base->addCutZone(in, out);
1247 m_listView->blockSignals(true);
1248 SubProjectItem *sub = new SubProjectItem(clip, in, out);
1250 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height());
1252 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1253 m_listView->blockSignals(false);
1257 void ProjectList::removeClipCut(const QString &id, int in, int out)
1259 ProjectItem *clip = getItemById(id);
1261 DocClipBase *base = clip->referencedClip();
1262 base->removeCutZone(in, out);
1263 for (int i = 0; i < clip->childCount(); i++) {
1264 QTreeWidgetItem *it = clip->child(i);
1265 if (it->type() != QTreeWidgetItem::UserType + 1) continue;
1266 SubProjectItem *sub = static_cast <SubProjectItem*>(it);
1267 if (sub->zone() == QPoint(in, out)) {
1268 m_listView->blockSignals(true);
1270 m_listView->blockSignals(false);
1277 #include "projectlist.moc"