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 "profilesdialog.h"
36 #include "editclipcommand.h"
37 #include "editclipcutcommand.h"
38 #include "editfoldercommand.h"
39 #include "addclipcutcommand.h"
41 #include "ui_templateclip_ui.h"
46 #include <KFileDialog>
47 #include <KInputDialog>
48 #include <KMessageBox>
49 #include <KIO/NetAccess>
51 #include <KApplication>
53 #include <nepomuk/global.h>
54 #include <nepomuk/resourcemanager.h>
55 //#include <nepomuk/tag.h>
58 #include <QMouseEvent>
59 #include <QStylePainter>
64 #include <QHeaderView>
65 #include <QInputDialog>
67 ProjectList::ProjectList(QWidget *parent) :
74 m_transcodeAction(NULL),
80 QVBoxLayout *layout = new QVBoxLayout;
81 layout->setContentsMargins(0, 0, 0, 0);
82 layout->setSpacing(0);
85 QFrame *frame = new QFrame;
86 frame->setFrameStyle(QFrame::NoFrame);
87 QHBoxLayout *box = new QHBoxLayout;
88 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
90 box->addWidget(searchView);
91 //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
92 //m_toolbar->setIconSize(QSize(s, s));
94 m_addButton = new QToolButton;
95 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
96 m_addButton->setAutoRaise(true);
97 box->addWidget(m_addButton);
99 m_editButton = new QToolButton;
100 m_editButton->setAutoRaise(true);
101 box->addWidget(m_editButton);
103 m_deleteButton = new QToolButton;
104 m_deleteButton->setAutoRaise(true);
105 box->addWidget(m_deleteButton);
106 frame->setLayout(box);
107 layout->addWidget(frame);
109 m_listView = new ProjectListView;
110 layout->addWidget(m_listView);
112 searchView->setTreeWidget(m_listView);
114 m_queueTimer.setInterval(100);
115 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
116 m_queueTimer.setSingleShot(true);
119 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
120 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
121 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
122 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
123 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
124 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
125 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
126 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
127 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
128 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
130 m_listViewDelegate = new ItemDelegate(m_listView);
131 m_listView->setItemDelegate(m_listViewDelegate);
133 if (KdenliveSettings::activate_nepomuk()) {
134 Nepomuk::ResourceManager::instance()->init();
135 if (!Nepomuk::ResourceManager::instance()->initialized()) {
136 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
137 KdenliveSettings::setActivate_nepomuk(false);
143 ProjectList::~ProjectList()
146 m_listView->blockSignals(true);
148 delete m_listViewDelegate;
151 void ProjectList::focusTree() const
153 m_listView->setFocus();
156 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
158 QList <QAction *> actions = addMenu->actions();
159 for (int i = 0; i < actions.count(); i++) {
160 if (actions.at(i)->data().toString() == "clip_properties") {
161 m_editButton->setDefaultAction(actions.at(i));
164 } else if (actions.at(i)->data().toString() == "delete_clip") {
165 m_deleteButton->setDefaultAction(actions.at(i));
168 } else if (actions.at(i)->data().toString() == "edit_clip") {
169 m_openAction = actions.at(i);
172 } else if (actions.at(i)->data().toString() == "reload_clip") {
173 m_reloadAction = actions.at(i);
179 QMenu *m = new QMenu();
180 m->addActions(actions);
181 m_addButton->setMenu(m);
182 m_addButton->setDefaultAction(defaultAction);
183 m_menu = new QMenu();
184 m_menu->addActions(addMenu->actions());
187 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
191 QMenu *menu = m_addButton->menu();
192 menu->addMenu(addMenu);
193 m_addButton->setMenu(menu);
195 m_menu->addMenu(addMenu);
196 if (addMenu->isEmpty())
197 addMenu->setEnabled(false);
198 m_menu->addMenu(transcodeMenu);
199 if (transcodeMenu->isEmpty())
200 transcodeMenu->setEnabled(false);
201 m_transcodeAction = transcodeMenu;
202 m_menu->addAction(m_reloadAction);
203 m_menu->addMenu(inTimelineMenu);
204 inTimelineMenu->setEnabled(false);
205 m_menu->addAction(m_editButton->defaultAction());
206 m_menu->addAction(m_openAction);
207 m_menu->addAction(m_deleteButton->defaultAction());
208 m_menu->insertSeparator(m_deleteButton->defaultAction());
212 QByteArray ProjectList::headerInfo() const
214 return m_listView->header()->saveState();
217 void ProjectList::setHeaderInfo(const QByteArray &state)
219 m_listView->header()->restoreState(state);
222 void ProjectList::updateProjectFormat(Timecode t)
227 void ProjectList::slotEditClip()
229 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
230 if (list.count() > 1) {
231 editClipSelection(list);
235 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
237 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
238 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
240 item = static_cast <ProjectItem*>(m_listView->currentItem());
241 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
242 emit clipSelected(item->referencedClip());
243 emit showClipProperties(item->referencedClip());
247 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
249 // Gather all common properties
250 QMap <QString, QString> commonproperties;
251 QList <DocClipBase *> clipList;
252 commonproperties.insert("force_aspect_ratio", "-");
253 commonproperties.insert("force_fps", "-");
254 commonproperties.insert("force_progressive", "-");
255 commonproperties.insert("threads", "-");
256 commonproperties.insert("video_index", "-");
257 commonproperties.insert("audio_index", "-");
259 bool allowDurationChange = true;
260 int commonDuration = -1;
262 for (int i = 0; i < list.count(); i++) {
264 if (list.at(i)->type() == PROJECTFOLDERTYPE)
266 if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
267 item = static_cast <ProjectItem*>(list.at(i)->parent());
269 item = static_cast <ProjectItem*>(list.at(i));
270 if (!(item->flags() & Qt::ItemIsDragEnabled))
274 DocClipBase *clip = item->referencedClip();
275 if (clipList.contains(clip)) continue;
276 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
277 allowDurationChange = false;
278 if (allowDurationChange && commonDuration != 0) {
279 if (commonDuration == -1)
280 commonDuration = clip->duration().frames(m_fps);
281 else if (commonDuration != clip->duration().frames(m_fps))
284 clipList.append(clip);
285 QMap <QString, QString> clipprops = clip->properties();
286 QMapIterator<QString, QString> p(commonproperties);
287 while (p.hasNext()) {
289 if (p.value().isEmpty()) continue;
290 if (clipprops.contains(p.key())) {
291 if (p.value() == "-")
292 commonproperties.insert(p.key(), clipprops.value(p.key()));
293 else if (p.value() != clipprops.value(p.key()))
294 commonproperties.insert(p.key(), QString());
296 commonproperties.insert(p.key(), QString());
301 if (allowDurationChange)
302 commonproperties.insert("out", QString::number(commonDuration));
303 QMapIterator<QString, QString> p(commonproperties);
304 while (p.hasNext()) {
306 kDebug() << "Result: " << p.key() << " = " << p.value();
308 emit showClipProperties(clipList, commonproperties);
311 void ProjectList::slotOpenClip()
314 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
316 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
317 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
319 item = static_cast <ProjectItem*>(m_listView->currentItem());
321 if (item->clipType() == IMAGE) {
322 if (KdenliveSettings::defaultimageapp().isEmpty())
323 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
325 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
327 if (item->clipType() == AUDIO) {
328 if (KdenliveSettings::defaultaudioapp().isEmpty())
329 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
331 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
336 void ProjectList::cleanup()
338 m_listView->clearSelection();
339 QTreeWidgetItemIterator it(m_listView);
342 if ((*it)->type() != PROJECTCLIPTYPE) {
346 item = static_cast <ProjectItem *>(*it);
347 if (item->numReferences() == 0)
348 item->setSelected(true);
354 void ProjectList::trashUnusedClips()
356 QTreeWidgetItemIterator it(m_listView);
361 if ((*it)->type() != PROJECTCLIPTYPE) {
365 item = static_cast <ProjectItem *>(*it);
366 if (item->numReferences() == 0) {
367 ids << item->clipId();
368 KUrl url = item->clipUrl();
369 if (!url.isEmpty() && !urls.contains(url.path()))
375 // Check that we don't use the URL in another clip
376 QTreeWidgetItemIterator it2(m_listView);
378 if ((*it2)->type() != PROJECTCLIPTYPE) {
382 item = static_cast <ProjectItem *>(*it2);
383 if (item->numReferences() > 0) {
384 KUrl url = item->clipUrl();
385 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
390 emit deleteProjectClips(ids, QMap <QString, QString>());
391 for (int i = 0; i < urls.count(); i++)
392 KIO::NetAccess::del(KUrl(urls.at(i)), this);
395 void ProjectList::slotReloadClip(const QString &id)
397 QList<QTreeWidgetItem *> selected;
399 selected = m_listView->selectedItems();
401 selected.append(getItemById(id));
403 for (int i = 0; i < selected.count(); i++) {
404 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
405 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
406 for (int j = 0; j < selected.at(i)->childCount(); j++)
407 selected.append(selected.at(i)->child(j));
411 item = static_cast <ProjectItem *>(selected.at(i));
413 if (item->clipType() == TEXT) {
414 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
415 regenerateTemplate(item);
416 } else if (item->clipType() != COLOR && item->clipType() != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
417 item->referencedClip()->setPlaceHolder(true);
418 item->setProperty("file_hash", QString());
419 } else if (item->clipType() == IMAGE) {
420 item->referencedClip()->producer()->set("force_reload", 1);
422 //requestClipInfo(item->toXml(), item->clipId(), true);
423 // Clear the file_hash value, which will cause a complete reload of the clip
424 emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true);
429 void ProjectList::slotModifiedClip(const QString &id)
431 ProjectItem *item = getItemById(id);
433 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
434 if (!pixmap.isNull()) {
436 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
437 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
440 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
442 item->setData(0, Qt::DecorationRole, pixmap);
446 void ProjectList::slotMissingClip(const QString &id)
448 ProjectItem *item = getItemById(id);
450 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
451 if (item->referencedClip()) {
452 item->referencedClip()->setPlaceHolder(true);
453 if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR";
454 item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
455 item->slotSetToolTip();
456 emit clipNeedsReload(id, true);
460 emit displayMessage(i18n("Check missing clips"), -2);
461 emit updateRenderStatus();
464 void ProjectList::slotAvailableClip(const QString &id)
466 ProjectItem *item = getItemById(id);
469 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
470 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
471 item->setProperty("file_hash", QString());
475 item->referencedClip()->setValid();
476 item->slotSetToolTip();
479 emit updateRenderStatus();
482 bool ProjectList::hasMissingClips()
484 bool missing = false;
485 QTreeWidgetItemIterator it(m_listView);
487 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
496 void ProjectList::setRenderer(Render *projectRender)
498 m_render = projectRender;
499 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
502 void ProjectList::slotClipSelected()
504 if (!m_listView->isEnabled()) return;
505 if (m_listView->currentItem()) {
506 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
507 emit clipSelected(NULL);
508 m_editButton->defaultAction()->setEnabled(false);
509 m_deleteButton->defaultAction()->setEnabled(true);
510 m_openAction->setEnabled(false);
511 m_reloadAction->setEnabled(false);
512 m_transcodeAction->setEnabled(false);
515 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
516 // this is a sub item, use base clip
517 m_deleteButton->defaultAction()->setEnabled(true);
518 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
519 if (clip == NULL) kDebug() << "-----------ERROR";
520 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
521 emit clipSelected(clip->referencedClip(), sub->zone());
522 m_transcodeAction->setEnabled(false);
525 clip = static_cast <ProjectItem*>(m_listView->currentItem());
527 emit clipSelected(clip->referencedClip());
528 m_editButton->defaultAction()->setEnabled(true);
529 m_deleteButton->defaultAction()->setEnabled(true);
530 m_reloadAction->setEnabled(true);
531 m_transcodeAction->setEnabled(true);
532 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
533 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
534 m_openAction->setEnabled(true);
535 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
536 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
537 m_openAction->setEnabled(true);
539 m_openAction->setEnabled(false);
541 // Display relevant transcoding actions only
542 adjustTranscodeActions(clip);
543 // Display uses in timeline
544 emit findInTimeline(clip->clipId());
547 emit clipSelected(NULL);
548 m_editButton->defaultAction()->setEnabled(false);
549 m_deleteButton->defaultAction()->setEnabled(false);
550 m_openAction->setEnabled(false);
551 m_reloadAction->setEnabled(false);
552 m_transcodeAction->setEnabled(false);
556 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
558 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
559 m_transcodeAction->setEnabled(false);
562 m_transcodeAction->setEnabled(true);
563 QList<QAction *> transcodeActions = m_transcodeAction->actions();
566 for (int i = 0; i < transcodeActions.count(); i++) {
567 data = transcodeActions.at(i)->data().toStringList();
568 if (data.count() > 2) {
569 condition = data.at(2);
570 if (condition.startsWith("vcodec"))
571 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
572 else if (condition.startsWith("acodec"))
573 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
579 void ProjectList::slotPauseMonitor()
585 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
587 ProjectItem *item = getItemById(id);
589 slotUpdateClipProperties(item, properties);
590 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
592 } else if (properties.contains("colour") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
593 slotRefreshClipThumbnail(item);
599 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
603 clip->setProperties(properties);
604 if (properties.contains("name")) {
605 m_listView->blockSignals(true);
606 clip->setText(0, properties.value("name"));
607 m_listView->blockSignals(false);
608 emit clipNameChanged(clip->clipId(), properties.value("name"));
610 if (properties.contains("description")) {
611 CLIPTYPE type = clip->clipType();
612 m_listView->blockSignals(true);
613 clip->setText(1, properties.value("description"));
614 m_listView->blockSignals(false);
616 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
617 // Use Nepomuk system to store clip description
618 Nepomuk::Resource f(clip->clipUrl().path());
619 f.setDescription(properties.value("description"));
622 emit projectModified();
626 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
628 if (item->type() == PROJECTSUBCLIPTYPE) {
629 // this is a sub-item
631 // user edited description
632 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
633 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
634 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
635 m_commandStack->push(command);
636 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
640 if (item->type() == PROJECTFOLDERTYPE) {
642 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
643 editFolder(item->text(0), folder->groupName(), folder->clipId());
644 folder->setGroupName(item->text(0));
645 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
646 const int children = item->childCount();
647 for (int i = 0; i < children; i++) {
648 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
649 child->setProperty("groupname", item->text(0));
655 ProjectItem *clip = static_cast <ProjectItem*>(item);
657 if (clip->referencedClip()) {
658 QMap <QString, QString> oldprops;
659 QMap <QString, QString> newprops;
660 oldprops["description"] = clip->referencedClip()->getProperty("description");
661 newprops["description"] = item->text(1);
663 if (clip->clipType() == TEXT) {
664 // This is a text template clip, update the image
665 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
666 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
667 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
668 newprops.insert("templatetext", item->text(1));
670 slotUpdateClipProperties(clip->clipId(), newprops);
671 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
672 m_commandStack->push(command);
674 } else if (column == 0) {
675 if (clip->referencedClip()) {
676 QMap <QString, QString> oldprops;
677 QMap <QString, QString> newprops;
678 oldprops["name"] = clip->referencedClip()->getProperty("name");
679 newprops["name"] = item->text(0);
680 slotUpdateClipProperties(clip, newprops);
681 emit projectModified();
682 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
683 m_commandStack->push(command);
688 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
690 bool enable = item ? true : false;
691 m_editButton->defaultAction()->setEnabled(enable);
692 m_deleteButton->defaultAction()->setEnabled(enable);
693 m_reloadAction->setEnabled(enable);
694 m_transcodeAction->setEnabled(enable);
696 ProjectItem *clip = NULL;
697 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
698 clip = static_cast <ProjectItem*>(item->parent());
699 m_transcodeAction->setEnabled(false);
700 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
701 clip = static_cast <ProjectItem*>(item);
702 // Display relevant transcoding actions only
703 adjustTranscodeActions(clip);
704 // Display uses in timeline
705 emit findInTimeline(clip->clipId());
707 m_transcodeAction->setEnabled(false);
709 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
710 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
711 m_openAction->setEnabled(true);
712 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
713 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
714 m_openAction->setEnabled(true);
716 m_openAction->setEnabled(false);
720 m_openAction->setEnabled(false);
725 void ProjectList::slotRemoveClip()
727 if (!m_listView->currentItem())
730 QMap <QString, QString> folderids;
731 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
733 QUndoCommand *delCommand = new QUndoCommand();
734 delCommand->setText(i18n("Delete Clip Zone"));
736 for (int i = 0; i < selected.count(); i++) {
737 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
739 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
740 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
741 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
742 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
744 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
745 folderids[folder->groupName()] = folder->clipId();
746 int children = folder->childCount();
748 if (children > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), 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)
750 for (int i = 0; i < children; ++i) {
751 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
752 ids << child->clipId();
755 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
756 ids << item->clipId();
757 if (item->numReferences() > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), 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)
762 if (delCommand->childCount() == 0)
765 m_commandStack->push(delCommand);
766 emit deleteProjectClips(ids, folderids);
769 void ProjectList::updateButtons() const
771 if (m_listView->topLevelItemCount() == 0) {
772 m_deleteButton->defaultAction()->setEnabled(false);
774 m_deleteButton->defaultAction()->setEnabled(true);
775 if (!m_listView->currentItem())
776 m_listView->setCurrentItem(m_listView->topLevelItem(0));
777 QTreeWidgetItem *item = m_listView->currentItem();
778 if (item && item->type() == PROJECTCLIPTYPE) {
779 m_editButton->defaultAction()->setEnabled(true);
780 m_openAction->setEnabled(true);
781 m_reloadAction->setEnabled(true);
782 m_transcodeAction->setEnabled(true);
787 m_editButton->defaultAction()->setEnabled(false);
788 m_openAction->setEnabled(false);
789 m_reloadAction->setEnabled(false);
790 m_transcodeAction->setEnabled(false);
793 void ProjectList::selectItemById(const QString &clipId)
795 ProjectItem *item = getItemById(clipId);
797 m_listView->setCurrentItem(item);
801 void ProjectList::slotDeleteClip(const QString &clipId)
803 ProjectItem *item = getItemById(clipId);
805 kDebug() << "/// Cannot find clip to delete";
808 m_listView->blockSignals(true);
809 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
810 if (!newSelectedItem)
811 newSelectedItem = m_listView->itemBelow(item);
813 m_doc->clipManager()->deleteClip(clipId);
814 m_listView->blockSignals(false);
815 if (newSelectedItem) {
816 m_listView->setCurrentItem(newSelectedItem);
819 emit clipSelected(NULL);
824 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
826 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
827 m_commandStack->push(command);
828 m_doc->setModified(true);
831 void ProjectList::slotAddFolder()
833 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
834 m_commandStack->push(command);
837 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
840 FolderProjectItem *item = getFolderItemById(clipId);
842 m_doc->clipManager()->deleteFolder(clipId);
843 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
844 if (!newSelectedItem)
845 newSelectedItem = m_listView->itemBelow(item);
848 m_listView->setCurrentItem(newSelectedItem);
854 FolderProjectItem *item = getFolderItemById(clipId);
856 m_listView->blockSignals(true);
857 item->setGroupName(foldername);
858 m_listView->blockSignals(false);
859 m_doc->clipManager()->addFolder(clipId, foldername);
860 const int children = item->childCount();
861 for (int i = 0; i < children; i++) {
862 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
863 child->setProperty("groupname", foldername);
867 m_listView->blockSignals(true);
868 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
869 m_doc->clipManager()->addFolder(clipId, foldername);
870 m_listView->blockSignals(false);
871 m_listView->editItem(m_listView->currentItem(), 0);
875 m_doc->setModified(true);
880 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
882 QMapIterator<QString, QString> i(map);
883 QUndoCommand *delCommand = new QUndoCommand();
884 delCommand->setText(i18n("Delete Folder"));
885 while (i.hasNext()) {
887 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
889 m_commandStack->push(delCommand);
892 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
894 m_listView->setEnabled(false);
896 m_listView->blockSignals(true);
898 // remove file_hash so that we load all properties for the clip
899 QDomElement e = clip->toXML().cloneNode().toElement();
900 e.removeAttribute("file_hash");
901 m_infoQueue.insert(clip->getId(), e);
902 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
904 clip->askForAudioThumbs();
905 const QString parent = clip->getProperty("groupid");
906 ProjectItem *item = NULL;
907 if (!parent.isEmpty()) {
908 FolderProjectItem *parentitem = getFolderItemById(parent);
911 QString groupName = clip->getProperty("groupname");
912 //kDebug() << "Adding clip to new group: " << groupName;
913 if (groupName.isEmpty()) groupName = i18n("Folder");
915 parentitem = new FolderProjectItem(m_listView, text, parent);
919 item = new ProjectItem(parentitem, clip);
922 item = new ProjectItem(m_listView, clip);
923 KUrl url = clip->fileURL();
925 if (getProperties == false && !clip->getClipHash().isEmpty()) {
926 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
927 if (QFile::exists(cachedPixmap)) {
928 QPixmap pix(cachedPixmap);
930 KIO::NetAccess::del(KUrl(cachedPixmap), this);
931 item->setData(0, Qt::DecorationRole, pix);
935 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
936 // if file has Nepomuk comment, use it
937 Nepomuk::Resource f(url.path());
938 QString annotation = f.description();
939 if (!annotation.isEmpty()) item->setText(1, annotation);
940 item->setText(2, QString::number(f.rating()));
944 QList <CutZoneInfo> cuts = clip->cutZones();
945 if (!cuts.isEmpty()) {
946 for (int i = 0; i < cuts.count(); i++) {
947 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
948 if (!clip->getClipHash().isEmpty()) {
949 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
950 if (QFile::exists(cachedPixmap)) {
951 QPixmap pix(cachedPixmap);
953 KIO::NetAccess::del(KUrl(cachedPixmap), this);
954 sub->setData(0, Qt::DecorationRole, pix);
959 if (m_listView->isEnabled()) {
962 m_listView->blockSignals(false);
964 if (getProperties && !m_queueTimer.isActive())
965 slotProcessNextClipInQueue();
968 void ProjectList::slotResetProjectList()
971 emit clipSelected(NULL);
972 m_thumbnailQueue.clear();
977 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
980 m_infoQueue.insert(id, xml);
981 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
984 void ProjectList::slotProcessNextClipInQueue()
986 if (m_infoQueue.isEmpty()) {
987 slotProcessNextThumbnail();
991 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
992 if (j != m_infoQueue.constEnd()) {
993 const QDomElement dom = j.value();
994 const QString id = j.key();
995 m_infoQueue.remove(j.key());
996 emit getFileProperties(dom, id, m_listView->iconSize().height(), false);
998 if (!m_infoQueue.isEmpty()) m_queueTimer.start();
1001 void ProjectList::slotUpdateClip(const QString &id)
1003 ProjectItem *item = getItemById(id);
1004 m_listView->blockSignals(true);
1005 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1006 m_listView->blockSignals(false);
1009 void ProjectList::updateAllClips()
1011 m_listView->setSortingEnabled(false);
1012 kDebug() << "// UPDATE ALL CLPY";
1014 QTreeWidgetItemIterator it(m_listView);
1017 m_listView->blockSignals(true);
1019 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1021 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1022 if (sub->data(0, Qt::DecorationRole).isNull()) {
1023 item = static_cast <ProjectItem *>((*it)->parent());
1024 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1028 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1033 item = static_cast <ProjectItem *>(*it);
1034 clip = item->referencedClip();
1035 if (item->referencedClip()->producer() == NULL) {
1036 if (clip->isPlaceHolder() == false)
1037 requestClipInfo(clip->toXML(), clip->getId());
1038 else if (!clip->isPlaceHolder())
1039 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1041 if (item->data(0, Qt::DecorationRole).isNull())
1042 requestClipThumbnail(clip->getId());
1043 if (item->data(0, DurationRole).toString().isEmpty())
1044 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1046 item->setData(0, UsageRole, QString::number(item->numReferences()));
1048 //qApp->processEvents();
1051 if (!m_queueTimer.isActive())
1052 m_queueTimer.start();
1053 if (m_listView->isEnabled())
1054 m_listView->blockSignals(false);
1055 m_listView->setSortingEnabled(true);
1056 if (m_infoQueue.isEmpty())
1057 slotProcessNextThumbnail();
1061 QString ProjectList::getExtensions()
1063 // Build list of mime types
1064 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1065 << "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"
1066 << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "application/mxf"
1067 << "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";
1069 QString allExtensions;
1070 foreach(const QString & mimeType, mimeTypes) {
1071 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1073 allExtensions.append(mime->patterns().join(" "));
1074 allExtensions.append(' ');
1077 return allExtensions.simplified();
1080 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1082 if (!m_commandStack)
1083 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1086 if (givenList.isEmpty()) {
1087 QString allExtensions = getExtensions();
1088 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1089 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1090 b->setChecked(KdenliveSettings::autoimagesequence());
1091 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), b);
1092 d->setOperationMode(KFileDialog::Opening);
1093 d->setMode(KFile::Files);
1095 list = d->selectedUrls();
1096 if (b->isChecked() && list.count() == 1) {
1097 // Check for image sequence
1098 KUrl url = list.at(0);
1099 QString fileName = url.fileName().section('.', 0, -2);
1100 if (fileName.at(fileName.size() - 1).isDigit()) {
1101 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1102 if (item.mimetype().startsWith("image")) {
1104 // import as sequence if we found more than one image in the sequence
1105 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &count);
1108 QStringList groupInfo = getGroup();
1110 // get image sequence base name
1111 while (fileName.at(fileName.size() - 1).isDigit()) {
1115 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1116 false, false, false,
1117 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1118 QString(), groupInfo.at(0), groupInfo.at(1));
1126 for (int i = 0; i < givenList.count(); i++)
1127 list << givenList.at(i);
1130 foreach(const KUrl & file, list) {
1131 // Check there is no folder here
1132 KMimeType::Ptr type = KMimeType::findByUrl(file);
1133 if (type->is("inode/directory")) {
1134 // user dropped a folder
1135 list.removeAll(file);
1142 if (givenList.isEmpty()) {
1143 QStringList groupInfo = getGroup();
1144 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1146 m_doc->slotAddClipList(list, groupName, groupId);
1150 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1152 ProjectItem *item = getItemById(id);
1153 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1155 const QString path = item->referencedClip()->fileURL().path();
1156 if (item->referencedClip()->isPlaceHolder()) replace = false;
1157 if (!path.isEmpty()) {
1159 KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1160 else if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes)
1164 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1168 void ProjectList::slotAddColorClip()
1170 if (!m_commandStack)
1171 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1173 QDialog *dia = new QDialog(this);
1174 Ui::ColorClip_UI dia_ui;
1175 dia_ui.setupUi(dia);
1176 dia->setWindowTitle(i18n("Color Clip"));
1177 dia_ui.clip_name->setText(i18n("Color Clip"));
1179 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1180 t->setValue(KdenliveSettings::color_duration());
1181 t->setTimeCodeFormat(false);
1182 dia_ui.clip_durationBox->addWidget(t);
1183 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1185 if (dia->exec() == QDialog::Accepted) {
1186 QString color = dia_ui.clip_color->color().name();
1187 KdenliveSettings::setColorclipcolor(color);
1188 color = color.replace(0, 1, "0x") + "ff";
1189 QStringList groupInfo = getGroup();
1190 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1197 void ProjectList::slotAddSlideshowClip()
1199 if (!m_commandStack)
1200 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1202 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1204 if (dia->exec() == QDialog::Accepted) {
1205 QStringList groupInfo = getGroup();
1206 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1207 dia->loop(), dia->crop(), dia->fade(),
1208 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1209 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1214 void ProjectList::slotAddTitleClip()
1216 QStringList groupInfo = getGroup();
1217 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1220 void ProjectList::slotAddTitleTemplateClip()
1222 if (!m_commandStack)
1223 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1225 QStringList groupInfo = getGroup();
1227 // Get the list of existing templates
1229 filter << "*.kdenlivetitle";
1230 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1231 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1233 QDialog *dia = new QDialog(this);
1234 Ui::TemplateClip_UI dia_ui;
1235 dia_ui.setupUi(dia);
1236 for (int i = 0; i < templateFiles.size(); ++i)
1237 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1239 if (!templateFiles.isEmpty())
1240 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1241 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1242 //warning: setting base directory doesn't work??
1243 KUrl startDir(path);
1244 dia_ui.template_list->fileDialog()->setUrl(startDir);
1245 dia_ui.text_box->setHidden(true);
1246 if (dia->exec() == QDialog::Accepted) {
1247 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1248 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1249 // Create a cloned template clip
1250 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1255 QStringList ProjectList::getGroup() const
1258 QTreeWidgetItem *item = m_listView->currentItem();
1259 while (item && item->type() != PROJECTFOLDERTYPE)
1260 item = item->parent();
1263 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1264 result << folder->groupName() << folder->clipId();
1266 result << QString() << QString();
1271 void ProjectList::setDocument(KdenliveDoc *doc)
1273 m_listView->blockSignals(true);
1274 m_listView->clear();
1275 m_listView->setSortingEnabled(false);
1276 emit clipSelected(NULL);
1277 m_thumbnailQueue.clear();
1278 m_infoQueue.clear();
1279 m_refreshed = false;
1281 m_timecode = doc->timecode();
1282 m_commandStack = doc->commandStack();
1285 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1286 QMapIterator<QString, QString> f(flist);
1287 while (f.hasNext()) {
1289 (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1292 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1293 for (int i = 0; i < list.count(); i++)
1294 slotAddClip(list.at(i), false);
1296 m_listView->blockSignals(false);
1297 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1298 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1299 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1300 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1301 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1304 QList <DocClipBase*> ProjectList::documentClipList() const
1307 return QList <DocClipBase*> ();
1309 return m_doc->clipManager()->documentClipList();
1312 QDomElement ProjectList::producersList()
1315 QDomElement prods = doc.createElement("producerlist");
1316 doc.appendChild(prods);
1317 kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
1318 QTreeWidgetItemIterator it(m_listView);
1320 if ((*it)->type() != PROJECTCLIPTYPE) {
1325 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1331 void ProjectList::slotCheckForEmptyQueue()
1333 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1335 emit loadingIsOver();
1336 emit displayMessage(QString(), -1);
1337 m_listView->blockSignals(false);
1338 m_listView->setEnabled(true);
1340 } else if (!m_refreshed) {
1341 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1345 void ProjectList::reloadClipThumbnails()
1347 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
1348 m_thumbnailQueue.clear();
1349 QTreeWidgetItemIterator it(m_listView);
1351 if ((*it)->type() != PROJECTCLIPTYPE) {
1356 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1359 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1362 void ProjectList::requestClipThumbnail(const QString id)
1364 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1367 void ProjectList::slotProcessNextThumbnail()
1369 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1370 slotCheckForEmptyQueue();
1373 if (!m_infoQueue.isEmpty()) {
1374 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1377 if (m_thumbnailQueue.count() > 1) {
1378 int max = m_doc->clipManager()->clipsCount();
1379 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1381 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1384 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1386 QTreeWidgetItem *item = getAnyItemById(clipId);
1388 slotRefreshClipThumbnail(item, update);
1390 slotProcessNextThumbnail();
1393 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1395 if (it == NULL) return;
1396 ProjectItem *item = NULL;
1397 bool isSubItem = false;
1399 if (it->type() == PROJECTFOLDERTYPE) return;
1400 if (it->type() == PROJECTSUBCLIPTYPE) {
1401 item = static_cast <ProjectItem *>(it->parent());
1402 frame = static_cast <SubProjectItem *>(it)->zone().x();
1405 item = static_cast <ProjectItem *>(it);
1406 frame = item->referencedClip()->getClipThumbFrame();
1410 DocClipBase *clip = item->referencedClip();
1412 slotProcessNextThumbnail();
1416 int height = m_listView->iconSize().height();
1417 int width = (int)(height * m_render->dar());
1418 if (clip->clipType() == AUDIO)
1419 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1420 else if (clip->clipType() == IMAGE)
1421 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1423 pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1425 if (!pix.isNull()) {
1426 m_listView->blockSignals(true);
1427 it->setData(0, Qt::DecorationRole, pix);
1428 if (m_listView->isEnabled())
1429 m_listView->blockSignals(false);
1431 m_doc->cachePixmap(item->getClipHash(), pix);
1433 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1436 emit projectModified();
1437 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
1441 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
1444 ProjectItem *item = getItemById(clipId);
1445 if (item && producer) {
1446 m_listView->blockSignals(true);
1447 item->setProperties(properties, metadata);
1448 if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1449 item->referencedClip()->setValid();
1450 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1453 //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
1454 item->referencedClip()->setProducer(producer, replace);
1455 item->referencedClip()->askForAudioThumbs();
1456 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1457 requestClipThumbnail(clipId);
1458 if (!toReload.isEmpty())
1459 item->slotSetToolTip();
1461 //emit receivedClipDuration(clipId);
1462 if (m_listView->isEnabled() && replace) {
1463 // update clip in clip monitor
1464 emit clipSelected(NULL);
1465 emit clipSelected(item->referencedClip());
1466 //TODO: Make sure the line below has no side effect
1470 // Check if duration changed.
1471 emit receivedClipDuration(clipId);
1474 if (m_listView->isEnabled())
1475 m_listView->blockSignals(false);
1476 /*if (item->icon(0).isNull()) {
1477 requestClipThumbnail(clipId);
1479 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1480 int max = m_doc->clipManager()->clipsCount();
1481 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1482 m_listView->setCurrentItem(item);
1483 bool updatedProfile = false;
1484 if (item->parent()) {
1485 if (item->parent()->type() == PROJECTFOLDERTYPE)
1486 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1487 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) {
1488 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1489 updatedProfile = adjustProjectProfileToItem(item);
1491 if (updatedProfile == false) emit clipSelected(item->referencedClip());
1493 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1495 if (!toReload.isEmpty())
1496 emit clipNeedsReload(toReload, true);
1497 // small delay so that the app can display the progress info
1498 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
1501 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1504 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1505 item = static_cast <ProjectItem*>(m_listView->currentItem());
1507 if (item == NULL || item->referencedClip() == NULL) {
1508 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1511 bool profileUpdated = false;
1512 QString size = item->referencedClip()->getProperty("frame_size");
1513 int width = size.section('x', 0, 0).toInt();
1514 int height = size.section('x', -1).toInt();
1515 double fps = item->referencedClip()->getProperty("fps").toDouble();
1516 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1517 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1518 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1519 // get a list of compatible profiles
1520 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1521 if (!suggestedProfiles.isEmpty()) {
1522 KDialog *dialog = new KDialog(this);
1523 dialog->setCaption(i18n("Change project profile"));
1524 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1527 QVBoxLayout *l = new QVBoxLayout;
1528 QLabel *label = new QLabel(i18n("Your clip does not match current project's profile.\nDo you want to change the project profile?\n\nThe following profiles match the clip (size: %1, fps: %2)", size, fps));
1529 l->addWidget(label);
1530 QListWidget *list = new QListWidget;
1531 list->setAlternatingRowColors(true);
1532 QMapIterator<QString, QString> i(suggestedProfiles);
1533 while (i.hasNext()) {
1535 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1536 item->setData(Qt::UserRole, i.key());
1537 item->setToolTip(i.key());
1539 list->setCurrentRow(0);
1541 container.setLayout(l);
1542 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1543 dialog->setMainWidget(&container);
1544 if (dialog->exec() == QDialog::Accepted) {
1545 //Change project profile
1546 profileUpdated = true;
1547 if (list->currentItem())
1548 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1552 } else KMessageBox::information(kapp->activeWindow(), i18n("Your clip does not match current project's profile.\nNo existing profile found to match the clip's properties.\nClip size: %1\nFps: %2\n", size, fps));
1555 return profileUpdated;
1558 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1560 ProjectItem *item = getItemById(clipId);
1561 if (item && !pix.isNull()) {
1562 m_listView->blockSignals(true);
1563 item->setData(0, Qt::DecorationRole, pix);
1564 m_doc->cachePixmap(item->getClipHash(), pix);
1565 if (m_listView->isEnabled())
1566 m_listView->blockSignals(false);
1570 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1572 QTreeWidgetItemIterator it(m_listView);
1573 QString lookId = id;
1574 if (id.contains('#'))
1575 lookId = id.section('#', 0, 0);
1577 ProjectItem *result = NULL;
1579 if ((*it)->type() != PROJECTCLIPTYPE) {
1584 ProjectItem *item = static_cast<ProjectItem *>(*it);
1585 if (item->clipId() == lookId) {
1591 if (result == NULL || !id.contains('#')) {
1594 for (int i = 0; i < result->childCount(); i++) {
1595 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1596 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1605 ProjectItem *ProjectList::getItemById(const QString &id)
1608 QTreeWidgetItemIterator it(m_listView);
1610 if ((*it)->type() != PROJECTCLIPTYPE) {
1615 item = static_cast<ProjectItem *>(*it);
1616 if (item->clipId() == id)
1623 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1625 FolderProjectItem *item;
1626 QTreeWidgetItemIterator it(m_listView);
1628 if ((*it)->type() == PROJECTFOLDERTYPE) {
1629 item = static_cast<FolderProjectItem *>(*it);
1630 if (item->clipId() == id)
1638 void ProjectList::slotSelectClip(const QString &ix)
1640 ProjectItem *clip = getItemById(ix);
1642 m_listView->setCurrentItem(clip);
1643 m_listView->scrollToItem(clip);
1644 m_editButton->defaultAction()->setEnabled(true);
1645 m_deleteButton->defaultAction()->setEnabled(true);
1646 m_reloadAction->setEnabled(true);
1647 m_transcodeAction->setEnabled(true);
1648 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1649 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1650 m_openAction->setEnabled(true);
1651 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1652 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1653 m_openAction->setEnabled(true);
1655 m_openAction->setEnabled(false);
1660 QString ProjectList::currentClipUrl() const
1663 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1664 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1666 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1668 item = static_cast <ProjectItem*>(m_listView->currentItem());
1672 return item->clipUrl().path();
1675 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1679 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1680 for (int i = 0; i < list.count(); i++) {
1681 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1683 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1685 item = static_cast <ProjectItem*>(list.at(i)->parent());
1687 item = static_cast <ProjectItem*>(list.at(i));
1689 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1691 DocClipBase *clip = item->referencedClip();
1692 if (!condition.isEmpty()) {
1693 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1695 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1698 result.append(item->clipUrl());
1703 void ProjectList::regenerateTemplate(const QString &id)
1705 ProjectItem *clip = getItemById(id);
1707 regenerateTemplate(clip);
1710 void ProjectList::regenerateTemplate(ProjectItem *clip)
1712 //TODO: remove this unused method, only force_reload is necessary
1713 clip->referencedClip()->producer()->set("force_reload", 1);
1716 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1720 if (!file.open(QIODevice::ReadOnly)) {
1721 kWarning() << "ERROR, CANNOT READ: " << path;
1724 if (!doc.setContent(&file)) {
1725 kWarning() << "ERROR, CANNOT READ: " << path;
1730 QDomNodeList texts = doc.elementsByTagName("content");
1731 for (int i = 0; i < texts.count(); i++) {
1732 QString data = texts.item(i).firstChild().nodeValue();
1733 data.replace("%s", replaceString);
1734 texts.item(i).firstChild().setNodeValue(data);
1740 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1742 ProjectItem *clip = getItemById(id);
1743 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1745 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1746 m_commandStack->push(command);
1749 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1751 ProjectItem *clip = getItemById(id);
1753 DocClipBase *base = clip->referencedClip();
1754 base->addCutZone(in, out);
1755 m_listView->blockSignals(true);
1756 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1757 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1758 if (!clip->isExpanded())
1759 clip->setExpanded(true);
1760 m_listView->scrollToItem(sub);
1761 m_listView->editItem(sub, 1);
1763 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1764 sub->setData(0, Qt::DecorationRole, p);
1765 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1766 m_listView->blockSignals(false);
1768 emit projectModified();
1771 void ProjectList::removeClipCut(const QString &id, int in, int out)
1773 ProjectItem *clip = getItemById(id);
1775 DocClipBase *base = clip->referencedClip();
1776 base->removeCutZone(in, out);
1777 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1779 m_listView->blockSignals(true);
1781 m_listView->blockSignals(false);
1784 emit projectModified();
1787 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1789 SubProjectItem *sub = NULL;
1791 for (int i = 0; i < clip->childCount(); i++) {
1792 QTreeWidgetItem *it = clip->child(i);
1793 if (it->type() == PROJECTSUBCLIPTYPE) {
1794 sub = static_cast <SubProjectItem*>(it);
1795 if (sub->zone() == zone)
1805 void ProjectList::slotUpdateClipCut(QPoint p)
1807 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
1809 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
1810 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1811 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
1812 m_commandStack->push(command);
1815 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
1817 ProjectItem *clip = getItemById(id);
1818 SubProjectItem *sub = getSubItem(clip, oldzone);
1819 if (sub == NULL || clip == NULL)
1821 DocClipBase *base = clip->referencedClip();
1822 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
1823 m_listView->blockSignals(true);
1825 sub->setDescription(comment);
1826 m_listView->blockSignals(false);
1827 emit projectModified();
1830 void ProjectList::slotForceProcessing(const QString &id)
1832 while (m_infoQueue.contains(id)) {
1833 slotProcessNextClipInQueue();
1837 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
1839 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
1841 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &count);
1843 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
1844 if (!existing.isEmpty()) {
1845 // Sequence already exists, update
1846 QString id = existing.at(0)->getId();
1847 //ProjectItem *item = getItemById(id);
1848 QMap <QString, QString> oldprops;
1849 QMap <QString, QString> newprops;
1850 int ttl = existing.at(0)->getProperty("ttl").toInt();
1851 oldprops["out"] = existing.at(0)->getProperty("out");
1852 newprops["out"] = QString::number(ttl * count - 1);
1853 slotUpdateClipProperties(id, newprops);
1854 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
1855 m_commandStack->push(command);
1859 QStringList groupInfo = getGroup();
1860 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1861 false, false, false,
1862 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1863 QString(), groupInfo.at(0), groupInfo.at(1));
1866 else emit displayMessage(i18n("Sequence not found"), -2);
1869 #include "projectlist.moc"