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>
65 #include <nepomuk/global.h>
66 #include <nepomuk/resourcemanager.h>
67 #include <Nepomuk/Resource>
68 //#include <nepomuk/tag.h>
71 #include <QMouseEvent>
72 #include <QStylePainter>
78 #include <QHeaderView>
79 #include <QInputDialog>
80 #include <QtConcurrentRun>
81 #include <QVBoxLayout>
82 #include <KPassivePopup>
85 MyMessageWidget::MyMessageWidget(QWidget *parent) : KMessageWidget(parent) {}
86 MyMessageWidget::MyMessageWidget(const QString &text, QWidget *parent) : KMessageWidget(text, parent) {}
89 bool MyMessageWidget::event(QEvent* ev) {
90 if (ev->type() == QEvent::Hide || ev->type() == QEvent::Close) emit messageClosing();
91 return KMessageWidget::event(ev);
94 SmallInfoLabel::SmallInfoLabel(QWidget *parent) : QPushButton(parent)
99 /*QString style = "QToolButton {background-color: %1;border-style: outset;border-width: 2px;
100 border-radius: 5px;border-color: beige;}";*/
101 m_timeLine = new QTimeLine(500, this);
102 QObject::connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(slotTimeLineChanged(qreal)));
103 QObject::connect(m_timeLine, SIGNAL(finished()), this, SLOT(slotTimeLineFinished()));
107 const QString SmallInfoLabel::getStyleSheet(const QPalette &p)
109 KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
110 QColor bg = scheme.background(KColorScheme::LinkBackground).color();
111 QColor fg = scheme.foreground(KColorScheme::LinkText).color();
112 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());
114 bg = scheme.background(KColorScheme::ActiveBackground).color();
115 fg = scheme.foreground(KColorScheme::ActiveText).color();
116 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()));
121 void SmallInfoLabel::slotTimeLineChanged(qreal value)
123 setFixedWidth(qMin(value * 2, qreal(1.0)) * sizeHint().width());
127 void SmallInfoLabel::slotTimeLineFinished()
129 if (m_timeLine->direction() == QTimeLine::Forward) {
139 void SmallInfoLabel::slotSetJobCount(int jobCount)
143 setText(i18np("%1 job", "%1 jobs", jobCount));
144 setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
146 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
147 setFixedWidth(sizeHint().width());
153 setFixedWidth(sizeHint().width());
160 int wantedWidth = sizeHint().width();
161 setGeometry(-wantedWidth, 0, wantedWidth, height());
162 m_timeLine->setDirection(QTimeLine::Forward);
163 if (m_timeLine->state() == QTimeLine::NotRunning) {
168 if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
174 m_timeLine->setDirection(QTimeLine::Backward);
175 if (m_timeLine->state() == QTimeLine::NotRunning) {
183 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
186 if (infoOnly) setButtons(KDialog::Ok);
187 else setButtons(KDialog::Yes | KDialog::No);
188 QWidget *w = new QWidget(this);
189 QVBoxLayout *l = new QVBoxLayout;
190 l->addWidget(new QLabel(message));
191 m_clipList = new QListWidget;
192 l->addWidget(m_clipList);
197 InvalidDialog::~InvalidDialog()
203 void InvalidDialog::addClip(const QString &id, const QString &path)
205 QListWidgetItem *item = new QListWidgetItem(path);
206 item->setData(Qt::UserRole, id);
207 m_clipList->addItem(item);
210 QStringList InvalidDialog::getIds() const
213 for (int i = 0; i < m_clipList->count(); i++) {
214 ids << m_clipList->item(i)->data(Qt::UserRole).toString();
220 ProjectList::ProjectList(QWidget *parent) :
224 m_commandStack(NULL),
226 m_reloadAction(NULL),
227 m_extractAudioAction(NULL),
228 m_transcodeAction(NULL),
229 m_stabilizeAction(NULL),
232 m_allClipsProcessed(false),
234 m_abortAllJobs(false),
236 m_invalidClipDialog(NULL)
238 qRegisterMetaType<stringMap> ("stringMap");
239 QVBoxLayout *layout = new QVBoxLayout;
240 layout->setContentsMargins(0, 0, 0, 0);
241 layout->setSpacing(0);
242 qRegisterMetaType<QDomElement>("QDomElement");
244 QFrame *frame = new QFrame;
245 frame->setFrameStyle(QFrame::NoFrame);
246 QHBoxLayout *box = new QHBoxLayout;
247 box->setContentsMargins(0, 0, 0, 0);
249 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
250 box->addWidget(searchView);
252 // small info button for pending jobs
253 m_infoLabel = new SmallInfoLabel(this);
254 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(palette()));
255 connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
256 m_jobsMenu = new QMenu(this);
257 connect(m_jobsMenu, SIGNAL(aboutToShow()), this, SLOT(slotPrepareJobsMenu()));
258 QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this);
259 cancelJobs->setCheckable(false);
260 connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs()));
261 connect(this, SIGNAL(checkJobProcess()), this, SLOT(slotCheckJobProcess()));
262 m_discardCurrentClipJobs = new QAction(i18n("Cancel Current Clip Jobs"), this);
263 m_discardCurrentClipJobs->setCheckable(false);
264 connect(m_discardCurrentClipJobs, SIGNAL(triggered()), this, SLOT(slotDiscardClipJobs()));
265 m_jobsMenu->addAction(cancelJobs);
266 m_jobsMenu->addAction(m_discardCurrentClipJobs);
267 m_infoLabel->setMenu(m_jobsMenu);
268 box->addWidget(m_infoLabel);
270 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
271 QSize iconSize(size, size);
273 m_addButton = new QToolButton;
274 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
275 m_addButton->setAutoRaise(true);
276 m_addButton->setIconSize(iconSize);
277 box->addWidget(m_addButton);
279 m_editButton = new QToolButton;
280 m_editButton->setAutoRaise(true);
281 m_editButton->setIconSize(iconSize);
282 box->addWidget(m_editButton);
284 m_deleteButton = new QToolButton;
285 m_deleteButton->setAutoRaise(true);
286 m_deleteButton->setIconSize(iconSize);
287 box->addWidget(m_deleteButton);
288 frame->setLayout(box);
289 layout->addWidget(frame);
291 m_listView = new ProjectListView(this);
292 layout->addWidget(m_listView);
294 #if KDE_IS_VERSION(4,7,0)
295 m_infoMessage = new MyMessageWidget;
296 layout->addWidget(m_infoMessage);
297 m_infoMessage->setCloseButtonVisible(true);
298 connect(m_infoMessage, SIGNAL(messageClosing()), this, SLOT(slotResetInfoMessage()));
299 //m_infoMessage->setWordWrap(true);
300 m_infoMessage->hide();
301 m_logAction = new QAction(i18n("Show Log"), this);
302 m_logAction->setCheckable(false);
303 connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
307 searchView->setTreeWidget(m_listView);
309 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
310 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
311 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
312 connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
313 connect(m_listView, SIGNAL(pauseMonitor()), this, SIGNAL(pauseMonitor()));
314 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
315 connect(m_listView, SIGNAL(addClip()), this, SIGNAL(pauseMonitor()));
316 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
317 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
318 connect(this, SIGNAL(addClip(const QString, const QString &, const QString &)), this, SLOT(slotAddClip(const QString, const QString &, const QString &)));
319 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
320 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
321 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
323 connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap)));
324 connect(this, SIGNAL(processLog(const QString, int , int, const QString)), this, SLOT(slotProcessLog(const QString, int , int, const QString)));
326 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)));
328 connect(this, SIGNAL(gotProxy(const QString)), this, SLOT(slotGotProxyForId(const QString)));
330 m_listViewDelegate = new ItemDelegate(m_listView);
331 m_listView->setItemDelegate(m_listViewDelegate);
333 if (KdenliveSettings::activate_nepomuk()) {
334 Nepomuk::ResourceManager::instance()->init();
335 if (!Nepomuk::ResourceManager::instance()->initialized()) {
336 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
337 KdenliveSettings::setActivate_nepomuk(false);
343 ProjectList::~ProjectList()
345 m_abortAllJobs = true;
346 for (int i = 0; i < m_jobList.count(); i++) {
347 m_jobList.at(i)->setStatus(JOBABORTED);
350 m_thumbnailQueue.clear();
351 m_jobThreads.waitForFinished();
352 m_jobThreads.clearFutures();
353 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
356 m_listView->blockSignals(true);
358 delete m_listViewDelegate;
359 #if KDE_IS_VERSION(4,7,0)
360 delete m_infoMessage;
364 void ProjectList::focusTree() const
366 m_listView->setFocus();
369 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
371 QList <QAction *> actions = addMenu->actions();
372 for (int i = 0; i < actions.count(); i++) {
373 if (actions.at(i)->data().toString() == "clip_properties") {
374 m_editButton->setDefaultAction(actions.at(i));
377 } else if (actions.at(i)->data().toString() == "delete_clip") {
378 m_deleteButton->setDefaultAction(actions.at(i));
381 } else if (actions.at(i)->data().toString() == "edit_clip") {
382 m_openAction = actions.at(i);
385 } else if (actions.at(i)->data().toString() == "reload_clip") {
386 m_reloadAction = actions.at(i);
389 } else if (actions.at(i)->data().toString() == "proxy_clip") {
390 m_proxyAction = actions.at(i);
396 QMenu *m = new QMenu();
397 m->addActions(actions);
398 m_addButton->setMenu(m);
399 m_addButton->setDefaultAction(defaultAction);
400 m_menu = new QMenu();
401 m_menu->addActions(addMenu->actions());
404 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
406 if (!menus.contains("addMenu") && ! menus.value("addMenu") )
408 QMenu *menu = m_addButton->menu();
409 if (menus.contains("addMenu") && menus.value("addMenu")){
410 QMenu* addMenu=menus.value("addMenu");
411 menu->addMenu(addMenu);
412 m_addButton->setMenu(menu);
413 if (addMenu->isEmpty())
414 addMenu->setEnabled(false);
416 if (menus.contains("extractAudioMenu") && menus.value("extractAudioMenu") ){
417 QMenu* extractAudioMenu = menus.value("extractAudioMenu");
418 m_menu->addMenu(extractAudioMenu);
419 m_extractAudioAction = extractAudioMenu;
421 if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
422 QMenu* transcodeMenu = menus.value("transcodeMenu");
423 m_menu->addMenu(transcodeMenu);
424 if (transcodeMenu->isEmpty())
425 transcodeMenu->setEnabled(false);
426 m_transcodeAction = transcodeMenu;
428 if (menus.contains("stabilizeMenu") && menus.value("stabilizeMenu") ){
429 QMenu* stabilizeMenu=menus.value("stabilizeMenu");
430 m_menu->addMenu(stabilizeMenu);
431 if (stabilizeMenu->isEmpty())
432 stabilizeMenu->setEnabled(false);
433 m_stabilizeAction=stabilizeMenu;
436 m_menu->addAction(m_reloadAction);
437 m_menu->addAction(m_proxyAction);
438 if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
439 QMenu* inTimelineMenu=menus.value("inTimelineMenu");
440 m_menu->addMenu(inTimelineMenu);
441 inTimelineMenu->setEnabled(false);
443 m_menu->addAction(m_editButton->defaultAction());
444 m_menu->addAction(m_openAction);
445 m_menu->addAction(m_deleteButton->defaultAction());
446 m_menu->insertSeparator(m_deleteButton->defaultAction());
449 void ProjectList::clearSelection()
451 m_listView->clearSelection();
454 QByteArray ProjectList::headerInfo() const
456 return m_listView->header()->saveState();
459 void ProjectList::setHeaderInfo(const QByteArray &state)
461 m_listView->header()->restoreState(state);
464 void ProjectList::updateProjectFormat(Timecode t)
469 void ProjectList::slotEditClip()
471 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
472 if (list.isEmpty()) return;
473 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
474 editClipSelection(list);
478 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
480 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
481 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
483 item = static_cast <ProjectItem*>(m_listView->currentItem());
484 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
485 emit clipSelected(item->referencedClip());
486 emit showClipProperties(item->referencedClip());
490 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
492 // Gather all common properties
493 QMap <QString, QString> commonproperties;
494 QList <DocClipBase *> clipList;
495 commonproperties.insert("force_aspect_num", "-");
496 commonproperties.insert("force_aspect_den", "-");
497 commonproperties.insert("force_fps", "-");
498 commonproperties.insert("force_progressive", "-");
499 commonproperties.insert("force_tff", "-");
500 commonproperties.insert("threads", "-");
501 commonproperties.insert("video_index", "-");
502 commonproperties.insert("audio_index", "-");
503 commonproperties.insert("force_colorspace", "-");
504 commonproperties.insert("full_luma", "-");
505 QString transparency = "-";
507 bool allowDurationChange = true;
508 int commonDuration = -1;
509 bool hasImages = false;;
511 for (int i = 0; i < list.count(); i++) {
513 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
514 // Add folder items to the list
515 int ct = list.at(i)->childCount();
516 for (int j = 0; j < ct; j++) {
517 list.append(list.at(i)->child(j));
521 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
522 item = static_cast <ProjectItem*>(list.at(i)->parent());
524 item = static_cast <ProjectItem*>(list.at(i));
525 if (!(item->flags() & Qt::ItemIsDragEnabled))
529 DocClipBase *clip = item->referencedClip();
530 if (clipList.contains(clip)) continue;
531 if (clip->clipType() == IMAGE) {
533 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
534 if (transparency == "-") {
535 // first non transparent image
538 else if (transparency == "1") {
539 // we have transparent and non transparent clips
544 if (transparency == "-") {
545 // first transparent image
548 else if (transparency == "0") {
549 // we have transparent and non transparent clips
554 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
555 allowDurationChange = false;
556 if (allowDurationChange && commonDuration != 0) {
557 if (commonDuration == -1)
558 commonDuration = clip->duration().frames(m_fps);
559 else if (commonDuration != clip->duration().frames(m_fps))
562 clipList.append(clip);
563 QMap <QString, QString> clipprops = clip->properties();
564 QMapIterator<QString, QString> p(commonproperties);
565 while (p.hasNext()) {
567 if (p.value().isEmpty()) continue;
568 if (clipprops.contains(p.key())) {
569 if (p.value() == "-")
570 commonproperties.insert(p.key(), clipprops.value(p.key()));
571 else if (p.value() != clipprops.value(p.key()))
572 commonproperties.insert(p.key(), QString());
574 commonproperties.insert(p.key(), QString());
579 if (allowDurationChange)
580 commonproperties.insert("out", QString::number(commonDuration));
582 commonproperties.insert("transparency", transparency);
583 /*QMapIterator<QString, QString> p(commonproperties);
584 while (p.hasNext()) {
586 kDebug() << "Result: " << p.key() << " = " << p.value();
588 if (clipList.isEmpty()) {
589 emit displayMessage(i18n("No available clip selected"), -2);
591 else emit showClipProperties(clipList, commonproperties);
594 void ProjectList::slotOpenClip()
597 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
599 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
600 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
602 item = static_cast <ProjectItem*>(m_listView->currentItem());
604 if (item->clipType() == IMAGE) {
605 if (KdenliveSettings::defaultimageapp().isEmpty())
606 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
608 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
610 if (item->clipType() == AUDIO) {
611 if (KdenliveSettings::defaultaudioapp().isEmpty())
612 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
614 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
619 void ProjectList::cleanup()
621 m_listView->clearSelection();
622 QTreeWidgetItemIterator it(m_listView);
625 if ((*it)->type() != PROJECTCLIPTYPE) {
629 item = static_cast <ProjectItem *>(*it);
630 if (item->numReferences() == 0)
631 item->setSelected(true);
637 void ProjectList::trashUnusedClips()
639 QTreeWidgetItemIterator it(m_listView);
644 if ((*it)->type() != PROJECTCLIPTYPE) {
648 item = static_cast <ProjectItem *>(*it);
649 if (item->numReferences() == 0) {
650 ids << item->clipId();
651 KUrl url = item->clipUrl();
652 if (!url.isEmpty() && !urls.contains(url.path()))
658 // Check that we don't use the URL in another clip
659 QTreeWidgetItemIterator it2(m_listView);
661 if ((*it2)->type() != PROJECTCLIPTYPE) {
665 item = static_cast <ProjectItem *>(*it2);
666 if (item->numReferences() > 0) {
667 KUrl url = item->clipUrl();
668 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
673 emit deleteProjectClips(ids, QMap <QString, QString>());
674 for (int i = 0; i < urls.count(); i++)
675 KIO::NetAccess::del(KUrl(urls.at(i)), this);
678 void ProjectList::slotReloadClip(const QString &id)
680 QList<QTreeWidgetItem *> selected;
682 selected = m_listView->selectedItems();
684 ProjectItem *itemToReLoad = getItemById(id);
685 if (itemToReLoad) selected.append(itemToReLoad);
688 for (int i = 0; i < selected.count(); i++) {
689 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
690 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
691 for (int j = 0; j < selected.at(i)->childCount(); j++)
692 selected.append(selected.at(i)->child(j));
696 item = static_cast <ProjectItem *>(selected.at(i));
697 if (item && !hasPendingJob(item, PROXYJOB)) {
698 DocClipBase *clip = item->referencedClip();
699 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
700 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
703 CLIPTYPE t = item->clipType();
705 if (clip && !clip->getProperty("xmltemplate").isEmpty())
706 regenerateTemplate(item);
707 } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
708 item->referencedClip()->setPlaceHolder(true);
709 item->setProperty("file_hash", QString());
710 } else if (t == IMAGE) {
711 //clip->getProducer() clip->getProducer()->set("force_reload", 1);
714 QDomElement e = item->toXml();
715 // Make sure we get the correct producer length if it was adjusted in timeline
716 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
717 int length = QString(clip->producerProperty("length")).toInt();
718 if (length > 0 && !e.hasAttribute("length")) {
719 e.setAttribute("length", length);
722 resetThumbsProducer(clip);
723 m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
728 void ProjectList::slotModifiedClip(const QString &id)
730 ProjectItem *item = getItemById(id);
732 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
733 if (!pixmap.isNull()) {
735 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
736 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
739 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
741 item->setData(0, Qt::DecorationRole, pixmap);
745 void ProjectList::slotMissingClip(const QString &id)
747 ProjectItem *item = getItemById(id);
749 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
750 int height = m_listView->iconSize().height();
751 if (m_render == NULL) {
752 kDebug() << "********* ERROR, NULL RENDR";
755 int width = (int)(height * m_render->dar());
756 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
757 if (pixmap.isNull()) {
758 pixmap = QPixmap(width, height);
759 pixmap.fill(Qt::transparent);
761 KIcon icon("dialog-close");
763 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
765 item->setData(0, Qt::DecorationRole, pixmap);
766 if (item->referencedClip()) {
767 item->referencedClip()->setPlaceHolder(true);
768 Mlt::Producer *newProd = m_render->invalidProducer(id);
769 if (item->referencedClip()->getProducer()) {
770 Mlt::Properties props(newProd->get_properties());
771 Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
772 props.inherit(src_props);
774 item->referencedClip()->setProducer(newProd, true);
775 item->slotSetToolTip();
776 emit clipNeedsReload(id);
780 emit displayMessage(i18n("Check missing clips"), -2);
781 emit updateRenderStatus();
784 void ProjectList::slotAvailableClip(const QString &id)
786 ProjectItem *item = getItemById(id);
789 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
790 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
791 item->setProperty("file_hash", QString());
795 item->referencedClip()->setValid();
796 item->slotSetToolTip();
799 emit updateRenderStatus();
802 bool ProjectList::hasMissingClips()
804 bool missing = false;
805 QTreeWidgetItemIterator it(m_listView);
807 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
816 void ProjectList::setRenderer(Render *projectRender)
818 m_render = projectRender;
819 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
820 connect(m_render, SIGNAL(requestProxy(QString)), this, SLOT(slotCreateProxy(QString)));
823 void ProjectList::slotClipSelected()
825 QTreeWidgetItem *item = m_listView->currentItem();
826 ProjectItem *clip = NULL;
828 if (item->type() == PROJECTFOLDERTYPE) {
829 emit clipSelected(NULL);
830 m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
831 m_deleteButton->defaultAction()->setEnabled(true);
832 m_openAction->setEnabled(false);
833 m_reloadAction->setEnabled(false);
834 m_extractAudioAction->setEnabled(false);
835 m_transcodeAction->setEnabled(false);
836 m_stabilizeAction->setEnabled(false);
838 if (item->type() == PROJECTSUBCLIPTYPE) {
839 // this is a sub item, use base clip
840 m_deleteButton->defaultAction()->setEnabled(true);
841 clip = static_cast <ProjectItem*>(item->parent());
842 if (clip == NULL) kDebug() << "-----------ERROR";
843 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
844 emit clipSelected(clip->referencedClip(), sub->zone());
845 m_extractAudioAction->setEnabled(false);
846 m_transcodeAction->setEnabled(false);
847 m_stabilizeAction->setEnabled(false);
848 m_reloadAction->setEnabled(false);
849 adjustProxyActions(clip);
852 clip = static_cast <ProjectItem*>(item);
853 if (clip && clip->referencedClip())
854 emit clipSelected(clip->referencedClip());
855 m_editButton->defaultAction()->setEnabled(true);
856 m_deleteButton->defaultAction()->setEnabled(true);
857 m_reloadAction->setEnabled(true);
858 m_extractAudioAction->setEnabled(true);
859 m_transcodeAction->setEnabled(true);
860 m_stabilizeAction->setEnabled(true);
861 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
862 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
863 m_openAction->setEnabled(true);
864 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
865 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
866 m_openAction->setEnabled(true);
868 m_openAction->setEnabled(false);
870 // Display relevant transcoding actions only
871 adjustTranscodeActions(clip);
872 adjustStabilizeActions(clip);
873 // Display uses in timeline
874 emit findInTimeline(clip->clipId());
877 emit clipSelected(NULL);
878 m_editButton->defaultAction()->setEnabled(false);
879 m_deleteButton->defaultAction()->setEnabled(false);
880 m_openAction->setEnabled(false);
881 m_reloadAction->setEnabled(false);
882 m_extractAudioAction->setEnabled(true);
883 m_transcodeAction->setEnabled(false);
884 m_stabilizeAction->setEnabled(false);
886 adjustProxyActions(clip);
889 void ProjectList::adjustProxyActions(ProjectItem *clip) const
891 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
892 m_proxyAction->setEnabled(false);
895 bool enabled = useProxy();
896 if (clip->referencedClip() && !clip->referencedClip()->getProperty("_missingsource").isEmpty()) enabled = false;
897 m_proxyAction->setEnabled(enabled);
898 m_proxyAction->blockSignals(true);
899 m_proxyAction->setChecked(clip->hasProxy());
900 m_proxyAction->blockSignals(false);
903 void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
906 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
907 m_stabilizeAction->setEnabled(false);
910 m_stabilizeAction->setEnabled(true);
914 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
916 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
917 m_transcodeAction->setEnabled(false);
918 m_extractAudioAction->setEnabled(false);
921 m_transcodeAction->setEnabled(true);
922 m_extractAudioAction->setEnabled(true);
923 QList<QAction *> transcodeActions = m_transcodeAction->actions();
926 for (int i = 0; i < transcodeActions.count(); i++) {
927 data = transcodeActions.at(i)->data().toStringList();
928 if (data.count() > 2) {
929 condition = data.at(2);
930 if (condition.startsWith("vcodec"))
931 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
932 else if (condition.startsWith("acodec"))
933 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
939 void ProjectList::slotPauseMonitor()
945 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
947 ProjectItem *item = getItemById(id);
949 slotUpdateClipProperties(item, properties);
950 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource") || properties.contains("video_index") || properties.contains("audio_index")) {
952 } else if (properties.contains("colour") ||
953 properties.contains("xmldata") ||
954 properties.contains("force_aspect_num") ||
955 properties.contains("force_aspect_den") ||
956 properties.contains("templatetext")) {
957 slotRefreshClipThumbnail(item);
958 emit refreshClip(id, true);
959 } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
960 emit refreshClip(id, false);
965 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
969 clip->setProperties(properties);
970 if (properties.contains("proxy")) {
971 if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
972 // this should only apply to proxy jobs
973 clip->setConditionalJobStatus(NOJOB, PROXYJOB);
975 if (properties.contains("name")) {
976 monitorItemEditing(false);
977 clip->setText(0, properties.value("name"));
978 monitorItemEditing(true);
979 emit clipNameChanged(clip->clipId(), properties.value("name"));
981 if (properties.contains("description")) {
982 CLIPTYPE type = clip->clipType();
983 monitorItemEditing(false);
984 clip->setText(1, properties.value("description"));
985 monitorItemEditing(true);
987 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
988 // Use Nepomuk system to store clip description
989 Nepomuk::Resource f(clip->clipUrl().path());
990 f.setDescription(properties.value("description"));
993 emit projectModified();
997 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
999 if (item->type() == PROJECTSUBCLIPTYPE) {
1000 // this is a sub-item
1002 // user edited description
1003 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
1004 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1005 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
1006 m_commandStack->push(command);
1007 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
1011 if (item->type() == PROJECTFOLDERTYPE) {
1013 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
1014 editFolder(item->text(0), folder->groupName(), folder->clipId());
1015 folder->setGroupName(item->text(0));
1016 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
1017 const int children = item->childCount();
1018 for (int i = 0; i < children; i++) {
1019 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1020 child->setProperty("groupname", item->text(0));
1026 ProjectItem *clip = static_cast <ProjectItem*>(item);
1028 if (clip->referencedClip()) {
1029 QMap <QString, QString> oldprops;
1030 QMap <QString, QString> newprops;
1031 oldprops["description"] = clip->referencedClip()->getProperty("description");
1032 newprops["description"] = item->text(1);
1034 if (clip->clipType() == TEXT) {
1035 // This is a text template clip, update the image
1036 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
1037 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
1038 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
1039 newprops.insert("templatetext", item->text(1));
1041 slotUpdateClipProperties(clip->clipId(), newprops);
1042 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1043 m_commandStack->push(command);
1045 } else if (column == 0) {
1046 if (clip->referencedClip()) {
1047 QMap <QString, QString> oldprops;
1048 QMap <QString, QString> newprops;
1049 oldprops["name"] = clip->referencedClip()->getProperty("name");
1050 if (oldprops.value("name") != item->text(0)) {
1051 newprops["name"] = item->text(0);
1052 slotUpdateClipProperties(clip, newprops);
1053 emit projectModified();
1054 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
1055 m_commandStack->push(command);
1056 QTimer::singleShot(100, this, SLOT(slotCheckScrolling()));
1062 void ProjectList::slotCheckScrolling()
1064 m_listView->scrollToItem(m_listView->currentItem());
1067 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
1069 bool enable = item ? true : false;
1070 m_editButton->defaultAction()->setEnabled(enable);
1071 m_deleteButton->defaultAction()->setEnabled(enable);
1072 m_reloadAction->setEnabled(enable);
1073 m_extractAudioAction->setEnabled(enable);
1074 m_transcodeAction->setEnabled(enable);
1075 m_stabilizeAction->setEnabled(enable);
1077 ProjectItem *clip = NULL;
1078 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1079 clip = static_cast <ProjectItem*>(item->parent());
1080 m_extractAudioAction->setEnabled(false);
1081 m_transcodeAction->setEnabled(false);
1082 m_stabilizeAction->setEnabled(false);
1083 adjustProxyActions(clip);
1084 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
1085 clip = static_cast <ProjectItem*>(item);
1086 // Display relevant transcoding actions only
1087 adjustTranscodeActions(clip);
1088 adjustStabilizeActions(clip);
1089 adjustProxyActions(clip);
1090 // Display uses in timeline
1091 emit findInTimeline(clip->clipId());
1093 m_extractAudioAction->setEnabled(false);
1094 m_transcodeAction->setEnabled(false);
1095 m_stabilizeAction->setEnabled(false);
1097 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1098 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1099 m_openAction->setEnabled(true);
1100 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1101 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1102 m_openAction->setEnabled(true);
1104 m_openAction->setEnabled(false);
1108 m_openAction->setEnabled(false);
1113 void ProjectList::slotRemoveClip()
1115 if (!m_listView->currentItem())
1118 QMap <QString, QString> folderids;
1119 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
1121 QUndoCommand *delCommand = new QUndoCommand();
1122 delCommand->setText(i18n("Delete Clip Zone"));
1123 for (int i = 0; i < selected.count(); i++) {
1124 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
1126 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
1127 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
1128 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
1129 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
1131 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
1132 folderids[folder->groupName()] = folder->clipId();
1133 int children = folder->childCount();
1135 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)
1137 for (int i = 0; i < children; ++i) {
1138 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
1139 ids << child->clipId();
1142 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
1143 ids << item->clipId();
1144 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) {
1145 KMessageBox::enableMessage("DeleteAll");
1150 KMessageBox::enableMessage("DeleteAll");
1151 if (delCommand->childCount() == 0)
1154 m_commandStack->push(delCommand);
1155 emit deleteProjectClips(ids, folderids);
1158 void ProjectList::updateButtons() const
1160 if (m_listView->topLevelItemCount() == 0) {
1161 m_deleteButton->defaultAction()->setEnabled(false);
1162 m_editButton->defaultAction()->setEnabled(false);
1164 m_deleteButton->defaultAction()->setEnabled(true);
1165 if (!m_listView->currentItem())
1166 m_listView->setCurrentItem(m_listView->topLevelItem(0));
1167 QTreeWidgetItem *item = m_listView->currentItem();
1168 if (item && item->type() == PROJECTCLIPTYPE) {
1169 m_editButton->defaultAction()->setEnabled(true);
1170 m_openAction->setEnabled(true);
1171 m_reloadAction->setEnabled(true);
1172 m_transcodeAction->setEnabled(true);
1173 m_stabilizeAction->setEnabled(true);
1176 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
1177 m_editButton->defaultAction()->setEnabled(true);
1179 else m_editButton->defaultAction()->setEnabled(false);
1181 m_openAction->setEnabled(false);
1182 m_reloadAction->setEnabled(false);
1183 m_transcodeAction->setEnabled(false);
1184 m_stabilizeAction->setEnabled(false);
1185 m_proxyAction->setEnabled(false);
1188 void ProjectList::selectItemById(const QString &clipId)
1190 ProjectItem *item = getItemById(clipId);
1192 m_listView->setCurrentItem(item);
1196 void ProjectList::slotDeleteClip(const QString &clipId)
1198 ProjectItem *item = getItemById(clipId);
1200 kDebug() << "/// Cannot find clip to delete";
1203 deleteJobsForClip(clipId);
1204 m_listView->blockSignals(true);
1205 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1206 if (!newSelectedItem)
1207 newSelectedItem = m_listView->itemBelow(item);
1209 // Pause playing to prevent crash while deleting clip
1211 m_doc->clipManager()->deleteClip(clipId);
1212 m_listView->blockSignals(false);
1213 if (newSelectedItem) {
1214 m_listView->setCurrentItem(newSelectedItem);
1217 emit clipSelected(NULL);
1222 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
1224 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
1225 m_commandStack->push(command);
1226 m_doc->setModified(true);
1229 void ProjectList::slotAddFolder(const QString &name)
1231 AddFolderCommand *command = new AddFolderCommand(this, name.isEmpty() ? i18n("Folder") : name, QString::number(m_doc->clipManager()->getFreeFolderId()), true);
1232 m_commandStack->push(command);
1235 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
1238 FolderProjectItem *item = getFolderItemById(clipId);
1240 m_doc->clipManager()->deleteFolder(clipId);
1241 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
1242 if (!newSelectedItem)
1243 newSelectedItem = m_listView->itemBelow(item);
1245 if (newSelectedItem)
1246 m_listView->setCurrentItem(newSelectedItem);
1252 FolderProjectItem *item = getFolderItemById(clipId);
1254 m_listView->blockSignals(true);
1255 item->setGroupName(foldername);
1256 m_listView->blockSignals(false);
1257 m_doc->clipManager()->addFolder(clipId, foldername);
1258 const int children = item->childCount();
1259 for (int i = 0; i < children; i++) {
1260 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
1261 child->setProperty("groupname", foldername);
1265 m_listView->blockSignals(true);
1266 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
1267 m_doc->clipManager()->addFolder(clipId, foldername);
1268 m_listView->blockSignals(false);
1269 m_listView->editItem(m_listView->currentItem(), 0);
1273 m_doc->setModified(true);
1278 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
1280 QMapIterator<QString, QString> i(map);
1281 QUndoCommand *delCommand = new QUndoCommand();
1282 delCommand->setText(i18n("Delete Folder"));
1283 while (i.hasNext()) {
1285 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
1287 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
1288 else delete delCommand;
1291 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
1293 //m_listView->setEnabled(false);
1294 const QString parent = clip->getProperty("groupid");
1295 QString groupName = clip->getProperty("groupname");
1296 ProjectItem *item = NULL;
1297 monitorItemEditing(false);
1298 if (!parent.isEmpty()) {
1299 FolderProjectItem *parentitem = getFolderItemById(parent);
1302 //kDebug() << "Adding clip to new group: " << groupName;
1303 if (groupName.isEmpty()) groupName = i18n("Folder");
1305 parentitem = new FolderProjectItem(m_listView, text, parent);
1309 item = new ProjectItem(parentitem, clip);
1312 item = new ProjectItem(m_listView, clip);
1314 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
1315 connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
1316 connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
1317 if (getProperties) {
1318 int height = m_listView->iconSize().height();
1319 int width = (int)(height * m_render->dar());
1320 QPixmap pix = KIcon("video-x-generic").pixmap(QSize(width, height));
1321 item->setData(0, Qt::DecorationRole, pix);
1322 //item->setFlags(Qt::ItemIsSelectable);
1323 m_listView->processLayout();
1324 QDomElement e = clip->toXML().cloneNode().toElement();
1325 if (!groupName.isEmpty()) {
1326 e.setAttribute("groupId", parent);
1327 e.setAttribute("group", groupName);
1329 e.removeAttribute("file_hash");
1330 resetThumbsProducer(clip);
1331 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1333 // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases?
1334 /*else if (item->hasProxy() && !item->isJobRunning()) {
1335 slotCreateProxy(clip->getId());
1338 KUrl url = clip->fileURL();
1340 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk() && clip->getProperty("description").isEmpty()) {
1341 // if file has Nepomuk comment, use it
1342 Nepomuk::Resource f(url.path());
1343 QString annotation = f.description();
1344 if (!annotation.isEmpty()) {
1345 item->setText(1, annotation);
1346 clip->setProperty("description", annotation);
1348 item->setText(2, QString::number(f.rating()));
1352 // Add info to date column
1353 QFileInfo fileInfo(url.path());
1354 if (fileInfo.exists()) {
1355 item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
1359 QList <CutZoneInfo> cuts = clip->cutZones();
1360 if (!cuts.isEmpty()) {
1361 for (int i = 0; i < cuts.count(); i++) {
1362 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1363 if (!clip->getClipHash().isEmpty()) {
1364 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1365 if (QFile::exists(cachedPixmap)) {
1366 QPixmap pix(cachedPixmap);
1368 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1369 sub->setData(0, Qt::DecorationRole, pix);
1374 monitorItemEditing(true);
1378 void ProjectList::slotGotProxy(const QString &proxyPath)
1380 if (proxyPath.isEmpty() || m_abortAllJobs) return;
1381 QTreeWidgetItemIterator it(m_listView);
1384 while (*it && !m_closing) {
1385 if ((*it)->type() == PROJECTCLIPTYPE) {
1386 item = static_cast <ProjectItem *>(*it);
1387 if (item->referencedClip()->getProperty("proxy") == proxyPath)
1394 void ProjectList::slotGotProxyForId(const QString id)
1396 if (m_closing) return;
1397 ProjectItem *item = getItemById(id);
1401 void ProjectList::slotGotProxy(ProjectItem *item)
1403 if (item == NULL) return;
1404 DocClipBase *clip = item->referencedClip();
1405 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
1406 // Clip is being reprocessed, abort
1407 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
1411 // Proxy clip successfully created
1412 QDomElement e = clip->toXML().cloneNode().toElement();
1414 // Make sure we get the correct producer length if it was adjusted in timeline
1415 CLIPTYPE t = item->clipType();
1416 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1417 int length = QString(clip->producerProperty("length")).toInt();
1418 if (length > 0 && !e.hasAttribute("length")) {
1419 e.setAttribute("length", length);
1422 resetThumbsProducer(clip);
1423 m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
1426 void ProjectList::slotResetProjectList()
1428 m_listView->blockSignals(true);
1429 m_abortAllJobs = true;
1430 for (int i = 0; i < m_jobList.count(); i++) {
1431 m_jobList.at(i)->setStatus(JOBABORTED);
1434 m_jobThreads.waitForFinished();
1435 m_jobThreads.clearFutures();
1436 m_thumbnailQueue.clear();
1437 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
1439 m_listView->clear();
1440 m_listView->setEnabled(true);
1441 emit clipSelected(NULL);
1442 m_refreshed = false;
1443 m_allClipsProcessed = false;
1444 m_abortAllJobs = false;
1446 m_listView->blockSignals(false);
1449 void ProjectList::slotUpdateClip(const QString &id)
1451 ProjectItem *item = getItemById(id);
1452 monitorItemEditing(false);
1453 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1454 monitorItemEditing(true);
1457 void ProjectList::getCachedThumbnail(ProjectItem *item)
1460 DocClipBase *clip = item->referencedClip();
1462 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1463 if (QFile::exists(cachedPixmap)) {
1464 QPixmap pix(cachedPixmap);
1466 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1467 requestClipThumbnail(item->clipId());
1470 processThumbOverlays(item, pix);
1471 item->setData(0, Qt::DecorationRole, pix);
1475 requestClipThumbnail(item->clipId());
1479 void ProjectList::getCachedThumbnail(SubProjectItem *item)
1482 ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
1483 if (!parentItem) return;
1484 DocClipBase *clip = parentItem->referencedClip();
1486 int pos = item->zone().x();
1487 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(pos) + ".png";
1488 if (QFile::exists(cachedPixmap)) {
1489 QPixmap pix(cachedPixmap);
1491 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1492 requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1494 else item->setData(0, Qt::DecorationRole, pix);
1496 else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
1499 void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
1501 if (!m_allClipsProcessed) m_listView->setEnabled(false);
1502 m_listView->setSortingEnabled(false);
1503 QTreeWidgetItemIterator it(m_listView);
1506 monitorItemEditing(false);
1507 int height = m_listView->iconSize().height();
1508 int width = (int)(height * m_render->dar());
1509 QPixmap missingPixmap = QPixmap(width, height);
1510 missingPixmap.fill(Qt::transparent);
1511 KIcon icon("dialog-close");
1512 QPainter p(&missingPixmap);
1513 p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
1516 int max = m_doc->clipManager()->clipsCount();
1521 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
1522 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1524 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1525 if (displayRatioChanged) {
1526 item = static_cast <ProjectItem *>((*it)->parent());
1527 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1529 else if (sub->data(0, Qt::DecorationRole).isNull()) {
1530 getCachedThumbnail(sub);
1534 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1539 item = static_cast <ProjectItem *>(*it);
1540 clip = item->referencedClip();
1541 if (clip->getProducer() == NULL) {
1542 bool replace = false;
1543 if (brokenClips.contains(item->clipId())) {
1544 // if this is a proxy clip, disable proxy
1545 item->setConditionalJobStatus(NOJOB, PROXYJOB);
1546 discardJobs(item->clipId(), PROXYJOB);
1547 clip->setProperty("proxy", "-");
1550 if (clip->isPlaceHolder() == false && !hasPendingJob(item, PROXYJOB)) {
1551 QDomElement xml = clip->toXML();
1553 xml.removeAttribute("out");
1554 xml.removeAttribute("file_hash");
1555 xml.removeAttribute("proxy_out");
1557 if (!replace) replace = xml.attribute("_replaceproxy") == "1";
1558 xml.removeAttribute("_replaceproxy");
1560 resetThumbsProducer(clip);
1562 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
1564 else if (clip->isPlaceHolder()) {
1565 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1566 if (item->data(0, Qt::DecorationRole).isNull()) {
1567 item->setData(0, Qt::DecorationRole, missingPixmap);
1570 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1571 QPainter p(&pixmap);
1572 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1574 item->setData(0, Qt::DecorationRole, pixmap);
1578 if (displayRatioChanged) {
1579 requestClipThumbnail(clip->getId());
1581 else if (item->data(0, Qt::DecorationRole).isNull()) {
1582 getCachedThumbnail(item);
1584 if (item->data(0, DurationRole).toString().isEmpty()) {
1585 item->changeDuration(clip->getProducer()->get_playtime());
1587 if (clip->isPlaceHolder()) {
1588 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
1589 if (pixmap.isNull()) {
1590 pixmap = QPixmap(width, height);
1591 pixmap.fill(Qt::transparent);
1593 QPainter p(&pixmap);
1594 p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
1596 item->setData(0, Qt::DecorationRole, pixmap);
1598 else if (clip->getProperty("_replaceproxy") == "1") {
1599 clip->setProperty("_replaceproxy", QString());
1600 slotCreateProxy(clip->getId());
1603 item->setData(0, UsageRole, QString::number(item->numReferences()));
1608 m_listView->setSortingEnabled(true);
1609 m_allClipsProcessed = true;
1610 if (m_render->processingItems() == 0) {
1611 monitorItemEditing(true);
1612 slotProcessNextThumbnail();
1617 QString ProjectList::getExtensions()
1619 // Build list of mime types
1620 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain";
1623 mimeTypes << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "video/mp4" << "video/quicktime" << "video/webm" << "video/3gpp";
1626 mimeTypes << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "audio/x-aiff" << "audio/aiff" << "application/ogg" << "application/mxf" << "application/x-shockwave-flash" << "audio/ac3";
1629 mimeTypes << "image/gif" << "image/jpeg" << "image/png" << "image/x-tga" << "image/x-bmp" << "image/svg+xml" << "image/tiff" << "image/x-xcf" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr";
1631 QString allExtensions;
1632 foreach(const QString & mimeType, mimeTypes) {
1633 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1635 allExtensions.append(mime->patterns().join(" "));
1636 allExtensions.append(' ');
1639 return allExtensions.simplified();
1642 void ProjectList::slotAddClip(const QString url, const QString &groupName, const QString &groupId)
1644 kDebug()<<"// Adding clip: "<<url;
1647 slotAddClip(list, groupName, groupId);
1650 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1652 if (!m_commandStack)
1653 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1656 if (givenList.isEmpty()) {
1657 QString allExtensions = getExtensions();
1658 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1659 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1660 b->setChecked(KdenliveSettings::autoimagesequence());
1661 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1662 c->setChecked(KdenliveSettings::autoimagetransparency());
1663 QFrame *f = new QFrame;
1664 f->setFrameShape(QFrame::NoFrame);
1665 QHBoxLayout *l = new QHBoxLayout;
1670 QPointer<KFileDialog> d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1671 d->setOperationMode(KFileDialog::Opening);
1672 d->setMode(KFile::Files);
1673 if (d->exec() == QDialog::Accepted) {
1674 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1676 list = d->selectedUrls();
1677 if (b->isChecked() && list.count() == 1) {
1678 // Check for image sequence
1679 KUrl url = list.at(0);
1680 QString fileName = url.fileName().section('.', 0, -2);
1681 if (fileName.at(fileName.size() - 1).isDigit()) {
1682 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1683 if (item.mimetype().startsWith("image")) {
1684 // import as sequence if we found more than one image in the sequence
1686 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1687 int count = list.count();
1690 QStringList groupInfo = getGroup();
1692 // get image sequence base name
1693 while (fileName.at(fileName.size() - 1).isDigit()) {
1696 QMap <QString, QString> properties;
1697 properties.insert("name", fileName);
1698 properties.insert("resource", pattern);
1699 properties.insert("in", "0");
1700 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
1701 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
1702 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
1703 properties.insert("loop", QString::number(false));
1704 properties.insert("crop", QString::number(false));
1705 properties.insert("fade", QString::number(false));
1706 properties.insert("luma_duration", QString::number(m_doc->getFramePos(m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))))));
1707 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1715 for (int i = 0; i < givenList.count(); i++)
1716 list << givenList.at(i);
1718 QList <KUrl::List> foldersList;
1720 foreach(const KUrl & file, list) {
1721 // Check there is no folder here
1722 KMimeType::Ptr type = KMimeType::findByUrl(file);
1723 if (type->is("inode/directory")) {
1724 // user dropped a folder, import its files
1725 list.removeAll(file);
1726 QDir dir(file.path());
1727 QStringList result = dir.entryList(QDir::Files);
1728 KUrl::List folderFiles;
1729 folderFiles << file;
1730 foreach(const QString & path, result) {
1731 KUrl newFile = file;
1732 newFile.addPath(path);
1733 folderFiles.append(newFile);
1735 if (folderFiles.count() > 1) foldersList.append(folderFiles);
1739 if (givenList.isEmpty() && !list.isEmpty()) {
1740 QStringList groupInfo = getGroup();
1741 QMap <QString, QString> data;
1742 data.insert("group", groupInfo.at(0));
1743 data.insert("groupId", groupInfo.at(1));
1744 m_doc->slotAddClipList(list, data);
1745 } else if (!list.isEmpty()) {
1746 QMap <QString, QString> data;
1747 data.insert("group", groupName);
1748 data.insert("groupId", groupId);
1749 m_doc->slotAddClipList(list, data);
1752 if (!foldersList.isEmpty()) {
1754 for (int i = 0; i < foldersList.count(); i++) {
1755 KUrl::List urls = foldersList.at(i);
1756 KUrl folderUrl = urls.takeFirst();
1757 QString folderName = folderUrl.fileName();
1758 FolderProjectItem *folder = NULL;
1759 if (!folderName.isEmpty()) {
1760 folder = getFolderItemByName(folderName);
1761 if (folder == NULL) {
1762 slotAddFolder(folderName);
1763 folder = getFolderItemByName(folderName);
1767 QMap <QString, QString> data;
1768 data.insert("group", folder->groupName());
1769 data.insert("groupId", folder->clipId());
1770 m_doc->slotAddClipList(urls, data);
1772 else m_doc->slotAddClipList(urls);
1777 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1779 ProjectItem *item = getItemById(id);
1780 m_thumbnailQueue.removeAll(id);
1782 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1783 const QString path = item->referencedClip()->fileURL().path();
1784 if (item->referencedClip()->isPlaceHolder()) replace = false;
1785 if (!path.isEmpty()) {
1786 if (m_invalidClipDialog) {
1787 m_invalidClipDialog->addClip(id, path);
1792 m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
1794 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());
1796 m_invalidClipDialog->addClip(id, path);
1797 int result = m_invalidClipDialog->exec();
1798 if (result == KDialog::Yes) replace = true;
1801 if (m_invalidClipDialog) {
1803 emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
1804 delete m_invalidClipDialog;
1805 m_invalidClipDialog = NULL;
1811 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1813 ProjectItem *item = getItemById(id);
1815 kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
1816 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1817 if (durationError) {
1818 kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1819 emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
1821 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
1822 QString path = item->referencedClip()->getProperty("proxy");
1823 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1825 //Security check: make sure the invalid proxy file is in the proxy folder
1826 if (proxyFolder.isParentOf(KUrl(path))) {
1827 QFile::remove(path);
1829 if (item->referencedClip()->getProducer() == NULL) {
1830 // Clip has no valid producer, request it
1831 slotProxyCurrentItem(false, item);
1834 // refresh thumbs producer
1835 item->referencedClip()->reloadThumbProducer();
1838 m_thumbnailQueue.removeAll(id);
1841 void ProjectList::slotAddColorClip()
1843 if (!m_commandStack)
1844 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1846 QPointer<QDialog> dia = new QDialog(this);
1847 Ui::ColorClip_UI dia_ui;
1848 dia_ui.setupUi(dia);
1849 dia->setWindowTitle(i18n("Color Clip"));
1850 dia_ui.clip_name->setText(i18n("Color Clip"));
1852 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1853 t->setValue(KdenliveSettings::color_duration());
1854 dia_ui.clip_durationBox->addWidget(t);
1855 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1857 if (dia->exec() == QDialog::Accepted) {
1858 QString color = dia_ui.clip_color->color().name();
1859 KdenliveSettings::setColorclipcolor(color);
1860 color = color.replace(0, 1, "0x") + "ff";
1861 QStringList groupInfo = getGroup();
1862 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1869 void ProjectList::slotAddSlideshowClip()
1871 if (!m_commandStack)
1872 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1874 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1876 if (dia->exec() == QDialog::Accepted) {
1877 QStringList groupInfo = getGroup();
1879 QMap <QString, QString> properties;
1880 properties.insert("name", dia->clipName());
1881 properties.insert("resource", dia->selectedPath());
1882 properties.insert("in", "0");
1883 properties.insert("out", QString::number(m_doc->getFramePos(dia->clipDuration()) * dia->imageCount()));
1884 properties.insert("ttl", QString::number(m_doc->getFramePos(dia->clipDuration())));
1885 properties.insert("loop", QString::number(dia->loop()));
1886 properties.insert("crop", QString::number(dia->crop()));
1887 properties.insert("fade", QString::number(dia->fade()));
1888 properties.insert("luma_duration", dia->lumaDuration());
1889 properties.insert("luma_file", dia->lumaFile());
1890 properties.insert("softness", QString::number(dia->softness()));
1891 properties.insert("animation", dia->animation());
1893 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
1898 void ProjectList::slotAddTitleClip()
1900 QStringList groupInfo = getGroup();
1901 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1904 void ProjectList::slotAddTitleTemplateClip()
1906 if (!m_commandStack)
1907 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1909 QStringList groupInfo = getGroup();
1911 // Get the list of existing templates
1913 filter << "*.kdenlivetitle";
1914 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1915 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1917 QPointer<QDialog> dia = new QDialog(this);
1918 Ui::TemplateClip_UI dia_ui;
1919 dia_ui.setupUi(dia);
1920 for (int i = 0; i < templateFiles.size(); ++i)
1921 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1923 if (!templateFiles.isEmpty())
1924 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1925 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1926 //warning: setting base directory doesn't work??
1927 KUrl startDir(path);
1928 dia_ui.template_list->fileDialog()->setUrl(startDir);
1929 dia_ui.text_box->setHidden(true);
1930 if (dia->exec() == QDialog::Accepted) {
1931 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1932 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1933 // Create a cloned template clip
1934 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1939 QStringList ProjectList::getGroup() const
1942 QTreeWidgetItem *item = m_listView->currentItem();
1943 while (item && item->type() != PROJECTFOLDERTYPE)
1944 item = item->parent();
1947 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1948 result << folder->groupName() << folder->clipId();
1950 result << QString() << QString();
1955 void ProjectList::setDocument(KdenliveDoc *doc)
1957 m_listView->blockSignals(true);
1958 m_abortAllJobs = true;
1959 for (int i = 0; i < m_jobList.count(); i++) {
1960 m_jobList.at(i)->setStatus(JOBABORTED);
1963 m_jobThreads.waitForFinished();
1964 m_jobThreads.clearFutures();
1965 m_thumbnailQueue.clear();
1966 m_listView->clear();
1968 m_listView->setSortingEnabled(false);
1969 emit clipSelected(NULL);
1970 m_refreshed = false;
1971 m_allClipsProcessed = false;
1973 m_timecode = doc->timecode();
1974 m_commandStack = doc->commandStack();
1976 m_abortAllJobs = false;
1979 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1980 QStringList openedFolders = doc->getExpandedFolders();
1981 QMapIterator<QString, QString> f(flist);
1982 while (f.hasNext()) {
1984 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1985 folder->setExpanded(openedFolders.contains(f.key()));
1988 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1989 if (list.isEmpty()) {
1992 m_allClipsProcessed = true;
1994 for (int i = 0; i < list.count(); i++)
1995 slotAddClip(list.at(i), false);
1997 m_listView->blockSignals(false);
1998 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1999 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
2000 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
2001 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
2002 connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
2005 QList <DocClipBase*> ProjectList::documentClipList() const
2008 return QList <DocClipBase*> ();
2010 return m_doc->clipManager()->documentClipList();
2013 QDomElement ProjectList::producersList()
2016 QDomElement prods = doc.createElement("producerlist");
2017 doc.appendChild(prods);
2018 QTreeWidgetItemIterator it(m_listView);
2020 if ((*it)->type() != PROJECTCLIPTYPE) {
2025 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
2031 void ProjectList::slotCheckForEmptyQueue()
2033 if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
2034 if (!m_refreshed && m_allClipsProcessed) {
2036 m_listView->setEnabled(true);
2038 QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
2039 emit displayMessage(QString(), -1);
2042 } else if (!m_refreshed) {
2043 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
2048 void ProjectList::requestClipThumbnail(const QString id)
2050 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
2051 slotProcessNextThumbnail();
2054 void ProjectList::resetThumbsProducer(DocClipBase *clip)
2057 clip->clearThumbProducer();
2058 QString id = clip->getId();
2059 m_thumbnailQueue.removeAll(id);
2062 void ProjectList::slotProcessNextThumbnail()
2064 if (m_render->processingItems() > 0) {
2067 if (m_thumbnailQueue.isEmpty()) {
2068 slotCheckForEmptyQueue();
2071 int max = m_doc->clipManager()->clipsCount();
2072 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
2073 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
2076 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
2078 QTreeWidgetItem *item = getAnyItemById(clipId);
2080 slotRefreshClipThumbnail(item, update);
2082 slotProcessNextThumbnail();
2086 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
2088 if (it == NULL) return;
2089 ProjectItem *item = NULL;
2090 bool isSubItem = false;
2092 if (it->type() == PROJECTFOLDERTYPE) return;
2093 if (it->type() == PROJECTSUBCLIPTYPE) {
2094 item = static_cast <ProjectItem *>(it->parent());
2095 frame = static_cast <SubProjectItem *>(it)->zone().x();
2098 item = static_cast <ProjectItem *>(it);
2099 frame = item->referencedClip()->getClipThumbFrame();
2103 DocClipBase *clip = item->referencedClip();
2105 slotProcessNextThumbnail();
2110 int height = m_listView->iconSize().height();
2111 int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
2112 int dwidth = (int)(height * m_render->dar() + 0.5);
2113 if (clip->clipType() == AUDIO)
2114 pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
2115 else if (clip->clipType() == IMAGE) {
2116 img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
2119 img = item->referencedClip()->extractImage(frame, dwidth, height);
2121 if (!pix.isNull() || !img.isNull()) {
2122 monitorItemEditing(false);
2123 if (!img.isNull()) {
2124 pix = QPixmap::fromImage(img);
2125 processThumbOverlays(item, pix);
2127 it->setData(0, Qt::DecorationRole, pix);
2128 monitorItemEditing(true);
2130 QString hash = item->getClipHash();
2131 if (!hash.isEmpty() && !img.isNull()) {
2133 m_doc->cacheImage(hash, img);
2135 m_doc->cacheImage(hash + '#' + QString::number(frame), img);
2139 emit projectModified();
2140 slotProcessNextThumbnail();
2145 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
2148 ProjectItem *item = getItemById(clipId);
2149 int queue = m_render->processingItems();
2150 if (item && producer) {
2151 monitorItemEditing(false);
2152 DocClipBase *clip = item->referencedClip();
2153 if (producer->is_valid()) {
2154 if (clip->isPlaceHolder()) {
2158 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
2160 item->setProperties(properties, metadata);
2161 clip->setProducer(producer, replace);
2164 QString size = properties.value("frame_size");
2165 if (!useProxy() && clip->getProperty("proxy").isEmpty()) {
2166 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2167 discardJobs(clipId, PROXYJOB);
2169 if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") {
2170 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2171 discardJobs(clipId, PROXYJOB);
2173 else if (useProxy() && !item->hasProxy() && !hasPendingJob(item, PROXYJOB)) {
2174 // proxy video and image clips
2176 CLIPTYPE t = item->clipType();
2177 if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2178 else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
2179 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)) {
2180 if (clip->getProperty("proxy").isEmpty()) {
2181 KUrl proxyPath = m_doc->projectFolder();
2182 proxyPath.addPath("proxy/");
2183 proxyPath.addPath(clip->getClipHash() + '.' + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
2184 QMap <QString, QString> newProps;
2185 // insert required duration for proxy
2186 if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
2187 newProps.insert("proxy", proxyPath.path());
2188 QMap <QString, QString> oldProps = clip->properties();
2189 oldProps.insert("proxy", QString());
2190 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
2191 m_doc->commandStack()->push(command);
2196 if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) {
2197 getCachedThumbnail(item);
2199 if (!toReload.isEmpty())
2200 item->slotSetToolTip();
2201 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
2203 monitorItemEditing(true);
2204 if (item && m_thumbnailQueue.isEmpty()) {
2205 if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
2206 m_listView->setCurrentItem(item);
2207 bool updatedProfile = false;
2208 if (item->parent()) {
2209 if (item->parent()->type() == PROJECTFOLDERTYPE)
2210 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
2211 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
2212 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
2213 updatedProfile = adjustProjectProfileToItem(item);
2215 if (updatedProfile == false) {
2216 //emit clipSelected(item->referencedClip());
2219 int max = m_doc->clipManager()->clipsCount();
2220 if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
2222 if (m_allClipsProcessed) emit processNextThumbnail();
2225 // no item for producer, delete it
2229 if (replace) toReload = clipId;
2230 if (!toReload.isEmpty())
2231 emit clipNeedsReload(toReload);
2234 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
2237 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
2238 item = static_cast <ProjectItem*>(m_listView->currentItem());
2240 if (item == NULL || item->referencedClip() == NULL) {
2241 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
2244 bool profileUpdated = false;
2245 QString size = item->referencedClip()->getProperty("frame_size");
2246 int width = size.section('x', 0, 0).toInt();
2247 int height = size.section('x', -1).toInt();
2248 // Fix some avchd clips tht report a wrong size (1920x1088)
2249 if (height == 1088) height = 1080;
2250 double fps = item->referencedClip()->getProperty("fps").toDouble();
2251 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
2252 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
2253 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
2254 // get a list of compatible profiles
2255 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
2256 if (!suggestedProfiles.isEmpty()) {
2257 KDialog *dialog = new KDialog(this);
2258 dialog->setCaption(i18n("Change project profile"));
2259 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2262 QVBoxLayout *l = new QVBoxLayout;
2263 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));
2264 l->addWidget(label);
2265 QListWidget *list = new QListWidget;
2266 list->setAlternatingRowColors(true);
2267 QMapIterator<QString, QString> i(suggestedProfiles);
2268 while (i.hasNext()) {
2270 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
2271 item->setData(Qt::UserRole, i.key());
2272 item->setToolTip(i.key());
2274 list->setCurrentRow(0);
2276 container.setLayout(l);
2277 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
2278 dialog->setMainWidget(&container);
2279 if (dialog->exec() == QDialog::Accepted) {
2280 //Change project profile
2281 profileUpdated = true;
2282 if (list->currentItem())
2283 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
2287 } else if (fps > 0) {
2288 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));
2292 return profileUpdated;
2295 QString ProjectList::getDocumentProperty(const QString &key) const
2297 return m_doc->getDocumentProperty(key);
2300 bool ProjectList::useProxy() const
2302 return m_doc->getDocumentProperty("enableproxy").toInt();
2305 bool ProjectList::generateProxy() const
2307 return m_doc->getDocumentProperty("generateproxy").toInt();
2310 bool ProjectList::generateImageProxy() const
2312 return m_doc->getDocumentProperty("generateimageproxy").toInt();
2315 void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
2317 ProjectItem *item = getItemById(clipId);
2318 if (item && !img.isNull()) {
2319 QPixmap pix = QPixmap::fromImage(img);
2320 processThumbOverlays(item, pix);
2321 monitorItemEditing(false);
2322 item->setData(0, Qt::DecorationRole, pix);
2323 monitorItemEditing(true);
2324 QString hash = item->getClipHash();
2325 if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
2329 void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
2331 // For clips that have a generic icon (like audio clips...)
2332 ProjectItem *item = getItemById(clipId);
2333 QPixmap pix = KIcon(name).pixmap(QSize(width, height));
2334 if (item && !pix.isNull()) {
2335 monitorItemEditing(false);
2336 item->setData(0, Qt::DecorationRole, pix);
2337 monitorItemEditing(true);
2341 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
2343 QTreeWidgetItemIterator it(m_listView);
2344 QString lookId = id;
2345 if (id.contains('#'))
2346 lookId = id.section('#', 0, 0);
2348 ProjectItem *result = NULL;
2350 if ((*it)->type() != PROJECTCLIPTYPE) {
2355 ProjectItem *item = static_cast<ProjectItem *>(*it);
2356 if (item->clipId() == lookId) {
2362 if (result == NULL || !id.contains('#')) {
2365 for (int i = 0; i < result->childCount(); i++) {
2366 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
2367 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
2376 ProjectItem *ProjectList::getItemById(const QString &id)
2379 QTreeWidgetItemIterator it(m_listView);
2381 if ((*it)->type() != PROJECTCLIPTYPE) {
2382 // subitem or folder
2386 item = static_cast<ProjectItem *>(*it);
2387 if (item->clipId() == id)
2394 FolderProjectItem *ProjectList::getFolderItemByName(const QString &name)
2396 FolderProjectItem *item = NULL;
2397 QList <QTreeWidgetItem *> hits = m_listView->findItems(name, Qt::MatchExactly, 0);
2398 for (int i = 0; i < hits.count(); i++) {
2399 if (hits.at(i)->type() == PROJECTFOLDERTYPE) {
2400 item = static_cast<FolderProjectItem *>(hits.at(i));
2407 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
2409 FolderProjectItem *item;
2410 QTreeWidgetItemIterator it(m_listView);
2412 if ((*it)->type() == PROJECTFOLDERTYPE) {
2413 item = static_cast<FolderProjectItem *>(*it);
2414 if (item->clipId() == id)
2422 void ProjectList::slotSelectClip(const QString &ix)
2424 ProjectItem *clip = getItemById(ix);
2426 m_listView->setCurrentItem(clip);
2427 m_listView->scrollToItem(clip);
2428 m_editButton->defaultAction()->setEnabled(true);
2429 m_deleteButton->defaultAction()->setEnabled(true);
2430 m_reloadAction->setEnabled(true);
2431 m_extractAudioAction->setEnabled(true);
2432 m_transcodeAction->setEnabled(true);
2433 m_stabilizeAction->setEnabled(true);
2434 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
2435 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
2436 m_openAction->setEnabled(true);
2437 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
2438 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
2439 m_openAction->setEnabled(true);
2441 m_openAction->setEnabled(false);
2446 QString ProjectList::currentClipUrl() const
2449 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
2450 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
2452 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
2454 item = static_cast <ProjectItem*>(m_listView->currentItem());
2458 return item->clipUrl().path();
2461 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
2465 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2466 for (int i = 0; i < list.count(); i++) {
2467 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2469 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2471 item = static_cast <ProjectItem*>(list.at(i)->parent());
2473 item = static_cast <ProjectItem*>(list.at(i));
2475 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2477 DocClipBase *clip = item->referencedClip();
2478 if (!condition.isEmpty()) {
2479 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2481 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2484 result.append(item->clipUrl());
2489 QStringList ProjectList::getConditionalIds(const QString &condition) const
2493 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2494 for (int i = 0; i < list.count(); i++) {
2495 if (list.at(i)->type() == PROJECTFOLDERTYPE)
2497 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
2499 item = static_cast <ProjectItem*>(list.at(i)->parent());
2501 item = static_cast <ProjectItem*>(list.at(i));
2503 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
2505 DocClipBase *clip = item->referencedClip();
2506 if (!condition.isEmpty()) {
2507 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
2509 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
2512 result.append(item->clipId());
2517 void ProjectList::regenerateTemplate(const QString &id)
2519 ProjectItem *clip = getItemById(id);
2521 regenerateTemplate(clip);
2524 void ProjectList::regenerateTemplate(ProjectItem *clip)
2526 //TODO: remove this unused method, only force_reload is necessary
2527 clip->referencedClip()->getProducer()->set("force_reload", 1);
2530 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
2534 if (!file.open(QIODevice::ReadOnly)) {
2535 kWarning() << "ERROR, CANNOT READ: " << path;
2538 if (!doc.setContent(&file)) {
2539 kWarning() << "ERROR, CANNOT READ: " << path;
2544 QDomNodeList texts = doc.elementsByTagName("content");
2545 for (int i = 0; i < texts.count(); i++) {
2546 QString data = texts.item(i).firstChild().nodeValue();
2547 data.replace("%s", replaceString);
2548 texts.item(i).firstChild().setNodeValue(data);
2554 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
2556 ProjectItem *clip = getItemById(id);
2557 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
2559 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
2560 m_commandStack->push(command);
2563 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
2565 ProjectItem *clip = getItemById(id);
2567 DocClipBase *base = clip->referencedClip();
2568 base->addCutZone(in, out);
2569 monitorItemEditing(false);
2570 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
2571 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
2572 if (!clip->isExpanded())
2573 clip->setExpanded(true);
2574 m_listView->scrollToItem(sub);
2575 m_listView->editItem(sub, 1);
2577 QImage img = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
2578 sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
2579 QString hash = clip->getClipHash();
2580 if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(in), img);
2581 monitorItemEditing(true);
2583 emit projectModified();
2586 void ProjectList::removeClipCut(const QString &id, int in, int out)
2588 ProjectItem *clip = getItemById(id);
2590 DocClipBase *base = clip->referencedClip();
2591 base->removeCutZone(in, out);
2592 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
2594 monitorItemEditing(false);
2596 monitorItemEditing(true);
2599 emit projectModified();
2602 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
2604 SubProjectItem *sub = NULL;
2606 for (int i = 0; i < clip->childCount(); i++) {
2607 QTreeWidgetItem *it = clip->child(i);
2608 if (it->type() == PROJECTSUBCLIPTYPE) {
2609 sub = static_cast <SubProjectItem*>(it);
2610 if (sub->zone() == zone)
2620 void ProjectList::slotUpdateClipCut(QPoint p)
2622 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2624 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2625 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2626 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2627 m_commandStack->push(command);
2630 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2632 ProjectItem *clip = getItemById(id);
2633 SubProjectItem *sub = getSubItem(clip, oldzone);
2634 if (sub == NULL || clip == NULL)
2636 DocClipBase *base = clip->referencedClip();
2637 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2638 monitorItemEditing(false);
2640 sub->setDescription(comment);
2641 monitorItemEditing(true);
2642 emit projectModified();
2645 void ProjectList::slotForceProcessing(const QString &id)
2647 m_render->forceProcessing(id);
2650 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2652 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2654 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2655 int count = list.count();
2657 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2658 if (!existing.isEmpty()) {
2659 // Sequence already exists, update
2660 QString id = existing.at(0)->getId();
2661 //ProjectItem *item = getItemById(id);
2662 QMap <QString, QString> oldprops;
2663 QMap <QString, QString> newprops;
2664 int ttl = existing.at(0)->getProperty("ttl").toInt();
2665 oldprops["out"] = existing.at(0)->getProperty("out");
2666 newprops["out"] = QString::number(ttl * count - 1);
2667 slotUpdateClipProperties(id, newprops);
2668 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2669 m_commandStack->push(command);
2672 QStringList groupInfo = getGroup();
2673 QMap <QString, QString> properties;
2674 properties.insert("name", fileName);
2675 properties.insert("resource", pattern);
2676 properties.insert("in", "0");
2677 QString duration = m_timecode.reformatSeparators(KdenliveSettings::sequence_duration());
2678 properties.insert("out", QString::number(m_doc->getFramePos(duration) * count));
2679 properties.insert("ttl", QString::number(m_doc->getFramePos(duration)));
2680 properties.insert("loop", QString::number(false));
2681 properties.insert("crop", QString::number(false));
2682 properties.insert("fade", QString::number(false));
2683 properties.insert("luma_duration", m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))));
2685 m_doc->slotCreateSlideshowClipFile(properties, groupInfo.at(0), groupInfo.at(1));
2687 } else emit displayMessage(i18n("Sequence not found"), -2);
2690 QMap <QString, QString> ProjectList::getProxies()
2692 QMap <QString, QString> list;
2694 QTreeWidgetItemIterator it(m_listView);
2696 if ((*it)->type() != PROJECTCLIPTYPE) {
2700 item = static_cast<ProjectItem *>(*it);
2701 if (item && item->referencedClip() != NULL) {
2702 if (item->hasProxy()) {
2703 QString proxy = item->referencedClip()->getProperty("proxy");
2704 list.insert(proxy, item->clipUrl().path());
2712 void ProjectList::slotCreateProxy(const QString id)
2714 ProjectItem *item = getItemById(id);
2715 if (!item || hasPendingJob(item, PROXYJOB) || item->referencedClip()->isPlaceHolder()) return;
2716 QString path = item->referencedClip()->getProperty("proxy");
2717 if (path.isEmpty()) {
2718 slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy, empty path."));
2722 if (QFileInfo(path).size() > 0) {
2723 // Proxy already created
2724 setJobStatus(item, PROXYJOB, JOBDONE);
2728 QString sourcePath = item->clipUrl().path();
2729 if (item->clipType() == PLAYLIST) {
2730 // Special case: playlists use the special 'consumer' producer to support resizing
2731 sourcePath.prepend("consumer:");
2733 ProxyJob *job = new ProxyJob(item->clipType(), id, QStringList() << path << sourcePath << item->referencedClip()->producerProperty("_exif_orientation") << m_doc->getDocumentProperty("proxyparams").simplified() << QString::number(m_render->frameRenderWidth()) << QString::number(m_render->renderHeight()));
2734 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2739 m_jobList.append(job);
2740 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2741 slotCheckJobProcess();
2744 void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
2746 ProjectItem *item = getItemById(id);
2747 if (!item|| item->referencedClip()->isPlaceHolder()) return;
2748 QString source = item->clipUrl().path();
2749 QString ext = source.section('.', -1);
2750 QString dest = source.section('.', 0, -2) + '_' + QString::number(zone.x()) + '.' + ext;
2752 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2753 if (clipFps == 0) clipFps = m_fps;
2754 // if clip and project have different frame rate, adjust in and out
2757 in = GenTime(in, m_timecode.fps()).frames(clipFps);
2758 out = GenTime(out, m_timecode.fps()).frames(clipFps);
2759 int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
2760 int duration = out - in + 1;
2761 QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
2762 QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
2764 QPointer<QDialog> d = new QDialog(this);
2765 Ui::CutJobDialog_UI ui;
2767 ui.extra_params->setVisible(false);
2768 ui.add_clip->setChecked(KdenliveSettings::add_new_clip());
2769 ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
2770 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2771 ui.file_url->setUrl(KUrl(dest));
2772 ui.button_more->setIcon(KIcon("configure"));
2773 ui.extra_params->setPlainText("-acodec copy -vcodec copy");
2774 QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
2775 ui.info_label->setText(mess);
2776 if (d->exec() != QDialog::Accepted) {
2780 dest = ui.file_url->url().path();
2781 bool acceptPath = dest != source;
2782 if (acceptPath && QFileInfo(dest).size() > 0) {
2783 // destination file olready exists, overwrite?
2786 while (!acceptPath) {
2787 // Do not allow to save over original clip
2788 if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
2789 else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
2790 if (d->exec() != QDialog::Accepted) {
2794 dest = ui.file_url->url().path();
2795 acceptPath = dest != source;
2796 if (acceptPath && QFileInfo(dest).size() > 0) {
2800 QString extraParams = ui.extra_params->toPlainText().simplified();
2801 KdenliveSettings::setAdd_new_clip(ui.add_clip->isChecked());
2804 QStringList jobParams;
2805 jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_new_clip());
2806 if (!extraParams.isEmpty()) jobParams << extraParams;
2807 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2808 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2812 m_jobList.append(job);
2813 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2815 slotCheckJobProcess();
2818 void ProjectList::slotTranscodeClipJob(const QString &condition, QString params, QString desc)
2820 QStringList existingFiles;
2821 QStringList ids = getConditionalIds(condition);
2822 QStringList destinations;
2823 foreach(const QString &id, ids) {
2824 ProjectItem *item = getItemById(id);
2825 if (!item) continue;
2826 QString newFile = params.section(' ', -1).replace("%1", item->clipUrl().path());
2827 destinations << newFile;
2828 if (QFile::exists(newFile)) existingFiles << newFile;
2830 if (!existingFiles.isEmpty()) {
2831 if (KMessageBox::warningContinueCancelList(this, i18n("The transcoding job will overwrite the following files:"), existingFiles) == KMessageBox::Cancel) return;
2834 QDialog *d = new QDialog(this);
2835 Ui::CutJobDialog_UI ui;
2837 d->setWindowTitle(i18n("Transcoding"));
2838 ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
2839 if (ids.count() == 1) {
2840 ui.file_url->setUrl(KUrl(destinations.first()));
2843 ui.destination_label->setVisible(false);
2844 ui.file_url->setVisible(false);
2846 ui.extra_params->setVisible(false);
2848 ui.button_more->setIcon(KIcon("configure"));
2849 ui.add_clip->setChecked(KdenliveSettings::add_new_clip());
2850 ui.extra_params->setPlainText(params.simplified().section(' ', 0, -2));
2851 QString mess = desc;
2852 mess.append(' ' + i18np("(%1 clip)", "(%1 clips)", ids.count()));
2853 ui.info_label->setText(mess);
2854 if (d->exec() != QDialog::Accepted) {
2858 params = ui.extra_params->toPlainText().simplified();
2859 KdenliveSettings::setAdd_new_clip(ui.add_clip->isChecked());
2861 foreach(const QString &id, ids) {
2862 ProjectItem *item = getItemById(id);
2863 if (!item || !item->referencedClip()) continue;
2864 QString src = item->clipUrl().path();
2866 if (ids.count() > 1) {
2867 dest = destinations.at(index);
2870 else dest = ui.file_url->url().path();
2871 QStringList jobParams;
2872 jobParams << dest << src << QString() << QString();
2873 double clipFps = item->referencedClip()->getProperty("fps").toDouble();
2874 if (clipFps == 0) clipFps = m_fps;
2875 int max = item->clipMaxDuration();
2876 QString duration = QString::number(max);
2877 jobParams << duration;
2878 jobParams << QString::number(KdenliveSettings::add_new_clip());
2879 jobParams << params;
2880 CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
2881 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
2885 m_jobList.append(job);
2886 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
2889 slotCheckJobProcess();
2893 void ProjectList::slotCheckJobProcess()
2895 if (!m_jobThreads.futures().isEmpty()) {
2896 // Remove inactive threads
2897 QList <QFuture<void> > futures = m_jobThreads.futures();
2898 m_jobThreads.clearFutures();
2899 for (int i = 0; i < futures.count(); i++)
2900 if (!futures.at(i).isFinished()) {
2901 m_jobThreads.addFuture(futures.at(i));
2904 if (m_jobList.isEmpty()) return;
2907 for (int i = 0; i < m_jobList.count(); i++) {
2908 if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING)
2911 // remove finished jobs
2912 AbstractClipJob *job = m_jobList.takeAt(i);
2918 emit jobCount(count);
2919 m_jobMutex.unlock();
2921 if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
2924 void ProjectList::slotAbortProxy(const QString id, const QString path)
2928 ProjectItem *item = getItemById(id);
2930 if (!item->isProxyRunning()) slotGotProxy(item);
2931 item->setConditionalJobStatus(NOJOB, PROXYJOB);
2932 discardJobs(id, PROXYJOB);
2935 void ProjectList::slotProcessJobs()
2937 while (!m_jobList.isEmpty() && !m_abortAllJobs) {
2938 emit projectModified();
2939 AbstractClipJob *job = NULL;
2942 for (int i = 0; i < m_jobList.count(); i++) {
2943 if (m_jobList.at(i)->jobStatus == JOBWAITING) {
2945 m_jobList.at(i)->jobStatus = JOBWORKING;
2946 job = m_jobList.at(i);
2950 else if (m_jobList.at(i)->jobStatus == JOBWORKING)
2954 emit jobCount(count);
2955 m_jobMutex.unlock();
2960 QString destination = job->destination();
2961 // Check if the clip is still here
2962 DocClipBase *currentClip = m_doc->clipManager()->getClipById(job->clipId());
2963 //ProjectItem *processingItem = getItemById(job->clipId());
2964 if (currentClip == NULL) {
2965 job->setStatus(JOBDONE);
2968 // Set clip status to started
2969 emit processLog(job->clipId(), 0, job->jobType, job->statusMessage());
2971 // Make sure destination path is writable
2972 if (!destination.isEmpty()) {
2973 QFile file(destination);
2974 if (!file.open(QIODevice::WriteOnly)) {
2975 emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Cannot write to path: %1", destination));
2976 job->setStatus(JOBCRASHED);
2980 QFile::remove(destination);
2982 connect(job, SIGNAL(jobProgress(QString, int, int)), this, SIGNAL(processLog(QString, int, int)));
2983 connect(job, SIGNAL(cancelRunningJob(const QString, stringMap)), this, SIGNAL(cancelRunningJob(const QString, stringMap)));
2984 connect(job, SIGNAL(gotFilterJobResults(QString,int, int, QString,stringMap)), this, SIGNAL(gotFilterJobResults(QString,int, int, QString,stringMap)));
2986 if (job->jobType == MLTJOB) {
2987 MeltJob *jb = static_cast<MeltJob *> (job);
2988 jb->setProducer(currentClip->getProducer(), currentClip->fileURL());
2991 if (job->jobStatus == JOBDONE) {
2992 emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
2993 //TODO: replace with more generic clip replacement framework
2994 if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
2995 if (job->addClipToProject()) {
2996 emit addClip(destination, QString(), QString());
2998 } else if (job->jobStatus == JOBCRASHED || job->jobStatus == JOBABORTED) {
2999 emit updateJobStatus(job->clipId(), job->jobType, job->jobStatus, job->errorMessage(), QString(), job->logDetails());
3002 // Thread finished, cleanup & update count
3003 QTimer::singleShot(200, this, SIGNAL(checkJobProcess()));
3007 void ProjectList::updateProxyConfig()
3010 QTreeWidgetItemIterator it(m_listView);
3011 QUndoCommand *command = new QUndoCommand();
3012 command->setText(i18n("Update proxy settings"));
3013 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3015 if ((*it)->type() != PROJECTCLIPTYPE) {
3019 item = static_cast<ProjectItem *>(*it);
3024 CLIPTYPE t = item->clipType();
3025 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
3026 if (generateProxy() && useProxy() && !hasPendingJob(item, PROXYJOB)) {
3027 DocClipBase *clip = item->referencedClip();
3028 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
3029 if (clip->getProperty("proxy").isEmpty()) {
3030 // We need to insert empty proxy in old properties so that undo will work
3031 QMap <QString, QString> oldProps;// = clip->properties();
3032 oldProps.insert("proxy", QString());
3033 QMap <QString, QString> newProps;
3034 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + '.' + m_doc->getDocumentProperty("proxyextension"));
3035 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3039 else if (item->hasProxy()) {
3041 QMap <QString, QString> newProps;
3042 newProps.insert("proxy", QString());
3043 // insert required duration for proxy
3044 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
3045 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
3048 else if (t == IMAGE && item->referencedClip() != NULL) {
3049 if (generateImageProxy() && useProxy()) {
3050 DocClipBase *clip = item->referencedClip();
3051 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
3052 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
3053 if (clip->getProperty("proxy").isEmpty()) {
3054 // We need to insert empty proxy in old properties so that undo will work
3055 QMap <QString, QString> oldProps = clip->properties();
3056 oldProps.insert("proxy", QString());
3057 QMap <QString, QString> newProps;
3058 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
3059 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
3063 else if (item->hasProxy()) {
3065 QMap <QString, QString> newProps;
3066 newProps.insert("proxy", QString());
3067 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
3072 if (command->childCount() > 0) m_doc->commandStack()->push(command);
3073 else delete command;
3076 void ProjectList::slotProcessLog(const QString id, int progress, int type, const QString message)
3078 ProjectItem *item = getItemById(id);
3079 setJobStatus(item, (JOBTYPE) type, JOBWORKING, progress, message);
3082 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
3084 QList<QTreeWidgetItem *> list;
3085 if (itemToProxy == NULL) list = m_listView->selectedItems();
3086 else list << itemToProxy;
3088 // expand list (folders, subclips) to get real clips
3089 QTreeWidgetItem *listItem;
3090 QList<ProjectItem *> clipList;
3091 for (int i = 0; i < list.count(); i++) {
3092 listItem = list.at(i);
3093 if (listItem->type() == PROJECTFOLDERTYPE) {
3094 for (int j = 0; j < listItem->childCount(); j++) {
3095 QTreeWidgetItem *sub = listItem->child(j);
3096 if (sub->type() == PROJECTCLIPTYPE) {
3097 ProjectItem *item = static_cast <ProjectItem*>(sub);
3098 if (!clipList.contains(item)) clipList.append(item);
3102 else if (listItem->type() == PROJECTSUBCLIPTYPE) {
3103 QTreeWidgetItem *sub = listItem->parent();
3104 ProjectItem *item = static_cast <ProjectItem*>(sub);
3105 if (!clipList.contains(item)) clipList.append(item);
3107 else if (listItem->type() == PROJECTCLIPTYPE) {
3108 ProjectItem *item = static_cast <ProjectItem*>(listItem);
3109 if (!clipList.contains(item)) clipList.append(item);
3113 QUndoCommand *command = new QUndoCommand();
3114 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
3115 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
3117 // Make sure the proxy folder exists
3118 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
3119 KStandardDirs::makeDir(proxydir);
3121 QMap <QString, QString> newProps;
3122 QMap <QString, QString> oldProps;
3123 if (!doProxy) newProps.insert("proxy", "-");
3124 for (int i = 0; i < clipList.count(); i++) {
3125 ProjectItem *item = clipList.at(i);
3126 CLIPTYPE t = item->clipType();
3127 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
3128 if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
3129 DocClipBase *clip = item->referencedClip();
3130 if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
3131 kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
3135 //oldProps = clip->properties();
3138 QString path = proxydir + clip->getClipHash() + '.' + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
3139 // insert required duration for proxy
3140 newProps.insert("proxy_out", clip->producerProperty("out"));
3141 newProps.insert("proxy", path);
3142 // We need to insert empty proxy so that undo will work
3143 //oldProps.insert("proxy", QString());
3145 else if (item->referencedClip()->getProducer() == NULL) {
3146 // Force clip reload
3147 kDebug()<<"// CLIP HAD NULL PROD------------";
3148 newProps.insert("resource", item->referencedClip()->getProperty("resource"));
3150 // We need to insert empty proxy so that undo will work
3151 oldProps = clip->currentProperties(newProps);
3152 if (doProxy) oldProps.insert("proxy", "-");
3153 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
3156 if (command->childCount() > 0) {
3157 m_doc->commandStack()->push(command);
3159 else delete command;
3163 void ProjectList::slotDeleteProxy(const QString proxyPath)
3165 if (proxyPath.isEmpty()) return;
3166 QUndoCommand *proxyCommand = new QUndoCommand();
3167 proxyCommand->setText(i18n("Remove Proxy"));
3168 QTreeWidgetItemIterator it(m_listView);
3171 if ((*it)->type() == PROJECTCLIPTYPE) {
3172 item = static_cast <ProjectItem *>(*it);
3173 if (item->referencedClip()->getProperty("proxy") == proxyPath) {
3174 QMap <QString, QString> props;
3175 props.insert("proxy", QString());
3176 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
3182 if (proxyCommand->childCount() == 0)
3183 delete proxyCommand;
3185 m_commandStack->push(proxyCommand);
3186 QFile::remove(proxyPath);
3189 void ProjectList::setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress, const QString &statusMessage)
3191 if (item == NULL || (m_abortAllJobs && m_closing)) return;
3192 monitorItemEditing(false);
3193 item->setJobStatus(jobType, status, progress, statusMessage);
3194 if (status == JOBCRASHED) {
3195 DocClipBase *clip = item->referencedClip();
3197 kDebug()<<"// PROXY CRASHED";
3199 else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
3200 // disable proxy and fetch real clip
3201 clip->setProperty("proxy", "-");
3202 QDomElement xml = clip->toXML();
3203 m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
3206 // Disable proxy for this clip
3207 clip->setProperty("proxy", "-");
3210 monitorItemEditing(true);
3213 void ProjectList::monitorItemEditing(bool enable)
3215 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3216 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
3219 QStringList ProjectList::expandedFolders() const
3222 FolderProjectItem *item;
3223 QTreeWidgetItemIterator it(m_listView);
3225 if ((*it)->type() != PROJECTFOLDERTYPE) {
3229 if ((*it)->isExpanded()) {
3230 item = static_cast<FolderProjectItem *>(*it);
3231 result.append(item->clipId());
3238 void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
3240 if (item->hasProxy()) {
3242 QColor c(220, 220, 10, 200);
3243 QRect r(0, 0, 12, 12);
3245 QFont font = p.font();
3248 p.setPen(Qt::black);
3249 p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
3253 void ProjectList::slotCancelJobs()
3255 m_abortAllJobs = true;
3256 for (int i = 0; i < m_jobList.count(); i++) {
3257 m_jobList.at(i)->setStatus(JOBABORTED);
3259 m_jobThreads.waitForFinished();
3260 m_jobThreads.clearFutures();
3261 QUndoCommand *command = new QUndoCommand();
3262 command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
3264 for (int i = 0; i < m_jobList.count(); i++) {
3265 DocClipBase *currentClip = m_doc->clipManager()->getClipById(m_jobList.at(i)->clipId());
3266 if (!currentClip) continue;
3267 QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
3268 if (newProps.isEmpty()) continue;
3269 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3270 new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command);
3272 m_jobMutex.unlock();
3273 if (command->childCount() > 0) {
3274 m_doc->commandStack()->push(command);
3276 else delete command;
3277 if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
3279 m_abortAllJobs = false;
3280 m_infoLabel->slotSetJobCount(0);
3283 void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
3285 if (newProps.isEmpty() || m_closing) return;
3286 DocClipBase *currentClip = m_doc->clipManager()->getClipById(id);
3287 if (!currentClip) return;
3288 QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
3289 if (newProps == oldProps) return;
3290 QMapIterator<QString, QString> i(oldProps);
3291 EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
3292 m_commandStack->push(command);
3295 bool ProjectList::hasPendingJob(ProjectItem *item, JOBTYPE type)
3297 if (!item || !item->referencedClip() || m_abortAllJobs) return false;
3298 AbstractClipJob *job;
3299 QMutexLocker lock(&m_jobMutex);
3300 for (int i = 0; i < m_jobList.count(); i++) {
3301 if (m_abortAllJobs) break;
3302 job = m_jobList.at(i);
3303 if (job->clipId() == item->clipId() && job->jobType == type && (job->jobStatus == JOBWAITING || job->jobStatus == JOBWORKING)) return true;
3309 void ProjectList::deleteJobsForClip(const QString &clipId)
3311 QMutexLocker lock(&m_jobMutex);
3312 for (int i = 0; i < m_jobList.count(); i++) {
3313 if (m_jobList.at(i)->clipId() == clipId) {
3314 m_jobList.at(i)->setStatus(JOBABORTED);
3319 void ProjectList::slotUpdateJobStatus(const QString id, int type, int status, const QString label, const QString actionName, const QString details)
3321 ProjectItem *item = getItemById(id);
3323 slotUpdateJobStatus(item, type, status, label, actionName, details);
3327 void ProjectList::slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName, const QString details)
3329 item->setJobStatus((JOBTYPE) type, (CLIPJOBSTATUS) status);
3330 if (status != JOBCRASHED) return;
3331 #if KDE_IS_VERSION(4,7,0)
3332 QList<QAction *> actions = m_infoMessage->actions();
3333 if (m_infoMessage->isHidden()) {
3334 m_infoMessage->setText(label);
3335 m_infoMessage->setWordWrap(m_infoMessage->text().length() > 35);
3336 m_infoMessage->setMessageType(KMessageWidget::Warning);
3339 if (!actionName.isEmpty()) {
3340 QAction *action = NULL;
3341 QList< KActionCollection * > collections = KActionCollection::allCollections();
3342 for (int i = 0; i < collections.count(); i++) {
3343 KActionCollection *coll = collections.at(i);
3344 action = coll->action(actionName);
3347 if (action && !actions.contains(action)) m_infoMessage->addAction(action);
3349 if (!details.isEmpty()) {
3350 m_errorLog.append(details);
3351 if (!actions.contains(m_logAction)) m_infoMessage->addAction(m_logAction);
3353 m_infoMessage->animatedShow();
3355 // warning for KDE < 4.7
3356 KPassivePopup *passivePop = new KPassivePopup( this );
3357 passivePop->setAutoDelete(true);
3358 connect(passivePop, SIGNAL(clicked()), this, SLOT(slotClosePopup()));
3359 m_errorLog.append(details);
3360 KVBox *vb = new KVBox( passivePop );
3361 KHBox *vh1 = new KHBox( vb );
3362 KIcon icon("dialog-warning");
3363 QLabel *iconLabel = new QLabel(vh1);
3364 iconLabel->setPixmap(icon.pixmap(m_listView->iconSize()));
3365 (void) new QLabel( label, vh1);
3366 KHBox *box = new KHBox( vb );
3367 QPushButton *but = new QPushButton( "Show log", box );
3368 connect(but, SIGNAL(clicked(bool)), this, SLOT(slotShowJobLog()));
3370 passivePop->setView( vb );
3376 void ProjectList::slotShowJobLog()
3379 d.setButtons(KDialog::Close);
3381 for (int i = 0; i < m_errorLog.count(); i++) {
3382 if (i > 0) t.insertHtml("<br><hr /><br>");
3383 t.insertPlainText(m_errorLog.at(i));
3385 t.setReadOnly(true);
3386 d.setMainWidget(&t);
3390 QStringList ProjectList::getPendingJobs(const QString &id)
3393 QMutexLocker lock(&m_jobMutex);
3394 for (int i = 0; i < m_jobList.count(); i++) {
3395 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobStatus == JOBWAITING || m_jobList.at(i)->jobStatus == JOBWORKING)) {
3397 result << m_jobList.at(i)->description;
3403 void ProjectList::discardJobs(const QString &id, JOBTYPE type) {
3404 QMutexLocker lock(&m_jobMutex);
3405 for (int i = 0; i < m_jobList.count(); i++) {
3406 if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobType == type || type == NOJOBTYPE)) {
3408 m_jobList.at(i)->setStatus(JOBABORTED);
3413 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)
3415 ProjectItem *item = getItemById(id);
3417 QStringList jobParams;
3418 jobParams << QString::number(info.cropStart.frames(m_fps)) << QString::number((info.cropStart + info.cropDuration).frames(m_fps));
3419 jobParams << QString() << filterName << filterParams << consumer << consumerParams << properties << QString::number(info.startPos.frames(m_fps)) << QString::number(info.track) << finalFilterName;
3420 MeltJob *job = new MeltJob(item->clipType(), id, jobParams);
3421 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3425 job->description = i18n("Filter %1", finalFilterName);
3426 m_jobList.append(job);
3427 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3428 slotCheckJobProcess();
3431 void ProjectList::startClipFilterJob(const QString &filterName, const QString &condition)
3433 QStringList ids = getConditionalIds(condition);
3434 QString destination;
3435 ProjectItem *item = getItemById(ids.at(0));
3437 emit displayMessage(i18n("Cannot find clip to process filter %1", filterName), -2);
3440 if (ids.count() == 1) {
3441 destination = item->clipUrl().path();
3444 destination = item->clipUrl().directory();
3446 QPointer<ClipStabilize> d = new ClipStabilize(destination, ids.count(), filterName);
3447 if (d->exec() == QDialog::Accepted) {
3448 processClipJob(ids, d->destination(), d->autoAddClip(), d->params(), d->desc());
3453 void ProjectList::processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description)
3455 QStringList preParams;
3457 preParams << QString::number(0) << QString::number(-1);
3459 preParams << jobParams.takeFirst();
3461 preParams << jobParams.takeFirst();
3463 preParams << jobParams.takeFirst();
3465 QString consumer = jobParams.takeFirst();
3467 foreach(const QString&id, ids) {
3468 ProjectItem *item = getItemById(id);
3469 if (!item) continue;
3470 QStringList jobArgs;
3471 jobArgs << preParams;
3472 if (ids.count() == 1) {
3473 jobArgs << consumer + ':' + destination;
3476 jobArgs << consumer + ':' + destination + item->clipUrl().fileName() + ".mlt";
3478 jobArgs << jobParams;
3480 MeltJob *job = new MeltJob(item->clipType(), id, jobArgs);
3482 job->setAddClipToProject(true);
3483 kDebug()<<"// ADDING TRUE";
3485 else kDebug()<<"// ADDING FALSE!!!";
3486 if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
3490 job->description = description;
3491 m_jobList.append(job);
3492 setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
3494 slotCheckJobProcess();
3497 void ProjectList::slotPrepareJobsMenu()
3500 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
3502 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
3503 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
3505 item = static_cast <ProjectItem*>(m_listView->currentItem());
3506 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
3507 QString id = item->clipId();
3508 m_discardCurrentClipJobs->setData(id);
3509 QStringList jobs = getPendingJobs(id);
3510 m_discardCurrentClipJobs->setEnabled(!jobs.isEmpty());
3512 m_discardCurrentClipJobs->setData(QString());
3513 m_discardCurrentClipJobs->setEnabled(false);
3517 void ProjectList::slotDiscardClipJobs()
3519 QString id = m_discardCurrentClipJobs->data().toString();
3520 if (id.isEmpty()) return;
3524 void ProjectList::updatePalette()
3526 m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(QApplication::palette()));
3527 m_listView->updateStyleSheet();
3530 void ProjectList::slotResetInfoMessage()
3532 #if KDE_IS_VERSION(4,7,0)
3534 QList<QAction *> actions = m_infoMessage->actions();
3535 for (int i = 0; i < actions.count(); i++) {
3536 m_infoMessage->removeAction(actions.at(i));
3541 void ProjectList::slotClosePopup()
3546 #include "projectlist.moc"