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 "addfoldercommand.h"
23 #include "kdenlivesettings.h"
24 #include "slideshowclip.h"
25 #include "ui_colorclip_ui.h"
26 #include "titlewidget.h"
27 #include "definitions.h"
28 #include "clipmanager.h"
29 #include "docclipbase.h"
30 #include "kdenlivedoc.h"
33 #include "projectlistview.h"
34 #include "timecodedisplay.h"
35 #include "profilesdialog.h"
36 #include "editclipcommand.h"
37 #include "editclipcutcommand.h"
38 #include "editfoldercommand.h"
39 #include "addclipcutcommand.h"
41 #include "ui_templateclip_ui.h"
46 #include <KFileDialog>
47 #include <KInputDialog>
48 #include <KMessageBox>
49 #include <KIO/NetAccess>
51 #include <KApplication>
52 #include <KStandardDirs>
55 #include <nepomuk/global.h>
56 #include <nepomuk/resourcemanager.h>
57 //#include <nepomuk/tag.h>
60 #include <QMouseEvent>
61 #include <QStylePainter>
66 #include <QHeaderView>
67 #include <QInputDialog>
68 #include <QtConcurrentRun>
70 ProjectList::ProjectList(QWidget *parent) :
77 m_transcodeAction(NULL),
83 QVBoxLayout *layout = new QVBoxLayout;
84 layout->setContentsMargins(0, 0, 0, 0);
85 layout->setSpacing(0);
86 qRegisterMetaType<QDomElement>("QDomElement");
88 QFrame *frame = new QFrame;
89 frame->setFrameStyle(QFrame::NoFrame);
90 QHBoxLayout *box = new QHBoxLayout;
91 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
93 box->addWidget(searchView);
94 //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
95 //m_toolbar->setIconSize(QSize(s, s));
97 m_addButton = new QToolButton;
98 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
99 m_addButton->setAutoRaise(true);
100 box->addWidget(m_addButton);
102 m_editButton = new QToolButton;
103 m_editButton->setAutoRaise(true);
104 box->addWidget(m_editButton);
106 m_deleteButton = new QToolButton;
107 m_deleteButton->setAutoRaise(true);
108 box->addWidget(m_deleteButton);
109 frame->setLayout(box);
110 layout->addWidget(frame);
112 m_listView = new ProjectListView;
113 layout->addWidget(m_listView);
115 searchView->setTreeWidget(m_listView);
117 m_proxyAction = new QAction(i18n("Proxy clip"), this);
118 m_proxyAction->setCheckable(true);
119 m_proxyAction->setChecked(false);
120 connect(m_proxyAction, SIGNAL(toggled(bool)), this, SLOT(slotProxyCurrentItem(bool)));
121 connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
122 connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
123 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
124 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
125 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
126 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
127 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
128 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
129 connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
130 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
131 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
133 m_listViewDelegate = new ItemDelegate(m_listView);
134 m_listView->setItemDelegate(m_listViewDelegate);
136 if (KdenliveSettings::activate_nepomuk()) {
137 Nepomuk::ResourceManager::instance()->init();
138 if (!Nepomuk::ResourceManager::instance()->initialized()) {
139 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
140 KdenliveSettings::setActivate_nepomuk(false);
146 ProjectList::~ProjectList()
149 m_listView->blockSignals(true);
151 delete m_listViewDelegate;
154 void ProjectList::focusTree() const
156 m_listView->setFocus();
159 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
161 QList <QAction *> actions = addMenu->actions();
162 for (int i = 0; i < actions.count(); i++) {
163 if (actions.at(i)->data().toString() == "clip_properties") {
164 m_editButton->setDefaultAction(actions.at(i));
167 } else if (actions.at(i)->data().toString() == "delete_clip") {
168 m_deleteButton->setDefaultAction(actions.at(i));
171 } else if (actions.at(i)->data().toString() == "edit_clip") {
172 m_openAction = actions.at(i);
175 } else if (actions.at(i)->data().toString() == "reload_clip") {
176 m_reloadAction = actions.at(i);
182 QMenu *m = new QMenu();
183 m->addActions(actions);
184 m_addButton->setMenu(m);
185 m_addButton->setDefaultAction(defaultAction);
186 m_menu = new QMenu();
187 m_menu->addActions(addMenu->actions());
190 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
194 QMenu *menu = m_addButton->menu();
195 menu->addMenu(addMenu);
196 m_addButton->setMenu(menu);
198 m_menu->addMenu(addMenu);
199 if (addMenu->isEmpty())
200 addMenu->setEnabled(false);
201 m_menu->addMenu(transcodeMenu);
202 if (transcodeMenu->isEmpty())
203 transcodeMenu->setEnabled(false);
204 m_transcodeAction = transcodeMenu;
205 m_menu->addAction(m_reloadAction);
206 m_menu->addAction(m_proxyAction);
207 m_menu->addMenu(inTimelineMenu);
208 inTimelineMenu->setEnabled(false);
209 m_menu->addAction(m_editButton->defaultAction());
210 m_menu->addAction(m_openAction);
211 m_menu->addAction(m_deleteButton->defaultAction());
212 m_menu->insertSeparator(m_deleteButton->defaultAction());
216 QByteArray ProjectList::headerInfo() const
218 return m_listView->header()->saveState();
221 void ProjectList::setHeaderInfo(const QByteArray &state)
223 m_listView->header()->restoreState(state);
226 void ProjectList::updateProjectFormat(Timecode t)
231 void ProjectList::slotEditClip()
233 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
234 if (list.isEmpty()) return;
235 if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) {
236 editClipSelection(list);
240 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
242 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
243 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
245 item = static_cast <ProjectItem*>(m_listView->currentItem());
246 if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
247 emit clipSelected(item->referencedClip());
248 emit showClipProperties(item->referencedClip());
252 void ProjectList::editClipSelection(QList<QTreeWidgetItem *> list)
254 // Gather all common properties
255 QMap <QString, QString> commonproperties;
256 QList <DocClipBase *> clipList;
257 commonproperties.insert("force_aspect_num", "-");
258 commonproperties.insert("force_aspect_den", "-");
259 commonproperties.insert("force_fps", "-");
260 commonproperties.insert("force_progressive", "-");
261 commonproperties.insert("force_tff", "-");
262 commonproperties.insert("threads", "-");
263 commonproperties.insert("video_index", "-");
264 commonproperties.insert("audio_index", "-");
265 commonproperties.insert("force_colorspace", "-");
266 commonproperties.insert("full_luma", "-");
267 QString transparency = "-";
269 bool allowDurationChange = true;
270 int commonDuration = -1;
271 bool hasImages = false;;
273 for (int i = 0; i < list.count(); i++) {
275 if (list.at(i)->type() == PROJECTFOLDERTYPE) {
276 // Add folder items to the list
277 int ct = list.at(i)->childCount();
278 for (int j = 0; j < ct; j++) {
279 list.append(list.at(i)->child(j));
283 else if (list.at(i)->type() == PROJECTSUBCLIPTYPE)
284 item = static_cast <ProjectItem*>(list.at(i)->parent());
286 item = static_cast <ProjectItem*>(list.at(i));
287 if (!(item->flags() & Qt::ItemIsDragEnabled))
291 DocClipBase *clip = item->referencedClip();
292 if (clipList.contains(clip)) continue;
293 if (clip->clipType() == IMAGE) {
295 if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
296 if (transparency == "-") {
297 // first non transparent image
300 else if (transparency == "1") {
301 // we have transparent and non transparent clips
306 if (transparency == "-") {
307 // first transparent image
310 else if (transparency == "0") {
311 // we have transparent and non transparent clips
316 if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
317 allowDurationChange = false;
318 if (allowDurationChange && commonDuration != 0) {
319 if (commonDuration == -1)
320 commonDuration = clip->duration().frames(m_fps);
321 else if (commonDuration != clip->duration().frames(m_fps))
324 clipList.append(clip);
325 QMap <QString, QString> clipprops = clip->properties();
326 QMapIterator<QString, QString> p(commonproperties);
327 while (p.hasNext()) {
329 if (p.value().isEmpty()) continue;
330 if (clipprops.contains(p.key())) {
331 if (p.value() == "-")
332 commonproperties.insert(p.key(), clipprops.value(p.key()));
333 else if (p.value() != clipprops.value(p.key()))
334 commonproperties.insert(p.key(), QString());
336 commonproperties.insert(p.key(), QString());
341 if (allowDurationChange)
342 commonproperties.insert("out", QString::number(commonDuration));
344 commonproperties.insert("transparency", transparency);
345 /*QMapIterator<QString, QString> p(commonproperties);
346 while (p.hasNext()) {
348 kDebug() << "Result: " << p.key() << " = " << p.value();
350 emit showClipProperties(clipList, commonproperties);
353 void ProjectList::slotOpenClip()
356 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
358 if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1)
359 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
361 item = static_cast <ProjectItem*>(m_listView->currentItem());
363 if (item->clipType() == IMAGE) {
364 if (KdenliveSettings::defaultimageapp().isEmpty())
365 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
367 QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
369 if (item->clipType() == AUDIO) {
370 if (KdenliveSettings::defaultaudioapp().isEmpty())
371 KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
373 QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
378 void ProjectList::cleanup()
380 m_listView->clearSelection();
381 QTreeWidgetItemIterator it(m_listView);
384 if ((*it)->type() != PROJECTCLIPTYPE) {
388 item = static_cast <ProjectItem *>(*it);
389 if (item->numReferences() == 0)
390 item->setSelected(true);
396 void ProjectList::trashUnusedClips()
398 QTreeWidgetItemIterator it(m_listView);
403 if ((*it)->type() != PROJECTCLIPTYPE) {
407 item = static_cast <ProjectItem *>(*it);
408 if (item->numReferences() == 0) {
409 ids << item->clipId();
410 KUrl url = item->clipUrl();
411 if (!url.isEmpty() && !urls.contains(url.path()))
417 // Check that we don't use the URL in another clip
418 QTreeWidgetItemIterator it2(m_listView);
420 if ((*it2)->type() != PROJECTCLIPTYPE) {
424 item = static_cast <ProjectItem *>(*it2);
425 if (item->numReferences() > 0) {
426 KUrl url = item->clipUrl();
427 if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path());
432 emit deleteProjectClips(ids, QMap <QString, QString>());
433 for (int i = 0; i < urls.count(); i++)
434 KIO::NetAccess::del(KUrl(urls.at(i)), this);
437 void ProjectList::slotReloadClip(const QString &id)
439 QList<QTreeWidgetItem *> selected;
441 selected = m_listView->selectedItems();
443 ProjectItem *itemToReLoad = getItemById(id);
444 if (itemToReLoad) selected.append(itemToReLoad);
447 for (int i = 0; i < selected.count(); i++) {
448 if (selected.at(i)->type() != PROJECTCLIPTYPE) {
449 if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
450 for (int j = 0; j < selected.at(i)->childCount(); j++)
451 selected.append(selected.at(i)->child(j));
455 item = static_cast <ProjectItem *>(selected.at(i));
457 CLIPTYPE t = item->clipType();
459 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
460 regenerateTemplate(item);
461 } else if (t != COLOR && t != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
462 item->referencedClip()->setPlaceHolder(true);
463 item->setProperty("file_hash", QString());
464 } else if (t == IMAGE) {
465 item->referencedClip()->producer()->set("force_reload", 1);
468 QDomElement e = item->toXml();
469 // Make sure we get the correct producer length if it was adjusted in timeline
470 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
471 int length = QString(item->referencedClip()->producerProperty("length")).toInt();
472 if (length > 0 && !e.hasAttribute("length")) {
473 e.setAttribute("length", length);
476 emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true, false);
481 void ProjectList::slotModifiedClip(const QString &id)
483 ProjectItem *item = getItemById(id);
485 QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
486 if (!pixmap.isNull()) {
488 p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200));
489 p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize()));
492 pixmap = KIcon("view-refresh").pixmap(m_listView->iconSize());
494 item->setData(0, Qt::DecorationRole, pixmap);
498 void ProjectList::slotMissingClip(const QString &id)
500 ProjectItem *item = getItemById(id);
502 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
503 if (item->referencedClip()) {
504 item->referencedClip()->setPlaceHolder(true);
505 if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR";
506 item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
507 item->slotSetToolTip();
508 emit clipNeedsReload(id, true);
512 emit displayMessage(i18n("Check missing clips"), -2);
513 emit updateRenderStatus();
516 void ProjectList::slotAvailableClip(const QString &id)
518 ProjectItem *item = getItemById(id);
521 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
522 if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) {
523 item->setProperty("file_hash", QString());
527 item->referencedClip()->setValid();
528 item->slotSetToolTip();
531 emit updateRenderStatus();
534 bool ProjectList::hasMissingClips()
536 bool missing = false;
537 QTreeWidgetItemIterator it(m_listView);
539 if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) {
548 void ProjectList::setRenderer(Render *projectRender)
550 m_render = projectRender;
551 m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
554 void ProjectList::slotClipSelected()
556 if (!m_listView->isEnabled()) return;
557 if (m_listView->currentItem()) {
558 if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
559 emit clipSelected(NULL);
560 m_editButton->defaultAction()->setEnabled(m_listView->currentItem()->childCount() > 0);
561 m_deleteButton->defaultAction()->setEnabled(true);
562 m_openAction->setEnabled(false);
563 m_reloadAction->setEnabled(false);
564 m_transcodeAction->setEnabled(false);
565 m_proxyAction->setEnabled(false);
568 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
569 // this is a sub item, use base clip
570 m_deleteButton->defaultAction()->setEnabled(true);
571 clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
572 if (clip == NULL) kDebug() << "-----------ERROR";
573 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
574 emit clipSelected(clip->referencedClip(), sub->zone());
575 m_transcodeAction->setEnabled(false);
578 clip = static_cast <ProjectItem*>(m_listView->currentItem());
579 if (clip && clip->referencedClip())
580 emit clipSelected(clip->referencedClip());
581 m_editButton->defaultAction()->setEnabled(true);
582 m_deleteButton->defaultAction()->setEnabled(true);
583 m_reloadAction->setEnabled(true);
584 m_transcodeAction->setEnabled(true);
585 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
586 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
587 m_openAction->setEnabled(true);
588 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
589 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
590 m_openAction->setEnabled(true);
592 m_openAction->setEnabled(false);
594 // Display relevant transcoding actions only
595 adjustTranscodeActions(clip);
596 // Display uses in timeline
597 emit findInTimeline(clip->clipId());
600 emit clipSelected(NULL);
601 m_editButton->defaultAction()->setEnabled(false);
602 m_deleteButton->defaultAction()->setEnabled(false);
603 m_openAction->setEnabled(false);
604 m_reloadAction->setEnabled(false);
605 m_transcodeAction->setEnabled(false);
609 void ProjectList::adjustProxyActions(ProjectItem *clip) const
611 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
612 m_proxyAction->setEnabled(false);
615 m_proxyAction->setEnabled(useProxy());
616 m_proxyAction->blockSignals(true);
617 m_proxyAction->setChecked(clip->hasProxy());
618 m_proxyAction->blockSignals(false);
621 void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
623 if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
624 m_transcodeAction->setEnabled(false);
627 m_transcodeAction->setEnabled(true);
628 QList<QAction *> transcodeActions = m_transcodeAction->actions();
631 for (int i = 0; i < transcodeActions.count(); i++) {
632 data = transcodeActions.at(i)->data().toStringList();
633 if (data.count() > 2) {
634 condition = data.at(2);
635 if (condition.startsWith("vcodec"))
636 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
637 else if (condition.startsWith("acodec"))
638 transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1)));
644 void ProjectList::slotPauseMonitor()
650 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
652 ProjectItem *item = getItemById(id);
654 slotUpdateClipProperties(item, properties);
655 if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
657 } else if (properties.contains("colour") ||
658 properties.contains("xmldata") ||
659 properties.contains("force_aspect_num") ||
660 properties.contains("force_aspect_den") ||
661 properties.contains("templatetext")) {
662 slotRefreshClipThumbnail(item);
663 emit refreshClip(id, true);
664 } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) {
665 emit refreshClip(id, false);
670 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
674 clip->setProperties(properties);
675 if (properties.contains("name")) {
676 monitorItemEditing(false);
677 clip->setText(0, properties.value("name"));
678 monitorItemEditing(true);
679 emit clipNameChanged(clip->clipId(), properties.value("name"));
681 if (properties.contains("description")) {
682 CLIPTYPE type = clip->clipType();
683 monitorItemEditing(false);
684 clip->setText(1, properties.value("description"));
685 monitorItemEditing(true);
687 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
688 // Use Nepomuk system to store clip description
689 Nepomuk::Resource f(clip->clipUrl().path());
690 f.setDescription(properties.value("description"));
693 emit projectModified();
697 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
699 if (item->type() == PROJECTSUBCLIPTYPE) {
700 // this is a sub-item
702 // user edited description
703 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
704 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
705 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), sub->zone(), sub->description(), sub->text(1), true);
706 m_commandStack->push(command);
707 //slotUpdateCutClipProperties(sub->clipId(), sub->zone(), sub->text(1), sub->text(1));
711 if (item->type() == PROJECTFOLDERTYPE) {
713 FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
714 editFolder(item->text(0), folder->groupName(), folder->clipId());
715 folder->setGroupName(item->text(0));
716 m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
717 const int children = item->childCount();
718 for (int i = 0; i < children; i++) {
719 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
720 child->setProperty("groupname", item->text(0));
726 ProjectItem *clip = static_cast <ProjectItem*>(item);
728 if (clip->referencedClip()) {
729 QMap <QString, QString> oldprops;
730 QMap <QString, QString> newprops;
731 oldprops["description"] = clip->referencedClip()->getProperty("description");
732 newprops["description"] = item->text(1);
734 if (clip->clipType() == TEXT) {
735 // This is a text template clip, update the image
736 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
737 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
738 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
739 newprops.insert("templatetext", item->text(1));
741 slotUpdateClipProperties(clip->clipId(), newprops);
742 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
743 m_commandStack->push(command);
745 } else if (column == 0) {
746 if (clip->referencedClip()) {
747 QMap <QString, QString> oldprops;
748 QMap <QString, QString> newprops;
749 oldprops["name"] = clip->referencedClip()->getProperty("name");
750 if (oldprops.value("name") != item->text(0)) {
751 newprops["name"] = item->text(0);
752 slotUpdateClipProperties(clip, newprops);
753 emit projectModified();
754 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
755 m_commandStack->push(command);
761 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
763 bool enable = item ? true : false;
764 m_editButton->defaultAction()->setEnabled(enable);
765 m_deleteButton->defaultAction()->setEnabled(enable);
766 m_reloadAction->setEnabled(enable);
767 m_transcodeAction->setEnabled(enable);
769 ProjectItem *clip = NULL;
770 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
771 clip = static_cast <ProjectItem*>(item->parent());
772 m_transcodeAction->setEnabled(false);
773 } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
774 clip = static_cast <ProjectItem*>(item);
775 // Display relevant transcoding actions only
776 adjustTranscodeActions(clip);
777 adjustProxyActions(clip);
778 // Display uses in timeline
779 emit findInTimeline(clip->clipId());
781 m_transcodeAction->setEnabled(false);
783 if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
784 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
785 m_openAction->setEnabled(true);
786 } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
787 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
788 m_openAction->setEnabled(true);
790 m_openAction->setEnabled(false);
794 m_openAction->setEnabled(false);
799 void ProjectList::slotRemoveClip()
801 if (!m_listView->currentItem())
804 QMap <QString, QString> folderids;
805 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
807 QUndoCommand *delCommand = new QUndoCommand();
808 delCommand->setText(i18n("Delete Clip Zone"));
809 for (int i = 0; i < selected.count(); i++) {
810 if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) {
812 SubProjectItem *sub = static_cast <SubProjectItem *>(selected.at(i));
813 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
814 new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand);
815 } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) {
817 FolderProjectItem *folder = static_cast <FolderProjectItem *>(selected.at(i));
818 folderids[folder->groupName()] = folder->clipId();
819 int children = folder->childCount();
821 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)
823 for (int i = 0; i < children; ++i) {
824 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
825 ids << child->clipId();
828 ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
829 ids << item->clipId();
830 if (item->numReferences() > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), i18np("Delete clip <b>%2</b>?<br />This will also remove the clip in timeline", "Delete clip <b>%2</b>?<br />This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteAll") == KMessageBox::No) {
831 KMessageBox::enableMessage("DeleteAll");
836 KMessageBox::enableMessage("DeleteAll");
837 if (delCommand->childCount() == 0)
840 m_commandStack->push(delCommand);
841 emit deleteProjectClips(ids, folderids);
844 void ProjectList::updateButtons() const
846 if (m_listView->topLevelItemCount() == 0) {
847 m_deleteButton->defaultAction()->setEnabled(false);
848 m_editButton->defaultAction()->setEnabled(false);
850 m_deleteButton->defaultAction()->setEnabled(true);
851 if (!m_listView->currentItem())
852 m_listView->setCurrentItem(m_listView->topLevelItem(0));
853 QTreeWidgetItem *item = m_listView->currentItem();
854 if (item && item->type() == PROJECTCLIPTYPE) {
855 m_editButton->defaultAction()->setEnabled(true);
856 m_openAction->setEnabled(true);
857 m_reloadAction->setEnabled(true);
858 m_transcodeAction->setEnabled(true);
859 m_proxyAction->setEnabled(useProxy());
862 else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
863 m_editButton->defaultAction()->setEnabled(true);
865 else m_editButton->defaultAction()->setEnabled(false);
867 m_openAction->setEnabled(false);
868 m_reloadAction->setEnabled(false);
869 m_transcodeAction->setEnabled(false);
870 m_proxyAction->setEnabled(false);
873 void ProjectList::selectItemById(const QString &clipId)
875 ProjectItem *item = getItemById(clipId);
877 m_listView->setCurrentItem(item);
881 void ProjectList::slotDeleteClip(const QString &clipId)
883 ProjectItem *item = getItemById(clipId);
885 kDebug() << "/// Cannot find clip to delete";
888 m_listView->blockSignals(true);
889 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
890 if (!newSelectedItem)
891 newSelectedItem = m_listView->itemBelow(item);
893 m_doc->clipManager()->deleteClip(clipId);
894 m_listView->blockSignals(false);
895 if (newSelectedItem) {
896 m_listView->setCurrentItem(newSelectedItem);
899 emit clipSelected(NULL);
904 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
906 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
907 m_commandStack->push(command);
908 m_doc->setModified(true);
911 void ProjectList::slotAddFolder()
913 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
914 m_commandStack->push(command);
917 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
920 FolderProjectItem *item = getFolderItemById(clipId);
922 m_doc->clipManager()->deleteFolder(clipId);
923 QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
924 if (!newSelectedItem)
925 newSelectedItem = m_listView->itemBelow(item);
928 m_listView->setCurrentItem(newSelectedItem);
934 FolderProjectItem *item = getFolderItemById(clipId);
936 m_listView->blockSignals(true);
937 item->setGroupName(foldername);
938 m_listView->blockSignals(false);
939 m_doc->clipManager()->addFolder(clipId, foldername);
940 const int children = item->childCount();
941 for (int i = 0; i < children; i++) {
942 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
943 child->setProperty("groupname", foldername);
947 m_listView->blockSignals(true);
948 m_listView->setCurrentItem(new FolderProjectItem(m_listView, QStringList() << foldername, clipId));
949 m_doc->clipManager()->addFolder(clipId, foldername);
950 m_listView->blockSignals(false);
951 m_listView->editItem(m_listView->currentItem(), 0);
955 m_doc->setModified(true);
960 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
962 QMapIterator<QString, QString> i(map);
963 QUndoCommand *delCommand = new QUndoCommand();
964 delCommand->setText(i18n("Delete Folder"));
965 while (i.hasNext()) {
967 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
969 if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
970 else delete delCommand;
973 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
975 m_listView->setEnabled(false);
976 const QString parent = clip->getProperty("groupid");
977 ProjectItem *item = NULL;
978 monitorItemEditing(false);
979 if (!parent.isEmpty()) {
980 FolderProjectItem *parentitem = getFolderItemById(parent);
983 QString groupName = clip->getProperty("groupname");
984 //kDebug() << "Adding clip to new group: " << groupName;
985 if (groupName.isEmpty()) groupName = i18n("Folder");
987 parentitem = new FolderProjectItem(m_listView, text, parent);
991 item = new ProjectItem(parentitem, clip);
994 item = new ProjectItem(m_listView, clip);
996 if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
997 connect(clip, SIGNAL(createProxy(const QString)), this, SLOT(slotCreateProxy(const QString)));
998 connect(clip, SIGNAL(abortProxy(const QString)), this, SLOT(slotAbortProxy(const QString)));
1000 m_listView->processLayout();
1001 QDomElement e = clip->toXML().cloneNode().toElement();
1002 e.removeAttribute("file_hash");
1003 m_infoQueue.insert(clip->getId(), e);
1005 else if (item->hasProxy() && !item->isProxyRunning()) {
1006 slotCreateProxy(clip->getId(), false);
1008 clip->askForAudioThumbs();
1010 KUrl url = clip->fileURL();
1011 if (getProperties == false && !clip->getClipHash().isEmpty()) {
1012 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
1013 if (QFile::exists(cachedPixmap)) {
1014 QPixmap pix(cachedPixmap);
1016 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1017 item->setData(0, Qt::DecorationRole, pix);
1021 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
1022 // if file has Nepomuk comment, use it
1023 Nepomuk::Resource f(url.path());
1024 QString annotation = f.description();
1025 if (!annotation.isEmpty()) item->setText(1, annotation);
1026 item->setText(2, QString::number(f.rating()));
1030 QList <CutZoneInfo> cuts = clip->cutZones();
1031 if (!cuts.isEmpty()) {
1032 for (int i = 0; i < cuts.count(); i++) {
1033 SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description);
1034 if (!clip->getClipHash().isEmpty()) {
1035 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
1036 if (QFile::exists(cachedPixmap)) {
1037 QPixmap pix(cachedPixmap);
1039 KIO::NetAccess::del(KUrl(cachedPixmap), this);
1040 sub->setData(0, Qt::DecorationRole, pix);
1045 monitorItemEditing(true);
1046 if (m_listView->isEnabled()) {
1050 if (getProperties && m_processingClips.isEmpty())
1051 m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1054 void ProjectList::slotGotProxy(const QString &id)
1056 ProjectItem *item = getItemById(id);
1058 // Proxy clip successfully created
1059 QDomElement e = item->referencedClip()->toXML().cloneNode().toElement();
1060 //e.removeAttribute("file_hash");
1062 // Make sure we get the correct producer length if it was adjusted in timeline
1063 CLIPTYPE t = item->clipType();
1064 if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
1065 int length = QString(item->referencedClip()->producerProperty("length")).toInt();
1066 if (length > 0 && !e.hasAttribute("length")) {
1067 e.setAttribute("length", length);
1070 e.setAttribute("replace", 1);
1071 m_infoQueue.insert(id, e);
1072 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1076 void ProjectList::slotResetProjectList()
1078 m_listView->clear();
1079 emit clipSelected(NULL);
1080 m_thumbnailQueue.clear();
1081 m_infoQueue.clear();
1082 m_refreshed = false;
1085 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
1087 m_infoQueue.insert(id, xml);
1088 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
1091 void ProjectList::slotProcessNextClipInQueue()
1093 if (m_infoQueue.isEmpty()) {
1094 emit processNextThumbnail();
1098 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
1099 if (j != m_infoQueue.constEnd()) {
1100 QDomElement dom = j.value();
1101 const QString id = j.key();
1102 m_infoQueue.remove(id);
1103 m_processingClips.append(id);
1105 if (dom.hasAttribute("replace")) {
1106 // Proxy action was enabled / disabled and we want to replace current producer
1107 dom.removeAttribute("replace");
1110 else replace = false;
1111 bool selectClip = !replace;
1112 if (m_infoQueue.count() > 1) selectClip = false;
1113 emit getFileProperties(dom, id, m_listView->iconSize().height(), replace, selectClip);
1117 void ProjectList::slotUpdateClip(const QString &id)
1119 ProjectItem *item = getItemById(id);
1120 monitorItemEditing(false);
1121 if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
1122 monitorItemEditing(true);
1125 void ProjectList::updateAllClips()
1127 m_listView->setSortingEnabled(false);
1128 kDebug() << "// UPDATE ALL CLPY";
1130 QTreeWidgetItemIterator it(m_listView);
1133 monitorItemEditing(false);
1135 if ((*it)->type() == PROJECTSUBCLIPTYPE) {
1137 SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
1138 if (sub->data(0, Qt::DecorationRole).isNull()) {
1139 item = static_cast <ProjectItem *>((*it)->parent());
1140 requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
1144 } else if ((*it)->type() == PROJECTFOLDERTYPE) {
1149 item = static_cast <ProjectItem *>(*it);
1150 clip = item->referencedClip();
1151 if (item->referencedClip()->producer() == NULL) {
1152 if (clip->isPlaceHolder() == false)
1153 requestClipInfo(clip->toXML(), clip->getId());
1154 else if (!clip->isPlaceHolder())
1155 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
1157 if (item->data(0, Qt::DecorationRole).isNull())
1158 requestClipThumbnail(clip->getId());
1159 if (item->data(0, DurationRole).toString().isEmpty()) {
1160 item->changeDuration(item->referencedClip()->producer()->get_playtime());
1163 item->setData(0, UsageRole, QString::number(item->numReferences()));
1165 //qApp->processEvents();
1169 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1170 if (m_listView->isEnabled())
1171 monitorItemEditing(true);
1172 m_listView->setSortingEnabled(true);
1173 if (m_infoQueue.isEmpty())
1174 slotProcessNextThumbnail();
1178 QString ProjectList::getExtensions()
1180 // Build list of mime types
1181 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain"
1182 << "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"
1183 << "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"
1184 << "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";
1186 QString allExtensions;
1187 foreach(const QString & mimeType, mimeTypes) {
1188 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
1190 allExtensions.append(mime->patterns().join(" "));
1191 allExtensions.append(' ');
1194 return allExtensions.simplified();
1197 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
1199 if (!m_commandStack)
1200 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1203 if (givenList.isEmpty()) {
1204 QString allExtensions = getExtensions();
1205 const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
1206 QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
1207 b->setChecked(KdenliveSettings::autoimagesequence());
1208 QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
1209 c->setChecked(KdenliveSettings::autoimagetransparency());
1210 QFrame *f = new QFrame;
1211 f->setFrameShape(QFrame::NoFrame);
1212 QHBoxLayout *l = new QHBoxLayout;
1217 KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
1218 d->setOperationMode(KFileDialog::Opening);
1219 d->setMode(KFile::Files);
1220 if (d->exec() == QDialog::Accepted) {
1221 KdenliveSettings::setAutoimagetransparency(c->isChecked());
1223 list = d->selectedUrls();
1224 if (b->isChecked() && list.count() == 1) {
1225 // Check for image sequence
1226 KUrl url = list.at(0);
1227 QString fileName = url.fileName().section('.', 0, -2);
1228 if (fileName.at(fileName.size() - 1).isDigit()) {
1229 KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
1230 if (item.mimetype().startsWith("image")) {
1231 // import as sequence if we found more than one image in the sequence
1233 QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list);
1234 int count = list.count();
1237 QStringList groupInfo = getGroup();
1239 // get image sequence base name
1240 while (fileName.at(fileName.size() - 1).isDigit()) {
1244 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
1245 false, false, false,
1246 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
1247 QString(), groupInfo.at(0), groupInfo.at(1));
1255 for (int i = 0; i < givenList.count(); i++)
1256 list << givenList.at(i);
1259 foreach(const KUrl & file, list) {
1260 // Check there is no folder here
1261 KMimeType::Ptr type = KMimeType::findByUrl(file);
1262 if (type->is("inode/directory")) {
1263 // user dropped a folder
1264 list.removeAll(file);
1271 if (givenList.isEmpty()) {
1272 QStringList groupInfo = getGroup();
1273 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
1275 m_doc->slotAddClipList(list, groupName, groupId);
1279 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
1281 ProjectItem *item = getItemById(id);
1282 m_processingClips.removeAll(id);
1283 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1285 const QString path = item->referencedClip()->fileURL().path();
1286 if (item->referencedClip()->isPlaceHolder()) replace = false;
1287 if (!path.isEmpty()) {
1289 KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
1290 else if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes)
1294 emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
1298 void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
1300 ProjectItem *item = getItemById(id);
1302 //TODO: use durationError to display correct message to user after 0.8 release
1303 if (durationError) kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
1304 item->setProxyStatus(PROXYCRASHED);
1305 QString path = item->referencedClip()->getProperty("proxy");
1306 KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
1308 //Security check: make sure the invalid proxy file is in the proxy folder
1309 if (proxyFolder.isParentOf(KUrl(path))) {
1310 QFile::remove(path);
1313 m_processingClips.removeAll(id);
1314 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1317 void ProjectList::slotAddColorClip()
1319 if (!m_commandStack)
1320 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1322 QDialog *dia = new QDialog(this);
1323 Ui::ColorClip_UI dia_ui;
1324 dia_ui.setupUi(dia);
1325 dia->setWindowTitle(i18n("Color Clip"));
1326 dia_ui.clip_name->setText(i18n("Color Clip"));
1328 TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
1329 t->setValue(KdenliveSettings::color_duration());
1330 t->setTimeCodeFormat(false);
1331 dia_ui.clip_durationBox->addWidget(t);
1332 dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
1334 if (dia->exec() == QDialog::Accepted) {
1335 QString color = dia_ui.clip_color->color().name();
1336 KdenliveSettings::setColorclipcolor(color);
1337 color = color.replace(0, 1, "0x") + "ff";
1338 QStringList groupInfo = getGroup();
1339 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
1346 void ProjectList::slotAddSlideshowClip()
1348 if (!m_commandStack)
1349 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1351 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
1353 if (dia->exec() == QDialog::Accepted) {
1354 QStringList groupInfo = getGroup();
1355 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(),
1356 dia->loop(), dia->crop(), dia->fade(),
1357 dia->lumaDuration(), dia->lumaFile(), dia->softness(),
1358 dia->animation(), groupInfo.at(0), groupInfo.at(1));
1363 void ProjectList::slotAddTitleClip()
1365 QStringList groupInfo = getGroup();
1366 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
1369 void ProjectList::slotAddTitleTemplateClip()
1371 if (!m_commandStack)
1372 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
1374 QStringList groupInfo = getGroup();
1376 // Get the list of existing templates
1378 filter << "*.kdenlivetitle";
1379 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
1380 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
1382 QDialog *dia = new QDialog(this);
1383 Ui::TemplateClip_UI dia_ui;
1384 dia_ui.setupUi(dia);
1385 for (int i = 0; i < templateFiles.size(); ++i)
1386 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
1388 if (!templateFiles.isEmpty())
1389 dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus();
1390 dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle");
1391 //warning: setting base directory doesn't work??
1392 KUrl startDir(path);
1393 dia_ui.template_list->fileDialog()->setUrl(startDir);
1394 dia_ui.text_box->setHidden(true);
1395 if (dia->exec() == QDialog::Accepted) {
1396 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
1397 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
1398 // Create a cloned template clip
1399 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
1404 QStringList ProjectList::getGroup() const
1407 QTreeWidgetItem *item = m_listView->currentItem();
1408 while (item && item->type() != PROJECTFOLDERTYPE)
1409 item = item->parent();
1412 FolderProjectItem *folder = static_cast <FolderProjectItem *>(item);
1413 result << folder->groupName() << folder->clipId();
1415 result << QString() << QString();
1420 void ProjectList::setDocument(KdenliveDoc *doc)
1422 m_listView->blockSignals(true);
1423 m_listView->clear();
1424 m_processingClips.clear();
1425 m_listView->setSortingEnabled(false);
1426 emit clipSelected(NULL);
1427 m_thumbnailQueue.clear();
1428 m_infoQueue.clear();
1429 m_refreshed = false;
1431 m_timecode = doc->timecode();
1432 m_commandStack = doc->commandStack();
1434 m_proxyList.clear();
1436 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
1437 QStringList openedFolders = doc->getExpandedFolders();
1438 QMapIterator<QString, QString> f(flist);
1439 while (f.hasNext()) {
1441 FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key());
1442 folder->setExpanded(openedFolders.contains(f.key()));
1445 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
1446 for (int i = 0; i < list.count(); i++)
1447 slotAddClip(list.at(i), false);
1449 m_listView->blockSignals(false);
1450 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
1451 connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
1452 connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
1453 connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
1454 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
1457 QList <DocClipBase*> ProjectList::documentClipList() const
1460 return QList <DocClipBase*> ();
1462 return m_doc->clipManager()->documentClipList();
1465 QDomElement ProjectList::producersList()
1468 QDomElement prods = doc.createElement("producerlist");
1469 doc.appendChild(prods);
1470 kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
1471 QTreeWidgetItemIterator it(m_listView);
1473 if ((*it)->type() != PROJECTCLIPTYPE) {
1478 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
1484 void ProjectList::slotCheckForEmptyQueue()
1486 if (!m_refreshed && m_processingClips.isEmpty() && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1488 emit loadingIsOver();
1489 emit displayMessage(QString(), -1);
1490 m_listView->blockSignals(false);
1491 m_listView->setEnabled(true);
1493 } else if (!m_refreshed) {
1494 QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
1498 void ProjectList::reloadClipThumbnails()
1500 m_thumbnailQueue.clear();
1501 QTreeWidgetItemIterator it(m_listView);
1503 if ((*it)->type() != PROJECTCLIPTYPE) {
1508 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
1511 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1514 void ProjectList::requestClipThumbnail(const QString id)
1516 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
1519 void ProjectList::slotProcessNextThumbnail()
1521 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
1522 slotCheckForEmptyQueue();
1525 if (!m_infoQueue.isEmpty()) {
1526 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
1529 if (m_thumbnailQueue.count() > 1) {
1530 int max = m_doc->clipManager()->clipsCount();
1531 emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
1533 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
1536 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
1538 QTreeWidgetItem *item = getAnyItemById(clipId);
1540 slotRefreshClipThumbnail(item, update);
1542 slotProcessNextThumbnail();
1545 void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
1547 if (it == NULL) return;
1548 ProjectItem *item = NULL;
1549 bool isSubItem = false;
1551 if (it->type() == PROJECTFOLDERTYPE) return;
1552 if (it->type() == PROJECTSUBCLIPTYPE) {
1553 item = static_cast <ProjectItem *>(it->parent());
1554 frame = static_cast <SubProjectItem *>(it)->zone().x();
1557 item = static_cast <ProjectItem *>(it);
1558 frame = item->referencedClip()->getClipThumbFrame();
1562 DocClipBase *clip = item->referencedClip();
1564 slotProcessNextThumbnail();
1568 int height = m_listView->iconSize().height();
1569 int width = (int)(height * m_render->dar());
1570 if (clip->clipType() == AUDIO)
1571 pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
1572 else if (clip->clipType() == IMAGE)
1573 pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
1575 pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
1577 if (!pix.isNull()) {
1578 monitorItemEditing(false);
1579 it->setData(0, Qt::DecorationRole, pix);
1580 monitorItemEditing(true);
1583 m_doc->cachePixmap(item->getClipHash(), pix);
1585 m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
1588 emit projectModified();
1590 slotProcessNextThumbnail();
1594 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace, bool selectClip)
1597 ProjectItem *item = getItemById(clipId);
1599 // we are still finishing to load the document
1602 m_processingClips.removeAll(clipId);
1603 if (m_infoQueue.isEmpty() && m_processingClips.isEmpty()) m_listView->setEnabled(true);
1604 if (item && producer) {
1605 //m_listView->blockSignals(true);
1606 monitorItemEditing(false);
1607 item->setProperties(properties, metadata);
1608 if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
1609 item->referencedClip()->setValid();
1610 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
1615 QString size = properties.value("frame_size");
1616 DocClipBase *clip = item->referencedClip();
1617 if (!useProxy() && item->referencedClip()->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY);
1618 if (useProxy() && generateProxy() && item->referencedClip()->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY);
1619 else if (useProxy() && !item->isProxyRunning() && (item->clipType() == AV || item->clipType() == VIDEO) && generateProxy() && size.section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
1620 if (clip->getProperty("proxy").isEmpty()) {
1621 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
1622 QMap <QString, QString> newProps;
1623 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
1624 // insert required duration for proxy
1625 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
1626 QMap <QString, QString> oldProps = clip->properties();
1627 oldProps.insert("proxy", QString());
1628 EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
1629 m_doc->commandStack()->push(command);
1633 clip->setProducer(producer, replace);
1634 clip->askForAudioThumbs();
1635 if (!replace && item->data(0, Qt::DecorationRole).isNull())
1636 requestClipThumbnail(clipId);
1637 if (!toReload.isEmpty())
1638 item->slotSetToolTip();
1640 if (m_listView->isEnabled() && replace) {
1641 // update clip in clip monitor
1642 emit clipSelected(NULL);
1643 emit clipSelected(clip);
1644 //TODO: Make sure the line below has no side effect
1648 // Check if duration changed.
1649 emit receivedClipDuration(clipId);
1652 if (m_listView->isEnabled())
1653 monitorItemEditing(true);
1654 /*if (item->icon(0).isNull()) {
1655 requestClipThumbnail(clipId);
1657 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
1658 if (selectClip && m_infoQueue.isEmpty()) {
1659 if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
1660 m_listView->setCurrentItem(item);
1661 bool updatedProfile = false;
1662 if (item->parent()) {
1663 if (item->parent()->type() == PROJECTFOLDERTYPE)
1664 static_cast <FolderProjectItem *>(item->parent())->switchIcon();
1665 } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) {
1666 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
1667 updatedProfile = adjustProjectProfileToItem(item);
1669 if (updatedProfile == false) emit clipSelected(item->referencedClip());
1671 int max = m_doc->clipManager()->clipsCount();
1672 emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
1675 if (!toReload.isEmpty())
1676 emit clipNeedsReload(toReload, true);
1678 if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
1681 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
1684 if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE)
1685 item = static_cast <ProjectItem*>(m_listView->currentItem());
1687 if (item == NULL || item->referencedClip() == NULL) {
1688 KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip"));
1691 bool profileUpdated = false;
1692 QString size = item->referencedClip()->getProperty("frame_size");
1693 int width = size.section('x', 0, 0).toInt();
1694 int height = size.section('x', -1).toInt();
1695 double fps = item->referencedClip()->getProperty("fps").toDouble();
1696 double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
1697 if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
1698 if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) {
1699 // get a list of compatible profiles
1700 QMap <QString, QString> suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE);
1701 if (!suggestedProfiles.isEmpty()) {
1702 KDialog *dialog = new KDialog(this);
1703 dialog->setCaption(i18n("Change project profile"));
1704 dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1707 QVBoxLayout *l = new QVBoxLayout;
1708 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));
1709 l->addWidget(label);
1710 QListWidget *list = new QListWidget;
1711 list->setAlternatingRowColors(true);
1712 QMapIterator<QString, QString> i(suggestedProfiles);
1713 while (i.hasNext()) {
1715 QListWidgetItem *item = new QListWidgetItem(i.value(), list);
1716 item->setData(Qt::UserRole, i.key());
1717 item->setToolTip(i.key());
1719 list->setCurrentRow(0);
1721 container.setLayout(l);
1722 dialog->setButtonText(KDialog::Ok, i18n("Update profile"));
1723 dialog->setMainWidget(&container);
1724 if (dialog->exec() == QDialog::Accepted) {
1725 //Change project profile
1726 profileUpdated = true;
1727 if (list->currentItem())
1728 emit updateProfile(list->currentItem()->data(Qt::UserRole).toString());
1732 } else if (fps > 0) {
1733 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));
1737 return profileUpdated;
1740 QString ProjectList::getDocumentProperty(const QString &key) const
1742 return m_doc->getDocumentProperty(key);
1745 bool ProjectList::useProxy() const
1747 return m_doc->getDocumentProperty("enableproxy").toInt();
1750 bool ProjectList::generateProxy() const
1752 return m_doc->getDocumentProperty("generateproxy").toInt();
1755 bool ProjectList::generateImageProxy() const
1757 return m_doc->getDocumentProperty("generateimageproxy").toInt();
1760 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
1762 ProjectItem *item = getItemById(clipId);
1763 if (item && !pix.isNull()) {
1764 monitorItemEditing(false);
1765 item->setData(0, Qt::DecorationRole, pix);
1766 monitorItemEditing(true);
1767 m_doc->cachePixmap(item->getClipHash(), pix);
1768 if (m_listView->isEnabled())
1769 m_listView->blockSignals(false);
1773 QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id)
1775 QTreeWidgetItemIterator it(m_listView);
1776 QString lookId = id;
1777 if (id.contains('#'))
1778 lookId = id.section('#', 0, 0);
1780 ProjectItem *result = NULL;
1782 if ((*it)->type() != PROJECTCLIPTYPE) {
1787 ProjectItem *item = static_cast<ProjectItem *>(*it);
1788 if (item->clipId() == lookId) {
1794 if (result == NULL || !id.contains('#')) {
1797 for (int i = 0; i < result->childCount(); i++) {
1798 SubProjectItem *sub = static_cast <SubProjectItem *>(result->child(i));
1799 if (sub && sub->zone().x() == id.section('#', 1, 1).toInt())
1808 ProjectItem *ProjectList::getItemById(const QString &id)
1811 QTreeWidgetItemIterator it(m_listView);
1813 if ((*it)->type() != PROJECTCLIPTYPE) {
1814 // subitem or folder
1818 item = static_cast<ProjectItem *>(*it);
1819 if (item->clipId() == id)
1826 FolderProjectItem *ProjectList::getFolderItemById(const QString &id)
1828 FolderProjectItem *item;
1829 QTreeWidgetItemIterator it(m_listView);
1831 if ((*it)->type() == PROJECTFOLDERTYPE) {
1832 item = static_cast<FolderProjectItem *>(*it);
1833 if (item->clipId() == id)
1841 void ProjectList::slotSelectClip(const QString &ix)
1843 ProjectItem *clip = getItemById(ix);
1845 m_listView->setCurrentItem(clip);
1846 m_listView->scrollToItem(clip);
1847 m_editButton->defaultAction()->setEnabled(true);
1848 m_deleteButton->defaultAction()->setEnabled(true);
1849 m_reloadAction->setEnabled(true);
1850 m_transcodeAction->setEnabled(true);
1851 m_proxyAction->setEnabled(useProxy());
1852 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1853 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1854 m_openAction->setEnabled(true);
1855 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1856 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1857 m_openAction->setEnabled(true);
1859 m_openAction->setEnabled(false);
1864 QString ProjectList::currentClipUrl() const
1867 if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString();
1868 if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
1870 item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
1872 item = static_cast <ProjectItem*>(m_listView->currentItem());
1876 return item->clipUrl().path();
1879 KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
1883 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
1884 for (int i = 0; i < list.count(); i++) {
1885 if (list.at(i)->type() == PROJECTFOLDERTYPE)
1887 if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
1889 item = static_cast <ProjectItem*>(list.at(i)->parent());
1891 item = static_cast <ProjectItem*>(list.at(i));
1893 if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
1895 DocClipBase *clip = item->referencedClip();
1896 if (!condition.isEmpty()) {
1897 if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
1899 else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
1902 result.append(item->clipUrl());
1907 void ProjectList::regenerateTemplate(const QString &id)
1909 ProjectItem *clip = getItemById(id);
1911 regenerateTemplate(clip);
1914 void ProjectList::regenerateTemplate(ProjectItem *clip)
1916 //TODO: remove this unused method, only force_reload is necessary
1917 clip->referencedClip()->producer()->set("force_reload", 1);
1920 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1924 if (!file.open(QIODevice::ReadOnly)) {
1925 kWarning() << "ERROR, CANNOT READ: " << path;
1928 if (!doc.setContent(&file)) {
1929 kWarning() << "ERROR, CANNOT READ: " << path;
1934 QDomNodeList texts = doc.elementsByTagName("content");
1935 for (int i = 0; i < texts.count(); i++) {
1936 QString data = texts.item(i).firstChild().nodeValue();
1937 data.replace("%s", replaceString);
1938 texts.item(i).firstChild().setNodeValue(data);
1944 void ProjectList::slotAddClipCut(const QString &id, int in, int out)
1946 ProjectItem *clip = getItemById(id);
1947 if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out)))
1949 AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false);
1950 m_commandStack->push(command);
1953 void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem)
1955 ProjectItem *clip = getItemById(id);
1957 DocClipBase *base = clip->referencedClip();
1958 base->addCutZone(in, out);
1959 monitorItemEditing(false);
1960 SubProjectItem *sub = new SubProjectItem(clip, in, out, desc);
1961 if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) {
1962 if (!clip->isExpanded())
1963 clip->setExpanded(true);
1964 m_listView->scrollToItem(sub);
1965 m_listView->editItem(sub, 1);
1967 QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
1968 sub->setData(0, Qt::DecorationRole, p);
1969 m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
1970 monitorItemEditing(true);
1972 emit projectModified();
1975 void ProjectList::removeClipCut(const QString &id, int in, int out)
1977 ProjectItem *clip = getItemById(id);
1979 DocClipBase *base = clip->referencedClip();
1980 base->removeCutZone(in, out);
1981 SubProjectItem *sub = getSubItem(clip, QPoint(in, out));
1983 monitorItemEditing(false);
1985 monitorItemEditing(true);
1988 emit projectModified();
1991 SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone)
1993 SubProjectItem *sub = NULL;
1995 for (int i = 0; i < clip->childCount(); i++) {
1996 QTreeWidgetItem *it = clip->child(i);
1997 if (it->type() == PROJECTSUBCLIPTYPE) {
1998 sub = static_cast <SubProjectItem*>(it);
1999 if (sub->zone() == zone)
2009 void ProjectList::slotUpdateClipCut(QPoint p)
2011 if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE)
2013 SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
2014 ProjectItem *item = static_cast <ProjectItem *>(sub->parent());
2015 EditClipCutCommand *command = new EditClipCutCommand(this, item->clipId(), sub->zone(), p, sub->text(1), sub->text(1), true);
2016 m_commandStack->push(command);
2019 void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const QPoint zone, const QString &comment)
2021 ProjectItem *clip = getItemById(id);
2022 SubProjectItem *sub = getSubItem(clip, oldzone);
2023 if (sub == NULL || clip == NULL)
2025 DocClipBase *base = clip->referencedClip();
2026 base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment);
2027 monitorItemEditing(false);
2029 sub->setDescription(comment);
2030 monitorItemEditing(true);
2031 emit projectModified();
2034 void ProjectList::slotForceProcessing(const QString &id)
2036 while (m_infoQueue.contains(id)) {
2037 slotProcessNextClipInQueue();
2041 void ProjectList::slotAddOrUpdateSequence(const QString frameName)
2043 QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
2045 QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
2046 int count = list.count();
2048 const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
2049 if (!existing.isEmpty()) {
2050 // Sequence already exists, update
2051 QString id = existing.at(0)->getId();
2052 //ProjectItem *item = getItemById(id);
2053 QMap <QString, QString> oldprops;
2054 QMap <QString, QString> newprops;
2055 int ttl = existing.at(0)->getProperty("ttl").toInt();
2056 oldprops["out"] = existing.at(0)->getProperty("out");
2057 newprops["out"] = QString::number(ttl * count - 1);
2058 slotUpdateClipProperties(id, newprops);
2059 EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
2060 m_commandStack->push(command);
2063 QStringList groupInfo = getGroup();
2064 m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
2065 false, false, false,
2066 m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
2067 QString(), groupInfo.at(0), groupInfo.at(1));
2069 } else emit displayMessage(i18n("Sequence not found"), -2);
2072 QMap <QString, QString> ProjectList::getProxies()
2074 QMap <QString, QString> list;
2076 QTreeWidgetItemIterator it(m_listView);
2078 if ((*it)->type() != PROJECTCLIPTYPE) {
2082 item = static_cast<ProjectItem *>(*it);
2083 if (item && item->referencedClip() != NULL) {
2084 if (item->hasProxy()) {
2085 QString proxy = item->referencedClip()->getProperty("proxy");
2086 list.insert(proxy, item->clipUrl().path());
2094 void ProjectList::slotCreateProxy(const QString id, bool createProducer)
2096 ProjectItem *item = getItemById(id);
2097 if (!item || item->isProxyRunning()) return;
2099 // If proxy producer already exists, skip creation
2100 if (!createProducer) {
2101 setProxyStatus(id, PROXYDONE);
2104 setProxyStatus(id, PROXYWAITING);
2105 if (m_abortProxyId.contains(id)) m_abortProxyId.removeAll(id);
2106 emit projectModified();
2107 QtConcurrent::run(this, &ProjectList::slotGenerateProxy, id);
2110 void ProjectList::slotAbortProxy(const QString id)
2112 if (m_proxyList.contains(id)) m_proxyList.removeAll(id);
2113 ProjectItem *item = getItemById(id);
2115 emit projectModified();
2116 if (item->isProxyReady()) slotGotProxy(id);
2117 else if (item->isProxyRunning()) m_abortProxyId << id;
2118 setProxyStatus(id, NOPROXY);
2122 void ProjectList::slotGenerateProxy(const QString id)
2124 setProxyStatus(id, CREATINGPROXY);
2125 ProjectItem *item = getItemById(id);
2126 if (item == NULL) return;
2127 QString path = item->referencedClip()->getProperty("proxy");
2128 if (path.isEmpty()) {
2129 setProxyStatus(id, PROXYCRASHED);
2133 QString url = item->clipUrl().path();
2135 if (QFile::exists(path)) {
2136 setProxyStatus(id, PROXYDONE);
2141 // Make sure proxy path is writable
2143 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
2144 setProxyStatus(id, PROXYCRASHED);
2148 QFile::remove(path);
2150 if (item->clipType() == IMAGE) {
2154 // Cannot load image
2155 setProxyStatus(id, PROXYCRASHED);
2159 // Images are scaled to profile size.
2160 //TODO: Make it be configurable?
2161 if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth());
2162 else proxy = i.scaledToHeight(m_render->renderHeight());
2163 int exif_orientation = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();
2164 if (exif_orientation > 1) {
2165 // Rotate image according to exif data
2169 switch ( exif_orientation ) {
2171 matrix.scale( -1, 1 );
2174 matrix.rotate( 180 );
2177 matrix.scale( 1, -1 );
2180 matrix.rotate( 270 );
2181 matrix.scale( -1, 1 );
2184 matrix.rotate( 90 );
2187 matrix.rotate( 90 );
2188 matrix.scale( -1, 1 );
2191 matrix.rotate( 270 );
2194 processed = proxy.transformed( matrix );
2195 processed.save(path);
2197 else proxy.save(path);
2198 setProxyStatus(id, PROXYDONE);
2203 QStringList parameters;
2204 parameters << "-i" << url;
2205 QString params = m_doc->getDocumentProperty("proxyparams").simplified();
2206 foreach(QString s, params.split(' '))
2209 // Make sure we don't block when proxy file already exists
2213 myProcess.start("ffmpeg", parameters);
2214 myProcess.waitForStarted();
2216 while (myProcess.state() != QProcess::NotRunning) {
2217 // building proxy file
2218 if (m_abortProxyId.contains(id)) {
2220 myProcess.waitForFinished();
2221 m_abortProxyId.removeAll(id);
2222 QFile::remove(path);
2223 setProxyStatus(id, NOPROXY);
2227 myProcess.waitForFinished(500);
2229 myProcess.waitForFinished();
2230 if (result == -1) result = myProcess.exitStatus();
2232 // proxy successfully created
2233 setProxyStatus(id, PROXYDONE);
2236 else if (result == 1) {
2237 // Proxy process crashed
2238 QFile::remove(path);
2239 setProxyStatus(id, PROXYCRASHED);
2243 void ProjectList::updateProxyConfig()
2246 QTreeWidgetItemIterator it(m_listView);
2247 QUndoCommand *command = new QUndoCommand();
2248 command->setText(i18n("Update proxy settings"));
2249 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2251 if ((*it)->type() != PROJECTCLIPTYPE) {
2255 item = static_cast<ProjectItem *>(*it);
2260 CLIPTYPE t = item->clipType();
2261 if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
2262 if (generateProxy() && useProxy() && !item->isProxyRunning()) {
2263 DocClipBase *clip = item->referencedClip();
2264 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
2265 if (clip->getProperty("proxy").isEmpty()) {
2266 // We need to insert empty proxy in old properties so that undo will work
2267 QMap <QString, QString> oldProps = clip->properties();
2268 oldProps.insert("proxy", QString());
2269 QMap <QString, QString> newProps;
2270 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
2271 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2275 else if (item->hasProxy()) {
2277 QMap <QString, QString> newProps;
2278 newProps.insert("proxy", QString());
2279 newProps.insert("replace", "1");
2280 // insert required duration for proxy
2281 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2282 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2285 else if (t == IMAGE && item->referencedClip() != NULL) {
2286 if (generateImageProxy() && useProxy()) {
2287 DocClipBase *clip = item->referencedClip();
2288 int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
2289 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
2290 if (clip->getProperty("proxy").isEmpty()) {
2291 // We need to insert empty proxy in old properties so that undo will work
2292 QMap <QString, QString> oldProps = clip->properties();
2293 oldProps.insert("proxy", QString());
2294 QMap <QString, QString> newProps;
2295 newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
2296 new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
2300 else if (item->hasProxy()) {
2302 QMap <QString, QString> newProps;
2303 newProps.insert("proxy", QString());
2304 newProps.insert("replace", "1");
2305 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
2310 if (command->childCount() > 0) m_doc->commandStack()->push(command);
2311 else delete command;
2312 if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
2315 void ProjectList::slotProxyCurrentItem(bool doProxy)
2317 QList<QTreeWidgetItem *> list = m_listView->selectedItems();
2318 QTreeWidgetItem *listItem;
2319 QUndoCommand *command = new QUndoCommand();
2320 if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", list.count()));
2321 else command->setText(i18np("Remove proxy clip", "Remove proxy clips", list.count()));
2323 // Make sure the proxy folder exists
2324 QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
2325 KStandardDirs::makeDir(proxydir);
2327 QMap <QString, QString> newProps;
2328 QMap <QString, QString> oldProps;
2329 if (!doProxy) newProps.insert("proxy", "-");
2330 for (int i = 0; i < list.count(); i++) {
2331 listItem = list.at(i);
2332 if (listItem->type() == PROJECTFOLDERTYPE) {
2333 for (int j = 0; j < listItem->childCount(); j++) {
2334 QTreeWidgetItem *sub = listItem->child(j);
2335 if (!list.contains(sub)) list.append(sub);
2338 if (listItem->type() == PROJECTCLIPTYPE) {
2339 ProjectItem *item = static_cast <ProjectItem*>(listItem);
2340 CLIPTYPE t = item->clipType();
2341 if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE) && item->referencedClip()) {
2342 oldProps = item->referencedClip()->properties();
2345 QString path = proxydir + item->referencedClip()->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
2346 newProps.insert("proxy", path);
2347 // insert required duration for proxy
2348 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
2349 // We need to insert empty proxy so that undo will work
2350 oldProps.insert("proxy", QString());
2352 new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
2356 if (command->childCount() > 0) {
2357 m_doc->commandStack()->push(command);
2359 else delete command;
2360 //if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
2363 void ProjectList::setProxyStatus(const QString id, PROXYSTATUS status)
2365 ProjectItem *item = getItemById(id);
2366 setProxyStatus(item, status);
2369 void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status)
2371 if (item == NULL) return;
2372 monitorItemEditing(false);
2373 item->setProxyStatus(status);
2374 monitorItemEditing(true);
2377 void ProjectList::monitorItemEditing(bool enable)
2379 if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2380 else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
2383 QStringList ProjectList::expandedFolders() const
2386 FolderProjectItem *item;
2387 QTreeWidgetItemIterator it(m_listView);
2389 if ((*it)->type() != PROJECTFOLDERTYPE) {
2393 if ((*it)->isExpanded()) {
2394 item = static_cast<FolderProjectItem *>(*it);
2395 result.append(item->clipId());
2402 #include "projectlist.moc"