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>
52 #include <KStandardDirs>
55 #include <nepomuk/global.h>
56 #include <nepomuk/resourcemanager.h>
57 //#include <nepomuk/tag.h>
60 #include <QMouseEvent>
61 #include <QStylePainter>
66 #include <QHeaderView>
67 #include <QInputDialog>
68 #include <QtConcurrentRun>
70 ProjectList::ProjectList(QWidget *parent) :
77 m_transcodeAction(NULL),
83 QVBoxLayout *layout = new QVBoxLayout;
84 layout->setContentsMargins(0, 0, 0, 0);
85 layout->setSpacing(0);
86 qRegisterMetaType<QDomElement>("QDomElement");
88 QFrame *frame = new QFrame;
89 frame->setFrameStyle(QFrame::NoFrame);
90 QHBoxLayout *box = new QHBoxLayout;
91 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
93 box->addWidget(searchView);
94 //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
95 //m_toolbar->setIconSize(QSize(s, s));
97 m_addButton = new QToolButton;
98 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
99 m_addButton->setAutoRaise(true);
100 box->addWidget(m_addButton);
102 m_editButton = new QToolButton;
103 m_editButton->setAutoRaise(true);
104 box->addWidget(m_editButton);
106 m_deleteButton = new QToolButton;
107 m_deleteButton->setAutoRaise(true);
108 box->addWidget(m_deleteButton);
109 frame->setLayout(box);
110 layout->addWidget(frame);
112 m_listView = new ProjectListView;
113 layout->addWidget(m_listView);
115 searchView->setTreeWidget(m_listView);
117 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
118 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
119 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
120 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
121 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
122 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
123 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
124 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
125 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
126 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
127 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
129 m_listViewDelegate = new ItemDelegate(m_listView);
130 m_listView->setItemDelegate(m_listViewDelegate);
132 if (KdenliveSettings::activate_nepomuk()) {
133 Nepomuk::ResourceManager::instance()->init();
134 if (!Nepomuk::ResourceManager::instance()->initialized()) {
135 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
136 KdenliveSettings::setActivate_nepomuk(false);
142 ProjectList::~ProjectList()
145 m_listView->blockSignals(true);
147 delete m_listViewDelegate;
150 void ProjectList::focusTree() const
152 m_listView->setFocus();
155 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
157 QList <QAction *> actions = addMenu->actions();
158 for (int i = 0; i < actions.count(); i++) {
159 if (actions.at(i)->data().toString() == "clip_properties") {
160 m_editButton->setDefaultAction(actions.at(i));
163 } else if (actions.at(i)->data().toString() == "delete_clip") {
164 m_deleteButton->setDefaultAction(actions.at(i));
167 } else if (actions.at(i)->data().toString() == "edit_clip") {
168 m_openAction = actions.at(i);
171 } else if (actions.at(i)->data().toString() == "reload_clip") {
172 m_reloadAction = actions.at(i);
175 } else if (actions.at(i)->data().toString() == "proxy_clip") {
176 m_proxyAction = actions.at(i);
182 QMenu *m = new QMenu();
183 m->addActions(actions);
184 m_addButton->setMenu(m);
185 m_addButton->setDefaultAction(defaultAction);
186 m_menu = new QMenu();
187 m_menu->addActions(addMenu->actions());
190 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
194 QMenu *menu = m_addButton->menu();
195 menu->addMenu(addMenu);
196 m_addButton->setMenu(menu);
198 m_menu->addMenu(addMenu);
199 if (addMenu->isEmpty())
200 addMenu->setEnabled(false);
201 m_menu->addMenu(transcodeMenu);
202 if (transcodeMenu->isEmpty())
203 transcodeMenu->setEnabled(false);
204 m_transcodeAction = transcodeMenu;
205 m_menu->addAction(m_reloadAction);
206 m_menu->addAction(m_proxyAction);
207 m_menu->addMenu(inTimelineMenu);
208 inTimelineMenu->setEnabled(false);
209 m_menu->addAction(m_editButton->defaultAction());
210 m_menu->addAction(m_openAction);
211 m_menu->addAction(m_deleteButton->defaultAction());
212 m_menu->insertSeparator(m_deleteButton->defaultAction());
216 QByteArray ProjectList::headerInfo() const
218 return m_listView->header()->saveState();
221 void ProjectList::setHeaderInfo(const QByteArray &state)
223 m_listView->header()->restoreState(state);
226 void ProjectList::updateProjectFormat(Timecode t)
231 void ProjectList::slotEditClip()
233 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
234 if (list.isEmpty()) return;
235 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
236 editClipSelection(list);
240 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
242 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
243 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
245 item = static_cast <ProjectItem*>(m_listView->currentItem());
246 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
247 emit clipSelected(item->referencedClip());
248 emit showClipProperties(item->referencedClip());
252 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
254 // Gather all common properties
255 QMap <QString, QString> commonproperties;
256 QList <DocClipBase *> clipList;
257 commonproperties.insert("force_aspect_num", "-");
258 commonproperties.insert("force_aspect_den", "-");
259 commonproperties.insert("force_fps", "-");
260 commonproperties.insert("force_progressive", "-");
261 commonproperties.insert("force_tff", "-");
262 commonproperties.insert("threads", "-");
263 commonproperties.insert("video_index", "-");
264 commonproperties.insert("audio_index", "-");
265 commonproperties.insert("force_colorspace", "-");
266 commonproperties.insert("full_luma", "-");
267 QString transparency = "-";
269 bool allowDurationChange = true;
270 int commonDuration = -1;
271 bool hasImages = false;;
273 for (int i = 0; i < list.count(); i++) {
275 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
276 // Add folder items to the list
277 int ct = list.at(i)->childCount();
278 for (int j = 0; j < ct; j++) {
279 list.append(list.at(i)->child(j));
283 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
284 item = static_cast <ProjectItem*>(list.at(i)->parent());
286 item = static_cast <ProjectItem*>(list.at(i));
287 if (!(item->flags() & Qt::ItemIsDragEnabled))
291 DocClipBase *clip = item->referencedClip();
292 if (clipList.contains(clip)) continue;
293 if (clip->clipType() == IMAGE) {
295 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
296 if (transparency == "-") {
297 // first non transparent image
300 else if (transparency == "1") {
301 // we have transparent and non transparent clips
306 if (transparency == "-") {
307 // first transparent image
310 else if (transparency == "0") {
311 // we have transparent and non transparent clips
316 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
317 allowDurationChange = false;
318 if (allowDurationChange && commonDuration != 0) {
319 if (commonDuration == -1)
320 commonDuration = clip->duration().frames(m_fps);
321 else if (commonDuration != clip->duration().frames(m_fps))
324 clipList.append(clip);
325 QMap <QString, QString> clipprops = clip->properties();
326 QMapIterator<QString, QString> p(commonproperties);
327 while (p.hasNext()) {
329 if (p.value().isEmpty()) continue;
330 if (clipprops.contains(p.key())) {
331 if (p.value() == "-")
332 commonproperties.insert(p.key(), clipprops.value(p.key()));
333 else if (p.value() != clipprops.value(p.key()))
334 commonproperties.insert(p.key(), QString());
336 commonproperties.insert(p.key(), QString());
341 if (allowDurationChange)
342 commonproperties.insert("out", QString::number(commonDuration));
344 commonproperties.insert("transparency", transparency);
345 /*QMapIterator<QString, QString> p(commonproperties);
346 while (p.hasNext()) {
348 kDebug() << "Result: " << p.key() << " = " << p.value();
350 emit showClipProperties(clipList, commonproperties);
353 void ProjectList::slotOpenClip()
356 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
358 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
359 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
361 item = static_cast <ProjectItem*>(m_listView->currentItem());
363 if (item->clipType() == IMAGE) {
364 if (KdenliveSettings::defaultimageapp().isEmpty())
365 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
367 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
369 if (item->clipType() == AUDIO) {
370 if (KdenliveSettings::defaultaudioapp().isEmpty())
371 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
373 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
378 void ProjectList::cleanup()
380 m_listView->clearSelection();
381 QTreeWidgetItemIterator it(m_listView);
384 if ((*it)->type() != PROJECTCLIPTYPE) {
388 item = static_cast <ProjectItem *>(*it);
389 if (item->numReferences() == 0)
390 item->setSelected(true);
396 void ProjectList::trashUnusedClips()
398 QTreeWidgetItemIterator it(m_listView);
403 if ((*it)->type() != PROJECTCLIPTYPE) {
407 item = static_cast <ProjectItem *>(*it);
408 if (item->numReferences() == 0) {
409 ids << item->clipId();
410 KUrl url = item->clipUrl();
411 if (!url.isEmpty() && !urls.contains(url.path()))
417 // Check that we don't use the URL in another clip
418 QTreeWidgetItemIterator it2(m_listView);
420 if ((*it2)->type() != PROJECTCLIPTYPE) {
424 item = static_cast <ProjectItem *>(*it2);
425 if (item->numReferences() > 0) {
426 KUrl url = item->clipUrl();
427 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
432 emit deleteProjectClips(ids, QMap <QString, QString>());
433 for (int i = 0; i < urls.count(); i++)
434 KIO::NetAccess::del(KUrl(urls.at(i)), this);
437 void ProjectList::slotReloadClip(const QString &id)
439 QList<QTreeWidgetItem *> selected;
441 selected = m_listView->selectedItems();
443 ProjectItem *itemToReLoad = getItemById(id);
444 if (itemToReLoad) selected.append(itemToReLoad);
447 for (int i = 0; i < selected.count(); i++) {
448 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
449 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
450 for (int j = 0; j < selected.at(i)->childCount(); j++)
451 selected.append(selected.at(i)->child(j));
455 item = static_cast <ProjectItem *>(selected.at(i));
457 CLIPTYPE t = item->clipType();
459 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
460 regenerateTemplate(item);
461 } else if (t != COLOR && t != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
462 item->referencedClip()->setPlaceHolder(true);
463 item->setProperty("file_hash", QString());
464 } else if (t == IMAGE) {
465 item->referencedClip()->producer()->set("force_reload", 1);
468 QDomElement e = item->toXml();
469 // Make sure we get the correct producer length if it was adjusted in timeline
470 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
471 int length = QString(item->referencedClip()->producerProperty("length")).toInt();
472 if (length > 0 && !e.hasAttribute("length")) {
473 e.setAttribute("length", length);
476 emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true, false);
481 void ProjectList::slotModifiedClip(const QString &id)
483 ProjectItem *item = getItemById(id);
485 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
486 if (!pixmap.isNull()) {
488 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
489 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
492 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
494 item->setData(0, Qt::DecorationRole, pixmap);
498 void ProjectList::slotMissingClip(const QString &id)
500 ProjectItem *item = getItemById(id);
502 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
503 int height = m_listView->iconSize().height();
504 int width = (int)(height * m_render->dar());
505 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
506 if (pixmap.isNull()) {
507 pixmap = QPixmap(width, height);
508 pixmap.fill(Qt::transparent);
510 KIcon icon("dialog-close");
512 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
514 item->setData(0, Qt::DecorationRole, pixmap);
515 if (item->referencedClip()) {
516 item->referencedClip()->setPlaceHolder(true);
517 if (m_render == NULL) {
518 kDebug() << "********* ERROR, NULL RENDR";
521 Mlt::Producer *newProd = m_render->invalidProducer(id);
522 if (item->referencedClip()->producer()) {
523 Mlt::Properties props(newProd->get_properties());
524 Mlt::Properties src_props(item->referencedClip()->producer()->get_properties());
525 props.inherit(src_props);
527 item->referencedClip()->setProducer(newProd, true);
528 item->slotSetToolTip();
529 emit clipNeedsReload(id, true);
533 emit displayMessage(i18n("Check missing clips"), -2);
534 emit updateRenderStatus();
537 void ProjectList::slotAvailableClip(const QString &id)
539 ProjectItem *item = getItemById(id);
542 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
543 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
544 item->setProperty("file_hash", QString());
548 item->referencedClip()->setValid();
549 item->slotSetToolTip();
552 emit updateRenderStatus();
555 bool ProjectList::hasMissingClips()
557 bool missing = false;
558 QTreeWidgetItemIterator it(m_listView);
560 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
569 void ProjectList::setRenderer(Render *projectRender)
571 m_render = projectRender;
572 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
575 void ProjectList::slotClipSelected()
577 if (!m_listView->isEnabled()) return;
578 if (m_listView->currentItem()) {
579 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
580 emit clipSelected(NULL);
581 m_editButton->defaultAction()->setEnabled(m_listView->currentItem()->childCount() > 0);
582 m_deleteButton->defaultAction()->setEnabled(true);
583 m_openAction->setEnabled(false);
584 m_reloadAction->setEnabled(false);
585 m_transcodeAction->setEnabled(false);
586 m_proxyAction->setEnabled(false);
589 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
590 // this is a sub item, use base clip
591 m_deleteButton->defaultAction()->setEnabled(true);
592 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
593 if (clip == NULL) kDebug() << "-----------ERROR";
594 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
595 emit clipSelected(clip->referencedClip(), sub->zone());
596 m_transcodeAction->setEnabled(false);
599 clip = static_cast <ProjectItem*>(m_listView->currentItem());
600 if (clip && clip->referencedClip())
601 emit clipSelected(clip->referencedClip());
602 m_editButton->defaultAction()->setEnabled(true);
603 m_deleteButton->defaultAction()->setEnabled(true);
604 m_reloadAction->setEnabled(true);
605 m_transcodeAction->setEnabled(true);
606 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
607 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
608 m_openAction->setEnabled(true);
609 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
610 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
611 m_openAction->setEnabled(true);
613 m_openAction->setEnabled(false);
615 // Display relevant transcoding actions only
616 adjustTranscodeActions(clip);
617 // Display uses in timeline
618 emit findInTimeline(clip->clipId());
621 emit clipSelected(NULL);
622 m_editButton->defaultAction()->setEnabled(false);
623 m_deleteButton->defaultAction()->setEnabled(false);
624 m_openAction->setEnabled(false);
625 m_reloadAction->setEnabled(false);
626 m_transcodeAction->setEnabled(false);
630 void ProjectList::adjustProxyActions(ProjectItem *clip) const
632 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
633 m_proxyAction->setEnabled(false);
636 m_proxyAction->setEnabled(useProxy());
637 m_proxyAction->blockSignals(true);
638 m_proxyAction->setChecked(clip->hasProxy());
639 m_proxyAction->blockSignals(false);
642 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
644 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
645 m_transcodeAction->setEnabled(false);
648 m_transcodeAction->setEnabled(true);
649 QList<QAction *> transcodeActions = m_transcodeAction->actions();
652 for (int i = 0; i < transcodeActions.count(); i++) {
653 data = transcodeActions.at(i)->data().toStringList();
654 if (data.count() > 2) {
655 condition = data.at(2);
656 if (condition.startsWith("vcodec"))
657 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
658 else if (condition.startsWith("acodec"))
659 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
665 void ProjectList::slotPauseMonitor()
671 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
673 ProjectItem *item = getItemById(id);
675 slotUpdateClipProperties(item, properties);
676 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
678 } else if (properties.contains("colour") ||
679 properties.contains("xmldata") ||
680 properties.contains("force_aspect_num") ||
681 properties.contains("force_aspect_den") ||
682 properties.contains("templatetext")) {
683 slotRefreshClipThumbnail(item);
684 emit refreshClip(id, true);
685 } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
686 emit refreshClip(id, false);
691 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
695 clip->setProperties(properties);
696 if (properties.contains("name")) {
697 monitorItemEditing(false);
698 clip->setText(0, properties.value("name"));
699 monitorItemEditing(true);
700 emit clipNameChanged(clip->clipId(), properties.value("name"));
702 if (properties.contains("description")) {
703 CLIPTYPE type = clip->clipType();
704 monitorItemEditing(false);
705 clip->setText(1, properties.value("description"));
706 monitorItemEditing(true);
708 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
709 // Use Nepomuk system to store clip description
710 Nepomuk::Resource f(clip->clipUrl().path());
711 f.setDescription(properties.value("description"));
714 emit projectModified();
718 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
720 if (item->type() == PROJECTSUBCLIPTYPE) {
721 // this is a sub-item
723 // user edited description
724 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
725 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
726 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
727 m_commandStack->push(command);
728 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
732 if (item->type() == PROJECTFOLDERTYPE) {
734 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
735 editFolder(item->text(0), folder->groupName(), folder->clipId());
736 folder->setGroupName(item->text(0));
737 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
738 const int children = item->childCount();
739 for (int i = 0; i < children; i++) {
740 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
741 child->setProperty("groupname", item->text(0));
747 ProjectItem *clip = static_cast <ProjectItem*>(item);
749 if (clip->referencedClip()) {
750 QMap <QString, QString> oldprops;
751 QMap <QString, QString> newprops;
752 oldprops["description"] = clip->referencedClip()->getProperty("description");
753 newprops["description"] = item->text(1);
755 if (clip->clipType() == TEXT) {
756 // This is a text template clip, update the image
757 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
758 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
759 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
760 newprops.insert("templatetext", item->text(1));
762 slotUpdateClipProperties(clip->clipId(), newprops);
763 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
764 m_commandStack->push(command);
766 } else if (column == 0) {
767 if (clip->referencedClip()) {
768 QMap <QString, QString> oldprops;
769 QMap <QString, QString> newprops;
770 oldprops["name"] = clip->referencedClip()->getProperty("name");
771 if (oldprops.value("name") != item->text(0)) {
772 newprops["name"] = item->text(0);
773 slotUpdateClipProperties(clip, newprops);
774 emit projectModified();
775 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
776 m_commandStack->push(command);
782 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
784 bool enable = item ? true : false;
785 m_editButton->defaultAction()->setEnabled(enable);
786 m_deleteButton->defaultAction()->setEnabled(enable);
787 m_reloadAction->setEnabled(enable);
788 m_transcodeAction->setEnabled(enable);
790 ProjectItem *clip = NULL;
791 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
792 clip = static_cast <ProjectItem*>(item->parent());
793 m_transcodeAction->setEnabled(false);
794 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
795 clip = static_cast <ProjectItem*>(item);
796 // Display relevant transcoding actions only
797 adjustTranscodeActions(clip);
798 adjustProxyActions(clip);
799 // Display uses in timeline
800 emit findInTimeline(clip->clipId());
802 m_transcodeAction->setEnabled(false);
804 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
805 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
806 m_openAction->setEnabled(true);
807 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
808 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
809 m_openAction->setEnabled(true);
811 m_openAction->setEnabled(false);
815 m_openAction->setEnabled(false);
820 void ProjectList::slotRemoveClip()
822 if (!m_listView->currentItem())
825 QMap <QString, QString> folderids;
826 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
828 QUndoCommand *delCommand = new QUndoCommand();
829 delCommand->setText(i18n("Delete Clip Zone"));
830 for (int i = 0; i < selected.count(); i++) {
831 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
833 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
834 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
835 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
836 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
838 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
839 folderids[folder->groupName()] = folder->clipId();
840 int children = folder->childCount();
842 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)
844 for (int i = 0; i < children; ++i) {
845 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
846 ids << child->clipId();
849 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
850 ids << item->clipId();
851 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"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteAll") == KMessageBox::No) {
852 KMessageBox::enableMessage("DeleteAll");
857 KMessageBox::enableMessage("DeleteAll");
858 if (delCommand->childCount() == 0)
861 m_commandStack->push(delCommand);
862 emit deleteProjectClips(ids, folderids);
865 void ProjectList::updateButtons() const
867 if (m_listView->topLevelItemCount() == 0) {
868 m_deleteButton->defaultAction()->setEnabled(false);
869 m_editButton->defaultAction()->setEnabled(false);
871 m_deleteButton->defaultAction()->setEnabled(true);
872 if (!m_listView->currentItem())
873 m_listView->setCurrentItem(m_listView->topLevelItem(0));
874 QTreeWidgetItem *item = m_listView->currentItem();
875 if (item && item->type() == PROJECTCLIPTYPE) {
876 m_editButton->defaultAction()->setEnabled(true);
877 m_openAction->setEnabled(true);
878 m_reloadAction->setEnabled(true);
879 m_transcodeAction->setEnabled(true);
880 m_proxyAction->setEnabled(useProxy());
883 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
884 m_editButton->defaultAction()->setEnabled(true);
886 else m_editButton->defaultAction()->setEnabled(false);
888 m_openAction->setEnabled(false);
889 m_reloadAction->setEnabled(false);
890 m_transcodeAction->setEnabled(false);
891 m_proxyAction->setEnabled(false);
894 void ProjectList::selectItemById(const QString &clipId)
896 ProjectItem *item = getItemById(clipId);
898 m_listView->setCurrentItem(item);
902 void ProjectList::slotDeleteClip(const QString &clipId)
904 ProjectItem *item = getItemById(clipId);
906 kDebug() << "/// Cannot find clip to delete";
909 if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
910 m_listView->blockSignals(true);
911 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
912 if (!newSelectedItem)
913 newSelectedItem = m_listView->itemBelow(item);
915 // Pause playing to prevent crash while deleting clip
917 m_doc->clipManager()->deleteClip(clipId);
918 m_listView->blockSignals(false);
919 if (newSelectedItem) {
920 m_listView->setCurrentItem(newSelectedItem);
923 emit clipSelected(NULL);
928 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
930 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
931 m_commandStack->push(command);
932 m_doc->setModified(true);
935 void ProjectList::slotAddFolder()
937 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
938 m_commandStack->push(command);
941 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
944 FolderProjectItem *item = getFolderItemById(clipId);
946 m_doc->clipManager()->deleteFolder(clipId);
947 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
948 if (!newSelectedItem)
949 newSelectedItem = m_listView->itemBelow(item);
952 m_listView->setCurrentItem(newSelectedItem);
958 FolderProjectItem *item = getFolderItemById(clipId);
960 m_listView->blockSignals(true);
961 item->setGroupName(foldername);
962 m_listView->blockSignals(false);
963 m_doc->clipManager()->addFolder(clipId, foldername);
964 const int children = item->childCount();
965 for (int i = 0; i < children; i++) {
966 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
967 child->setProperty("groupname", foldername);
971 m_listView->blockSignals(true);
972 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
973 m_doc->clipManager()->addFolder(clipId, foldername);
974 m_listView->blockSignals(false);
975 m_listView->editItem(m_listView->currentItem(), 0);
979 m_doc->setModified(true);
984 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
986 QMapIterator<QString, QString> i(map);
987 QUndoCommand *delCommand = new QUndoCommand();
988 delCommand->setText(i18n("Delete Folder"));
989 while (i.hasNext()) {
991 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
993 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
994 else delete delCommand;
997 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
999 m_listView->setEnabled(false);
1000 const QString parent = clip->getProperty("groupid");
1001 ProjectItem *item = NULL;
1002 monitorItemEditing(false);
1003 if (!parent.isEmpty()) {
1004 FolderProjectItem *parentitem = getFolderItemById(parent);
1007 QString groupName = clip->getProperty("groupname");
1008 //kDebug() << "Adding clip to new group: " << groupName;
1009 if (groupName.isEmpty()) groupName = i18n("Folder");
1011 parentitem = new FolderProjectItem(m_listView, text, parent);
1015 item = new ProjectItem(parentitem, clip);
1018 item = new ProjectItem(m_listView, clip);
1020 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1021 connect(clip, SIGNAL(createProxy(const QString)), this, SLOT(slotCreateProxy(const QString)));
1022 connect(clip, SIGNAL(abortProxy(const QString, const QString)), this, SLOT(slotAbortProxy(const QString, const QString)));
1023 if (getProperties) {
1024 m_listView->processLayout();
1025 QDomElement e = clip->toXML().cloneNode().toElement();
1026 e.removeAttribute("file_hash");
1028 m_infoQueue.insert(clip->getId(), e);
1031 else if (item->hasProxy() && !item->isProxyRunning()) {
1032 slotCreateProxy(clip->getId());
1034 clip->askForAudioThumbs();
1036 KUrl url = clip->fileURL();
1037 if (getProperties == false && !clip->getClipHash().isEmpty()) {
1038 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1039 if (QFile::exists(cachedPixmap)) {
1040 QPixmap pix(cachedPixmap);
1042 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1043 item->setData(0, Qt::DecorationRole, pix);
1047 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
1048 // if file has Nepomuk comment, use it
1049 Nepomuk::Resource f(url.path());
1050 QString annotation = f.description();
1051 if (!annotation.isEmpty()) item->setText(1, annotation);
1052 item->setText(2, QString::number(f.rating()));
1056 QList <CutZoneInfo> cuts = clip->cutZones();
1057 if (!cuts.isEmpty()) {
1058 for (int i = 0; i < cuts.count(); i++) {
1059 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1060 if (!clip->getClipHash().isEmpty()) {
1061 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1062 if (QFile::exists(cachedPixmap)) {
1063 QPixmap pix(cachedPixmap);
1065 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1066 sub->setData(0, Qt::DecorationRole, pix);
1071 monitorItemEditing(true);
1072 if (m_listView->isEnabled()) {
1076 //if (getProperties && m_processingClips.isEmpty())
1077 //m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1079 QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1082 void ProjectList::slotGotProxy(const QString &proxyPath)
1084 if (proxyPath.isEmpty() || !m_refreshed) return;
1085 QTreeWidgetItemIterator it(m_listView);
1089 if ((*it)->type() == PROJECTCLIPTYPE) {
1090 item = static_cast <ProjectItem *>(*it);
1091 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1098 void ProjectList::slotGotProxy(ProjectItem *item)
1100 if (item == NULL || !m_refreshed) return;
1101 DocClipBase *clip = item->referencedClip();
1102 // Proxy clip successfully created
1103 QDomElement e = clip->toXML().cloneNode().toElement();
1105 // Make sure we get the correct producer length if it was adjusted in timeline
1106 CLIPTYPE t = item->clipType();
1107 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1108 int length = QString(clip->producerProperty("length")).toInt();
1109 if (length > 0 && !e.hasAttribute("length")) {
1110 e.setAttribute("length", length);
1113 e.setAttribute("replace", 1);
1115 m_infoQueue.insert(clip->getId(), e);
1117 //if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1118 QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1121 void ProjectList::slotResetProjectList()
1123 m_listView->clear();
1124 emit clipSelected(NULL);
1125 m_thumbnailQueue.clear();
1126 m_infoQueue.clear();
1127 m_refreshed = false;
1130 void ProjectList::slotProcessNextClipInQueue()
1132 if (m_infoQueue.isEmpty()) {
1133 emit processNextThumbnail();
1136 QMutexLocker locker(&m_mutex);
1137 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
1138 if (j != m_infoQueue.constEnd()) {
1139 QDomElement dom = j.value().cloneNode().toElement();
1140 const QString id = j.key();
1141 m_infoQueue.remove(id);
1142 m_processingClips.append(id);
1145 if (dom.hasAttribute("replace")) {
1146 // Proxy action was enabled / disabled and we want to replace current producer
1147 dom.removeAttribute("replace");
1150 else replace = false;
1151 bool selectClip = !replace;
1152 if (m_infoQueue.count() > 1) selectClip = false;
1153 emit getFileProperties(dom, id, m_listView->iconSize().height(), replace, selectClip);
1157 void ProjectList::slotUpdateClip(const QString &id)
1159 ProjectItem *item = getItemById(id);
1160 monitorItemEditing(false);
1161 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1162 monitorItemEditing(true);
1165 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged)
1167 m_listView->setSortingEnabled(false);
1169 QTreeWidgetItemIterator it(m_listView);
1172 monitorItemEditing(false);
1173 int height = m_listView->iconSize().height();
1174 int width = (int)(height * m_render->dar());
1175 QPixmap missingPixmap = QPixmap(width, height);
1176 missingPixmap.fill(Qt::transparent);
1177 KIcon icon("dialog-close");
1178 QPainter p(&missingPixmap);
1179 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1181 kDebug()<<"//////////////7 UPDATE ALL CLPS";
1183 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1185 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1186 if (displayRatioChanged || sub->data(0, Qt::DecorationRole).isNull()) {
1187 item = static_cast <ProjectItem *>((*it)->parent());
1188 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1192 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1197 item = static_cast <ProjectItem *>(*it);
1198 clip = item->referencedClip();
1199 if (item->referencedClip()->producer() == NULL) {
1200 if (clip->isPlaceHolder() == false) {
1201 QDomElement xml = clip->toXML();
1203 xml.removeAttribute("out");
1204 xml.removeAttribute("file_hash");
1205 xml.removeAttribute("proxy_out");
1208 m_infoQueue.insert(clip->getId(), xml);
1210 QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1213 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1214 if (item->data(0, Qt::DecorationRole).isNull()) {
1215 item->setData(0, Qt::DecorationRole, missingPixmap);
1218 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1219 QPainter p(&pixmap);
1220 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1222 item->setData(0, Qt::DecorationRole, pixmap);
1226 if (displayRatioChanged || item->data(0, Qt::DecorationRole).isNull())
1227 requestClipThumbnail(clip->getId());
1228 if (item->data(0, DurationRole).toString().isEmpty()) {
1229 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1231 if (clip->isPlaceHolder()) {
1232 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1233 if (pixmap.isNull()) {
1234 pixmap = QPixmap(width, height);
1235 pixmap.fill(Qt::transparent);
1237 QPainter p(&pixmap);
1238 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1240 item->setData(0, Qt::DecorationRole, pixmap);
1243 item->setData(0, UsageRole, QString::number(item->numReferences()));
1248 //if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1249 //QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1250 /*while (!m_infoQueue.isEmpty()) {
1251 QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1254 if (m_listView->isEnabled())
1255 monitorItemEditing(true);
1256 m_listView->setSortingEnabled(true);
1257 if (m_infoQueue.isEmpty()) {
1258 slotProcessNextThumbnail();
1263 QString ProjectList::getExtensions()
1265 // Build list of mime types
1266 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1267 << "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" << "video/webm"
1268 << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "audio/x-aiff" << "audio/aiff" << "application/ogg" << "application/mxf" << "application/x-shockwave-flash"
1269 << "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";
1271 QString allExtensions;
1272 foreach(const QString & mimeType, mimeTypes) {
1273 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1275 allExtensions.append(mime->patterns().join(" "));
1276 allExtensions.append(' ');
1279 return allExtensions.simplified();
1282 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1284 if (!m_commandStack)
1285 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1288 if (givenList.isEmpty()) {
1289 QString allExtensions = getExtensions();
1290 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1291 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1292 b->setChecked(KdenliveSettings::autoimagesequence());
1293 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1294 c->setChecked(KdenliveSettings::autoimagetransparency());
1295 QFrame *f = new QFrame;
1296 f->setFrameShape(QFrame::NoFrame);
1297 QHBoxLayout *l = new QHBoxLayout;
1302 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1303 d->setOperationMode(KFileDialog::Opening);
1304 d->setMode(KFile::Files);
1305 if (d->exec() == QDialog::Accepted) {
1306 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1308 list = d->selectedUrls();
1309 if (b->isChecked() && list.count() == 1) {
1310 // Check for image sequence
1311 KUrl url = list.at(0);
1312 QString fileName = url.fileName().section('.', 0, -2);
1313 if (fileName.at(fileName.size() - 1).isDigit()) {
1314 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1315 if (item.mimetype().startsWith("image")) {
1316 // import as sequence if we found more than one image in the sequence
1318 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1319 int count = list.count();
1322 QStringList groupInfo = getGroup();
1324 // get image sequence base name
1325 while (fileName.at(fileName.size() - 1).isDigit()) {
1329 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1330 false, false, false,
1331 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1332 QString(), groupInfo.at(0), groupInfo.at(1));
1340 for (int i = 0; i < givenList.count(); i++)
1341 list << givenList.at(i);
1344 foreach(const KUrl & file, list) {
1345 // Check there is no folder here
1346 KMimeType::Ptr type = KMimeType::findByUrl(file);
1347 if (type->is("inode/directory")) {
1348 // user dropped a folder
1349 list.removeAll(file);
1356 if (givenList.isEmpty()) {
1357 QStringList groupInfo = getGroup();
1358 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1360 m_doc->slotAddClipList(list, groupName, groupId);
1364 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1366 ProjectItem *item = getItemById(id);
1367 m_processingClips.removeAll(id);
1368 m_thumbnailQueue.removeAll(id);
1369 //if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1370 QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1372 const QString path = item->referencedClip()->fileURL().path();
1373 if (item->referencedClip()->isPlaceHolder()) replace = false;
1374 if (!path.isEmpty()) {
1376 KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1377 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)
1381 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1385 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1387 ProjectItem *item = getItemById(id);
1389 if (durationError) {
1390 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1391 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1393 item->setProxyStatus(PROXYCRASHED);
1394 QString path = item->referencedClip()->getProperty("proxy");
1395 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1397 //Security check: make sure the invalid proxy file is in the proxy folder
1398 if (proxyFolder.isParentOf(KUrl(path))) {
1399 QFile::remove(path);
1402 m_processingClips.removeAll(id);
1403 m_thumbnailQueue.removeAll(id);
1404 //if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1405 QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1408 void ProjectList::slotAddColorClip()
1410 if (!m_commandStack)
1411 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1413 QDialog *dia = new QDialog(this);
1414 Ui::ColorClip_UI dia_ui;
1415 dia_ui.setupUi(dia);
1416 dia->setWindowTitle(i18n("Color Clip"));
1417 dia_ui.clip_name->setText(i18n("Color Clip"));
1419 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1420 t->setValue(KdenliveSettings::color_duration());
1421 t->setTimeCodeFormat(false);
1422 dia_ui.clip_durationBox->addWidget(t);
1423 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1425 if (dia->exec() == QDialog::Accepted) {
1426 QString color = dia_ui.clip_color->color().name();
1427 KdenliveSettings::setColorclipcolor(color);
1428 color = color.replace(0, 1, "0x") + "ff";
1429 QStringList groupInfo = getGroup();
1430 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1437 void ProjectList::slotAddSlideshowClip()
1439 if (!m_commandStack)
1440 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1442 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1444 if (dia->exec() == QDialog::Accepted) {
1445 QStringList groupInfo = getGroup();
1446 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1447 dia->loop(), dia->crop(), dia->fade(),
1448 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1449 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1454 void ProjectList::slotAddTitleClip()
1456 QStringList groupInfo = getGroup();
1457 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1460 void ProjectList::slotAddTitleTemplateClip()
1462 if (!m_commandStack)
1463 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1465 QStringList groupInfo = getGroup();
1467 // Get the list of existing templates
1469 filter << "*.kdenlivetitle";
1470 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1471 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1473 QDialog *dia = new QDialog(this);
1474 Ui::TemplateClip_UI dia_ui;
1475 dia_ui.setupUi(dia);
1476 for (int i = 0; i < templateFiles.size(); ++i)
1477 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1479 if (!templateFiles.isEmpty())
1480 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1481 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1482 //warning: setting base directory doesn't work??
1483 KUrl startDir(path);
1484 dia_ui.template_list->fileDialog()->setUrl(startDir);
1485 dia_ui.text_box->setHidden(true);
1486 if (dia->exec() == QDialog::Accepted) {
1487 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1488 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1489 // Create a cloned template clip
1490 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1495 QStringList ProjectList::getGroup() const
1498 QTreeWidgetItem *item = m_listView->currentItem();
1499 while (item && item->type() != PROJECTFOLDERTYPE)
1500 item = item->parent();
1503 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1504 result << folder->groupName() << folder->clipId();
1506 result << QString() << QString();
1511 void ProjectList::setDocument(KdenliveDoc *doc)
1513 m_listView->blockSignals(true);
1514 m_listView->clear();
1515 m_processingClips.clear();
1516 m_listView->setSortingEnabled(false);
1517 emit clipSelected(NULL);
1518 m_thumbnailQueue.clear();
1519 m_infoQueue.clear();
1520 m_refreshed = false;
1522 m_timecode = doc->timecode();
1523 m_commandStack = doc->commandStack();
1525 setEnabled(!m_doc->isReadOnly());
1527 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1528 QStringList openedFolders = doc->getExpandedFolders();
1529 QMapIterator<QString, QString> f(flist);
1530 while (f.hasNext()) {
1532 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1533 folder->setExpanded(openedFolders.contains(f.key()));
1536 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1537 if (list.isEmpty()) m_refreshed = true;
1538 for (int i = 0; i < list.count(); i++)
1539 slotAddClip(list.at(i), false);
1541 m_listView->blockSignals(false);
1542 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1543 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1544 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1545 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1546 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool)), this, SLOT(updateAllClips(bool, bool)));
1549 QList <DocClipBase*> ProjectList::documentClipList() const
1552 return QList <DocClipBase*> ();
1554 return m_doc->clipManager()->documentClipList();
1557 QDomElement ProjectList::producersList()
1560 QDomElement prods = doc.createElement("producerlist");
1561 doc.appendChild(prods);
1562 kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
1563 QTreeWidgetItemIterator it(m_listView);
1565 if ((*it)->type() != PROJECTCLIPTYPE) {
1570 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1576 void ProjectList::slotCheckForEmptyQueue()
1578 if (m_processingClips.isEmpty() && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1580 emit loadingIsOver();
1581 emit displayMessage(QString(), -1);
1584 m_listView->blockSignals(false);
1585 m_listView->setEnabled(true);
1587 } else if (!m_refreshed) {
1588 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1593 void ProjectList::requestClipThumbnail(const QString id)
1595 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1598 void ProjectList::slotProcessNextThumbnail()
1600 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1601 slotCheckForEmptyQueue();
1604 if (!m_infoQueue.isEmpty()) {
1605 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1608 if (m_thumbnailQueue.count() > 1) {
1609 int max = m_doc->clipManager()->clipsCount();
1610 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1612 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1615 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1617 QTreeWidgetItem *item = getAnyItemById(clipId);
1619 slotRefreshClipThumbnail(item, update);
1621 slotProcessNextThumbnail();
1625 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1627 if (it == NULL) return;
1628 ProjectItem *item = NULL;
1629 bool isSubItem = false;
1631 if (it->type() == PROJECTFOLDERTYPE) return;
1632 if (it->type() == PROJECTSUBCLIPTYPE) {
1633 item = static_cast <ProjectItem *>(it->parent());
1634 frame = static_cast <SubProjectItem *>(it)->zone().x();
1637 item = static_cast <ProjectItem *>(it);
1638 frame = item->referencedClip()->getClipThumbFrame();
1642 DocClipBase *clip = item->referencedClip();
1644 slotProcessNextThumbnail();
1648 int height = m_listView->iconSize().height();
1649 int width = (int)(height * m_render->dar());
1650 if (clip->clipType() == AUDIO)
1651 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1652 else if (clip->clipType() == IMAGE)
1653 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1655 pix = item->referencedClip()->extractImage(frame, width, height);
1657 if (!pix.isNull()) {
1658 monitorItemEditing(false);
1659 it->setData(0, Qt::DecorationRole, pix);
1660 monitorItemEditing(true);
1663 m_doc->cachePixmap(item->getClipHash(), pix);
1665 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1668 emit projectModified();
1669 slotProcessNextThumbnail();
1673 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace, bool selectClip)
1676 ProjectItem *item = getItemById(clipId);
1678 // we are still finishing to load the document
1681 m_processingClips.removeAll(clipId);
1682 if (m_infoQueue.isEmpty() && m_processingClips.isEmpty()) m_listView->setEnabled(true);
1683 if (item && producer) {
1684 //m_listView->blockSignals(true);
1685 monitorItemEditing(false);
1686 DocClipBase *clip = item->referencedClip();
1687 item->setProperties(properties, metadata);
1688 if (clip->isPlaceHolder() && producer->is_valid()) {
1690 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1693 clip->setProducer(producer, replace);
1694 clip->askForAudioThumbs();
1696 QString size = properties.value("frame_size");
1697 if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY);
1698 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY);
1699 else if (useProxy() && !item->isProxyRunning()) {
1700 // proxy video and image clips
1702 CLIPTYPE t = item->clipType();
1703 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
1704 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
1705 if ((((t == AV || t == VIDEO || t == PLAYLIST) && generateProxy()) || (t == IMAGE && generateImageProxy())) && (size.section('x', 0, 0).toInt() > maxSize || size.section('x', 1, 1).toInt() > maxSize)) {
1706 if (clip->getProperty("proxy").isEmpty()) {
1707 KUrl proxyPath = m_doc->projectFolder();
1708 proxyPath.addPath("proxy/");
1709 proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
1710 QMap <QString, QString> newProps;
1711 // insert required duration for proxy
1712 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
1713 newProps.insert("proxy", proxyPath.path());
1714 QMap <QString, QString> oldProps = clip->properties();
1715 oldProps.insert("proxy", QString());
1716 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
1717 m_doc->commandStack()->push(command);
1722 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1723 requestClipThumbnail(clipId);
1724 if (!toReload.isEmpty())
1725 item->slotSetToolTip();
1727 if (m_listView->isEnabled())
1728 monitorItemEditing(true);
1729 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1730 if (selectClip && m_infoQueue.isEmpty()) {
1731 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1732 m_listView->setCurrentItem(item);
1733 bool updatedProfile = false;
1734 if (item->parent()) {
1735 if (item->parent()->type() == PROJECTFOLDERTYPE)
1736 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1737 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) {
1738 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1739 updatedProfile = adjustProjectProfileToItem(item);
1741 if (updatedProfile == false) emit clipSelected(item->referencedClip());
1743 int max = m_doc->clipManager()->clipsCount();
1744 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1747 if (item && m_listView->isEnabled() && replace) {
1748 // update clip in clip monitor
1749 if (item->isSelected() && m_listView->selectedItems().count() == 1)
1750 emit clipSelected(item->referencedClip());
1751 //TODO: Make sure the line below has no side effect
1754 if (!toReload.isEmpty())
1755 emit clipNeedsReload(toReload, true);
1757 //if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1758 QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1761 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1764 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1765 item = static_cast <ProjectItem*>(m_listView->currentItem());
1767 if (item == NULL || item->referencedClip() == NULL) {
1768 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1771 bool profileUpdated = false;
1772 QString size = item->referencedClip()->getProperty("frame_size");
1773 int width = size.section('x', 0, 0).toInt();
1774 int height = size.section('x', -1).toInt();
1775 double fps = item->referencedClip()->getProperty("fps").toDouble();
1776 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1777 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1778 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1779 // get a list of compatible profiles
1780 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1781 if (!suggestedProfiles.isEmpty()) {
1782 KDialog *dialog = new KDialog(this);
1783 dialog->setCaption(i18n("Change project profile"));
1784 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1787 QVBoxLayout *l = new QVBoxLayout;
1788 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));
1789 l->addWidget(label);
1790 QListWidget *list = new QListWidget;
1791 list->setAlternatingRowColors(true);
1792 QMapIterator<QString, QString> i(suggestedProfiles);
1793 while (i.hasNext()) {
1795 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1796 item->setData(Qt::UserRole, i.key());
1797 item->setToolTip(i.key());
1799 list->setCurrentRow(0);
1801 container.setLayout(l);
1802 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1803 dialog->setMainWidget(&container);
1804 if (dialog->exec() == QDialog::Accepted) {
1805 //Change project profile
1806 profileUpdated = true;
1807 if (list->currentItem())
1808 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1812 } else if (fps > 0) {
1813 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));
1817 return profileUpdated;
1820 QString ProjectList::getDocumentProperty(const QString &key) const
1822 return m_doc->getDocumentProperty(key);
1825 bool ProjectList::useProxy() const
1827 return m_doc->getDocumentProperty("enableproxy").toInt();
1830 bool ProjectList::generateProxy() const
1832 return m_doc->getDocumentProperty("generateproxy").toInt();
1835 bool ProjectList::generateImageProxy() const
1837 return m_doc->getDocumentProperty("generateimageproxy").toInt();
1840 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1842 ProjectItem *item = getItemById(clipId);
1843 if (item && !pix.isNull()) {
1844 monitorItemEditing(false);
1845 item->setData(0, Qt::DecorationRole, pix);
1846 monitorItemEditing(true);
1847 m_doc->cachePixmap(item->getClipHash(), pix);
1848 if (m_listView->isEnabled())
1849 m_listView->blockSignals(false);
1853 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1855 QTreeWidgetItemIterator it(m_listView);
1856 QString lookId = id;
1857 if (id.contains('#'))
1858 lookId = id.section('#', 0, 0);
1860 ProjectItem *result = NULL;
1862 if ((*it)->type() != PROJECTCLIPTYPE) {
1867 ProjectItem *item = static_cast<ProjectItem *>(*it);
1868 if (item->clipId() == lookId) {
1874 if (result == NULL || !id.contains('#')) {
1877 for (int i = 0; i < result->childCount(); i++) {
1878 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1879 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1888 ProjectItem *ProjectList::getItemById(const QString &id)
1891 QTreeWidgetItemIterator it(m_listView);
1893 if ((*it)->type() != PROJECTCLIPTYPE) {
1894 // subitem or folder
1898 item = static_cast<ProjectItem *>(*it);
1899 if (item->clipId() == id)
1906 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1908 FolderProjectItem *item;
1909 QTreeWidgetItemIterator it(m_listView);
1911 if ((*it)->type() == PROJECTFOLDERTYPE) {
1912 item = static_cast<FolderProjectItem *>(*it);
1913 if (item->clipId() == id)
1921 void ProjectList::slotSelectClip(const QString &ix)
1923 ProjectItem *clip = getItemById(ix);
1925 m_listView->setCurrentItem(clip);
1926 m_listView->scrollToItem(clip);
1927 m_editButton->defaultAction()->setEnabled(true);
1928 m_deleteButton->defaultAction()->setEnabled(true);
1929 m_reloadAction->setEnabled(true);
1930 m_transcodeAction->setEnabled(true);
1931 m_proxyAction->setEnabled(useProxy());
1932 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1933 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1934 m_openAction->setEnabled(true);
1935 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1936 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1937 m_openAction->setEnabled(true);
1939 m_openAction->setEnabled(false);
1944 QString ProjectList::currentClipUrl() const
1947 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1948 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1950 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1952 item = static_cast <ProjectItem*>(m_listView->currentItem());
1956 return item->clipUrl().path();
1959 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1963 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1964 for (int i = 0; i < list.count(); i++) {
1965 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1967 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1969 item = static_cast <ProjectItem*>(list.at(i)->parent());
1971 item = static_cast <ProjectItem*>(list.at(i));
1973 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1975 DocClipBase *clip = item->referencedClip();
1976 if (!condition.isEmpty()) {
1977 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1979 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1982 result.append(item->clipUrl());
1987 void ProjectList::regenerateTemplate(const QString &id)
1989 ProjectItem *clip = getItemById(id);
1991 regenerateTemplate(clip);
1994 void ProjectList::regenerateTemplate(ProjectItem *clip)
1996 //TODO: remove this unused method, only force_reload is necessary
1997 clip->referencedClip()->producer()->set("force_reload", 1);
2000 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2004 if (!file.open(QIODevice::ReadOnly)) {
2005 kWarning() << "ERROR, CANNOT READ: " << path;
2008 if (!doc.setContent(&file)) {
2009 kWarning() << "ERROR, CANNOT READ: " << path;
2014 QDomNodeList texts = doc.elementsByTagName("content");
2015 for (int i = 0; i < texts.count(); i++) {
2016 QString data = texts.item(i).firstChild().nodeValue();
2017 data.replace("%s", replaceString);
2018 texts.item(i).firstChild().setNodeValue(data);
2024 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2026 ProjectItem *clip = getItemById(id);
2027 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2029 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2030 m_commandStack->push(command);
2033 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2035 ProjectItem *clip = getItemById(id);
2037 DocClipBase *base = clip->referencedClip();
2038 base->addCutZone(in, out);
2039 monitorItemEditing(false);
2040 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2041 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2042 if (!clip->isExpanded())
2043 clip->setExpanded(true);
2044 m_listView->scrollToItem(sub);
2045 m_listView->editItem(sub, 1);
2047 QPixmap p = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
2048 sub->setData(0, Qt::DecorationRole, p);
2049 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
2050 monitorItemEditing(true);
2052 emit projectModified();
2055 void ProjectList::removeClipCut(const QString &id, int in, int out)
2057 ProjectItem *clip = getItemById(id);
2059 DocClipBase *base = clip->referencedClip();
2060 base->removeCutZone(in, out);
2061 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2063 monitorItemEditing(false);
2065 monitorItemEditing(true);
2068 emit projectModified();
2071 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2073 SubProjectItem *sub = NULL;
2075 for (int i = 0; i < clip->childCount(); i++) {
2076 QTreeWidgetItem *it = clip->child(i);
2077 if (it->type() == PROJECTSUBCLIPTYPE) {
2078 sub = static_cast <SubProjectItem*>(it);
2079 if (sub->zone() == zone)
2089 void ProjectList::slotUpdateClipCut(QPoint p)
2091 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2093 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2094 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2095 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2096 m_commandStack->push(command);
2099 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2101 ProjectItem *clip = getItemById(id);
2102 SubProjectItem *sub = getSubItem(clip, oldzone);
2103 if (sub == NULL || clip == NULL)
2105 DocClipBase *base = clip->referencedClip();
2106 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2107 monitorItemEditing(false);
2109 sub->setDescription(comment);
2110 monitorItemEditing(true);
2111 emit projectModified();
2114 void ProjectList::slotForceProcessing(const QString &id)
2116 while (m_infoQueue.contains(id)) {
2117 slotProcessNextClipInQueue();
2121 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2123 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2125 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2126 int count = list.count();
2128 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2129 if (!existing.isEmpty()) {
2130 // Sequence already exists, update
2131 QString id = existing.at(0)->getId();
2132 //ProjectItem *item = getItemById(id);
2133 QMap <QString, QString> oldprops;
2134 QMap <QString, QString> newprops;
2135 int ttl = existing.at(0)->getProperty("ttl").toInt();
2136 oldprops["out"] = existing.at(0)->getProperty("out");
2137 newprops["out"] = QString::number(ttl * count - 1);
2138 slotUpdateClipProperties(id, newprops);
2139 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2140 m_commandStack->push(command);
2143 QStringList groupInfo = getGroup();
2144 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
2145 false, false, false,
2146 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
2147 QString(), groupInfo.at(0), groupInfo.at(1));
2149 } else emit displayMessage(i18n("Sequence not found"), -2);
2152 QMap <QString, QString> ProjectList::getProxies()
2154 QMap <QString, QString> list;
2156 QTreeWidgetItemIterator it(m_listView);
2158 if ((*it)->type() != PROJECTCLIPTYPE) {
2162 item = static_cast<ProjectItem *>(*it);
2163 if (item && item->referencedClip() != NULL) {
2164 if (item->hasProxy()) {
2165 QString proxy = item->referencedClip()->getProperty("proxy");
2166 list.insert(proxy, item->clipUrl().path());
2174 void ProjectList::slotCreateProxy(const QString id)
2176 ProjectItem *item = getItemById(id);
2177 if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
2178 QString path = item->referencedClip()->getProperty("proxy");
2179 if (path.isEmpty()) {
2180 setProxyStatus(path, PROXYCRASHED);
2183 setProxyStatus(path, PROXYWAITING);
2184 if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
2185 if (m_processingProxy.contains(path)) {
2186 // Proxy is already being generated
2189 if (QFile::exists(path)) {
2190 // Proxy already created
2191 setProxyStatus(path, PROXYDONE);
2195 m_processingProxy.append(path);
2196 QtConcurrent::run(this, &ProjectList::slotGenerateProxy, path, item->clipUrl().path(), item->clipType(), QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt());
2199 void ProjectList::slotAbortProxy(const QString id, const QString path)
2201 QTreeWidgetItemIterator it(m_listView);
2202 ProjectItem *item = getItemById(id);
2203 setProxyStatus(item, NOPROXY);
2205 if (!path.isEmpty() && m_processingProxy.contains(path)) {
2206 m_abortProxy << path;
2207 setProxyStatus(path, NOPROXY);
2211 void ProjectList::slotGenerateProxy(const QString destPath, const QString sourcePath, int clipType, int exif_orientation)
2213 emit projectModified();
2214 // Make sure proxy path is writable
2215 QFile file(destPath);
2216 if (!file.open(QIODevice::WriteOnly)) {
2217 setProxyStatus(destPath, PROXYCRASHED);
2218 m_processingProxy.removeAll(destPath);
2222 QFile::remove(destPath);
2224 setProxyStatus(destPath, CREATINGPROXY);
2226 // Special case: playlist clips (.mlt or .kdenlive project files)
2227 if (clipType == PLAYLIST) {
2228 // change FFmpeg params to MLT format
2229 QStringList parameters;
2230 parameters << sourcePath;
2231 parameters << "-consumer" << "avformat:" + destPath;
2232 QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts);
2234 foreach(QString s, params) {
2236 if (s.count(' ') == 0) {
2239 else s.replace(' ', '=');
2243 parameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads()));
2245 //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
2246 double display_ratio = KdenliveDoc::getDisplayRatio(sourcePath);
2247 parameters << "aspect=" + QString::number(display_ratio);
2249 //kDebug()<<"TRANSCOD: "<<parameters;
2251 myProcess.start(KdenliveSettings::rendererpath(), parameters);
2252 myProcess.waitForStarted();
2254 while (myProcess.state() != QProcess::NotRunning) {
2255 // building proxy file
2256 if (m_abortProxy.contains(destPath)) {
2258 myProcess.waitForFinished();
2259 m_abortProxy.removeAll(destPath);
2260 m_processingProxy.removeAll(destPath);
2261 QFile::remove(destPath);
2262 setProxyStatus(destPath, NOPROXY);
2266 myProcess.waitForFinished(500);
2268 myProcess.waitForFinished();
2269 m_processingProxy.removeAll(destPath);
2270 if (result == -1) result = myProcess.exitStatus();
2272 // proxy successfully created
2273 setProxyStatus(destPath, PROXYDONE);
2274 slotGotProxy(destPath);
2276 else if (result == 1) {
2277 // Proxy process crashed
2278 QFile::remove(destPath);
2279 setProxyStatus(destPath, PROXYCRASHED);
2284 if (clipType == IMAGE) {
2286 QImage i(sourcePath);
2288 // Cannot load image
2289 setProxyStatus(destPath, PROXYCRASHED);
2293 // Images are scaled to profile size.
2294 //TODO: Make it be configurable?
2295 if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth());
2296 else proxy = i.scaledToHeight(m_render->renderHeight());
2297 if (exif_orientation > 1) {
2298 // Rotate image according to exif data
2302 switch ( exif_orientation ) {
2304 matrix.scale( -1, 1 );
2307 matrix.rotate( 180 );
2310 matrix.scale( 1, -1 );
2313 matrix.rotate( 270 );
2314 matrix.scale( -1, 1 );
2317 matrix.rotate( 90 );
2320 matrix.rotate( 90 );
2321 matrix.scale( -1, 1 );
2324 matrix.rotate( 270 );
2327 processed = proxy.transformed( matrix );
2328 processed.save(destPath);
2330 else proxy.save(destPath);
2331 setProxyStatus(destPath, PROXYDONE);
2332 slotGotProxy(destPath);
2333 m_abortProxy.removeAll(destPath);
2334 m_processingProxy.removeAll(destPath);
2338 QStringList parameters;
2339 parameters << "-i" << sourcePath;
2340 QString params = m_doc->getDocumentProperty("proxyparams").simplified();
2341 foreach(QString s, params.split(' '))
2344 // Make sure we don't block when proxy file already exists
2346 parameters << destPath;
2347 kDebug()<<"// STARTING PROXY GEN: "<<parameters;
2349 myProcess.start("ffmpeg", parameters);
2350 myProcess.waitForStarted();
2352 while (myProcess.state() != QProcess::NotRunning) {
2353 // building proxy file
2354 if (m_abortProxy.contains(destPath)) {
2356 myProcess.waitForFinished();
2357 m_abortProxy.removeAll(destPath);
2358 m_processingProxy.removeAll(destPath);
2359 QFile::remove(destPath);
2360 setProxyStatus(destPath, NOPROXY);
2364 myProcess.waitForFinished(500);
2366 myProcess.waitForFinished();
2367 if (result == -1) result = myProcess.exitStatus();
2369 // proxy successfully created
2370 setProxyStatus(destPath, PROXYDONE);
2371 slotGotProxy(destPath);
2373 else if (result == 1) {
2374 // Proxy process crashed
2375 QFile::remove(destPath);
2376 setProxyStatus(destPath, PROXYCRASHED);
2378 m_abortProxy.removeAll(destPath);
2379 m_processingProxy.removeAll(destPath);
2382 void ProjectList::updateProxyConfig()
2385 QTreeWidgetItemIterator it(m_listView);
2386 QUndoCommand *command = new QUndoCommand();
2387 command->setText(i18n("Update proxy settings"));
2388 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2390 if ((*it)->type() != PROJECTCLIPTYPE) {
2394 item = static_cast<ProjectItem *>(*it);
2399 CLIPTYPE t = item->clipType();
2400 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2401 if (generateProxy() && useProxy() && !item->isProxyRunning()) {
2402 DocClipBase *clip = item->referencedClip();
2403 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
2404 if (clip->getProperty("proxy").isEmpty()) {
2405 // We need to insert empty proxy in old properties so that undo will work
2406 QMap <QString, QString> oldProps;// = clip->properties();
2407 oldProps.insert("proxy", QString());
2408 QMap <QString, QString> newProps;
2409 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
2410 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2414 else if (item->hasProxy()) {
2416 QMap <QString, QString> newProps;
2417 newProps.insert("proxy", QString());
2418 newProps.insert("replace", "1");
2419 // insert required duration for proxy
2420 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2421 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2424 else if (t == IMAGE && item->referencedClip() != NULL) {
2425 if (generateImageProxy() && useProxy()) {
2426 DocClipBase *clip = item->referencedClip();
2427 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2428 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
2429 if (clip->getProperty("proxy").isEmpty()) {
2430 // We need to insert empty proxy in old properties so that undo will work
2431 QMap <QString, QString> oldProps = clip->properties();
2432 oldProps.insert("proxy", QString());
2433 QMap <QString, QString> newProps;
2434 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
2435 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2439 else if (item->hasProxy()) {
2441 QMap <QString, QString> newProps;
2442 newProps.insert("proxy", QString());
2443 newProps.insert("replace", "1");
2444 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2449 if (command->childCount() > 0) m_doc->commandStack()->push(command);
2450 else delete command;
2451 //if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
2452 QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
2455 void ProjectList::slotProxyCurrentItem(bool doProxy)
2457 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2458 QTreeWidgetItem *listItem;
2459 QUndoCommand *command = new QUndoCommand();
2460 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", list.count()));
2461 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", list.count()));
2463 // Make sure the proxy folder exists
2464 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2465 KStandardDirs::makeDir(proxydir);
2467 QMap <QString, QString> newProps;
2468 QMap <QString, QString> oldProps;
2469 if (!doProxy) newProps.insert("proxy", "-");
2470 for (int i = 0; i < list.count(); i++) {
2471 listItem = list.at(i);
2472 if (listItem->type() == PROJECTFOLDERTYPE) {
2473 for (int j = 0; j < listItem->childCount(); j++) {
2474 QTreeWidgetItem *sub = listItem->child(j);
2475 if (!list.contains(sub)) list.append(sub);
2478 if (listItem->type() == PROJECTCLIPTYPE) {
2479 ProjectItem *item = static_cast <ProjectItem*>(listItem);
2480 CLIPTYPE t = item->clipType();
2481 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
2482 oldProps = item->referencedClip()->properties();
2485 QString path = proxydir + item->referencedClip()->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
2486 // insert required duration for proxy
2487 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2488 newProps.insert("proxy", path);
2489 // We need to insert empty proxy so that undo will work
2490 oldProps.insert("proxy", QString());
2492 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
2496 if (command->childCount() > 0) {
2497 m_doc->commandStack()->push(command);
2499 else delete command;
2500 //if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
2501 if (!m_infoQueue.isEmpty()) QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
2505 void ProjectList::slotDeleteProxy(const QString proxyPath)
2507 if (proxyPath.isEmpty()) return;
2508 QUndoCommand *proxyCommand = new QUndoCommand();
2509 proxyCommand->setText(i18n("Remove Proxy"));
2510 QTreeWidgetItemIterator it(m_listView);
2513 if ((*it)->type() == PROJECTCLIPTYPE) {
2514 item = static_cast <ProjectItem *>(*it);
2515 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
2516 QMap <QString, QString> props;
2517 props.insert("proxy", QString());
2518 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), props, true, proxyCommand);
2524 if (proxyCommand->childCount() == 0)
2525 delete proxyCommand;
2527 m_commandStack->push(proxyCommand);
2528 QFile::remove(proxyPath);
2531 void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status)
2533 if (proxyPath.isEmpty()) return;
2534 QTreeWidgetItemIterator it(m_listView);
2537 if ((*it)->type() == PROJECTCLIPTYPE) {
2538 item = static_cast <ProjectItem *>(*it);
2539 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
2540 setProxyStatus(item, status);
2547 void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status)
2549 if (item == NULL) return;
2550 monitorItemEditing(false);
2551 item->setProxyStatus(status);
2552 monitorItemEditing(true);
2555 void ProjectList::monitorItemEditing(bool enable)
2557 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2558 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2561 QStringList ProjectList::expandedFolders() const
2564 FolderProjectItem *item;
2565 QTreeWidgetItemIterator it(m_listView);
2567 if ((*it)->type() != PROJECTFOLDERTYPE) {
2571 if ((*it)->isExpanded()) {
2572 item = static_cast<FolderProjectItem *>(*it);
2573 result.append(item->clipId());
2580 #include "projectlist.moc"