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 "projecttree/proxyclipjob.h"
24 #include "projecttree/cutclipjob.h"
25 #include "kdenlivesettings.h"
26 #include "slideshowclip.h"
27 #include "ui_colorclip_ui.h"
28 #include "titlewidget.h"
29 #include "definitions.h"
30 #include "clipmanager.h"
31 #include "docclipbase.h"
32 #include "kdenlivedoc.h"
35 #include "projectlistview.h"
36 #include "timecodedisplay.h"
37 #include "profilesdialog.h"
38 #include "commands/editclipcommand.h"
39 #include "commands/editclipcutcommand.h"
40 #include "commands/editfoldercommand.h"
41 #include "commands/addclipcutcommand.h"
43 #include "ui_templateclip_ui.h"
44 #include "ui_cutjobdialog_ui.h"
49 #include <KFileDialog>
50 #include <KInputDialog>
51 #include <KMessageBox>
52 #include <KIO/NetAccess>
54 #include <KApplication>
55 #include <KStandardDirs>
56 #include <KColorScheme>
57 #include <KActionCollection>
58 #include <KUrlRequester>
61 #include <nepomuk/global.h>
62 #include <nepomuk/resourcemanager.h>
63 //#include <nepomuk/tag.h>
66 #include <QMouseEvent>
67 #include <QStylePainter>
72 #include <QHeaderView>
73 #include <QInputDialog>
74 #include <QtConcurrentRun>
75 #include <QVBoxLayout>
77 SmallInfoLabel::SmallInfoLabel(QWidget *parent) : QPushButton(parent)
82 /*QString style = "QToolButton {background-color: %1;border-style: outset;border-width: 2px;
83 border-radius: 5px;border-color: beige;}";*/
84 KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
85 QColor bg = scheme.background(KColorScheme::LinkBackground).color();
86 QColor fg = scheme.foreground(KColorScheme::LinkText).color();
87 QString style = QString("QPushButton {padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}").arg(bg.red()).arg(bg.green()).arg(bg.blue()).arg(fg.red()).arg(fg.green()).arg(fg.blue());
89 bg = scheme.background(KColorScheme::ActiveBackground).color();
90 fg = scheme.foreground(KColorScheme::ActiveText).color();
91 style.append(QString("\nQPushButton:hover {padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}").arg(bg.red()).arg(bg.green()).arg(bg.blue()).arg(fg.red()).arg(fg.green()).arg(fg.blue()));
94 m_timeLine = new QTimeLine(500, this);
95 QObject::connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(slotTimeLineChanged(qreal)));
96 QObject::connect(m_timeLine, SIGNAL(finished()), this, SLOT(slotTimeLineFinished()));
100 void SmallInfoLabel::slotTimeLineChanged(qreal value)
102 setFixedWidth(qMin(value * 2, qreal(1.0)) * sizeHint().width());
106 void SmallInfoLabel::slotTimeLineFinished()
108 if (m_timeLine->direction() == QTimeLine::Forward) {
118 void SmallInfoLabel::slotSetJobCount(int jobCount)
122 setText(i18np("%1 job", "%1 jobs", jobCount));
123 setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
125 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
126 setFixedWidth(sizeHint().width());
132 setFixedWidth(sizeHint().width());
139 int wantedWidth = sizeHint().width();
140 setGeometry(-wantedWidth, 0, wantedWidth, height());
141 m_timeLine->setDirection(QTimeLine::Forward);
142 if (m_timeLine->state() == QTimeLine::NotRunning) {
147 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
153 m_timeLine->setDirection(QTimeLine::Backward);
154 if (m_timeLine->state() == QTimeLine::NotRunning) {
162 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
165 if (infoOnly) setButtons(KDialog::Ok);
166 else setButtons(KDialog::Yes | KDialog::No);
167 QWidget *w = new QWidget(this);
168 QVBoxLayout *l = new QVBoxLayout;
169 l->addWidget(new QLabel(message));
170 m_clipList = new QListWidget;
171 l->addWidget(m_clipList);
176 InvalidDialog::~InvalidDialog()
182 void InvalidDialog::addClip(const QString &id, const QString &path)
184 QListWidgetItem *item = new QListWidgetItem(path);
185 item->setData(Qt::UserRole, id);
186 m_clipList->addItem(item);
189 QStringList InvalidDialog::getIds() const
192 for (int i = 0; i < m_clipList->count(); i++) {
193 ids << m_clipList->item(i)->data(Qt::UserRole).toString();
199 ProjectList::ProjectList(QWidget *parent) :
203 m_commandStack(NULL),
205 m_reloadAction(NULL),
206 m_stabilizeAction(NULL),
207 m_transcodeAction(NULL),
210 m_allClipsProcessed(false),
212 m_abortAllJobs(false),
214 m_invalidClipDialog(NULL)
216 qRegisterMetaType<stringMap> ("stringMap");
217 QVBoxLayout *layout = new QVBoxLayout;
218 layout->setContentsMargins(0, 0, 0, 0);
219 layout->setSpacing(0);
220 qRegisterMetaType<QDomElement>("QDomElement");
222 QFrame *frame = new QFrame;
223 frame->setFrameStyle(QFrame::NoFrame);
224 QHBoxLayout *box = new QHBoxLayout;
225 box->setContentsMargins(0, 0, 0, 0);
227 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
228 box->addWidget(searchView);
230 // small info button for pending jobs
231 m_infoLabel = new SmallInfoLabel(this);
232 connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
233 m_jobsMenu = new QMenu(this);
234 QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this);
235 cancelJobs->setCheckable(false);
236 connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs()));
237 m_jobsMenu->addAction(cancelJobs);
238 m_infoLabel->setMenu(m_jobsMenu);
239 box->addWidget(m_infoLabel);
241 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
242 QSize iconSize(size, size);
244 m_addButton = new QToolButton;
245 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
246 m_addButton->setAutoRaise(true);
247 m_addButton->setIconSize(iconSize);
248 box->addWidget(m_addButton);
250 m_editButton = new QToolButton;
251 m_editButton->setAutoRaise(true);
252 m_editButton->setIconSize(iconSize);
253 box->addWidget(m_editButton);
255 m_deleteButton = new QToolButton;
256 m_deleteButton->setAutoRaise(true);
257 m_deleteButton->setIconSize(iconSize);
258 box->addWidget(m_deleteButton);
259 frame->setLayout(box);
260 layout->addWidget(frame);
262 m_listView = new ProjectListView;
263 layout->addWidget(m_listView);
265 #if KDE_IS_VERSION(4,7,0)
266 m_infoMessage = new KMessageWidget;
267 layout->addWidget(m_infoMessage);
268 m_infoMessage->setCloseButtonVisible(true);
269 //m_infoMessage->setWordWrap(true);
270 m_infoMessage->hide();
271 m_logAction = new QAction(i18n("Show Log"), this);
272 m_logAction->setCheckable(false);
273 connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
277 searchView->setTreeWidget(m_listView);
279 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
280 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
281 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
282 connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
283 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
284 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
285 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
286 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
287 connect(this, SIGNAL(addClip(const QString, const QString &, const QString &)), this, SLOT(slotAddClip(const QString, const QString &, const QString &)));
288 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
289 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
290 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
292 connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap)));
293 connect(this, SIGNAL(processLog(ProjectItem *, int , int)), this, SLOT(slotProcessLog(ProjectItem *, int , int)));
295 connect(this, SIGNAL(jobCrashed(const QString &, const QString &, const QString &, const QString)), this, SLOT(slotJobCrashed(const QString &, const QString &, const QString &, const QString)));
297 m_listViewDelegate = new ItemDelegate(m_listView);
298 m_listView->setItemDelegate(m_listViewDelegate);
300 if (KdenliveSettings::activate_nepomuk()) {
301 Nepomuk::ResourceManager::instance()->init();
302 if (!Nepomuk::ResourceManager::instance()->initialized()) {
303 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
304 KdenliveSettings::setActivate_nepomuk(false);
310 ProjectList::~ProjectList()
312 m_abortAllJobs = true;
314 m_thumbnailQueue.clear();
315 m_jobThreads.waitForFinished();
316 m_jobThreads.clearFutures();
317 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
320 m_listView->blockSignals(true);
322 delete m_listViewDelegate;
323 #if KDE_IS_VERSION(4,7,0)
324 delete m_infoMessage;
328 void ProjectList::focusTree() const
330 m_listView->setFocus();
333 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
335 QList <QAction *> actions = addMenu->actions();
336 for (int i = 0; i < actions.count(); i++) {
337 if (actions.at(i)->data().toString() == "clip_properties") {
338 m_editButton->setDefaultAction(actions.at(i));
341 } else if (actions.at(i)->data().toString() == "delete_clip") {
342 m_deleteButton->setDefaultAction(actions.at(i));
345 } else if (actions.at(i)->data().toString() == "edit_clip") {
346 m_openAction = actions.at(i);
349 } else if (actions.at(i)->data().toString() == "reload_clip") {
350 m_reloadAction = actions.at(i);
353 } else if (actions.at(i)->data().toString() == "proxy_clip") {
354 m_proxyAction = actions.at(i);
360 QMenu *m = new QMenu();
361 m->addActions(actions);
362 m_addButton->setMenu(m);
363 m_addButton->setDefaultAction(defaultAction);
364 m_menu = new QMenu();
365 m_menu->addActions(addMenu->actions());
368 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
370 if (!menus.contains("addMenu") && ! menus.value("addMenu") )
372 QMenu *menu = m_addButton->menu();
373 if (menus.contains("addMenu") && menus.value("addMenu")){
374 QMenu* addMenu=menus.value("addMenu");
375 menu->addMenu(addMenu);
376 m_addButton->setMenu(menu);
378 m_menu->addMenu(addMenu);
379 if (addMenu->isEmpty())
380 addMenu->setEnabled(false);
382 if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
383 QMenu* transcodeMenu=menus.value("transcodeMenu");
384 m_menu->addMenu(transcodeMenu);
385 if (transcodeMenu->isEmpty())
386 transcodeMenu->setEnabled(false);
387 m_transcodeAction = transcodeMenu;
389 if (menus.contains("stabilizeMenu") && menus.value("stabilizeMenu") ){
390 QMenu* stabilizeMenu=menus.value("stabilizeMenu");
391 m_menu->addMenu(stabilizeMenu);
392 if (stabilizeMenu->isEmpty())
393 stabilizeMenu->setEnabled(false);
394 m_stabilizeAction=stabilizeMenu;
397 m_menu->addAction(m_reloadAction);
398 m_menu->addAction(m_proxyAction);
399 if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
400 QMenu* inTimelineMenu=menus.value("inTimelineMenu");
401 m_menu->addMenu(inTimelineMenu);
402 inTimelineMenu->setEnabled(false);
404 m_menu->addAction(m_editButton->defaultAction());
405 m_menu->addAction(m_openAction);
406 m_menu->addAction(m_deleteButton->defaultAction());
407 m_menu->insertSeparator(m_deleteButton->defaultAction());
410 void ProjectList::clearSelection()
412 m_listView->clearSelection();
415 QByteArray ProjectList::headerInfo() const
417 return m_listView->header()->saveState();
420 void ProjectList::setHeaderInfo(const QByteArray &state)
422 m_listView->header()->restoreState(state);
425 void ProjectList::updateProjectFormat(Timecode t)
430 void ProjectList::slotEditClip()
432 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
433 if (list.isEmpty()) return;
434 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
435 editClipSelection(list);
439 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
441 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
442 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
444 item = static_cast <ProjectItem*>(m_listView->currentItem());
445 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
446 emit clipSelected(item->referencedClip());
447 emit showClipProperties(item->referencedClip());
451 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
453 // Gather all common properties
454 QMap <QString, QString> commonproperties;
455 QList <DocClipBase *> clipList;
456 commonproperties.insert("force_aspect_num", "-");
457 commonproperties.insert("force_aspect_den", "-");
458 commonproperties.insert("force_fps", "-");
459 commonproperties.insert("force_progressive", "-");
460 commonproperties.insert("force_tff", "-");
461 commonproperties.insert("threads", "-");
462 commonproperties.insert("video_index", "-");
463 commonproperties.insert("audio_index", "-");
464 commonproperties.insert("force_colorspace", "-");
465 commonproperties.insert("full_luma", "-");
466 QString transparency = "-";
468 bool allowDurationChange = true;
469 int commonDuration = -1;
470 bool hasImages = false;;
472 for (int i = 0; i < list.count(); i++) {
474 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
475 // Add folder items to the list
476 int ct = list.at(i)->childCount();
477 for (int j = 0; j < ct; j++) {
478 list.append(list.at(i)->child(j));
482 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
483 item = static_cast <ProjectItem*>(list.at(i)->parent());
485 item = static_cast <ProjectItem*>(list.at(i));
486 if (!(item->flags() & Qt::ItemIsDragEnabled))
490 DocClipBase *clip = item->referencedClip();
491 if (clipList.contains(clip)) continue;
492 if (clip->clipType() == IMAGE) {
494 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
495 if (transparency == "-") {
496 // first non transparent image
499 else if (transparency == "1") {
500 // we have transparent and non transparent clips
505 if (transparency == "-") {
506 // first transparent image
509 else if (transparency == "0") {
510 // we have transparent and non transparent clips
515 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
516 allowDurationChange = false;
517 if (allowDurationChange && commonDuration != 0) {
518 if (commonDuration == -1)
519 commonDuration = clip->duration().frames(m_fps);
520 else if (commonDuration != clip->duration().frames(m_fps))
523 clipList.append(clip);
524 QMap <QString, QString> clipprops = clip->properties();
525 QMapIterator<QString, QString> p(commonproperties);
526 while (p.hasNext()) {
528 if (p.value().isEmpty()) continue;
529 if (clipprops.contains(p.key())) {
530 if (p.value() == "-")
531 commonproperties.insert(p.key(), clipprops.value(p.key()));
532 else if (p.value() != clipprops.value(p.key()))
533 commonproperties.insert(p.key(), QString());
535 commonproperties.insert(p.key(), QString());
540 if (allowDurationChange)
541 commonproperties.insert("out", QString::number(commonDuration));
543 commonproperties.insert("transparency", transparency);
544 /*QMapIterator<QString, QString> p(commonproperties);
545 while (p.hasNext()) {
547 kDebug() << "Result: " << p.key() << " = " << p.value();
549 emit showClipProperties(clipList, commonproperties);
552 void ProjectList::slotOpenClip()
555 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
557 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
558 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
560 item = static_cast <ProjectItem*>(m_listView->currentItem());
562 if (item->clipType() == IMAGE) {
563 if (KdenliveSettings::defaultimageapp().isEmpty())
564 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
566 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
568 if (item->clipType() == AUDIO) {
569 if (KdenliveSettings::defaultaudioapp().isEmpty())
570 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
572 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
577 void ProjectList::cleanup()
579 m_listView->clearSelection();
580 QTreeWidgetItemIterator it(m_listView);
583 if ((*it)->type() != PROJECTCLIPTYPE) {
587 item = static_cast <ProjectItem *>(*it);
588 if (item->numReferences() == 0)
589 item->setSelected(true);
595 void ProjectList::trashUnusedClips()
597 QTreeWidgetItemIterator it(m_listView);
602 if ((*it)->type() != PROJECTCLIPTYPE) {
606 item = static_cast <ProjectItem *>(*it);
607 if (item->numReferences() == 0) {
608 ids << item->clipId();
609 KUrl url = item->clipUrl();
610 if (!url.isEmpty() && !urls.contains(url.path()))
616 // Check that we don't use the URL in another clip
617 QTreeWidgetItemIterator it2(m_listView);
619 if ((*it2)->type() != PROJECTCLIPTYPE) {
623 item = static_cast <ProjectItem *>(*it2);
624 if (item->numReferences() > 0) {
625 KUrl url = item->clipUrl();
626 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
631 emit deleteProjectClips(ids, QMap <QString, QString>());
632 for (int i = 0; i < urls.count(); i++)
633 KIO::NetAccess::del(KUrl(urls.at(i)), this);
636 void ProjectList::slotReloadClip(const QString &id)
638 QList<QTreeWidgetItem *> selected;
640 selected = m_listView->selectedItems();
642 ProjectItem *itemToReLoad = getItemById(id);
643 if (itemToReLoad) selected.append(itemToReLoad);
646 for (int i = 0; i < selected.count(); i++) {
647 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
648 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
649 for (int j = 0; j < selected.at(i)->childCount(); j++)
650 selected.append(selected.at(i)->child(j));
654 item = static_cast <ProjectItem *>(selected.at(i));
655 if (item && !hasPendingProxy(item)) {
656 DocClipBase *clip = item->referencedClip();
657 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
658 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
661 CLIPTYPE t = item->clipType();
663 if (clip && !clip->getProperty("xmltemplate").isEmpty())
664 regenerateTemplate(item);
665 } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
666 item->referencedClip()->setPlaceHolder(true);
667 item->setProperty("file_hash", QString());
668 } else if (t == IMAGE) {
669 clip->getProducer()->set("force_reload", 1);
672 QDomElement e = item->toXml();
673 // Make sure we get the correct producer length if it was adjusted in timeline
674 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
675 int length = QString(clip->producerProperty("length")).toInt();
676 if (length > 0 && !e.hasAttribute("length")) {
677 e.setAttribute("length", length);
680 resetThumbsProducer(clip);
681 m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
686 void ProjectList::slotModifiedClip(const QString &id)
688 ProjectItem *item = getItemById(id);
690 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
691 if (!pixmap.isNull()) {
693 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
694 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
697 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
699 item->setData(0, Qt::DecorationRole, pixmap);
703 void ProjectList::slotMissingClip(const QString &id)
705 ProjectItem *item = getItemById(id);
707 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
708 int height = m_listView->iconSize().height();
709 int width = (int)(height * m_render->dar());
710 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
711 if (pixmap.isNull()) {
712 pixmap = QPixmap(width, height);
713 pixmap.fill(Qt::transparent);
715 KIcon icon("dialog-close");
717 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
719 item->setData(0, Qt::DecorationRole, pixmap);
720 if (item->referencedClip()) {
721 item->referencedClip()->setPlaceHolder(true);
722 if (m_render == NULL) {
723 kDebug() << "********* ERROR, NULL RENDR";
726 Mlt::Producer *newProd = m_render->invalidProducer(id);
727 if (item->referencedClip()->getProducer()) {
728 Mlt::Properties props(newProd->get_properties());
729 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
730 props.inherit(src_props);
732 item->referencedClip()->setProducer(newProd, true);
733 item->slotSetToolTip();
734 emit clipNeedsReload(id);
738 emit displayMessage(i18n("Check missing clips"), -2);
739 emit updateRenderStatus();
742 void ProjectList::slotAvailableClip(const QString &id)
744 ProjectItem *item = getItemById(id);
747 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
748 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
749 item->setProperty("file_hash", QString());
753 item->referencedClip()->setValid();
754 item->slotSetToolTip();
757 emit updateRenderStatus();
760 bool ProjectList::hasMissingClips()
762 bool missing = false;
763 QTreeWidgetItemIterator it(m_listView);
765 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
774 void ProjectList::setRenderer(Render *projectRender)
776 m_render = projectRender;
777 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
780 void ProjectList::slotClipSelected()
782 QTreeWidgetItem *item = m_listView->currentItem();
783 ProjectItem *clip = NULL;
785 if (item->type() == PROJECTFOLDERTYPE) {
786 emit clipSelected(NULL);
787 m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
788 m_deleteButton->defaultAction()->setEnabled(true);
789 m_openAction->setEnabled(false);
790 m_reloadAction->setEnabled(false);
791 m_transcodeAction->setEnabled(false);
792 m_stabilizeAction->setEnabled(false);
794 if (item->type() == PROJECTSUBCLIPTYPE) {
795 // this is a sub item, use base clip
796 m_deleteButton->defaultAction()->setEnabled(true);
797 clip = static_cast <ProjectItem*>(item->parent());
798 if (clip == NULL) kDebug() << "-----------ERROR";
799 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
800 emit clipSelected(clip->referencedClip(), sub->zone());
801 m_transcodeAction->setEnabled(false);
802 m_stabilizeAction->setEnabled(false);
803 m_reloadAction->setEnabled(false);
804 adjustProxyActions(clip);
807 clip = static_cast <ProjectItem*>(item);
808 if (clip && clip->referencedClip())
809 emit clipSelected(clip->referencedClip());
810 m_editButton->defaultAction()->setEnabled(true);
811 m_deleteButton->defaultAction()->setEnabled(true);
812 m_reloadAction->setEnabled(true);
813 m_transcodeAction->setEnabled(true);
814 m_stabilizeAction->setEnabled(true);
815 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
816 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
817 m_openAction->setEnabled(true);
818 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
819 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
820 m_openAction->setEnabled(true);
822 m_openAction->setEnabled(false);
824 // Display relevant transcoding actions only
825 adjustTranscodeActions(clip);
826 adjustStabilizeActions(clip);
827 // Display uses in timeline
828 emit findInTimeline(clip->clipId());
831 emit clipSelected(NULL);
832 m_editButton->defaultAction()->setEnabled(false);
833 m_deleteButton->defaultAction()->setEnabled(false);
834 m_openAction->setEnabled(false);
835 m_reloadAction->setEnabled(false);
836 m_transcodeAction->setEnabled(false);
837 m_stabilizeAction->setEnabled(false);
839 adjustProxyActions(clip);
842 void ProjectList::adjustProxyActions(ProjectItem *clip) const
844 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
845 m_proxyAction->setEnabled(false);
848 m_proxyAction->setEnabled(useProxy());
849 m_proxyAction->blockSignals(true);
850 m_proxyAction->setChecked(clip->hasProxy());
851 m_proxyAction->blockSignals(false);
854 void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
857 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
858 m_stabilizeAction->setEnabled(false);
861 m_stabilizeAction->setEnabled(true);
865 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
867 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
868 m_transcodeAction->setEnabled(false);
871 m_transcodeAction->setEnabled(true);
872 QList<QAction *> transcodeActions = m_transcodeAction->actions();
875 for (int i = 0; i < transcodeActions.count(); i++) {
876 data = transcodeActions.at(i)->data().toStringList();
877 if (data.count() > 2) {
878 condition = data.at(2);
879 if (condition.startsWith("vcodec"))
880 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
881 else if (condition.startsWith("acodec"))
882 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
888 void ProjectList::slotPauseMonitor()
894 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
896 ProjectItem *item = getItemById(id);
898 slotUpdateClipProperties(item, properties);
899 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
901 } else if (properties.contains("colour") ||
902 properties.contains("xmldata") ||
903 properties.contains("force_aspect_num") ||
904 properties.contains("force_aspect_den") ||
905 properties.contains("templatetext")) {
906 slotRefreshClipThumbnail(item);
907 emit refreshClip(id, true);
908 } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
909 emit refreshClip(id, false);
914 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
918 clip->setProperties(properties);
919 if (properties.contains("proxy")) {
920 if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
921 // this should only apply to proxy jobs
922 clip->setConditionalJobStatus(NOJOB, PROXYJOB);
924 if (properties.contains("name")) {
925 monitorItemEditing(false);
926 clip->setText(0, properties.value("name"));
927 monitorItemEditing(true);
928 emit clipNameChanged(clip->clipId(), properties.value("name"));
930 if (properties.contains("description")) {
931 CLIPTYPE type = clip->clipType();
932 monitorItemEditing(false);
933 clip->setText(1, properties.value("description"));
934 monitorItemEditing(true);
936 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
937 // Use Nepomuk system to store clip description
938 Nepomuk::Resource f(clip->clipUrl().path());
939 f.setDescription(properties.value("description"));
942 emit projectModified();
946 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
948 if (item->type() == PROJECTSUBCLIPTYPE) {
949 // this is a sub-item
951 // user edited description
952 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
953 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
954 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
955 m_commandStack->push(command);
956 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
960 if (item->type() == PROJECTFOLDERTYPE) {
962 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
963 editFolder(item->text(0), folder->groupName(), folder->clipId());
964 folder->setGroupName(item->text(0));
965 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
966 const int children = item->childCount();
967 for (int i = 0; i < children; i++) {
968 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
969 child->setProperty("groupname", item->text(0));
975 ProjectItem *clip = static_cast <ProjectItem*>(item);
977 if (clip->referencedClip()) {
978 QMap <QString, QString> oldprops;
979 QMap <QString, QString> newprops;
980 oldprops["description"] = clip->referencedClip()->getProperty("description");
981 newprops["description"] = item->text(1);
983 if (clip->clipType() == TEXT) {
984 // This is a text template clip, update the image
985 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
986 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
987 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
988 newprops.insert("templatetext", item->text(1));
990 slotUpdateClipProperties(clip->clipId(), newprops);
991 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
992 m_commandStack->push(command);
994 } else if (column == 0) {
995 if (clip->referencedClip()) {
996 QMap <QString, QString> oldprops;
997 QMap <QString, QString> newprops;
998 oldprops["name"] = clip->referencedClip()->getProperty("name");
999 if (oldprops.value("name") != item->text(0)) {
1000 newprops["name"] = item->text(0);
1001 slotUpdateClipProperties(clip, newprops);
1002 emit projectModified();
1003 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1004 m_commandStack->push(command);
1010 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
1012 bool enable = item ? true : false;
1013 m_editButton->defaultAction()->setEnabled(enable);
1014 m_deleteButton->defaultAction()->setEnabled(enable);
1015 m_reloadAction->setEnabled(enable);
1016 m_transcodeAction->setEnabled(enable);
1017 m_stabilizeAction->setEnabled(enable);
1019 ProjectItem *clip = NULL;
1020 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1021 clip = static_cast <ProjectItem*>(item->parent());
1022 m_transcodeAction->setEnabled(false);
1023 m_stabilizeAction->setEnabled(false);
1024 adjustProxyActions(clip);
1025 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
1026 clip = static_cast <ProjectItem*>(item);
1027 // Display relevant transcoding actions only
1028 adjustTranscodeActions(clip);
1029 adjustStabilizeActions(clip);
1030 adjustProxyActions(clip);
1031 // Display uses in timeline
1032 emit findInTimeline(clip->clipId());
1034 m_transcodeAction->setEnabled(false);
1035 m_stabilizeAction->setEnabled(false);
1037 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1038 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1039 m_openAction->setEnabled(true);
1040 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1041 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1042 m_openAction->setEnabled(true);
1044 m_openAction->setEnabled(false);
1048 m_openAction->setEnabled(false);
1053 void ProjectList::slotRemoveClip()
1055 if (!m_listView->currentItem())
1058 QMap <QString, QString> folderids;
1059 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
1061 QUndoCommand *delCommand = new QUndoCommand();
1062 delCommand->setText(i18n("Delete Clip Zone"));
1063 for (int i = 0; i < selected.count(); i++) {
1064 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
1066 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
1067 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1068 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
1069 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
1071 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
1072 folderids[folder->groupName()] = folder->clipId();
1073 int children = folder->childCount();
1075 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)
1077 for (int i = 0; i < children; ++i) {
1078 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
1079 ids << child->clipId();
1082 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
1083 ids << item->clipId();
1084 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) {
1085 KMessageBox::enableMessage("DeleteAll");
1090 KMessageBox::enableMessage("DeleteAll");
1091 if (delCommand->childCount() == 0)
1094 m_commandStack->push(delCommand);
1095 emit deleteProjectClips(ids, folderids);
1098 void ProjectList::updateButtons() const
1100 if (m_listView->topLevelItemCount() == 0) {
1101 m_deleteButton->defaultAction()->setEnabled(false);
1102 m_editButton->defaultAction()->setEnabled(false);
1104 m_deleteButton->defaultAction()->setEnabled(true);
1105 if (!m_listView->currentItem())
1106 m_listView->setCurrentItem(m_listView->topLevelItem(0));
1107 QTreeWidgetItem *item = m_listView->currentItem();
1108 if (item && item->type() == PROJECTCLIPTYPE) {
1109 m_editButton->defaultAction()->setEnabled(true);
1110 m_openAction->setEnabled(true);
1111 m_reloadAction->setEnabled(true);
1112 m_transcodeAction->setEnabled(true);
1113 m_stabilizeAction->setEnabled(true);
1116 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
1117 m_editButton->defaultAction()->setEnabled(true);
1119 else m_editButton->defaultAction()->setEnabled(false);
1121 m_openAction->setEnabled(false);
1122 m_reloadAction->setEnabled(false);
1123 m_transcodeAction->setEnabled(false);
1124 m_stabilizeAction->setEnabled(false);
1125 m_proxyAction->setEnabled(false);
1128 void ProjectList::selectItemById(const QString &clipId)
1130 ProjectItem *item = getItemById(clipId);
1132 m_listView->setCurrentItem(item);
1136 void ProjectList::slotDeleteClip(const QString &clipId)
1138 ProjectItem *item = getItemById(clipId);
1140 kDebug() << "/// Cannot find clip to delete";
1143 deleteJobsForClip(clipId);
1144 m_listView->blockSignals(true);
1145 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1146 if (!newSelectedItem)
1147 newSelectedItem = m_listView->itemBelow(item);
1149 // Pause playing to prevent crash while deleting clip
1151 m_doc->clipManager()->deleteClip(clipId);
1152 m_listView->blockSignals(false);
1153 if (newSelectedItem) {
1154 m_listView->setCurrentItem(newSelectedItem);
1157 emit clipSelected(NULL);
1162 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1164 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1165 m_commandStack->push(command);
1166 m_doc->setModified(true);
1169 void ProjectList::slotAddFolder()
1171 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1172 m_commandStack->push(command);
1175 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
1178 FolderProjectItem *item = getFolderItemById(clipId);
1180 m_doc->clipManager()->deleteFolder(clipId);
1181 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1182 if (!newSelectedItem)
1183 newSelectedItem = m_listView->itemBelow(item);
1185 if (newSelectedItem)
1186 m_listView->setCurrentItem(newSelectedItem);
1192 FolderProjectItem *item = getFolderItemById(clipId);
1194 m_listView->blockSignals(true);
1195 item->setGroupName(foldername);
1196 m_listView->blockSignals(false);
1197 m_doc->clipManager()->addFolder(clipId, foldername);
1198 const int children = item->childCount();
1199 for (int i = 0; i < children; i++) {
1200 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1201 child->setProperty("groupname", foldername);
1205 m_listView->blockSignals(true);
1206 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1207 m_doc->clipManager()->addFolder(clipId, foldername);
1208 m_listView->blockSignals(false);
1209 m_listView->editItem(m_listView->currentItem(), 0);
1213 m_doc->setModified(true);
1218 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1220 QMapIterator<QString, QString> i(map);
1221 QUndoCommand *delCommand = new QUndoCommand();
1222 delCommand->setText(i18n("Delete Folder"));
1223 while (i.hasNext()) {
1225 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1227 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1228 else delete delCommand;
1231 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1233 //m_listView->setEnabled(false);
1234 const QString parent = clip->getProperty("groupid");
1235 ProjectItem *item = NULL;
1236 monitorItemEditing(false);
1237 if (!parent.isEmpty()) {
1238 FolderProjectItem *parentitem = getFolderItemById(parent);
1241 QString groupName = clip->getProperty("groupname");
1242 //kDebug() << "Adding clip to new group: " << groupName;
1243 if (groupName.isEmpty()) groupName = i18n("Folder");
1245 parentitem = new FolderProjectItem(m_listView, text, parent);
1249 item = new ProjectItem(parentitem, clip);
1252 item = new ProjectItem(m_listView, clip);
1254 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1255 connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1256 connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1257 if (getProperties) {
1258 int height = m_listView->iconSize().height();
1259 int width = (int)(height * m_render->dar());
1260 QPixmap pix = KIcon("video-x-generic").pixmap(QSize(width, height));
1261 item->setData(0, Qt::DecorationRole, pix);
1262 //item->setFlags(Qt::ItemIsSelectable);
1263 m_listView->processLayout();
1264 QDomElement e = clip->toXML().cloneNode().toElement();
1265 e.removeAttribute("file_hash");
1266 resetThumbsProducer(clip);
1267 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1269 // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases?
1270 /*else if (item->hasProxy() && !item->isJobRunning()) {
1271 slotCreateProxy(clip->getId());
1274 KUrl url = clip->fileURL();
1276 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
1277 // if file has Nepomuk comment, use it
1278 Nepomuk::Resource f(url.path());
1279 QString annotation = f.description();
1280 if (!annotation.isEmpty()) item->setText(1, annotation);
1281 item->setText(2, QString::number(f.rating()));
1285 // Add info to date column
1286 QFileInfo fileInfo(url.path());
1287 if (fileInfo.exists()) {
1288 item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1292 QList <CutZoneInfo> cuts = clip->cutZones();
1293 if (!cuts.isEmpty()) {
1294 for (int i = 0; i < cuts.count(); i++) {
1295 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1296 if (!clip->getClipHash().isEmpty()) {
1297 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1298 if (QFile::exists(cachedPixmap)) {
1299 QPixmap pix(cachedPixmap);
1301 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1302 sub->setData(0, Qt::DecorationRole, pix);
1307 monitorItemEditing(true);
1311 void ProjectList::slotGotProxy(const QString &proxyPath)
1313 if (proxyPath.isEmpty() || m_abortAllJobs) return;
1314 QTreeWidgetItemIterator it(m_listView);
1317 while (*it && !(m_abortAllJobs && m_closing)) {
1318 if ((*it)->type() == PROJECTCLIPTYPE) {
1319 item = static_cast <ProjectItem *>(*it);
1320 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1327 void ProjectList::slotGotProxy(ProjectItem *item)
1329 if (item == NULL) return;
1330 DocClipBase *clip = item->referencedClip();
1331 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1332 // Clip is being reprocessed, abort
1333 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1337 // Proxy clip successfully created
1338 QDomElement e = clip->toXML().cloneNode().toElement();
1340 // Make sure we get the correct producer length if it was adjusted in timeline
1341 CLIPTYPE t = item->clipType();
1342 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1343 int length = QString(clip->producerProperty("length")).toInt();
1344 if (length > 0 && !e.hasAttribute("length")) {
1345 e.setAttribute("length", length);
1348 resetThumbsProducer(clip);
1349 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1352 void ProjectList::slotResetProjectList()
1354 m_listView->blockSignals(true);
1355 m_abortAllJobs = true;
1357 m_jobThreads.waitForFinished();
1358 m_jobThreads.clearFutures();
1359 m_thumbnailQueue.clear();
1360 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
1362 m_listView->clear();
1363 m_listView->setEnabled(true);
1364 emit clipSelected(NULL);
1365 m_refreshed = false;
1366 m_allClipsProcessed = false;
1367 m_abortAllJobs = false;
1369 m_listView->blockSignals(false);
1372 void ProjectList::slotUpdateClip(const QString &id)
1374 ProjectItem *item = getItemById(id);
1375 monitorItemEditing(false);
1376 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1377 monitorItemEditing(true);
1380 void ProjectList::getCachedThumbnail(ProjectItem *item)
1383 DocClipBase *clip = item->referencedClip();
1385 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1386 if (QFile::exists(cachedPixmap)) {
1387 QPixmap pix(cachedPixmap);
1389 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1390 requestClipThumbnail(item->clipId());
1393 processThumbOverlays(item, pix);
1394 item->setData(0, Qt::DecorationRole, pix);
1398 requestClipThumbnail(item->clipId());
1402 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1405 ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1406 if (!parentItem) return;
1407 DocClipBase *clip = parentItem->referencedClip();
1409 int pos = item->zone().x();
1410 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + "#" + QString::number(pos) + ".png";
1411 if (QFile::exists(cachedPixmap)) {
1412 QPixmap pix(cachedPixmap);
1414 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1415 requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1417 else item->setData(0, Qt::DecorationRole, pix);
1419 else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1422 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1424 if (!m_allClipsProcessed) m_listView->setEnabled(false);
1425 m_listView->setSortingEnabled(false);
1426 QTreeWidgetItemIterator it(m_listView);
1429 monitorItemEditing(false);
1430 int height = m_listView->iconSize().height();
1431 int width = (int)(height * m_render->dar());
1432 QPixmap missingPixmap = QPixmap(width, height);
1433 missingPixmap.fill(Qt::transparent);
1434 KIcon icon("dialog-close");
1435 QPainter p(&missingPixmap);
1436 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1439 int max = m_doc->clipManager()->clipsCount();
1444 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1445 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1447 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1448 if (displayRatioChanged) {
1449 item = static_cast <ProjectItem *>((*it)->parent());
1450 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1452 else if (sub->data(0, Qt::DecorationRole).isNull()) {
1453 getCachedThumbnail(sub);
1457 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1462 item = static_cast <ProjectItem *>(*it);
1463 clip = item->referencedClip();
1464 if (item->referencedClip()->getProducer() == NULL) {
1465 bool replace = false;
1466 if (brokenClips.contains(item->clipId())) {
1467 // if this is a proxy clip, disable proxy
1468 discardJobs(item->clipId(), PROXYJOB);
1469 clip->setProperty("proxy", "-");
1472 if (clip->isPlaceHolder() == false && !hasPendingProxy(item)) {
1473 QDomElement xml = clip->toXML();
1475 xml.removeAttribute("out");
1476 xml.removeAttribute("file_hash");
1477 xml.removeAttribute("proxy_out");
1479 if (!replace) replace = xml.attribute("replace") == "1";
1481 resetThumbsProducer(clip);
1483 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1485 else if (clip->isPlaceHolder()) {
1486 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1487 if (item->data(0, Qt::DecorationRole).isNull()) {
1488 item->setData(0, Qt::DecorationRole, missingPixmap);
1491 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1492 QPainter p(&pixmap);
1493 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1495 item->setData(0, Qt::DecorationRole, pixmap);
1499 if (displayRatioChanged) {
1500 requestClipThumbnail(clip->getId());
1502 else if (item->data(0, Qt::DecorationRole).isNull()) {
1503 getCachedThumbnail(item);
1505 if (item->data(0, DurationRole).toString().isEmpty()) {
1506 item->changeDuration(item->referencedClip()->getProducer()->get_playtime());
1508 if (clip->isPlaceHolder()) {
1509 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1510 if (pixmap.isNull()) {
1511 pixmap = QPixmap(width, height);
1512 pixmap.fill(Qt::transparent);
1514 QPainter p(&pixmap);
1515 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1517 item->setData(0, Qt::DecorationRole, pixmap);
1520 item->setData(0, UsageRole, QString::number(item->numReferences()));
1525 m_listView->setSortingEnabled(true);
1526 m_allClipsProcessed = true;
1527 if (m_render->processingItems() == 0) {
1528 monitorItemEditing(true);
1529 slotProcessNextThumbnail();
1534 QString ProjectList::getExtensions()
1536 // Build list of mime types
1537 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1538 << "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"
1539 << "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"
1540 << "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";
1542 QString allExtensions;
1543 foreach(const QString & mimeType, mimeTypes) {
1544 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1546 allExtensions.append(mime->patterns().join(" "));
1547 allExtensions.append(' ');
1550 return allExtensions.simplified();
1553 void ProjectList::slotAddClip(const QString url, const QString &groupName, const QString &groupId)
1555 kDebug()<<"// Adding clip: "<<url;
1558 slotAddClip(list, groupName, groupId);
1561 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1563 if (!m_commandStack)
1564 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1567 if (givenList.isEmpty()) {
1568 QString allExtensions = getExtensions();
1569 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1570 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1571 b->setChecked(KdenliveSettings::autoimagesequence());
1572 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1573 c->setChecked(KdenliveSettings::autoimagetransparency());
1574 QFrame *f = new QFrame;
1575 f->setFrameShape(QFrame::NoFrame);
1576 QHBoxLayout *l = new QHBoxLayout;
1581 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1582 d->setOperationMode(KFileDialog::Opening);
1583 d->setMode(KFile::Files);
1584 if (d->exec() == QDialog::Accepted) {
1585 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1587 list = d->selectedUrls();
1588 if (b->isChecked() && list.count() == 1) {
1589 // Check for image sequence
1590 KUrl url = list.at(0);
1591 QString fileName = url.fileName().section('.', 0, -2);
1592 if (fileName.at(fileName.size() - 1).isDigit()) {
1593 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1594 if (item.mimetype().startsWith("image")) {
1595 // import as sequence if we found more than one image in the sequence
1597 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1598 int count = list.count();
1601 QStringList groupInfo = getGroup();
1603 // get image sequence base name
1604 while (fileName.at(fileName.size() - 1).isDigit()) {
1608 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1609 false, false, false,
1610 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1611 QString(), groupInfo.at(0), groupInfo.at(1));
1619 for (int i = 0; i < givenList.count(); i++)
1620 list << givenList.at(i);
1623 foreach(const KUrl & file, list) {
1624 // Check there is no folder here
1625 KMimeType::Ptr type = KMimeType::findByUrl(file);
1626 if (type->is("inode/directory")) {
1627 // user dropped a folder
1628 list.removeAll(file);
1635 if (givenList.isEmpty()) {
1636 QStringList groupInfo = getGroup();
1637 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1639 m_doc->slotAddClipList(list, groupName, groupId);
1643 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1645 ProjectItem *item = getItemById(id);
1646 m_processingClips.removeAll(id);
1647 m_thumbnailQueue.removeAll(id);
1649 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1650 const QString path = item->referencedClip()->fileURL().path();
1651 if (item->referencedClip()->isPlaceHolder()) replace = false;
1652 if (!path.isEmpty()) {
1653 if (m_invalidClipDialog) {
1654 m_invalidClipDialog->addClip(id, path);
1659 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1661 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());
1663 m_invalidClipDialog->addClip(id, path);
1664 int result = m_invalidClipDialog->exec();
1665 if (result == KDialog::Yes) replace = true;
1668 if (m_invalidClipDialog) {
1670 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1671 delete m_invalidClipDialog;
1672 m_invalidClipDialog = NULL;
1678 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1680 ProjectItem *item = getItemById(id);
1682 kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1683 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1684 if (durationError) {
1685 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1686 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1688 slotJobCrashed(item, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
1689 QString path = item->referencedClip()->getProperty("proxy");
1690 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1692 //Security check: make sure the invalid proxy file is in the proxy folder
1693 if (proxyFolder.isParentOf(KUrl(path))) {
1694 QFile::remove(path);
1696 if (item->referencedClip()->getProducer() == NULL) {
1697 // Clip has no valid producer, request it
1698 slotProxyCurrentItem(false, item);
1701 // refresh thumbs producer
1702 item->referencedClip()->reloadThumbProducer();
1705 m_processingClips.removeAll(id);
1706 m_thumbnailQueue.removeAll(id);
1709 void ProjectList::slotAddColorClip()
1711 if (!m_commandStack)
1712 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1714 QDialog *dia = new QDialog(this);
1715 Ui::ColorClip_UI dia_ui;
1716 dia_ui.setupUi(dia);
1717 dia->setWindowTitle(i18n("Color Clip"));
1718 dia_ui.clip_name->setText(i18n("Color Clip"));
1720 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1721 t->setValue(KdenliveSettings::color_duration());
1722 dia_ui.clip_durationBox->addWidget(t);
1723 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1725 if (dia->exec() == QDialog::Accepted) {
1726 QString color = dia_ui.clip_color->color().name();
1727 KdenliveSettings::setColorclipcolor(color);
1728 color = color.replace(0, 1, "0x") + "ff";
1729 QStringList groupInfo = getGroup();
1730 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1737 void ProjectList::slotAddSlideshowClip()
1739 if (!m_commandStack)
1740 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1742 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1744 if (dia->exec() == QDialog::Accepted) {
1745 QStringList groupInfo = getGroup();
1746 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1747 dia->loop(), dia->crop(), dia->fade(),
1748 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1749 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1754 void ProjectList::slotAddTitleClip()
1756 QStringList groupInfo = getGroup();
1757 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1760 void ProjectList::slotAddTitleTemplateClip()
1762 if (!m_commandStack)
1763 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1765 QStringList groupInfo = getGroup();
1767 // Get the list of existing templates
1769 filter << "*.kdenlivetitle";
1770 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1771 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1773 QDialog *dia = new QDialog(this);
1774 Ui::TemplateClip_UI dia_ui;
1775 dia_ui.setupUi(dia);
1776 for (int i = 0; i < templateFiles.size(); ++i)
1777 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1779 if (!templateFiles.isEmpty())
1780 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1781 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1782 //warning: setting base directory doesn't work??
1783 KUrl startDir(path);
1784 dia_ui.template_list->fileDialog()->setUrl(startDir);
1785 dia_ui.text_box->setHidden(true);
1786 if (dia->exec() == QDialog::Accepted) {
1787 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1788 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1789 // Create a cloned template clip
1790 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1795 QStringList ProjectList::getGroup() const
1798 QTreeWidgetItem *item = m_listView->currentItem();
1799 while (item && item->type() != PROJECTFOLDERTYPE)
1800 item = item->parent();
1803 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1804 result << folder->groupName() << folder->clipId();
1806 result << QString() << QString();
1811 void ProjectList::setDocument(KdenliveDoc *doc)
1813 m_listView->blockSignals(true);
1814 m_abortAllJobs = true;
1816 m_jobThreads.waitForFinished();
1817 m_jobThreads.clearFutures();
1818 m_thumbnailQueue.clear();
1819 m_listView->clear();
1820 m_processingClips.clear();
1822 m_listView->setSortingEnabled(false);
1823 emit clipSelected(NULL);
1824 m_refreshed = false;
1825 m_allClipsProcessed = false;
1827 m_timecode = doc->timecode();
1828 m_commandStack = doc->commandStack();
1830 m_abortAllJobs = false;
1833 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1834 QStringList openedFolders = doc->getExpandedFolders();
1835 QMapIterator<QString, QString> f(flist);
1836 while (f.hasNext()) {
1838 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1839 folder->setExpanded(openedFolders.contains(f.key()));
1842 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1843 if (list.isEmpty()) {
1846 m_allClipsProcessed = true;
1848 for (int i = 0; i < list.count(); i++)
1849 slotAddClip(list.at(i), false);
1851 m_listView->blockSignals(false);
1852 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1853 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1854 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1855 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1856 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
1859 QList <DocClipBase*> ProjectList::documentClipList() const
1862 return QList <DocClipBase*> ();
1864 return m_doc->clipManager()->documentClipList();
1867 QDomElement ProjectList::producersList()
1870 QDomElement prods = doc.createElement("producerlist");
1871 doc.appendChild(prods);
1872 QTreeWidgetItemIterator it(m_listView);
1874 if ((*it)->type() != PROJECTCLIPTYPE) {
1879 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1885 void ProjectList::slotCheckForEmptyQueue()
1887 if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
1888 if (!m_refreshed && m_allClipsProcessed) {
1890 m_listView->setEnabled(true);
1892 QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
1893 emit displayMessage(QString(), -1);
1896 } else if (!m_refreshed) {
1897 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1902 void ProjectList::requestClipThumbnail(const QString id)
1904 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1905 slotProcessNextThumbnail();
1908 void ProjectList::resetThumbsProducer(DocClipBase *clip)
1911 clip->clearThumbProducer();
1912 QString id = clip->getId();
1913 m_thumbnailQueue.removeAll(id);
1916 void ProjectList::slotProcessNextThumbnail()
1918 if (m_render->processingItems() > 0) {
1921 if (m_thumbnailQueue.isEmpty()) {
1922 slotCheckForEmptyQueue();
1925 int max = m_doc->clipManager()->clipsCount();
1926 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1927 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1930 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1932 QTreeWidgetItem *item = getAnyItemById(clipId);
1934 slotRefreshClipThumbnail(item, update);
1936 slotProcessNextThumbnail();
1940 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1942 if (it == NULL) return;
1943 ProjectItem *item = NULL;
1944 bool isSubItem = false;
1946 if (it->type() == PROJECTFOLDERTYPE) return;
1947 if (it->type() == PROJECTSUBCLIPTYPE) {
1948 item = static_cast <ProjectItem *>(it->parent());
1949 frame = static_cast <SubProjectItem *>(it)->zone().x();
1952 item = static_cast <ProjectItem *>(it);
1953 frame = item->referencedClip()->getClipThumbFrame();
1957 DocClipBase *clip = item->referencedClip();
1959 slotProcessNextThumbnail();
1964 int height = m_listView->iconSize().height();
1965 int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
1966 int dwidth = (int)(height * m_render->dar() + 0.5);
1967 if (clip->clipType() == AUDIO)
1968 pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
1969 else if (clip->clipType() == IMAGE)
1970 img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
1972 img = item->referencedClip()->extractImage(frame, dwidth, height);
1975 if (!pix.isNull() || !img.isNull()) {
1976 monitorItemEditing(false);
1977 if (!img.isNull()) {
1978 pix = QPixmap::fromImage(img);
1979 processThumbOverlays(item, pix);
1981 it->setData(0, Qt::DecorationRole, pix);
1982 monitorItemEditing(true);
1984 QString hash = item->getClipHash();
1985 if (!hash.isEmpty() && !img.isNull()) {
1987 m_doc->cacheImage(hash, img);
1989 m_doc->cacheImage(hash + '#' + QString::number(frame), img);
1993 emit projectModified();
1994 slotProcessNextThumbnail();
1999 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
2002 ProjectItem *item = getItemById(clipId);
2004 int queue = m_render->processingItems();
2005 if (item && producer) {
2006 monitorItemEditing(false);
2007 DocClipBase *clip = item->referencedClip();
2008 if (producer->is_valid()) {
2009 if (clip->isPlaceHolder()) {
2013 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
2015 item->setProperties(properties, metadata);
2016 clip->setProducer(producer, replace);
2019 QString size = properties.value("frame_size");
2020 if (!useProxy() && clip->getProperty("proxy").isEmpty()) {
2021 discardJobs(clipId, PROXYJOB);
2023 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") {
2024 discardJobs(clipId, PROXYJOB);
2026 else if (useProxy() && !item->hasProxy() && !hasPendingProxy(item)) {
2027 // proxy video and image clips
2029 CLIPTYPE t = item->clipType();
2030 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2031 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
2032 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)) {
2033 if (clip->getProperty("proxy").isEmpty()) {
2034 KUrl proxyPath = m_doc->projectFolder();
2035 proxyPath.addPath("proxy/");
2036 proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
2037 QMap <QString, QString> newProps;
2038 // insert required duration for proxy
2039 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
2040 newProps.insert("proxy", proxyPath.path());
2041 QMap <QString, QString> oldProps = clip->properties();
2042 oldProps.insert("proxy", QString());
2043 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
2044 m_doc->commandStack()->push(command);
2049 if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) {
2050 getCachedThumbnail(item);
2052 if (!toReload.isEmpty())
2053 item->slotSetToolTip();
2054 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
2056 monitorItemEditing(true);
2057 if (item && m_thumbnailQueue.isEmpty()) {
2058 if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
2059 m_listView->setCurrentItem(item);
2060 bool updatedProfile = false;
2061 if (item->parent()) {
2062 if (item->parent()->type() == PROJECTFOLDERTYPE)
2063 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
2064 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
2065 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
2066 updatedProfile = adjustProjectProfileToItem(item);
2068 if (updatedProfile == false) {
2069 //emit clipSelected(item->referencedClip());
2072 int max = m_doc->clipManager()->clipsCount();
2073 if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
2075 if (m_allClipsProcessed) emit processNextThumbnail();
2078 // no item for producer, delete it
2082 if (replace) toReload = clipId;
2083 if (!toReload.isEmpty())
2084 emit clipNeedsReload(toReload);
2087 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
2090 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
2091 item = static_cast <ProjectItem*>(m_listView->currentItem());
2093 if (item == NULL || item->referencedClip() == NULL) {
2094 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
2097 bool profileUpdated = false;
2098 QString size = item->referencedClip()->getProperty("frame_size");
2099 int width = size.section('x', 0, 0).toInt();
2100 int height = size.section('x', -1).toInt();
2101 double fps = item->referencedClip()->getProperty("fps").toDouble();
2102 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
2103 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
2104 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
2105 // get a list of compatible profiles
2106 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
2107 if (!suggestedProfiles.isEmpty()) {
2108 KDialog *dialog = new KDialog(this);
2109 dialog->setCaption(i18n("Change project profile"));
2110 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2113 QVBoxLayout *l = new QVBoxLayout;
2114 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));
2115 l->addWidget(label);
2116 QListWidget *list = new QListWidget;
2117 list->setAlternatingRowColors(true);
2118 QMapIterator<QString, QString> i(suggestedProfiles);
2119 while (i.hasNext()) {
2121 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
2122 item->setData(Qt::UserRole, i.key());
2123 item->setToolTip(i.key());
2125 list->setCurrentRow(0);
2127 container.setLayout(l);
2128 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
2129 dialog->setMainWidget(&container);
2130 if (dialog->exec() == QDialog::Accepted) {
2131 //Change project profile
2132 profileUpdated = true;
2133 if (list->currentItem())
2134 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
2138 } else if (fps > 0) {
2139 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));
2143 return profileUpdated;
2146 QString ProjectList::getDocumentProperty(const QString &key) const
2148 return m_doc->getDocumentProperty(key);
2151 bool ProjectList::useProxy() const
2153 return m_doc->getDocumentProperty("enableproxy").toInt();
2156 bool ProjectList::generateProxy() const
2158 return m_doc->getDocumentProperty("generateproxy").toInt();
2161 bool ProjectList::generateImageProxy() const
2163 return m_doc->getDocumentProperty("generateimageproxy").toInt();
2166 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2168 ProjectItem *item = getItemById(clipId);
2169 if (item && !img.isNull()) {
2170 QPixmap pix = QPixmap::fromImage(img);
2171 processThumbOverlays(item, pix);
2172 monitorItemEditing(false);
2173 item->setData(0, Qt::DecorationRole, pix);
2174 monitorItemEditing(true);
2175 QString hash = item->getClipHash();
2176 if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2180 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2182 // For clips that have a generic icon (like audio clips...)
2183 ProjectItem *item = getItemById(clipId);
2184 QPixmap pix = KIcon(name).pixmap(QSize(width, height));
2185 if (item && !pix.isNull()) {
2186 monitorItemEditing(false);
2187 item->setData(0, Qt::DecorationRole, pix);
2188 monitorItemEditing(true);
2192 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2194 QTreeWidgetItemIterator it(m_listView);
2195 QString lookId = id;
2196 if (id.contains('#'))
2197 lookId = id.section('#', 0, 0);
2199 ProjectItem *result = NULL;
2201 if ((*it)->type() != PROJECTCLIPTYPE) {
2206 ProjectItem *item = static_cast<ProjectItem *>(*it);
2207 if (item->clipId() == lookId) {
2213 if (result == NULL || !id.contains('#')) {
2216 for (int i = 0; i < result->childCount(); i++) {
2217 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2218 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2227 ProjectItem *ProjectList::getItemById(const QString &id)
2230 QTreeWidgetItemIterator it(m_listView);
2232 if ((*it)->type() != PROJECTCLIPTYPE) {
2233 // subitem or folder
2237 item = static_cast<ProjectItem *>(*it);
2238 if (item->clipId() == id)
2245 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2247 FolderProjectItem *item;
2248 QTreeWidgetItemIterator it(m_listView);
2250 if ((*it)->type() == PROJECTFOLDERTYPE) {
2251 item = static_cast<FolderProjectItem *>(*it);
2252 if (item->clipId() == id)
2260 void ProjectList::slotSelectClip(const QString &ix)
2262 ProjectItem *clip = getItemById(ix);
2264 m_listView->setCurrentItem(clip);
2265 m_listView->scrollToItem(clip);
2266 m_editButton->defaultAction()->setEnabled(true);
2267 m_deleteButton->defaultAction()->setEnabled(true);
2268 m_reloadAction->setEnabled(true);
2269 m_transcodeAction->setEnabled(true);
2270 m_stabilizeAction->setEnabled(true);
2271 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2272 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2273 m_openAction->setEnabled(true);
2274 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2275 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2276 m_openAction->setEnabled(true);
2278 m_openAction->setEnabled(false);
2283 QString ProjectList::currentClipUrl() const
2286 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2287 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2289 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2291 item = static_cast <ProjectItem*>(m_listView->currentItem());
2295 return item->clipUrl().path();
2298 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2302 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2303 for (int i = 0; i < list.count(); i++) {
2304 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2306 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2308 item = static_cast <ProjectItem*>(list.at(i)->parent());
2310 item = static_cast <ProjectItem*>(list.at(i));
2312 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2314 DocClipBase *clip = item->referencedClip();
2315 if (!condition.isEmpty()) {
2316 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2318 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2321 result.append(item->clipUrl());
2326 void ProjectList::regenerateTemplate(const QString &id)
2328 ProjectItem *clip = getItemById(id);
2330 regenerateTemplate(clip);
2333 void ProjectList::regenerateTemplate(ProjectItem *clip)
2335 //TODO: remove this unused method, only force_reload is necessary
2336 clip->referencedClip()->getProducer()->set("force_reload", 1);
2339 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2343 if (!file.open(QIODevice::ReadOnly)) {
2344 kWarning() << "ERROR, CANNOT READ: " << path;
2347 if (!doc.setContent(&file)) {
2348 kWarning() << "ERROR, CANNOT READ: " << path;
2353 QDomNodeList texts = doc.elementsByTagName("content");
2354 for (int i = 0; i < texts.count(); i++) {
2355 QString data = texts.item(i).firstChild().nodeValue();
2356 data.replace("%s", replaceString);
2357 texts.item(i).firstChild().setNodeValue(data);
2363 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2365 ProjectItem *clip = getItemById(id);
2366 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2368 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2369 m_commandStack->push(command);
2372 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2374 ProjectItem *clip = getItemById(id);
2376 DocClipBase *base = clip->referencedClip();
2377 base->addCutZone(in, out);
2378 monitorItemEditing(false);
2379 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2380 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2381 if (!clip->isExpanded())
2382 clip->setExpanded(true);
2383 m_listView->scrollToItem(sub);
2384 m_listView->editItem(sub, 1);
2386 QImage img = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
2387 sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2388 QString hash = clip->getClipHash();
2389 if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(in), img);
2390 monitorItemEditing(true);
2392 emit projectModified();
2395 void ProjectList::removeClipCut(const QString &id, int in, int out)
2397 ProjectItem *clip = getItemById(id);
2399 DocClipBase *base = clip->referencedClip();
2400 base->removeCutZone(in, out);
2401 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2403 monitorItemEditing(false);
2405 monitorItemEditing(true);
2408 emit projectModified();
2411 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2413 SubProjectItem *sub = NULL;
2415 for (int i = 0; i < clip->childCount(); i++) {
2416 QTreeWidgetItem *it = clip->child(i);
2417 if (it->type() == PROJECTSUBCLIPTYPE) {
2418 sub = static_cast <SubProjectItem*>(it);
2419 if (sub->zone() == zone)
2429 void ProjectList::slotUpdateClipCut(QPoint p)
2431 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2433 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2434 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2435 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2436 m_commandStack->push(command);
2439 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2441 ProjectItem *clip = getItemById(id);
2442 SubProjectItem *sub = getSubItem(clip, oldzone);
2443 if (sub == NULL || clip == NULL)
2445 DocClipBase *base = clip->referencedClip();
2446 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2447 monitorItemEditing(false);
2449 sub->setDescription(comment);
2450 monitorItemEditing(true);
2451 emit projectModified();
2454 void ProjectList::slotForceProcessing(const QString &id)
2456 m_render->forceProcessing(id);
2459 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2461 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2463 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2464 int count = list.count();
2466 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2467 if (!existing.isEmpty()) {
2468 // Sequence already exists, update
2469 QString id = existing.at(0)->getId();
2470 //ProjectItem *item = getItemById(id);
2471 QMap <QString, QString> oldprops;
2472 QMap <QString, QString> newprops;
2473 int ttl = existing.at(0)->getProperty("ttl").toInt();
2474 oldprops["out"] = existing.at(0)->getProperty("out");
2475 newprops["out"] = QString::number(ttl * count - 1);
2476 slotUpdateClipProperties(id, newprops);
2477 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2478 m_commandStack->push(command);
2481 QStringList groupInfo = getGroup();
2482 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
2483 false, false, false,
2484 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
2485 QString(), groupInfo.at(0), groupInfo.at(1));
2487 } else emit displayMessage(i18n("Sequence not found"), -2);
2490 QMap <QString, QString> ProjectList::getProxies()
2492 QMap <QString, QString> list;
2494 QTreeWidgetItemIterator it(m_listView);
2496 if ((*it)->type() != PROJECTCLIPTYPE) {
2500 item = static_cast<ProjectItem *>(*it);
2501 if (item && item->referencedClip() != NULL) {
2502 if (item->hasProxy()) {
2503 QString proxy = item->referencedClip()->getProperty("proxy");
2504 list.insert(proxy, item->clipUrl().path());
2512 void ProjectList::slotCreateProxy(const QString id)
2514 ProjectItem *item = getItemById(id);
2515 if (!item || hasPendingProxy(item) || item->referencedClip()->isPlaceHolder()) return;
2516 QString path = item->referencedClip()->getProperty("proxy");
2517 if (path.isEmpty()) {
2518 slotJobCrashed(item, i18n("Failed to create proxy, empty path."));
2522 if (m_processingProxy.contains(path)) {
2523 // Proxy is already being generated
2526 if (QFileInfo(path).size() > 0) {
2527 // Proxy already created
2528 setJobStatus(item, JOBDONE);
2532 m_processingProxy.append(path);
2534 ProxyJob *job = new ProxyJob(item->clipType(), id, QStringList() << path << item->clipUrl().path() << item->referencedClip()->producerProperty("_exif_orientation") << m_doc->getDocumentProperty("proxyparams").simplified() << QString::number(m_render->frameRenderWidth()) << QString::number(m_render->renderHeight()));
2535 m_jobList.append(job);
2536 setJobStatus(item, JOBWAITING);
2540 void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
2542 ProjectItem *item = getItemById(id);
2543 if (!item|| item->referencedClip()->isPlaceHolder()) return;
2544 QString source = item->clipUrl().path();
2545 QString ext = source.section('.', -1);
2546 QString dest = source.section('.', 0, -2) + "_" + QString::number(zone.x()) + "." + ext;
2548 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2549 if (clipFps == 0) clipFps = m_fps;
2550 // if clip and project have different frame rate, adjust in and out
2553 in = GenTime(in, m_timecode.fps()).frames(clipFps);
2554 out = GenTime(out, m_timecode.fps()).frames(clipFps);
2555 int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
2556 int duration = out - in + 1;
2557 QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
2558 QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
2560 QDialog *d = new QDialog(this);
2561 Ui::CutJobDialog_UI ui;
2563 ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
2564 ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
2565 ui.file_url->setUrl(KUrl(dest));
2566 QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
2567 ui.info_label->setText(mess);
2568 if (d->exec() != QDialog::Accepted) {
2572 dest = ui.file_url->url().path();
2573 bool acceptPath = dest != source;
2574 if (acceptPath && QFileInfo(dest).size() > 0) {
2575 // destination file olready exists, overwrite?
2578 while (!acceptPath) {
2579 // Do not allow to save over original clip
2580 if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
2581 else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
2582 if (d->exec() != QDialog::Accepted) {
2586 dest = ui.file_url->url().path();
2587 acceptPath = dest != source;
2588 if (acceptPath && QFileInfo(dest).size() > 0) {
2592 QString extraParams = ui.extra_params->toPlainText().simplified();
2593 KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
2596 m_processingProxy.append(dest);
2597 QStringList jobParams;
2598 jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_clip_cut());
2599 if (!extraParams.isEmpty()) jobParams << extraParams;
2600 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2601 m_jobList.append(job);
2602 setJobStatus(item, JOBWAITING);
2608 void ProjectList::startJobProcess()
2610 if (!m_jobThreads.futures().isEmpty()) {
2611 // Remove inactive threads
2612 QList <QFuture<void> > futures = m_jobThreads.futures();
2613 m_jobThreads.clearFutures();
2614 for (int i = 0; i < futures.count(); i++)
2615 if (!futures.at(i).isFinished()) {
2616 m_jobThreads.addFuture(futures.at(i));
2620 for (int i = 0; i < m_jobList.count(); i++) {
2621 if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING)
2624 // remove finished jobs
2625 AbstractClipJob *job = m_jobList.takeAt(i);
2630 emit jobCount(count);
2632 if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
2635 void ProjectList::slotAbortProxy(const QString id, const QString path)
2637 QTreeWidgetItemIterator it(m_listView);
2638 ProjectItem *item = getItemById(id);
2640 if (!item->isProxyRunning()) slotGotProxy(item);
2641 discardJobs(id, PROXYJOB);
2644 void ProjectList::slotProcessJobs()
2646 while (!m_jobList.isEmpty() && !m_abortAllJobs) {
2647 emit projectModified();
2648 AbstractClipJob *job = NULL;
2650 for (int i = 0; i < m_jobList.count(); i++) {
2651 if (job == NULL && m_jobList.at(i)->jobStatus == JOBWAITING) {
2652 m_jobList.at(i)->jobStatus = JOBWORKING;
2653 job = m_jobList.at(i);
2656 else if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING)
2660 emit jobCount(count);
2664 QString destination = job->destination();
2666 // Get the list of clips that will need to get progress info
2667 ProjectItem *processingItem = getItemById(job->clipId());
2668 if (processingItem == NULL) {
2669 job->setStatus(JOBDONE);
2673 // Make sure destination path is writable
2674 QFile file(destination);
2675 if (!file.open(QIODevice::WriteOnly)) {
2676 emit jobCrashed(processingItem->clipId(), i18n("Cannot write to path: %1", destination));
2677 m_processingProxy.removeAll(destination);
2678 job->setStatus(JOBCRASHED);
2682 QFile::remove(destination);
2684 //setJobStatus(processingItem, JOBWORKING, 0, job->jobType, job->statusMessage());
2687 QProcess *jobProcess = job->startJob(&success);
2689 if (jobProcess == NULL) {
2692 setJobStatus(processingItem, JOBDONE);
2693 if (job->jobType == PROXYJOB) slotGotProxy(destination);
2694 //TODO: set folder for transcoded clips
2695 else if (job->jobType == CUTJOB) emit addClip(destination, QString(), QString());
2696 job->setStatus(JOBDONE);
2699 QFile::remove(destination);
2700 emit jobCrashed(processingItem->clipId(), job->errorMessage());
2701 job->setStatus(JOBCRASHED);
2703 m_processingProxy.removeAll(destination);
2706 else while (jobProcess->state() != QProcess::NotRunning) {
2707 // building proxy file
2708 if (m_abortAllJobs || job->jobStatus == JOBABORTED) {
2709 job->jobStatus = JOBABORTED;
2710 jobProcess->close();
2711 jobProcess->waitForFinished();
2712 QFile::remove(destination);
2713 m_processingProxy.removeAll(destination);
2715 emit cancelRunningJob(job->clipId(), job->cancelProperties());
2721 int progress = job->processLogInfo();
2722 if (progress > 0) emit processLog(processingItem, progress, job->jobType);
2724 jobProcess->waitForFinished(500);
2726 jobProcess->waitForFinished();
2727 m_processingProxy.removeAll(destination);
2728 if (result == -1) result = jobProcess->exitStatus();
2730 if (result != -2 && QFileInfo(destination).size() == 0) {
2731 job->processLogInfo();
2732 emit jobCrashed(processingItem->clipId(), i18n("Failed to create file"), QString(), job->errorMessage());
2733 job->setStatus(JOBCRASHED);
2736 if (result == QProcess::NormalExit) {
2737 // proxy successfully created
2738 setJobStatus(processingItem, JOBDONE);
2739 if (job->jobType == PROXYJOB) slotGotProxy(destination);
2740 //TODO: set folder for transcoded clips
2741 else if (job->jobType == CUTJOB) {
2742 CutClipJob *cutJob = static_cast<CutClipJob *>(job);
2743 if (cutJob->addClipToProject) emit addClip(destination, QString(), QString());
2745 job->setStatus(JOBDONE);
2747 else if (result == QProcess::CrashExit) {
2748 // Proxy process crashed
2749 QFile::remove(destination);
2750 emit jobCrashed(processingItem->clipId(), i18n("Job crashed"), QString(), job->errorMessage());
2751 job->setStatus(JOBCRASHED);
2755 // Thread finished, cleanup & update count
2757 for (int i = 0; i < m_jobList.count(); i++) {
2758 if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING) {
2762 AbstractClipJob *job = m_jobList.takeAt(i);
2768 emit jobCount(count);
2772 void ProjectList::updateProxyConfig()
2775 QTreeWidgetItemIterator it(m_listView);
2776 QUndoCommand *command = new QUndoCommand();
2777 command->setText(i18n("Update proxy settings"));
2778 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2780 if ((*it)->type() != PROJECTCLIPTYPE) {
2784 item = static_cast<ProjectItem *>(*it);
2789 CLIPTYPE t = item->clipType();
2790 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2791 if (generateProxy() && useProxy() && !hasPendingProxy(item)) {
2792 DocClipBase *clip = item->referencedClip();
2793 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
2794 if (clip->getProperty("proxy").isEmpty()) {
2795 // We need to insert empty proxy in old properties so that undo will work
2796 QMap <QString, QString> oldProps;// = clip->properties();
2797 oldProps.insert("proxy", QString());
2798 QMap <QString, QString> newProps;
2799 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
2800 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2804 else if (item->hasProxy()) {
2806 QMap <QString, QString> newProps;
2807 newProps.insert("proxy", QString());
2808 newProps.insert("replace", "1");
2809 // insert required duration for proxy
2810 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2811 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
2814 else if (t == IMAGE && item->referencedClip() != NULL) {
2815 if (generateImageProxy() && useProxy()) {
2816 DocClipBase *clip = item->referencedClip();
2817 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2818 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
2819 if (clip->getProperty("proxy").isEmpty()) {
2820 // We need to insert empty proxy in old properties so that undo will work
2821 QMap <QString, QString> oldProps = clip->properties();
2822 oldProps.insert("proxy", QString());
2823 QMap <QString, QString> newProps;
2824 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
2825 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2829 else if (item->hasProxy()) {
2831 QMap <QString, QString> newProps;
2832 newProps.insert("proxy", QString());
2833 newProps.insert("replace", "1");
2834 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2839 if (command->childCount() > 0) m_doc->commandStack()->push(command);
2840 else delete command;
2843 void ProjectList::slotProcessLog(ProjectItem *item, int progress, int type)
2845 kDebug()<<"// SET STATUS: "<<progress;
2846 setJobStatus(item, JOBWORKING, progress, (JOBTYPE) type);
2849 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
2851 QList<QTreeWidgetItem *> list;
2852 if (itemToProxy == NULL) list = m_listView->selectedItems();
2853 else list << itemToProxy;
2855 // expand list (folders, subclips) to get real clips
2856 QTreeWidgetItem *listItem;
2857 QList<ProjectItem *> clipList;
2858 for (int i = 0; i < list.count(); i++) {
2859 listItem = list.at(i);
2860 if (listItem->type() == PROJECTFOLDERTYPE) {
2861 for (int j = 0; j < listItem->childCount(); j++) {
2862 QTreeWidgetItem *sub = listItem->child(j);
2863 if (sub->type() == PROJECTCLIPTYPE) {
2864 ProjectItem *item = static_cast <ProjectItem*>(sub);
2865 if (!clipList.contains(item)) clipList.append(item);
2869 else if (listItem->type() == PROJECTSUBCLIPTYPE) {
2870 QTreeWidgetItem *sub = listItem->parent();
2871 ProjectItem *item = static_cast <ProjectItem*>(sub);
2872 if (!clipList.contains(item)) clipList.append(item);
2874 else if (listItem->type() == PROJECTCLIPTYPE) {
2875 ProjectItem *item = static_cast <ProjectItem*>(listItem);
2876 if (!clipList.contains(item)) clipList.append(item);
2880 QUndoCommand *command = new QUndoCommand();
2881 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
2882 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
2884 // Make sure the proxy folder exists
2885 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2886 KStandardDirs::makeDir(proxydir);
2888 QMap <QString, QString> newProps;
2889 QMap <QString, QString> oldProps;
2890 if (!doProxy) newProps.insert("proxy", "-");
2891 for (int i = 0; i < clipList.count(); i++) {
2892 ProjectItem *item = clipList.at(i);
2893 CLIPTYPE t = item->clipType();
2894 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
2895 if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
2896 DocClipBase *clip = item->referencedClip();
2897 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
2898 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
2902 //oldProps = clip->properties();
2905 QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
2906 // insert required duration for proxy
2907 newProps.insert("proxy_out", clip->producerProperty("out"));
2908 newProps.insert("proxy", path);
2909 // We need to insert empty proxy so that undo will work
2910 //oldProps.insert("proxy", QString());
2912 else if (item->referencedClip()->getProducer() == NULL) {
2913 // Force clip reload
2914 kDebug()<<"// CLIP HAD NULL PROD------------";
2915 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
2917 // We need to insert empty proxy so that undo will work
2918 oldProps = clip->currentProperties(newProps);
2919 if (doProxy) oldProps.insert("proxy", "-");
2920 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
2923 if (command->childCount() > 0) {
2924 m_doc->commandStack()->push(command);
2926 else delete command;
2930 void ProjectList::slotDeleteProxy(const QString proxyPath)
2932 if (proxyPath.isEmpty()) return;
2933 QUndoCommand *proxyCommand = new QUndoCommand();
2934 proxyCommand->setText(i18n("Remove Proxy"));
2935 QTreeWidgetItemIterator it(m_listView);
2938 if ((*it)->type() == PROJECTCLIPTYPE) {
2939 item = static_cast <ProjectItem *>(*it);
2940 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
2941 QMap <QString, QString> props;
2942 props.insert("proxy", QString());
2943 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
2949 if (proxyCommand->childCount() == 0)
2950 delete proxyCommand;
2952 m_commandStack->push(proxyCommand);
2953 QFile::remove(proxyPath);
2956 void ProjectList::setJobStatus(ProjectItem *item, CLIPJOBSTATUS status, int progress, JOBTYPE jobType, const QString &statusMessage)
2958 if (item == NULL || (m_abortAllJobs && m_closing)) return;
2959 monitorItemEditing(false);
2960 item->setJobStatus(status, progress, jobType);
2961 if (status == JOBCRASHED) {
2962 DocClipBase *clip = item->referencedClip();
2964 kDebug()<<"// PROXY CRASHED";
2966 else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
2967 // disable proxy and fetch real clip
2968 clip->setProperty("proxy", "-");
2969 QDomElement xml = clip->toXML();
2970 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
2973 // Disable proxy for this clip
2974 clip->setProperty("proxy", "-");
2977 monitorItemEditing(true);
2980 void ProjectList::monitorItemEditing(bool enable)
2982 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2983 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2986 QStringList ProjectList::expandedFolders() const
2989 FolderProjectItem *item;
2990 QTreeWidgetItemIterator it(m_listView);
2992 if ((*it)->type() != PROJECTFOLDERTYPE) {
2996 if ((*it)->isExpanded()) {
2997 item = static_cast<FolderProjectItem *>(*it);
2998 result.append(item->clipId());
3005 void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
3007 if (item->hasProxy()) {
3009 QColor c = QPalette().base().color();
3013 p.setPen(Qt::NoPen);
3014 QRect r(1, 1, 10, 10);
3016 p.setPen(QPalette().text().color());
3017 p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
3021 void ProjectList::slotCancelJobs()
3023 m_abortAllJobs = true;
3024 m_jobThreads.waitForFinished();
3025 m_jobThreads.clearFutures();
3026 QUndoCommand *command = new QUndoCommand();
3027 command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
3028 for (int i = 0; i < m_jobList.count(); i++) {
3029 ProjectItem *item = getItemById(m_jobList.at(i)->clipId());
3030 if (!item || !item->referencedClip()) continue;
3031 QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
3032 if (newProps.isEmpty()) continue;
3033 QMap <QString, QString> oldProps = item->referencedClip()->currentProperties(newProps);
3034 new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command);
3036 if (command->childCount() > 0) {
3037 m_doc->commandStack()->push(command);
3039 else delete command;
3040 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
3041 m_processingProxy.clear();
3043 m_abortAllJobs = false;
3044 m_infoLabel->slotSetJobCount(0);
3047 void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
3049 if (newProps.isEmpty()) return;
3050 ProjectItem *item = getItemById(id);
3051 if (!item || !item->referencedClip()) return;
3052 QMap <QString, QString> oldProps = item->referencedClip()->currentProperties(newProps);
3053 if (newProps == oldProps) return;
3054 QMapIterator<QString, QString> i(oldProps);
3055 EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
3056 m_commandStack->push(command);
3059 bool ProjectList::hasPendingProxy(ProjectItem *item)
3061 if (!item || !item->referencedClip() || m_abortAllJobs) return false;
3062 for (int i = 0; i < m_jobList.count(); i++) {
3063 if (m_abortAllJobs) break;
3064 if (m_jobList.at(i)->clipId() == item->clipId() && m_jobList.at(i)->jobType == PROXYJOB) return true;
3066 if (item->isProxyRunning()) return true;
3070 void ProjectList::deleteJobsForClip(const QString &clipId)
3072 for (int i = 0; i < m_jobList.count(); i++) {
3073 if (m_abortAllJobs) break;
3074 if (m_jobList.at(i)->clipId() == clipId) {
3075 m_jobList.at(i)->setStatus(JOBABORTED);
3080 void ProjectList::slotJobCrashed(const QString &id, const QString &label, const QString &actionName, const QString details)
3082 ProjectItem *item = getItemById(id);
3084 slotJobCrashed(item, label, actionName, details);
3088 void ProjectList::slotJobCrashed(ProjectItem *item, const QString &label, const QString &actionName, const QString details)
3090 #if KDE_IS_VERSION(4,7,0)
3091 m_infoMessage->animatedHide();
3093 m_infoMessage->setText(label);
3094 m_infoMessage->setWordWrap(label.length() > 35);
3095 m_infoMessage->setMessageType(KMessageWidget::Warning);
3096 QList<QAction *> actions = m_infoMessage->actions();
3097 for (int i = 0; i < actions.count(); i++) {
3098 m_infoMessage->removeAction(actions.at(i));
3101 if (!actionName.isEmpty()) {
3103 QList< KActionCollection * > collections = KActionCollection::allCollections();
3104 for (int i = 0; i < collections.count(); i++) {
3105 KActionCollection *coll = collections.at(i);
3106 action = coll->action(actionName);
3109 if (action) m_infoMessage->addAction(action);
3111 if (!details.isEmpty()) {
3112 m_errorLog = details;
3113 m_infoMessage->addAction(m_logAction);
3115 m_infoMessage->animatedShow();
3117 item->setJobStatus(JOBCRASHED);
3121 void ProjectList::slotShowJobLog()
3123 #if KDE_IS_VERSION(4,7,0)
3125 d.setButtons(KDialog::Close);
3127 t.setPlainText(m_errorLog);
3128 t.setReadOnly(true);
3129 d.setMainWidget(&t);
3134 void ProjectList::discardJobs(const QString &id, JOBTYPE type) {
3135 for (int i = 0; i < m_jobList.count(); i++) {
3136 if (m_jobList.at(i)->clipId() == id && m_jobList.at(i)->jobType == type) {
3138 m_jobList.at(i)->setStatus(JOBABORTED);
3144 #include "projectlist.moc"