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>
44 #include <KIO/NetAccess>
47 #include <nepomuk/global.h>
48 #include <nepomuk/resourcemanager.h>
49 //#include <nepomuk/tag.h>
51 #include <QMouseEvent>
52 #include <QStylePainter>
57 #include <QHeaderView>
59 ProjectList::ProjectList(QWidget *parent) :
68 m_transcodeAction(NULL),
75 m_listView = new ProjectListView(this);;
76 QVBoxLayout *layout = new QVBoxLayout;
77 layout->setContentsMargins(0, 0, 0, 0);
80 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
81 m_toolbar = new QToolBar("projectToolBar", this);
82 m_toolbar->addWidget(searchView);
83 searchView->setTreeWidget(m_listView);
85 m_addButton = new QToolButton(m_toolbar);
86 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
87 m_toolbar->addWidget(m_addButton);
89 layout->addWidget(m_toolbar);
90 layout->addWidget(m_listView);
93 m_queueTimer.setInterval(100);
94 connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue()));
95 m_queueTimer.setSingleShot(true);
99 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
100 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
101 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
102 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
103 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
104 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
105 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
106 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
108 m_listViewDelegate = new ItemDelegate(m_listView);
109 m_listView->setItemDelegate(m_listViewDelegate);
111 if (KdenliveSettings::activate_nepomuk()) {
112 Nepomuk::ResourceManager::instance()->init();
113 if (!Nepomuk::ResourceManager::instance()->initialized()) {
114 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
115 KdenliveSettings::setActivate_nepomuk(false);
120 ProjectList::~ProjectList()
124 m_listView->blockSignals(true);
126 delete m_listViewDelegate;
129 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
131 QList <QAction *> actions = addMenu->actions();
132 for (int i = 0; i < actions.count(); i++) {
133 if (actions.at(i)->data().toString() == "clip_properties") {
134 m_editAction = actions.at(i);
135 m_toolbar->addAction(m_editAction);
138 } else if (actions.at(i)->data().toString() == "delete_clip") {
139 m_deleteAction = actions.at(i);
140 m_toolbar->addAction(m_deleteAction);
143 } else if (actions.at(i)->data().toString() == "edit_clip") {
144 m_openAction = actions.at(i);
147 } else if (actions.at(i)->data().toString() == "reload_clip") {
148 m_reloadAction = actions.at(i);
154 QMenu *m = new QMenu();
155 m->addActions(actions);
156 m_addButton->setMenu(m);
157 m_addButton->setDefaultAction(defaultAction);
158 m_menu = new QMenu();
159 m_menu->addActions(addMenu->actions());
162 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
164 if (!addMenu) return;
165 QMenu *menu = m_addButton->menu();
166 menu->addMenu(addMenu);
167 m_addButton->setMenu(menu);
169 m_menu->addMenu(addMenu);
170 if (addMenu->isEmpty()) addMenu->setEnabled(false);
171 m_menu->addMenu(transcodeMenu);
172 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
173 m_transcodeAction = transcodeMenu;
174 m_menu->addAction(m_reloadAction);
175 m_menu->addAction(m_editAction);
176 m_menu->addAction(m_openAction);
177 m_menu->addAction(m_deleteAction);
178 m_menu->insertSeparator(m_deleteAction);
182 QByteArray ProjectList::headerInfo() const
184 return m_listView->header()->saveState();
187 void ProjectList::setHeaderInfo(const QByteArray &state)
189 m_listView->header()->restoreState(state);
192 void ProjectList::slotEditClip()
194 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
195 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
196 if (item && !item->isGroup()) {
197 emit clipSelected(item->referencedClip());
198 emit showClipProperties(item->referencedClip());
202 void ProjectList::slotOpenClip()
204 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
205 if (item && !item->isGroup()) {
206 if (item->clipType() == IMAGE) {
207 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
208 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
210 if (item->clipType() == AUDIO) {
211 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
212 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
217 void ProjectList::cleanup()
219 m_listView->clearSelection();
220 QTreeWidgetItemIterator it(m_listView);
223 item = static_cast <ProjectItem *>(*it);
224 if (item->numReferences() == 0) item->setSelected(true);
230 void ProjectList::trashUnusedClips()
232 QTreeWidgetItemIterator it(m_listView);
237 item = static_cast <ProjectItem *>(*it);
238 if (item->numReferences() == 0) {
239 ids << item->clipId();
240 KUrl url = item->clipUrl();
241 if (!url.isEmpty()) urls << url;
245 m_doc->deleteProjectClip(ids);
246 for (int i = 0; i < urls.count(); i++) {
247 KIO::NetAccess::del(urls.at(i), this);
251 void ProjectList::slotReloadClip(const QString &id)
253 QList<QTreeWidgetItem *> selected;
254 if (id.isEmpty()) selected = m_listView->selectedItems();
255 else selected.append(getItemById(id));
257 for (int i = 0; i < selected.count(); i++) {
258 item = static_cast <ProjectItem *>(selected.at(i));
259 if (item && !item->isGroup()) {
260 if (item->clipType() == IMAGE) {
261 item->referencedClip()->producer()->set("force_reload", 1);
262 } else if (item->clipType() == TEXT) {
263 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
265 //requestClipInfo(item->toXml(), item->clipId(), true);
266 // Clear the file_hash value, which will cause a complete reload of the clip
267 emit getFileProperties(item->toXml(), item->clipId(), true);
272 void ProjectList::setRenderer(Render *projectRender)
274 m_render = projectRender;
275 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
278 void ProjectList::slotClipSelected()
280 if (m_listView->currentItem()) {
281 ProjectItem *clip = static_cast <ProjectItem*>(m_listView->currentItem());
282 if (!clip->isGroup()) {
283 m_selectedItem = clip;
284 emit clipSelected(clip->referencedClip());
286 m_editAction->setEnabled(true);
287 m_deleteAction->setEnabled(true);
288 m_reloadAction->setEnabled(true);
289 m_transcodeAction->setEnabled(true);
290 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
291 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
292 m_openAction->setEnabled(true);
293 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
294 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
295 m_openAction->setEnabled(true);
296 } else m_openAction->setEnabled(false);
298 emit clipSelected(NULL);
299 m_editAction->setEnabled(false);
300 m_deleteAction->setEnabled(false);
301 m_openAction->setEnabled(false);
302 m_reloadAction->setEnabled(false);
303 m_transcodeAction->setEnabled(false);
307 void ProjectList::slotPauseMonitor()
309 if (m_render) m_render->pause();
312 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
314 ProjectItem *item = getItemById(id);
316 slotUpdateClipProperties(item, properties);
317 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
318 slotRefreshClipThumbnail(item);
321 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
325 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
328 if (!clip->isGroup()) clip->setProperties(properties);
329 if (properties.contains("name")) {
330 m_listView->blockSignals(true);
331 clip->setText(1, properties.value("name"));
332 m_listView->blockSignals(false);
333 emit clipNameChanged(clip->clipId(), properties.value("name"));
335 if (properties.contains("description")) {
336 CLIPTYPE type = clip->clipType();
337 m_listView->blockSignals(true);
338 clip->setText(2, properties.value("description"));
339 m_listView->blockSignals(false);
340 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
341 // Use Nepomuk system to store clip description
342 Nepomuk::Resource f(clip->clipUrl().path());
343 f.setDescription(properties.value("description"));
345 emit projectModified();
349 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
351 ProjectItem *clip = static_cast <ProjectItem*>(item);
353 if (clip->referencedClip()) {
354 QMap <QString, QString> oldprops;
355 QMap <QString, QString> newprops;
356 oldprops["description"] = clip->referencedClip()->getProperty("description");
357 newprops["description"] = item->text(2);
359 if (clip->clipType() == TEXT) {
360 // This is a text template clip, update the image
361 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
362 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
363 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
364 newprops.insert("templatetext", item->text(2));
367 slotUpdateClipProperties(clip->clipId(), newprops);
368 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
369 m_commandStack->push(command);
371 } else if (column == 1) {
372 if (clip->isGroup()) {
373 editFolder(item->text(1), clip->groupName(), clip->clipId());
374 clip->setGroupName(item->text(1));
375 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
376 const int children = item->childCount();
377 for (int i = 0; i < children; i++) {
378 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
379 child->setProperty("groupname", item->text(1));
382 if (clip->referencedClip()) {
383 QMap <QString, QString> oldprops;
384 QMap <QString, QString> newprops;
385 oldprops["name"] = clip->referencedClip()->getProperty("name");
386 newprops["name"] = item->text(1);
387 slotUpdateClipProperties(clip, newprops);
388 emit projectModified();
389 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
390 m_commandStack->push(command);
396 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
402 m_editAction->setEnabled(enable);
403 m_deleteAction->setEnabled(enable);
404 m_reloadAction->setEnabled(enable);
405 m_transcodeAction->setEnabled(enable);
407 ProjectItem *clip = static_cast <ProjectItem*>(item);
408 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
409 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
410 m_openAction->setEnabled(true);
411 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
412 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
413 m_openAction->setEnabled(true);
414 } else m_openAction->setEnabled(false);
415 } else m_openAction->setEnabled(false);
419 void ProjectList::slotRemoveClip()
421 if (!m_listView->currentItem()) return;
423 QMap <QString, QString> folderids;
424 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
426 for (int i = 0; i < selected.count(); i++) {
427 item = static_cast <ProjectItem *>(selected.at(i));
428 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
429 else ids << item->clipId();
430 if (item->numReferences() > 0) {
431 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;
432 } else if (item->isGroup() && item->childCount() > 0) {
433 int children = item->childCount();
434 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;
435 for (int i = 0; i < children; ++i) {
436 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
437 ids << child->clipId();
441 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
442 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
443 if (m_listView->topLevelItemCount() == 0) {
444 m_editAction->setEnabled(false);
445 m_deleteAction->setEnabled(false);
446 m_openAction->setEnabled(false);
447 m_reloadAction->setEnabled(false);
448 m_transcodeAction->setEnabled(false);
452 void ProjectList::selectItemById(const QString &clipId)
454 ProjectItem *item = getItemById(clipId);
455 if (item) m_listView->setCurrentItem(item);
459 void ProjectList::slotDeleteClip(const QString &clipId)
461 ProjectItem *item = getItemById(clipId);
463 kDebug() << "/// Cannot find clip to delete";
466 m_listView->blockSignals(true);
468 m_doc->clipManager()->deleteClip(clipId);
469 m_listView->blockSignals(false);
474 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
476 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
477 m_commandStack->push(command);
478 m_doc->setModified(true);
481 void ProjectList::slotAddFolder()
483 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
484 m_commandStack->push(command);
487 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
490 ProjectItem *item = getFolderItemById(clipId);
492 m_doc->clipManager()->deleteFolder(clipId);
497 ProjectItem *item = getFolderItemById(clipId);
499 m_listView->blockSignals(true);
500 item->setGroupName(foldername);
501 m_listView->blockSignals(false);
502 m_doc->clipManager()->addFolder(clipId, foldername);
503 const int children = item->childCount();
504 for (int i = 0; i < children; i++) {
505 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
506 child->setProperty("groupname", foldername);
511 text << QString() << foldername;
512 m_listView->blockSignals(true);
513 m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId));
514 m_doc->clipManager()->addFolder(clipId, foldername);
515 m_listView->blockSignals(false);
522 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
524 QMapIterator<QString, QString> i(map);
525 QUndoCommand *delCommand = new QUndoCommand();
526 delCommand->setText(i18n("Delete Folder"));
527 while (i.hasNext()) {
529 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
531 m_commandStack->push(delCommand);
532 m_doc->setModified(true);
535 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
537 m_listView->setEnabled(false);
539 m_listView->blockSignals(true);
541 // remove file_hash so that we load all properties for the clip
542 QDomElement e = clip->toXML().cloneNode().toElement();
543 e.removeAttribute("file_hash");
544 m_infoQueue.insert(clip->getId(), e);
545 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
547 const QString parent = clip->getProperty("groupid");
548 kDebug() << "Adding clip with groupid: " << parent;
549 ProjectItem *item = NULL;
550 if (!parent.isEmpty()) {
551 ProjectItem *parentitem = getFolderItemById(parent);
554 QString groupName = clip->getProperty("groupname");
555 //kDebug() << "Adding clip to new group: " << groupName;
556 if (groupName.isEmpty()) groupName = i18n("Folder");
557 text << QString() << groupName;
558 parentitem = new ProjectItem(m_listView, text, parent);
560 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
562 if (parentitem) item = new ProjectItem(parentitem, clip);
564 if (item == NULL) item = new ProjectItem(m_listView, clip);
565 KUrl url = clip->fileURL();
567 if (getProperties == false && !clip->getClipHash().isEmpty()) {
568 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
569 if (QFile::exists(cachedPixmap)) {
570 item->setIcon(0, QPixmap(cachedPixmap));
574 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
575 // if file has Nepomuk comment, use it
576 Nepomuk::Resource f(url.path());
577 QString annotation = f.description();
578 if (!annotation.isEmpty()) item->setText(2, annotation);
579 item->setText(3, QString::number(f.rating()));
581 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
582 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
585 void ProjectList::slotResetProjectList()
588 emit clipSelected(NULL);
589 m_thumbnailQueue.clear();
594 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
597 m_infoQueue.insert(id, xml);
598 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
601 void ProjectList::slotProcessNextClipInQueue()
603 if (m_infoQueue.isEmpty()) {
604 slotProcessNextThumbnail();
608 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
609 if (j != m_infoQueue.constEnd()) {
610 const QDomElement dom = j.value();
611 const QString id = j.key();
612 m_infoQueue.remove(j.key());
613 emit getFileProperties(dom, id, false);
616 if (!m_infoQueue.isEmpty() && !m_queueTimer.isActive()) m_queueTimer.start();
619 void ProjectList::slotUpdateClip(const QString &id)
621 ProjectItem *item = getItemById(id);
622 m_listView->blockSignals(true);
623 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
624 m_listView->blockSignals(false);
627 void ProjectList::updateAllClips()
629 m_listView->setSortingEnabled(false);
631 QTreeWidgetItemIterator it(m_listView);
634 m_listView->blockSignals(true);
636 item = static_cast <ProjectItem *>(*it);
637 if (!item->isGroup()) {
638 clip = item->referencedClip();
639 if (item->referencedClip()->producer() == NULL) {
640 if (clip->isPlaceHolder() == false) {
641 requestClipInfo(clip->toXML(), clip->getId());
642 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
644 if (item->icon(0).isNull()) {
645 requestClipThumbnail(clip->getId());
647 if (item->data(1, DurationRole).toString().isEmpty()) {
648 item->changeDuration(item->referencedClip()->producer()->get_playtime());
651 item->setData(1, UsageRole, QString::number(item->numReferences()));
652 //qApp->processEvents();
656 qApp->processEvents();
657 if (!m_queueTimer.isActive()) m_queueTimer.start();
659 if (m_listView->isEnabled()) m_listView->blockSignals(false);
660 m_listView->setSortingEnabled(true);
661 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
664 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
666 if (!m_commandStack) {
667 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
670 if (givenList.isEmpty()) {
671 // Build list of mime types
672 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";
674 QString allExtensions;
675 foreach(const QString& mimeType, mimeTypes) {
676 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
678 allExtensions.append(mime->patterns().join(" "));
679 allExtensions.append(' ');
682 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
683 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
686 for (int i = 0; i < givenList.count(); i++)
687 list << givenList.at(i);
689 if (list.isEmpty()) return;
691 if (givenList.isEmpty()) {
692 QStringList groupInfo = getGroup();
693 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
694 } else m_doc->slotAddClipList(list, groupName, groupId);
697 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
699 ProjectItem *item = getItemById(id);
700 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
702 const QString path = item->referencedClip()->fileURL().path();
703 if (!path.isEmpty()) {
704 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
706 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;
711 if (replace) m_doc->deleteProjectClip(ids);
715 void ProjectList::slotAddColorClip()
717 if (!m_commandStack) {
718 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
720 QDialog *dia = new QDialog(this);
721 Ui::ColorClip_UI dia_ui;
723 dia_ui.clip_name->setText(i18n("Color Clip"));
724 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
725 if (dia->exec() == QDialog::Accepted) {
726 QString color = dia_ui.clip_color->color().name();
727 color = color.replace(0, 1, "0x") + "ff";
728 QStringList groupInfo = getGroup();
729 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
735 void ProjectList::slotAddSlideshowClip()
737 if (!m_commandStack) {
738 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
740 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
742 if (dia->exec() == QDialog::Accepted) {
743 QStringList groupInfo = getGroup();
744 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));
749 void ProjectList::slotAddTitleClip()
751 QStringList groupInfo = getGroup();
752 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
755 void ProjectList::slotAddTitleTemplateClip()
757 QStringList groupInfo = getGroup();
758 if (!m_commandStack) {
759 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
762 // Get the list of existing templates
764 filter << "*.kdenlivetitle";
765 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
766 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
768 QDialog *dia = new QDialog(this);
769 Ui::TemplateClip_UI dia_ui;
771 for (int i = 0; i < templateFiles.size(); ++i) {
772 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
774 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
775 //warning: setting base directory doesn't work??
777 dia_ui.template_list->fileDialog()->setUrl(startDir);
778 dia_ui.text_box->setHidden(true);
779 if (dia->exec() == QDialog::Accepted) {
780 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
781 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
782 // Create a cloned template clip
783 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
788 QStringList ProjectList::getGroup() const
791 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
792 if (item && !item->isGroup()) {
793 while (item->parent()) {
794 item = static_cast <ProjectItem*>(item->parent());
795 if (item->isGroup()) break;
798 if (item && item->isGroup()) {
799 result << item->groupName();
800 result << item->clipId();
801 } else result << QString() << QString();
805 void ProjectList::setDocument(KdenliveDoc *doc)
807 m_listView->blockSignals(true);
809 m_listView->setSortingEnabled(false);
810 emit clipSelected(NULL);
811 m_thumbnailQueue.clear();
815 m_timecode = doc->timecode();
816 m_commandStack = doc->commandStack();
819 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
820 QMapIterator<QString, QString> f(flist);
821 while (f.hasNext()) {
823 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
826 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
827 for (int i = 0; i < list.count(); i++) {
828 slotAddClip(list.at(i), false);
831 m_listView->blockSignals(false);
832 m_toolbar->setEnabled(true);
833 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
834 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
837 QDomElement ProjectList::producersList()
840 QDomElement prods = doc.createElement("producerlist");
841 doc.appendChild(prods);
842 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
843 QTreeWidgetItemIterator it(m_listView);
845 if (!((ProjectItem *)(*it))->isGroup())
846 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
852 void ProjectList::slotCheckForEmptyQueue()
854 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
856 emit loadingIsOver();
857 emit displayMessage(QString(), DefaultMessage);
858 m_listView->blockSignals(false);
859 m_listView->setEnabled(true);
860 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
863 void ProjectList::reloadClipThumbnails()
865 m_thumbnailQueue.clear();
866 QTreeWidgetItemIterator it(m_listView);
868 if (!((ProjectItem *)(*it))->isGroup())
869 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
872 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
875 void ProjectList::requestClipThumbnail(const QString id)
877 m_thumbnailQueue.append(id);
880 void ProjectList::slotProcessNextThumbnail()
882 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
883 slotCheckForEmptyQueue();
886 if (!m_infoQueue.isEmpty()) {
887 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
890 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
891 if (m_thumbnailQueue.count() > 1) {
892 emit displayMessage(i18n("Loading clips (%1)", m_thumbnailQueue.count()), InformationMessage);
893 qApp->processEvents();
897 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
899 ProjectItem *item = getItemById(clipId);
900 if (item) slotRefreshClipThumbnail(item, update);
901 else slotProcessNextThumbnail();
904 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
907 DocClipBase *clip = item->referencedClip();
909 slotProcessNextThumbnail();
914 int width = (int)(height * m_render->dar());
915 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
916 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
917 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
919 m_listView->blockSignals(true);
920 item->setIcon(0, pix);
921 if (m_listView->isEnabled()) m_listView->blockSignals(false);
922 m_doc->cachePixmap(item->getClipHash(), pix);
924 if (update) emit projectModified();
925 QTimer::singleShot(100, this, SLOT(slotProcessNextThumbnail()));
929 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
931 ProjectItem *item = getItemById(clipId);
932 if (item && producer) {
933 m_listView->blockSignals(true);
934 item->setProperties(properties, metadata);
935 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
936 item->referencedClip()->setProducer(producer, replace);
937 emit receivedClipDuration(clipId);
938 if (m_listView->isEnabled() && replace) {
939 // update clip in clip monitor
940 emit clipSelected(NULL);
941 emit clipSelected(item->referencedClip());
944 // Check if duration changed.
945 emit receivedClipDuration(clipId);
948 if (m_listView->isEnabled()) m_listView->blockSignals(false);
949 if (item->icon(0).isNull()) {
950 requestClipThumbnail(clipId);
952 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
954 slotProcessNextClipInQueue();
957 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
959 ProjectItem *item = getItemById(clipId);
960 if (item && !pix.isNull()) {
961 m_listView->blockSignals(true);
962 item->setIcon(0, pix);
963 m_doc->cachePixmap(item->getClipHash(), pix);
964 if (m_listView->isEnabled()) m_listView->blockSignals(false);
968 ProjectItem *ProjectList::getItemById(const QString &id)
971 QTreeWidgetItemIterator it(m_listView);
973 item = static_cast<ProjectItem *>(*it);
974 if (item->clipId() == id && item->clipType() != FOLDER)
981 ProjectItem *ProjectList::getFolderItemById(const QString &id)
984 QTreeWidgetItemIterator it(m_listView);
986 item = static_cast<ProjectItem *>(*it);
987 if (item->clipId() == id && item->clipType() == FOLDER)
994 void ProjectList::slotSelectClip(const QString &ix)
996 ProjectItem *clip = getItemById(ix);
998 m_listView->setCurrentItem(clip);
999 m_listView->scrollToItem(clip);
1000 m_editAction->setEnabled(true);
1001 m_deleteAction->setEnabled(true);
1002 m_reloadAction->setEnabled(true);
1003 m_transcodeAction->setEnabled(true);
1004 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1005 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1006 m_openAction->setEnabled(true);
1007 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1008 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1009 m_openAction->setEnabled(true);
1010 } else m_openAction->setEnabled(false);
1014 QString ProjectList::currentClipUrl() const
1016 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
1017 if (item == NULL) return QString();
1018 return item->clipUrl().path();
1021 void ProjectList::regenerateTemplate(const QString &id)
1023 ProjectItem *clip = getItemById(id);
1024 if (clip) regenerateTemplate(clip);
1027 void ProjectList::regenerateTemplate(ProjectItem *clip)
1029 //TODO: remove this unused method, only force_reload is necessary
1030 clip->referencedClip()->producer()->set("force_reload", 1);
1033 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1037 if (!file.open(QIODevice::ReadOnly)) {
1038 kWarning() << "ERROR, CANNOT READ: " << path;
1041 if (!doc.setContent(&file)) {
1042 kWarning() << "ERROR, CANNOT READ: " << path;
1047 QDomNodeList texts = doc.elementsByTagName("content");
1048 for (int i = 0; i < texts.count(); i++) {
1049 QString data = texts.item(i).firstChild().nodeValue();
1050 data.replace("%s", replaceString);
1051 texts.item(i).firstChild().setNodeValue(data);
1056 #include "projectlist.moc"