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 "commands/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 "commands/editclipcommand.h"
37 #include "commands/editclipcutcommand.h"
38 #include "commands/editfoldercommand.h"
39 #include "commands/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>
69 #include <QVBoxLayout>
71 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
74 if (infoOnly) setButtons(KDialog::Ok);
75 else setButtons(KDialog::Yes | KDialog::No);
76 QWidget *w = new QWidget(this);
77 QVBoxLayout *l = new QVBoxLayout;
78 l->addWidget(new QLabel(message));
79 m_clipList = new QListWidget;
80 l->addWidget(m_clipList);
85 InvalidDialog::~InvalidDialog()
91 void InvalidDialog::addClip(const QString &id, const QString &path)
93 QListWidgetItem *item = new QListWidgetItem(path);
94 item->setData(Qt::UserRole, id);
95 m_clipList->addItem(item);
98 QStringList InvalidDialog::getIds() const
101 for (int i = 0; i < m_clipList->count(); i++) {
102 ids << m_clipList->item(i)->data(Qt::UserRole).toString();
108 ProjectList::ProjectList(QWidget *parent) :
112 m_commandStack(NULL),
114 m_reloadAction(NULL),
115 m_stabilizeAction(NULL),
116 m_transcodeAction(NULL),
119 m_allClipsProcessed(false),
121 m_abortAllProxies(false),
122 m_invalidClipDialog(NULL)
124 QVBoxLayout *layout = new QVBoxLayout;
125 layout->setContentsMargins(0, 0, 0, 0);
126 layout->setSpacing(0);
127 qRegisterMetaType<QDomElement>("QDomElement");
129 QFrame *frame = new QFrame;
130 frame->setFrameStyle(QFrame::NoFrame);
131 QHBoxLayout *box = new QHBoxLayout;
132 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
133 box->addWidget(searchView);
135 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
136 QSize iconSize(size, size);
138 m_addButton = new QToolButton;
139 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
140 m_addButton->setAutoRaise(true);
141 m_addButton->setIconSize(iconSize);
142 box->addWidget(m_addButton);
144 m_editButton = new QToolButton;
145 m_editButton->setAutoRaise(true);
146 m_editButton->setIconSize(iconSize);
147 box->addWidget(m_editButton);
149 m_deleteButton = new QToolButton;
150 m_deleteButton->setAutoRaise(true);
151 m_deleteButton->setIconSize(iconSize);
152 box->addWidget(m_deleteButton);
153 frame->setLayout(box);
154 layout->addWidget(frame);
156 m_listView = new ProjectListView;
157 layout->addWidget(m_listView);
159 searchView->setTreeWidget(m_listView);
161 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
162 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
163 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
164 connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
165 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
166 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
167 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
168 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
169 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
170 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
171 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
173 m_listViewDelegate = new ItemDelegate(m_listView);
174 m_listView->setItemDelegate(m_listViewDelegate);
176 if (KdenliveSettings::activate_nepomuk()) {
177 Nepomuk::ResourceManager::instance()->init();
178 if (!Nepomuk::ResourceManager::instance()->initialized()) {
179 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
180 KdenliveSettings::setActivate_nepomuk(false);
186 ProjectList::~ProjectList()
188 m_abortAllProxies = true;
189 m_thumbnailQueue.clear();
191 m_listView->blockSignals(true);
193 delete m_listViewDelegate;
196 void ProjectList::focusTree() const
198 m_listView->setFocus();
201 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
203 QList <QAction *> actions = addMenu->actions();
204 for (int i = 0; i < actions.count(); i++) {
205 if (actions.at(i)->data().toString() == "clip_properties") {
206 m_editButton->setDefaultAction(actions.at(i));
209 } else if (actions.at(i)->data().toString() == "delete_clip") {
210 m_deleteButton->setDefaultAction(actions.at(i));
213 } else if (actions.at(i)->data().toString() == "edit_clip") {
214 m_openAction = actions.at(i);
217 } else if (actions.at(i)->data().toString() == "reload_clip") {
218 m_reloadAction = actions.at(i);
221 } else if (actions.at(i)->data().toString() == "proxy_clip") {
222 m_proxyAction = actions.at(i);
228 QMenu *m = new QMenu();
229 m->addActions(actions);
230 m_addButton->setMenu(m);
231 m_addButton->setDefaultAction(defaultAction);
232 m_menu = new QMenu();
233 m_menu->addActions(addMenu->actions());
236 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
238 if (!menus.contains("addMenu") && ! menus.value("addMenu") )
240 QMenu *menu = m_addButton->menu();
241 if (menus.contains("addMenu") && menus.value("addMenu")){
242 QMenu* addMenu=menus.value("addMenu");
243 menu->addMenu(addMenu);
244 m_addButton->setMenu(menu);
246 m_menu->addMenu(addMenu);
247 if (addMenu->isEmpty())
248 addMenu->setEnabled(false);
250 if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
251 QMenu* transcodeMenu=menus.value("transcodeMenu");
252 m_menu->addMenu(transcodeMenu);
253 if (transcodeMenu->isEmpty())
254 transcodeMenu->setEnabled(false);
255 m_transcodeAction = transcodeMenu;
257 if (menus.contains("stabilizeMenu") && menus.value("stabilizeMenu") ){
258 QMenu* stabilizeMenu=menus.value("stabilizeMenu");
259 m_menu->addMenu(stabilizeMenu);
260 if (stabilizeMenu->isEmpty())
261 stabilizeMenu->setEnabled(false);
262 m_stabilizeAction=stabilizeMenu;
265 m_menu->addAction(m_reloadAction);
266 m_menu->addAction(m_proxyAction);
267 if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
268 QMenu* inTimelineMenu=menus.value("inTimelineMenu");
269 m_menu->addMenu(inTimelineMenu);
270 inTimelineMenu->setEnabled(false);
272 m_menu->addAction(m_editButton->defaultAction());
273 m_menu->addAction(m_openAction);
274 m_menu->addAction(m_deleteButton->defaultAction());
275 m_menu->insertSeparator(m_deleteButton->defaultAction());
278 void ProjectList::clearSelection()
280 m_listView->clearSelection();
283 QByteArray ProjectList::headerInfo() const
285 return m_listView->header()->saveState();
288 void ProjectList::setHeaderInfo(const QByteArray &state)
290 m_listView->header()->restoreState(state);
293 void ProjectList::updateProjectFormat(Timecode t)
298 void ProjectList::slotEditClip()
300 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
301 if (list.isEmpty()) return;
302 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
303 editClipSelection(list);
307 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
309 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
310 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
312 item = static_cast <ProjectItem*>(m_listView->currentItem());
313 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
314 emit clipSelected(item->referencedClip());
315 emit showClipProperties(item->referencedClip());
319 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
321 // Gather all common properties
322 QMap <QString, QString> commonproperties;
323 QList <DocClipBase *> clipList;
324 commonproperties.insert("force_aspect_num", "-");
325 commonproperties.insert("force_aspect_den", "-");
326 commonproperties.insert("force_fps", "-");
327 commonproperties.insert("force_progressive", "-");
328 commonproperties.insert("force_tff", "-");
329 commonproperties.insert("threads", "-");
330 commonproperties.insert("video_index", "-");
331 commonproperties.insert("audio_index", "-");
332 commonproperties.insert("force_colorspace", "-");
333 commonproperties.insert("full_luma", "-");
334 QString transparency = "-";
336 bool allowDurationChange = true;
337 int commonDuration = -1;
338 bool hasImages = false;;
340 for (int i = 0; i < list.count(); i++) {
342 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
343 // Add folder items to the list
344 int ct = list.at(i)->childCount();
345 for (int j = 0; j < ct; j++) {
346 list.append(list.at(i)->child(j));
350 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
351 item = static_cast <ProjectItem*>(list.at(i)->parent());
353 item = static_cast <ProjectItem*>(list.at(i));
354 if (!(item->flags() & Qt::ItemIsDragEnabled))
358 DocClipBase *clip = item->referencedClip();
359 if (clipList.contains(clip)) continue;
360 if (clip->clipType() == IMAGE) {
362 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
363 if (transparency == "-") {
364 // first non transparent image
367 else if (transparency == "1") {
368 // we have transparent and non transparent clips
373 if (transparency == "-") {
374 // first transparent image
377 else if (transparency == "0") {
378 // we have transparent and non transparent clips
383 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
384 allowDurationChange = false;
385 if (allowDurationChange && commonDuration != 0) {
386 if (commonDuration == -1)
387 commonDuration = clip->duration().frames(m_fps);
388 else if (commonDuration != clip->duration().frames(m_fps))
391 clipList.append(clip);
392 QMap <QString, QString> clipprops = clip->properties();
393 QMapIterator<QString, QString> p(commonproperties);
394 while (p.hasNext()) {
396 if (p.value().isEmpty()) continue;
397 if (clipprops.contains(p.key())) {
398 if (p.value() == "-")
399 commonproperties.insert(p.key(), clipprops.value(p.key()));
400 else if (p.value() != clipprops.value(p.key()))
401 commonproperties.insert(p.key(), QString());
403 commonproperties.insert(p.key(), QString());
408 if (allowDurationChange)
409 commonproperties.insert("out", QString::number(commonDuration));
411 commonproperties.insert("transparency", transparency);
412 /*QMapIterator<QString, QString> p(commonproperties);
413 while (p.hasNext()) {
415 kDebug() << "Result: " << p.key() << " = " << p.value();
417 emit showClipProperties(clipList, commonproperties);
420 void ProjectList::slotOpenClip()
423 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
425 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
426 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
428 item = static_cast <ProjectItem*>(m_listView->currentItem());
430 if (item->clipType() == IMAGE) {
431 if (KdenliveSettings::defaultimageapp().isEmpty())
432 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
434 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
436 if (item->clipType() == AUDIO) {
437 if (KdenliveSettings::defaultaudioapp().isEmpty())
438 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
440 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
445 void ProjectList::cleanup()
447 m_listView->clearSelection();
448 QTreeWidgetItemIterator it(m_listView);
451 if ((*it)->type() != PROJECTCLIPTYPE) {
455 item = static_cast <ProjectItem *>(*it);
456 if (item->numReferences() == 0)
457 item->setSelected(true);
463 void ProjectList::trashUnusedClips()
465 QTreeWidgetItemIterator it(m_listView);
470 if ((*it)->type() != PROJECTCLIPTYPE) {
474 item = static_cast <ProjectItem *>(*it);
475 if (item->numReferences() == 0) {
476 ids << item->clipId();
477 KUrl url = item->clipUrl();
478 if (!url.isEmpty() && !urls.contains(url.path()))
484 // Check that we don't use the URL in another clip
485 QTreeWidgetItemIterator it2(m_listView);
487 if ((*it2)->type() != PROJECTCLIPTYPE) {
491 item = static_cast <ProjectItem *>(*it2);
492 if (item->numReferences() > 0) {
493 KUrl url = item->clipUrl();
494 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
499 emit deleteProjectClips(ids, QMap <QString, QString>());
500 for (int i = 0; i < urls.count(); i++)
501 KIO::NetAccess::del(KUrl(urls.at(i)), this);
504 void ProjectList::slotReloadClip(const QString &id)
506 QList<QTreeWidgetItem *> selected;
508 selected = m_listView->selectedItems();
510 ProjectItem *itemToReLoad = getItemById(id);
511 if (itemToReLoad) selected.append(itemToReLoad);
514 for (int i = 0; i < selected.count(); i++) {
515 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
516 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
517 for (int j = 0; j < selected.at(i)->childCount(); j++)
518 selected.append(selected.at(i)->child(j));
522 item = static_cast <ProjectItem *>(selected.at(i));
523 if (item && !item->isProxyRunning()) {
524 DocClipBase *clip = item->referencedClip();
525 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
526 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
529 CLIPTYPE t = item->clipType();
531 if (clip && !clip->getProperty("xmltemplate").isEmpty())
532 regenerateTemplate(item);
533 } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
534 item->referencedClip()->setPlaceHolder(true);
535 item->setProperty("file_hash", QString());
536 } else if (t == IMAGE) {
537 clip->getProducer()->set("force_reload", 1);
540 QDomElement e = item->toXml();
541 // Make sure we get the correct producer length if it was adjusted in timeline
542 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
543 int length = QString(clip->producerProperty("length")).toInt();
544 if (length > 0 && !e.hasAttribute("length")) {
545 e.setAttribute("length", length);
548 resetThumbsProducer(clip);
549 m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
554 void ProjectList::slotModifiedClip(const QString &id)
556 ProjectItem *item = getItemById(id);
558 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
559 if (!pixmap.isNull()) {
561 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
562 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
565 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
567 item->setData(0, Qt::DecorationRole, pixmap);
571 void ProjectList::slotMissingClip(const QString &id)
573 ProjectItem *item = getItemById(id);
575 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
576 int height = m_listView->iconSize().height();
577 int width = (int)(height * m_render->dar());
578 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
579 if (pixmap.isNull()) {
580 pixmap = QPixmap(width, height);
581 pixmap.fill(Qt::transparent);
583 KIcon icon("dialog-close");
585 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
587 item->setData(0, Qt::DecorationRole, pixmap);
588 if (item->referencedClip()) {
589 item->referencedClip()->setPlaceHolder(true);
590 if (m_render == NULL) {
591 kDebug() << "********* ERROR, NULL RENDR";
594 Mlt::Producer *newProd = m_render->invalidProducer(id);
595 if (item->referencedClip()->getProducer()) {
596 Mlt::Properties props(newProd->get_properties());
597 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
598 props.inherit(src_props);
600 item->referencedClip()->setProducer(newProd, true);
601 item->slotSetToolTip();
602 emit clipNeedsReload(id);
606 emit displayMessage(i18n("Check missing clips"), -2);
607 emit updateRenderStatus();
610 void ProjectList::slotAvailableClip(const QString &id)
612 ProjectItem *item = getItemById(id);
615 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
616 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
617 item->setProperty("file_hash", QString());
621 item->referencedClip()->setValid();
622 item->slotSetToolTip();
625 emit updateRenderStatus();
628 bool ProjectList::hasMissingClips()
630 bool missing = false;
631 QTreeWidgetItemIterator it(m_listView);
633 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
642 void ProjectList::setRenderer(Render *projectRender)
644 m_render = projectRender;
645 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
648 void ProjectList::slotClipSelected()
650 QTreeWidgetItem *item = m_listView->currentItem();
651 ProjectItem *clip = NULL;
653 if (item->type() == PROJECTFOLDERTYPE) {
654 emit clipSelected(NULL);
655 m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
656 m_deleteButton->defaultAction()->setEnabled(true);
657 m_openAction->setEnabled(false);
658 m_reloadAction->setEnabled(false);
659 m_transcodeAction->setEnabled(false);
660 m_stabilizeAction->setEnabled(false);
662 if (item->type() == PROJECTSUBCLIPTYPE) {
663 // this is a sub item, use base clip
664 m_deleteButton->defaultAction()->setEnabled(true);
665 clip = static_cast <ProjectItem*>(item->parent());
666 if (clip == NULL) kDebug() << "-----------ERROR";
667 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
668 emit clipSelected(clip->referencedClip(), sub->zone());
669 m_transcodeAction->setEnabled(false);
670 m_stabilizeAction->setEnabled(false);
671 m_reloadAction->setEnabled(false);
672 adjustProxyActions(clip);
675 clip = static_cast <ProjectItem*>(item);
676 if (clip && clip->referencedClip())
677 emit clipSelected(clip->referencedClip());
678 m_editButton->defaultAction()->setEnabled(true);
679 m_deleteButton->defaultAction()->setEnabled(true);
680 m_reloadAction->setEnabled(true);
681 m_transcodeAction->setEnabled(true);
682 m_stabilizeAction->setEnabled(true);
683 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
684 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
685 m_openAction->setEnabled(true);
686 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
687 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
688 m_openAction->setEnabled(true);
690 m_openAction->setEnabled(false);
692 // Display relevant transcoding actions only
693 adjustTranscodeActions(clip);
694 adjustStabilizeActions(clip);
695 // Display uses in timeline
696 emit findInTimeline(clip->clipId());
699 emit clipSelected(NULL);
700 m_editButton->defaultAction()->setEnabled(false);
701 m_deleteButton->defaultAction()->setEnabled(false);
702 m_openAction->setEnabled(false);
703 m_reloadAction->setEnabled(false);
704 m_transcodeAction->setEnabled(false);
705 m_stabilizeAction->setEnabled(false);
707 adjustProxyActions(clip);
710 void ProjectList::adjustProxyActions(ProjectItem *clip) const
712 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
713 m_proxyAction->setEnabled(false);
716 m_proxyAction->setEnabled(useProxy());
717 m_proxyAction->blockSignals(true);
718 m_proxyAction->setChecked(clip->hasProxy());
719 m_proxyAction->blockSignals(false);
722 void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
725 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
726 m_stabilizeAction->setEnabled(false);
729 m_stabilizeAction->setEnabled(true);
733 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
735 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
736 m_transcodeAction->setEnabled(false);
739 m_transcodeAction->setEnabled(true);
740 QList<QAction *> transcodeActions = m_transcodeAction->actions();
743 for (int i = 0; i < transcodeActions.count(); i++) {
744 data = transcodeActions.at(i)->data().toStringList();
745 if (data.count() > 2) {
746 condition = data.at(2);
747 if (condition.startsWith("vcodec"))
748 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
749 else if (condition.startsWith("acodec"))
750 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
756 void ProjectList::slotPauseMonitor()
762 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
764 ProjectItem *item = getItemById(id);
766 slotUpdateClipProperties(item, properties);
767 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
769 } else if (properties.contains("colour") ||
770 properties.contains("xmldata") ||
771 properties.contains("force_aspect_num") ||
772 properties.contains("force_aspect_den") ||
773 properties.contains("templatetext")) {
774 slotRefreshClipThumbnail(item);
775 emit refreshClip(id, true);
776 } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
777 emit refreshClip(id, false);
782 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
786 clip->setProperties(properties);
787 if (properties.contains("name")) {
788 monitorItemEditing(false);
789 clip->setText(0, properties.value("name"));
790 monitorItemEditing(true);
791 emit clipNameChanged(clip->clipId(), properties.value("name"));
793 if (properties.contains("description")) {
794 CLIPTYPE type = clip->clipType();
795 monitorItemEditing(false);
796 clip->setText(1, properties.value("description"));
797 monitorItemEditing(true);
799 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
800 // Use Nepomuk system to store clip description
801 Nepomuk::Resource f(clip->clipUrl().path());
802 f.setDescription(properties.value("description"));
805 emit projectModified();
809 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
811 if (item->type() == PROJECTSUBCLIPTYPE) {
812 // this is a sub-item
814 // user edited description
815 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
816 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
817 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
818 m_commandStack->push(command);
819 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
823 if (item->type() == PROJECTFOLDERTYPE) {
825 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
826 editFolder(item->text(0), folder->groupName(), folder->clipId());
827 folder->setGroupName(item->text(0));
828 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
829 const int children = item->childCount();
830 for (int i = 0; i < children; i++) {
831 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
832 child->setProperty("groupname", item->text(0));
838 ProjectItem *clip = static_cast <ProjectItem*>(item);
840 if (clip->referencedClip()) {
841 QMap <QString, QString> oldprops;
842 QMap <QString, QString> newprops;
843 oldprops["description"] = clip->referencedClip()->getProperty("description");
844 newprops["description"] = item->text(1);
846 if (clip->clipType() == TEXT) {
847 // This is a text template clip, update the image
848 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
849 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
850 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
851 newprops.insert("templatetext", item->text(1));
853 slotUpdateClipProperties(clip->clipId(), newprops);
854 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
855 m_commandStack->push(command);
857 } else if (column == 0) {
858 if (clip->referencedClip()) {
859 QMap <QString, QString> oldprops;
860 QMap <QString, QString> newprops;
861 oldprops["name"] = clip->referencedClip()->getProperty("name");
862 if (oldprops.value("name") != item->text(0)) {
863 newprops["name"] = item->text(0);
864 slotUpdateClipProperties(clip, newprops);
865 emit projectModified();
866 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
867 m_commandStack->push(command);
873 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
875 bool enable = item ? true : false;
876 m_editButton->defaultAction()->setEnabled(enable);
877 m_deleteButton->defaultAction()->setEnabled(enable);
878 m_reloadAction->setEnabled(enable);
879 m_transcodeAction->setEnabled(enable);
880 m_stabilizeAction->setEnabled(enable);
882 ProjectItem *clip = NULL;
883 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
884 clip = static_cast <ProjectItem*>(item->parent());
885 m_transcodeAction->setEnabled(false);
886 m_stabilizeAction->setEnabled(false);
887 adjustProxyActions(clip);
888 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
889 clip = static_cast <ProjectItem*>(item);
890 // Display relevant transcoding actions only
891 adjustTranscodeActions(clip);
892 adjustStabilizeActions(clip);
893 adjustProxyActions(clip);
894 // Display uses in timeline
895 emit findInTimeline(clip->clipId());
897 m_transcodeAction->setEnabled(false);
898 m_stabilizeAction->setEnabled(false);
900 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
901 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
902 m_openAction->setEnabled(true);
903 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
904 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
905 m_openAction->setEnabled(true);
907 m_openAction->setEnabled(false);
911 m_openAction->setEnabled(false);
916 void ProjectList::slotRemoveClip()
918 if (!m_listView->currentItem())
921 QMap <QString, QString> folderids;
922 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
924 QUndoCommand *delCommand = new QUndoCommand();
925 delCommand->setText(i18n("Delete Clip Zone"));
926 for (int i = 0; i < selected.count(); i++) {
927 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
929 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
930 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
931 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
932 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
934 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
935 folderids[folder->groupName()] = folder->clipId();
936 int children = folder->childCount();
938 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)
940 for (int i = 0; i < children; ++i) {
941 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
942 ids << child->clipId();
945 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
946 ids << item->clipId();
947 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) {
948 KMessageBox::enableMessage("DeleteAll");
953 KMessageBox::enableMessage("DeleteAll");
954 if (delCommand->childCount() == 0)
957 m_commandStack->push(delCommand);
958 emit deleteProjectClips(ids, folderids);
961 void ProjectList::updateButtons() const
963 if (m_listView->topLevelItemCount() == 0) {
964 m_deleteButton->defaultAction()->setEnabled(false);
965 m_editButton->defaultAction()->setEnabled(false);
967 m_deleteButton->defaultAction()->setEnabled(true);
968 if (!m_listView->currentItem())
969 m_listView->setCurrentItem(m_listView->topLevelItem(0));
970 QTreeWidgetItem *item = m_listView->currentItem();
971 if (item && item->type() == PROJECTCLIPTYPE) {
972 m_editButton->defaultAction()->setEnabled(true);
973 m_openAction->setEnabled(true);
974 m_reloadAction->setEnabled(true);
975 m_transcodeAction->setEnabled(true);
976 m_stabilizeAction->setEnabled(true);
979 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
980 m_editButton->defaultAction()->setEnabled(true);
982 else m_editButton->defaultAction()->setEnabled(false);
984 m_openAction->setEnabled(false);
985 m_reloadAction->setEnabled(false);
986 m_transcodeAction->setEnabled(false);
987 m_stabilizeAction->setEnabled(false);
988 m_proxyAction->setEnabled(false);
991 void ProjectList::selectItemById(const QString &clipId)
993 ProjectItem *item = getItemById(clipId);
995 m_listView->setCurrentItem(item);
999 void ProjectList::slotDeleteClip(const QString &clipId)
1001 ProjectItem *item = getItemById(clipId);
1003 kDebug() << "/// Cannot find clip to delete";
1006 if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
1007 m_listView->blockSignals(true);
1008 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1009 if (!newSelectedItem)
1010 newSelectedItem = m_listView->itemBelow(item);
1012 // Pause playing to prevent crash while deleting clip
1014 m_doc->clipManager()->deleteClip(clipId);
1015 m_listView->blockSignals(false);
1016 if (newSelectedItem) {
1017 m_listView->setCurrentItem(newSelectedItem);
1020 emit clipSelected(NULL);
1025 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1027 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1028 m_commandStack->push(command);
1029 m_doc->setModified(true);
1032 void ProjectList::slotAddFolder()
1034 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1035 m_commandStack->push(command);
1038 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
1041 FolderProjectItem *item = getFolderItemById(clipId);
1043 m_doc->clipManager()->deleteFolder(clipId);
1044 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1045 if (!newSelectedItem)
1046 newSelectedItem = m_listView->itemBelow(item);
1048 if (newSelectedItem)
1049 m_listView->setCurrentItem(newSelectedItem);
1055 FolderProjectItem *item = getFolderItemById(clipId);
1057 m_listView->blockSignals(true);
1058 item->setGroupName(foldername);
1059 m_listView->blockSignals(false);
1060 m_doc->clipManager()->addFolder(clipId, foldername);
1061 const int children = item->childCount();
1062 for (int i = 0; i < children; i++) {
1063 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1064 child->setProperty("groupname", foldername);
1068 m_listView->blockSignals(true);
1069 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1070 m_doc->clipManager()->addFolder(clipId, foldername);
1071 m_listView->blockSignals(false);
1072 m_listView->editItem(m_listView->currentItem(), 0);
1076 m_doc->setModified(true);
1081 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1083 QMapIterator<QString, QString> i(map);
1084 QUndoCommand *delCommand = new QUndoCommand();
1085 delCommand->setText(i18n("Delete Folder"));
1086 while (i.hasNext()) {
1088 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1090 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1091 else delete delCommand;
1094 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1096 //m_listView->setEnabled(false);
1097 const QString parent = clip->getProperty("groupid");
1098 ProjectItem *item = NULL;
1099 monitorItemEditing(false);
1100 if (!parent.isEmpty()) {
1101 FolderProjectItem *parentitem = getFolderItemById(parent);
1104 QString groupName = clip->getProperty("groupname");
1105 //kDebug() << "Adding clip to new group: " << groupName;
1106 if (groupName.isEmpty()) groupName = i18n("Folder");
1108 parentitem = new FolderProjectItem(m_listView, text, parent);
1112 item = new ProjectItem(parentitem, clip);
1115 item = new ProjectItem(m_listView, clip);
1117 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1118 QString proxy = clip->getProperty("proxy");
1119 if (!proxy.isEmpty() && proxy != "-") slotCreateProxy(clip->getId());
1120 connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1121 connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1122 if (getProperties) {
1123 int height = m_listView->iconSize().height();
1124 int width = (int)(height * m_render->dar());
1125 QPixmap pix = KIcon("video-x-generic").pixmap(QSize(width, height));
1126 item->setData(0, Qt::DecorationRole, pix);
1127 //item->setFlags(Qt::ItemIsSelectable);
1128 m_listView->processLayout();
1129 QDomElement e = clip->toXML().cloneNode().toElement();
1130 e.removeAttribute("file_hash");
1131 resetThumbsProducer(clip);
1132 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1134 else if (item->hasProxy() && !item->isProxyRunning()) {
1135 slotCreateProxy(clip->getId());
1138 KUrl url = clip->fileURL();
1140 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
1141 // if file has Nepomuk comment, use it
1142 Nepomuk::Resource f(url.path());
1143 QString annotation = f.description();
1144 if (!annotation.isEmpty()) item->setText(1, annotation);
1145 item->setText(2, QString::number(f.rating()));
1149 // Add info to date column
1150 QFileInfo fileInfo(url.path());
1151 if (fileInfo.exists()) {
1152 item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1156 QList <CutZoneInfo> cuts = clip->cutZones();
1157 if (!cuts.isEmpty()) {
1158 for (int i = 0; i < cuts.count(); i++) {
1159 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1160 if (!clip->getClipHash().isEmpty()) {
1161 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1162 if (QFile::exists(cachedPixmap)) {
1163 QPixmap pix(cachedPixmap);
1165 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1166 sub->setData(0, Qt::DecorationRole, pix);
1171 monitorItemEditing(true);
1175 void ProjectList::slotGotProxy(const QString &proxyPath)
1177 if (proxyPath.isEmpty() || m_abortAllProxies) return;
1178 QTreeWidgetItemIterator it(m_listView);
1181 while (*it && !m_abortAllProxies) {
1182 if ((*it)->type() == PROJECTCLIPTYPE) {
1183 item = static_cast <ProjectItem *>(*it);
1184 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1191 void ProjectList::slotGotProxy(ProjectItem *item)
1193 if (item == NULL) return;
1194 DocClipBase *clip = item->referencedClip();
1195 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1196 // Clip is being reprocessed, abort
1197 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1201 // Proxy clip successfully created
1202 QDomElement e = clip->toXML().cloneNode().toElement();
1204 // Make sure we get the correct producer length if it was adjusted in timeline
1205 CLIPTYPE t = item->clipType();
1206 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1207 int length = QString(clip->producerProperty("length")).toInt();
1208 if (length > 0 && !e.hasAttribute("length")) {
1209 e.setAttribute("length", length);
1212 resetThumbsProducer(clip);
1213 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1216 void ProjectList::slotResetProjectList()
1218 m_listView->blockSignals(true);
1219 m_abortAllProxies = true;
1220 m_proxyThreads.waitForFinished();
1221 m_proxyThreads.clearFutures();
1222 m_thumbnailQueue.clear();
1223 m_listView->clear();
1224 m_listView->setEnabled(true);
1225 emit clipSelected(NULL);
1226 m_refreshed = false;
1227 m_allClipsProcessed = false;
1228 m_abortAllProxies = false;
1229 m_listView->blockSignals(false);
1232 void ProjectList::slotUpdateClip(const QString &id)
1234 ProjectItem *item = getItemById(id);
1235 monitorItemEditing(false);
1236 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1237 monitorItemEditing(true);
1240 void ProjectList::getCachedThumbnail(ProjectItem *item)
1243 DocClipBase *clip = item->referencedClip();
1245 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1246 if (QFile::exists(cachedPixmap)) {
1247 QPixmap pix(cachedPixmap);
1249 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1250 requestClipThumbnail(item->clipId());
1252 else item->setData(0, Qt::DecorationRole, pix);
1255 requestClipThumbnail(item->clipId());
1259 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1262 ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1263 if (!parentItem) return;
1264 DocClipBase *clip = parentItem->referencedClip();
1266 int pos = item->zone().x();
1267 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + "#" + QString::number(pos) + ".png";
1268 if (QFile::exists(cachedPixmap)) {
1269 QPixmap pix(cachedPixmap);
1271 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1272 requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1274 else item->setData(0, Qt::DecorationRole, pix);
1276 else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1279 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1281 if (!m_allClipsProcessed) m_listView->setEnabled(false);
1282 m_listView->setSortingEnabled(false);
1283 QTreeWidgetItemIterator it(m_listView);
1286 monitorItemEditing(false);
1287 int height = m_listView->iconSize().height();
1288 int width = (int)(height * m_render->dar());
1289 QPixmap missingPixmap = QPixmap(width, height);
1290 missingPixmap.fill(Qt::transparent);
1291 KIcon icon("dialog-close");
1292 QPainter p(&missingPixmap);
1293 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1296 int max = m_doc->clipManager()->clipsCount();
1301 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1302 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1304 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1305 if (displayRatioChanged) {
1306 item = static_cast <ProjectItem *>((*it)->parent());
1307 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1309 else if (sub->data(0, Qt::DecorationRole).isNull()) {
1310 getCachedThumbnail(sub);
1314 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1319 item = static_cast <ProjectItem *>(*it);
1320 clip = item->referencedClip();
1321 if (item->referencedClip()->getProducer() == NULL) {
1322 bool replace = false;
1323 if (brokenClips.contains(item->clipId())) {
1324 // if this is a proxy clip, disable proxy
1325 item->setProxyStatus(NOPROXY);
1326 clip->setProperty("proxy", "-");
1329 if (clip->isPlaceHolder() == false && !item->isProxyRunning()) {
1330 QDomElement xml = clip->toXML();
1332 xml.removeAttribute("out");
1333 xml.removeAttribute("file_hash");
1334 xml.removeAttribute("proxy_out");
1336 if (!replace) replace = xml.attribute("replace") == "1";
1337 if (replace) resetThumbsProducer(clip);
1338 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1340 else if (clip->isPlaceHolder()) {
1341 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1342 if (item->data(0, Qt::DecorationRole).isNull()) {
1343 item->setData(0, Qt::DecorationRole, missingPixmap);
1346 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1347 QPainter p(&pixmap);
1348 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1350 item->setData(0, Qt::DecorationRole, pixmap);
1354 if (displayRatioChanged)
1355 requestClipThumbnail(clip->getId());
1356 else if (item->data(0, Qt::DecorationRole).isNull()) {
1357 getCachedThumbnail(item);
1359 if (item->data(0, DurationRole).toString().isEmpty()) {
1360 item->changeDuration(item->referencedClip()->getProducer()->get_playtime());
1362 if (clip->isPlaceHolder()) {
1363 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1364 if (pixmap.isNull()) {
1365 pixmap = QPixmap(width, height);
1366 pixmap.fill(Qt::transparent);
1368 QPainter p(&pixmap);
1369 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1371 item->setData(0, Qt::DecorationRole, pixmap);
1374 item->setData(0, UsageRole, QString::number(item->numReferences()));
1379 m_listView->setSortingEnabled(true);
1380 m_allClipsProcessed = true;
1381 if (m_render->processingItems() == 0) {
1382 monitorItemEditing(true);
1383 slotProcessNextThumbnail();
1388 QString ProjectList::getExtensions()
1390 // Build list of mime types
1391 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1392 << "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"
1393 << "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"
1394 << "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";
1396 QString allExtensions;
1397 foreach(const QString & mimeType, mimeTypes) {
1398 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1400 allExtensions.append(mime->patterns().join(" "));
1401 allExtensions.append(' ');
1404 return allExtensions.simplified();
1407 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1409 if (!m_commandStack)
1410 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1413 if (givenList.isEmpty()) {
1414 QString allExtensions = getExtensions();
1415 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1416 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1417 b->setChecked(KdenliveSettings::autoimagesequence());
1418 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1419 c->setChecked(KdenliveSettings::autoimagetransparency());
1420 QFrame *f = new QFrame;
1421 f->setFrameShape(QFrame::NoFrame);
1422 QHBoxLayout *l = new QHBoxLayout;
1427 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1428 d->setOperationMode(KFileDialog::Opening);
1429 d->setMode(KFile::Files);
1430 if (d->exec() == QDialog::Accepted) {
1431 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1433 list = d->selectedUrls();
1434 if (b->isChecked() && list.count() == 1) {
1435 // Check for image sequence
1436 KUrl url = list.at(0);
1437 QString fileName = url.fileName().section('.', 0, -2);
1438 if (fileName.at(fileName.size() - 1).isDigit()) {
1439 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1440 if (item.mimetype().startsWith("image")) {
1441 // import as sequence if we found more than one image in the sequence
1443 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1444 int count = list.count();
1447 QStringList groupInfo = getGroup();
1449 // get image sequence base name
1450 while (fileName.at(fileName.size() - 1).isDigit()) {
1454 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1455 false, false, false,
1456 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1457 QString(), groupInfo.at(0), groupInfo.at(1));
1465 for (int i = 0; i < givenList.count(); i++)
1466 list << givenList.at(i);
1469 foreach(const KUrl & file, list) {
1470 // Check there is no folder here
1471 KMimeType::Ptr type = KMimeType::findByUrl(file);
1472 if (type->is("inode/directory")) {
1473 // user dropped a folder
1474 list.removeAll(file);
1481 if (givenList.isEmpty()) {
1482 QStringList groupInfo = getGroup();
1483 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1485 m_doc->slotAddClipList(list, groupName, groupId);
1489 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1491 ProjectItem *item = getItemById(id);
1492 m_processingClips.removeAll(id);
1493 m_thumbnailQueue.removeAll(id);
1495 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1496 const QString path = item->referencedClip()->fileURL().path();
1497 if (item->referencedClip()->isPlaceHolder()) replace = false;
1498 if (!path.isEmpty()) {
1499 if (m_invalidClipDialog) {
1500 m_invalidClipDialog->addClip(id, path);
1505 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1507 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", QString()), replace, kapp->activeWindow());
1509 m_invalidClipDialog->addClip(id, path);
1510 int result = m_invalidClipDialog->exec();
1511 if (result == KDialog::Yes) replace = true;
1514 if (m_invalidClipDialog) {
1516 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1517 delete m_invalidClipDialog;
1518 m_invalidClipDialog = NULL;
1524 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1526 ProjectItem *item = getItemById(id);
1528 kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1529 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1530 if (durationError) {
1531 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1532 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1534 item->setProxyStatus(PROXYCRASHED);
1535 QString path = item->referencedClip()->getProperty("proxy");
1536 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1538 //Security check: make sure the invalid proxy file is in the proxy folder
1539 if (proxyFolder.isParentOf(KUrl(path))) {
1540 QFile::remove(path);
1542 if (item->referencedClip()->getProducer() == NULL) {
1543 // Clip has no valid producer, request it
1544 slotProxyCurrentItem(false, item);
1547 // refresh thumbs producer
1548 item->referencedClip()->reloadThumbProducer();
1551 m_processingClips.removeAll(id);
1552 m_thumbnailQueue.removeAll(id);
1555 void ProjectList::slotAddColorClip()
1557 if (!m_commandStack)
1558 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1560 QDialog *dia = new QDialog(this);
1561 Ui::ColorClip_UI dia_ui;
1562 dia_ui.setupUi(dia);
1563 dia->setWindowTitle(i18n("Color Clip"));
1564 dia_ui.clip_name->setText(i18n("Color Clip"));
1566 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1567 t->setValue(KdenliveSettings::color_duration());
1568 dia_ui.clip_durationBox->addWidget(t);
1569 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1571 if (dia->exec() == QDialog::Accepted) {
1572 QString color = dia_ui.clip_color->color().name();
1573 KdenliveSettings::setColorclipcolor(color);
1574 color = color.replace(0, 1, "0x") + "ff";
1575 QStringList groupInfo = getGroup();
1576 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1583 void ProjectList::slotAddSlideshowClip()
1585 if (!m_commandStack)
1586 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1588 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1590 if (dia->exec() == QDialog::Accepted) {
1591 QStringList groupInfo = getGroup();
1592 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1593 dia->loop(), dia->crop(), dia->fade(),
1594 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1595 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1600 void ProjectList::slotAddTitleClip()
1602 QStringList groupInfo = getGroup();
1603 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1606 void ProjectList::slotAddTitleTemplateClip()
1608 if (!m_commandStack)
1609 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1611 QStringList groupInfo = getGroup();
1613 // Get the list of existing templates
1615 filter << "*.kdenlivetitle";
1616 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1617 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1619 QDialog *dia = new QDialog(this);
1620 Ui::TemplateClip_UI dia_ui;
1621 dia_ui.setupUi(dia);
1622 for (int i = 0; i < templateFiles.size(); ++i)
1623 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1625 if (!templateFiles.isEmpty())
1626 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1627 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1628 //warning: setting base directory doesn't work??
1629 KUrl startDir(path);
1630 dia_ui.template_list->fileDialog()->setUrl(startDir);
1631 dia_ui.text_box->setHidden(true);
1632 if (dia->exec() == QDialog::Accepted) {
1633 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1634 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1635 // Create a cloned template clip
1636 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1641 QStringList ProjectList::getGroup() const
1644 QTreeWidgetItem *item = m_listView->currentItem();
1645 while (item && item->type() != PROJECTFOLDERTYPE)
1646 item = item->parent();
1649 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1650 result << folder->groupName() << folder->clipId();
1652 result << QString() << QString();
1657 void ProjectList::setDocument(KdenliveDoc *doc)
1659 m_listView->blockSignals(true);
1660 m_abortAllProxies = true;
1661 m_proxyThreads.waitForFinished();
1662 m_proxyThreads.clearFutures();
1663 m_thumbnailQueue.clear();
1664 m_listView->clear();
1665 m_processingClips.clear();
1667 m_listView->setSortingEnabled(false);
1668 emit clipSelected(NULL);
1669 m_refreshed = false;
1670 m_allClipsProcessed = false;
1672 m_timecode = doc->timecode();
1673 m_commandStack = doc->commandStack();
1675 m_abortAllProxies = false;
1677 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1678 QStringList openedFolders = doc->getExpandedFolders();
1679 QMapIterator<QString, QString> f(flist);
1680 while (f.hasNext()) {
1682 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1683 folder->setExpanded(openedFolders.contains(f.key()));
1686 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1687 if (list.isEmpty()) {
1690 m_allClipsProcessed = true;
1692 for (int i = 0; i < list.count(); i++)
1693 slotAddClip(list.at(i), false);
1695 m_listView->blockSignals(false);
1696 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1697 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1698 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1699 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1700 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
1703 QList <DocClipBase*> ProjectList::documentClipList() const
1706 return QList <DocClipBase*> ();
1708 return m_doc->clipManager()->documentClipList();
1711 QDomElement ProjectList::producersList()
1714 QDomElement prods = doc.createElement("producerlist");
1715 doc.appendChild(prods);
1716 QTreeWidgetItemIterator it(m_listView);
1718 if ((*it)->type() != PROJECTCLIPTYPE) {
1723 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1729 void ProjectList::slotCheckForEmptyQueue()
1731 if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
1732 if (!m_refreshed && m_allClipsProcessed) {
1734 m_listView->setEnabled(true);
1736 QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
1737 emit displayMessage(QString(), -1);
1740 } else if (!m_refreshed) {
1741 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1746 void ProjectList::requestClipThumbnail(const QString id)
1748 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1749 slotProcessNextThumbnail();
1752 void ProjectList::resetThumbsProducer(DocClipBase *clip)
1755 clip->clearThumbProducer();
1756 QString id = clip->getId();
1757 m_thumbnailQueue.removeAll(id);
1760 void ProjectList::slotProcessNextThumbnail()
1762 if (m_render->processingItems() > 0) {
1765 if (m_thumbnailQueue.isEmpty()) {
1766 slotCheckForEmptyQueue();
1769 int max = m_doc->clipManager()->clipsCount();
1770 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1771 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1774 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1776 QTreeWidgetItem *item = getAnyItemById(clipId);
1778 slotRefreshClipThumbnail(item, update);
1780 slotProcessNextThumbnail();
1784 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1786 if (it == NULL) return;
1787 ProjectItem *item = NULL;
1788 bool isSubItem = false;
1790 if (it->type() == PROJECTFOLDERTYPE) return;
1791 if (it->type() == PROJECTSUBCLIPTYPE) {
1792 item = static_cast <ProjectItem *>(it->parent());
1793 frame = static_cast <SubProjectItem *>(it)->zone().x();
1796 item = static_cast <ProjectItem *>(it);
1797 frame = item->referencedClip()->getClipThumbFrame();
1801 DocClipBase *clip = item->referencedClip();
1803 slotProcessNextThumbnail();
1808 int height = m_listView->iconSize().height();
1809 int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
1810 int dwidth = (int)(height * m_render->dar() + 0.5);
1811 if (clip->clipType() == AUDIO)
1812 pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
1813 else if (clip->clipType() == IMAGE)
1814 img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
1816 img = item->referencedClip()->extractImage(frame, dwidth, height);
1819 if (!pix.isNull() || !img.isNull()) {
1820 monitorItemEditing(false);
1821 if (!img.isNull()) pix = QPixmap::fromImage(img);
1822 it->setData(0, Qt::DecorationRole, pix);
1823 monitorItemEditing(true);
1825 QString hash = item->getClipHash();
1826 if (!hash.isEmpty() && !img.isNull()) {
1828 m_doc->cacheImage(hash, img);
1830 m_doc->cacheImage(hash + '#' + QString::number(frame), img);
1834 emit projectModified();
1835 slotProcessNextThumbnail();
1840 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
1843 ProjectItem *item = getItemById(clipId);
1845 int queue = m_render->processingItems();
1846 if (item && producer) {
1847 monitorItemEditing(false);
1848 DocClipBase *clip = item->referencedClip();
1849 if (producer->is_valid()) {
1850 if (clip->isPlaceHolder()) {
1854 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1856 item->setProperties(properties, metadata);
1857 clip->setProducer(producer, replace);
1860 QString size = properties.value("frame_size");
1861 if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY);
1862 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY);
1863 else if (useProxy() && !item->hasProxy() && !item->isProxyRunning()) {
1864 // proxy video and image clips
1866 CLIPTYPE t = item->clipType();
1867 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
1868 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
1869 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)) {
1870 if (clip->getProperty("proxy").isEmpty()) {
1871 KUrl proxyPath = m_doc->projectFolder();
1872 proxyPath.addPath("proxy/");
1873 proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
1874 QMap <QString, QString> newProps;
1875 // insert required duration for proxy
1876 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
1877 newProps.insert("proxy", proxyPath.path());
1878 QMap <QString, QString> oldProps = clip->properties();
1879 oldProps.insert("proxy", QString());
1880 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
1881 m_doc->commandStack()->push(command);
1886 if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) {
1887 getCachedThumbnail(item);
1889 if (!toReload.isEmpty())
1890 item->slotSetToolTip();
1891 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1893 monitorItemEditing(true);
1894 if (item && m_thumbnailQueue.isEmpty()) {
1895 if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
1896 m_listView->setCurrentItem(item);
1897 bool updatedProfile = false;
1898 if (item->parent()) {
1899 if (item->parent()->type() == PROJECTFOLDERTYPE)
1900 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1901 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
1902 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1903 updatedProfile = adjustProjectProfileToItem(item);
1905 if (updatedProfile == false) {
1906 //emit clipSelected(item->referencedClip());
1909 int max = m_doc->clipManager()->clipsCount();
1910 if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
1912 if (m_allClipsProcessed) emit processNextThumbnail();
1915 // no item for producer, delete it
1919 if (replace) toReload = clipId;
1920 if (!toReload.isEmpty())
1921 emit clipNeedsReload(toReload);
1924 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1927 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1928 item = static_cast <ProjectItem*>(m_listView->currentItem());
1930 if (item == NULL || item->referencedClip() == NULL) {
1931 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1934 bool profileUpdated = false;
1935 QString size = item->referencedClip()->getProperty("frame_size");
1936 int width = size.section('x', 0, 0).toInt();
1937 int height = size.section('x', -1).toInt();
1938 double fps = item->referencedClip()->getProperty("fps").toDouble();
1939 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1940 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1941 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1942 // get a list of compatible profiles
1943 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1944 if (!suggestedProfiles.isEmpty()) {
1945 KDialog *dialog = new KDialog(this);
1946 dialog->setCaption(i18n("Change project profile"));
1947 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1950 QVBoxLayout *l = new QVBoxLayout;
1951 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));
1952 l->addWidget(label);
1953 QListWidget *list = new QListWidget;
1954 list->setAlternatingRowColors(true);
1955 QMapIterator<QString, QString> i(suggestedProfiles);
1956 while (i.hasNext()) {
1958 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1959 item->setData(Qt::UserRole, i.key());
1960 item->setToolTip(i.key());
1962 list->setCurrentRow(0);
1964 container.setLayout(l);
1965 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1966 dialog->setMainWidget(&container);
1967 if (dialog->exec() == QDialog::Accepted) {
1968 //Change project profile
1969 profileUpdated = true;
1970 if (list->currentItem())
1971 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1975 } else if (fps > 0) {
1976 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));
1980 return profileUpdated;
1983 QString ProjectList::getDocumentProperty(const QString &key) const
1985 return m_doc->getDocumentProperty(key);
1988 bool ProjectList::useProxy() const
1990 return m_doc->getDocumentProperty("enableproxy").toInt();
1993 bool ProjectList::generateProxy() const
1995 return m_doc->getDocumentProperty("generateproxy").toInt();
1998 bool ProjectList::generateImageProxy() const
2000 return m_doc->getDocumentProperty("generateimageproxy").toInt();
2003 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2005 ProjectItem *item = getItemById(clipId);
2006 if (item && !img.isNull()) {
2007 QPixmap pix = QPixmap::fromImage(img);
2008 monitorItemEditing(false);
2009 item->setData(0, Qt::DecorationRole, pix);
2010 monitorItemEditing(true);
2011 QString hash = item->getClipHash();
2012 if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2016 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2018 // For clips that have a generic icon (like audio clips...)
2019 ProjectItem *item = getItemById(clipId);
2020 QPixmap pix = KIcon(name).pixmap(QSize(width, height));
2021 if (item && !pix.isNull()) {
2022 monitorItemEditing(false);
2023 item->setData(0, Qt::DecorationRole, pix);
2024 monitorItemEditing(true);
2028 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2030 QTreeWidgetItemIterator it(m_listView);
2031 QString lookId = id;
2032 if (id.contains('#'))
2033 lookId = id.section('#', 0, 0);
2035 ProjectItem *result = NULL;
2037 if ((*it)->type() != PROJECTCLIPTYPE) {
2042 ProjectItem *item = static_cast<ProjectItem *>(*it);
2043 if (item->clipId() == lookId) {
2049 if (result == NULL || !id.contains('#')) {
2052 for (int i = 0; i < result->childCount(); i++) {
2053 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2054 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2063 ProjectItem *ProjectList::getItemById(const QString &id)
2066 QTreeWidgetItemIterator it(m_listView);
2068 if ((*it)->type() != PROJECTCLIPTYPE) {
2069 // subitem or folder
2073 item = static_cast<ProjectItem *>(*it);
2074 if (item->clipId() == id)
2081 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2083 FolderProjectItem *item;
2084 QTreeWidgetItemIterator it(m_listView);
2086 if ((*it)->type() == PROJECTFOLDERTYPE) {
2087 item = static_cast<FolderProjectItem *>(*it);
2088 if (item->clipId() == id)
2096 void ProjectList::slotSelectClip(const QString &ix)
2098 ProjectItem *clip = getItemById(ix);
2100 m_listView->setCurrentItem(clip);
2101 m_listView->scrollToItem(clip);
2102 m_editButton->defaultAction()->setEnabled(true);
2103 m_deleteButton->defaultAction()->setEnabled(true);
2104 m_reloadAction->setEnabled(true);
2105 m_transcodeAction->setEnabled(true);
2106 m_stabilizeAction->setEnabled(true);
2107 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2108 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2109 m_openAction->setEnabled(true);
2110 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2111 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2112 m_openAction->setEnabled(true);
2114 m_openAction->setEnabled(false);
2119 QString ProjectList::currentClipUrl() const
2122 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2123 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2125 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2127 item = static_cast <ProjectItem*>(m_listView->currentItem());
2131 return item->clipUrl().path();
2134 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2138 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2139 for (int i = 0; i < list.count(); i++) {
2140 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2142 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2144 item = static_cast <ProjectItem*>(list.at(i)->parent());
2146 item = static_cast <ProjectItem*>(list.at(i));
2148 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2150 DocClipBase *clip = item->referencedClip();
2151 if (!condition.isEmpty()) {
2152 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2154 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2157 result.append(item->clipUrl());
2162 void ProjectList::regenerateTemplate(const QString &id)
2164 ProjectItem *clip = getItemById(id);
2166 regenerateTemplate(clip);
2169 void ProjectList::regenerateTemplate(ProjectItem *clip)
2171 //TODO: remove this unused method, only force_reload is necessary
2172 clip->referencedClip()->getProducer()->set("force_reload", 1);
2175 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2179 if (!file.open(QIODevice::ReadOnly)) {
2180 kWarning() << "ERROR, CANNOT READ: " << path;
2183 if (!doc.setContent(&file)) {
2184 kWarning() << "ERROR, CANNOT READ: " << path;
2189 QDomNodeList texts = doc.elementsByTagName("content");
2190 for (int i = 0; i < texts.count(); i++) {
2191 QString data = texts.item(i).firstChild().nodeValue();
2192 data.replace("%s", replaceString);
2193 texts.item(i).firstChild().setNodeValue(data);
2199 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2201 ProjectItem *clip = getItemById(id);
2202 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2204 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2205 m_commandStack->push(command);
2208 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2210 ProjectItem *clip = getItemById(id);
2212 DocClipBase *base = clip->referencedClip();
2213 base->addCutZone(in, out);
2214 monitorItemEditing(false);
2215 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2216 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2217 if (!clip->isExpanded())
2218 clip->setExpanded(true);
2219 m_listView->scrollToItem(sub);
2220 m_listView->editItem(sub, 1);
2222 QImage img = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
2223 sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2224 QString hash = clip->getClipHash();
2225 if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(in), img);
2226 monitorItemEditing(true);
2228 emit projectModified();
2231 void ProjectList::removeClipCut(const QString &id, int in, int out)
2233 ProjectItem *clip = getItemById(id);
2235 DocClipBase *base = clip->referencedClip();
2236 base->removeCutZone(in, out);
2237 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2239 monitorItemEditing(false);
2241 monitorItemEditing(true);
2244 emit projectModified();
2247 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2249 SubProjectItem *sub = NULL;
2251 for (int i = 0; i < clip->childCount(); i++) {
2252 QTreeWidgetItem *it = clip->child(i);
2253 if (it->type() == PROJECTSUBCLIPTYPE) {
2254 sub = static_cast <SubProjectItem*>(it);
2255 if (sub->zone() == zone)
2265 void ProjectList::slotUpdateClipCut(QPoint p)
2267 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2269 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2270 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2271 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2272 m_commandStack->push(command);
2275 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2277 ProjectItem *clip = getItemById(id);
2278 SubProjectItem *sub = getSubItem(clip, oldzone);
2279 if (sub == NULL || clip == NULL)
2281 DocClipBase *base = clip->referencedClip();
2282 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2283 monitorItemEditing(false);
2285 sub->setDescription(comment);
2286 monitorItemEditing(true);
2287 emit projectModified();
2290 void ProjectList::slotForceProcessing(const QString &id)
2292 m_render->forceProcessing(id);
2295 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2297 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2299 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2300 int count = list.count();
2302 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2303 if (!existing.isEmpty()) {
2304 // Sequence already exists, update
2305 QString id = existing.at(0)->getId();
2306 //ProjectItem *item = getItemById(id);
2307 QMap <QString, QString> oldprops;
2308 QMap <QString, QString> newprops;
2309 int ttl = existing.at(0)->getProperty("ttl").toInt();
2310 oldprops["out"] = existing.at(0)->getProperty("out");
2311 newprops["out"] = QString::number(ttl * count - 1);
2312 slotUpdateClipProperties(id, newprops);
2313 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2314 m_commandStack->push(command);
2317 QStringList groupInfo = getGroup();
2318 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
2319 false, false, false,
2320 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
2321 QString(), groupInfo.at(0), groupInfo.at(1));
2323 } else emit displayMessage(i18n("Sequence not found"), -2);
2326 QMap <QString, QString> ProjectList::getProxies()
2328 QMap <QString, QString> list;
2330 QTreeWidgetItemIterator it(m_listView);
2332 if ((*it)->type() != PROJECTCLIPTYPE) {
2336 item = static_cast<ProjectItem *>(*it);
2337 if (item && item->referencedClip() != NULL) {
2338 if (item->hasProxy()) {
2339 QString proxy = item->referencedClip()->getProperty("proxy");
2340 list.insert(proxy, item->clipUrl().path());
2348 void ProjectList::slotCreateProxy(const QString id)
2350 ProjectItem *item = getItemById(id);
2351 if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
2352 QString path = item->referencedClip()->getProperty("proxy");
2353 if (path.isEmpty()) {
2354 setProxyStatus(item, PROXYCRASHED);
2357 setProxyStatus(item, PROXYWAITING);
2358 if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
2359 if (m_processingProxy.contains(path)) {
2360 // Proxy is already being generated
2363 if (QFileInfo(path).size() > 0) {
2364 // Proxy already created
2365 setProxyStatus(item, PROXYDONE);
2369 m_processingProxy.append(path);
2373 info.src = item->clipUrl().path();
2374 info.type = item->clipType();
2375 info.exif = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();
2376 m_proxyList.append(info);
2377 if (!m_proxyThreads.futures().isEmpty()) {
2378 // Remove inactive threads
2379 QList <QFuture<void> > futures = m_proxyThreads.futures();
2380 m_proxyThreads.clearFutures();
2381 for (int i = 0; i < futures.count(); i++)
2382 if (!futures.at(i).isFinished()) {
2383 m_proxyThreads.addFuture(futures.at(i));
2386 if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy));
2389 void ProjectList::slotAbortProxy(const QString id, const QString path)
2391 QTreeWidgetItemIterator it(m_listView);
2392 ProjectItem *item = getItemById(id);
2393 if (!path.isEmpty() && m_processingProxy.contains(path)) {
2394 m_abortProxy << path;
2395 setProxyStatus(item, NOPROXY);
2398 setProxyStatus(item, NOPROXY);
2403 void ProjectList::slotGenerateProxy()
2405 while (!m_proxyList.isEmpty() && !m_abortAllProxies) {
2406 emit projectModified();
2407 PROXYINFO info = m_proxyList.takeFirst();
2408 if (m_abortProxy.contains(info.dest)) {
2409 m_abortProxy.removeAll(info.dest);
2412 // Get the list of clips that will need to get progress info
2413 QTreeWidgetItemIterator it(m_listView);
2414 QList <ProjectItem *> processingItems;
2415 while (*it && !m_abortAllProxies) {
2416 if ((*it)->type() == PROJECTCLIPTYPE) {
2417 ProjectItem *item = static_cast <ProjectItem *>(*it);
2418 if (item->referencedClip()->getProperty("proxy") == info.dest) {
2419 processingItems.append(item);
2425 // Make sure proxy path is writable
2426 QFile file(info.dest);
2427 if (!file.open(QIODevice::WriteOnly)) {
2428 for (int i = 0; i < processingItems.count(); i++)
2429 setProxyStatus(processingItems.at(i), PROXYCRASHED);
2430 m_processingProxy.removeAll(info.dest);
2434 QFile::remove(info.dest);
2436 for (int i = 0; i < processingItems.count(); i++)
2437 setProxyStatus(processingItems.at(i), CREATINGPROXY);
2439 // Special case: playlist clips (.mlt or .kdenlive project files)
2440 if (info.type == PLAYLIST) {
2441 // change FFmpeg params to MLT format
2442 QStringList parameters;
2443 parameters << info.src;
2444 parameters << "-consumer" << "avformat:" + info.dest;
2445 QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts);
2447 foreach(QString s, params) {
2449 if (s.count(' ') == 0) {
2452 else s.replace(' ', '=');
2456 parameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads()));
2458 //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
2459 double display_ratio = KdenliveDoc::getDisplayRatio(info.src);
2460 parameters << "aspect=" + QString::number(display_ratio);
2462 //kDebug()<<"TRANSCOD: "<<parameters;
2464 myProcess.setProcessChannelMode(QProcess::MergedChannels);
2465 myProcess.start(KdenliveSettings::rendererpath(), parameters);
2466 myProcess.waitForStarted();
2469 while (myProcess.state() != QProcess::NotRunning) {
2470 // building proxy file
2471 if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
2473 myProcess.waitForFinished();
2474 QFile::remove(info.dest);
2475 m_abortProxy.removeAll(info.dest);
2476 m_processingProxy.removeAll(info.dest);
2477 for (int i = 0; i < processingItems.count(); i++)
2478 setProxyStatus(processingItems.at(i), NOPROXY);
2482 QString log = QString(myProcess.readAll());
2483 processLogInfo(processingItems, &duration, log);
2485 myProcess.waitForFinished(500);
2487 myProcess.waitForFinished();
2488 m_processingProxy.removeAll(info.dest);
2489 if (result == -1) result = myProcess.exitStatus();
2491 // proxy successfully created
2492 for (int i = 0; i < processingItems.count(); i++)
2493 setProxyStatus(processingItems.at(i), PROXYDONE);
2494 slotGotProxy(info.dest);
2496 else if (result == 1) {
2497 // Proxy process crashed
2498 QFile::remove(info.dest);
2499 for (int i = 0; i < processingItems.count(); i++)
2500 setProxyStatus(processingItems.at(i), PROXYCRASHED);
2505 if (info.type == IMAGE) {
2509 // Cannot load image
2510 for (int i = 0; i < processingItems.count(); i++)
2511 setProxyStatus(processingItems.at(i), PROXYCRASHED);
2515 // Images are scaled to profile size.
2516 //TODO: Make it be configurable?
2517 if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth());
2518 else proxy = i.scaledToHeight(m_render->renderHeight());
2519 if (info.exif > 1) {
2520 // Rotate image according to exif data
2524 switch ( info.exif ) {
2526 matrix.scale( -1, 1 );
2529 matrix.rotate( 180 );
2532 matrix.scale( 1, -1 );
2535 matrix.rotate( 270 );
2536 matrix.scale( -1, 1 );
2539 matrix.rotate( 90 );
2542 matrix.rotate( 90 );
2543 matrix.scale( -1, 1 );
2546 matrix.rotate( 270 );
2549 processed = proxy.transformed( matrix );
2550 processed.save(info.dest);
2552 else proxy.save(info.dest);
2553 for (int i = 0; i < processingItems.count(); i++)
2554 setProxyStatus(processingItems.at(i), PROXYDONE);
2555 slotGotProxy(info.dest);
2556 m_abortProxy.removeAll(info.dest);
2557 m_processingProxy.removeAll(info.dest);
2561 QStringList parameters;
2562 parameters << "-i" << info.src;
2563 QString params = m_doc->getDocumentProperty("proxyparams").simplified();
2564 foreach(QString s, params.split(' '))
2567 // Make sure we don't block when proxy file already exists
2569 parameters << info.dest;
2571 myProcess.setProcessChannelMode(QProcess::MergedChannels);
2572 myProcess.start("ffmpeg", parameters);
2573 myProcess.waitForStarted();
2577 while (myProcess.state() != QProcess::NotRunning) {
2578 // building proxy file
2579 if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
2581 myProcess.waitForFinished();
2582 m_abortProxy.removeAll(info.dest);
2583 m_processingProxy.removeAll(info.dest);
2584 QFile::remove(info.dest);
2585 if (!m_abortAllProxies) {
2586 for (int i = 0; i < processingItems.count(); i++)
2587 setProxyStatus(processingItems.at(i), NOPROXY);
2593 QString log = QString(myProcess.readAll());
2594 processLogInfo(processingItems, &duration, log);
2596 myProcess.waitForFinished(500);
2598 myProcess.waitForFinished();
2599 m_abortProxy.removeAll(info.dest);
2600 m_processingProxy.removeAll(info.dest);
2602 result = myProcess.exitStatus();
2605 // FFmpeg process terminated normally, but make sure proxy clip exists
2606 if (result != -2 && QFileInfo(info.dest).size() == 0) {
2607 result = QProcess::CrashExit;
2610 if (result == QProcess::NormalExit) {
2611 // proxy successfully created
2612 for (int i = 0; i < processingItems.count(); i++)
2613 setProxyStatus(processingItems.at(i), PROXYDONE);
2614 slotGotProxy(info.dest);
2616 else if (result == QProcess::CrashExit) {
2617 // Proxy process crashed
2618 QFile::remove(info.dest);
2619 for (int i = 0; i < processingItems.count(); i++)
2620 setProxyStatus(processingItems.at(i), PROXYCRASHED);
2626 void ProjectList::processLogInfo(QList <ProjectItem *>items, int *duration, const QString &log)
2629 if (*duration == 0) {
2630 if (log.contains("Duration:")) {
2631 QString data = log.section("Duration:", 1, 1).section(',', 0, 0).simplified();
2632 QStringList numbers = data.split(':');
2633 *duration = (int) (numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble());
2636 else if (log.contains("time=")) {
2637 QString time = log.section("time=", 1, 1).simplified().section(' ', 0, 0);
2638 if (time.contains(':')) {
2639 QStringList numbers = time.split(':');
2640 progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble();
2642 else progress = (int) time.toDouble();
2643 for (int i = 0; i < items.count(); i++)
2644 setProxyStatus(items.at(i), CREATINGPROXY, (int) (100.0 * progress / (*duration)));
2648 void ProjectList::updateProxyConfig()
2651 QTreeWidgetItemIterator it(m_listView);
2652 QUndoCommand *command = new QUndoCommand();
2653 command->setText(i18n("Update proxy settings"));
2654 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2656 if ((*it)->type() != PROJECTCLIPTYPE) {
2660 item = static_cast<ProjectItem *>(*it);
2665 CLIPTYPE t = item->clipType();
2666 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2667 if (generateProxy() && useProxy() && !item->isProxyRunning()) {
2668 DocClipBase *clip = item->referencedClip();
2669 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
2670 if (clip->getProperty("proxy").isEmpty()) {
2671 // We need to insert empty proxy in old properties so that undo will work
2672 QMap <QString, QString> oldProps;// = clip->properties();
2673 oldProps.insert("proxy", QString());
2674 QMap <QString, QString> newProps;
2675 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
2676 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2680 else if (item->hasProxy()) {
2682 QMap <QString, QString> newProps;
2683 newProps.insert("proxy", QString());
2684 newProps.insert("replace", "1");
2685 // insert required duration for proxy
2686 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2687 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
2690 else if (t == IMAGE && item->referencedClip() != NULL) {
2691 if (generateImageProxy() && useProxy()) {
2692 DocClipBase *clip = item->referencedClip();
2693 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2694 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
2695 if (clip->getProperty("proxy").isEmpty()) {
2696 // We need to insert empty proxy in old properties so that undo will work
2697 QMap <QString, QString> oldProps = clip->properties();
2698 oldProps.insert("proxy", QString());
2699 QMap <QString, QString> newProps;
2700 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
2701 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2705 else if (item->hasProxy()) {
2707 QMap <QString, QString> newProps;
2708 newProps.insert("proxy", QString());
2709 newProps.insert("replace", "1");
2710 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2715 if (command->childCount() > 0) m_doc->commandStack()->push(command);
2716 else delete command;
2719 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
2721 QList<QTreeWidgetItem *> list;
2722 if (itemToProxy == NULL) list = m_listView->selectedItems();
2723 else list << itemToProxy;
2725 // expand list (folders, subclips) to get real clips
2726 QTreeWidgetItem *listItem;
2727 QList<ProjectItem *> clipList;
2728 for (int i = 0; i < list.count(); i++) {
2729 listItem = list.at(i);
2730 if (listItem->type() == PROJECTFOLDERTYPE) {
2731 for (int j = 0; j < listItem->childCount(); j++) {
2732 QTreeWidgetItem *sub = listItem->child(j);
2733 if (sub->type() == PROJECTCLIPTYPE) {
2734 ProjectItem *item = static_cast <ProjectItem*>(sub);
2735 if (!clipList.contains(item)) clipList.append(item);
2739 else if (listItem->type() == PROJECTSUBCLIPTYPE) {
2740 QTreeWidgetItem *sub = listItem->parent();
2741 ProjectItem *item = static_cast <ProjectItem*>(sub);
2742 if (!clipList.contains(item)) clipList.append(item);
2744 else if (listItem->type() == PROJECTCLIPTYPE) {
2745 ProjectItem *item = static_cast <ProjectItem*>(listItem);
2746 if (!clipList.contains(item)) clipList.append(item);
2750 QUndoCommand *command = new QUndoCommand();
2751 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
2752 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
2754 // Make sure the proxy folder exists
2755 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2756 KStandardDirs::makeDir(proxydir);
2758 QMap <QString, QString> newProps;
2759 QMap <QString, QString> oldProps;
2760 if (!doProxy) newProps.insert("proxy", "-");
2761 for (int i = 0; i < clipList.count(); i++) {
2762 ProjectItem *item = clipList.at(i);
2763 CLIPTYPE t = item->clipType();
2764 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
2765 if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
2766 DocClipBase *clip = item->referencedClip();
2767 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
2768 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
2772 oldProps = clip->properties();
2775 QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
2776 // insert required duration for proxy
2777 newProps.insert("proxy_out", clip->producerProperty("out"));
2778 newProps.insert("proxy", path);
2779 // We need to insert empty proxy so that undo will work
2780 oldProps.insert("proxy", QString());
2782 else if (item->referencedClip()->getProducer() == NULL) {
2783 // Force clip reload
2784 kDebug()<<"// CLIP HAD NULL PROD------------";
2785 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
2787 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
2790 if (command->childCount() > 0) {
2791 m_doc->commandStack()->push(command);
2793 else delete command;
2797 void ProjectList::slotDeleteProxy(const QString proxyPath)
2799 if (proxyPath.isEmpty()) return;
2800 QUndoCommand *proxyCommand = new QUndoCommand();
2801 proxyCommand->setText(i18n("Remove Proxy"));
2802 QTreeWidgetItemIterator it(m_listView);
2805 if ((*it)->type() == PROJECTCLIPTYPE) {
2806 item = static_cast <ProjectItem *>(*it);
2807 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
2808 QMap <QString, QString> props;
2809 props.insert("proxy", QString());
2810 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
2816 if (proxyCommand->childCount() == 0)
2817 delete proxyCommand;
2819 m_commandStack->push(proxyCommand);
2820 QFile::remove(proxyPath);
2823 void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress)
2825 if (item == NULL || m_abortAllProxies) return;
2826 monitorItemEditing(false);
2827 item->setProxyStatus(status, progress);
2828 if (status == PROXYCRASHED) {
2829 DocClipBase *clip = item->referencedClip();
2831 kDebug()<<"// PROXY CRASHED";
2833 else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
2834 // disable proxy and fetch real clip
2835 clip->setProperty("proxy", "-");
2836 QDomElement xml = clip->toXML();
2837 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
2840 // Disable proxy for this clip
2841 clip->setProperty("proxy", "-");
2844 monitorItemEditing(true);
2847 void ProjectList::monitorItemEditing(bool enable)
2849 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2850 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2853 QStringList ProjectList::expandedFolders() const
2856 FolderProjectItem *item;
2857 QTreeWidgetItemIterator it(m_listView);
2859 if ((*it)->type() != PROJECTFOLDERTYPE) {
2863 if ((*it)->isExpanded()) {
2864 item = static_cast<FolderProjectItem *>(*it);
2865 result.append(item->clipId());
2872 #include "projectlist.moc"