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 "timecodedisplay.h"
35 #include "editclipcommand.h"
36 #include "editclipcutcommand.h"
37 #include "editfoldercommand.h"
38 #include "addclipcutcommand.h"
40 #include "ui_templateclip_ui.h"
45 #include <KFileDialog>
46 #include <KInputDialog>
47 #include <KMessageBox>
48 #include <KIO/NetAccess>
51 #include <nepomuk/global.h>
52 #include <nepomuk/resourcemanager.h>
53 //#include <nepomuk/tag.h>
56 #include <QMouseEvent>
57 #include <QStylePainter>
62 #include <QHeaderView>
63 #include <QInputDialog>
65 ProjectList::ProjectList(QWidget *parent) :
74 m_transcodeAction(NULL),
81 m_listView = new ProjectListView(this);;
82 QVBoxLayout *layout = new QVBoxLayout;
83 layout->setContentsMargins(0, 0, 0, 0);
84 layout->setSpacing(0);
87 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
88 m_toolbar = new QToolBar("projectToolBar", this);
89 m_toolbar->addWidget(searchView);
90 int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
91 m_toolbar->setIconSize(QSize(s, s));
92 searchView->setTreeWidget(m_listView);
94 m_addButton = new QToolButton(m_toolbar);
95 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
96 m_toolbar->addWidget(m_addButton);
98 layout->addWidget(m_toolbar);
99 layout->addWidget(m_listView);
102 m_queueTimer.setInterval(100);
103 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
104 m_queueTimer.setSingleShot(true);
107 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
108 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
109 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
110 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
111 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
112 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
113 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
114 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
115 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
116 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
118 m_listViewDelegate = new ItemDelegate(m_listView);
119 m_listView->setItemDelegate(m_listViewDelegate);
121 if (KdenliveSettings::activate_nepomuk()) {
122 Nepomuk::ResourceManager::instance()->init();
123 if (!Nepomuk::ResourceManager::instance()->initialized()) {
124 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
125 KdenliveSettings::setActivate_nepomuk(false);
131 ProjectList::~ProjectList()
135 m_listView->blockSignals(true);
137 delete m_listViewDelegate;
140 void ProjectList::focusTree() const
142 m_listView->setFocus();
145 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
147 QList <QAction *> actions = addMenu->actions();
148 for (int i = 0; i < actions.count(); i++) {
149 if (actions.at(i)->data().toString() == "clip_properties") {
150 m_editAction = actions.at(i);
151 m_toolbar->addAction(m_editAction);
154 } else if (actions.at(i)->data().toString() == "delete_clip") {
155 m_deleteAction = actions.at(i);
156 m_toolbar->addAction(m_deleteAction);
159 } else if (actions.at(i)->data().toString() == "edit_clip") {
160 m_openAction = actions.at(i);
163 } else if (actions.at(i)->data().toString() == "reload_clip") {
164 m_reloadAction = actions.at(i);
170 QMenu *m = new QMenu();
171 m->addActions(actions);
172 m_addButton->setMenu(m);
173 m_addButton->setDefaultAction(defaultAction);
174 m_menu = new QMenu();
175 m_menu->addActions(addMenu->actions());
178 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
182 QMenu *menu = m_addButton->menu();
183 menu->addMenu(addMenu);
184 m_addButton->setMenu(menu);
186 m_menu->addMenu(addMenu);
187 if (addMenu->isEmpty())
188 addMenu->setEnabled(false);
189 m_menu->addMenu(transcodeMenu);
190 if (transcodeMenu->isEmpty())
191 transcodeMenu->setEnabled(false);
192 m_transcodeAction = transcodeMenu;
193 m_menu->addAction(m_reloadAction);
194 m_menu->addMenu(inTimelineMenu);
195 inTimelineMenu->setEnabled(false);
196 m_menu->addAction(m_editAction);
197 m_menu->addAction(m_openAction);
198 m_menu->addAction(m_deleteAction);
199 m_menu->insertSeparator(m_deleteAction);
203 QByteArray ProjectList::headerInfo() const
205 return m_listView->header()->saveState();
208 void ProjectList::setHeaderInfo(const QByteArray &state)
210 m_listView->header()->restoreState(state);
213 void ProjectList::updateProjectFormat(Timecode t)
218 void ProjectList::slotEditClip()
220 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
221 if (list.count() > 1) {
222 editClipSelection(list);
226 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
228 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
229 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
231 item = static_cast <ProjectItem*>(m_listView->currentItem());
232 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
233 emit clipSelected(item->referencedClip());
234 emit showClipProperties(item->referencedClip());
238 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
240 // Gather all common properties
241 QMap <QString, QString> commonproperties;
242 QList <DocClipBase *> clipList;
243 commonproperties.insert("force_aspect_ratio", "-");
244 commonproperties.insert("force_fps", "-");
245 commonproperties.insert("force_progressive", "-");
246 commonproperties.insert("threads", "-");
247 commonproperties.insert("video_index", "-");
248 commonproperties.insert("audio_index", "-");
250 bool allowDurationChange = true;
251 int commonDuration = -1;
253 for (int i = 0; i < list.count(); i++) {
255 if (list.at(i)->type() == PROJECTFOLDERTYPE)
257 if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
258 item = static_cast <ProjectItem*>(list.at(i)->parent());
260 item = static_cast <ProjectItem*>(list.at(i));
261 if (!(item->flags() & Qt::ItemIsDragEnabled))
265 DocClipBase *clip = item->referencedClip();
266 if (clipList.contains(clip)) continue;
267 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
268 allowDurationChange = false;
269 if (allowDurationChange && commonDuration != 0) {
270 if (commonDuration == -1)
271 commonDuration = clip->duration().frames(m_fps);
272 else if (commonDuration != clip->duration().frames(m_fps))
275 clipList.append(clip);
276 QMap <QString, QString> clipprops = clip->properties();
277 QMapIterator<QString, QString> p(commonproperties);
278 while (p.hasNext()) {
280 if (p.value().isEmpty()) continue;
281 if (clipprops.contains(p.key())) {
282 if (p.value() == "-")
283 commonproperties.insert(p.key(), clipprops.value(p.key()));
284 else if (p.value() != clipprops.value(p.key()))
285 commonproperties.insert(p.key(), QString());
287 commonproperties.insert(p.key(), QString());
292 if (allowDurationChange)
293 commonproperties.insert("out", QString::number(commonDuration));
294 QMapIterator<QString, QString> p(commonproperties);
295 while (p.hasNext()) {
297 kDebug() << "Result: " << p.key() << " = " << p.value();
299 emit showClipProperties(clipList, commonproperties);
302 void ProjectList::slotOpenClip()
305 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
307 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
308 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
310 item = static_cast <ProjectItem*>(m_listView->currentItem());
312 if (item->clipType() == IMAGE) {
313 if (KdenliveSettings::defaultimageapp().isEmpty())
314 KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
316 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
318 if (item->clipType() == AUDIO) {
319 if (KdenliveSettings::defaultaudioapp().isEmpty())
320 KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
322 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
327 void ProjectList::cleanup()
329 m_listView->clearSelection();
330 QTreeWidgetItemIterator it(m_listView);
333 if ((*it)->type() != PROJECTCLIPTYPE) {
337 item = static_cast <ProjectItem *>(*it);
338 if (item->numReferences() == 0)
339 item->setSelected(true);
345 void ProjectList::trashUnusedClips()
347 QTreeWidgetItemIterator it(m_listView);
352 if ((*it)->type() != PROJECTCLIPTYPE) {
356 item = static_cast <ProjectItem *>(*it);
357 if (item->numReferences() == 0) {
358 ids << item->clipId();
359 KUrl url = item->clipUrl();
360 if (!url.isEmpty() && !urls.contains(url.path()))
366 // Check that we don't use the URL in another clip
367 QTreeWidgetItemIterator it2(m_listView);
369 if ((*it2)->type() != PROJECTCLIPTYPE) {
373 item = static_cast <ProjectItem *>(*it2);
374 if (item->numReferences() > 0) {
375 KUrl url = item->clipUrl();
376 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
381 emit deleteProjectClips(ids, QMap <QString, QString>());
382 for (int i = 0; i < urls.count(); i++)
383 KIO::NetAccess::del(KUrl(urls.at(i)), this);
386 void ProjectList::slotReloadClip(const QString &id)
388 QList<QTreeWidgetItem *> selected;
390 selected = m_listView->selectedItems();
392 selected.append(getItemById(id));
394 for (int i = 0; i < selected.count(); i++) {
395 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
396 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
397 for (int j = 0; j < selected.at(i)->childCount(); j++)
398 selected.append(selected.at(i)->child(j));
402 item = static_cast <ProjectItem *>(selected.at(i));
404 if (item->clipType() == TEXT) {
405 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
406 regenerateTemplate(item);
407 } else if (item->clipType() != COLOR && item->clipType() != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
408 item->referencedClip()->setPlaceHolder(true);
409 item->setProperty("file_hash", QString());
410 } else if (item->clipType() == IMAGE) {
411 item->referencedClip()->producer()->set("force_reload", 1);
413 //requestClipInfo(item->toXml(), item->clipId(), true);
414 // Clear the file_hash value, which will cause a complete reload of the clip
415 emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
420 void ProjectList::slotModifiedClip(const QString &id)
422 ProjectItem *item = getItemById(id);
424 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
425 if (!pixmap.isNull()) {
427 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
428 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
431 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
433 item->setData(0, Qt::DecorationRole, pixmap);
437 void ProjectList::slotMissingClip(const QString &id)
439 ProjectItem *item = getItemById(id);
441 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
442 if (item->referencedClip()) {
443 item->referencedClip()->setPlaceHolder(true);
444 if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR";
445 item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
446 item->slotSetToolTip();
447 emit clipNeedsReload(id, true);
451 emit displayMessage(i18n("Check missing clips"), -2);
452 emit updateRenderStatus();
455 void ProjectList::slotAvailableClip(const QString &id)
457 ProjectItem *item = getItemById(id);
460 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
461 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
462 item->setProperty("file_hash", QString());
466 item->referencedClip()->setValid();
467 item->slotSetToolTip();
470 emit updateRenderStatus();
473 bool ProjectList::hasMissingClips()
475 bool missing = false;
476 QTreeWidgetItemIterator it(m_listView);
478 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
487 void ProjectList::setRenderer(Render *projectRender)
489 m_render = projectRender;
490 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
493 void ProjectList::slotClipSelected()
495 if (!m_listView->isEnabled()) return;
496 if (m_listView->currentItem()) {
497 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
498 emit clipSelected(NULL);
499 m_editAction->setEnabled(false);
500 m_deleteAction->setEnabled(true);
501 m_openAction->setEnabled(false);
502 m_reloadAction->setEnabled(false);
503 m_transcodeAction->setEnabled(false);
506 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
507 // this is a sub item, use base clip
508 m_deleteAction->setEnabled(true);
509 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
510 if (clip == NULL) kDebug() << "-----------ERROR";
511 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
512 emit clipSelected(clip->referencedClip(), sub->zone());
513 m_transcodeAction->setEnabled(false);
516 clip = static_cast <ProjectItem*>(m_listView->currentItem());
518 emit clipSelected(clip->referencedClip());
519 m_editAction->setEnabled(true);
520 m_deleteAction->setEnabled(true);
521 m_reloadAction->setEnabled(true);
522 m_transcodeAction->setEnabled(true);
523 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
524 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
525 m_openAction->setEnabled(true);
526 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
527 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
528 m_openAction->setEnabled(true);
530 m_openAction->setEnabled(false);
532 // Display relevant transcoding actions only
533 adjustTranscodeActions(clip);
534 // Display uses in timeline
535 emit findInTimeline(clip->clipId());
538 emit clipSelected(NULL);
539 m_editAction->setEnabled(false);
540 m_deleteAction->setEnabled(false);
541 m_openAction->setEnabled(false);
542 m_reloadAction->setEnabled(false);
543 m_transcodeAction->setEnabled(false);
547 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
549 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
550 m_transcodeAction->setEnabled(false);
553 m_transcodeAction->setEnabled(true);
554 QList<QAction *> transcodeActions = m_transcodeAction->actions();
557 for (int i = 0; i < transcodeActions.count(); i++) {
558 data = transcodeActions.at(i)->data().toStringList();
559 if (data.count() > 2) {
560 condition = data.at(2);
561 if (condition.startsWith("vcodec"))
562 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section("=", 1, 1)));
563 else if (condition.startsWith("acodec"))
564 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section("=", 1, 1)));
570 void ProjectList::slotPauseMonitor()
576 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
578 ProjectItem *item = getItemById(id);
580 slotUpdateClipProperties(item, properties);
581 if (properties.contains("out") || properties.contains("force_fps")) {
583 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
584 slotRefreshClipThumbnail(item);
590 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
594 clip->setProperties(properties);
595 if (properties.contains("name")) {
596 m_listView->blockSignals(true);
597 clip->setText(0, properties.value("name"));
598 m_listView->blockSignals(false);
599 emit clipNameChanged(clip->clipId(), properties.value("name"));
601 if (properties.contains("description")) {
602 CLIPTYPE type = clip->clipType();
603 m_listView->blockSignals(true);
604 clip->setText(1, properties.value("description"));
605 m_listView->blockSignals(false);
607 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
608 // Use Nepomuk system to store clip description
609 Nepomuk::Resource f(clip->clipUrl().path());
610 f.setDescription(properties.value("description"));
613 emit projectModified();
617 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
619 if (item->type() == PROJECTSUBCLIPTYPE) {
620 // this is a sub-item
622 // user edited description
623 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
624 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
625 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
626 m_commandStack->push(command);
627 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
631 if (item->type() == PROJECTFOLDERTYPE) {
633 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
634 editFolder(item->text(0), folder->groupName(), folder->clipId());
635 folder->setGroupName(item->text(0));
636 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
637 const int children = item->childCount();
638 for (int i = 0; i < children; i++) {
639 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
640 child->setProperty("groupname", item->text(0));
646 ProjectItem *clip = static_cast <ProjectItem*>(item);
648 if (clip->referencedClip()) {
649 QMap <QString, QString> oldprops;
650 QMap <QString, QString> newprops;
651 oldprops["description"] = clip->referencedClip()->getProperty("description");
652 newprops["description"] = item->text(1);
654 if (clip->clipType() == TEXT) {
655 // This is a text template clip, update the image
656 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
657 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
658 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
659 newprops.insert("templatetext", item->text(1));
661 slotUpdateClipProperties(clip->clipId(), newprops);
662 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
663 m_commandStack->push(command);
665 } else if (column == 0) {
666 if (clip->referencedClip()) {
667 QMap <QString, QString> oldprops;
668 QMap <QString, QString> newprops;
669 oldprops["name"] = clip->referencedClip()->getProperty("name");
670 newprops["name"] = item->text(0);
671 slotUpdateClipProperties(clip, newprops);
672 emit projectModified();
673 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
674 m_commandStack->push(command);
679 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
681 bool enable = item ? true : false;
682 m_editAction->setEnabled(enable);
683 m_deleteAction->setEnabled(enable);
684 m_reloadAction->setEnabled(enable);
685 m_transcodeAction->setEnabled(enable);
687 ProjectItem *clip = NULL;
688 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
689 clip = static_cast <ProjectItem*>(item->parent());
690 m_transcodeAction->setEnabled(false);
691 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
692 clip = static_cast <ProjectItem*>(item);
693 // Display relevant transcoding actions only
694 adjustTranscodeActions(clip);
695 // Display uses in timeline
696 emit findInTimeline(clip->clipId());
698 m_transcodeAction->setEnabled(false);
700 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
701 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
702 m_openAction->setEnabled(true);
703 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
704 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
705 m_openAction->setEnabled(true);
707 m_openAction->setEnabled(false);
711 m_openAction->setEnabled(false);
716 void ProjectList::slotRemoveClip()
718 if (!m_listView->currentItem())
721 QMap <QString, QString> folderids;
722 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
724 QUndoCommand *delCommand = new QUndoCommand();
725 delCommand->setText(i18n("Delete Clip Zone"));
727 for (int i = 0; i < selected.count(); i++) {
728 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
730 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
731 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
732 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
733 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
735 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
736 folderids[folder->groupName()] = folder->clipId();
737 int children = folder->childCount();
739 if (children > 0 && 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, folder->text(1)), i18n("Delete Folder")) != KMessageBox::Yes)
741 for (int i = 0; i < children; ++i) {
742 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
743 ids << child->clipId();
746 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
747 ids << item->clipId();
748 if (item->numReferences() > 0 && 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)
753 if (delCommand->childCount() == 0)
756 m_commandStack->push(delCommand);
757 emit deleteProjectClips(ids, folderids);
760 void ProjectList::updateButtons() const
762 if (m_listView->topLevelItemCount() == 0) {
763 m_deleteAction->setEnabled(false);
765 m_deleteAction->setEnabled(true);
766 if (!m_listView->currentItem())
767 m_listView->setCurrentItem(m_listView->topLevelItem(0));
768 QTreeWidgetItem *item = m_listView->currentItem();
769 if (item && item->type() == PROJECTCLIPTYPE) {
770 m_editAction->setEnabled(true);
771 m_openAction->setEnabled(true);
772 m_reloadAction->setEnabled(true);
773 m_transcodeAction->setEnabled(true);
778 m_editAction->setEnabled(false);
779 m_openAction->setEnabled(false);
780 m_reloadAction->setEnabled(false);
781 m_transcodeAction->setEnabled(false);
784 void ProjectList::selectItemById(const QString &clipId)
786 ProjectItem *item = getItemById(clipId);
788 m_listView->setCurrentItem(item);
792 void ProjectList::slotDeleteClip(const QString &clipId)
794 ProjectItem *item = getItemById(clipId);
796 kDebug() << "/// Cannot find clip to delete";
799 m_listView->blockSignals(true);
800 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
801 if (!newSelectedItem)
802 newSelectedItem = m_listView->itemBelow(item);
804 m_doc->clipManager()->deleteClip(clipId);
805 m_listView->blockSignals(false);
806 if (newSelectedItem) {
807 m_listView->setCurrentItem(newSelectedItem);
810 emit clipSelected(NULL);
815 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
817 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
818 m_commandStack->push(command);
819 m_doc->setModified(true);
822 void ProjectList::slotAddFolder()
824 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
825 m_commandStack->push(command);
828 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
831 FolderProjectItem *item = getFolderItemById(clipId);
833 m_doc->clipManager()->deleteFolder(clipId);
834 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
835 if (!newSelectedItem)
836 newSelectedItem = m_listView->itemBelow(item);
839 m_listView->setCurrentItem(newSelectedItem);
845 FolderProjectItem *item = getFolderItemById(clipId);
847 m_listView->blockSignals(true);
848 item->setGroupName(foldername);
849 m_listView->blockSignals(false);
850 m_doc->clipManager()->addFolder(clipId, foldername);
851 const int children = item->childCount();
852 for (int i = 0; i < children; i++) {
853 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
854 child->setProperty("groupname", foldername);
858 m_listView->blockSignals(true);
859 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
860 m_doc->clipManager()->addFolder(clipId, foldername);
861 m_listView->blockSignals(false);
862 m_listView->editItem(m_listView->currentItem(), 0);
866 m_doc->setModified(true);
871 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
873 QMapIterator<QString, QString> i(map);
874 QUndoCommand *delCommand = new QUndoCommand();
875 delCommand->setText(i18n("Delete Folder"));
876 while (i.hasNext()) {
878 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
880 m_commandStack->push(delCommand);
883 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
885 m_listView->setEnabled(false);
887 m_listView->blockSignals(true);
889 // remove file_hash so that we load all properties for the clip
890 QDomElement e = clip->toXML().cloneNode().toElement();
891 e.removeAttribute("file_hash");
892 m_infoQueue.insert(clip->getId(), e);
893 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
895 clip->askForAudioThumbs();
896 const QString parent = clip->getProperty("groupid");
897 ProjectItem *item = NULL;
898 if (!parent.isEmpty()) {
899 FolderProjectItem *parentitem = getFolderItemById(parent);
902 QString groupName = clip->getProperty("groupname");
903 //kDebug() << "Adding clip to new group: " << groupName;
904 if (groupName.isEmpty()) groupName = i18n("Folder");
906 parentitem = new FolderProjectItem(m_listView, text, parent);
910 item = new ProjectItem(parentitem, clip);
913 item = new ProjectItem(m_listView, clip);
914 KUrl url = clip->fileURL();
916 if (getProperties == false && !clip->getClipHash().isEmpty()) {
917 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
918 if (QFile::exists(cachedPixmap)) {
919 QPixmap pix(cachedPixmap);
921 KIO::NetAccess::del(KUrl(cachedPixmap), this);
922 item->setData(0, Qt::DecorationRole, pix);
926 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
927 // if file has Nepomuk comment, use it
928 Nepomuk::Resource f(url.path());
929 QString annotation = f.description();
930 if (!annotation.isEmpty()) item->setText(1, annotation);
931 item->setText(2, QString::number(f.rating()));
935 QList <CutZoneInfo> cuts = clip->cutZones();
936 if (!cuts.isEmpty()) {
937 for (int i = 0; i < cuts.count(); i++) {
938 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
939 if (!clip->getClipHash().isEmpty()) {
940 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
941 if (QFile::exists(cachedPixmap)) {
942 QPixmap pix(cachedPixmap);
944 KIO::NetAccess::del(KUrl(cachedPixmap), this);
945 sub->setData(0, Qt::DecorationRole, pix);
950 if (m_listView->isEnabled()) {
953 m_listView->blockSignals(false);
955 if (getProperties && !m_queueTimer.isActive())
956 m_queueTimer.start();
959 void ProjectList::slotResetProjectList()
962 emit clipSelected(NULL);
963 m_thumbnailQueue.clear();
968 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
971 m_infoQueue.insert(id, xml);
972 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
975 void ProjectList::slotProcessNextClipInQueue()
977 if (m_infoQueue.isEmpty()) {
978 slotProcessNextThumbnail();
982 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
983 if (j != m_infoQueue.constEnd()) {
984 const QDomElement dom = j.value();
985 const QString id = j.key();
986 m_infoQueue.remove(j.key());
987 emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
991 void ProjectList::slotUpdateClip(const QString &id)
993 ProjectItem *item = getItemById(id);
994 m_listView->blockSignals(true);
995 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
996 m_listView->blockSignals(false);
999 void ProjectList::updateAllClips()
1001 m_listView->setSortingEnabled(false);
1002 kDebug() << "// UPDATE ALL CLPY";
1004 QTreeWidgetItemIterator it(m_listView);
1007 m_listView->blockSignals(true);
1009 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1011 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1012 if (sub->data(0, Qt::DecorationRole).isNull()) {
1013 item = static_cast <ProjectItem *>((*it)->parent());
1014 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1018 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1023 item = static_cast <ProjectItem *>(*it);
1024 clip = item->referencedClip();
1025 if (item->referencedClip()->producer() == NULL) {
1026 if (clip->isPlaceHolder() == false)
1027 requestClipInfo(clip->toXML(), clip->getId());
1028 else if (!clip->isPlaceHolder())
1029 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1031 if (item->data(0, Qt::DecorationRole).isNull())
1032 requestClipThumbnail(clip->getId());
1033 if (item->data(0, DurationRole).toString().isEmpty())
1034 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1036 item->setData(0, UsageRole, QString::number(item->numReferences()));
1038 //qApp->processEvents();
1041 if (!m_queueTimer.isActive())
1042 m_queueTimer.start();
1043 if (m_listView->isEnabled())
1044 m_listView->blockSignals(false);
1045 m_listView->setSortingEnabled(true);
1046 if (m_infoQueue.isEmpty())
1047 slotProcessNextThumbnail();
1051 QString ProjectList::getExtensions()
1053 // Build list of mime types
1054 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1055 << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "video/mp4" << "video/quicktime"
1056 << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg"
1057 << "image/gif" << "image/jpeg" << "image/png" << "image/x-tga" << "image/x-bmp" << "image/svg+xml" << "image/tiff" << "image/x-xcf" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr";
1059 QString allExtensions;
1060 foreach(const QString& mimeType, mimeTypes) {
1061 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1063 allExtensions.append(mime->patterns().join(" "));
1064 allExtensions.append(' ');
1067 return allExtensions.simplified();
1070 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1072 if (!m_commandStack)
1073 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1076 if (givenList.isEmpty()) {
1077 QString allExtensions = getExtensions();
1078 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1079 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
1082 for (int i = 0; i < givenList.count(); i++)
1083 list << givenList.at(i);
1086 foreach(const KUrl &file, list) {
1087 // Check there is no folder here
1088 KMimeType::Ptr type = KMimeType::findByUrl(file);
1089 if (type->is("inode/directory")) {
1090 // user dropped a folder
1091 list.removeAll(file);
1098 if (givenList.isEmpty()) {
1099 QStringList groupInfo = getGroup();
1100 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1102 m_doc->slotAddClipList(list, groupName, groupId);
1106 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1108 ProjectItem *item = getItemById(id);
1109 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1111 const QString path = item->referencedClip()->fileURL().path();
1112 if (item->referencedClip()->isPlaceHolder()) replace = false;
1113 if (!path.isEmpty()) {
1115 KMessageBox::sorry(this, i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1116 else if (KMessageBox::questionYesNo(this, i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes)
1120 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1124 void ProjectList::slotAddColorClip()
1126 if (!m_commandStack)
1127 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1129 QDialog *dia = new QDialog(this);
1130 Ui::ColorClip_UI dia_ui;
1131 dia_ui.setupUi(dia);
1132 dia->setWindowTitle(i18n("Color Clip"));
1133 dia_ui.clip_name->setText(i18n("Color Clip"));
1135 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1136 t->setValue(KdenliveSettings::color_duration());
1137 t->setTimeCodeFormat(false);
1138 dia_ui.clip_durationBox->addWidget(t);
1139 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1141 if (dia->exec() == QDialog::Accepted) {
1142 QString color = dia_ui.clip_color->color().name();
1143 KdenliveSettings::setColorclipcolor(color);
1144 color = color.replace(0, 1, "0x") + "ff";
1145 QStringList groupInfo = getGroup();
1146 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1153 void ProjectList::slotAddSlideshowClip()
1155 if (!m_commandStack)
1156 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1158 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1160 if (dia->exec() == QDialog::Accepted) {
1161 QStringList groupInfo = getGroup();
1162 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(),
1163 dia->lumaDuration(), dia->lumaFile(), dia->softness(), groupInfo.at(0), groupInfo.at(1));
1168 void ProjectList::slotAddTitleClip()
1170 QStringList groupInfo = getGroup();
1171 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1174 void ProjectList::slotAddTitleTemplateClip()
1176 if (!m_commandStack)
1177 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1179 QStringList groupInfo = getGroup();
1181 // Get the list of existing templates
1183 filter << "*.kdenlivetitle";
1184 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1185 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1187 QDialog *dia = new QDialog(this);
1188 Ui::TemplateClip_UI dia_ui;
1189 dia_ui.setupUi(dia);
1190 for (int i = 0; i < templateFiles.size(); ++i)
1191 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1193 if (!templateFiles.isEmpty())
1194 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1195 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
1196 //warning: setting base directory doesn't work??
1197 KUrl startDir(path);
1198 dia_ui.template_list->fileDialog()->setUrl(startDir);
1199 dia_ui.text_box->setHidden(true);
1200 if (dia->exec() == QDialog::Accepted) {
1201 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1202 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1203 // Create a cloned template clip
1204 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1209 QStringList ProjectList::getGroup() const
1212 QTreeWidgetItem *item = m_listView->currentItem();
1213 while (item && item->type() != PROJECTFOLDERTYPE)
1214 item = item->parent();
1217 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1218 result << folder->groupName() << folder->clipId();
1220 result << QString() << QString();
1225 void ProjectList::setDocument(KdenliveDoc *doc)
1227 m_listView->blockSignals(true);
1228 m_listView->clear();
1229 m_listView->setSortingEnabled(false);
1230 emit clipSelected(NULL);
1231 m_thumbnailQueue.clear();
1232 m_infoQueue.clear();
1233 m_refreshed = false;
1235 m_timecode = doc->timecode();
1236 m_commandStack = doc->commandStack();
1239 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1240 QMapIterator<QString, QString> f(flist);
1241 while (f.hasNext()) {
1243 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1246 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1247 for (int i = 0; i < list.count(); i++)
1248 slotAddClip(list.at(i), false);
1250 m_listView->blockSignals(false);
1251 m_toolbar->setEnabled(true);
1252 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1253 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1254 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1255 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1256 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1259 QList <DocClipBase*> ProjectList::documentClipList() const
1262 return QList <DocClipBase*> ();
1264 return m_doc->clipManager()->documentClipList();
1267 QDomElement ProjectList::producersList()
1270 QDomElement prods = doc.createElement("producerlist");
1271 doc.appendChild(prods);
1272 kDebug() << "//////////// PRO LISTÂ BUILD PRDSLIST ";
1273 QTreeWidgetItemIterator it(m_listView);
1275 if ((*it)->type() != PROJECTCLIPTYPE) {
1280 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1286 void ProjectList::slotCheckForEmptyQueue()
1288 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1290 emit loadingIsOver();
1291 emit displayMessage(QString(), -1);
1292 m_listView->blockSignals(false);
1293 m_listView->setEnabled(true);
1295 } else if (!m_refreshed) {
1296 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1300 void ProjectList::reloadClipThumbnails()
1302 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
1303 m_thumbnailQueue.clear();
1304 QTreeWidgetItemIterator it(m_listView);
1306 if ((*it)->type() != PROJECTCLIPTYPE) {
1311 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1314 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1317 void ProjectList::requestClipThumbnail(const QString id)
1319 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1322 void ProjectList::slotProcessNextThumbnail()
1324 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1325 slotCheckForEmptyQueue();
1328 if (!m_infoQueue.isEmpty()) {
1329 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1332 if (m_thumbnailQueue.count() > 1) {
1333 int max = m_doc->clipManager()->clipsCount();
1334 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1336 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1339 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1341 QTreeWidgetItem *item = getAnyItemById(clipId);
1343 slotRefreshClipThumbnail(item, update);
1345 slotProcessNextThumbnail();
1348 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1350 if (it == NULL) return;
1351 ProjectItem *item = NULL;
1352 bool isSubItem = false;
1354 if (it->type() == PROJECTFOLDERTYPE) return;
1355 if (it->type() == PROJECTSUBCLIPTYPE) {
1356 item = static_cast <ProjectItem *>(it->parent());
1357 frame = static_cast <SubProjectItem *>(it)->zone().x();
1360 item = static_cast <ProjectItem *>(it);
1361 frame = item->referencedClip()->getClipThumbFrame();
1365 DocClipBase *clip = item->referencedClip();
1367 slotProcessNextThumbnail();
1371 int height = m_listView->iconSize().height();
1372 int width = (int)(height * m_render->dar());
1373 if (clip->clipType() == AUDIO)
1374 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1375 else if (clip->clipType() == IMAGE)
1376 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1378 pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1380 if (!pix.isNull()) {
1381 m_listView->blockSignals(true);
1382 it->setData(0, Qt::DecorationRole, pix);
1383 if (m_listView->isEnabled())
1384 m_listView->blockSignals(false);
1386 m_doc->cachePixmap(item->getClipHash(), pix);
1388 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1391 emit projectModified();
1392 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1396 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1399 ProjectItem *item = getItemById(clipId);
1400 if (item && producer) {
1401 m_listView->blockSignals(true);
1402 item->setProperties(properties, metadata);
1403 if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1404 item->referencedClip()->setValid();
1405 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1408 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1409 item->referencedClip()->setProducer(producer, replace);
1410 item->referencedClip()->askForAudioThumbs();
1411 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1412 requestClipThumbnail(clipId);
1413 if (!toReload.isEmpty())
1414 item->slotSetToolTip();
1416 //emit receivedClipDuration(clipId);
1417 if (m_listView->isEnabled() && replace) {
1418 // update clip in clip monitor
1419 emit clipSelected(NULL);
1420 emit clipSelected(item->referencedClip());
1421 //TODO: Make sure the line below has no side effect
1425 // Check if duration changed.
1426 emit receivedClipDuration(clipId);
1429 if (m_listView->isEnabled())
1430 m_listView->blockSignals(false);
1431 /*if (item->icon(0).isNull()) {
1432 requestClipThumbnail(clipId);
1434 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1435 int max = m_doc->clipManager()->clipsCount();
1436 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1437 m_listView->setCurrentItem(item);
1438 if (item->parent()) {
1439 if (item->parent()->type() == PROJECTFOLDERTYPE)
1440 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1442 emit clipSelected(item->referencedClip());
1444 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1446 if (!toReload.isEmpty())
1447 emit clipNeedsReload(toReload, true);
1448 // small delay so that the app can display the progress info
1449 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1452 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1454 ProjectItem *item = getItemById(clipId);
1455 if (item && !pix.isNull()) {
1456 m_listView->blockSignals(true);
1457 item->setData(0, Qt::DecorationRole, pix);
1458 m_doc->cachePixmap(item->getClipHash(), pix);
1459 if (m_listView->isEnabled())
1460 m_listView->blockSignals(false);
1464 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1466 QTreeWidgetItemIterator it(m_listView);
1467 QString lookId = id;
1468 if (id.contains('#'))
1469 lookId = id.section('#', 0, 0);
1471 ProjectItem *result = NULL;
1473 if ((*it)->type() != PROJECTCLIPTYPE) {
1478 ProjectItem *item = static_cast<ProjectItem *>(*it);
1479 if (item->clipId() == lookId) {
1485 if (result == NULL || !id.contains('#')) {
1488 for (int i = 0; i < result->childCount(); i++) {
1489 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1490 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1499 ProjectItem *ProjectList::getItemById(const QString &id)
1502 QTreeWidgetItemIterator it(m_listView);
1504 if ((*it)->type() != PROJECTCLIPTYPE) {
1509 item = static_cast<ProjectItem *>(*it);
1510 if (item->clipId() == id)
1517 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1519 FolderProjectItem *item;
1520 QTreeWidgetItemIterator it(m_listView);
1522 if ((*it)->type() == PROJECTFOLDERTYPE) {
1523 item = static_cast<FolderProjectItem *>(*it);
1524 if (item->clipId() == id)
1532 void ProjectList::slotSelectClip(const QString &ix)
1534 ProjectItem *clip = getItemById(ix);
1536 m_listView->setCurrentItem(clip);
1537 m_listView->scrollToItem(clip);
1538 m_editAction->setEnabled(true);
1539 m_deleteAction->setEnabled(true);
1540 m_reloadAction->setEnabled(true);
1541 m_transcodeAction->setEnabled(true);
1542 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1543 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1544 m_openAction->setEnabled(true);
1545 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1546 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1547 m_openAction->setEnabled(true);
1549 m_openAction->setEnabled(false);
1554 QString ProjectList::currentClipUrl() const
1557 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1558 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1560 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1562 item = static_cast <ProjectItem*>(m_listView->currentItem());
1566 return item->clipUrl().path();
1569 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1573 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1574 for (int i = 0; i < list.count(); i++) {
1575 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1577 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1579 item = static_cast <ProjectItem*>(list.at(i)->parent());
1581 item = static_cast <ProjectItem*>(list.at(i));
1583 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1585 DocClipBase *clip = item->referencedClip();
1586 if (!condition.isEmpty()) {
1587 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section("=", 1, 1)))
1589 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section("=", 1, 1)))
1592 result.append(item->clipUrl());
1597 void ProjectList::regenerateTemplate(const QString &id)
1599 ProjectItem *clip = getItemById(id);
1601 regenerateTemplate(clip);
1604 void ProjectList::regenerateTemplate(ProjectItem *clip)
1606 //TODO: remove this unused method, only force_reload is necessary
1607 clip->referencedClip()->producer()->set("force_reload", 1);
1610 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1614 if (!file.open(QIODevice::ReadOnly)) {
1615 kWarning() << "ERROR, CANNOT READ: " << path;
1618 if (!doc.setContent(&file)) {
1619 kWarning() << "ERROR, CANNOT READ: " << path;
1624 QDomNodeList texts = doc.elementsByTagName("content");
1625 for (int i = 0; i < texts.count(); i++) {
1626 QString data = texts.item(i).firstChild().nodeValue();
1627 data.replace("%s", replaceString);
1628 texts.item(i).firstChild().setNodeValue(data);
1634 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1636 ProjectItem *clip = getItemById(id);
1637 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1639 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1640 m_commandStack->push(command);
1643 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1645 ProjectItem *clip = getItemById(id);
1647 DocClipBase *base = clip->referencedClip();
1648 base->addCutZone(in, out);
1649 m_listView->blockSignals(true);
1650 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1651 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1652 if (!clip->isExpanded())
1653 clip->setExpanded(true);
1654 m_listView->scrollToItem(sub);
1655 m_listView->editItem(sub, 1);
1657 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1658 sub->setData(0, Qt::DecorationRole, p);
1659 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1660 m_listView->blockSignals(false);
1662 emit projectModified();
1665 void ProjectList::removeClipCut(const QString &id, int in, int out)
1667 ProjectItem *clip = getItemById(id);
1669 DocClipBase *base = clip->referencedClip();
1670 base->removeCutZone(in, out);
1671 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1673 m_listView->blockSignals(true);
1675 m_listView->blockSignals(false);
1678 emit projectModified();
1681 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1683 SubProjectItem *sub = NULL;
1685 for (int i = 0; i < clip->childCount(); i++) {
1686 QTreeWidgetItem *it = clip->child(i);
1687 if (it->type() == PROJECTSUBCLIPTYPE) {
1688 sub = static_cast <SubProjectItem*>(it);
1689 if (sub->zone() == zone)
1699 void ProjectList::slotUpdateClipCut(QPoint p)
1701 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
1703 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1704 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1705 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1706 m_commandStack->push(command);
1709 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1711 ProjectItem *clip = getItemById(id);
1712 SubProjectItem *sub = getSubItem(clip, oldzone);
1713 if (sub == NULL || clip == NULL)
1715 DocClipBase *base = clip->referencedClip();
1716 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1717 m_listView->blockSignals(true);
1719 sub->setDescription(comment);
1720 m_listView->blockSignals(false);
1721 emit projectModified();
1724 #include "projectlist.moc"