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"
51 #include <KFileDialog>
52 #include <KInputDialog>
53 #include <KMessageBox>
54 #include <KIO/NetAccess>
56 #include <KApplication>
57 #include <KStandardDirs>
58 #include <KColorScheme>
59 #include <KActionCollection>
60 #include <KUrlRequester>
63 #include <nepomuk/global.h>
64 #include <nepomuk/resourcemanager.h>
65 #include <Nepomuk/Resource>
66 //#include <nepomuk/tag.h>
69 #include <QMouseEvent>
70 #include <QStylePainter>
76 #include <QHeaderView>
77 #include <QInputDialog>
78 #include <QtConcurrentRun>
79 #include <QVBoxLayout>
81 SmallInfoLabel::SmallInfoLabel(QWidget *parent) : QPushButton(parent)
86 /*QString style = "QToolButton {background-color: %1;border-style: outset;border-width: 2px;
87 border-radius: 5px;border-color: beige;}";*/
88 m_timeLine = new QTimeLine(500, this);
89 QObject::connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(slotTimeLineChanged(qreal)));
90 QObject::connect(m_timeLine, SIGNAL(finished()), this, SLOT(slotTimeLineFinished()));
94 const QString SmallInfoLabel::getStyleSheet(const QPalette &p)
96 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
97 QColor bg = scheme.background(KColorScheme::LinkBackground).color();
98 QColor fg = scheme.foreground(KColorScheme::LinkText).color();
99 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());
101 bg = scheme.background(KColorScheme::ActiveBackground).color();
102 fg = scheme.foreground(KColorScheme::ActiveText).color();
103 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()));
108 void SmallInfoLabel::slotTimeLineChanged(qreal value)
110 setFixedWidth(qMin(value * 2, qreal(1.0)) * sizeHint().width());
114 void SmallInfoLabel::slotTimeLineFinished()
116 if (m_timeLine->direction() == QTimeLine::Forward) {
126 void SmallInfoLabel::slotSetJobCount(int jobCount)
130 setText(i18np("%1 job", "%1 jobs", jobCount));
131 setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
133 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
134 setFixedWidth(sizeHint().width());
140 setFixedWidth(sizeHint().width());
147 int wantedWidth = sizeHint().width();
148 setGeometry(-wantedWidth, 0, wantedWidth, height());
149 m_timeLine->setDirection(QTimeLine::Forward);
150 if (m_timeLine->state() == QTimeLine::NotRunning) {
155 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
161 m_timeLine->setDirection(QTimeLine::Backward);
162 if (m_timeLine->state() == QTimeLine::NotRunning) {
170 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
173 if (infoOnly) setButtons(KDialog::Ok);
174 else setButtons(KDialog::Yes | KDialog::No);
175 QWidget *w = new QWidget(this);
176 QVBoxLayout *l = new QVBoxLayout;
177 l->addWidget(new QLabel(message));
178 m_clipList = new QListWidget;
179 l->addWidget(m_clipList);
184 InvalidDialog::~InvalidDialog()
190 void InvalidDialog::addClip(const QString &id, const QString &path)
192 QListWidgetItem *item = new QListWidgetItem(path);
193 item->setData(Qt::UserRole, id);
194 m_clipList->addItem(item);
197 QStringList InvalidDialog::getIds() const
200 for (int i = 0; i < m_clipList->count(); i++) {
201 ids << m_clipList->item(i)->data(Qt::UserRole).toString();
207 ProjectList::ProjectList(QWidget *parent) :
211 m_commandStack(NULL),
213 m_reloadAction(NULL),
214 m_extractAudioAction(NULL),
215 m_transcodeAction(NULL),
216 m_stabilizeAction(NULL),
219 m_allClipsProcessed(false),
221 m_abortAllJobs(false),
223 m_invalidClipDialog(NULL)
225 qRegisterMetaType<stringMap> ("stringMap");
226 QVBoxLayout *layout = new QVBoxLayout;
227 layout->setContentsMargins(0, 0, 0, 0);
228 layout->setSpacing(0);
229 qRegisterMetaType<QDomElement>("QDomElement");
231 QFrame *frame = new QFrame;
232 frame->setFrameStyle(QFrame::NoFrame);
233 QHBoxLayout *box = new QHBoxLayout;
234 box->setContentsMargins(0, 0, 0, 0);
236 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
237 box->addWidget(searchView);
239 // small info button for pending jobs
240 m_infoLabel = new SmallInfoLabel(this);
241 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(palette()));
242 connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
243 m_jobsMenu = new QMenu(this);
244 connect(m_jobsMenu, SIGNAL(aboutToShow()), this, SLOT(slotPrepareJobsMenu()));
245 QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this);
246 cancelJobs->setCheckable(false);
247 connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs()));
248 connect(this, SIGNAL(checkJobProcess()), this, SLOT(slotCheckJobProcess()));
249 m_discardCurrentClipJobs = new QAction(i18n("Cancel Current Clip Jobs"), this);
250 m_discardCurrentClipJobs->setCheckable(false);
251 connect(m_discardCurrentClipJobs, SIGNAL(triggered()), this, SLOT(slotDiscardClipJobs()));
252 m_jobsMenu->addAction(cancelJobs);
253 m_jobsMenu->addAction(m_discardCurrentClipJobs);
254 m_infoLabel->setMenu(m_jobsMenu);
255 box->addWidget(m_infoLabel);
257 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
258 QSize iconSize(size, size);
260 m_addButton = new QToolButton;
261 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
262 m_addButton->setAutoRaise(true);
263 m_addButton->setIconSize(iconSize);
264 box->addWidget(m_addButton);
266 m_editButton = new QToolButton;
267 m_editButton->setAutoRaise(true);
268 m_editButton->setIconSize(iconSize);
269 box->addWidget(m_editButton);
271 m_deleteButton = new QToolButton;
272 m_deleteButton->setAutoRaise(true);
273 m_deleteButton->setIconSize(iconSize);
274 box->addWidget(m_deleteButton);
275 frame->setLayout(box);
276 layout->addWidget(frame);
278 m_listView = new ProjectListView(this);
279 layout->addWidget(m_listView);
281 #if KDE_IS_VERSION(4,7,0)
282 m_infoMessage = new KMessageWidget;
283 layout->addWidget(m_infoMessage);
284 m_infoMessage->setCloseButtonVisible(true);
285 //m_infoMessage->setWordWrap(true);
286 m_infoMessage->hide();
287 m_logAction = new QAction(i18n("Show Log"), this);
288 m_logAction->setCheckable(false);
289 connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
293 searchView->setTreeWidget(m_listView);
295 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
296 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
297 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
298 connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
299 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
300 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
301 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
302 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
303 connect(this, SIGNAL(addClip(const QString, const QString &, const QString &)), this, SLOT(slotAddClip(const QString, const QString &, const QString &)));
304 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
305 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
306 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
308 connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap)));
309 connect(this, SIGNAL(processLog(const QString, int , int, const QString)), this, SLOT(slotProcessLog(const QString, int , int, const QString)));
311 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)));
313 connect(this, SIGNAL(gotProxy(const QString)), this, SLOT(slotGotProxyForId(const QString)));
315 m_listViewDelegate = new ItemDelegate(m_listView);
316 m_listView->setItemDelegate(m_listViewDelegate);
318 if (KdenliveSettings::activate_nepomuk()) {
319 Nepomuk::ResourceManager::instance()->init();
320 if (!Nepomuk::ResourceManager::instance()->initialized()) {
321 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
322 KdenliveSettings::setActivate_nepomuk(false);
328 ProjectList::~ProjectList()
330 m_abortAllJobs = true;
331 for (int i = 0; i < m_jobList.count(); i++) {
332 m_jobList.at(i)->setStatus(JOBABORTED);
335 m_thumbnailQueue.clear();
336 m_jobThreads.waitForFinished();
337 m_jobThreads.clearFutures();
338 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
341 m_listView->blockSignals(true);
343 delete m_listViewDelegate;
344 #if KDE_IS_VERSION(4,7,0)
345 delete m_infoMessage;
349 void ProjectList::focusTree() const
351 m_listView->setFocus();
354 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
356 QList <QAction *> actions = addMenu->actions();
357 for (int i = 0; i < actions.count(); i++) {
358 if (actions.at(i)->data().toString() == "clip_properties") {
359 m_editButton->setDefaultAction(actions.at(i));
362 } else if (actions.at(i)->data().toString() == "delete_clip") {
363 m_deleteButton->setDefaultAction(actions.at(i));
366 } else if (actions.at(i)->data().toString() == "edit_clip") {
367 m_openAction = actions.at(i);
370 } else if (actions.at(i)->data().toString() == "reload_clip") {
371 m_reloadAction = actions.at(i);
374 } else if (actions.at(i)->data().toString() == "proxy_clip") {
375 m_proxyAction = actions.at(i);
381 QMenu *m = new QMenu();
382 m->addActions(actions);
383 m_addButton->setMenu(m);
384 m_addButton->setDefaultAction(defaultAction);
385 m_menu = new QMenu();
386 m_menu->addActions(addMenu->actions());
389 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
391 if (!menus.contains("addMenu") && ! menus.value("addMenu") )
393 QMenu *menu = m_addButton->menu();
394 if (menus.contains("addMenu") && menus.value("addMenu")){
395 QMenu* addMenu=menus.value("addMenu");
396 menu->addMenu(addMenu);
397 m_addButton->setMenu(menu);
398 if (addMenu->isEmpty())
399 addMenu->setEnabled(false);
401 if (menus.contains("extractAudioMenu") && menus.value("extractAudioMenu") ){
402 QMenu* extractAudioMenu = menus.value("extractAudioMenu");
403 m_menu->addMenu(extractAudioMenu);
404 m_extractAudioAction = extractAudioMenu;
406 if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
407 QMenu* transcodeMenu = menus.value("transcodeMenu");
408 m_menu->addMenu(transcodeMenu);
409 if (transcodeMenu->isEmpty())
410 transcodeMenu->setEnabled(false);
411 m_transcodeAction = transcodeMenu;
413 if (menus.contains("stabilizeMenu") && menus.value("stabilizeMenu") ){
414 QMenu* stabilizeMenu=menus.value("stabilizeMenu");
415 m_menu->addMenu(stabilizeMenu);
416 if (stabilizeMenu->isEmpty())
417 stabilizeMenu->setEnabled(false);
418 m_stabilizeAction=stabilizeMenu;
421 m_menu->addAction(m_reloadAction);
422 m_menu->addAction(m_proxyAction);
423 if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
424 QMenu* inTimelineMenu=menus.value("inTimelineMenu");
425 m_menu->addMenu(inTimelineMenu);
426 inTimelineMenu->setEnabled(false);
428 m_menu->addAction(m_editButton->defaultAction());
429 m_menu->addAction(m_openAction);
430 m_menu->addAction(m_deleteButton->defaultAction());
431 m_menu->insertSeparator(m_deleteButton->defaultAction());
434 void ProjectList::clearSelection()
436 m_listView->clearSelection();
439 QByteArray ProjectList::headerInfo() const
441 return m_listView->header()->saveState();
444 void ProjectList::setHeaderInfo(const QByteArray &state)
446 m_listView->header()->restoreState(state);
449 void ProjectList::updateProjectFormat(Timecode t)
454 void ProjectList::slotEditClip()
456 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
457 if (list.isEmpty()) return;
458 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
459 editClipSelection(list);
463 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
465 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
466 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
468 item = static_cast <ProjectItem*>(m_listView->currentItem());
469 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
470 emit clipSelected(item->referencedClip());
471 emit showClipProperties(item->referencedClip());
475 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
477 // Gather all common properties
478 QMap <QString, QString> commonproperties;
479 QList <DocClipBase *> clipList;
480 commonproperties.insert("force_aspect_num", "-");
481 commonproperties.insert("force_aspect_den", "-");
482 commonproperties.insert("force_fps", "-");
483 commonproperties.insert("force_progressive", "-");
484 commonproperties.insert("force_tff", "-");
485 commonproperties.insert("threads", "-");
486 commonproperties.insert("video_index", "-");
487 commonproperties.insert("audio_index", "-");
488 commonproperties.insert("force_colorspace", "-");
489 commonproperties.insert("full_luma", "-");
490 QString transparency = "-";
492 bool allowDurationChange = true;
493 int commonDuration = -1;
494 bool hasImages = false;;
496 for (int i = 0; i < list.count(); i++) {
498 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
499 // Add folder items to the list
500 int ct = list.at(i)->childCount();
501 for (int j = 0; j < ct; j++) {
502 list.append(list.at(i)->child(j));
506 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
507 item = static_cast <ProjectItem*>(list.at(i)->parent());
509 item = static_cast <ProjectItem*>(list.at(i));
510 if (!(item->flags() & Qt::ItemIsDragEnabled))
514 DocClipBase *clip = item->referencedClip();
515 if (clipList.contains(clip)) continue;
516 if (clip->clipType() == IMAGE) {
518 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
519 if (transparency == "-") {
520 // first non transparent image
523 else if (transparency == "1") {
524 // we have transparent and non transparent clips
529 if (transparency == "-") {
530 // first transparent image
533 else if (transparency == "0") {
534 // we have transparent and non transparent clips
539 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
540 allowDurationChange = false;
541 if (allowDurationChange && commonDuration != 0) {
542 if (commonDuration == -1)
543 commonDuration = clip->duration().frames(m_fps);
544 else if (commonDuration != clip->duration().frames(m_fps))
547 clipList.append(clip);
548 QMap <QString, QString> clipprops = clip->properties();
549 QMapIterator<QString, QString> p(commonproperties);
550 while (p.hasNext()) {
552 if (p.value().isEmpty()) continue;
553 if (clipprops.contains(p.key())) {
554 if (p.value() == "-")
555 commonproperties.insert(p.key(), clipprops.value(p.key()));
556 else if (p.value() != clipprops.value(p.key()))
557 commonproperties.insert(p.key(), QString());
559 commonproperties.insert(p.key(), QString());
564 if (allowDurationChange)
565 commonproperties.insert("out", QString::number(commonDuration));
567 commonproperties.insert("transparency", transparency);
568 /*QMapIterator<QString, QString> p(commonproperties);
569 while (p.hasNext()) {
571 kDebug() << "Result: " << p.key() << " = " << p.value();
573 if (clipList.isEmpty()) {
574 emit displayMessage(i18n("No available clip selected"), -2);
576 else emit showClipProperties(clipList, commonproperties);
579 void ProjectList::slotOpenClip()
582 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
584 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
585 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
587 item = static_cast <ProjectItem*>(m_listView->currentItem());
589 if (item->clipType() == IMAGE) {
590 if (KdenliveSettings::defaultimageapp().isEmpty())
591 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
593 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
595 if (item->clipType() == AUDIO) {
596 if (KdenliveSettings::defaultaudioapp().isEmpty())
597 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
599 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
604 void ProjectList::cleanup()
606 m_listView->clearSelection();
607 QTreeWidgetItemIterator it(m_listView);
610 if ((*it)->type() != PROJECTCLIPTYPE) {
614 item = static_cast <ProjectItem *>(*it);
615 if (item->numReferences() == 0)
616 item->setSelected(true);
622 void ProjectList::trashUnusedClips()
624 QTreeWidgetItemIterator it(m_listView);
629 if ((*it)->type() != PROJECTCLIPTYPE) {
633 item = static_cast <ProjectItem *>(*it);
634 if (item->numReferences() == 0) {
635 ids << item->clipId();
636 KUrl url = item->clipUrl();
637 if (!url.isEmpty() && !urls.contains(url.path()))
643 // Check that we don't use the URL in another clip
644 QTreeWidgetItemIterator it2(m_listView);
646 if ((*it2)->type() != PROJECTCLIPTYPE) {
650 item = static_cast <ProjectItem *>(*it2);
651 if (item->numReferences() > 0) {
652 KUrl url = item->clipUrl();
653 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
658 emit deleteProjectClips(ids, QMap <QString, QString>());
659 for (int i = 0; i < urls.count(); i++)
660 KIO::NetAccess::del(KUrl(urls.at(i)), this);
663 void ProjectList::slotReloadClip(const QString &id)
665 QList<QTreeWidgetItem *> selected;
667 selected = m_listView->selectedItems();
669 ProjectItem *itemToReLoad = getItemById(id);
670 if (itemToReLoad) selected.append(itemToReLoad);
673 for (int i = 0; i < selected.count(); i++) {
674 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
675 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
676 for (int j = 0; j < selected.at(i)->childCount(); j++)
677 selected.append(selected.at(i)->child(j));
681 item = static_cast <ProjectItem *>(selected.at(i));
682 if (item && !hasPendingJob(item, PROXYJOB)) {
683 DocClipBase *clip = item->referencedClip();
684 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
685 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
688 CLIPTYPE t = item->clipType();
690 if (clip && !clip->getProperty("xmltemplate").isEmpty())
691 regenerateTemplate(item);
692 } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
693 item->referencedClip()->setPlaceHolder(true);
694 item->setProperty("file_hash", QString());
695 } else if (t == IMAGE) {
696 clip->getProducer()->set("force_reload", 1);
699 QDomElement e = item->toXml();
700 // Make sure we get the correct producer length if it was adjusted in timeline
701 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
702 int length = QString(clip->producerProperty("length")).toInt();
703 if (length > 0 && !e.hasAttribute("length")) {
704 e.setAttribute("length", length);
707 resetThumbsProducer(clip);
708 m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
713 void ProjectList::slotModifiedClip(const QString &id)
715 ProjectItem *item = getItemById(id);
717 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
718 if (!pixmap.isNull()) {
720 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
721 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
724 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
726 item->setData(0, Qt::DecorationRole, pixmap);
730 void ProjectList::slotMissingClip(const QString &id)
732 ProjectItem *item = getItemById(id);
734 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
735 int height = m_listView->iconSize().height();
736 int width = (int)(height * m_render->dar());
737 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
738 if (pixmap.isNull()) {
739 pixmap = QPixmap(width, height);
740 pixmap.fill(Qt::transparent);
742 KIcon icon("dialog-close");
744 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
746 item->setData(0, Qt::DecorationRole, pixmap);
747 if (item->referencedClip()) {
748 item->referencedClip()->setPlaceHolder(true);
749 if (m_render == NULL) {
750 kDebug() << "********* ERROR, NULL RENDR";
753 Mlt::Producer *newProd = m_render->invalidProducer(id);
754 if (item->referencedClip()->getProducer()) {
755 Mlt::Properties props(newProd->get_properties());
756 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
757 props.inherit(src_props);
759 item->referencedClip()->setProducer(newProd, true);
760 item->slotSetToolTip();
761 emit clipNeedsReload(id);
765 emit displayMessage(i18n("Check missing clips"), -2);
766 emit updateRenderStatus();
769 void ProjectList::slotAvailableClip(const QString &id)
771 ProjectItem *item = getItemById(id);
774 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
775 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
776 item->setProperty("file_hash", QString());
780 item->referencedClip()->setValid();
781 item->slotSetToolTip();
784 emit updateRenderStatus();
787 bool ProjectList::hasMissingClips()
789 bool missing = false;
790 QTreeWidgetItemIterator it(m_listView);
792 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
801 void ProjectList::setRenderer(Render *projectRender)
803 m_render = projectRender;
804 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
805 connect(m_render, SIGNAL(requestProxy(QString)), this, SLOT(slotCreateProxy(QString)));
808 void ProjectList::slotClipSelected()
810 QTreeWidgetItem *item = m_listView->currentItem();
811 ProjectItem *clip = NULL;
813 if (item->type() == PROJECTFOLDERTYPE) {
814 emit clipSelected(NULL);
815 m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
816 m_deleteButton->defaultAction()->setEnabled(true);
817 m_openAction->setEnabled(false);
818 m_reloadAction->setEnabled(false);
819 m_extractAudioAction->setEnabled(false);
820 m_transcodeAction->setEnabled(false);
821 m_stabilizeAction->setEnabled(false);
823 if (item->type() == PROJECTSUBCLIPTYPE) {
824 // this is a sub item, use base clip
825 m_deleteButton->defaultAction()->setEnabled(true);
826 clip = static_cast <ProjectItem*>(item->parent());
827 if (clip == NULL) kDebug() << "-----------ERROR";
828 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
829 emit clipSelected(clip->referencedClip(), sub->zone());
830 m_extractAudioAction->setEnabled(false);
831 m_transcodeAction->setEnabled(false);
832 m_stabilizeAction->setEnabled(false);
833 m_reloadAction->setEnabled(false);
834 adjustProxyActions(clip);
837 clip = static_cast <ProjectItem*>(item);
838 if (clip && clip->referencedClip())
839 emit clipSelected(clip->referencedClip());
840 m_editButton->defaultAction()->setEnabled(true);
841 m_deleteButton->defaultAction()->setEnabled(true);
842 m_reloadAction->setEnabled(true);
843 m_extractAudioAction->setEnabled(true);
844 m_transcodeAction->setEnabled(true);
845 m_stabilizeAction->setEnabled(true);
846 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
847 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
848 m_openAction->setEnabled(true);
849 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
850 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
851 m_openAction->setEnabled(true);
853 m_openAction->setEnabled(false);
855 // Display relevant transcoding actions only
856 adjustTranscodeActions(clip);
857 adjustStabilizeActions(clip);
858 // Display uses in timeline
859 emit findInTimeline(clip->clipId());
862 emit clipSelected(NULL);
863 m_editButton->defaultAction()->setEnabled(false);
864 m_deleteButton->defaultAction()->setEnabled(false);
865 m_openAction->setEnabled(false);
866 m_reloadAction->setEnabled(false);
867 m_extractAudioAction->setEnabled(true);
868 m_transcodeAction->setEnabled(false);
869 m_stabilizeAction->setEnabled(false);
871 adjustProxyActions(clip);
874 void ProjectList::adjustProxyActions(ProjectItem *clip) const
876 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
877 m_proxyAction->setEnabled(false);
880 bool enabled = useProxy();
881 if (clip->referencedClip() && !clip->referencedClip()->getProperty("_missingsource").isEmpty()) enabled = false;
882 m_proxyAction->setEnabled(enabled);
883 m_proxyAction->blockSignals(true);
884 m_proxyAction->setChecked(clip->hasProxy());
885 m_proxyAction->blockSignals(false);
888 void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
891 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
892 m_stabilizeAction->setEnabled(false);
895 m_stabilizeAction->setEnabled(true);
899 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
901 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
902 m_transcodeAction->setEnabled(false);
903 m_extractAudioAction->setEnabled(false);
906 m_transcodeAction->setEnabled(true);
907 m_extractAudioAction->setEnabled(true);
908 QList<QAction *> transcodeActions = m_transcodeAction->actions();
911 for (int i = 0; i < transcodeActions.count(); i++) {
912 data = transcodeActions.at(i)->data().toStringList();
913 if (data.count() > 2) {
914 condition = data.at(2);
915 if (condition.startsWith("vcodec"))
916 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
917 else if (condition.startsWith("acodec"))
918 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
924 void ProjectList::slotPauseMonitor()
930 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
932 ProjectItem *item = getItemById(id);
934 slotUpdateClipProperties(item, properties);
935 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
937 } else if (properties.contains("colour") ||
938 properties.contains("xmldata") ||
939 properties.contains("force_aspect_num") ||
940 properties.contains("force_aspect_den") ||
941 properties.contains("templatetext")) {
942 slotRefreshClipThumbnail(item);
943 emit refreshClip(id, true);
944 } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
945 emit refreshClip(id, false);
950 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
954 clip->setProperties(properties);
955 if (properties.contains("proxy")) {
956 if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
957 // this should only apply to proxy jobs
958 clip->setConditionalJobStatus(NOJOB, PROXYJOB);
960 if (properties.contains("name")) {
961 monitorItemEditing(false);
962 clip->setText(0, properties.value("name"));
963 monitorItemEditing(true);
964 emit clipNameChanged(clip->clipId(), properties.value("name"));
966 if (properties.contains("description")) {
967 CLIPTYPE type = clip->clipType();
968 monitorItemEditing(false);
969 clip->setText(1, properties.value("description"));
970 monitorItemEditing(true);
972 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
973 // Use Nepomuk system to store clip description
974 Nepomuk::Resource f(clip->clipUrl().path());
975 f.setDescription(properties.value("description"));
978 emit projectModified();
982 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
984 if (item->type() == PROJECTSUBCLIPTYPE) {
985 // this is a sub-item
987 // user edited description
988 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
989 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
990 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
991 m_commandStack->push(command);
992 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
996 if (item->type() == PROJECTFOLDERTYPE) {
998 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
999 editFolder(item->text(0), folder->groupName(), folder->clipId());
1000 folder->setGroupName(item->text(0));
1001 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
1002 const int children = item->childCount();
1003 for (int i = 0; i < children; i++) {
1004 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1005 child->setProperty("groupname", item->text(0));
1011 ProjectItem *clip = static_cast <ProjectItem*>(item);
1013 if (clip->referencedClip()) {
1014 QMap <QString, QString> oldprops;
1015 QMap <QString, QString> newprops;
1016 oldprops["description"] = clip->referencedClip()->getProperty("description");
1017 newprops["description"] = item->text(1);
1019 if (clip->clipType() == TEXT) {
1020 // This is a text template clip, update the image
1021 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
1022 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
1023 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
1024 newprops.insert("templatetext", item->text(1));
1026 slotUpdateClipProperties(clip->clipId(), newprops);
1027 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1028 m_commandStack->push(command);
1030 } else if (column == 0) {
1031 if (clip->referencedClip()) {
1032 QMap <QString, QString> oldprops;
1033 QMap <QString, QString> newprops;
1034 oldprops["name"] = clip->referencedClip()->getProperty("name");
1035 if (oldprops.value("name") != item->text(0)) {
1036 newprops["name"] = item->text(0);
1037 slotUpdateClipProperties(clip, newprops);
1038 emit projectModified();
1039 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1040 m_commandStack->push(command);
1041 QTimer::singleShot(100, this, SLOT(slotCheckScrolling()));
1047 void ProjectList::slotCheckScrolling()
1049 m_listView->scrollToItem(m_listView->currentItem());
1052 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
1054 bool enable = item ? true : false;
1055 m_editButton->defaultAction()->setEnabled(enable);
1056 m_deleteButton->defaultAction()->setEnabled(enable);
1057 m_reloadAction->setEnabled(enable);
1058 m_extractAudioAction->setEnabled(enable);
1059 m_transcodeAction->setEnabled(enable);
1060 m_stabilizeAction->setEnabled(enable);
1062 ProjectItem *clip = NULL;
1063 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1064 clip = static_cast <ProjectItem*>(item->parent());
1065 m_extractAudioAction->setEnabled(false);
1066 m_transcodeAction->setEnabled(false);
1067 m_stabilizeAction->setEnabled(false);
1068 adjustProxyActions(clip);
1069 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
1070 clip = static_cast <ProjectItem*>(item);
1071 // Display relevant transcoding actions only
1072 adjustTranscodeActions(clip);
1073 adjustStabilizeActions(clip);
1074 adjustProxyActions(clip);
1075 // Display uses in timeline
1076 emit findInTimeline(clip->clipId());
1078 m_extractAudioAction->setEnabled(false);
1079 m_transcodeAction->setEnabled(false);
1080 m_stabilizeAction->setEnabled(false);
1082 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1083 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1084 m_openAction->setEnabled(true);
1085 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1086 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1087 m_openAction->setEnabled(true);
1089 m_openAction->setEnabled(false);
1093 m_openAction->setEnabled(false);
1098 void ProjectList::slotRemoveClip()
1100 if (!m_listView->currentItem())
1103 QMap <QString, QString> folderids;
1104 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
1106 QUndoCommand *delCommand = new QUndoCommand();
1107 delCommand->setText(i18n("Delete Clip Zone"));
1108 for (int i = 0; i < selected.count(); i++) {
1109 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
1111 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
1112 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1113 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
1114 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
1116 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
1117 folderids[folder->groupName()] = folder->clipId();
1118 int children = folder->childCount();
1120 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)
1122 for (int i = 0; i < children; ++i) {
1123 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
1124 ids << child->clipId();
1127 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
1128 ids << item->clipId();
1129 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) {
1130 KMessageBox::enableMessage("DeleteAll");
1135 KMessageBox::enableMessage("DeleteAll");
1136 if (delCommand->childCount() == 0)
1139 m_commandStack->push(delCommand);
1140 emit deleteProjectClips(ids, folderids);
1143 void ProjectList::updateButtons() const
1145 if (m_listView->topLevelItemCount() == 0) {
1146 m_deleteButton->defaultAction()->setEnabled(false);
1147 m_editButton->defaultAction()->setEnabled(false);
1149 m_deleteButton->defaultAction()->setEnabled(true);
1150 if (!m_listView->currentItem())
1151 m_listView->setCurrentItem(m_listView->topLevelItem(0));
1152 QTreeWidgetItem *item = m_listView->currentItem();
1153 if (item && item->type() == PROJECTCLIPTYPE) {
1154 m_editButton->defaultAction()->setEnabled(true);
1155 m_openAction->setEnabled(true);
1156 m_reloadAction->setEnabled(true);
1157 m_transcodeAction->setEnabled(true);
1158 m_stabilizeAction->setEnabled(true);
1161 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
1162 m_editButton->defaultAction()->setEnabled(true);
1164 else m_editButton->defaultAction()->setEnabled(false);
1166 m_openAction->setEnabled(false);
1167 m_reloadAction->setEnabled(false);
1168 m_transcodeAction->setEnabled(false);
1169 m_stabilizeAction->setEnabled(false);
1170 m_proxyAction->setEnabled(false);
1173 void ProjectList::selectItemById(const QString &clipId)
1175 ProjectItem *item = getItemById(clipId);
1177 m_listView->setCurrentItem(item);
1181 void ProjectList::slotDeleteClip(const QString &clipId)
1183 ProjectItem *item = getItemById(clipId);
1185 kDebug() << "/// Cannot find clip to delete";
1188 deleteJobsForClip(clipId);
1189 m_listView->blockSignals(true);
1190 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1191 if (!newSelectedItem)
1192 newSelectedItem = m_listView->itemBelow(item);
1194 // Pause playing to prevent crash while deleting clip
1196 m_doc->clipManager()->deleteClip(clipId);
1197 m_listView->blockSignals(false);
1198 if (newSelectedItem) {
1199 m_listView->setCurrentItem(newSelectedItem);
1202 emit clipSelected(NULL);
1207 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1209 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1210 m_commandStack->push(command);
1211 m_doc->setModified(true);
1214 void ProjectList::slotAddFolder(const QString &name)
1216 AddFolderCommand *command = new AddFolderCommand(this, name.isEmpty() ? i18n("Folder") : name, QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1217 m_commandStack->push(command);
1220 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
1223 FolderProjectItem *item = getFolderItemById(clipId);
1225 m_doc->clipManager()->deleteFolder(clipId);
1226 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1227 if (!newSelectedItem)
1228 newSelectedItem = m_listView->itemBelow(item);
1230 if (newSelectedItem)
1231 m_listView->setCurrentItem(newSelectedItem);
1237 FolderProjectItem *item = getFolderItemById(clipId);
1239 m_listView->blockSignals(true);
1240 item->setGroupName(foldername);
1241 m_listView->blockSignals(false);
1242 m_doc->clipManager()->addFolder(clipId, foldername);
1243 const int children = item->childCount();
1244 for (int i = 0; i < children; i++) {
1245 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1246 child->setProperty("groupname", foldername);
1250 m_listView->blockSignals(true);
1251 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1252 m_doc->clipManager()->addFolder(clipId, foldername);
1253 m_listView->blockSignals(false);
1254 m_listView->editItem(m_listView->currentItem(), 0);
1258 m_doc->setModified(true);
1263 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1265 QMapIterator<QString, QString> i(map);
1266 QUndoCommand *delCommand = new QUndoCommand();
1267 delCommand->setText(i18n("Delete Folder"));
1268 while (i.hasNext()) {
1270 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1272 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1273 else delete delCommand;
1276 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1278 //m_listView->setEnabled(false);
1279 const QString parent = clip->getProperty("groupid");
1280 ProjectItem *item = NULL;
1281 monitorItemEditing(false);
1282 if (!parent.isEmpty()) {
1283 FolderProjectItem *parentitem = getFolderItemById(parent);
1286 QString groupName = clip->getProperty("groupname");
1287 //kDebug() << "Adding clip to new group: " << groupName;
1288 if (groupName.isEmpty()) groupName = i18n("Folder");
1290 parentitem = new FolderProjectItem(m_listView, text, parent);
1294 item = new ProjectItem(parentitem, clip);
1297 item = new ProjectItem(m_listView, clip);
1299 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1300 connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1301 connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1302 if (getProperties) {
1303 int height = m_listView->iconSize().height();
1304 int width = (int)(height * m_render->dar());
1305 QPixmap pix = KIcon("video-x-generic").pixmap(QSize(width, height));
1306 item->setData(0, Qt::DecorationRole, pix);
1307 //item->setFlags(Qt::ItemIsSelectable);
1308 m_listView->processLayout();
1309 QDomElement e = clip->toXML().cloneNode().toElement();
1310 e.removeAttribute("file_hash");
1311 resetThumbsProducer(clip);
1312 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1314 // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases?
1315 /*else if (item->hasProxy() && !item->isJobRunning()) {
1316 slotCreateProxy(clip->getId());
1319 KUrl url = clip->fileURL();
1321 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk() && clip->getProperty("description").isEmpty()) {
1322 // if file has Nepomuk comment, use it
1323 Nepomuk::Resource f(url.path());
1324 QString annotation = f.description();
1325 if (!annotation.isEmpty()) {
1326 item->setText(1, annotation);
1327 clip->setProperty("description", annotation);
1329 item->setText(2, QString::number(f.rating()));
1333 // Add info to date column
1334 QFileInfo fileInfo(url.path());
1335 if (fileInfo.exists()) {
1336 item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1340 QList <CutZoneInfo> cuts = clip->cutZones();
1341 if (!cuts.isEmpty()) {
1342 for (int i = 0; i < cuts.count(); i++) {
1343 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1344 if (!clip->getClipHash().isEmpty()) {
1345 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1346 if (QFile::exists(cachedPixmap)) {
1347 QPixmap pix(cachedPixmap);
1349 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1350 sub->setData(0, Qt::DecorationRole, pix);
1355 monitorItemEditing(true);
1359 void ProjectList::slotGotProxy(const QString &proxyPath)
1361 if (proxyPath.isEmpty() || m_abortAllJobs) return;
1362 QTreeWidgetItemIterator it(m_listView);
1365 while (*it && !m_closing) {
1366 if ((*it)->type() == PROJECTCLIPTYPE) {
1367 item = static_cast <ProjectItem *>(*it);
1368 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1375 void ProjectList::slotGotProxyForId(const QString id)
1377 if (m_closing) return;
1378 ProjectItem *item = getItemById(id);
1382 void ProjectList::slotGotProxy(ProjectItem *item)
1384 if (item == NULL) return;
1385 DocClipBase *clip = item->referencedClip();
1386 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1387 // Clip is being reprocessed, abort
1388 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1392 // Proxy clip successfully created
1393 QDomElement e = clip->toXML().cloneNode().toElement();
1395 // Make sure we get the correct producer length if it was adjusted in timeline
1396 CLIPTYPE t = item->clipType();
1397 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1398 int length = QString(clip->producerProperty("length")).toInt();
1399 if (length > 0 && !e.hasAttribute("length")) {
1400 e.setAttribute("length", length);
1403 resetThumbsProducer(clip);
1404 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1407 void ProjectList::slotResetProjectList()
1409 m_listView->blockSignals(true);
1410 m_abortAllJobs = true;
1411 for (int i = 0; i < m_jobList.count(); i++) {
1412 m_jobList.at(i)->setStatus(JOBABORTED);
1415 m_jobThreads.waitForFinished();
1416 m_jobThreads.clearFutures();
1417 m_thumbnailQueue.clear();
1418 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
1420 m_listView->clear();
1421 m_listView->setEnabled(true);
1422 emit clipSelected(NULL);
1423 m_refreshed = false;
1424 m_allClipsProcessed = false;
1425 m_abortAllJobs = false;
1427 m_listView->blockSignals(false);
1430 void ProjectList::slotUpdateClip(const QString &id)
1432 ProjectItem *item = getItemById(id);
1433 monitorItemEditing(false);
1434 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1435 monitorItemEditing(true);
1438 void ProjectList::getCachedThumbnail(ProjectItem *item)
1441 DocClipBase *clip = item->referencedClip();
1443 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1444 if (QFile::exists(cachedPixmap)) {
1445 QPixmap pix(cachedPixmap);
1447 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1448 requestClipThumbnail(item->clipId());
1451 processThumbOverlays(item, pix);
1452 item->setData(0, Qt::DecorationRole, pix);
1456 requestClipThumbnail(item->clipId());
1460 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1463 ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1464 if (!parentItem) return;
1465 DocClipBase *clip = parentItem->referencedClip();
1467 int pos = item->zone().x();
1468 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + "#" + QString::number(pos) + ".png";
1469 if (QFile::exists(cachedPixmap)) {
1470 QPixmap pix(cachedPixmap);
1472 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1473 requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1475 else item->setData(0, Qt::DecorationRole, pix);
1477 else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1480 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1482 if (!m_allClipsProcessed) m_listView->setEnabled(false);
1483 m_listView->setSortingEnabled(false);
1484 QTreeWidgetItemIterator it(m_listView);
1487 monitorItemEditing(false);
1488 int height = m_listView->iconSize().height();
1489 int width = (int)(height * m_render->dar());
1490 QPixmap missingPixmap = QPixmap(width, height);
1491 missingPixmap.fill(Qt::transparent);
1492 KIcon icon("dialog-close");
1493 QPainter p(&missingPixmap);
1494 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1497 int max = m_doc->clipManager()->clipsCount();
1502 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1503 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1505 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1506 if (displayRatioChanged) {
1507 item = static_cast <ProjectItem *>((*it)->parent());
1508 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1510 else if (sub->data(0, Qt::DecorationRole).isNull()) {
1511 getCachedThumbnail(sub);
1515 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1520 item = static_cast <ProjectItem *>(*it);
1521 clip = item->referencedClip();
1522 if (clip->getProducer() == NULL) {
1523 bool replace = false;
1524 if (brokenClips.contains(item->clipId())) {
1525 // if this is a proxy clip, disable proxy
1526 item->setConditionalJobStatus(NOJOB, PROXYJOB);
1527 discardJobs(item->clipId(), PROXYJOB);
1528 clip->setProperty("proxy", "-");
1531 if (clip->isPlaceHolder() == false && !hasPendingJob(item, PROXYJOB)) {
1532 QDomElement xml = clip->toXML();
1534 xml.removeAttribute("out");
1535 xml.removeAttribute("file_hash");
1536 xml.removeAttribute("proxy_out");
1538 if (!replace) replace = xml.attribute("_replaceproxy") == "1";
1539 xml.removeAttribute("_replaceproxy");
1541 resetThumbsProducer(clip);
1543 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1545 else if (clip->isPlaceHolder()) {
1546 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1547 if (item->data(0, Qt::DecorationRole).isNull()) {
1548 item->setData(0, Qt::DecorationRole, missingPixmap);
1551 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1552 QPainter p(&pixmap);
1553 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1555 item->setData(0, Qt::DecorationRole, pixmap);
1559 if (displayRatioChanged) {
1560 requestClipThumbnail(clip->getId());
1562 else if (item->data(0, Qt::DecorationRole).isNull()) {
1563 getCachedThumbnail(item);
1565 if (item->data(0, DurationRole).toString().isEmpty()) {
1566 item->changeDuration(clip->getProducer()->get_playtime());
1568 if (clip->isPlaceHolder()) {
1569 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1570 if (pixmap.isNull()) {
1571 pixmap = QPixmap(width, height);
1572 pixmap.fill(Qt::transparent);
1574 QPainter p(&pixmap);
1575 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1577 item->setData(0, Qt::DecorationRole, pixmap);
1579 else if (clip->getProperty("_replaceproxy") == "1") {
1580 clip->setProperty("_replaceproxy", QString());
1581 slotCreateProxy(clip->getId());
1584 item->setData(0, UsageRole, QString::number(item->numReferences()));
1589 m_listView->setSortingEnabled(true);
1590 m_allClipsProcessed = true;
1591 if (m_render->processingItems() == 0) {
1592 monitorItemEditing(true);
1593 slotProcessNextThumbnail();
1598 QString ProjectList::getExtensions()
1600 // Build list of mime types
1601 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1602 << "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"
1603 << "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"
1604 << "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";
1606 QString allExtensions;
1607 foreach(const QString & mimeType, mimeTypes) {
1608 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1610 allExtensions.append(mime->patterns().join(" "));
1611 allExtensions.append(' ');
1614 return allExtensions.simplified();
1617 void ProjectList::slotAddClip(const QString url, const QString &groupName, const QString &groupId)
1619 kDebug()<<"// Adding clip: "<<url;
1622 slotAddClip(list, groupName, groupId);
1625 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1627 if (!m_commandStack)
1628 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1631 if (givenList.isEmpty()) {
1632 QString allExtensions = getExtensions();
1633 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1634 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1635 b->setChecked(KdenliveSettings::autoimagesequence());
1636 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1637 c->setChecked(KdenliveSettings::autoimagetransparency());
1638 QFrame *f = new QFrame;
1639 f->setFrameShape(QFrame::NoFrame);
1640 QHBoxLayout *l = new QHBoxLayout;
1645 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1646 d->setOperationMode(KFileDialog::Opening);
1647 d->setMode(KFile::Files);
1648 if (d->exec() == QDialog::Accepted) {
1649 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1651 list = d->selectedUrls();
1652 if (b->isChecked() && list.count() == 1) {
1653 // Check for image sequence
1654 KUrl url = list.at(0);
1655 QString fileName = url.fileName().section('.', 0, -2);
1656 if (fileName.at(fileName.size() - 1).isDigit()) {
1657 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1658 if (item.mimetype().startsWith("image")) {
1659 // import as sequence if we found more than one image in the sequence
1661 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1662 int count = list.count();
1665 QStringList groupInfo = getGroup();
1667 // get image sequence base name
1668 while (fileName.at(fileName.size() - 1).isDigit()) {
1671 QMap <QString, QString> properties;
1672 properties.insert("name", fileName);
1673 properties.insert("resource", pattern);
1674 properties.insert("in", "0");
1675 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
1676 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
1677 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
1678 properties.insert("loop", QString::number(false));
1679 properties.insert("crop", QString::number(false));
1680 properties.insert("fade", QString::number(false));
1681 properties.insert("luma_duration", QString::number(m_doc->getFramePos(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))))));
1682 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1690 for (int i = 0; i < givenList.count(); i++)
1691 list << givenList.at(i);
1693 QList <KUrl::List> foldersList;
1695 foreach(const KUrl & file, list) {
1696 // Check there is no folder here
1697 KMimeType::Ptr type = KMimeType::findByUrl(file);
1698 if (type->is("inode/directory")) {
1699 // user dropped a folder, import its files
1700 list.removeAll(file);
1701 QDir dir(file.path());
1702 QStringList result = dir.entryList(QDir::Files);
1703 KUrl::List folderFiles;
1704 folderFiles << file;
1705 foreach(const QString & path, result) {
1706 KUrl newFile = file;
1707 newFile.addPath(path);
1708 folderFiles.append(newFile);
1710 if (folderFiles.count() > 1) foldersList.append(folderFiles);
1714 if (givenList.isEmpty() && !list.isEmpty()) {
1715 QStringList groupInfo = getGroup();
1716 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1717 } else if (!list.isEmpty()) {
1718 m_doc->slotAddClipList(list, groupName, groupId);
1721 if (!foldersList.isEmpty()) {
1723 for (int i = 0; i < foldersList.count(); i++) {
1724 KUrl::List urls = foldersList.at(i);
1725 KUrl folderUrl = urls.takeFirst();
1726 QString folderName = folderUrl.fileName();
1727 FolderProjectItem *folder = NULL;
1728 if (!folderName.isEmpty()) {
1729 folder = getFolderItemByName(folderName);
1730 if (folder == NULL) {
1731 slotAddFolder(folderName);
1732 folder = getFolderItemByName(folderName);
1736 m_doc->slotAddClipList(urls, folder->groupName(), folder->clipId());
1737 else m_doc->slotAddClipList(urls);
1742 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1744 ProjectItem *item = getItemById(id);
1745 m_thumbnailQueue.removeAll(id);
1747 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1748 const QString path = item->referencedClip()->fileURL().path();
1749 if (item->referencedClip()->isPlaceHolder()) replace = false;
1750 if (!path.isEmpty()) {
1751 if (m_invalidClipDialog) {
1752 m_invalidClipDialog->addClip(id, path);
1757 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1759 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());
1761 m_invalidClipDialog->addClip(id, path);
1762 int result = m_invalidClipDialog->exec();
1763 if (result == KDialog::Yes) replace = true;
1766 if (m_invalidClipDialog) {
1768 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1769 delete m_invalidClipDialog;
1770 m_invalidClipDialog = NULL;
1776 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1778 ProjectItem *item = getItemById(id);
1780 kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1781 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1782 if (durationError) {
1783 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1784 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1786 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
1787 QString path = item->referencedClip()->getProperty("proxy");
1788 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1790 //Security check: make sure the invalid proxy file is in the proxy folder
1791 if (proxyFolder.isParentOf(KUrl(path))) {
1792 QFile::remove(path);
1794 if (item->referencedClip()->getProducer() == NULL) {
1795 // Clip has no valid producer, request it
1796 slotProxyCurrentItem(false, item);
1799 // refresh thumbs producer
1800 item->referencedClip()->reloadThumbProducer();
1803 m_thumbnailQueue.removeAll(id);
1806 void ProjectList::slotAddColorClip()
1808 if (!m_commandStack)
1809 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1811 QDialog *dia = new QDialog(this);
1812 Ui::ColorClip_UI dia_ui;
1813 dia_ui.setupUi(dia);
1814 dia->setWindowTitle(i18n("Color Clip"));
1815 dia_ui.clip_name->setText(i18n("Color Clip"));
1817 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1818 t->setValue(KdenliveSettings::color_duration());
1819 dia_ui.clip_durationBox->addWidget(t);
1820 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1822 if (dia->exec() == QDialog::Accepted) {
1823 QString color = dia_ui.clip_color->color().name();
1824 KdenliveSettings::setColorclipcolor(color);
1825 color = color.replace(0, 1, "0x") + "ff";
1826 QStringList groupInfo = getGroup();
1827 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1834 void ProjectList::slotAddSlideshowClip()
1836 if (!m_commandStack)
1837 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1839 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1841 if (dia->exec() == QDialog::Accepted) {
1842 QStringList groupInfo = getGroup();
1844 QMap <QString, QString> properties;
1845 properties.insert("name", dia->clipName());
1846 properties.insert("resource", dia->selectedPath());
1847 properties.insert("in", "0");
1848 properties.insert("out", QString::number(m_doc->getFramePos(dia->clipDuration()) * dia->imageCount()));
1849 properties.insert("ttl", QString::number(m_doc->getFramePos(dia->clipDuration())));
1850 properties.insert("loop", QString::number(dia->loop()));
1851 properties.insert("crop", QString::number(dia->crop()));
1852 properties.insert("fade", QString::number(dia->fade()));
1853 properties.insert("luma_duration", dia->lumaDuration());
1854 properties.insert("luma_file", dia->lumaFile());
1855 properties.insert("softness", QString::number(dia->softness()));
1856 properties.insert("animation", dia->animation());
1858 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1863 void ProjectList::slotAddTitleClip()
1865 QStringList groupInfo = getGroup();
1866 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1869 void ProjectList::slotAddTitleTemplateClip()
1871 if (!m_commandStack)
1872 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1874 QStringList groupInfo = getGroup();
1876 // Get the list of existing templates
1878 filter << "*.kdenlivetitle";
1879 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1880 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1882 QDialog *dia = new QDialog(this);
1883 Ui::TemplateClip_UI dia_ui;
1884 dia_ui.setupUi(dia);
1885 for (int i = 0; i < templateFiles.size(); ++i)
1886 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1888 if (!templateFiles.isEmpty())
1889 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1890 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1891 //warning: setting base directory doesn't work??
1892 KUrl startDir(path);
1893 dia_ui.template_list->fileDialog()->setUrl(startDir);
1894 dia_ui.text_box->setHidden(true);
1895 if (dia->exec() == QDialog::Accepted) {
1896 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1897 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1898 // Create a cloned template clip
1899 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1904 QStringList ProjectList::getGroup() const
1907 QTreeWidgetItem *item = m_listView->currentItem();
1908 while (item && item->type() != PROJECTFOLDERTYPE)
1909 item = item->parent();
1912 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1913 result << folder->groupName() << folder->clipId();
1915 result << QString() << QString();
1920 void ProjectList::setDocument(KdenliveDoc *doc)
1922 m_listView->blockSignals(true);
1923 m_abortAllJobs = true;
1924 for (int i = 0; i < m_jobList.count(); i++) {
1925 m_jobList.at(i)->setStatus(JOBABORTED);
1928 m_jobThreads.waitForFinished();
1929 m_jobThreads.clearFutures();
1930 m_thumbnailQueue.clear();
1931 m_listView->clear();
1933 m_listView->setSortingEnabled(false);
1934 emit clipSelected(NULL);
1935 m_refreshed = false;
1936 m_allClipsProcessed = false;
1938 m_timecode = doc->timecode();
1939 m_commandStack = doc->commandStack();
1941 m_abortAllJobs = false;
1944 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1945 QStringList openedFolders = doc->getExpandedFolders();
1946 QMapIterator<QString, QString> f(flist);
1947 while (f.hasNext()) {
1949 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1950 folder->setExpanded(openedFolders.contains(f.key()));
1953 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1954 if (list.isEmpty()) {
1957 m_allClipsProcessed = true;
1959 for (int i = 0; i < list.count(); i++)
1960 slotAddClip(list.at(i), false);
1962 m_listView->blockSignals(false);
1963 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1964 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1965 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1966 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1967 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
1970 QList <DocClipBase*> ProjectList::documentClipList() const
1973 return QList <DocClipBase*> ();
1975 return m_doc->clipManager()->documentClipList();
1978 QDomElement ProjectList::producersList()
1981 QDomElement prods = doc.createElement("producerlist");
1982 doc.appendChild(prods);
1983 QTreeWidgetItemIterator it(m_listView);
1985 if ((*it)->type() != PROJECTCLIPTYPE) {
1990 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1996 void ProjectList::slotCheckForEmptyQueue()
1998 if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
1999 if (!m_refreshed && m_allClipsProcessed) {
2001 m_listView->setEnabled(true);
2003 QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
2004 emit displayMessage(QString(), -1);
2007 } else if (!m_refreshed) {
2008 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
2013 void ProjectList::requestClipThumbnail(const QString id)
2015 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
2016 slotProcessNextThumbnail();
2019 void ProjectList::resetThumbsProducer(DocClipBase *clip)
2022 clip->clearThumbProducer();
2023 QString id = clip->getId();
2024 m_thumbnailQueue.removeAll(id);
2027 void ProjectList::slotProcessNextThumbnail()
2029 if (m_render->processingItems() > 0) {
2032 if (m_thumbnailQueue.isEmpty()) {
2033 slotCheckForEmptyQueue();
2036 int max = m_doc->clipManager()->clipsCount();
2037 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
2038 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
2041 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
2043 QTreeWidgetItem *item = getAnyItemById(clipId);
2045 slotRefreshClipThumbnail(item, update);
2047 slotProcessNextThumbnail();
2051 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
2053 if (it == NULL) return;
2054 ProjectItem *item = NULL;
2055 bool isSubItem = false;
2057 if (it->type() == PROJECTFOLDERTYPE) return;
2058 if (it->type() == PROJECTSUBCLIPTYPE) {
2059 item = static_cast <ProjectItem *>(it->parent());
2060 frame = static_cast <SubProjectItem *>(it)->zone().x();
2063 item = static_cast <ProjectItem *>(it);
2064 frame = item->referencedClip()->getClipThumbFrame();
2068 DocClipBase *clip = item->referencedClip();
2070 slotProcessNextThumbnail();
2075 int height = m_listView->iconSize().height();
2076 int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
2077 int dwidth = (int)(height * m_render->dar() + 0.5);
2078 if (clip->clipType() == AUDIO)
2079 pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
2080 else if (clip->clipType() == IMAGE)
2081 img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
2083 img = item->referencedClip()->extractImage(frame, dwidth, height);
2086 if (!pix.isNull() || !img.isNull()) {
2087 monitorItemEditing(false);
2088 if (!img.isNull()) {
2089 pix = QPixmap::fromImage(img);
2090 processThumbOverlays(item, pix);
2092 it->setData(0, Qt::DecorationRole, pix);
2093 monitorItemEditing(true);
2095 QString hash = item->getClipHash();
2096 if (!hash.isEmpty() && !img.isNull()) {
2098 m_doc->cacheImage(hash, img);
2100 m_doc->cacheImage(hash + '#' + QString::number(frame), img);
2104 emit projectModified();
2105 slotProcessNextThumbnail();
2110 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
2113 ProjectItem *item = getItemById(clipId);
2114 int queue = m_render->processingItems();
2115 if (item && producer) {
2116 monitorItemEditing(false);
2117 DocClipBase *clip = item->referencedClip();
2118 if (producer->is_valid()) {
2119 if (clip->isPlaceHolder()) {
2123 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
2125 item->setProperties(properties, metadata);
2126 clip->setProducer(producer, replace);
2129 QString size = properties.value("frame_size");
2130 if (!useProxy() && clip->getProperty("proxy").isEmpty()) {
2131 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2132 discardJobs(clipId, PROXYJOB);
2134 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") {
2135 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2136 discardJobs(clipId, PROXYJOB);
2138 else if (useProxy() && !item->hasProxy() && !hasPendingJob(item, PROXYJOB)) {
2139 // proxy video and image clips
2141 CLIPTYPE t = item->clipType();
2142 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2143 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
2144 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)) {
2145 if (clip->getProperty("proxy").isEmpty()) {
2146 KUrl proxyPath = m_doc->projectFolder();
2147 proxyPath.addPath("proxy/");
2148 proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
2149 QMap <QString, QString> newProps;
2150 // insert required duration for proxy
2151 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
2152 newProps.insert("proxy", proxyPath.path());
2153 QMap <QString, QString> oldProps = clip->properties();
2154 oldProps.insert("proxy", QString());
2155 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
2156 m_doc->commandStack()->push(command);
2161 if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) {
2162 getCachedThumbnail(item);
2164 if (!toReload.isEmpty())
2165 item->slotSetToolTip();
2166 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
2168 monitorItemEditing(true);
2169 if (item && m_thumbnailQueue.isEmpty()) {
2170 if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
2171 m_listView->setCurrentItem(item);
2172 bool updatedProfile = false;
2173 if (item->parent()) {
2174 if (item->parent()->type() == PROJECTFOLDERTYPE)
2175 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
2176 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
2177 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
2178 updatedProfile = adjustProjectProfileToItem(item);
2180 if (updatedProfile == false) {
2181 //emit clipSelected(item->referencedClip());
2184 int max = m_doc->clipManager()->clipsCount();
2185 if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
2187 if (m_allClipsProcessed) emit processNextThumbnail();
2190 // no item for producer, delete it
2194 if (replace) toReload = clipId;
2195 if (!toReload.isEmpty())
2196 emit clipNeedsReload(toReload);
2199 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
2202 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
2203 item = static_cast <ProjectItem*>(m_listView->currentItem());
2205 if (item == NULL || item->referencedClip() == NULL) {
2206 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
2209 bool profileUpdated = false;
2210 QString size = item->referencedClip()->getProperty("frame_size");
2211 int width = size.section('x', 0, 0).toInt();
2212 int height = size.section('x', -1).toInt();
2213 // Fix some avchd clips tht report a wrong size (1920x1088)
2214 if (height == 1088) height = 1080;
2215 double fps = item->referencedClip()->getProperty("fps").toDouble();
2216 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
2217 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
2218 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
2219 // get a list of compatible profiles
2220 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
2221 if (!suggestedProfiles.isEmpty()) {
2222 KDialog *dialog = new KDialog(this);
2223 dialog->setCaption(i18n("Change project profile"));
2224 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2227 QVBoxLayout *l = new QVBoxLayout;
2228 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));
2229 l->addWidget(label);
2230 QListWidget *list = new QListWidget;
2231 list->setAlternatingRowColors(true);
2232 QMapIterator<QString, QString> i(suggestedProfiles);
2233 while (i.hasNext()) {
2235 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
2236 item->setData(Qt::UserRole, i.key());
2237 item->setToolTip(i.key());
2239 list->setCurrentRow(0);
2241 container.setLayout(l);
2242 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
2243 dialog->setMainWidget(&container);
2244 if (dialog->exec() == QDialog::Accepted) {
2245 //Change project profile
2246 profileUpdated = true;
2247 if (list->currentItem())
2248 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
2252 } else if (fps > 0) {
2253 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));
2257 return profileUpdated;
2260 QString ProjectList::getDocumentProperty(const QString &key) const
2262 return m_doc->getDocumentProperty(key);
2265 bool ProjectList::useProxy() const
2267 return m_doc->getDocumentProperty("enableproxy").toInt();
2270 bool ProjectList::generateProxy() const
2272 return m_doc->getDocumentProperty("generateproxy").toInt();
2275 bool ProjectList::generateImageProxy() const
2277 return m_doc->getDocumentProperty("generateimageproxy").toInt();
2280 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2282 ProjectItem *item = getItemById(clipId);
2283 if (item && !img.isNull()) {
2284 QPixmap pix = QPixmap::fromImage(img);
2285 processThumbOverlays(item, pix);
2286 monitorItemEditing(false);
2287 item->setData(0, Qt::DecorationRole, pix);
2288 monitorItemEditing(true);
2289 QString hash = item->getClipHash();
2290 if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2294 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2296 // For clips that have a generic icon (like audio clips...)
2297 ProjectItem *item = getItemById(clipId);
2298 QPixmap pix = KIcon(name).pixmap(QSize(width, height));
2299 if (item && !pix.isNull()) {
2300 monitorItemEditing(false);
2301 item->setData(0, Qt::DecorationRole, pix);
2302 monitorItemEditing(true);
2306 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2308 QTreeWidgetItemIterator it(m_listView);
2309 QString lookId = id;
2310 if (id.contains('#'))
2311 lookId = id.section('#', 0, 0);
2313 ProjectItem *result = NULL;
2315 if ((*it)->type() != PROJECTCLIPTYPE) {
2320 ProjectItem *item = static_cast<ProjectItem *>(*it);
2321 if (item->clipId() == lookId) {
2327 if (result == NULL || !id.contains('#')) {
2330 for (int i = 0; i < result->childCount(); i++) {
2331 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2332 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2341 ProjectItem *ProjectList::getItemById(const QString &id)
2344 QTreeWidgetItemIterator it(m_listView);
2346 if ((*it)->type() != PROJECTCLIPTYPE) {
2347 // subitem or folder
2351 item = static_cast<ProjectItem *>(*it);
2352 if (item->clipId() == id)
2359 FolderProjectItem *ProjectList::getFolderItemByName(const QString &name)
2361 FolderProjectItem *item = NULL;
2362 QList <QTreeWidgetItem *> hits = m_listView->findItems(name, Qt::MatchExactly, 0);
2363 for (int i = 0; i < hits.count(); i++) {
2364 if (hits.at(i)->type() == PROJECTFOLDERTYPE) {
2365 item = static_cast<FolderProjectItem *>(hits.at(i));
2372 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2374 FolderProjectItem *item;
2375 QTreeWidgetItemIterator it(m_listView);
2377 if ((*it)->type() == PROJECTFOLDERTYPE) {
2378 item = static_cast<FolderProjectItem *>(*it);
2379 if (item->clipId() == id)
2387 void ProjectList::slotSelectClip(const QString &ix)
2389 ProjectItem *clip = getItemById(ix);
2391 m_listView->setCurrentItem(clip);
2392 m_listView->scrollToItem(clip);
2393 m_editButton->defaultAction()->setEnabled(true);
2394 m_deleteButton->defaultAction()->setEnabled(true);
2395 m_reloadAction->setEnabled(true);
2396 m_extractAudioAction->setEnabled(true);
2397 m_transcodeAction->setEnabled(true);
2398 m_stabilizeAction->setEnabled(true);
2399 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2400 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2401 m_openAction->setEnabled(true);
2402 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2403 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2404 m_openAction->setEnabled(true);
2406 m_openAction->setEnabled(false);
2411 QString ProjectList::currentClipUrl() const
2414 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2415 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2417 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2419 item = static_cast <ProjectItem*>(m_listView->currentItem());
2423 return item->clipUrl().path();
2426 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2430 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2431 for (int i = 0; i < list.count(); i++) {
2432 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2434 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2436 item = static_cast <ProjectItem*>(list.at(i)->parent());
2438 item = static_cast <ProjectItem*>(list.at(i));
2440 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2442 DocClipBase *clip = item->referencedClip();
2443 if (!condition.isEmpty()) {
2444 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2446 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2449 result.append(item->clipUrl());
2454 QStringList ProjectList::getConditionalIds(const QString &condition) const
2458 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2459 for (int i = 0; i < list.count(); i++) {
2460 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2462 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2464 item = static_cast <ProjectItem*>(list.at(i)->parent());
2466 item = static_cast <ProjectItem*>(list.at(i));
2468 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2470 DocClipBase *clip = item->referencedClip();
2471 if (!condition.isEmpty()) {
2472 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2474 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2477 result.append(item->clipId());
2482 void ProjectList::regenerateTemplate(const QString &id)
2484 ProjectItem *clip = getItemById(id);
2486 regenerateTemplate(clip);
2489 void ProjectList::regenerateTemplate(ProjectItem *clip)
2491 //TODO: remove this unused method, only force_reload is necessary
2492 clip->referencedClip()->getProducer()->set("force_reload", 1);
2495 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2499 if (!file.open(QIODevice::ReadOnly)) {
2500 kWarning() << "ERROR, CANNOT READ: " << path;
2503 if (!doc.setContent(&file)) {
2504 kWarning() << "ERROR, CANNOT READ: " << path;
2509 QDomNodeList texts = doc.elementsByTagName("content");
2510 for (int i = 0; i < texts.count(); i++) {
2511 QString data = texts.item(i).firstChild().nodeValue();
2512 data.replace("%s", replaceString);
2513 texts.item(i).firstChild().setNodeValue(data);
2519 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2521 ProjectItem *clip = getItemById(id);
2522 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2524 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2525 m_commandStack->push(command);
2528 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2530 ProjectItem *clip = getItemById(id);
2532 DocClipBase *base = clip->referencedClip();
2533 base->addCutZone(in, out);
2534 monitorItemEditing(false);
2535 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2536 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2537 if (!clip->isExpanded())
2538 clip->setExpanded(true);
2539 m_listView->scrollToItem(sub);
2540 m_listView->editItem(sub, 1);
2542 QImage img = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
2543 sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2544 QString hash = clip->getClipHash();
2545 if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(in), img);
2546 monitorItemEditing(true);
2548 emit projectModified();
2551 void ProjectList::removeClipCut(const QString &id, int in, int out)
2553 ProjectItem *clip = getItemById(id);
2555 DocClipBase *base = clip->referencedClip();
2556 base->removeCutZone(in, out);
2557 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2559 monitorItemEditing(false);
2561 monitorItemEditing(true);
2564 emit projectModified();
2567 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2569 SubProjectItem *sub = NULL;
2571 for (int i = 0; i < clip->childCount(); i++) {
2572 QTreeWidgetItem *it = clip->child(i);
2573 if (it->type() == PROJECTSUBCLIPTYPE) {
2574 sub = static_cast <SubProjectItem*>(it);
2575 if (sub->zone() == zone)
2585 void ProjectList::slotUpdateClipCut(QPoint p)
2587 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2589 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2590 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2591 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2592 m_commandStack->push(command);
2595 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2597 ProjectItem *clip = getItemById(id);
2598 SubProjectItem *sub = getSubItem(clip, oldzone);
2599 if (sub == NULL || clip == NULL)
2601 DocClipBase *base = clip->referencedClip();
2602 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2603 monitorItemEditing(false);
2605 sub->setDescription(comment);
2606 monitorItemEditing(true);
2607 emit projectModified();
2610 void ProjectList::slotForceProcessing(const QString &id)
2612 m_render->forceProcessing(id);
2615 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2617 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2619 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2620 int count = list.count();
2622 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2623 if (!existing.isEmpty()) {
2624 // Sequence already exists, update
2625 QString id = existing.at(0)->getId();
2626 //ProjectItem *item = getItemById(id);
2627 QMap <QString, QString> oldprops;
2628 QMap <QString, QString> newprops;
2629 int ttl = existing.at(0)->getProperty("ttl").toInt();
2630 oldprops["out"] = existing.at(0)->getProperty("out");
2631 newprops["out"] = QString::number(ttl * count - 1);
2632 slotUpdateClipProperties(id, newprops);
2633 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2634 m_commandStack->push(command);
2637 QStringList groupInfo = getGroup();
2638 QMap <QString, QString> properties;
2639 properties.insert("name", fileName);
2640 properties.insert("resource", pattern);
2641 properties.insert("in", "0");
2642 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
2643 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
2644 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
2645 properties.insert("loop", QString::number(false));
2646 properties.insert("crop", QString::number(false));
2647 properties.insert("fade", QString::number(false));
2648 properties.insert("luma_duration", m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
2650 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
2652 } else emit displayMessage(i18n("Sequence not found"), -2);
2655 QMap <QString, QString> ProjectList::getProxies()
2657 QMap <QString, QString> list;
2659 QTreeWidgetItemIterator it(m_listView);
2661 if ((*it)->type() != PROJECTCLIPTYPE) {
2665 item = static_cast<ProjectItem *>(*it);
2666 if (item && item->referencedClip() != NULL) {
2667 if (item->hasProxy()) {
2668 QString proxy = item->referencedClip()->getProperty("proxy");
2669 list.insert(proxy, item->clipUrl().path());
2677 void ProjectList::slotCreateProxy(const QString id)
2679 ProjectItem *item = getItemById(id);
2680 if (!item || hasPendingJob(item, PROXYJOB) || item->referencedClip()->isPlaceHolder()) return;
2681 QString path = item->referencedClip()->getProperty("proxy");
2682 if (path.isEmpty()) {
2683 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy, empty path."));
2687 if (QFileInfo(path).size() > 0) {
2688 // Proxy already created
2689 setJobStatus(item, PROXYJOB, JOBDONE);
2694 ProxyJob *job = new ProxyJob(item->clipType(), id, QStringList() << path << item->clipUrl().path() << item->referencedClip()->producerProperty("_exif_orientation") << m_doc->getDocumentProperty("proxyparams").simplified() << QString::number(m_render->frameRenderWidth()) << QString::number(m_render->renderHeight()));
2695 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2700 m_jobList.append(job);
2701 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2702 slotCheckJobProcess();
2705 void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
2707 ProjectItem *item = getItemById(id);
2708 if (!item|| item->referencedClip()->isPlaceHolder()) return;
2709 QString source = item->clipUrl().path();
2710 QString ext = source.section('.', -1);
2711 QString dest = source.section('.', 0, -2) + "_" + QString::number(zone.x()) + "." + ext;
2713 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2714 if (clipFps == 0) clipFps = m_fps;
2715 // if clip and project have different frame rate, adjust in and out
2718 in = GenTime(in, m_timecode.fps()).frames(clipFps);
2719 out = GenTime(out, m_timecode.fps()).frames(clipFps);
2720 int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
2721 int duration = out - in + 1;
2722 QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
2723 QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
2725 QDialog *d = new QDialog(this);
2726 Ui::CutJobDialog_UI ui;
2728 ui.extra_params->setVisible(false);
2729 ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
2730 ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
2731 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2732 ui.file_url->setUrl(KUrl(dest));
2733 ui.button_more->setIcon(KIcon("configure"));
2734 ui.extra_params->setPlainText("-acodec copy -vcodec copy");
2735 QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
2736 ui.info_label->setText(mess);
2737 if (d->exec() != QDialog::Accepted) {
2741 dest = ui.file_url->url().path();
2742 bool acceptPath = dest != source;
2743 if (acceptPath && QFileInfo(dest).size() > 0) {
2744 // destination file olready exists, overwrite?
2747 while (!acceptPath) {
2748 // Do not allow to save over original clip
2749 if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
2750 else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
2751 if (d->exec() != QDialog::Accepted) {
2755 dest = ui.file_url->url().path();
2756 acceptPath = dest != source;
2757 if (acceptPath && QFileInfo(dest).size() > 0) {
2761 QString extraParams = ui.extra_params->toPlainText().simplified();
2762 KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
2765 QStringList jobParams;
2766 jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_clip_cut());
2767 if (!extraParams.isEmpty()) jobParams << extraParams;
2768 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2769 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2773 m_jobList.append(job);
2774 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2776 slotCheckJobProcess();
2779 void ProjectList::slotTranscodeClipJob(const QString &condition, QString params, QString desc)
2781 QStringList existingFiles;
2782 QStringList ids = getConditionalIds(condition);
2783 QStringList destinations;
2784 foreach(const QString &id, ids) {
2785 ProjectItem *item = getItemById(id);
2786 if (!item) continue;
2787 QString newFile = params.section(' ', -1).replace("%1", item->clipUrl().path());
2788 destinations << newFile;
2789 if (QFile::exists(newFile)) existingFiles << newFile;
2791 if (!existingFiles.isEmpty()) {
2792 if (KMessageBox::warningContinueCancelList(this, i18n("The transcoding job will overwrite the following files:"), existingFiles) == KMessageBox::Cancel) return;
2795 QDialog *d = new QDialog(this);
2796 Ui::CutJobDialog_UI ui;
2798 d->setWindowTitle(i18n("Transcoding"));
2799 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2800 if (ids.count() == 1) {
2801 ui.file_url->setUrl(KUrl(destinations.first()));
2804 ui.destination_label->setVisible(false);
2805 ui.file_url->setVisible(false);
2807 ui.extra_params->setVisible(false);
2809 ui.button_more->setIcon(KIcon("configure"));
2810 ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
2811 ui.extra_params->setPlainText(params.simplified().section(" ", 0, -2));
2812 QString mess = desc;
2813 mess.append(" " + i18np("(%1 clip)", "(%1 clips)", ids.count()));
2814 ui.info_label->setText(mess);
2815 if (d->exec() != QDialog::Accepted) {
2819 params = ui.extra_params->toPlainText().simplified();
2820 KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
2822 foreach(const QString &id, ids) {
2823 ProjectItem *item = getItemById(id);
2824 if (!item || !item->referencedClip()) continue;
2825 QString src = item->clipUrl().path();
2827 if (ids.count() > 1) dest = params.section(' ', -1).replace("%1", src);
2828 else dest = ui.file_url->url().path();
2829 QStringList jobParams;
2830 jobParams << dest << src << QString() << QString();
2831 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2832 if (clipFps == 0) clipFps = m_fps;
2833 int max = item->clipMaxDuration();
2834 QString duration = QString::number(max);
2835 jobParams << duration;
2836 jobParams << QString::number(KdenliveSettings::add_clip_cut());
2837 jobParams << params;
2838 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2839 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2843 m_jobList.append(job);
2844 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2847 slotCheckJobProcess();
2851 void ProjectList::slotCheckJobProcess()
2853 if (!m_jobThreads.futures().isEmpty()) {
2854 // Remove inactive threads
2855 QList <QFuture<void> > futures = m_jobThreads.futures();
2856 m_jobThreads.clearFutures();
2857 for (int i = 0; i < futures.count(); i++)
2858 if (!futures.at(i).isFinished()) {
2859 m_jobThreads.addFuture(futures.at(i));
2862 if (m_jobList.isEmpty()) return;
2865 for (int i = 0; i < m_jobList.count(); i++) {
2866 if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING)
2869 // remove finished jobs
2870 AbstractClipJob *job = m_jobList.takeAt(i);
2876 emit jobCount(count);
2877 m_jobMutex.unlock();
2879 if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
2882 void ProjectList::slotAbortProxy(const QString id, const QString path)
2886 ProjectItem *item = getItemById(id);
2888 if (!item->isProxyRunning()) slotGotProxy(item);
2889 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2890 discardJobs(id, PROXYJOB);
2893 void ProjectList::slotProcessJobs()
2895 while (!m_jobList.isEmpty() && !m_abortAllJobs) {
2896 emit projectModified();
2897 AbstractClipJob *job = NULL;
2900 for (int i = 0; i < m_jobList.count(); i++) {
2901 if (m_jobList.at(i)->jobStatus == JOBWAITING) {
2903 m_jobList.at(i)->jobStatus = JOBWORKING;
2904 job = m_jobList.at(i);
2908 else if (m_jobList.at(i)->jobStatus == JOBWORKING)
2912 emit jobCount(count);
2913 m_jobMutex.unlock();
2918 QString destination = job->destination();
2919 // Check if the clip is still here
2920 DocClipBase *currentClip = m_doc->clipManager()->getClipById(job->clipId());
2921 //ProjectItem *processingItem = getItemById(job->clipId());
2922 if (currentClip == NULL) {
2923 job->setStatus(JOBDONE);
2926 // Set clip status to started
2927 emit processLog(job->clipId(), 0, job->jobType, job->statusMessage());
2929 // Make sure destination path is writable
2930 if (!destination.isEmpty()) {
2931 QFile file(destination);
2932 if (!file.open(QIODevice::WriteOnly)) {
2933 emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Cannot write to path: %1", destination));
2934 job->setStatus(JOBCRASHED);
2938 QFile::remove(destination);
2940 connect(job, SIGNAL(jobProgress(QString, int, int)), this, SIGNAL(processLog(QString, int, int)));
2941 connect(job, SIGNAL(cancelRunningJob(const QString, stringMap)), this, SIGNAL(cancelRunningJob(const QString, stringMap)));
2942 connect(job, SIGNAL(gotFilterJobResults(QString,int, int, QString,stringMap)), this, SIGNAL(gotFilterJobResults(QString,int, int, QString,stringMap)));
2944 if (job->jobType == MLTJOB) {
2945 MeltJob *jb = static_cast<MeltJob *> (job);
2946 jb->setProducer(currentClip->getProducer());
2949 if (job->jobStatus == JOBDONE) {
2950 emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
2951 //TODO: replace with more generic clip replacement framework
2952 if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
2953 if (job->addClipToProject()) {
2954 emit addClip(destination, QString(), QString());
2956 } else if (job->jobStatus == JOBCRASHED || job->jobStatus == JOBABORTED) {
2957 emit updateJobStatus(job->clipId(), job->jobType, job->jobStatus, job->errorMessage(), QString(), job->logDetails());
2960 // Thread finished, cleanup & update count
2961 QTimer::singleShot(200, this, SIGNAL(checkJobProcess()));
2965 void ProjectList::updateProxyConfig()
2968 QTreeWidgetItemIterator it(m_listView);
2969 QUndoCommand *command = new QUndoCommand();
2970 command->setText(i18n("Update proxy settings"));
2971 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2973 if ((*it)->type() != PROJECTCLIPTYPE) {
2977 item = static_cast<ProjectItem *>(*it);
2982 CLIPTYPE t = item->clipType();
2983 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2984 if (generateProxy() && useProxy() && !hasPendingJob(item, PROXYJOB)) {
2985 DocClipBase *clip = item->referencedClip();
2986 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
2987 if (clip->getProperty("proxy").isEmpty()) {
2988 // We need to insert empty proxy in old properties so that undo will work
2989 QMap <QString, QString> oldProps;// = clip->properties();
2990 oldProps.insert("proxy", QString());
2991 QMap <QString, QString> newProps;
2992 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
2993 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2997 else if (item->hasProxy()) {
2999 QMap <QString, QString> newProps;
3000 newProps.insert("proxy", QString());
3001 // insert required duration for proxy
3002 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
3003 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
3006 else if (t == IMAGE && item->referencedClip() != NULL) {
3007 if (generateImageProxy() && useProxy()) {
3008 DocClipBase *clip = item->referencedClip();
3009 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
3010 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
3011 if (clip->getProperty("proxy").isEmpty()) {
3012 // We need to insert empty proxy in old properties so that undo will work
3013 QMap <QString, QString> oldProps = clip->properties();
3014 oldProps.insert("proxy", QString());
3015 QMap <QString, QString> newProps;
3016 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
3017 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3021 else if (item->hasProxy()) {
3023 QMap <QString, QString> newProps;
3024 newProps.insert("proxy", QString());
3025 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
3030 if (command->childCount() > 0) m_doc->commandStack()->push(command);
3031 else delete command;
3034 void ProjectList::slotProcessLog(const QString id, int progress, int type, const QString message)
3036 ProjectItem *item = getItemById(id);
3037 setJobStatus(item, (JOBTYPE) type, JOBWORKING, progress, message);
3040 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
3042 QList<QTreeWidgetItem *> list;
3043 if (itemToProxy == NULL) list = m_listView->selectedItems();
3044 else list << itemToProxy;
3046 // expand list (folders, subclips) to get real clips
3047 QTreeWidgetItem *listItem;
3048 QList<ProjectItem *> clipList;
3049 for (int i = 0; i < list.count(); i++) {
3050 listItem = list.at(i);
3051 if (listItem->type() == PROJECTFOLDERTYPE) {
3052 for (int j = 0; j < listItem->childCount(); j++) {
3053 QTreeWidgetItem *sub = listItem->child(j);
3054 if (sub->type() == PROJECTCLIPTYPE) {
3055 ProjectItem *item = static_cast <ProjectItem*>(sub);
3056 if (!clipList.contains(item)) clipList.append(item);
3060 else if (listItem->type() == PROJECTSUBCLIPTYPE) {
3061 QTreeWidgetItem *sub = listItem->parent();
3062 ProjectItem *item = static_cast <ProjectItem*>(sub);
3063 if (!clipList.contains(item)) clipList.append(item);
3065 else if (listItem->type() == PROJECTCLIPTYPE) {
3066 ProjectItem *item = static_cast <ProjectItem*>(listItem);
3067 if (!clipList.contains(item)) clipList.append(item);
3071 QUndoCommand *command = new QUndoCommand();
3072 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
3073 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
3075 // Make sure the proxy folder exists
3076 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3077 KStandardDirs::makeDir(proxydir);
3079 QMap <QString, QString> newProps;
3080 QMap <QString, QString> oldProps;
3081 if (!doProxy) newProps.insert("proxy", "-");
3082 for (int i = 0; i < clipList.count(); i++) {
3083 ProjectItem *item = clipList.at(i);
3084 CLIPTYPE t = item->clipType();
3085 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
3086 if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
3087 DocClipBase *clip = item->referencedClip();
3088 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
3089 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
3093 //oldProps = clip->properties();
3096 QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
3097 // insert required duration for proxy
3098 newProps.insert("proxy_out", clip->producerProperty("out"));
3099 newProps.insert("proxy", path);
3100 // We need to insert empty proxy so that undo will work
3101 //oldProps.insert("proxy", QString());
3103 else if (item->referencedClip()->getProducer() == NULL) {
3104 // Force clip reload
3105 kDebug()<<"// CLIP HAD NULL PROD------------";
3106 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
3108 // We need to insert empty proxy so that undo will work
3109 oldProps = clip->currentProperties(newProps);
3110 if (doProxy) oldProps.insert("proxy", "-");
3111 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
3114 if (command->childCount() > 0) {
3115 m_doc->commandStack()->push(command);
3117 else delete command;
3121 void ProjectList::slotDeleteProxy(const QString proxyPath)
3123 if (proxyPath.isEmpty()) return;
3124 QUndoCommand *proxyCommand = new QUndoCommand();
3125 proxyCommand->setText(i18n("Remove Proxy"));
3126 QTreeWidgetItemIterator it(m_listView);
3129 if ((*it)->type() == PROJECTCLIPTYPE) {
3130 item = static_cast <ProjectItem *>(*it);
3131 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
3132 QMap <QString, QString> props;
3133 props.insert("proxy", QString());
3134 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
3140 if (proxyCommand->childCount() == 0)
3141 delete proxyCommand;
3143 m_commandStack->push(proxyCommand);
3144 QFile::remove(proxyPath);
3147 void ProjectList::setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress, const QString &statusMessage)
3149 if (item == NULL || (m_abortAllJobs && m_closing)) return;
3150 monitorItemEditing(false);
3151 item->setJobStatus(jobType, status, progress, statusMessage);
3152 if (status == JOBCRASHED) {
3153 DocClipBase *clip = item->referencedClip();
3155 kDebug()<<"// PROXY CRASHED";
3157 else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
3158 // disable proxy and fetch real clip
3159 clip->setProperty("proxy", "-");
3160 QDomElement xml = clip->toXML();
3161 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
3164 // Disable proxy for this clip
3165 clip->setProperty("proxy", "-");
3168 monitorItemEditing(true);
3171 void ProjectList::monitorItemEditing(bool enable)
3173 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3174 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3177 QStringList ProjectList::expandedFolders() const
3180 FolderProjectItem *item;
3181 QTreeWidgetItemIterator it(m_listView);
3183 if ((*it)->type() != PROJECTFOLDERTYPE) {
3187 if ((*it)->isExpanded()) {
3188 item = static_cast<FolderProjectItem *>(*it);
3189 result.append(item->clipId());
3196 void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
3198 if (item->hasProxy()) {
3200 QColor c(220, 220, 10, 200);
3201 QRect r(0, 0, 12, 12);
3203 QFont font = p.font();
3206 p.setPen(Qt::black);
3207 p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
3211 void ProjectList::slotCancelJobs()
3213 m_abortAllJobs = true;
3214 for (int i = 0; i < m_jobList.count(); i++) {
3215 m_jobList.at(i)->setStatus(JOBABORTED);
3217 m_jobThreads.waitForFinished();
3218 m_jobThreads.clearFutures();
3219 QUndoCommand *command = new QUndoCommand();
3220 command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
3222 for (int i = 0; i < m_jobList.count(); i++) {
3223 DocClipBase *currentClip = m_doc->clipManager()->getClipById(m_jobList.at(i)->clipId());
3224 if (!currentClip) continue;
3225 QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
3226 if (newProps.isEmpty()) continue;
3227 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3228 new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command);
3230 m_jobMutex.unlock();
3231 if (command->childCount() > 0) {
3232 m_doc->commandStack()->push(command);
3234 else delete command;
3235 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
3237 m_abortAllJobs = false;
3238 m_infoLabel->slotSetJobCount(0);
3241 void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
3243 if (newProps.isEmpty() || m_closing) return;
3244 DocClipBase *currentClip = m_doc->clipManager()->getClipById(id);
3245 if (!currentClip) return;
3246 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3247 if (newProps == oldProps) return;
3248 QMapIterator<QString, QString> i(oldProps);
3249 EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
3250 m_commandStack->push(command);
3253 bool ProjectList::hasPendingJob(ProjectItem *item, JOBTYPE type)
3255 if (!item || !item->referencedClip() || m_abortAllJobs) return false;
3256 AbstractClipJob *job;
3257 QMutexLocker lock(&m_jobMutex);
3258 for (int i = 0; i < m_jobList.count(); i++) {
3259 if (m_abortAllJobs) break;
3260 job = m_jobList.at(i);
3261 if (job->clipId() == item->clipId() && job->jobType == type && (job->jobStatus == JOBWAITING || job->jobStatus == JOBWORKING)) return true;
3267 void ProjectList::deleteJobsForClip(const QString &clipId)
3269 QMutexLocker lock(&m_jobMutex);
3270 for (int i = 0; i < m_jobList.count(); i++) {
3271 if (m_jobList.at(i)->clipId() == clipId) {
3272 m_jobList.at(i)->setStatus(JOBABORTED);
3277 void ProjectList::slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details)
3279 ProjectItem *item = getItemById(id);
3281 slotUpdateJobStatus(item, type, status, label, actionName, details);
3285 void ProjectList::slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName, const QString details)
3287 item->setJobStatus((JOBTYPE) type, (CLIPJOBSTATUS) status);
3288 if (status != JOBCRASHED) return;
3289 #if KDE_IS_VERSION(4,7,0)
3290 m_infoMessage->animatedHide();
3292 m_infoMessage->setText(label);
3293 m_infoMessage->setWordWrap(label.length() > 35);
3294 m_infoMessage->setMessageType(KMessageWidget::Warning);
3295 QList<QAction *> actions = m_infoMessage->actions();
3296 for (int i = 0; i < actions.count(); i++) {
3297 m_infoMessage->removeAction(actions.at(i));
3300 if (!actionName.isEmpty()) {
3301 QAction *action = NULL;
3302 QList< KActionCollection * > collections = KActionCollection::allCollections();
3303 for (int i = 0; i < collections.count(); i++) {
3304 KActionCollection *coll = collections.at(i);
3305 action = coll->action(actionName);
3308 if (action) m_infoMessage->addAction(action);
3310 if (!details.isEmpty()) {
3311 m_errorLog = details;
3312 m_infoMessage->addAction(m_logAction);
3314 m_infoMessage->animatedShow();
3318 void ProjectList::slotShowJobLog()
3320 #if KDE_IS_VERSION(4,7,0)
3322 d.setButtons(KDialog::Close);
3324 t.setPlainText(m_errorLog);
3325 t.setReadOnly(true);
3326 d.setMainWidget(&t);
3331 QStringList ProjectList::getPendingJobs(const QString &id)
3334 QMutexLocker lock(&m_jobMutex);
3335 for (int i = 0; i < m_jobList.count(); i++) {
3336 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobStatus == JOBWAITING || m_jobList.at(i)->jobStatus == JOBWORKING)) {
3338 result << m_jobList.at(i)->description;
3344 void ProjectList::discardJobs(const QString &id, JOBTYPE type) {
3345 QMutexLocker lock(&m_jobMutex);
3346 for (int i = 0; i < m_jobList.count(); i++) {
3347 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobType == type || type == NOJOBTYPE)) {
3349 m_jobList.at(i)->setStatus(JOBABORTED);
3354 void ProjectList::slotStartFilterJob(ItemInfo info, const QString&id, const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
3356 ProjectItem *item = getItemById(id);
3358 QStringList jobParams;
3359 jobParams << QString::number(info.cropStart.frames(m_fps)) << QString::number((info.cropStart + info.cropDuration).frames(m_fps));
3360 jobParams << QString() << filterName << filterParams << consumer << consumerParams << properties << QString::number(info.startPos.frames(m_fps)) << QString::number(info.track) << finalFilterName;
3361 MeltJob *job = new MeltJob(item->clipType(), id, jobParams);
3362 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3366 job->description = i18n("Filter %1", finalFilterName);
3367 m_jobList.append(job);
3368 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3369 slotCheckJobProcess();
3372 void ProjectList::startClipFilterJob(const QString &filterName, const QString &condition)
3374 QStringList ids = getConditionalIds(condition);
3375 QString destination;
3376 ProjectItem *item = getItemById(ids.at(0));
3378 emit displayMessage(i18n("Cannot find clip to process filter %1", filterName), -2);
3381 if (ids.count() == 1) {
3382 destination = item->clipUrl().path();
3385 destination = item->clipUrl().directory();
3387 ClipStabilize *d = new ClipStabilize(destination, ids.count(), filterName);
3388 if (d->exec() == QDialog::Accepted) {
3389 processClipJob(ids, d->destination(), d->autoAddClip(), d->params(), d->desc());
3394 void ProjectList::processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description)
3396 QStringList preParams;
3398 preParams << QString::number(0) << QString::number(-1);
3400 preParams << jobParams.takeFirst();
3402 preParams << jobParams.takeFirst();
3404 preParams << jobParams.takeFirst();
3406 QString consumer = jobParams.takeFirst();
3408 foreach(const QString&id, ids) {
3409 ProjectItem *item = getItemById(id);
3410 if (!item) continue;
3411 if (ids.count() == 1) {
3412 consumer += ":" + destination;
3415 consumer += ":" + destination + item->clipUrl().fileName() + ".mlt";
3417 preParams << consumer << jobParams;
3419 MeltJob *job = new MeltJob(item->clipType(), id, preParams);
3421 job->setAddClipToProject(true);
3422 kDebug()<<"// ADDING TRUE";
3424 else kDebug()<<"// ADDING FALSE!!!";
3425 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3429 job->description = description;
3430 m_jobList.append(job);
3431 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3433 slotCheckJobProcess();
3436 void ProjectList::slotPrepareJobsMenu()
3439 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
3441 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
3442 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
3444 item = static_cast <ProjectItem*>(m_listView->currentItem());
3445 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
3446 QString id = item->clipId();
3447 m_discardCurrentClipJobs->setData(id);
3448 QStringList jobs = getPendingJobs(id);
3449 m_discardCurrentClipJobs->setEnabled(!jobs.isEmpty());
3451 m_discardCurrentClipJobs->setData(QString());
3452 m_discardCurrentClipJobs->setEnabled(false);
3456 void ProjectList::slotDiscardClipJobs()
3458 QString id = m_discardCurrentClipJobs->data().toString();
3459 if (id.isEmpty()) return;
3463 void ProjectList::updatePalette()
3465 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(QApplication::palette()));
3466 m_listView->updateStyleSheet();
3469 #include "projectlist.moc"