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 m_listView->blockSignals(true);
910 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
911 if (!newSelectedItem)
912 newSelectedItem = m_listView->itemBelow(item);
914 m_doc->clipManager()->deleteClip(clipId);
915 m_listView->blockSignals(false);
916 if (newSelectedItem) {
917 m_listView->setCurrentItem(newSelectedItem);
920 emit clipSelected(NULL);
925 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
927 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
928 m_commandStack->push(command);
929 m_doc->setModified(true);
932 void ProjectList::slotAddFolder()
934 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
935 m_commandStack->push(command);
938 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
941 FolderProjectItem *item = getFolderItemById(clipId);
943 m_doc->clipManager()->deleteFolder(clipId);
944 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
945 if (!newSelectedItem)
946 newSelectedItem = m_listView->itemBelow(item);
949 m_listView->setCurrentItem(newSelectedItem);
955 FolderProjectItem *item = getFolderItemById(clipId);
957 m_listView->blockSignals(true);
958 item->setGroupName(foldername);
959 m_listView->blockSignals(false);
960 m_doc->clipManager()->addFolder(clipId, foldername);
961 const int children = item->childCount();
962 for (int i = 0; i < children; i++) {
963 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
964 child->setProperty("groupname", foldername);
968 m_listView->blockSignals(true);
969 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
970 m_doc->clipManager()->addFolder(clipId, foldername);
971 m_listView->blockSignals(false);
972 m_listView->editItem(m_listView->currentItem(), 0);
976 m_doc->setModified(true);
981 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
983 QMapIterator<QString, QString> i(map);
984 QUndoCommand *delCommand = new QUndoCommand();
985 delCommand->setText(i18n("Delete Folder"));
986 while (i.hasNext()) {
988 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
990 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
991 else delete delCommand;
994 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
996 m_listView->setEnabled(false);
997 const QString parent = clip->getProperty("groupid");
998 ProjectItem *item = NULL;
999 monitorItemEditing(false);
1000 if (!parent.isEmpty()) {
1001 FolderProjectItem *parentitem = getFolderItemById(parent);
1004 QString groupName = clip->getProperty("groupname");
1005 //kDebug() << "Adding clip to new group: " << groupName;
1006 if (groupName.isEmpty()) groupName = i18n("Folder");
1008 parentitem = new FolderProjectItem(m_listView, text, parent);
1012 item = new ProjectItem(parentitem, clip);
1015 item = new ProjectItem(m_listView, clip);
1017 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1018 connect(clip, SIGNAL(createProxy(const QString)), this, SLOT(slotCreateProxy(const QString)));
1019 connect(clip, SIGNAL(abortProxy(const QString, const QString)), this, SLOT(slotAbortProxy(const QString, const QString)));
1020 if (getProperties) {
1021 m_listView->processLayout();
1022 QDomElement e = clip->toXML().cloneNode().toElement();
1023 e.removeAttribute("file_hash");
1024 m_infoQueue.insert(clip->getId(), e);
1026 else if (item->hasProxy() && !item->isProxyRunning()) {
1027 slotCreateProxy(clip->getId());
1029 clip->askForAudioThumbs();
1031 KUrl url = clip->fileURL();
1032 if (getProperties == false && !clip->getClipHash().isEmpty()) {
1033 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1034 if (QFile::exists(cachedPixmap)) {
1035 QPixmap pix(cachedPixmap);
1037 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1038 item->setData(0, Qt::DecorationRole, pix);
1042 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
1043 // if file has Nepomuk comment, use it
1044 Nepomuk::Resource f(url.path());
1045 QString annotation = f.description();
1046 if (!annotation.isEmpty()) item->setText(1, annotation);
1047 item->setText(2, QString::number(f.rating()));
1051 QList <CutZoneInfo> cuts = clip->cutZones();
1052 if (!cuts.isEmpty()) {
1053 for (int i = 0; i < cuts.count(); i++) {
1054 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1055 if (!clip->getClipHash().isEmpty()) {
1056 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1057 if (QFile::exists(cachedPixmap)) {
1058 QPixmap pix(cachedPixmap);
1060 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1061 sub->setData(0, Qt::DecorationRole, pix);
1066 monitorItemEditing(true);
1067 if (m_listView->isEnabled()) {
1071 if (getProperties && m_processingClips.isEmpty())
1072 m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1075 void ProjectList::slotGotProxy(const QString &proxyPath)
1077 if (proxyPath.isEmpty()) return;
1078 QTreeWidgetItemIterator it(m_listView);
1082 if ((*it)->type() == PROJECTCLIPTYPE) {
1083 item = static_cast <ProjectItem *>(*it);
1084 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1091 void ProjectList::slotGotProxy(ProjectItem *item)
1093 if (item == NULL) return;
1094 DocClipBase *clip = item->referencedClip();
1095 // Proxy clip successfully created
1096 QDomElement e = clip->toXML().cloneNode().toElement();
1098 // Make sure we get the correct producer length if it was adjusted in timeline
1099 CLIPTYPE t = item->clipType();
1100 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1101 int length = QString(clip->producerProperty("length")).toInt();
1102 if (length > 0 && !e.hasAttribute("length")) {
1103 e.setAttribute("length", length);
1106 e.setAttribute("replace", 1);
1107 m_infoQueue.insert(clip->getId(), e);
1108 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1111 void ProjectList::slotResetProjectList()
1113 m_listView->clear();
1114 emit clipSelected(NULL);
1115 m_thumbnailQueue.clear();
1116 m_infoQueue.clear();
1117 m_refreshed = false;
1120 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
1122 m_infoQueue.insert(id, xml);
1123 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1126 void ProjectList::slotProcessNextClipInQueue()
1128 if (m_infoQueue.isEmpty()) {
1129 emit processNextThumbnail();
1133 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
1134 if (j != m_infoQueue.constEnd()) {
1135 QDomElement dom = j.value().cloneNode().toElement();
1136 const QString id = j.key();
1137 m_infoQueue.remove(id);
1138 m_processingClips.append(id);
1140 if (dom.hasAttribute("replace")) {
1141 // Proxy action was enabled / disabled and we want to replace current producer
1142 dom.removeAttribute("replace");
1145 else replace = false;
1146 bool selectClip = !replace;
1147 if (m_infoQueue.count() > 1) selectClip = false;
1148 emit getFileProperties(dom, id, m_listView->iconSize().height(), replace, selectClip);
1152 void ProjectList::slotUpdateClip(const QString &id)
1154 ProjectItem *item = getItemById(id);
1155 monitorItemEditing(false);
1156 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1157 monitorItemEditing(true);
1160 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged)
1162 m_listView->setSortingEnabled(false);
1164 QTreeWidgetItemIterator it(m_listView);
1167 monitorItemEditing(false);
1168 int height = m_listView->iconSize().height();
1169 int width = (int)(height * m_render->dar());
1170 QPixmap missingPixmap = QPixmap(width, height);
1171 missingPixmap.fill(Qt::transparent);
1172 KIcon icon("dialog-close");
1173 QPainter p(&missingPixmap);
1174 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1178 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1180 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1181 if (displayRatioChanged || sub->data(0, Qt::DecorationRole).isNull()) {
1182 item = static_cast <ProjectItem *>((*it)->parent());
1183 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1187 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1192 item = static_cast <ProjectItem *>(*it);
1193 clip = item->referencedClip();
1194 if (item->referencedClip()->producer() == NULL) {
1195 if (clip->isPlaceHolder() == false) {
1196 QDomElement xml = clip->toXML();
1198 xml.removeAttribute("out");
1199 xml.removeAttribute("file_hash");
1200 xml.removeAttribute("proxy_out");
1202 requestClipInfo(xml, clip->getId());
1205 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1206 if (item->data(0, Qt::DecorationRole).isNull()) {
1207 item->setData(0, Qt::DecorationRole, missingPixmap);
1210 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1211 QPainter p(&pixmap);
1212 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1214 item->setData(0, Qt::DecorationRole, pixmap);
1218 if (displayRatioChanged || item->data(0, Qt::DecorationRole).isNull())
1219 requestClipThumbnail(clip->getId());
1220 if (item->data(0, DurationRole).toString().isEmpty()) {
1221 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1223 if (clip->isPlaceHolder()) {
1224 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1225 if (pixmap.isNull()) {
1226 pixmap = QPixmap(width, height);
1227 pixmap.fill(Qt::transparent);
1229 QPainter p(&pixmap);
1230 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1232 item->setData(0, Qt::DecorationRole, pixmap);
1235 item->setData(0, UsageRole, QString::number(item->numReferences()));
1240 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1241 if (m_listView->isEnabled())
1242 monitorItemEditing(true);
1243 m_listView->setSortingEnabled(true);
1244 if (m_infoQueue.isEmpty()) {
1245 slotProcessNextThumbnail();
1250 QString ProjectList::getExtensions()
1252 // Build list of mime types
1253 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1254 << "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"
1255 << "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"
1256 << "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";
1258 QString allExtensions;
1259 foreach(const QString & mimeType, mimeTypes) {
1260 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1262 allExtensions.append(mime->patterns().join(" "));
1263 allExtensions.append(' ');
1266 return allExtensions.simplified();
1269 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1271 if (!m_commandStack)
1272 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1275 if (givenList.isEmpty()) {
1276 QString allExtensions = getExtensions();
1277 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1278 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1279 b->setChecked(KdenliveSettings::autoimagesequence());
1280 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1281 c->setChecked(KdenliveSettings::autoimagetransparency());
1282 QFrame *f = new QFrame;
1283 f->setFrameShape(QFrame::NoFrame);
1284 QHBoxLayout *l = new QHBoxLayout;
1289 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1290 d->setOperationMode(KFileDialog::Opening);
1291 d->setMode(KFile::Files);
1292 if (d->exec() == QDialog::Accepted) {
1293 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1295 list = d->selectedUrls();
1296 if (b->isChecked() && list.count() == 1) {
1297 // Check for image sequence
1298 KUrl url = list.at(0);
1299 QString fileName = url.fileName().section('.', 0, -2);
1300 if (fileName.at(fileName.size() - 1).isDigit()) {
1301 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1302 if (item.mimetype().startsWith("image")) {
1303 // import as sequence if we found more than one image in the sequence
1305 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1306 int count = list.count();
1309 QStringList groupInfo = getGroup();
1311 // get image sequence base name
1312 while (fileName.at(fileName.size() - 1).isDigit()) {
1316 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1317 false, false, false,
1318 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1319 QString(), groupInfo.at(0), groupInfo.at(1));
1327 for (int i = 0; i < givenList.count(); i++)
1328 list << givenList.at(i);
1331 foreach(const KUrl & file, list) {
1332 // Check there is no folder here
1333 KMimeType::Ptr type = KMimeType::findByUrl(file);
1334 if (type->is("inode/directory")) {
1335 // user dropped a folder
1336 list.removeAll(file);
1343 if (givenList.isEmpty()) {
1344 QStringList groupInfo = getGroup();
1345 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1347 m_doc->slotAddClipList(list, groupName, groupId);
1351 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1353 ProjectItem *item = getItemById(id);
1354 m_processingClips.removeAll(id);
1355 m_thumbnailQueue.removeAll(id);
1356 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1358 const QString path = item->referencedClip()->fileURL().path();
1359 if (item->referencedClip()->isPlaceHolder()) replace = false;
1360 if (!path.isEmpty()) {
1362 KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1363 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)
1367 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1371 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1373 ProjectItem *item = getItemById(id);
1375 if (durationError) {
1376 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1377 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1379 item->setProxyStatus(PROXYCRASHED);
1380 QString path = item->referencedClip()->getProperty("proxy");
1381 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1383 //Security check: make sure the invalid proxy file is in the proxy folder
1384 if (proxyFolder.isParentOf(KUrl(path))) {
1385 QFile::remove(path);
1388 m_processingClips.removeAll(id);
1389 m_thumbnailQueue.removeAll(id);
1390 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1393 void ProjectList::slotAddColorClip()
1395 if (!m_commandStack)
1396 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1398 QDialog *dia = new QDialog(this);
1399 Ui::ColorClip_UI dia_ui;
1400 dia_ui.setupUi(dia);
1401 dia->setWindowTitle(i18n("Color Clip"));
1402 dia_ui.clip_name->setText(i18n("Color Clip"));
1404 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1405 t->setValue(KdenliveSettings::color_duration());
1406 t->setTimeCodeFormat(false);
1407 dia_ui.clip_durationBox->addWidget(t);
1408 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1410 if (dia->exec() == QDialog::Accepted) {
1411 QString color = dia_ui.clip_color->color().name();
1412 KdenliveSettings::setColorclipcolor(color);
1413 color = color.replace(0, 1, "0x") + "ff";
1414 QStringList groupInfo = getGroup();
1415 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1422 void ProjectList::slotAddSlideshowClip()
1424 if (!m_commandStack)
1425 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1427 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1429 if (dia->exec() == QDialog::Accepted) {
1430 QStringList groupInfo = getGroup();
1431 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1432 dia->loop(), dia->crop(), dia->fade(),
1433 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1434 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1439 void ProjectList::slotAddTitleClip()
1441 QStringList groupInfo = getGroup();
1442 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1445 void ProjectList::slotAddTitleTemplateClip()
1447 if (!m_commandStack)
1448 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1450 QStringList groupInfo = getGroup();
1452 // Get the list of existing templates
1454 filter << "*.kdenlivetitle";
1455 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1456 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1458 QDialog *dia = new QDialog(this);
1459 Ui::TemplateClip_UI dia_ui;
1460 dia_ui.setupUi(dia);
1461 for (int i = 0; i < templateFiles.size(); ++i)
1462 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1464 if (!templateFiles.isEmpty())
1465 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1466 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1467 //warning: setting base directory doesn't work??
1468 KUrl startDir(path);
1469 dia_ui.template_list->fileDialog()->setUrl(startDir);
1470 dia_ui.text_box->setHidden(true);
1471 if (dia->exec() == QDialog::Accepted) {
1472 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1473 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1474 // Create a cloned template clip
1475 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1480 QStringList ProjectList::getGroup() const
1483 QTreeWidgetItem *item = m_listView->currentItem();
1484 while (item && item->type() != PROJECTFOLDERTYPE)
1485 item = item->parent();
1488 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1489 result << folder->groupName() << folder->clipId();
1491 result << QString() << QString();
1496 void ProjectList::setDocument(KdenliveDoc *doc)
1498 m_listView->blockSignals(true);
1499 m_listView->clear();
1500 m_processingClips.clear();
1501 m_listView->setSortingEnabled(false);
1502 emit clipSelected(NULL);
1503 m_thumbnailQueue.clear();
1504 m_infoQueue.clear();
1505 m_refreshed = false;
1507 m_timecode = doc->timecode();
1508 m_commandStack = doc->commandStack();
1511 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1512 QStringList openedFolders = doc->getExpandedFolders();
1513 QMapIterator<QString, QString> f(flist);
1514 while (f.hasNext()) {
1516 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1517 folder->setExpanded(openedFolders.contains(f.key()));
1520 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1521 for (int i = 0; i < list.count(); i++)
1522 slotAddClip(list.at(i), false);
1524 m_listView->blockSignals(false);
1525 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1526 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1527 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1528 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1529 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool)), this, SLOT(updateAllClips(bool, bool)));
1532 QList <DocClipBase*> ProjectList::documentClipList() const
1535 return QList <DocClipBase*> ();
1537 return m_doc->clipManager()->documentClipList();
1540 QDomElement ProjectList::producersList()
1543 QDomElement prods = doc.createElement("producerlist");
1544 doc.appendChild(prods);
1545 kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
1546 QTreeWidgetItemIterator it(m_listView);
1548 if ((*it)->type() != PROJECTCLIPTYPE) {
1553 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1559 void ProjectList::slotCheckForEmptyQueue()
1561 if (!m_refreshed && m_processingClips.isEmpty() && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1563 emit loadingIsOver();
1564 emit displayMessage(QString(), -1);
1565 m_listView->blockSignals(false);
1566 m_listView->setEnabled(true);
1568 } else if (!m_refreshed) {
1569 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1574 void ProjectList::requestClipThumbnail(const QString id)
1576 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1579 void ProjectList::slotProcessNextThumbnail()
1581 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1582 slotCheckForEmptyQueue();
1585 if (!m_infoQueue.isEmpty()) {
1586 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1589 if (m_thumbnailQueue.count() > 1) {
1590 int max = m_doc->clipManager()->clipsCount();
1591 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1593 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1596 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1598 QTreeWidgetItem *item = getAnyItemById(clipId);
1600 slotRefreshClipThumbnail(item, update);
1602 slotProcessNextThumbnail();
1606 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1608 if (it == NULL) return;
1609 ProjectItem *item = NULL;
1610 bool isSubItem = false;
1612 if (it->type() == PROJECTFOLDERTYPE) return;
1613 if (it->type() == PROJECTSUBCLIPTYPE) {
1614 item = static_cast <ProjectItem *>(it->parent());
1615 frame = static_cast <SubProjectItem *>(it)->zone().x();
1618 item = static_cast <ProjectItem *>(it);
1619 frame = item->referencedClip()->getClipThumbFrame();
1623 DocClipBase *clip = item->referencedClip();
1625 slotProcessNextThumbnail();
1629 int height = m_listView->iconSize().height();
1630 int width = (int)(height * m_render->dar());
1631 if (clip->clipType() == AUDIO)
1632 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1633 else if (clip->clipType() == IMAGE)
1634 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1636 pix = item->referencedClip()->extractImage(frame, width, height);
1638 if (!pix.isNull()) {
1639 monitorItemEditing(false);
1640 it->setData(0, Qt::DecorationRole, pix);
1641 monitorItemEditing(true);
1644 m_doc->cachePixmap(item->getClipHash(), pix);
1646 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1649 emit projectModified();
1650 slotProcessNextThumbnail();
1654 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace, bool selectClip)
1657 ProjectItem *item = getItemById(clipId);
1659 // we are still finishing to load the document
1662 m_processingClips.removeAll(clipId);
1663 if (m_infoQueue.isEmpty() && m_processingClips.isEmpty()) m_listView->setEnabled(true);
1664 if (item && producer) {
1665 //m_listView->blockSignals(true);
1666 monitorItemEditing(false);
1667 DocClipBase *clip = item->referencedClip();
1668 item->setProperties(properties, metadata);
1669 if (clip->isPlaceHolder() && producer->is_valid()) {
1671 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1674 clip->setProducer(producer, replace);
1675 clip->askForAudioThumbs();
1677 QString size = properties.value("frame_size");
1678 if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY);
1679 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY);
1680 else if (useProxy() && !item->isProxyRunning()) {
1681 // proxy video and image clips
1683 CLIPTYPE t = item->clipType();
1684 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
1685 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
1686 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)) {
1687 if (clip->getProperty("proxy").isEmpty()) {
1688 KUrl proxyPath = m_doc->projectFolder();
1689 proxyPath.addPath("proxy/");
1690 proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
1691 QMap <QString, QString> newProps;
1692 // insert required duration for proxy
1693 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
1694 newProps.insert("proxy", proxyPath.path());
1695 QMap <QString, QString> oldProps = clip->properties();
1696 oldProps.insert("proxy", QString());
1697 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
1698 m_doc->commandStack()->push(command);
1703 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1704 requestClipThumbnail(clipId);
1705 if (!toReload.isEmpty())
1706 item->slotSetToolTip();
1708 if (m_listView->isEnabled())
1709 monitorItemEditing(true);
1710 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1711 if (selectClip && m_infoQueue.isEmpty()) {
1712 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1713 m_listView->setCurrentItem(item);
1714 bool updatedProfile = false;
1715 if (item->parent()) {
1716 if (item->parent()->type() == PROJECTFOLDERTYPE)
1717 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1718 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) {
1719 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1720 updatedProfile = adjustProjectProfileToItem(item);
1722 if (updatedProfile == false) emit clipSelected(item->referencedClip());
1724 int max = m_doc->clipManager()->clipsCount();
1725 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1728 if (item && m_listView->isEnabled() && replace) {
1729 // update clip in clip monitor
1730 if (item->isSelected() && m_listView->selectedItems().count() == 1)
1731 emit clipSelected(item->referencedClip());
1732 //TODO: Make sure the line below has no side effect
1735 if (!toReload.isEmpty())
1736 emit clipNeedsReload(toReload, true);
1738 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1741 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1744 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1745 item = static_cast <ProjectItem*>(m_listView->currentItem());
1747 if (item == NULL || item->referencedClip() == NULL) {
1748 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1751 bool profileUpdated = false;
1752 QString size = item->referencedClip()->getProperty("frame_size");
1753 int width = size.section('x', 0, 0).toInt();
1754 int height = size.section('x', -1).toInt();
1755 double fps = item->referencedClip()->getProperty("fps").toDouble();
1756 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1757 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1758 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1759 // get a list of compatible profiles
1760 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1761 if (!suggestedProfiles.isEmpty()) {
1762 KDialog *dialog = new KDialog(this);
1763 dialog->setCaption(i18n("Change project profile"));
1764 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1767 QVBoxLayout *l = new QVBoxLayout;
1768 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));
1769 l->addWidget(label);
1770 QListWidget *list = new QListWidget;
1771 list->setAlternatingRowColors(true);
1772 QMapIterator<QString, QString> i(suggestedProfiles);
1773 while (i.hasNext()) {
1775 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1776 item->setData(Qt::UserRole, i.key());
1777 item->setToolTip(i.key());
1779 list->setCurrentRow(0);
1781 container.setLayout(l);
1782 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1783 dialog->setMainWidget(&container);
1784 if (dialog->exec() == QDialog::Accepted) {
1785 //Change project profile
1786 profileUpdated = true;
1787 if (list->currentItem())
1788 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1792 } else if (fps > 0) {
1793 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));
1797 return profileUpdated;
1800 QString ProjectList::getDocumentProperty(const QString &key) const
1802 return m_doc->getDocumentProperty(key);
1805 bool ProjectList::useProxy() const
1807 return m_doc->getDocumentProperty("enableproxy").toInt();
1810 bool ProjectList::generateProxy() const
1812 return m_doc->getDocumentProperty("generateproxy").toInt();
1815 bool ProjectList::generateImageProxy() const
1817 return m_doc->getDocumentProperty("generateimageproxy").toInt();
1820 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1822 ProjectItem *item = getItemById(clipId);
1823 if (item && !pix.isNull()) {
1824 monitorItemEditing(false);
1825 item->setData(0, Qt::DecorationRole, pix);
1826 monitorItemEditing(true);
1827 m_doc->cachePixmap(item->getClipHash(), pix);
1828 if (m_listView->isEnabled())
1829 m_listView->blockSignals(false);
1833 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1835 QTreeWidgetItemIterator it(m_listView);
1836 QString lookId = id;
1837 if (id.contains('#'))
1838 lookId = id.section('#', 0, 0);
1840 ProjectItem *result = NULL;
1842 if ((*it)->type() != PROJECTCLIPTYPE) {
1847 ProjectItem *item = static_cast<ProjectItem *>(*it);
1848 if (item->clipId() == lookId) {
1854 if (result == NULL || !id.contains('#')) {
1857 for (int i = 0; i < result->childCount(); i++) {
1858 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1859 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1868 ProjectItem *ProjectList::getItemById(const QString &id)
1871 QTreeWidgetItemIterator it(m_listView);
1873 if ((*it)->type() != PROJECTCLIPTYPE) {
1874 // subitem or folder
1878 item = static_cast<ProjectItem *>(*it);
1879 if (item->clipId() == id)
1886 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1888 FolderProjectItem *item;
1889 QTreeWidgetItemIterator it(m_listView);
1891 if ((*it)->type() == PROJECTFOLDERTYPE) {
1892 item = static_cast<FolderProjectItem *>(*it);
1893 if (item->clipId() == id)
1901 void ProjectList::slotSelectClip(const QString &ix)
1903 ProjectItem *clip = getItemById(ix);
1905 m_listView->setCurrentItem(clip);
1906 m_listView->scrollToItem(clip);
1907 m_editButton->defaultAction()->setEnabled(true);
1908 m_deleteButton->defaultAction()->setEnabled(true);
1909 m_reloadAction->setEnabled(true);
1910 m_transcodeAction->setEnabled(true);
1911 m_proxyAction->setEnabled(useProxy());
1912 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1913 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1914 m_openAction->setEnabled(true);
1915 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1916 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1917 m_openAction->setEnabled(true);
1919 m_openAction->setEnabled(false);
1924 QString ProjectList::currentClipUrl() const
1927 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1928 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1930 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1932 item = static_cast <ProjectItem*>(m_listView->currentItem());
1936 return item->clipUrl().path();
1939 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1943 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1944 for (int i = 0; i < list.count(); i++) {
1945 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1947 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1949 item = static_cast <ProjectItem*>(list.at(i)->parent());
1951 item = static_cast <ProjectItem*>(list.at(i));
1953 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1955 DocClipBase *clip = item->referencedClip();
1956 if (!condition.isEmpty()) {
1957 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1959 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1962 result.append(item->clipUrl());
1967 void ProjectList::regenerateTemplate(const QString &id)
1969 ProjectItem *clip = getItemById(id);
1971 regenerateTemplate(clip);
1974 void ProjectList::regenerateTemplate(ProjectItem *clip)
1976 //TODO: remove this unused method, only force_reload is necessary
1977 clip->referencedClip()->producer()->set("force_reload", 1);
1980 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1984 if (!file.open(QIODevice::ReadOnly)) {
1985 kWarning() << "ERROR, CANNOT READ: " << path;
1988 if (!doc.setContent(&file)) {
1989 kWarning() << "ERROR, CANNOT READ: " << path;
1994 QDomNodeList texts = doc.elementsByTagName("content");
1995 for (int i = 0; i < texts.count(); i++) {
1996 QString data = texts.item(i).firstChild().nodeValue();
1997 data.replace("%s", replaceString);
1998 texts.item(i).firstChild().setNodeValue(data);
2004 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2006 ProjectItem *clip = getItemById(id);
2007 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2009 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2010 m_commandStack->push(command);
2013 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2015 ProjectItem *clip = getItemById(id);
2017 DocClipBase *base = clip->referencedClip();
2018 base->addCutZone(in, out);
2019 monitorItemEditing(false);
2020 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2021 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2022 if (!clip->isExpanded())
2023 clip->setExpanded(true);
2024 m_listView->scrollToItem(sub);
2025 m_listView->editItem(sub, 1);
2027 QPixmap p = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
2028 sub->setData(0, Qt::DecorationRole, p);
2029 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
2030 monitorItemEditing(true);
2032 emit projectModified();
2035 void ProjectList::removeClipCut(const QString &id, int in, int out)
2037 ProjectItem *clip = getItemById(id);
2039 DocClipBase *base = clip->referencedClip();
2040 base->removeCutZone(in, out);
2041 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2043 monitorItemEditing(false);
2045 monitorItemEditing(true);
2048 emit projectModified();
2051 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2053 SubProjectItem *sub = NULL;
2055 for (int i = 0; i < clip->childCount(); i++) {
2056 QTreeWidgetItem *it = clip->child(i);
2057 if (it->type() == PROJECTSUBCLIPTYPE) {
2058 sub = static_cast <SubProjectItem*>(it);
2059 if (sub->zone() == zone)
2069 void ProjectList::slotUpdateClipCut(QPoint p)
2071 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2073 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2074 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2075 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2076 m_commandStack->push(command);
2079 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2081 ProjectItem *clip = getItemById(id);
2082 SubProjectItem *sub = getSubItem(clip, oldzone);
2083 if (sub == NULL || clip == NULL)
2085 DocClipBase *base = clip->referencedClip();
2086 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2087 monitorItemEditing(false);
2089 sub->setDescription(comment);
2090 monitorItemEditing(true);
2091 emit projectModified();
2094 void ProjectList::slotForceProcessing(const QString &id)
2096 while (m_infoQueue.contains(id)) {
2097 slotProcessNextClipInQueue();
2101 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2103 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2105 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2106 int count = list.count();
2108 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2109 if (!existing.isEmpty()) {
2110 // Sequence already exists, update
2111 QString id = existing.at(0)->getId();
2112 //ProjectItem *item = getItemById(id);
2113 QMap <QString, QString> oldprops;
2114 QMap <QString, QString> newprops;
2115 int ttl = existing.at(0)->getProperty("ttl").toInt();
2116 oldprops["out"] = existing.at(0)->getProperty("out");
2117 newprops["out"] = QString::number(ttl * count - 1);
2118 slotUpdateClipProperties(id, newprops);
2119 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2120 m_commandStack->push(command);
2123 QStringList groupInfo = getGroup();
2124 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
2125 false, false, false,
2126 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
2127 QString(), groupInfo.at(0), groupInfo.at(1));
2129 } else emit displayMessage(i18n("Sequence not found"), -2);
2132 QMap <QString, QString> ProjectList::getProxies()
2134 QMap <QString, QString> list;
2136 QTreeWidgetItemIterator it(m_listView);
2138 if ((*it)->type() != PROJECTCLIPTYPE) {
2142 item = static_cast<ProjectItem *>(*it);
2143 if (item && item->referencedClip() != NULL) {
2144 if (item->hasProxy()) {
2145 QString proxy = item->referencedClip()->getProperty("proxy");
2146 list.insert(proxy, item->clipUrl().path());
2154 void ProjectList::slotCreateProxy(const QString id)
2156 ProjectItem *item = getItemById(id);
2157 if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
2158 QString path = item->referencedClip()->getProperty("proxy");
2159 if (path.isEmpty()) {
2160 setProxyStatus(path, PROXYCRASHED);
2163 setProxyStatus(path, PROXYWAITING);
2164 if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
2165 if (m_processingProxy.contains(path)) {
2166 // Proxy is already being generated
2169 if (QFile::exists(path)) {
2170 // Proxy already created
2171 setProxyStatus(path, PROXYDONE);
2175 m_processingProxy.append(path);
2176 QtConcurrent::run(this, &ProjectList::slotGenerateProxy, path, item->clipUrl().path(), item->clipType(), QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt());
2179 void ProjectList::slotAbortProxy(const QString id, const QString path)
2181 QTreeWidgetItemIterator it(m_listView);
2182 ProjectItem *item = getItemById(id);
2183 setProxyStatus(item, NOPROXY);
2185 if (!path.isEmpty() && m_processingProxy.contains(path)) {
2186 m_abortProxy << path;
2187 setProxyStatus(path, NOPROXY);
2191 void ProjectList::slotGenerateProxy(const QString destPath, const QString sourcePath, int clipType, int exif_orientation)
2193 emit projectModified();
2194 // Make sure proxy path is writable
2195 QFile file(destPath);
2196 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
2197 setProxyStatus(destPath, PROXYCRASHED);
2201 QFile::remove(destPath);
2203 setProxyStatus(destPath, CREATINGPROXY);
2205 // Special case: playlist clips (.mlt or .kdenlive project files)
2206 if (clipType == PLAYLIST) {
2207 // change FFmpeg params to MLT format
2208 QStringList parameters;
2209 parameters << sourcePath;
2210 parameters << "-consumer" << "avformat:" + destPath;
2211 QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts);
2213 foreach(QString s, params) {
2215 if (s.count(' ') == 0) {
2218 else s.replace(' ', '=');
2222 parameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads()));
2224 //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
2225 double display_ratio = KdenliveDoc::getDisplayRatio(sourcePath);
2226 parameters << "aspect=" + QString::number(display_ratio);
2228 //kDebug()<<"TRANSCOD: "<<parameters;
2230 myProcess.start(KdenliveSettings::rendererpath(), parameters);
2231 myProcess.waitForStarted();
2233 while (myProcess.state() != QProcess::NotRunning) {
2234 // building proxy file
2235 if (m_abortProxy.contains(destPath)) {
2237 myProcess.waitForFinished();
2238 m_abortProxy.removeAll(destPath);
2239 m_processingProxy.removeAll(destPath);
2240 QFile::remove(destPath);
2241 setProxyStatus(destPath, NOPROXY);
2245 myProcess.waitForFinished(500);
2247 myProcess.waitForFinished();
2248 m_processingProxy.removeAll(destPath);
2249 if (result == -1) result = myProcess.exitStatus();
2251 // proxy successfully created
2252 setProxyStatus(destPath, PROXYDONE);
2253 slotGotProxy(destPath);
2255 else if (result == 1) {
2256 // Proxy process crashed
2257 QFile::remove(destPath);
2258 setProxyStatus(destPath, PROXYCRASHED);
2263 if (clipType == IMAGE) {
2265 QImage i(sourcePath);
2267 // Cannot load image
2268 setProxyStatus(destPath, PROXYCRASHED);
2272 // Images are scaled to profile size.
2273 //TODO: Make it be configurable?
2274 if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth());
2275 else proxy = i.scaledToHeight(m_render->renderHeight());
2276 if (exif_orientation > 1) {
2277 // Rotate image according to exif data
2281 switch ( exif_orientation ) {
2283 matrix.scale( -1, 1 );
2286 matrix.rotate( 180 );
2289 matrix.scale( 1, -1 );
2292 matrix.rotate( 270 );
2293 matrix.scale( -1, 1 );
2296 matrix.rotate( 90 );
2299 matrix.rotate( 90 );
2300 matrix.scale( -1, 1 );
2303 matrix.rotate( 270 );
2306 processed = proxy.transformed( matrix );
2307 processed.save(destPath);
2309 else proxy.save(destPath);
2310 setProxyStatus(destPath, PROXYDONE);
2311 slotGotProxy(destPath);
2312 m_abortProxy.removeAll(destPath);
2313 m_processingProxy.removeAll(destPath);
2317 QStringList parameters;
2318 parameters << "-i" << sourcePath;
2319 QString params = m_doc->getDocumentProperty("proxyparams").simplified();
2320 foreach(QString s, params.split(' '))
2323 // Make sure we don't block when proxy file already exists
2325 parameters << destPath;
2326 kDebug()<<"// STARTING PROXY GEN: "<<parameters;
2328 myProcess.start("ffmpeg", parameters);
2329 myProcess.waitForStarted();
2331 while (myProcess.state() != QProcess::NotRunning) {
2332 // building proxy file
2333 if (m_abortProxy.contains(destPath)) {
2335 myProcess.waitForFinished();
2336 m_abortProxy.removeAll(destPath);
2337 m_processingProxy.removeAll(destPath);
2338 QFile::remove(destPath);
2339 setProxyStatus(destPath, NOPROXY);
2343 myProcess.waitForFinished(500);
2345 myProcess.waitForFinished();
2346 if (result == -1) result = myProcess.exitStatus();
2348 // proxy successfully created
2349 setProxyStatus(destPath, PROXYDONE);
2350 slotGotProxy(destPath);
2352 else if (result == 1) {
2353 // Proxy process crashed
2354 QFile::remove(destPath);
2355 setProxyStatus(destPath, PROXYCRASHED);
2357 m_abortProxy.removeAll(destPath);
2358 m_processingProxy.removeAll(destPath);
2361 void ProjectList::updateProxyConfig()
2364 QTreeWidgetItemIterator it(m_listView);
2365 QUndoCommand *command = new QUndoCommand();
2366 command->setText(i18n("Update proxy settings"));
2367 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2369 if ((*it)->type() != PROJECTCLIPTYPE) {
2373 item = static_cast<ProjectItem *>(*it);
2378 CLIPTYPE t = item->clipType();
2379 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2380 if (generateProxy() && useProxy() && !item->isProxyRunning()) {
2381 DocClipBase *clip = item->referencedClip();
2382 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
2383 if (clip->getProperty("proxy").isEmpty()) {
2384 // We need to insert empty proxy in old properties so that undo will work
2385 QMap <QString, QString> oldProps;// = clip->properties();
2386 oldProps.insert("proxy", QString());
2387 QMap <QString, QString> newProps;
2388 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
2389 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2393 else if (item->hasProxy()) {
2395 QMap <QString, QString> newProps;
2396 newProps.insert("proxy", QString());
2397 newProps.insert("replace", "1");
2398 // insert required duration for proxy
2399 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2400 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2403 else if (t == IMAGE && item->referencedClip() != NULL) {
2404 if (generateImageProxy() && useProxy()) {
2405 DocClipBase *clip = item->referencedClip();
2406 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2407 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
2408 if (clip->getProperty("proxy").isEmpty()) {
2409 // We need to insert empty proxy in old properties so that undo will work
2410 QMap <QString, QString> oldProps = clip->properties();
2411 oldProps.insert("proxy", QString());
2412 QMap <QString, QString> newProps;
2413 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
2414 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2418 else if (item->hasProxy()) {
2420 QMap <QString, QString> newProps;
2421 newProps.insert("proxy", QString());
2422 newProps.insert("replace", "1");
2423 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2428 if (command->childCount() > 0) m_doc->commandStack()->push(command);
2429 else delete command;
2430 if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
2433 void ProjectList::slotProxyCurrentItem(bool doProxy)
2435 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2436 QTreeWidgetItem *listItem;
2437 QUndoCommand *command = new QUndoCommand();
2438 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", list.count()));
2439 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", list.count()));
2441 // Make sure the proxy folder exists
2442 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2443 KStandardDirs::makeDir(proxydir);
2445 QMap <QString, QString> newProps;
2446 QMap <QString, QString> oldProps;
2447 if (!doProxy) newProps.insert("proxy", "-");
2448 for (int i = 0; i < list.count(); i++) {
2449 listItem = list.at(i);
2450 if (listItem->type() == PROJECTFOLDERTYPE) {
2451 for (int j = 0; j < listItem->childCount(); j++) {
2452 QTreeWidgetItem *sub = listItem->child(j);
2453 if (!list.contains(sub)) list.append(sub);
2456 if (listItem->type() == PROJECTCLIPTYPE) {
2457 ProjectItem *item = static_cast <ProjectItem*>(listItem);
2458 CLIPTYPE t = item->clipType();
2459 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
2460 oldProps = item->referencedClip()->properties();
2463 QString path = proxydir + item->referencedClip()->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
2464 // insert required duration for proxy
2465 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2466 newProps.insert("proxy", path);
2467 // We need to insert empty proxy so that undo will work
2468 oldProps.insert("proxy", QString());
2470 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
2474 if (command->childCount() > 0) {
2475 m_doc->commandStack()->push(command);
2477 else delete command;
2478 //if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
2482 void ProjectList::slotDeleteProxy(const QString proxyPath)
2484 if (proxyPath.isEmpty()) return;
2485 QUndoCommand *proxyCommand = new QUndoCommand();
2486 proxyCommand->setText(i18n("Remove Proxy"));
2487 QTreeWidgetItemIterator it(m_listView);
2490 if ((*it)->type() == PROJECTCLIPTYPE) {
2491 item = static_cast <ProjectItem *>(*it);
2492 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
2493 QMap <QString, QString> props;
2494 props.insert("proxy", QString());
2495 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), props, true, proxyCommand);
2501 if (proxyCommand->childCount() == 0)
2502 delete proxyCommand;
2504 m_commandStack->push(proxyCommand);
2505 QFile::remove(proxyPath);
2508 void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status)
2510 if (proxyPath.isEmpty()) return;
2511 QTreeWidgetItemIterator it(m_listView);
2514 if ((*it)->type() == PROJECTCLIPTYPE) {
2515 item = static_cast <ProjectItem *>(*it);
2516 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
2517 setProxyStatus(item, status);
2524 void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status)
2526 if (item == NULL) return;
2527 monitorItemEditing(false);
2528 item->setProxyStatus(status);
2529 monitorItemEditing(true);
2532 void ProjectList::monitorItemEditing(bool enable)
2534 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2535 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2538 QStringList ProjectList::expandedFolders() const
2541 FolderProjectItem *item;
2542 QTreeWidgetItemIterator it(m_listView);
2544 if ((*it)->type() != PROJECTFOLDERTYPE) {
2548 if ((*it)->isExpanded()) {
2549 item = static_cast<FolderProjectItem *>(*it);
2550 result.append(item->clipId());
2557 #include "projectlist.moc"