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 slotProcessNextClipInQueue();
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);
989 if (!m_infoQueue.isEmpty()) m_queueTimer.start();
992 void ProjectList::slotUpdateClip(const QString &id)
994 ProjectItem *item = getItemById(id);
995 m_listView->blockSignals(true);
996 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
997 m_listView->blockSignals(false);
1000 void ProjectList::updateAllClips()
1002 m_listView->setSortingEnabled(false);
1003 kDebug() << "// UPDATE ALL CLPY";
1005 QTreeWidgetItemIterator it(m_listView);
1008 m_listView->blockSignals(true);
1010 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1012 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1013 if (sub->data(0, Qt::DecorationRole).isNull()) {
1014 item = static_cast <ProjectItem *>((*it)->parent());
1015 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1019 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1024 item = static_cast <ProjectItem *>(*it);
1025 clip = item->referencedClip();
1026 if (item->referencedClip()->producer() == NULL) {
1027 if (clip->isPlaceHolder() == false)
1028 requestClipInfo(clip->toXML(), clip->getId());
1029 else if (!clip->isPlaceHolder())
1030 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1032 if (item->data(0, Qt::DecorationRole).isNull())
1033 requestClipThumbnail(clip->getId());
1034 if (item->data(0, DurationRole).toString().isEmpty())
1035 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1037 item->setData(0, UsageRole, QString::number(item->numReferences()));
1039 //qApp->processEvents();
1042 if (!m_queueTimer.isActive())
1043 m_queueTimer.start();
1044 if (m_listView->isEnabled())
1045 m_listView->blockSignals(false);
1046 m_listView->setSortingEnabled(true);
1047 if (m_infoQueue.isEmpty())
1048 slotProcessNextThumbnail();
1052 QString ProjectList::getExtensions()
1054 // Build list of mime types
1055 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1056 << "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"
1057 << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "application/mxf"
1058 << "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";
1060 QString allExtensions;
1061 foreach(const QString& mimeType, mimeTypes) {
1062 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1064 allExtensions.append(mime->patterns().join(" "));
1065 allExtensions.append(' ');
1068 return allExtensions.simplified();
1071 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1073 if (!m_commandStack)
1074 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1077 if (givenList.isEmpty()) {
1078 QString allExtensions = getExtensions();
1079 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1080 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1081 b->setChecked(KdenliveSettings::autoimagesequence());
1082 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, this, b);
1083 d->setOperationMode(KFileDialog::Opening);
1084 d->setMode(KFile::Files);
1086 list = d->selectedUrls();
1087 if (b->isChecked() && list.count() == 1) {
1088 // Check for image sequence
1089 KUrl url = list.at(0);
1090 QString fileName = url.fileName().section('.', 0, -2);
1091 if (fileName.at(fileName.size() - 1).isDigit()) {
1092 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1093 if (item.mimetype().startsWith("image")) {
1095 // import as sequence if we found more than one image in the sequence
1096 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &count);
1099 QStringList groupInfo = getGroup();
1101 // get image sequence base name
1102 while (fileName.at(fileName.size() - 1).isDigit()) {
1106 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1107 false, false, false,
1108 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1109 QString(), groupInfo.at(0), groupInfo.at(1));
1117 for (int i = 0; i < givenList.count(); i++)
1118 list << givenList.at(i);
1121 foreach(const KUrl &file, list) {
1122 // Check there is no folder here
1123 KMimeType::Ptr type = KMimeType::findByUrl(file);
1124 if (type->is("inode/directory")) {
1125 // user dropped a folder
1126 list.removeAll(file);
1133 if (givenList.isEmpty()) {
1134 QStringList groupInfo = getGroup();
1135 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1137 m_doc->slotAddClipList(list, groupName, groupId);
1141 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1143 ProjectItem *item = getItemById(id);
1144 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1146 const QString path = item->referencedClip()->fileURL().path();
1147 if (item->referencedClip()->isPlaceHolder()) replace = false;
1148 if (!path.isEmpty()) {
1150 KMessageBox::sorry(this, i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1151 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)
1155 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1159 void ProjectList::slotAddColorClip()
1161 if (!m_commandStack)
1162 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1164 QDialog *dia = new QDialog(this);
1165 Ui::ColorClip_UI dia_ui;
1166 dia_ui.setupUi(dia);
1167 dia->setWindowTitle(i18n("Color Clip"));
1168 dia_ui.clip_name->setText(i18n("Color Clip"));
1170 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1171 t->setValue(KdenliveSettings::color_duration());
1172 t->setTimeCodeFormat(false);
1173 dia_ui.clip_durationBox->addWidget(t);
1174 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1176 if (dia->exec() == QDialog::Accepted) {
1177 QString color = dia_ui.clip_color->color().name();
1178 KdenliveSettings::setColorclipcolor(color);
1179 color = color.replace(0, 1, "0x") + "ff";
1180 QStringList groupInfo = getGroup();
1181 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1188 void ProjectList::slotAddSlideshowClip()
1190 if (!m_commandStack)
1191 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1193 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1195 if (dia->exec() == QDialog::Accepted) {
1196 QStringList groupInfo = getGroup();
1197 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1198 dia->loop(), dia->crop(), dia->fade(),
1199 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1200 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1205 void ProjectList::slotAddTitleClip()
1207 QStringList groupInfo = getGroup();
1208 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1211 void ProjectList::slotAddTitleTemplateClip()
1213 if (!m_commandStack)
1214 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1216 QStringList groupInfo = getGroup();
1218 // Get the list of existing templates
1220 filter << "*.kdenlivetitle";
1221 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1222 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1224 QDialog *dia = new QDialog(this);
1225 Ui::TemplateClip_UI dia_ui;
1226 dia_ui.setupUi(dia);
1227 for (int i = 0; i < templateFiles.size(); ++i)
1228 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1230 if (!templateFiles.isEmpty())
1231 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1232 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
1233 //warning: setting base directory doesn't work??
1234 KUrl startDir(path);
1235 dia_ui.template_list->fileDialog()->setUrl(startDir);
1236 dia_ui.text_box->setHidden(true);
1237 if (dia->exec() == QDialog::Accepted) {
1238 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1239 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1240 // Create a cloned template clip
1241 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1246 QStringList ProjectList::getGroup() const
1249 QTreeWidgetItem *item = m_listView->currentItem();
1250 while (item && item->type() != PROJECTFOLDERTYPE)
1251 item = item->parent();
1254 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1255 result << folder->groupName() << folder->clipId();
1257 result << QString() << QString();
1262 void ProjectList::setDocument(KdenliveDoc *doc)
1264 m_listView->blockSignals(true);
1265 m_listView->clear();
1266 m_listView->setSortingEnabled(false);
1267 emit clipSelected(NULL);
1268 m_thumbnailQueue.clear();
1269 m_infoQueue.clear();
1270 m_refreshed = false;
1272 m_timecode = doc->timecode();
1273 m_commandStack = doc->commandStack();
1276 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1277 QMapIterator<QString, QString> f(flist);
1278 while (f.hasNext()) {
1280 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1283 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1284 for (int i = 0; i < list.count(); i++)
1285 slotAddClip(list.at(i), false);
1287 m_listView->blockSignals(false);
1288 m_toolbar->setEnabled(true);
1289 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1290 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1291 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1292 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1293 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1296 QList <DocClipBase*> ProjectList::documentClipList() const
1299 return QList <DocClipBase*> ();
1301 return m_doc->clipManager()->documentClipList();
1304 QDomElement ProjectList::producersList()
1307 QDomElement prods = doc.createElement("producerlist");
1308 doc.appendChild(prods);
1309 kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
1310 QTreeWidgetItemIterator it(m_listView);
1312 if ((*it)->type() != PROJECTCLIPTYPE) {
1317 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1323 void ProjectList::slotCheckForEmptyQueue()
1325 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1327 emit loadingIsOver();
1328 emit displayMessage(QString(), -1);
1329 m_listView->blockSignals(false);
1330 m_listView->setEnabled(true);
1332 } else if (!m_refreshed) {
1333 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1337 void ProjectList::reloadClipThumbnails()
1339 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
1340 m_thumbnailQueue.clear();
1341 QTreeWidgetItemIterator it(m_listView);
1343 if ((*it)->type() != PROJECTCLIPTYPE) {
1348 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1351 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1354 void ProjectList::requestClipThumbnail(const QString id)
1356 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1359 void ProjectList::slotProcessNextThumbnail()
1361 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1362 slotCheckForEmptyQueue();
1365 if (!m_infoQueue.isEmpty()) {
1366 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1369 if (m_thumbnailQueue.count() > 1) {
1370 int max = m_doc->clipManager()->clipsCount();
1371 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1373 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1376 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1378 QTreeWidgetItem *item = getAnyItemById(clipId);
1380 slotRefreshClipThumbnail(item, update);
1382 slotProcessNextThumbnail();
1385 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1387 if (it == NULL) return;
1388 ProjectItem *item = NULL;
1389 bool isSubItem = false;
1391 if (it->type() == PROJECTFOLDERTYPE) return;
1392 if (it->type() == PROJECTSUBCLIPTYPE) {
1393 item = static_cast <ProjectItem *>(it->parent());
1394 frame = static_cast <SubProjectItem *>(it)->zone().x();
1397 item = static_cast <ProjectItem *>(it);
1398 frame = item->referencedClip()->getClipThumbFrame();
1402 DocClipBase *clip = item->referencedClip();
1404 slotProcessNextThumbnail();
1408 int height = m_listView->iconSize().height();
1409 int width = (int)(height * m_render->dar());
1410 if (clip->clipType() == AUDIO)
1411 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1412 else if (clip->clipType() == IMAGE)
1413 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1415 pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1417 if (!pix.isNull()) {
1418 m_listView->blockSignals(true);
1419 it->setData(0, Qt::DecorationRole, pix);
1420 if (m_listView->isEnabled())
1421 m_listView->blockSignals(false);
1423 m_doc->cachePixmap(item->getClipHash(), pix);
1425 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1428 emit projectModified();
1429 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1433 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1436 ProjectItem *item = getItemById(clipId);
1437 if (item && producer) {
1438 m_listView->blockSignals(true);
1439 item->setProperties(properties, metadata);
1440 if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1441 item->referencedClip()->setValid();
1442 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1445 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1446 item->referencedClip()->setProducer(producer, replace);
1447 item->referencedClip()->askForAudioThumbs();
1448 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1449 requestClipThumbnail(clipId);
1450 if (!toReload.isEmpty())
1451 item->slotSetToolTip();
1453 //emit receivedClipDuration(clipId);
1454 if (m_listView->isEnabled() && replace) {
1455 // update clip in clip monitor
1456 emit clipSelected(NULL);
1457 emit clipSelected(item->referencedClip());
1458 //TODO: Make sure the line below has no side effect
1462 // Check if duration changed.
1463 emit receivedClipDuration(clipId);
1466 if (m_listView->isEnabled())
1467 m_listView->blockSignals(false);
1468 /*if (item->icon(0).isNull()) {
1469 requestClipThumbnail(clipId);
1471 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1472 int max = m_doc->clipManager()->clipsCount();
1473 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1474 m_listView->setCurrentItem(item);
1475 if (item->parent()) {
1476 if (item->parent()->type() == PROJECTFOLDERTYPE)
1477 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1479 emit clipSelected(item->referencedClip());
1481 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1483 if (!toReload.isEmpty())
1484 emit clipNeedsReload(toReload, true);
1485 // small delay so that the app can display the progress info
1486 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1489 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1491 ProjectItem *item = getItemById(clipId);
1492 if (item && !pix.isNull()) {
1493 m_listView->blockSignals(true);
1494 item->setData(0, Qt::DecorationRole, pix);
1495 m_doc->cachePixmap(item->getClipHash(), pix);
1496 if (m_listView->isEnabled())
1497 m_listView->blockSignals(false);
1501 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1503 QTreeWidgetItemIterator it(m_listView);
1504 QString lookId = id;
1505 if (id.contains('#'))
1506 lookId = id.section('#', 0, 0);
1508 ProjectItem *result = NULL;
1510 if ((*it)->type() != PROJECTCLIPTYPE) {
1515 ProjectItem *item = static_cast<ProjectItem *>(*it);
1516 if (item->clipId() == lookId) {
1522 if (result == NULL || !id.contains('#')) {
1525 for (int i = 0; i < result->childCount(); i++) {
1526 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1527 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1536 ProjectItem *ProjectList::getItemById(const QString &id)
1539 QTreeWidgetItemIterator it(m_listView);
1541 if ((*it)->type() != PROJECTCLIPTYPE) {
1546 item = static_cast<ProjectItem *>(*it);
1547 if (item->clipId() == id)
1554 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1556 FolderProjectItem *item;
1557 QTreeWidgetItemIterator it(m_listView);
1559 if ((*it)->type() == PROJECTFOLDERTYPE) {
1560 item = static_cast<FolderProjectItem *>(*it);
1561 if (item->clipId() == id)
1569 void ProjectList::slotSelectClip(const QString &ix)
1571 ProjectItem *clip = getItemById(ix);
1573 m_listView->setCurrentItem(clip);
1574 m_listView->scrollToItem(clip);
1575 m_editAction->setEnabled(true);
1576 m_deleteAction->setEnabled(true);
1577 m_reloadAction->setEnabled(true);
1578 m_transcodeAction->setEnabled(true);
1579 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1580 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1581 m_openAction->setEnabled(true);
1582 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1583 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1584 m_openAction->setEnabled(true);
1586 m_openAction->setEnabled(false);
1591 QString ProjectList::currentClipUrl() const
1594 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1595 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1597 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1599 item = static_cast <ProjectItem*>(m_listView->currentItem());
1603 return item->clipUrl().path();
1606 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1610 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1611 for (int i = 0; i < list.count(); i++) {
1612 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1614 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1616 item = static_cast <ProjectItem*>(list.at(i)->parent());
1618 item = static_cast <ProjectItem*>(list.at(i));
1620 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1622 DocClipBase *clip = item->referencedClip();
1623 if (!condition.isEmpty()) {
1624 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section("=", 1, 1)))
1626 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section("=", 1, 1)))
1629 result.append(item->clipUrl());
1634 void ProjectList::regenerateTemplate(const QString &id)
1636 ProjectItem *clip = getItemById(id);
1638 regenerateTemplate(clip);
1641 void ProjectList::regenerateTemplate(ProjectItem *clip)
1643 //TODO: remove this unused method, only force_reload is necessary
1644 clip->referencedClip()->producer()->set("force_reload", 1);
1647 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1651 if (!file.open(QIODevice::ReadOnly)) {
1652 kWarning() << "ERROR, CANNOT READ: " << path;
1655 if (!doc.setContent(&file)) {
1656 kWarning() << "ERROR, CANNOT READ: " << path;
1661 QDomNodeList texts = doc.elementsByTagName("content");
1662 for (int i = 0; i < texts.count(); i++) {
1663 QString data = texts.item(i).firstChild().nodeValue();
1664 data.replace("%s", replaceString);
1665 texts.item(i).firstChild().setNodeValue(data);
1671 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1673 ProjectItem *clip = getItemById(id);
1674 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1676 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1677 m_commandStack->push(command);
1680 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1682 ProjectItem *clip = getItemById(id);
1684 DocClipBase *base = clip->referencedClip();
1685 base->addCutZone(in, out);
1686 m_listView->blockSignals(true);
1687 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1688 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1689 if (!clip->isExpanded())
1690 clip->setExpanded(true);
1691 m_listView->scrollToItem(sub);
1692 m_listView->editItem(sub, 1);
1694 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1695 sub->setData(0, Qt::DecorationRole, p);
1696 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1697 m_listView->blockSignals(false);
1699 emit projectModified();
1702 void ProjectList::removeClipCut(const QString &id, int in, int out)
1704 ProjectItem *clip = getItemById(id);
1706 DocClipBase *base = clip->referencedClip();
1707 base->removeCutZone(in, out);
1708 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1710 m_listView->blockSignals(true);
1712 m_listView->blockSignals(false);
1715 emit projectModified();
1718 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1720 SubProjectItem *sub = NULL;
1722 for (int i = 0; i < clip->childCount(); i++) {
1723 QTreeWidgetItem *it = clip->child(i);
1724 if (it->type() == PROJECTSUBCLIPTYPE) {
1725 sub = static_cast <SubProjectItem*>(it);
1726 if (sub->zone() == zone)
1736 void ProjectList::slotUpdateClipCut(QPoint p)
1738 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
1740 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1741 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1742 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1743 m_commandStack->push(command);
1746 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1748 ProjectItem *clip = getItemById(id);
1749 SubProjectItem *sub = getSubItem(clip, oldzone);
1750 if (sub == NULL || clip == NULL)
1752 DocClipBase *base = clip->referencedClip();
1753 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1754 m_listView->blockSignals(true);
1756 sub->setDescription(comment);
1757 m_listView->blockSignals(false);
1758 emit projectModified();
1761 void ProjectList::slotForceProcessing(const QString &id)
1763 while (m_infoQueue.contains(id)) {
1764 slotProcessNextClipInQueue();
1768 #include "projectlist.moc"