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 "projecttree/meltjob.h"
26 #include "kdenlivesettings.h"
27 #include "slideshowclip.h"
28 #include "ui_colorclip_ui.h"
29 #include "titlewidget.h"
30 #include "definitions.h"
31 #include "clipmanager.h"
32 #include "docclipbase.h"
33 #include "kdenlivedoc.h"
36 #include "projectlistview.h"
37 #include "timecodedisplay.h"
38 #include "profilesdialog.h"
39 #include "clipstabilize.h"
40 #include "commands/editclipcommand.h"
41 #include "commands/editclipcutcommand.h"
42 #include "commands/editfoldercommand.h"
43 #include "commands/addclipcutcommand.h"
45 #include "ui_templateclip_ui.h"
46 #include "ui_cutjobdialog_ui.h"
47 #include "ui_scenecutdialog_ui.h"
52 #include <KFileDialog>
53 #include <KInputDialog>
54 #include <KMessageBox>
55 #include <KIO/NetAccess>
57 #include <KApplication>
58 #include <KStandardDirs>
59 #include <KColorScheme>
60 #include <KActionCollection>
61 #include <KUrlRequester>
66 #include <nepomuk/global.h>
67 #include <nepomuk/resourcemanager.h>
68 #include <Nepomuk/Resource>
69 //#include <nepomuk/tag.h>
72 #include <QMouseEvent>
73 #include <QStylePainter>
79 #include <QHeaderView>
80 #include <QInputDialog>
81 #include <QtConcurrentRun>
82 #include <QVBoxLayout>
83 #include <KPassivePopup>
86 MyMessageWidget::MyMessageWidget(QWidget *parent) : KMessageWidget(parent) {}
87 MyMessageWidget::MyMessageWidget(const QString &text, QWidget *parent) : KMessageWidget(text, parent) {}
90 bool MyMessageWidget::event(QEvent* ev) {
91 if (ev->type() == QEvent::Hide || ev->type() == QEvent::Close) emit messageClosing();
92 return KMessageWidget::event(ev);
95 SmallInfoLabel::SmallInfoLabel(QWidget *parent) : QPushButton(parent)
100 /*QString style = "QToolButton {background-color: %1;border-style: outset;border-width: 2px;
101 border-radius: 5px;border-color: beige;}";*/
102 m_timeLine = new QTimeLine(500, this);
103 QObject::connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(slotTimeLineChanged(qreal)));
104 QObject::connect(m_timeLine, SIGNAL(finished()), this, SLOT(slotTimeLineFinished()));
108 const QString SmallInfoLabel::getStyleSheet(const QPalette &p)
110 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
111 QColor bg = scheme.background(KColorScheme::LinkBackground).color();
112 QColor fg = scheme.foreground(KColorScheme::LinkText).color();
113 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());
115 bg = scheme.background(KColorScheme::ActiveBackground).color();
116 fg = scheme.foreground(KColorScheme::ActiveText).color();
117 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()));
122 void SmallInfoLabel::slotTimeLineChanged(qreal value)
124 setFixedWidth(qMin(value * 2, qreal(1.0)) * sizeHint().width());
128 void SmallInfoLabel::slotTimeLineFinished()
130 if (m_timeLine->direction() == QTimeLine::Forward) {
140 void SmallInfoLabel::slotSetJobCount(int jobCount)
144 setText(i18np("%1 job", "%1 jobs", jobCount));
145 setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
147 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
148 setFixedWidth(sizeHint().width());
154 setFixedWidth(sizeHint().width());
161 int wantedWidth = sizeHint().width();
162 setGeometry(-wantedWidth, 0, wantedWidth, height());
163 m_timeLine->setDirection(QTimeLine::Forward);
164 if (m_timeLine->state() == QTimeLine::NotRunning) {
169 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
175 m_timeLine->setDirection(QTimeLine::Backward);
176 if (m_timeLine->state() == QTimeLine::NotRunning) {
184 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
187 if (infoOnly) setButtons(KDialog::Ok);
188 else setButtons(KDialog::Yes | KDialog::No);
189 QWidget *w = new QWidget(this);
190 QVBoxLayout *l = new QVBoxLayout;
191 l->addWidget(new QLabel(message));
192 m_clipList = new QListWidget;
193 l->addWidget(m_clipList);
198 InvalidDialog::~InvalidDialog()
204 void InvalidDialog::addClip(const QString &id, const QString &path)
206 QListWidgetItem *item = new QListWidgetItem(path);
207 item->setData(Qt::UserRole, id);
208 m_clipList->addItem(item);
211 QStringList InvalidDialog::getIds() const
214 for (int i = 0; i < m_clipList->count(); i++) {
215 ids << m_clipList->item(i)->data(Qt::UserRole).toString();
221 ProjectList::ProjectList(QWidget *parent) :
225 m_commandStack(NULL),
227 m_reloadAction(NULL),
228 m_extractAudioAction(NULL),
229 m_transcodeAction(NULL),
230 m_stabilizeAction(NULL),
233 m_allClipsProcessed(false),
235 m_abortAllJobs(false),
237 m_invalidClipDialog(NULL)
239 qRegisterMetaType<stringMap> ("stringMap");
240 QVBoxLayout *layout = new QVBoxLayout;
241 layout->setContentsMargins(0, 0, 0, 0);
242 layout->setSpacing(0);
243 qRegisterMetaType<QDomElement>("QDomElement");
245 QFrame *frame = new QFrame;
246 frame->setFrameStyle(QFrame::NoFrame);
247 QHBoxLayout *box = new QHBoxLayout;
248 box->setContentsMargins(0, 0, 0, 0);
250 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
251 box->addWidget(searchView);
253 // small info button for pending jobs
254 m_infoLabel = new SmallInfoLabel(this);
255 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(palette()));
256 connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
257 m_jobsMenu = new QMenu(this);
258 connect(m_jobsMenu, SIGNAL(aboutToShow()), this, SLOT(slotPrepareJobsMenu()));
259 QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this);
260 cancelJobs->setCheckable(false);
261 connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs()));
262 connect(this, SIGNAL(checkJobProcess()), this, SLOT(slotCheckJobProcess()));
263 m_discardCurrentClipJobs = new QAction(i18n("Cancel Current Clip Jobs"), this);
264 m_discardCurrentClipJobs->setCheckable(false);
265 connect(m_discardCurrentClipJobs, SIGNAL(triggered()), this, SLOT(slotDiscardClipJobs()));
266 m_jobsMenu->addAction(cancelJobs);
267 m_jobsMenu->addAction(m_discardCurrentClipJobs);
268 m_infoLabel->setMenu(m_jobsMenu);
269 box->addWidget(m_infoLabel);
271 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
272 QSize iconSize(size, size);
274 m_addButton = new QToolButton;
275 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
276 m_addButton->setAutoRaise(true);
277 m_addButton->setIconSize(iconSize);
278 box->addWidget(m_addButton);
280 m_editButton = new QToolButton;
281 m_editButton->setAutoRaise(true);
282 m_editButton->setIconSize(iconSize);
283 box->addWidget(m_editButton);
285 m_deleteButton = new QToolButton;
286 m_deleteButton->setAutoRaise(true);
287 m_deleteButton->setIconSize(iconSize);
288 box->addWidget(m_deleteButton);
289 frame->setLayout(box);
290 layout->addWidget(frame);
292 m_listView = new ProjectListView(this);
293 layout->addWidget(m_listView);
295 #if KDE_IS_VERSION(4,7,0)
296 m_infoMessage = new MyMessageWidget;
297 layout->addWidget(m_infoMessage);
298 m_infoMessage->setCloseButtonVisible(true);
299 connect(m_infoMessage, SIGNAL(messageClosing()), this, SLOT(slotResetInfoMessage()));
300 //m_infoMessage->setWordWrap(true);
301 m_infoMessage->hide();
302 m_logAction = new QAction(i18n("Show Log"), this);
303 m_logAction->setCheckable(false);
304 connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
308 searchView->setTreeWidget(m_listView);
310 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
311 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
312 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
313 connect(m_listView, SIGNAL(focusMonitor(bool)), this, SIGNAL(raiseClipMonitor(bool)));
314 connect(m_listView, SIGNAL(pauseMonitor()), this, SIGNAL(pauseMonitor()));
315 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
316 connect(m_listView, SIGNAL(addClip()), this, SIGNAL(pauseMonitor()));
317 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
318 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
319 connect(this, SIGNAL(addClip(const QString, const QString &, const QString &)), this, SLOT(slotAddClip(const QString, const QString &, const QString &)));
320 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
321 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
322 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
324 connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap)));
325 connect(this, SIGNAL(processLog(const QString, int , int, const QString)), this, SLOT(slotProcessLog(const QString, int , int, const QString)));
327 connect(this, SIGNAL(updateJobStatus(const QString, int, int, const QString, const QString, const QString)), this, SLOT(slotUpdateJobStatus(const QString, int, int, const QString, const QString, const QString)));
329 connect(this, SIGNAL(gotProxy(const QString)), this, SLOT(slotGotProxyForId(const QString)));
331 m_listViewDelegate = new ItemDelegate(m_listView);
332 m_listView->setItemDelegate(m_listViewDelegate);
334 if (KdenliveSettings::activate_nepomuk()) {
335 Nepomuk::ResourceManager::instance()->init();
336 if (!Nepomuk::ResourceManager::instance()->initialized()) {
337 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
338 KdenliveSettings::setActivate_nepomuk(false);
344 ProjectList::~ProjectList()
346 m_abortAllJobs = true;
347 for (int i = 0; i < m_jobList.count(); i++) {
348 m_jobList.at(i)->setStatus(JOBABORTED);
351 m_thumbnailQueue.clear();
352 m_jobThreads.waitForFinished();
353 m_jobThreads.clearFutures();
354 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
357 m_listView->blockSignals(true);
359 delete m_listViewDelegate;
360 #if KDE_IS_VERSION(4,7,0)
361 delete m_infoMessage;
365 void ProjectList::focusTree() const
367 m_listView->setFocus();
370 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
372 QList <QAction *> actions = addMenu->actions();
373 for (int i = 0; i < actions.count(); i++) {
374 if (actions.at(i)->data().toString() == "clip_properties") {
375 m_editButton->setDefaultAction(actions.at(i));
378 } else if (actions.at(i)->data().toString() == "delete_clip") {
379 m_deleteButton->setDefaultAction(actions.at(i));
382 } else if (actions.at(i)->data().toString() == "edit_clip") {
383 m_openAction = actions.at(i);
386 } else if (actions.at(i)->data().toString() == "reload_clip") {
387 m_reloadAction = actions.at(i);
390 } else if (actions.at(i)->data().toString() == "proxy_clip") {
391 m_proxyAction = actions.at(i);
397 QMenu *m = new QMenu();
398 m->addActions(actions);
399 m_addButton->setMenu(m);
400 m_addButton->setDefaultAction(defaultAction);
401 m_menu = new QMenu();
402 m_menu->addActions(addMenu->actions());
405 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
407 if (!menus.contains("addMenu") && ! menus.value("addMenu") )
409 QMenu *menu = m_addButton->menu();
410 if (menus.contains("addMenu") && menus.value("addMenu")){
411 QMenu* addMenu=menus.value("addMenu");
412 menu->addMenu(addMenu);
413 m_addButton->setMenu(menu);
414 if (addMenu->isEmpty())
415 addMenu->setEnabled(false);
417 if (menus.contains("extractAudioMenu") && menus.value("extractAudioMenu") ){
418 QMenu* extractAudioMenu = menus.value("extractAudioMenu");
419 m_menu->addMenu(extractAudioMenu);
420 m_extractAudioAction = extractAudioMenu;
422 if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
423 QMenu* transcodeMenu = menus.value("transcodeMenu");
424 m_menu->addMenu(transcodeMenu);
425 if (transcodeMenu->isEmpty())
426 transcodeMenu->setEnabled(false);
427 m_transcodeAction = transcodeMenu;
429 if (menus.contains("clipActionsMenu") && menus.value("clipActionsMenu") ){
430 QMenu* stabilizeMenu=menus.value("clipActionsMenu");
431 m_menu->addMenu(stabilizeMenu);
432 if (stabilizeMenu->isEmpty())
433 stabilizeMenu->setEnabled(false);
434 m_stabilizeAction=stabilizeMenu;
437 m_menu->addAction(m_reloadAction);
438 m_menu->addAction(m_proxyAction);
439 if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
440 QMenu* inTimelineMenu=menus.value("inTimelineMenu");
441 m_menu->addMenu(inTimelineMenu);
442 inTimelineMenu->setEnabled(false);
444 m_menu->addAction(m_editButton->defaultAction());
445 m_menu->addAction(m_openAction);
446 m_menu->addAction(m_deleteButton->defaultAction());
447 m_menu->insertSeparator(m_deleteButton->defaultAction());
450 void ProjectList::clearSelection()
452 m_listView->clearSelection();
455 QByteArray ProjectList::headerInfo() const
457 return m_listView->header()->saveState();
460 void ProjectList::setHeaderInfo(const QByteArray &state)
462 m_listView->header()->restoreState(state);
465 void ProjectList::updateProjectFormat(Timecode t)
470 void ProjectList::slotEditClip()
472 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
473 if (list.isEmpty()) return;
474 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
475 editClipSelection(list);
479 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
481 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
482 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
484 item = static_cast <ProjectItem*>(m_listView->currentItem());
485 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
486 emit clipSelected(item->referencedClip());
487 emit showClipProperties(item->referencedClip());
491 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
493 // Gather all common properties
494 QMap <QString, QString> commonproperties;
495 QList <DocClipBase *> clipList;
496 commonproperties.insert("force_aspect_num", "-");
497 commonproperties.insert("force_aspect_den", "-");
498 commonproperties.insert("force_fps", "-");
499 commonproperties.insert("force_progressive", "-");
500 commonproperties.insert("force_tff", "-");
501 commonproperties.insert("threads", "-");
502 commonproperties.insert("video_index", "-");
503 commonproperties.insert("audio_index", "-");
504 commonproperties.insert("force_colorspace", "-");
505 commonproperties.insert("full_luma", "-");
506 QString transparency = "-";
508 bool allowDurationChange = true;
509 int commonDuration = -1;
510 bool hasImages = false;;
512 for (int i = 0; i < list.count(); i++) {
514 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
515 // Add folder items to the list
516 int ct = list.at(i)->childCount();
517 for (int j = 0; j < ct; j++) {
518 list.append(list.at(i)->child(j));
522 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
523 item = static_cast <ProjectItem*>(list.at(i)->parent());
525 item = static_cast <ProjectItem*>(list.at(i));
526 if (!(item->flags() & Qt::ItemIsDragEnabled))
530 DocClipBase *clip = item->referencedClip();
531 if (clipList.contains(clip)) continue;
532 if (clip->clipType() == IMAGE) {
534 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
535 if (transparency == "-") {
536 // first non transparent image
539 else if (transparency == "1") {
540 // we have transparent and non transparent clips
545 if (transparency == "-") {
546 // first transparent image
549 else if (transparency == "0") {
550 // we have transparent and non transparent clips
555 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
556 allowDurationChange = false;
557 if (allowDurationChange && commonDuration != 0) {
558 if (commonDuration == -1)
559 commonDuration = clip->duration().frames(m_fps);
560 else if (commonDuration != clip->duration().frames(m_fps))
563 clipList.append(clip);
564 QMap <QString, QString> clipprops = clip->properties();
565 QMapIterator<QString, QString> p(commonproperties);
566 while (p.hasNext()) {
568 if (p.value().isEmpty()) continue;
569 if (clipprops.contains(p.key())) {
570 if (p.value() == "-")
571 commonproperties.insert(p.key(), clipprops.value(p.key()));
572 else if (p.value() != clipprops.value(p.key()))
573 commonproperties.insert(p.key(), QString());
575 commonproperties.insert(p.key(), QString());
580 if (allowDurationChange)
581 commonproperties.insert("out", QString::number(commonDuration));
583 commonproperties.insert("transparency", transparency);
584 /*QMapIterator<QString, QString> p(commonproperties);
585 while (p.hasNext()) {
587 kDebug() << "Result: " << p.key() << " = " << p.value();
589 if (clipList.isEmpty()) {
590 emit displayMessage(i18n("No available clip selected"), -2, ErrorMessage);
592 else emit showClipProperties(clipList, commonproperties);
595 void ProjectList::slotOpenClip()
598 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
600 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
601 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
603 item = static_cast <ProjectItem*>(m_listView->currentItem());
605 if (item->clipType() == IMAGE) {
606 if (KdenliveSettings::defaultimageapp().isEmpty())
607 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
609 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
611 if (item->clipType() == AUDIO) {
612 if (KdenliveSettings::defaultaudioapp().isEmpty())
613 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
615 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
620 void ProjectList::cleanup()
622 m_listView->clearSelection();
623 QTreeWidgetItemIterator it(m_listView);
626 if ((*it)->type() != PROJECTCLIPTYPE) {
630 item = static_cast <ProjectItem *>(*it);
631 if (item->numReferences() == 0)
632 item->setSelected(true);
638 void ProjectList::trashUnusedClips()
640 QTreeWidgetItemIterator it(m_listView);
645 if ((*it)->type() != PROJECTCLIPTYPE) {
649 item = static_cast <ProjectItem *>(*it);
650 if (item->numReferences() == 0) {
651 ids << item->clipId();
652 KUrl url = item->clipUrl();
653 if (!url.isEmpty() && !urls.contains(url.path()))
659 // Check that we don't use the URL in another clip
660 QTreeWidgetItemIterator it2(m_listView);
662 if ((*it2)->type() != PROJECTCLIPTYPE) {
666 item = static_cast <ProjectItem *>(*it2);
667 if (item->numReferences() > 0) {
668 KUrl url = item->clipUrl();
669 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
674 emit deleteProjectClips(ids, QMap <QString, QString>());
675 for (int i = 0; i < urls.count(); i++)
676 KIO::NetAccess::del(KUrl(urls.at(i)), this);
679 void ProjectList::slotReloadClip(const QString &id)
681 QList<QTreeWidgetItem *> selected;
683 selected = m_listView->selectedItems();
685 ProjectItem *itemToReLoad = getItemById(id);
686 if (itemToReLoad) selected.append(itemToReLoad);
689 for (int i = 0; i < selected.count(); i++) {
690 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
691 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
692 for (int j = 0; j < selected.at(i)->childCount(); j++)
693 selected.append(selected.at(i)->child(j));
697 item = static_cast <ProjectItem *>(selected.at(i));
698 if (item && !hasPendingJob(item, PROXYJOB)) {
699 DocClipBase *clip = item->referencedClip();
700 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
701 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
704 CLIPTYPE t = item->clipType();
706 if (clip && !clip->getProperty("xmltemplate").isEmpty())
707 regenerateTemplate(item);
708 } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
709 item->referencedClip()->setPlaceHolder(true);
710 item->setProperty("file_hash", QString());
711 } else if (t == IMAGE) {
712 //clip->getProducer() clip->getProducer()->set("force_reload", 1);
715 QDomElement e = item->toXml();
716 // Make sure we get the correct producer length if it was adjusted in timeline
717 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
718 int length = QString(clip->producerProperty("length")).toInt();
719 if (length > 0 && !e.hasAttribute("length")) {
720 e.setAttribute("length", length);
722 e.setAttribute("duration", clip->getProperty("duration"));
724 resetThumbsProducer(clip);
725 m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
730 void ProjectList::slotModifiedClip(const QString &id)
732 ProjectItem *item = getItemById(id);
734 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
735 if (!pixmap.isNull()) {
737 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
738 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
741 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
743 item->setPixmap(pixmap);
747 void ProjectList::slotMissingClip(const QString &id)
749 ProjectItem *item = getItemById(id);
751 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
752 int height = m_listView->iconSize().height();
753 if (m_render == NULL) {
754 kDebug() << "********* ERROR, NULL RENDR";
757 int width = (int)(height * m_render->dar());
758 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
759 if (pixmap.isNull()) {
760 pixmap = QPixmap(width, height);
761 pixmap.fill(Qt::transparent);
763 KIcon icon("dialog-close");
765 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
767 item->setPixmap(pixmap);
768 if (item->referencedClip()) {
769 item->referencedClip()->setPlaceHolder(true);
770 Mlt::Producer *newProd = m_render->invalidProducer(id);
771 if (item->referencedClip()->getProducer()) {
772 Mlt::Properties props(newProd->get_properties());
773 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
774 props.inherit(src_props);
776 item->referencedClip()->setProducer(newProd, true);
777 item->slotSetToolTip();
778 emit clipNeedsReload(id);
782 emit displayMessage(i18n("Check missing clips"), -2, ErrorMessage);
783 emit updateRenderStatus();
786 void ProjectList::slotAvailableClip(const QString &id)
788 ProjectItem *item = getItemById(id);
791 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
792 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
793 item->setProperty("file_hash", QString());
797 item->referencedClip()->setValid();
798 item->slotSetToolTip();
801 emit updateRenderStatus();
804 bool ProjectList::hasMissingClips()
806 bool missing = false;
807 QTreeWidgetItemIterator it(m_listView);
809 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
818 void ProjectList::setRenderer(Render *projectRender)
820 m_render = projectRender;
821 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
822 connect(m_render, SIGNAL(requestProxy(QString)), this, SLOT(slotCreateProxy(QString)));
825 void ProjectList::slotClipSelected()
827 QTreeWidgetItem *item = m_listView->currentItem();
828 ProjectItem *clip = NULL;
830 if (item->type() == PROJECTFOLDERTYPE) {
831 emit clipSelected(NULL);
832 m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
833 m_deleteButton->defaultAction()->setEnabled(true);
834 m_openAction->setEnabled(false);
835 m_reloadAction->setEnabled(false);
836 m_extractAudioAction->setEnabled(false);
837 m_transcodeAction->setEnabled(false);
838 m_stabilizeAction->setEnabled(false);
840 if (item->type() == PROJECTSUBCLIPTYPE) {
841 // this is a sub item, use base clip
842 m_deleteButton->defaultAction()->setEnabled(true);
843 clip = static_cast <ProjectItem*>(item->parent());
844 if (clip == NULL) kDebug() << "-----------ERROR";
845 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
846 if (clip->referencedClip()->getProducer() == NULL) m_render->getFileProperties(clip->referencedClip()->toXML(), clip->clipId(), m_listView->iconSize().height(), true);
847 emit clipSelected(clip->referencedClip(), sub->zone());
848 m_extractAudioAction->setEnabled(false);
849 m_transcodeAction->setEnabled(false);
850 m_stabilizeAction->setEnabled(false);
851 m_reloadAction->setEnabled(false);
852 adjustProxyActions(clip);
855 clip = static_cast <ProjectItem*>(item);
856 if (clip && clip->referencedClip())
857 emit clipSelected(clip->referencedClip());
858 if (clip->referencedClip()->getProducer() == NULL) m_render->getFileProperties(clip->referencedClip()->toXML(), clip->clipId(), m_listView->iconSize().height(), true);
859 m_editButton->defaultAction()->setEnabled(true);
860 m_deleteButton->defaultAction()->setEnabled(true);
861 m_reloadAction->setEnabled(true);
862 m_extractAudioAction->setEnabled(true);
863 m_transcodeAction->setEnabled(true);
864 m_stabilizeAction->setEnabled(true);
865 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
866 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
867 m_openAction->setEnabled(true);
868 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
869 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
870 m_openAction->setEnabled(true);
872 m_openAction->setEnabled(false);
874 // Display relevant transcoding actions only
875 adjustTranscodeActions(clip);
876 adjustStabilizeActions(clip);
877 // Display uses in timeline
878 emit findInTimeline(clip->clipId());
881 emit clipSelected(NULL);
882 m_editButton->defaultAction()->setEnabled(false);
883 m_deleteButton->defaultAction()->setEnabled(false);
884 m_openAction->setEnabled(false);
885 m_reloadAction->setEnabled(false);
886 m_extractAudioAction->setEnabled(true);
887 m_transcodeAction->setEnabled(false);
888 m_stabilizeAction->setEnabled(false);
890 adjustProxyActions(clip);
893 void ProjectList::adjustProxyActions(ProjectItem *clip) const
895 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
896 m_proxyAction->setEnabled(false);
899 bool enabled = useProxy();
900 if (clip->referencedClip() && !clip->referencedClip()->getProperty("_missingsource").isEmpty()) enabled = false;
901 m_proxyAction->setEnabled(enabled);
902 m_proxyAction->blockSignals(true);
903 m_proxyAction->setChecked(clip->hasProxy());
904 m_proxyAction->blockSignals(false);
907 void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
910 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW) {
911 m_stabilizeAction->setEnabled(false);
914 m_stabilizeAction->setEnabled(true);
918 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
920 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
921 m_transcodeAction->setEnabled(false);
922 m_extractAudioAction->setEnabled(false);
925 m_transcodeAction->setEnabled(true);
926 m_extractAudioAction->setEnabled(true);
927 QList<QAction *> transcodeActions = m_transcodeAction->actions();
930 for (int i = 0; i < transcodeActions.count(); i++) {
931 data = transcodeActions.at(i)->data().toStringList();
932 if (data.count() > 2) {
933 condition = data.at(2);
934 if (condition.startsWith("vcodec"))
935 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
936 else if (condition.startsWith("acodec"))
937 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
943 void ProjectList::slotPauseMonitor()
949 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
951 ProjectItem *item = getItemById(id);
953 slotUpdateClipProperties(item, properties);
954 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource") || properties.contains("video_index") || properties.contains("audio_index") || properties.contains("full_luma")) {
956 } else if (properties.contains("colour") ||
957 properties.contains("xmldata") ||
958 properties.contains("force_aspect_num") ||
959 properties.contains("force_aspect_den") ||
960 properties.contains("templatetext")) {
961 slotRefreshClipThumbnail(item);
962 emit refreshClip(id, true);
963 } else if (properties.contains("force_colorspace") || properties.contains("loop")) {
964 emit refreshClip(id, false);
969 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
973 clip->setProperties(properties);
974 if (properties.contains("proxy")) {
975 if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
976 // this should only apply to proxy jobs
977 clip->setConditionalJobStatus(NOJOB, PROXYJOB);
979 if (properties.contains("name")) {
980 monitorItemEditing(false);
981 clip->setText(0, properties.value("name"));
982 monitorItemEditing(true);
983 emit clipNameChanged(clip->clipId(), properties.value("name"));
985 if (properties.contains("description")) {
986 CLIPTYPE type = clip->clipType();
987 monitorItemEditing(false);
988 clip->setText(1, properties.value("description"));
989 monitorItemEditing(true);
991 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
992 // Use Nepomuk system to store clip description
993 Nepomuk::Resource f(clip->clipUrl().path());
994 f.setDescription(properties.value("description"));
997 emit projectModified();
1001 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
1003 if (item->type() == PROJECTSUBCLIPTYPE) {
1004 // this is a sub-item
1006 // user edited description
1007 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
1008 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1009 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
1010 m_commandStack->push(command);
1011 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
1015 if (item->type() == PROJECTFOLDERTYPE) {
1017 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
1018 editFolder(item->text(0), folder->groupName(), folder->clipId());
1019 folder->setGroupName(item->text(0));
1020 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
1021 const int children = item->childCount();
1022 for (int i = 0; i < children; i++) {
1023 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1024 child->setProperty("groupname", item->text(0));
1030 ProjectItem *clip = static_cast <ProjectItem*>(item);
1032 if (clip->referencedClip()) {
1033 QMap <QString, QString> oldprops;
1034 QMap <QString, QString> newprops;
1035 oldprops["description"] = clip->referencedClip()->getProperty("description");
1036 newprops["description"] = item->text(1);
1038 if (clip->clipType() == TEXT) {
1039 // This is a text template clip, update the image
1040 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
1041 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
1042 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
1043 newprops.insert("templatetext", item->text(1));
1045 slotUpdateClipProperties(clip->clipId(), newprops);
1046 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1047 m_commandStack->push(command);
1049 } else if (column == 0) {
1050 if (clip->referencedClip()) {
1051 QMap <QString, QString> oldprops;
1052 QMap <QString, QString> newprops;
1053 oldprops["name"] = clip->referencedClip()->getProperty("name");
1054 if (oldprops.value("name") != item->text(0)) {
1055 newprops["name"] = item->text(0);
1056 slotUpdateClipProperties(clip, newprops);
1057 emit projectModified();
1058 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1059 m_commandStack->push(command);
1060 QTimer::singleShot(100, this, SLOT(slotCheckScrolling()));
1066 void ProjectList::slotCheckScrolling()
1068 m_listView->scrollToItem(m_listView->currentItem());
1071 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
1073 bool enable = item ? true : false;
1074 m_editButton->defaultAction()->setEnabled(enable);
1075 m_deleteButton->defaultAction()->setEnabled(enable);
1076 m_reloadAction->setEnabled(enable);
1077 m_extractAudioAction->setEnabled(enable);
1078 m_transcodeAction->setEnabled(enable);
1079 m_stabilizeAction->setEnabled(enable);
1081 ProjectItem *clip = NULL;
1082 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1083 clip = static_cast <ProjectItem*>(item->parent());
1084 m_extractAudioAction->setEnabled(false);
1085 m_transcodeAction->setEnabled(false);
1086 m_stabilizeAction->setEnabled(false);
1087 adjustProxyActions(clip);
1088 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
1089 clip = static_cast <ProjectItem*>(item);
1090 // Display relevant transcoding actions only
1091 adjustTranscodeActions(clip);
1092 adjustStabilizeActions(clip);
1093 adjustProxyActions(clip);
1094 // Display uses in timeline
1095 emit findInTimeline(clip->clipId());
1097 m_extractAudioAction->setEnabled(false);
1098 m_transcodeAction->setEnabled(false);
1099 m_stabilizeAction->setEnabled(false);
1101 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1102 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1103 m_openAction->setEnabled(true);
1104 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1105 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1106 m_openAction->setEnabled(true);
1108 m_openAction->setEnabled(false);
1112 m_openAction->setEnabled(false);
1117 void ProjectList::slotRemoveClip()
1119 if (!m_listView->currentItem())
1122 QMap <QString, QString> folderids;
1123 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
1125 QUndoCommand *delCommand = new QUndoCommand();
1126 delCommand->setText(i18n("Delete Clip Zone"));
1127 for (int i = 0; i < selected.count(); i++) {
1128 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
1130 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
1131 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1132 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
1133 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
1135 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
1136 folderids[folder->groupName()] = folder->clipId();
1137 int children = folder->childCount();
1139 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)
1141 for (int i = 0; i < children; ++i) {
1142 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
1143 ids << child->clipId();
1146 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
1147 ids << item->clipId();
1148 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->text(1)), i18n("Delete Clip"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteAll") == KMessageBox::No) {
1149 KMessageBox::enableMessage("DeleteAll");
1154 KMessageBox::enableMessage("DeleteAll");
1155 if (delCommand->childCount() == 0)
1158 m_commandStack->push(delCommand);
1159 emit deleteProjectClips(ids, folderids);
1162 void ProjectList::updateButtons() const
1164 if (m_listView->topLevelItemCount() == 0) {
1165 m_deleteButton->defaultAction()->setEnabled(false);
1166 m_editButton->defaultAction()->setEnabled(false);
1168 m_deleteButton->defaultAction()->setEnabled(true);
1169 if (!m_listView->currentItem())
1170 m_listView->setCurrentItem(m_listView->topLevelItem(0));
1171 QTreeWidgetItem *item = m_listView->currentItem();
1172 if (item && item->type() == PROJECTCLIPTYPE) {
1173 m_editButton->defaultAction()->setEnabled(true);
1174 m_openAction->setEnabled(true);
1175 m_reloadAction->setEnabled(true);
1176 m_transcodeAction->setEnabled(true);
1177 m_stabilizeAction->setEnabled(true);
1180 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
1181 m_editButton->defaultAction()->setEnabled(true);
1183 else m_editButton->defaultAction()->setEnabled(false);
1185 m_openAction->setEnabled(false);
1186 m_reloadAction->setEnabled(false);
1187 m_transcodeAction->setEnabled(false);
1188 m_stabilizeAction->setEnabled(false);
1189 m_proxyAction->setEnabled(false);
1192 void ProjectList::selectItemById(const QString &clipId)
1194 ProjectItem *item = getItemById(clipId);
1196 m_listView->setCurrentItem(item);
1200 void ProjectList::slotDeleteClip(const QString &clipId)
1202 ProjectItem *item = getItemById(clipId);
1204 kDebug() << "/// Cannot find clip to delete";
1207 deleteJobsForClip(clipId);
1208 m_listView->blockSignals(true);
1209 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1210 if (!newSelectedItem)
1211 newSelectedItem = m_listView->itemBelow(item);
1213 // Pause playing to prevent crash while deleting clip
1215 m_doc->clipManager()->deleteClip(clipId);
1216 m_listView->blockSignals(false);
1217 if (newSelectedItem) {
1218 m_listView->setCurrentItem(newSelectedItem);
1221 emit clipSelected(NULL);
1226 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1228 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1229 m_commandStack->push(command);
1230 m_doc->setModified(true);
1233 void ProjectList::slotAddFolder(const QString &name)
1235 AddFolderCommand *command = new AddFolderCommand(this, name.isEmpty() ? i18n("Folder") : name, QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1236 m_commandStack->push(command);
1239 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
1242 FolderProjectItem *item = getFolderItemById(clipId);
1244 m_doc->clipManager()->deleteFolder(clipId);
1245 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1246 if (!newSelectedItem)
1247 newSelectedItem = m_listView->itemBelow(item);
1249 if (newSelectedItem)
1250 m_listView->setCurrentItem(newSelectedItem);
1256 FolderProjectItem *item = getFolderItemById(clipId);
1258 m_listView->blockSignals(true);
1259 item->setGroupName(foldername);
1260 m_listView->blockSignals(false);
1261 m_doc->clipManager()->addFolder(clipId, foldername);
1262 const int children = item->childCount();
1263 for (int i = 0; i < children; i++) {
1264 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1265 child->setProperty("groupname", foldername);
1269 m_listView->blockSignals(true);
1270 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1271 m_doc->clipManager()->addFolder(clipId, foldername);
1272 m_listView->blockSignals(false);
1273 m_listView->editItem(m_listView->currentItem(), 0);
1277 m_doc->setModified(true);
1282 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1284 QMapIterator<QString, QString> i(map);
1285 QUndoCommand *delCommand = new QUndoCommand();
1286 delCommand->setText(i18n("Delete Folder"));
1287 while (i.hasNext()) {
1289 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1291 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1292 else delete delCommand;
1295 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1297 //m_listView->setEnabled(false);
1298 const QString parent = clip->getProperty("groupid");
1299 QString groupName = clip->getProperty("groupname");
1300 QSize pixelSize((int)(m_listView->iconSize().height() * m_render->dar()), m_listView->iconSize().height());
1301 ProjectItem *item = NULL;
1302 monitorItemEditing(false);
1303 if (!parent.isEmpty()) {
1304 FolderProjectItem *parentitem = getFolderItemById(parent);
1307 //kDebug() << "Adding clip to new group: " << groupName;
1308 if (groupName.isEmpty()) groupName = i18n("Folder");
1310 parentitem = new FolderProjectItem(m_listView, text, parent);
1314 item = new ProjectItem(parentitem, clip, pixelSize);
1317 item = new ProjectItem(m_listView, clip, pixelSize);
1319 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1320 connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1321 connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1323 if (getProperties) {
1324 //item->setFlags(Qt::ItemIsSelectable);
1325 m_listView->processLayout();
1326 QDomElement e = clip->toXML().cloneNode().toElement();
1327 if (!groupName.isEmpty()) {
1328 e.setAttribute("groupId", parent);
1329 e.setAttribute("group", groupName);
1331 e.removeAttribute("file_hash");
1332 resetThumbsProducer(clip);
1333 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1335 // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases?
1336 /*else if (item->hasProxy() && !item->isJobRunning()) {
1337 slotCreateProxy(clip->getId());
1340 KUrl url = clip->fileURL();
1342 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk() && clip->getProperty("description").isEmpty()) {
1343 // if file has Nepomuk comment, use it
1344 Nepomuk::Resource f(url.path());
1345 QString annotation = f.description();
1346 if (!annotation.isEmpty()) {
1347 item->setText(1, annotation);
1348 clip->setProperty("description", annotation);
1350 item->setText(2, QString::number(f.rating()));
1354 // Add info to date column
1355 QFileInfo fileInfo(url.path());
1356 if (fileInfo.exists()) {
1357 item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1361 QList <CutZoneInfo> cuts = clip->cutZones();
1362 if (!cuts.isEmpty()) {
1363 for (int i = 0; i < cuts.count(); i++) {
1364 SubProjectItem *sub = new SubProjectItem(m_render->dar(), item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1365 if (!clip->getClipHash().isEmpty()) {
1366 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1367 if (QFile::exists(cachedPixmap)) {
1368 QPixmap pix(cachedPixmap);
1370 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1371 sub->setData(0, Qt::DecorationRole, pix);
1376 monitorItemEditing(true);
1380 void ProjectList::slotGotProxy(const QString &proxyPath)
1382 if (proxyPath.isEmpty() || m_abortAllJobs) return;
1383 QTreeWidgetItemIterator it(m_listView);
1386 while (*it && !m_closing) {
1387 if ((*it)->type() == PROJECTCLIPTYPE) {
1388 item = static_cast <ProjectItem *>(*it);
1389 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1396 void ProjectList::slotGotProxyForId(const QString id)
1398 if (m_closing) return;
1399 ProjectItem *item = getItemById(id);
1403 void ProjectList::slotGotProxy(ProjectItem *item)
1405 if (item == NULL) return;
1406 DocClipBase *clip = item->referencedClip();
1407 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1408 // Clip is being reprocessed, abort
1409 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1413 // Proxy clip successfully created
1414 QDomElement e = clip->toXML().cloneNode().toElement();
1416 // Make sure we get the correct producer length if it was adjusted in timeline
1417 CLIPTYPE t = item->clipType();
1418 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1419 int length = QString(clip->producerProperty("length")).toInt();
1420 if (length > 0 && !e.hasAttribute("length")) {
1421 e.setAttribute("length", length);
1424 resetThumbsProducer(clip);
1425 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1428 void ProjectList::slotResetProjectList()
1430 m_listView->blockSignals(true);
1431 m_abortAllJobs = true;
1432 for (int i = 0; i < m_jobList.count(); i++) {
1433 m_jobList.at(i)->setStatus(JOBABORTED);
1436 m_jobThreads.waitForFinished();
1437 m_jobThreads.clearFutures();
1438 m_thumbnailQueue.clear();
1439 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
1441 m_listView->clear();
1442 m_listView->setEnabled(true);
1443 emit clipSelected(NULL);
1444 m_refreshed = false;
1445 m_allClipsProcessed = false;
1446 m_abortAllJobs = false;
1448 m_listView->blockSignals(false);
1451 void ProjectList::slotUpdateClip(const QString &id)
1453 ProjectItem *item = getItemById(id);
1454 monitorItemEditing(false);
1455 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1456 monitorItemEditing(true);
1459 void ProjectList::getCachedThumbnail(ProjectItem *item)
1462 DocClipBase *clip = item->referencedClip();
1466 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1467 if (QFile::exists(cachedPixmap)) {
1468 QPixmap pix(cachedPixmap);
1470 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1471 requestClipThumbnail(item->clipId());
1474 QPixmap result = roundedPixmap(pix);
1475 processThumbOverlays(item, result);
1476 item->setPixmap(result);
1480 requestClipThumbnail(item->clipId());
1484 QPixmap ProjectList::roundedPixmap(QImage img)
1486 QPixmap pix(img.width(), img.height());
1487 pix.fill(Qt::transparent);
1489 p.setRenderHint(QPainter::Antialiasing, true);
1491 path.addRoundedRect(0.5, 0.5, pix.width() - 1, pix.height() - 1, 2, 2);
1492 p.setClipPath(path);
1493 p.drawImage(0, 0, img);
1498 QPixmap ProjectList::roundedPixmap(QPixmap source)
1500 QPixmap pix(source.width(), source.height());
1501 pix.fill(Qt::transparent);
1503 p.setRenderHint(QPainter::Antialiasing, true);
1505 path.addRoundedRect(0.5, 0.5, pix.width() - 1, pix.height() - 1, 2, 2);
1506 p.setClipPath(path);
1507 p.drawPixmap(0, 0, source);
1512 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1515 ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1516 if (!parentItem) return;
1517 DocClipBase *clip = parentItem->referencedClip();
1519 int pos = item->zone().x();
1520 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(pos) + ".png";
1521 if (QFile::exists(cachedPixmap)) {
1522 QPixmap pix(cachedPixmap);
1524 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1525 requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1527 else item->setData(0, Qt::DecorationRole, pix);
1529 else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1532 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1534 if (!m_allClipsProcessed) m_listView->setEnabled(false);
1535 m_listView->setSortingEnabled(false);
1536 QTreeWidgetItemIterator it(m_listView);
1539 monitorItemEditing(false);
1540 int height = m_listView->iconSize().height();
1541 int width = (int)(height * m_render->dar());
1542 QPixmap missingPixmap = QPixmap(width, height);
1543 missingPixmap.fill(Qt::transparent);
1544 KIcon icon("dialog-close");
1545 QPainter p(&missingPixmap);
1546 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1549 int max = m_doc->clipManager()->clipsCount();
1554 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1555 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1557 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1558 if (displayRatioChanged) {
1559 item = static_cast <ProjectItem *>((*it)->parent());
1560 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1562 else if (sub->data(0, Qt::DecorationRole).isNull()) {
1563 getCachedThumbnail(sub);
1567 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1572 item = static_cast <ProjectItem *>(*it);
1573 clip = item->referencedClip();
1574 if (clip->getProducer() == NULL) {
1575 bool replace = false;
1576 if (brokenClips.contains(item->clipId())) {
1577 // if this is a proxy clip, disable proxy
1578 item->setConditionalJobStatus(NOJOB, PROXYJOB);
1579 discardJobs(item->clipId(), PROXYJOB);
1580 clip->setProperty("proxy", "-");
1583 if (clip->isPlaceHolder() == false && !hasPendingJob(item, PROXYJOB)) {
1584 QDomElement xml = clip->toXML();
1585 getCachedThumbnail(item);
1587 xml.removeAttribute("out");
1588 xml.removeAttribute("file_hash");
1589 xml.removeAttribute("proxy_out");
1591 if (!replace) replace = xml.attribute("_replaceproxy") == "1";
1592 xml.removeAttribute("_replaceproxy");
1594 resetThumbsProducer(clip);
1595 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1598 else if (clip->isPlaceHolder()) {
1599 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1600 if (!item->hasPixmap()) {
1601 item->setPixmap(missingPixmap);
1604 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1605 QPainter p(&pixmap);
1606 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1608 item->setPixmap(pixmap);
1612 if (displayRatioChanged) {
1613 requestClipThumbnail(clip->getId());
1615 else if (!item->hasPixmap()) {
1616 getCachedThumbnail(item);
1618 if (item->data(0, DurationRole).toString().isEmpty()) {
1619 item->changeDuration(clip->getProducer()->get_playtime());
1621 if (clip->isPlaceHolder()) {
1622 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1623 if (pixmap.isNull()) {
1624 pixmap = QPixmap(width, height);
1625 pixmap.fill(Qt::transparent);
1627 QPainter p(&pixmap);
1628 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1630 item->setPixmap(pixmap);
1632 else if (clip->getProperty("_replaceproxy") == "1") {
1633 clip->setProperty("_replaceproxy", QString());
1634 slotCreateProxy(clip->getId());
1637 item->setData(0, UsageRole, QString::number(item->numReferences()));
1642 m_listView->setSortingEnabled(true);
1643 m_allClipsProcessed = true;
1644 if (m_render->processingItems() == 0) {
1645 monitorItemEditing(true);
1646 slotProcessNextThumbnail();
1651 QString ProjectList::getExtensions()
1653 // Build list of mime types
1654 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain";
1657 mimeTypes << "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" << "video/3gpp" << "video/mp2t";
1660 mimeTypes << "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" << "audio/ac3";
1663 mimeTypes << "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";
1665 QString allExtensions;
1666 foreach(const QString & mimeType, mimeTypes) {
1667 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1669 allExtensions.append(mime->patterns().join(" "));
1670 allExtensions.append(' ');
1673 return allExtensions.simplified();
1676 void ProjectList::slotAddClip(const QString url, const QString &groupName, const QString &groupId)
1678 kDebug()<<"// Adding clip: "<<url;
1681 slotAddClip(list, groupName, groupId);
1684 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1686 if (!m_commandStack)
1687 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1690 if (givenList.isEmpty()) {
1691 QString allExtensions = getExtensions();
1692 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1693 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1694 b->setChecked(KdenliveSettings::autoimagesequence());
1695 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1696 c->setChecked(KdenliveSettings::autoimagetransparency());
1697 QFrame *f = new QFrame;
1698 f->setFrameShape(QFrame::NoFrame);
1699 QHBoxLayout *l = new QHBoxLayout;
1704 QPointer<KFileDialog> d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1705 d->setOperationMode(KFileDialog::Opening);
1706 d->setMode(KFile::Files);
1707 if (d->exec() == QDialog::Accepted) {
1708 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1710 list = d->selectedUrls();
1711 if (b->isChecked() && list.count() == 1) {
1712 // Check for image sequence
1713 KUrl url = list.at(0);
1714 QString fileName = url.fileName().section('.', 0, -2);
1715 if (fileName.at(fileName.size() - 1).isDigit()) {
1716 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1717 if (item.mimetype().startsWith("image")) {
1718 // import as sequence if we found more than one image in the sequence
1720 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1721 int count = list.count();
1724 QStringList groupInfo = getGroup();
1726 // get image sequence base name
1727 while (fileName.at(fileName.size() - 1).isDigit()) {
1730 QMap <QString, QString> properties;
1731 properties.insert("name", fileName);
1732 properties.insert("resource", pattern);
1733 properties.insert("in", "0");
1734 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
1735 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
1736 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
1737 properties.insert("loop", QString::number(false));
1738 properties.insert("crop", QString::number(false));
1739 properties.insert("fade", QString::number(false));
1740 properties.insert("luma_duration", QString::number(m_doc->getFramePos(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))))));
1741 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1749 for (int i = 0; i < givenList.count(); i++)
1750 list << givenList.at(i);
1752 QList <KUrl::List> foldersList;
1754 foreach(const KUrl & file, list) {
1755 // Check there is no folder here
1756 KMimeType::Ptr type = KMimeType::findByUrl(file);
1757 if (type->is("inode/directory")) {
1758 // user dropped a folder, import its files
1759 list.removeAll(file);
1760 QDir dir(file.path());
1761 QStringList result = dir.entryList(QDir::Files);
1762 KUrl::List folderFiles;
1763 folderFiles << file;
1764 foreach(const QString & path, result) {
1765 KUrl newFile = file;
1766 newFile.addPath(path);
1767 folderFiles.append(newFile);
1769 if (folderFiles.count() > 1) foldersList.append(folderFiles);
1773 if (givenList.isEmpty() && !list.isEmpty()) {
1774 QStringList groupInfo = getGroup();
1775 QMap <QString, QString> data;
1776 data.insert("group", groupInfo.at(0));
1777 data.insert("groupId", groupInfo.at(1));
1778 m_doc->slotAddClipList(list, data);
1779 } else if (!list.isEmpty()) {
1780 QMap <QString, QString> data;
1781 data.insert("group", groupName);
1782 data.insert("groupId", groupId);
1783 m_doc->slotAddClipList(list, data);
1786 if (!foldersList.isEmpty()) {
1788 for (int i = 0; i < foldersList.count(); i++) {
1789 KUrl::List urls = foldersList.at(i);
1790 KUrl folderUrl = urls.takeFirst();
1791 QString folderName = folderUrl.fileName();
1792 FolderProjectItem *folder = NULL;
1793 if (!folderName.isEmpty()) {
1794 folder = getFolderItemByName(folderName);
1795 if (folder == NULL) {
1796 slotAddFolder(folderName);
1797 folder = getFolderItemByName(folderName);
1801 QMap <QString, QString> data;
1802 data.insert("group", folder->groupName());
1803 data.insert("groupId", folder->clipId());
1804 m_doc->slotAddClipList(urls, data);
1806 else m_doc->slotAddClipList(urls);
1811 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1813 ProjectItem *item = getItemById(id);
1814 m_thumbnailQueue.removeAll(id);
1816 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1817 const QString path = item->referencedClip()->fileURL().path();
1818 if (item->referencedClip()->isPlaceHolder()) replace = false;
1819 if (!path.isEmpty()) {
1820 if (m_invalidClipDialog) {
1821 m_invalidClipDialog->addClip(id, path);
1826 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1828 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());
1830 m_invalidClipDialog->addClip(id, path);
1831 int result = m_invalidClipDialog->exec();
1832 if (result == KDialog::Yes) replace = true;
1835 if (m_invalidClipDialog) {
1837 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1838 delete m_invalidClipDialog;
1839 m_invalidClipDialog = NULL;
1845 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1847 ProjectItem *item = getItemById(id);
1849 kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1850 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1851 if (durationError) {
1852 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1853 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2, ErrorMessage);
1855 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
1856 QString path = item->referencedClip()->getProperty("proxy");
1857 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1859 //Security check: make sure the invalid proxy file is in the proxy folder
1860 if (proxyFolder.isParentOf(KUrl(path))) {
1861 QFile::remove(path);
1863 if (item->referencedClip()->getProducer() == NULL) {
1864 // Clip has no valid producer, request it
1865 slotProxyCurrentItem(false, item);
1868 // refresh thumbs producer
1869 item->referencedClip()->reloadThumbProducer();
1872 m_thumbnailQueue.removeAll(id);
1875 void ProjectList::slotAddColorClip()
1877 if (!m_commandStack)
1878 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1880 QPointer<QDialog> dia = new QDialog(this);
1881 Ui::ColorClip_UI dia_ui;
1882 dia_ui.setupUi(dia);
1883 dia->setWindowTitle(i18n("Color Clip"));
1884 dia_ui.clip_name->setText(i18n("Color Clip"));
1886 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1887 t->setValue(KdenliveSettings::color_duration());
1888 dia_ui.clip_durationBox->addWidget(t);
1889 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1891 if (dia->exec() == QDialog::Accepted) {
1892 QString color = dia_ui.clip_color->color().name();
1893 KdenliveSettings::setColorclipcolor(color);
1894 color = color.replace(0, 1, "0x") + "ff";
1895 QStringList groupInfo = getGroup();
1896 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1903 void ProjectList::slotAddSlideshowClip()
1905 if (!m_commandStack)
1906 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1908 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1910 if (dia->exec() == QDialog::Accepted) {
1911 QStringList groupInfo = getGroup();
1913 QMap <QString, QString> properties;
1914 properties.insert("name", dia->clipName());
1915 properties.insert("resource", dia->selectedPath());
1916 properties.insert("in", "0");
1917 properties.insert("out", QString::number(m_doc->getFramePos(dia->clipDuration()) * dia->imageCount()));
1918 properties.insert("ttl", QString::number(m_doc->getFramePos(dia->clipDuration())));
1919 properties.insert("loop", QString::number(dia->loop()));
1920 properties.insert("crop", QString::number(dia->crop()));
1921 properties.insert("fade", QString::number(dia->fade()));
1922 properties.insert("luma_duration", dia->lumaDuration());
1923 properties.insert("luma_file", dia->lumaFile());
1924 properties.insert("softness", QString::number(dia->softness()));
1925 properties.insert("animation", dia->animation());
1927 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1932 void ProjectList::slotAddTitleClip()
1934 QStringList groupInfo = getGroup();
1935 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1938 void ProjectList::slotAddTitleTemplateClip()
1940 if (!m_commandStack)
1941 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1943 QStringList groupInfo = getGroup();
1945 // Get the list of existing templates
1947 filter << "*.kdenlivetitle";
1948 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1949 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1951 QPointer<QDialog> dia = new QDialog(this);
1952 Ui::TemplateClip_UI dia_ui;
1953 dia_ui.setupUi(dia);
1954 for (int i = 0; i < templateFiles.size(); ++i)
1955 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1957 if (!templateFiles.isEmpty())
1958 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1959 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1960 //warning: setting base directory doesn't work??
1961 KUrl startDir(path);
1962 dia_ui.template_list->fileDialog()->setUrl(startDir);
1963 dia_ui.text_box->setHidden(true);
1964 if (dia->exec() == QDialog::Accepted) {
1965 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1966 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1967 // Create a cloned template clip
1968 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1973 QStringList ProjectList::getGroup() const
1976 QTreeWidgetItem *item = m_listView->currentItem();
1977 while (item && item->type() != PROJECTFOLDERTYPE)
1978 item = item->parent();
1981 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1982 result << folder->groupName() << folder->clipId();
1984 result << QString() << QString();
1989 void ProjectList::setDocument(KdenliveDoc *doc)
1991 m_listView->blockSignals(true);
1992 m_abortAllJobs = true;
1993 for (int i = 0; i < m_jobList.count(); i++) {
1994 m_jobList.at(i)->setStatus(JOBABORTED);
1997 m_jobThreads.waitForFinished();
1998 m_jobThreads.clearFutures();
1999 m_thumbnailQueue.clear();
2000 m_listView->clear();
2002 m_listView->setSortingEnabled(false);
2003 emit clipSelected(NULL);
2004 m_refreshed = false;
2005 m_allClipsProcessed = false;
2007 m_timecode = doc->timecode();
2008 m_commandStack = doc->commandStack();
2010 m_abortAllJobs = false;
2013 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
2014 QStringList openedFolders = doc->getExpandedFolders();
2015 QMapIterator<QString, QString> f(flist);
2016 while (f.hasNext()) {
2018 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
2019 folder->setExpanded(openedFolders.contains(f.key()));
2022 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
2023 if (list.isEmpty()) {
2026 m_allClipsProcessed = true;
2028 for (int i = 0; i < list.count(); i++)
2029 slotAddClip(list.at(i), false);
2031 m_listView->blockSignals(false);
2032 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
2033 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
2034 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
2035 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
2036 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
2037 connect(m_doc->clipManager(), SIGNAL(thumbReady(const QString &, int, QImage)), this, SLOT(slotSetThumbnail(const QString &, int, QImage)));
2040 void ProjectList::slotSetThumbnail(const QString &id, int framePos, QImage img)
2042 QString fullid = id + '#' + QString::number(framePos);
2043 ProjectItem *pItem = NULL;
2044 QTreeWidgetItem *item = getAnyItemById(fullid);
2045 if (item && item->parent()) pItem = static_cast <ProjectItem *>(item->parent());
2046 if (!item && framePos == 0) pItem = getItemById(id);
2047 if (!item && !pItem) return;
2049 if (item->type() == PROJECTCLIPTYPE) static_cast<ProjectItem*>(item)->setPixmap(QPixmap::fromImage(img));
2050 else item->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2052 else if (pItem) pItem->setPixmap(QPixmap::fromImage(img));
2054 QString hash = pItem->getClipHash();
2055 if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(framePos), img);
2059 QList <DocClipBase*> ProjectList::documentClipList() const
2062 return QList <DocClipBase*> ();
2064 return m_doc->clipManager()->documentClipList();
2067 QDomElement ProjectList::producersList()
2070 QDomElement prods = doc.createElement("producerlist");
2071 doc.appendChild(prods);
2072 QTreeWidgetItemIterator it(m_listView);
2074 if ((*it)->type() != PROJECTCLIPTYPE) {
2079 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
2085 void ProjectList::slotCheckForEmptyQueue()
2087 if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
2088 if (!m_refreshed && m_allClipsProcessed) {
2090 m_listView->setEnabled(true);
2092 QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
2093 emit displayMessage(QString(), -1);
2096 } else if (!m_refreshed) {
2097 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
2102 void ProjectList::requestClipThumbnail(const QString id)
2104 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
2105 slotProcessNextThumbnail();
2108 void ProjectList::resetThumbsProducer(DocClipBase *clip)
2111 clip->clearThumbProducer();
2112 QString id = clip->getId();
2113 m_thumbnailQueue.removeAll(id);
2116 void ProjectList::slotProcessNextThumbnail()
2118 if (m_render->processingItems() > 0) {
2121 if (m_thumbnailQueue.isEmpty()) {
2122 slotCheckForEmptyQueue();
2125 int max = m_doc->clipManager()->clipsCount();
2126 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
2127 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
2130 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
2132 QTreeWidgetItem *item = getAnyItemById(clipId);
2134 slotRefreshClipThumbnail(item, update);
2136 slotProcessNextThumbnail();
2140 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
2142 if (it == NULL) return;
2143 ProjectItem *item = NULL;
2144 bool isSubItem = false;
2146 if (it->type() == PROJECTFOLDERTYPE) return;
2147 if (it->type() == PROJECTSUBCLIPTYPE) {
2148 item = static_cast <ProjectItem *>(it->parent());
2149 frame = static_cast <SubProjectItem *>(it)->zone().x();
2152 item = static_cast <ProjectItem *>(it);
2153 frame = item->referencedClip()->getClipThumbFrame();
2157 DocClipBase *clip = item->referencedClip();
2159 slotProcessNextThumbnail();
2163 int height = m_listView->iconSize().height();
2164 int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
2165 int dwidth = (int)(height * m_render->dar() + 0.5);
2166 if (clip->clipType() == IMAGE) {
2167 img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
2169 else if (clip->clipType() != AUDIO) {
2170 img = item->referencedClip()->extractImage(frame, dwidth, height);
2172 if (!img.isNull()) {
2173 monitorItemEditing(false);
2174 QPixmap pix = roundedPixmap(img);
2175 processThumbOverlays(item, pix);
2176 if (isSubItem) it->setData(0, Qt::DecorationRole, pix);
2177 else item->setPixmap(pix);
2178 monitorItemEditing(true);
2180 QString hash = item->getClipHash();
2181 if (!hash.isEmpty() && !img.isNull()) {
2183 m_doc->cacheImage(hash, img);
2185 m_doc->cacheImage(hash + '#' + QString::number(frame), img);
2189 emit projectModified();
2190 slotProcessNextThumbnail();
2195 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
2198 ProjectItem *item = getItemById(clipId);
2199 if (item && producer) {
2200 monitorItemEditing(false);
2201 DocClipBase *clip = item->referencedClip();
2202 if (producer->is_valid()) {
2203 if (clip->isPlaceHolder()) {
2207 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
2209 item->setProperties(properties, metadata);
2210 clip->setProducer(producer, replace);
2211 m_render->processingDone(clipId);
2214 QString size = properties.value("frame_size");
2215 if (!useProxy() && clip->getProperty("proxy").isEmpty()) {
2216 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2217 discardJobs(clipId, PROXYJOB);
2219 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") {
2220 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2221 discardJobs(clipId, PROXYJOB);
2223 else if (useProxy() && !item->hasProxy() && !hasPendingJob(item, PROXYJOB)) {
2224 // proxy video and image clips
2226 CLIPTYPE t = item->clipType();
2227 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2228 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
2229 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)) {
2230 if (clip->getProperty("proxy").isEmpty()) {
2231 KUrl proxyPath = m_doc->projectFolder();
2232 proxyPath.addPath("proxy/");
2233 proxyPath.addPath(clip->getClipHash() + '.' + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
2234 QMap <QString, QString> newProps;
2235 // insert required duration for proxy
2236 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
2237 newProps.insert("proxy", proxyPath.path());
2238 QMap <QString, QString> oldProps = clip->properties();
2239 oldProps.insert("proxy", QString());
2240 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
2241 m_doc->commandStack()->push(command);
2246 if (!replace && m_allClipsProcessed && !item->hasPixmap()) {
2247 getCachedThumbnail(item);
2249 if (!toReload.isEmpty())
2250 item->slotSetToolTip();
2252 kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
2253 m_render->processingDone(clipId);
2255 int queue = m_render->processingItems();
2257 monitorItemEditing(true);
2258 if (item && m_thumbnailQueue.isEmpty()) {
2259 if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
2260 m_listView->setCurrentItem(item);
2261 bool updatedProfile = false;
2262 if (item->parent()) {
2263 if (item->parent()->type() == PROJECTFOLDERTYPE)
2264 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
2265 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
2266 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
2267 updatedProfile = adjustProjectProfileToItem(item);
2269 if (updatedProfile == false) {
2270 //emit clipSelected(item->referencedClip());
2273 int max = m_doc->clipManager()->clipsCount();
2274 if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
2276 if (m_allClipsProcessed) emit processNextThumbnail();
2279 // no item for producer, delete it
2283 if (replace) toReload = clipId;
2284 if (!toReload.isEmpty())
2285 emit clipNeedsReload(toReload);
2288 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
2291 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
2292 item = static_cast <ProjectItem*>(m_listView->currentItem());
2294 if (item == NULL || item->referencedClip() == NULL) {
2295 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
2298 bool profileUpdated = false;
2299 QString size = item->referencedClip()->getProperty("frame_size");
2300 int width = size.section('x', 0, 0).toInt();
2301 int height = size.section('x', -1).toInt();
2302 // Fix some avchd clips tht report a wrong size (1920x1088)
2303 if (height == 1088) height = 1080;
2304 double fps = item->referencedClip()->getProperty("fps").toDouble();
2305 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
2306 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
2307 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
2308 // get a list of compatible profiles
2309 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
2310 if (!suggestedProfiles.isEmpty()) {
2311 KDialog *dialog = new KDialog(this);
2312 dialog->setCaption(i18n("Change project profile"));
2313 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2316 QVBoxLayout *l = new QVBoxLayout;
2317 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));
2318 l->addWidget(label);
2319 QListWidget *list = new QListWidget;
2320 list->setAlternatingRowColors(true);
2321 QMapIterator<QString, QString> i(suggestedProfiles);
2322 while (i.hasNext()) {
2324 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
2325 item->setData(Qt::UserRole, i.key());
2326 item->setToolTip(i.key());
2328 list->setCurrentRow(0);
2330 container.setLayout(l);
2331 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
2332 dialog->setMainWidget(&container);
2333 if (dialog->exec() == QDialog::Accepted) {
2334 //Change project profile
2335 profileUpdated = true;
2336 if (list->currentItem())
2337 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
2341 } else if (fps > 0) {
2342 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));
2346 return profileUpdated;
2349 QString ProjectList::getDocumentProperty(const QString &key) const
2351 return m_doc->getDocumentProperty(key);
2354 bool ProjectList::useProxy() const
2356 return m_doc->getDocumentProperty("enableproxy").toInt();
2359 bool ProjectList::generateProxy() const
2361 return m_doc->getDocumentProperty("generateproxy").toInt();
2364 bool ProjectList::generateImageProxy() const
2366 return m_doc->getDocumentProperty("generateimageproxy").toInt();
2369 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2371 ProjectItem *item = getItemById(clipId);
2372 if (item && !img.isNull()) {
2373 QPixmap pix = roundedPixmap(img);
2374 processThumbOverlays(item, pix);
2375 monitorItemEditing(false);
2376 item->setPixmap(pix);
2377 monitorItemEditing(true);
2378 QString hash = item->getClipHash();
2379 if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2383 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2385 // For clips that have a generic icon (like audio clips...)
2386 ProjectItem *item = getItemById(clipId);
2387 QPixmap pix = KIcon(name).pixmap(QSize(width, height));
2388 if (item && !pix.isNull()) {
2389 monitorItemEditing(false);
2390 item->setData(0, Qt::DecorationRole, pix);
2391 monitorItemEditing(true);
2395 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2397 QTreeWidgetItemIterator it(m_listView);
2398 QString lookId = id;
2399 if (id.contains('#'))
2400 lookId = id.section('#', 0, 0);
2402 ProjectItem *result = NULL;
2404 if ((*it)->type() != PROJECTCLIPTYPE) {
2409 ProjectItem *item = static_cast<ProjectItem *>(*it);
2410 if (item->clipId() == lookId) {
2416 if (result == NULL || !id.contains('#')) {
2419 for (int i = 0; i < result->childCount(); i++) {
2420 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2421 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2430 ProjectItem *ProjectList::getItemById(const QString &id)
2433 QTreeWidgetItemIterator it(m_listView);
2435 if ((*it)->type() != PROJECTCLIPTYPE) {
2436 // subitem or folder
2440 item = static_cast<ProjectItem *>(*it);
2441 if (item->clipId() == id)
2448 FolderProjectItem *ProjectList::getFolderItemByName(const QString &name)
2450 FolderProjectItem *item = NULL;
2451 QList <QTreeWidgetItem *> hits = m_listView->findItems(name, Qt::MatchExactly, 0);
2452 for (int i = 0; i < hits.count(); i++) {
2453 if (hits.at(i)->type() == PROJECTFOLDERTYPE) {
2454 item = static_cast<FolderProjectItem *>(hits.at(i));
2461 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2463 FolderProjectItem *item;
2464 QTreeWidgetItemIterator it(m_listView);
2466 if ((*it)->type() == PROJECTFOLDERTYPE) {
2467 item = static_cast<FolderProjectItem *>(*it);
2468 if (item->clipId() == id)
2476 void ProjectList::slotSelectClip(const QString &ix)
2478 ProjectItem *clip = getItemById(ix);
2480 m_listView->setCurrentItem(clip);
2481 m_listView->scrollToItem(clip);
2482 m_editButton->defaultAction()->setEnabled(true);
2483 m_deleteButton->defaultAction()->setEnabled(true);
2484 m_reloadAction->setEnabled(true);
2485 m_extractAudioAction->setEnabled(true);
2486 m_transcodeAction->setEnabled(true);
2487 m_stabilizeAction->setEnabled(true);
2488 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2489 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2490 m_openAction->setEnabled(true);
2491 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2492 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2493 m_openAction->setEnabled(true);
2495 m_openAction->setEnabled(false);
2500 QString ProjectList::currentClipUrl() const
2503 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2504 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2506 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2508 item = static_cast <ProjectItem*>(m_listView->currentItem());
2512 return item->clipUrl().path();
2515 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2519 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2520 for (int i = 0; i < list.count(); i++) {
2521 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2523 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2525 item = static_cast <ProjectItem*>(list.at(i)->parent());
2527 item = static_cast <ProjectItem*>(list.at(i));
2529 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2531 DocClipBase *clip = item->referencedClip();
2532 if (!condition.isEmpty()) {
2533 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2535 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2538 result.append(item->clipUrl());
2543 QStringList ProjectList::getConditionalIds(const QString &condition) const
2547 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2548 for (int i = 0; i < list.count(); i++) {
2549 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2551 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2553 item = static_cast <ProjectItem*>(list.at(i)->parent());
2555 item = static_cast <ProjectItem*>(list.at(i));
2557 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2559 DocClipBase *clip = item->referencedClip();
2560 if (!condition.isEmpty()) {
2561 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2563 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2566 result.append(item->clipId());
2571 void ProjectList::regenerateTemplate(const QString &id)
2573 ProjectItem *clip = getItemById(id);
2575 regenerateTemplate(clip);
2578 void ProjectList::regenerateTemplate(ProjectItem *clip)
2580 //TODO: remove this unused method, only force_reload is necessary
2581 clip->referencedClip()->getProducer()->set("force_reload", 1);
2584 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2588 if (!file.open(QIODevice::ReadOnly)) {
2589 kWarning() << "ERROR, CANNOT READ: " << path;
2592 if (!doc.setContent(&file)) {
2593 kWarning() << "ERROR, CANNOT READ: " << path;
2598 QDomNodeList texts = doc.elementsByTagName("content");
2599 for (int i = 0; i < texts.count(); i++) {
2600 QString data = texts.item(i).firstChild().nodeValue();
2601 data.replace("%s", replaceString);
2602 texts.item(i).firstChild().setNodeValue(data);
2608 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2610 ProjectItem *clip = getItemById(id);
2611 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2613 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2614 m_commandStack->push(command);
2617 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2619 ProjectItem *clip = getItemById(id);
2621 DocClipBase *base = clip->referencedClip();
2622 base->addCutZone(in, out);
2623 monitorItemEditing(false);
2624 SubProjectItem *sub = new SubProjectItem(m_render->dar(), clip, in, out, desc);
2625 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2626 if (!clip->isExpanded())
2627 clip->setExpanded(true);
2628 m_listView->scrollToItem(sub);
2629 m_listView->editItem(sub, 1);
2631 m_doc->clipManager()->requestThumbs(QString('#' + id), QList <int>() << in);
2632 monitorItemEditing(true);
2634 emit projectModified();
2637 void ProjectList::removeClipCut(const QString &id, int in, int out)
2639 ProjectItem *clip = getItemById(id);
2641 DocClipBase *base = clip->referencedClip();
2642 base->removeCutZone(in, out);
2643 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2645 monitorItemEditing(false);
2647 monitorItemEditing(true);
2650 emit projectModified();
2653 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2655 SubProjectItem *sub = NULL;
2657 for (int i = 0; i < clip->childCount(); i++) {
2658 QTreeWidgetItem *it = clip->child(i);
2659 if (it->type() == PROJECTSUBCLIPTYPE) {
2660 sub = static_cast <SubProjectItem*>(it);
2661 if (sub->zone() == zone)
2671 void ProjectList::slotUpdateClipCut(QPoint p)
2673 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2675 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2676 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2677 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2678 m_commandStack->push(command);
2681 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2683 ProjectItem *clip = getItemById(id);
2684 SubProjectItem *sub = getSubItem(clip, oldzone);
2685 if (sub == NULL || clip == NULL)
2687 DocClipBase *base = clip->referencedClip();
2688 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2689 monitorItemEditing(false);
2691 sub->setDescription(comment);
2692 monitorItemEditing(true);
2693 emit projectModified();
2696 void ProjectList::slotForceProcessing(const QString &id)
2698 m_render->forceProcessing(id);
2701 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2703 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2705 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2706 int count = list.count();
2708 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2709 if (!existing.isEmpty()) {
2710 // Sequence already exists, update
2711 QString id = existing.at(0)->getId();
2712 //ProjectItem *item = getItemById(id);
2713 QMap <QString, QString> oldprops;
2714 QMap <QString, QString> newprops;
2715 int ttl = existing.at(0)->getProperty("ttl").toInt();
2716 oldprops["out"] = existing.at(0)->getProperty("out");
2717 newprops["out"] = QString::number(ttl * count - 1);
2718 slotUpdateClipProperties(id, newprops);
2719 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2720 m_commandStack->push(command);
2723 QStringList groupInfo = getGroup();
2724 QMap <QString, QString> properties;
2725 properties.insert("name", fileName);
2726 properties.insert("resource", pattern);
2727 properties.insert("in", "0");
2728 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
2729 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
2730 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
2731 properties.insert("loop", QString::number(false));
2732 properties.insert("crop", QString::number(false));
2733 properties.insert("fade", QString::number(false));
2734 properties.insert("luma_duration", m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
2736 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
2738 } else emit displayMessage(i18n("Sequence not found"), -2, ErrorMessage);
2741 QMap <QString, QString> ProjectList::getProxies()
2743 QMap <QString, QString> list;
2745 QTreeWidgetItemIterator it(m_listView);
2747 if ((*it)->type() != PROJECTCLIPTYPE) {
2751 item = static_cast<ProjectItem *>(*it);
2752 if (item && item->referencedClip() != NULL) {
2753 if (item->hasProxy()) {
2754 QString proxy = item->referencedClip()->getProperty("proxy");
2755 list.insert(proxy, item->clipUrl().path());
2763 void ProjectList::slotCreateProxy(const QString id)
2765 ProjectItem *item = getItemById(id);
2766 if (!item || hasPendingJob(item, PROXYJOB) || item->referencedClip()->isPlaceHolder()) return;
2767 QString path = item->referencedClip()->getProperty("proxy");
2768 if (path.isEmpty()) {
2769 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy, empty path."));
2773 if (QFileInfo(path).size() > 0) {
2774 // Proxy already created
2775 setJobStatus(item, PROXYJOB, JOBDONE);
2779 QString sourcePath = item->clipUrl().path();
2780 if (item->clipType() == PLAYLIST) {
2781 // Special case: playlists use the special 'consumer' producer to support resizing
2782 sourcePath.prepend("consumer:");
2784 ProxyJob *job = new ProxyJob(item->clipType(), id, QStringList() << path << sourcePath << item->referencedClip()->producerProperty("_exif_orientation") << m_doc->getDocumentProperty("proxyparams").simplified() << QString::number(m_render->frameRenderWidth()) << QString::number(m_render->renderHeight()));
2785 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2790 m_jobList.append(job);
2791 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2792 slotCheckJobProcess();
2795 void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
2797 ProjectItem *item = getItemById(id);
2798 if (!item|| item->referencedClip()->isPlaceHolder()) return;
2799 QString source = item->clipUrl().path();
2800 QString ext = source.section('.', -1);
2801 QString dest = source.section('.', 0, -2) + '_' + QString::number(zone.x()) + '.' + ext;
2803 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2804 if (clipFps == 0) clipFps = m_fps;
2805 // if clip and project have different frame rate, adjust in and out
2808 in = GenTime(in, m_timecode.fps()).frames(clipFps);
2809 out = GenTime(out, m_timecode.fps()).frames(clipFps);
2810 int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
2811 int duration = out - in + 1;
2812 QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
2813 QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
2815 QPointer<QDialog> d = new QDialog(this);
2816 Ui::CutJobDialog_UI ui;
2818 ui.extra_params->setVisible(false);
2819 ui.add_clip->setChecked(KdenliveSettings::add_new_clip());
2820 ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
2821 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2822 ui.file_url->setUrl(KUrl(dest));
2823 ui.button_more->setIcon(KIcon("configure"));
2824 ui.extra_params->setPlainText("-acodec copy -vcodec copy");
2825 QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
2826 ui.info_label->setText(mess);
2827 if (d->exec() != QDialog::Accepted) {
2831 dest = ui.file_url->url().path();
2832 bool acceptPath = dest != source;
2833 if (acceptPath && QFileInfo(dest).size() > 0) {
2834 // destination file olready exists, overwrite?
2837 while (!acceptPath) {
2838 // Do not allow to save over original clip
2839 if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
2840 else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
2841 if (d->exec() != QDialog::Accepted) {
2845 dest = ui.file_url->url().path();
2846 acceptPath = dest != source;
2847 if (acceptPath && QFileInfo(dest).size() > 0) {
2851 QString extraParams = ui.extra_params->toPlainText().simplified();
2852 KdenliveSettings::setAdd_new_clip(ui.add_clip->isChecked());
2855 QStringList jobParams;
2856 jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_new_clip());
2857 if (!extraParams.isEmpty()) jobParams << extraParams;
2858 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2859 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2863 m_jobList.append(job);
2864 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2866 slotCheckJobProcess();
2869 void ProjectList::slotTranscodeClipJob(const QString &condition, QString params, QString desc)
2871 QStringList existingFiles;
2872 QStringList ids = getConditionalIds(condition);
2873 QStringList destinations;
2874 foreach(const QString &id, ids) {
2875 ProjectItem *item = getItemById(id);
2876 if (!item) continue;
2877 QString newFile = params.section(' ', -1).replace("%1", item->clipUrl().path());
2878 destinations << newFile;
2879 if (QFile::exists(newFile)) existingFiles << newFile;
2881 if (!existingFiles.isEmpty()) {
2882 if (KMessageBox::warningContinueCancelList(this, i18n("The transcoding job will overwrite the following files:"), existingFiles) == KMessageBox::Cancel) return;
2885 QDialog *d = new QDialog(this);
2886 Ui::CutJobDialog_UI ui;
2888 d->setWindowTitle(i18n("Transcoding"));
2889 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2890 if (ids.count() == 1) {
2891 ui.file_url->setUrl(KUrl(destinations.first()));
2894 ui.destination_label->setVisible(false);
2895 ui.file_url->setVisible(false);
2897 ui.extra_params->setVisible(false);
2899 ui.button_more->setIcon(KIcon("configure"));
2900 ui.add_clip->setChecked(KdenliveSettings::add_new_clip());
2901 ui.extra_params->setPlainText(params.simplified().section(' ', 0, -2));
2902 QString mess = desc;
2903 mess.append(' ' + i18np("(%1 clip)", "(%1 clips)", ids.count()));
2904 ui.info_label->setText(mess);
2905 if (d->exec() != QDialog::Accepted) {
2909 params = ui.extra_params->toPlainText().simplified();
2910 KdenliveSettings::setAdd_new_clip(ui.add_clip->isChecked());
2912 foreach(const QString &id, ids) {
2913 ProjectItem *item = getItemById(id);
2914 if (!item || !item->referencedClip()) continue;
2915 QString src = item->clipUrl().path();
2917 if (ids.count() > 1) {
2918 dest = destinations.at(index);
2921 else dest = ui.file_url->url().path();
2922 QStringList jobParams;
2923 jobParams << dest << src << QString() << QString();
2924 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2925 if (clipFps == 0) clipFps = m_fps;
2926 int max = item->clipMaxDuration();
2927 QString duration = QString::number(max);
2928 jobParams << duration;
2929 jobParams << QString::number(KdenliveSettings::add_new_clip());
2930 jobParams << params;
2931 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2932 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2936 m_jobList.append(job);
2937 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2940 slotCheckJobProcess();
2944 void ProjectList::slotCheckJobProcess()
2946 if (!m_jobThreads.futures().isEmpty()) {
2947 // Remove inactive threads
2948 QList <QFuture<void> > futures = m_jobThreads.futures();
2949 m_jobThreads.clearFutures();
2950 for (int i = 0; i < futures.count(); i++)
2951 if (!futures.at(i).isFinished()) {
2952 m_jobThreads.addFuture(futures.at(i));
2955 if (m_jobList.isEmpty()) return;
2959 for (int i = 0; i < m_jobList.count(); i++) {
2960 if (m_jobList.at(i)->status() == JOBWORKING || m_jobList.at(i)->status() == JOBWAITING)
2963 // remove finished jobs
2964 AbstractClipJob *job = m_jobList.takeAt(i);
2969 emit jobCount(count);
2970 m_jobMutex.unlock();
2971 if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
2974 void ProjectList::slotAbortProxy(const QString id, const QString path)
2978 ProjectItem *item = getItemById(id);
2980 if (!item->isProxyRunning()) slotGotProxy(item);
2981 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2982 discardJobs(id, PROXYJOB);
2985 void ProjectList::slotProcessJobs()
2987 while (!m_jobList.isEmpty() && !m_abortAllJobs) {
2988 emit projectModified();
2989 AbstractClipJob *job = NULL;
2992 for (int i = 0; i < m_jobList.count(); i++) {
2993 if (m_jobList.at(i)->status() == JOBWAITING) {
2995 m_jobList.at(i)->setStatus(JOBWORKING);
2996 job = m_jobList.at(i);
3000 else if (m_jobList.at(i)->status() == JOBWORKING)
3004 emit jobCount(count);
3005 m_jobMutex.unlock();
3010 QString destination = job->destination();
3011 // Check if the clip is still here
3012 DocClipBase *currentClip = m_doc->clipManager()->getClipById(job->clipId());
3013 //ProjectItem *processingItem = getItemById(job->clipId());
3014 if (currentClip == NULL) {
3015 job->setStatus(JOBDONE);
3018 // Set clip status to started
3019 emit processLog(job->clipId(), 0, job->jobType, job->statusMessage());
3021 // Make sure destination path is writable
3022 if (!destination.isEmpty()) {
3023 QFile file(destination);
3024 if (!file.open(QIODevice::WriteOnly)) {
3025 emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Cannot write to path: %1", destination));
3026 job->setStatus(JOBCRASHED);
3030 QFile::remove(destination);
3032 connect(job, SIGNAL(jobProgress(QString, int, int)), this, SIGNAL(processLog(QString, int, int)));
3033 connect(job, SIGNAL(cancelRunningJob(const QString, stringMap)), this, SIGNAL(cancelRunningJob(const QString, stringMap)));
3035 if (job->jobType == MLTJOB) {
3036 MeltJob *jb = static_cast<MeltJob *> (job);
3037 jb->setProducer(currentClip->getProducer(), currentClip->fileURL());
3038 if (jb->isProjectFilter())
3039 connect(job, SIGNAL(gotFilterJobResults(QString,int, int, stringMap,stringMap)), this, SLOT(slotGotFilterJobResults(QString,int, int,stringMap,stringMap)));
3041 connect(job, SIGNAL(gotFilterJobResults(QString,int, int, stringMap,stringMap)), this, SIGNAL(gotFilterJobResults(QString,int, int,stringMap,stringMap)));
3044 if (job->status() == JOBDONE) {
3045 emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
3046 //TODO: replace with more generic clip replacement framework
3047 if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
3048 if (job->addClipToProject()) {
3049 emit addClip(destination, QString(), QString());
3051 } else if (job->status() == JOBCRASHED || job->status() == JOBABORTED) {
3052 emit updateJobStatus(job->clipId(), job->jobType, job->status(), job->errorMessage(), QString(), job->logDetails());
3055 // Thread finished, cleanup & update count
3056 QTimer::singleShot(200, this, SIGNAL(checkJobProcess()));
3060 void ProjectList::updateProxyConfig()
3063 QTreeWidgetItemIterator it(m_listView);
3064 QUndoCommand *command = new QUndoCommand();
3065 command->setText(i18n("Update proxy settings"));
3066 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3068 if ((*it)->type() != PROJECTCLIPTYPE) {
3072 item = static_cast<ProjectItem *>(*it);
3077 CLIPTYPE t = item->clipType();
3078 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
3079 if (generateProxy() && useProxy() && !hasPendingJob(item, PROXYJOB)) {
3080 DocClipBase *clip = item->referencedClip();
3081 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
3082 if (clip->getProperty("proxy").isEmpty()) {
3083 // We need to insert empty proxy in old properties so that undo will work
3084 QMap <QString, QString> oldProps;// = clip->properties();
3085 oldProps.insert("proxy", QString());
3086 QMap <QString, QString> newProps;
3087 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + '.' + m_doc->getDocumentProperty("proxyextension"));
3088 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3092 else if (item->hasProxy()) {
3094 QMap <QString, QString> newProps;
3095 newProps.insert("proxy", QString());
3096 // insert required duration for proxy
3097 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
3098 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
3101 else if (t == IMAGE && item->referencedClip() != NULL) {
3102 if (generateImageProxy() && useProxy()) {
3103 DocClipBase *clip = item->referencedClip();
3104 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
3105 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
3106 if (clip->getProperty("proxy").isEmpty()) {
3107 // We need to insert empty proxy in old properties so that undo will work
3108 QMap <QString, QString> oldProps = clip->properties();
3109 oldProps.insert("proxy", QString());
3110 QMap <QString, QString> newProps;
3111 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
3112 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3116 else if (item->hasProxy()) {
3118 QMap <QString, QString> newProps;
3119 newProps.insert("proxy", QString());
3120 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
3125 if (command->childCount() > 0) m_doc->commandStack()->push(command);
3126 else delete command;
3129 void ProjectList::slotProcessLog(const QString id, int progress, int type, const QString message)
3131 ProjectItem *item = getItemById(id);
3132 setJobStatus(item, (JOBTYPE) type, JOBWORKING, progress, message);
3135 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
3137 QList<QTreeWidgetItem *> list;
3138 if (itemToProxy == NULL) list = m_listView->selectedItems();
3139 else list << itemToProxy;
3141 // expand list (folders, subclips) to get real clips
3142 QTreeWidgetItem *listItem;
3143 QList<ProjectItem *> clipList;
3144 for (int i = 0; i < list.count(); i++) {
3145 listItem = list.at(i);
3146 if (listItem->type() == PROJECTFOLDERTYPE) {
3147 for (int j = 0; j < listItem->childCount(); j++) {
3148 QTreeWidgetItem *sub = listItem->child(j);
3149 if (sub->type() == PROJECTCLIPTYPE) {
3150 ProjectItem *item = static_cast <ProjectItem*>(sub);
3151 if (!clipList.contains(item)) clipList.append(item);
3155 else if (listItem->type() == PROJECTSUBCLIPTYPE) {
3156 QTreeWidgetItem *sub = listItem->parent();
3157 ProjectItem *item = static_cast <ProjectItem*>(sub);
3158 if (!clipList.contains(item)) clipList.append(item);
3160 else if (listItem->type() == PROJECTCLIPTYPE) {
3161 ProjectItem *item = static_cast <ProjectItem*>(listItem);
3162 if (!clipList.contains(item)) clipList.append(item);
3166 QUndoCommand *command = new QUndoCommand();
3167 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
3168 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
3170 // Make sure the proxy folder exists
3171 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3172 KStandardDirs::makeDir(proxydir);
3174 QMap <QString, QString> newProps;
3175 QMap <QString, QString> oldProps;
3176 if (!doProxy) newProps.insert("proxy", "-");
3177 for (int i = 0; i < clipList.count(); i++) {
3178 ProjectItem *item = clipList.at(i);
3179 CLIPTYPE t = item->clipType();
3180 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
3181 if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
3182 DocClipBase *clip = item->referencedClip();
3183 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
3184 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
3188 //oldProps = clip->properties();
3191 QString path = proxydir + clip->getClipHash() + '.' + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
3192 // insert required duration for proxy
3193 newProps.insert("proxy_out", clip->producerProperty("out"));
3194 newProps.insert("proxy", path);
3195 // We need to insert empty proxy so that undo will work
3196 //oldProps.insert("proxy", QString());
3198 else if (item->referencedClip()->getProducer() == NULL) {
3199 // Force clip reload
3200 kDebug()<<"// CLIP HAD NULL PROD------------";
3201 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
3203 // We need to insert empty proxy so that undo will work
3204 oldProps = clip->currentProperties(newProps);
3205 if (doProxy) oldProps.insert("proxy", "-");
3206 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
3209 if (command->childCount() > 0) {
3210 m_doc->commandStack()->push(command);
3212 else delete command;
3216 void ProjectList::slotDeleteProxy(const QString proxyPath)
3218 if (proxyPath.isEmpty()) return;
3219 QUndoCommand *proxyCommand = new QUndoCommand();
3220 proxyCommand->setText(i18n("Remove Proxy"));
3221 QTreeWidgetItemIterator it(m_listView);
3224 if ((*it)->type() == PROJECTCLIPTYPE) {
3225 item = static_cast <ProjectItem *>(*it);
3226 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
3227 QMap <QString, QString> props;
3228 props.insert("proxy", QString());
3229 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
3235 if (proxyCommand->childCount() == 0)
3236 delete proxyCommand;
3238 m_commandStack->push(proxyCommand);
3239 QFile::remove(proxyPath);
3242 void ProjectList::setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress, const QString &statusMessage)
3244 if (item == NULL || (m_abortAllJobs && m_closing)) return;
3245 monitorItemEditing(false);
3246 item->setJobStatus(jobType, status, progress, statusMessage);
3247 if (status == JOBCRASHED) {
3248 DocClipBase *clip = item->referencedClip();
3250 kDebug()<<"// PROXY CRASHED";
3252 else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
3253 // disable proxy and fetch real clip
3254 clip->setProperty("proxy", "-");
3255 QDomElement xml = clip->toXML();
3256 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
3259 // Disable proxy for this clip
3260 clip->setProperty("proxy", "-");
3263 monitorItemEditing(true);
3266 void ProjectList::monitorItemEditing(bool enable)
3268 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3269 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3272 QStringList ProjectList::expandedFolders() const
3275 FolderProjectItem *item;
3276 QTreeWidgetItemIterator it(m_listView);
3278 if ((*it)->type() != PROJECTFOLDERTYPE) {
3282 if ((*it)->isExpanded()) {
3283 item = static_cast<FolderProjectItem *>(*it);
3284 result.append(item->clipId());
3291 void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
3293 if (item->hasProxy()) {
3295 QColor c(220, 220, 10, 200);
3296 QRect r(0, 0, 12, 12);
3298 QFont font = p.font();
3301 p.setPen(Qt::black);
3302 p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
3306 void ProjectList::slotCancelJobs()
3308 m_abortAllJobs = true;
3309 for (int i = 0; i < m_jobList.count(); i++) {
3310 m_jobList.at(i)->setStatus(JOBABORTED);
3312 m_jobThreads.waitForFinished();
3313 m_jobThreads.clearFutures();
3314 QUndoCommand *command = new QUndoCommand();
3315 command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
3317 for (int i = 0; i < m_jobList.count(); i++) {
3318 DocClipBase *currentClip = m_doc->clipManager()->getClipById(m_jobList.at(i)->clipId());
3319 if (!currentClip) continue;
3320 QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
3321 if (newProps.isEmpty()) continue;
3322 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3323 new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command);
3325 m_jobMutex.unlock();
3326 if (command->childCount() > 0) {
3327 m_doc->commandStack()->push(command);
3329 else delete command;
3330 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
3332 m_abortAllJobs = false;
3333 m_infoLabel->slotSetJobCount(0);
3336 void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
3338 if (newProps.isEmpty() || m_closing) return;
3339 DocClipBase *currentClip = m_doc->clipManager()->getClipById(id);
3340 if (!currentClip) return;
3341 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3342 if (newProps == oldProps) return;
3343 QMapIterator<QString, QString> i(oldProps);
3344 EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
3345 m_commandStack->push(command);
3348 bool ProjectList::hasPendingJob(ProjectItem *item, JOBTYPE type)
3350 if (!item || !item->referencedClip() || m_abortAllJobs) return false;
3351 AbstractClipJob *job;
3352 QMutexLocker lock(&m_jobMutex);
3353 for (int i = 0; i < m_jobList.count(); i++) {
3354 if (m_abortAllJobs) break;
3355 job = m_jobList.at(i);
3356 if (job->clipId() == item->clipId() && job->jobType == type && (job->status() == JOBWAITING || job->status() == JOBWORKING)) return true;
3362 void ProjectList::deleteJobsForClip(const QString &clipId)
3364 QMutexLocker lock(&m_jobMutex);
3365 for (int i = 0; i < m_jobList.count(); i++) {
3366 if (m_jobList.at(i)->clipId() == clipId) {
3367 m_jobList.at(i)->setStatus(JOBABORTED);
3372 void ProjectList::slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details)
3374 ProjectItem *item = getItemById(id);
3376 slotUpdateJobStatus(item, type, status, label, actionName, details);
3380 void ProjectList::slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName, const QString details)
3382 item->setJobStatus((JOBTYPE) type, (CLIPJOBSTATUS) status);
3383 if (status != JOBCRASHED) return;
3384 #if KDE_IS_VERSION(4,7,0)
3385 QList<QAction *> actions = m_infoMessage->actions();
3386 if (m_infoMessage->isHidden()) {
3387 m_infoMessage->setText(label);
3388 m_infoMessage->setWordWrap(m_infoMessage->text().length() > 35);
3389 m_infoMessage->setMessageType(KMessageWidget::Warning);
3392 if (!actionName.isEmpty()) {
3393 QAction *action = NULL;
3394 QList< KActionCollection * > collections = KActionCollection::allCollections();
3395 for (int i = 0; i < collections.count(); i++) {
3396 KActionCollection *coll = collections.at(i);
3397 action = coll->action(actionName);
3400 if (action && !actions.contains(action)) m_infoMessage->addAction(action);
3402 if (!details.isEmpty()) {
3403 m_errorLog.append(details);
3404 if (!actions.contains(m_logAction)) m_infoMessage->addAction(m_logAction);
3406 m_infoMessage->animatedShow();
3408 // warning for KDE < 4.7
3409 KPassivePopup *passivePop = new KPassivePopup( this );
3410 passivePop->setAutoDelete(true);
3411 connect(passivePop, SIGNAL(clicked()), this, SLOT(slotClosePopup()));
3412 m_errorLog.append(details);
3413 KVBox *vb = new KVBox( passivePop );
3414 KHBox *vh1 = new KHBox( vb );
3415 KIcon icon("dialog-warning");
3416 QLabel *iconLabel = new QLabel(vh1);
3417 iconLabel->setPixmap(icon.pixmap(m_listView->iconSize()));
3418 (void) new QLabel( label, vh1);
3419 KHBox *box = new KHBox( vb );
3420 QPushButton *but = new QPushButton( "Show log", box );
3421 connect(but, SIGNAL(clicked(bool)), this, SLOT(slotShowJobLog()));
3423 passivePop->setView( vb );
3429 void ProjectList::slotShowJobLog()
3432 d.setButtons(KDialog::Close);
3434 for (int i = 0; i < m_errorLog.count(); i++) {
3435 if (i > 0) t.insertHtml("<br><hr /><br>");
3436 t.insertPlainText(m_errorLog.at(i));
3438 t.setReadOnly(true);
3439 d.setMainWidget(&t);
3443 QStringList ProjectList::getPendingJobs(const QString &id)
3446 QMutexLocker lock(&m_jobMutex);
3447 for (int i = 0; i < m_jobList.count(); i++) {
3448 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->status() == JOBWAITING || m_jobList.at(i)->status() == JOBWORKING)) {
3450 result << m_jobList.at(i)->description;
3456 void ProjectList::discardJobs(const QString &id, JOBTYPE type) {
3457 QMutexLocker lock(&m_jobMutex);
3458 for (int i = 0; i < m_jobList.count(); i++) {
3459 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobType == type || type == NOJOBTYPE)) {
3461 m_jobList.at(i)->setStatus(JOBABORTED);
3466 void ProjectList::slotStartFilterJob(ItemInfo info, const QString&id, const QString&filterName, const QString&filterParams, const QString&consumer, const QString&consumerParams, const QMap <QString, QString> &extraParams)
3468 ProjectItem *item = getItemById(id);
3470 QStringList jobParams;
3471 jobParams << QString::number(info.cropStart.frames(m_fps)) << QString::number((info.cropStart + info.cropDuration).frames(m_fps));
3472 jobParams << QString() << filterName << filterParams << consumer << consumerParams << QString::number(info.startPos.frames(m_fps)) << QString::number(info.track);
3473 MeltJob *job = new MeltJob(item->clipType(), id, jobParams, extraParams);
3474 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3478 job->description = i18n("Filter %1", extraParams.value("finalfilter"));
3479 m_jobList.append(job);
3480 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3481 slotCheckJobProcess();
3484 void ProjectList::startClipFilterJob(const QString &filterName, const QString &condition)
3486 QStringList ids = getConditionalIds(condition);
3487 QString destination;
3488 ProjectItem *item = getItemById(ids.at(0));
3490 emit displayMessage(i18n("Cannot find clip to process filter %1", filterName), -2, ErrorMessage);
3493 if (ids.count() == 1) {
3494 destination = item->clipUrl().path();
3497 destination = item->clipUrl().directory();
3499 if (filterName == "motion_est") {
3500 // Show config dialog
3501 QPointer<QDialog> d = new QDialog(this);
3502 Ui::SceneCutDialog_UI ui;
3504 // Set up categories
3505 for (int i = 0; i < 5; ++i) {
3506 ui.marker_type->insertItem(i, i18n("Category %1", i));
3507 ui.marker_type->setItemData(i, CommentedTime::markerColor(i), Qt::DecorationRole);
3509 ui.marker_type->setCurrentIndex(KdenliveSettings::default_marker_type());
3510 if (d->exec() != QDialog::Accepted) {
3515 QStringList jobParams;
3517 jobParams << QString();
3518 // Filter params, use a smaller region of the image to speed up operation
3519 // In fact, it's faster to rescale whole image than using part of it (bounding=\"25%x25%:15%x15\")
3520 jobParams << filterName << "shot_change_list=0 denoise=0";
3522 jobParams << "null" << "all=1 terminate_on_pause=1 real_time=-1 rescale=nearest deinterlace_method=onefield top_field_first=-1";
3523 QMap <QString, QString> extraParams;
3524 extraParams.insert("key", "shot_change_list");
3525 extraParams.insert("projecttreefilter", "1");
3526 QString keyword("%count");
3527 extraParams.insert("resultmessage", i18n("Found %1 scenes.", keyword));
3528 extraParams.insert("resize_profile", "160");
3529 if (ui.store_data->isChecked()) {
3530 // We want to save result as clip metadata
3531 extraParams.insert("storedata", "1");
3533 if (ui.zone_only->isChecked()) {
3534 // We want to analyze only clip zone
3535 extraParams.insert("zoneonly", "1");
3537 if (ui.add_markers->isChecked()) {
3538 // We want to create markers
3539 extraParams.insert("addmarkers", QString::number(ui.marker_type->currentIndex()));
3541 if (ui.cut_scenes->isChecked()) {
3542 // We want to cut scenes
3543 extraParams.insert("cutscenes", "1");
3546 processClipJob(ids, QString(), false, jobParams, i18n("Auto split"), extraParams);
3549 QPointer<ClipStabilize> d = new ClipStabilize(destination, ids.count(), filterName);
3550 if (d->exec() == QDialog::Accepted) {
3551 QMap <QString, QString> extraParams;
3552 extraParams.insert("producer_profile", "1");
3553 processClipJob(ids, d->destination(), d->autoAddClip(), d->params(), d->desc(), extraParams);
3559 void ProjectList::processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description, QMap <QString, QString> extraParams)
3561 QStringList preParams;
3563 preParams << QString::number(0) << QString::number(-1);
3565 preParams << jobParams.takeFirst();
3567 preParams << jobParams.takeFirst();
3569 preParams << jobParams.takeFirst();
3571 QString consumer = jobParams.takeFirst();
3573 foreach(const QString&id, ids) {
3574 ProjectItem *item = getItemById(id);
3575 if (!item) continue;
3576 QStringList jobArgs;
3577 if (extraParams.contains("zoneonly")) {
3578 // Analyse clip zone only, remove in / out and replace with zone
3579 preParams.takeFirst();
3580 preParams.takeFirst();
3581 QPoint zone = item->referencedClip()->zone();
3582 jobArgs << QString::number(zone.x()) << QString::number(zone.y());
3584 jobArgs << preParams;
3585 if (ids.count() == 1) {
3586 jobArgs << consumer + ':' + destination;
3589 jobArgs << consumer + ':' + destination + item->clipUrl().fileName() + ".mlt";
3591 jobArgs << jobParams;
3593 MeltJob *job = new MeltJob(item->clipType(), id, jobArgs, extraParams);
3595 job->setAddClipToProject(true);
3596 kDebug()<<"// ADDING TRUE";
3598 else kDebug()<<"// ADDING FALSE!!!";
3600 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3604 job->description = description;
3605 m_jobList.append(job);
3606 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3607 slotCheckJobProcess();
3612 void ProjectList::slotPrepareJobsMenu()
3615 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
3617 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
3618 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
3620 item = static_cast <ProjectItem*>(m_listView->currentItem());
3621 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
3622 QString id = item->clipId();
3623 m_discardCurrentClipJobs->setData(id);
3624 QStringList jobs = getPendingJobs(id);
3625 m_discardCurrentClipJobs->setEnabled(!jobs.isEmpty());
3627 m_discardCurrentClipJobs->setData(QString());
3628 m_discardCurrentClipJobs->setEnabled(false);
3632 void ProjectList::slotDiscardClipJobs()
3634 QString id = m_discardCurrentClipJobs->data().toString();
3635 if (id.isEmpty()) return;
3639 void ProjectList::updatePalette()
3641 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(QApplication::palette()));
3642 m_listView->updateStyleSheet();
3645 void ProjectList::slotResetInfoMessage()
3647 #if KDE_IS_VERSION(4,7,0)
3649 QList<QAction *> actions = m_infoMessage->actions();
3650 for (int i = 0; i < actions.count(); i++) {
3651 m_infoMessage->removeAction(actions.at(i));
3656 void ProjectList::slotClosePopup()
3661 void ProjectList::slotGotFilterJobResults(QString id, int , int , stringMap results, stringMap filterInfo)
3663 // Currently, only the first value of results is used
3664 //kDebug()<<"// FILTER RES:\n"<<filterInfo<<"\n--------------\n"<<results;
3665 ProjectItem *clip = getItemById(id);
3668 // Check for return value
3669 int markersType = -1;
3670 if (filterInfo.contains("addmarkers")) markersType = filterInfo.value("addmarkers").toInt();
3671 if (results.isEmpty()) {
3672 emit displayMessage(i18n("No data returned from clip analysis"), 0, ErrorMessage);
3675 bool dataProcessed = false;
3676 QString key = filterInfo.value("key");
3677 int offset = filterInfo.value("offset").toInt();
3678 QStringList value = results.value(key).split(';', QString::SkipEmptyParts);
3679 kDebug()<<"// RESULT; "<<key<<" = "<<value;
3680 if (filterInfo.contains("resultmessage")) {
3681 QString mess = filterInfo.value("resultmessage");
3682 mess.replace("%count", QString::number(value.count()));
3683 emit displayMessage(mess, 0, InformationMessage);
3685 else emit displayMessage(i18n("Processing data analysis"), 0, InformationMessage);
3686 if (filterInfo.contains("cutscenes")) {
3687 // Check if we want to cut scenes from returned data
3688 dataProcessed = true;
3690 QUndoCommand *command = new QUndoCommand();
3691 command->setText(i18n("Auto Split Clip"));
3692 foreach (QString pos, value) {
3693 if (!pos.contains("=")) continue;
3694 int newPos = pos.section("=", 0, 0).toInt();
3695 // Don't use scenes shorter than 1 second
3696 if (newPos - cutPos < 24) continue;
3697 (void) new AddClipCutCommand(this, id, cutPos + offset, newPos + offset, QString(), true, false, command);
3700 if (command->childCount() == 0)
3702 else m_commandStack->push(command);
3704 if (markersType >= 0) {
3705 // Add markers from returned data
3706 dataProcessed = true;
3708 QUndoCommand *command = new QUndoCommand();
3709 command->setText(i18n("Add Markers"));
3710 QList <CommentedTime> markersList;
3712 foreach (QString pos, value) {
3713 if (!pos.contains("=")) continue;
3714 int newPos = pos.section("=", 0, 0).toInt();
3715 // Don't use scenes shorter than 1 second
3716 if (newPos - cutPos < 24) continue;
3717 CommentedTime m(GenTime(newPos + offset, m_fps), QString::number(index), markersType);
3722 emit addMarkers(id, markersList);
3724 if (!dataProcessed || filterInfo.contains("storedata")) {
3725 // Store returned data as clip extra data
3726 clip->referencedClip()->setAnalysisData(filterInfo.contains("displaydataname") ? filterInfo.value("displaydataname") : key, results.value(key), filterInfo.value("offset").toInt());
3727 emit updateAnalysisData(clip->referencedClip());
3732 #include "projectlist.moc"