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 "editclipcommand.h"
35 #include "editfoldercommand.h"
36 #include "ui_templateclip_ui.h"
41 #include <KFileDialog>
42 #include <KInputDialog>
43 #include <KMessageBox>
45 #include <nepomuk/global.h>
46 #include <nepomuk/resourcemanager.h>
47 //#include <nepomuk/tag.h>
49 #include <QMouseEvent>
50 #include <QStylePainter>
55 #include <QHeaderView>
57 ProjectList::ProjectList(QWidget *parent) :
66 m_transcodeAction(NULL),
73 m_listView = new ProjectListView(this);;
74 QVBoxLayout *layout = new QVBoxLayout;
75 layout->setContentsMargins(0, 0, 0, 0);
78 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
79 m_toolbar = new QToolBar("projectToolBar", this);
80 m_toolbar->addWidget(searchView);
81 searchView->setTreeWidget(m_listView);
83 m_addButton = new QToolButton(m_toolbar);
84 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
85 m_toolbar->addWidget(m_addButton);
87 layout->addWidget(m_toolbar);
88 layout->addWidget(m_listView);
91 m_queueTimer.setInterval(100);
92 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
93 m_queueTimer.setSingleShot(true);
97 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
98 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
99 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
100 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
101 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
102 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
103 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
104 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
106 m_listViewDelegate = new ItemDelegate(m_listView);
107 m_listView->setItemDelegate(m_listViewDelegate);
109 if (KdenliveSettings::activate_nepomuk()) {
110 Nepomuk::ResourceManager::instance()->init();
111 if (!Nepomuk::ResourceManager::instance()->initialized()) {
112 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
113 KdenliveSettings::setActivate_nepomuk(false);
118 ProjectList::~ProjectList()
122 m_listView->blockSignals(true);
124 delete m_listViewDelegate;
127 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
129 QList <QAction *> actions = addMenu->actions();
130 for (int i = 0; i < actions.count(); i++) {
131 if (actions.at(i)->data().toString() == "clip_properties") {
132 m_editAction = actions.at(i);
133 m_toolbar->addAction(m_editAction);
136 } else if (actions.at(i)->data().toString() == "delete_clip") {
137 m_deleteAction = actions.at(i);
138 m_toolbar->addAction(m_deleteAction);
141 } else if (actions.at(i)->data().toString() == "edit_clip") {
142 m_openAction = actions.at(i);
145 } else if (actions.at(i)->data().toString() == "reload_clip") {
146 m_reloadAction = actions.at(i);
152 QMenu *m = new QMenu();
153 m->addActions(actions);
154 m_addButton->setMenu(m);
155 m_addButton->setDefaultAction(defaultAction);
156 m_menu = new QMenu();
157 m_menu->addActions(addMenu->actions());
160 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
162 if (!addMenu) return;
163 QMenu *menu = m_addButton->menu();
164 menu->addMenu(addMenu);
165 m_addButton->setMenu(menu);
167 m_menu->addMenu(addMenu);
168 if (addMenu->isEmpty()) addMenu->setEnabled(false);
169 m_menu->addMenu(transcodeMenu);
170 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
171 m_transcodeAction = transcodeMenu;
172 m_menu->addAction(m_reloadAction);
173 m_menu->addAction(m_editAction);
174 m_menu->addAction(m_openAction);
175 m_menu->addAction(m_deleteAction);
176 m_menu->insertSeparator(m_deleteAction);
180 QByteArray ProjectList::headerInfo() const
182 return m_listView->header()->saveState();
185 void ProjectList::setHeaderInfo(const QByteArray &state)
187 m_listView->header()->restoreState(state);
190 void ProjectList::slotEditClip()
192 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
193 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
194 if (item && !item->isGroup()) {
195 emit clipSelected(item->referencedClip());
196 emit showClipProperties(item->referencedClip());
200 void ProjectList::slotOpenClip()
202 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
203 if (item && !item->isGroup()) {
204 if (item->clipType() == IMAGE) {
205 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
206 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
208 if (item->clipType() == AUDIO) {
209 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
210 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
215 void ProjectList::slotReloadClip(const QString &id)
217 QList<QTreeWidgetItem *> selected;
218 if (id.isEmpty()) selected = m_listView->selectedItems();
219 else selected.append(getItemById(id));
221 for (int i = 0; i < selected.count(); i++) {
222 item = static_cast <ProjectItem *>(selected.at(i));
223 if (item && !item->isGroup()) {
224 if (item->clipType() == IMAGE) {
225 item->referencedClip()->producer()->set("force_reload", 1);
226 } else if (item->clipType() == TEXT) {
227 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
229 //requestClipInfo(item->toXml(), item->clipId(), true);
230 // Clear the file_hash value, which will cause a complete reload of the clip
231 emit getFileProperties(item->toXml(), item->clipId(), true);
236 void ProjectList::setRenderer(Render *projectRender)
238 m_render = projectRender;
239 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
242 void ProjectList::slotClipSelected()
244 if (m_listView->currentItem()) {
245 ProjectItem *clip = static_cast <ProjectItem*>(m_listView->currentItem());
246 if (!clip->isGroup()) {
247 m_selectedItem = clip;
248 emit clipSelected(clip->referencedClip());
250 m_editAction->setEnabled(true);
251 m_deleteAction->setEnabled(true);
252 m_reloadAction->setEnabled(true);
253 m_transcodeAction->setEnabled(true);
254 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
255 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
256 m_openAction->setEnabled(true);
257 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
258 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
259 m_openAction->setEnabled(true);
260 } else m_openAction->setEnabled(false);
262 emit clipSelected(NULL);
263 m_editAction->setEnabled(false);
264 m_deleteAction->setEnabled(false);
265 m_openAction->setEnabled(false);
266 m_reloadAction->setEnabled(false);
267 m_transcodeAction->setEnabled(false);
271 void ProjectList::slotPauseMonitor()
273 if (m_render) m_render->pause();
276 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
278 ProjectItem *item = getItemById(id);
280 slotUpdateClipProperties(item, properties);
281 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
282 slotRefreshClipThumbnail(item);
285 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
289 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
292 if (!clip->isGroup()) clip->setProperties(properties);
293 if (properties.contains("name")) {
294 m_listView->blockSignals(true);
295 clip->setText(1, properties.value("name"));
296 m_listView->blockSignals(false);
297 emit clipNameChanged(clip->clipId(), properties.value("name"));
299 if (properties.contains("description")) {
300 CLIPTYPE type = clip->clipType();
301 m_listView->blockSignals(true);
302 clip->setText(2, properties.value("description"));
303 m_listView->blockSignals(false);
304 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
305 // Use Nepomuk system to store clip description
306 Nepomuk::Resource f(clip->clipUrl().path());
307 f.setDescription(properties.value("description"));
309 emit projectModified();
313 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
315 ProjectItem *clip = static_cast <ProjectItem*>(item);
317 if (clip->referencedClip()) {
318 QMap <QString, QString> oldprops;
319 QMap <QString, QString> newprops;
320 oldprops["description"] = clip->referencedClip()->getProperty("description");
321 newprops["description"] = item->text(2);
323 if (clip->clipType() == TEXT) {
324 // This is a text template clip, update the image
325 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
326 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
327 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
328 newprops.insert("templatetext", item->text(2));
331 slotUpdateClipProperties(clip->clipId(), newprops);
332 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
333 m_commandStack->push(command);
335 } else if (column == 1) {
336 if (clip->isGroup()) {
337 editFolder(item->text(1), clip->groupName(), clip->clipId());
338 clip->setGroupName(item->text(1));
339 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
340 const int children = item->childCount();
341 for (int i = 0; i < children; i++) {
342 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
343 child->setProperty("groupname", item->text(1));
346 if (clip->referencedClip()) {
347 QMap <QString, QString> oldprops;
348 QMap <QString, QString> newprops;
349 oldprops["name"] = clip->referencedClip()->getProperty("name");
350 newprops["name"] = item->text(1);
351 slotUpdateClipProperties(clip, newprops);
352 emit projectModified();
353 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
354 m_commandStack->push(command);
360 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
366 m_editAction->setEnabled(enable);
367 m_deleteAction->setEnabled(enable);
368 m_reloadAction->setEnabled(enable);
369 m_transcodeAction->setEnabled(enable);
371 ProjectItem *clip = static_cast <ProjectItem*>(item);
372 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
373 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
374 m_openAction->setEnabled(true);
375 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
376 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
377 m_openAction->setEnabled(true);
378 } else m_openAction->setEnabled(false);
379 } else m_openAction->setEnabled(false);
383 void ProjectList::slotRemoveClip()
385 if (!m_listView->currentItem()) return;
387 QMap <QString, QString> folderids;
388 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
390 for (int i = 0; i < selected.count(); i++) {
391 item = static_cast <ProjectItem *>(selected.at(i));
392 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
393 else ids << item->clipId();
394 if (item->numReferences() > 0) {
395 if (KMessageBox::questionYesNo(this, 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")) != KMessageBox::Yes) return;
396 } else if (item->isGroup() && item->childCount() > 0) {
397 int children = item->childCount();
398 if (KMessageBox::questionYesNo(this, 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, item->names().at(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
399 for (int i = 0; i < children; ++i) {
400 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
401 ids << child->clipId();
405 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
406 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
407 if (m_listView->topLevelItemCount() == 0) {
408 m_editAction->setEnabled(false);
409 m_deleteAction->setEnabled(false);
410 m_openAction->setEnabled(false);
411 m_reloadAction->setEnabled(false);
412 m_transcodeAction->setEnabled(false);
416 void ProjectList::selectItemById(const QString &clipId)
418 ProjectItem *item = getItemById(clipId);
419 if (item) m_listView->setCurrentItem(item);
423 void ProjectList::slotDeleteClip(const QString &clipId)
425 ProjectItem *item = getItemById(clipId);
427 kDebug() << "/// Cannot find clip to delete";
430 m_listView->blockSignals(true);
432 m_doc->clipManager()->deleteClip(clipId);
433 m_listView->blockSignals(false);
438 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
440 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
441 m_commandStack->push(command);
442 m_doc->setModified(true);
445 void ProjectList::slotAddFolder()
447 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
448 m_commandStack->push(command);
451 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
454 ProjectItem *item = getFolderItemById(clipId);
456 m_doc->clipManager()->deleteFolder(clipId);
461 ProjectItem *item = getFolderItemById(clipId);
463 m_listView->blockSignals(true);
464 item->setGroupName(foldername);
465 m_listView->blockSignals(false);
466 m_doc->clipManager()->addFolder(clipId, foldername);
467 const int children = item->childCount();
468 for (int i = 0; i < children; i++) {
469 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
470 child->setProperty("groupname", foldername);
475 text << QString() << foldername;
476 m_listView->blockSignals(true);
477 m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId));
478 m_doc->clipManager()->addFolder(clipId, foldername);
479 m_listView->blockSignals(false);
486 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
488 QMapIterator<QString, QString> i(map);
489 QUndoCommand *delCommand = new QUndoCommand();
490 delCommand->setText(i18n("Delete Folder"));
491 while (i.hasNext()) {
493 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
495 m_commandStack->push(delCommand);
496 m_doc->setModified(true);
499 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
501 m_listView->setEnabled(false);
503 m_listView->blockSignals(true);
505 m_infoQueue.insert(clip->getId(), clip->toXML());
506 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
508 const QString parent = clip->getProperty("groupid");
509 kDebug() << "Adding clip with groupid: " << parent;
510 ProjectItem *item = NULL;
511 if (!parent.isEmpty()) {
512 ProjectItem *parentitem = getFolderItemById(parent);
515 QString groupName = clip->getProperty("groupname");
516 //kDebug() << "Adding clip to new group: " << groupName;
517 if (groupName.isEmpty()) groupName = i18n("Folder");
518 text << QString() << groupName;
519 parentitem = new ProjectItem(m_listView, text, parent);
521 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
523 if (parentitem) item = new ProjectItem(parentitem, clip);
525 if (item == NULL) item = new ProjectItem(m_listView, clip);
526 KUrl url = clip->fileURL();
528 if (getProperties == false && !clip->getClipHash().isEmpty()) {
529 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
530 if (QFile::exists(cachedPixmap)) {
531 item->setIcon(0, QPixmap(cachedPixmap));
535 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
536 // if file has Nepomuk comment, use it
537 Nepomuk::Resource f(url.path());
538 QString annotation = f.description();
539 if (!annotation.isEmpty()) item->setText(2, annotation);
540 item->setText(3, QString::number(f.rating()));
542 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
543 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
546 void ProjectList::slotResetProjectList()
549 emit clipSelected(NULL);
550 m_thumbnailQueue.clear();
555 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
558 m_infoQueue.insert(id, xml);
559 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
562 void ProjectList::slotProcessNextClipInQueue()
564 if (m_infoQueue.isEmpty()) {
565 slotProcessNextThumbnail();
569 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
570 if (j != m_infoQueue.constEnd()) {
571 const QDomElement dom = j.value();
572 const QString id = j.key();
573 m_infoQueue.remove(j.key());
574 emit getFileProperties(dom, id, false);
577 if (!m_infoQueue.isEmpty() && !m_queueTimer.isActive()) m_queueTimer.start();
580 void ProjectList::slotUpdateClip(const QString &id)
582 ProjectItem *item = getItemById(id);
583 m_listView->blockSignals(true);
584 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
585 m_listView->blockSignals(false);
588 void ProjectList::updateAllClips()
590 m_listView->setSortingEnabled(false);
592 QTreeWidgetItemIterator it(m_listView);
595 m_listView->blockSignals(true);
597 item = static_cast <ProjectItem *>(*it);
598 if (!item->isGroup()) {
599 clip = item->referencedClip();
600 if (item->referencedClip()->producer() == NULL) {
601 if (clip->isPlaceHolder() == false) {
602 requestClipInfo(clip->toXML(), clip->getId());
603 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
605 if (item->icon(0).isNull()) {
606 requestClipThumbnail(clip->getId());
608 if (item->data(1, DurationRole).toString().isEmpty()) {
609 item->changeDuration(item->referencedClip()->producer()->get_playtime());
612 item->setData(1, UsageRole, QString::number(item->numReferences()));
613 //qApp->processEvents();
617 qApp->processEvents();
618 if (!m_queueTimer.isActive()) m_queueTimer.start();
620 if (m_listView->isEnabled()) m_listView->blockSignals(false);
621 m_listView->setSortingEnabled(true);
622 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
625 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
627 if (!m_commandStack) {
628 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
631 if (givenList.isEmpty()) {
632 // Build list of mime types
633 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mlt-playlist" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "video/mp4" << "video/quicktime" << "image/gif" << "image/jpeg" << "image/png" << "image/x-tga" << "image/x-bmp" << "image/svg+xml" << "image/tiff" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr";
635 QString allExtensions;
636 foreach(const QString& mimeType, mimeTypes) {
637 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
639 allExtensions.append(mime->patterns().join(" "));
640 allExtensions.append(' ');
643 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
644 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
647 for (int i = 0; i < givenList.count(); i++)
648 list << givenList.at(i);
650 if (list.isEmpty()) return;
652 if (givenList.isEmpty()) {
653 QStringList groupInfo = getGroup();
654 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
655 } else m_doc->slotAddClipList(list, groupName, groupId);
658 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
660 ProjectItem *item = getItemById(id);
661 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
663 const QString path = item->referencedClip()->fileURL().path();
664 if (!path.isEmpty()) {
665 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
667 if (KMessageBox::questionYesNo(this, i18n("Clip <b>%1</b><br>is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes) replace = true;
672 if (replace) m_doc->deleteProjectClip(ids);
676 void ProjectList::slotAddColorClip()
678 if (!m_commandStack) {
679 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
681 QDialog *dia = new QDialog(this);
682 Ui::ColorClip_UI dia_ui;
684 dia_ui.clip_name->setText(i18n("Color Clip"));
685 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
686 if (dia->exec() == QDialog::Accepted) {
687 QString color = dia_ui.clip_color->color().name();
688 color = color.replace(0, 1, "0x") + "ff";
689 QStringList groupInfo = getGroup();
690 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
696 void ProjectList::slotAddSlideshowClip()
698 if (!m_commandStack) {
699 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
701 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
703 if (dia->exec() == QDialog::Accepted) {
704 QStringList groupInfo = getGroup();
705 m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), groupInfo.at(0), groupInfo.at(1));
710 void ProjectList::slotAddTitleClip()
712 QStringList groupInfo = getGroup();
713 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
716 void ProjectList::slotAddTitleTemplateClip()
718 QStringList groupInfo = getGroup();
719 if (!m_commandStack) {
720 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
723 // Get the list of existing templates
725 filter << "*.kdenlivetitle";
726 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
727 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
729 QDialog *dia = new QDialog(this);
730 Ui::TemplateClip_UI dia_ui;
732 for (int i = 0; i < templateFiles.size(); ++i) {
733 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
735 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
736 //warning: setting base directory doesn't work??
738 dia_ui.template_list->fileDialog()->setUrl(startDir);
739 dia_ui.text_box->setHidden(true);
740 if (dia->exec() == QDialog::Accepted) {
741 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
742 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
743 // Create a cloned template clip
744 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
749 QStringList ProjectList::getGroup() const
752 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
753 if (item && !item->isGroup()) {
754 while (item->parent()) {
755 item = static_cast <ProjectItem*>(item->parent());
756 if (item->isGroup()) break;
759 if (item && item->isGroup()) {
760 result << item->groupName();
761 result << item->clipId();
762 } else result << QString() << QString();
766 void ProjectList::setDocument(KdenliveDoc *doc)
768 m_listView->blockSignals(true);
770 m_listView->setSortingEnabled(false);
771 emit clipSelected(NULL);
772 m_thumbnailQueue.clear();
776 m_timecode = doc->timecode();
777 m_commandStack = doc->commandStack();
780 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
781 QMapIterator<QString, QString> f(flist);
782 while (f.hasNext()) {
784 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
787 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
788 for (int i = 0; i < list.count(); i++) {
789 slotAddClip(list.at(i), false);
792 m_listView->blockSignals(false);
793 m_toolbar->setEnabled(true);
794 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
795 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
798 QDomElement ProjectList::producersList()
801 QDomElement prods = doc.createElement("producerlist");
802 doc.appendChild(prods);
803 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
804 QTreeWidgetItemIterator it(m_listView);
806 if (!((ProjectItem *)(*it))->isGroup())
807 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
813 void ProjectList::slotCheckForEmptyQueue()
815 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
817 emit loadingIsOver();
818 emit displayMessage(QString(), DefaultMessage);
819 m_listView->blockSignals(false);
820 m_listView->setEnabled(true);
821 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
824 void ProjectList::reloadClipThumbnails()
826 m_thumbnailQueue.clear();
827 QTreeWidgetItemIterator it(m_listView);
829 if (!((ProjectItem *)(*it))->isGroup())
830 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
833 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
836 void ProjectList::requestClipThumbnail(const QString id)
838 m_thumbnailQueue.append(id);
841 void ProjectList::slotProcessNextThumbnail()
843 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
844 slotCheckForEmptyQueue();
847 if (!m_infoQueue.isEmpty()) {
848 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
851 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
852 if (m_thumbnailQueue.count() > 1) {
853 emit displayMessage(i18n("Loading clips (%1)", m_thumbnailQueue.count()), InformationMessage);
854 qApp->processEvents();
858 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
860 ProjectItem *item = getItemById(clipId);
861 if (item) slotRefreshClipThumbnail(item, update);
862 else slotProcessNextThumbnail();
865 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
868 DocClipBase *clip = item->referencedClip();
870 slotProcessNextThumbnail();
875 int width = (int)(height * m_render->dar());
876 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
877 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
878 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
880 m_listView->blockSignals(true);
881 item->setIcon(0, pix);
882 if (m_listView->isEnabled()) m_listView->blockSignals(false);
883 m_doc->cachePixmap(item->getClipHash(), pix);
885 if (update) emit projectModified();
886 QTimer::singleShot(100, this, SLOT(slotProcessNextThumbnail()));
890 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
892 ProjectItem *item = getItemById(clipId);
893 if (item && producer) {
894 m_listView->blockSignals(true);
895 item->setProperties(properties, metadata);
896 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
897 item->referencedClip()->setProducer(producer, replace);
898 emit receivedClipDuration(clipId);
899 if (m_listView->isEnabled() && replace) {
900 // update clip in clip monitor
901 emit clipSelected(NULL);
902 emit clipSelected(item->referencedClip());
905 // Check if duration changed.
906 emit receivedClipDuration(clipId);
909 if (m_listView->isEnabled()) m_listView->blockSignals(false);
910 if (item->icon(0).isNull()) {
911 requestClipThumbnail(clipId);
913 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
915 slotProcessNextClipInQueue();
918 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
920 ProjectItem *item = getItemById(clipId);
921 if (item && !pix.isNull()) {
922 m_listView->blockSignals(true);
923 item->setIcon(0, pix);
924 m_doc->cachePixmap(item->getClipHash(), pix);
925 if (m_listView->isEnabled()) m_listView->blockSignals(false);
929 ProjectItem *ProjectList::getItemById(const QString &id)
932 QTreeWidgetItemIterator it(m_listView);
934 item = static_cast<ProjectItem *>(*it);
935 if (item->clipId() == id && item->clipType() != FOLDER)
942 ProjectItem *ProjectList::getFolderItemById(const QString &id)
945 QTreeWidgetItemIterator it(m_listView);
947 item = static_cast<ProjectItem *>(*it);
948 if (item->clipId() == id && item->clipType() == FOLDER)
955 void ProjectList::slotSelectClip(const QString &ix)
957 ProjectItem *clip = getItemById(ix);
959 m_listView->setCurrentItem(clip);
960 m_listView->scrollToItem(clip);
961 m_editAction->setEnabled(true);
962 m_deleteAction->setEnabled(true);
963 m_reloadAction->setEnabled(true);
964 m_transcodeAction->setEnabled(true);
965 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
966 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
967 m_openAction->setEnabled(true);
968 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
969 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
970 m_openAction->setEnabled(true);
971 } else m_openAction->setEnabled(false);
975 QString ProjectList::currentClipUrl() const
977 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
978 if (item == NULL) return QString();
979 return item->clipUrl().path();
982 void ProjectList::regenerateTemplate(const QString &id)
984 ProjectItem *clip = getItemById(id);
985 if (clip) regenerateTemplate(clip);
988 void ProjectList::regenerateTemplate(ProjectItem *clip)
990 //TODO: remove this unused method, only force_reload is necessary
991 clip->referencedClip()->producer()->set("force_reload", 1);
994 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
998 if (!file.open(QIODevice::ReadOnly)) {
999 kWarning() << "ERROR, CANNOT READ: " << path;
1002 if (!doc.setContent(&file)) {
1003 kWarning() << "ERROR, CANNOT READ: " << path;
1008 QDomNodeList texts = doc.elementsByTagName("content");
1009 for (int i = 0; i < texts.count(); i++) {
1010 QString data = texts.item(i).firstChild().nodeValue();
1011 data.replace("%s", replaceString);
1012 texts.item(i).firstChild().setNodeValue(data);
1017 #include "projectlist.moc"