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->isGroup() && item->numReferences() == 0) item->setSelected(true);
230 void ProjectList::trashUnusedClips()
232 QTreeWidgetItemIterator it(m_listView);
237 item = static_cast <ProjectItem *>(*it);
238 if (!item->isGroup() && item->numReferences() == 0) {
239 ids << item->clipId();
240 KUrl url = item->clipUrl();
241 if (!url.isEmpty()) urls << url;
245 // Check that we don't use the URL in another clip
246 QTreeWidgetItemIterator it2(m_listView);
248 item = static_cast <ProjectItem *>(*it2);
249 if (item->numReferences() > 0) {
250 KUrl url = item->clipUrl();
251 if (!url.isEmpty() && urls.contains(url)) urls.removeAll(url);
256 m_doc->deleteProjectClip(ids);
257 for (int i = 0; i < urls.count(); i++) {
258 KIO::NetAccess::del(urls.at(i), this);
262 void ProjectList::slotReloadClip(const QString &id)
264 QList<QTreeWidgetItem *> selected;
265 if (id.isEmpty()) selected = m_listView->selectedItems();
266 else selected.append(getItemById(id));
268 for (int i = 0; i < selected.count(); i++) {
269 item = static_cast <ProjectItem *>(selected.at(i));
270 if (item && !item->isGroup()) {
271 if (item->clipType() == IMAGE) {
272 item->referencedClip()->producer()->set("force_reload", 1);
273 } else if (item->clipType() == TEXT) {
274 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
276 //requestClipInfo(item->toXml(), item->clipId(), true);
277 // Clear the file_hash value, which will cause a complete reload of the clip
278 emit getFileProperties(item->toXml(), item->clipId(), true);
283 void ProjectList::setRenderer(Render *projectRender)
285 m_render = projectRender;
286 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
289 void ProjectList::slotClipSelected()
291 if (m_listView->currentItem()) {
292 ProjectItem *clip = static_cast <ProjectItem*>(m_listView->currentItem());
293 if (!clip->isGroup()) {
294 m_selectedItem = clip;
295 emit clipSelected(clip->referencedClip());
297 m_editAction->setEnabled(true);
298 m_deleteAction->setEnabled(true);
299 m_reloadAction->setEnabled(true);
300 m_transcodeAction->setEnabled(true);
301 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
302 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
303 m_openAction->setEnabled(true);
304 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
305 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
306 m_openAction->setEnabled(true);
307 } else m_openAction->setEnabled(false);
309 emit clipSelected(NULL);
310 m_editAction->setEnabled(false);
311 m_deleteAction->setEnabled(false);
312 m_openAction->setEnabled(false);
313 m_reloadAction->setEnabled(false);
314 m_transcodeAction->setEnabled(false);
318 void ProjectList::slotPauseMonitor()
320 if (m_render) m_render->pause();
323 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
325 ProjectItem *item = getItemById(id);
327 slotUpdateClipProperties(item, properties);
328 if (properties.contains("out")) {
330 } else if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
331 slotRefreshClipThumbnail(item);
337 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
340 if (!clip->isGroup()) clip->setProperties(properties);
341 if (properties.contains("name")) {
342 m_listView->blockSignals(true);
343 clip->setText(1, properties.value("name"));
344 m_listView->blockSignals(false);
345 emit clipNameChanged(clip->clipId(), properties.value("name"));
347 if (properties.contains("description")) {
348 CLIPTYPE type = clip->clipType();
349 m_listView->blockSignals(true);
350 clip->setText(2, properties.value("description"));
351 m_listView->blockSignals(false);
352 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
353 // Use Nepomuk system to store clip description
354 Nepomuk::Resource f(clip->clipUrl().path());
355 f.setDescription(properties.value("description"));
357 emit projectModified();
361 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
363 ProjectItem *clip = static_cast <ProjectItem*>(item);
365 if (clip->referencedClip()) {
366 QMap <QString, QString> oldprops;
367 QMap <QString, QString> newprops;
368 oldprops["description"] = clip->referencedClip()->getProperty("description");
369 newprops["description"] = item->text(2);
371 if (clip->clipType() == TEXT) {
372 // This is a text template clip, update the image
373 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
374 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
375 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
376 newprops.insert("templatetext", item->text(2));
378 slotUpdateClipProperties(clip->clipId(), newprops);
379 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
380 m_commandStack->push(command);
382 } else if (column == 1) {
383 if (clip->isGroup()) {
384 editFolder(item->text(1), clip->groupName(), clip->clipId());
385 clip->setGroupName(item->text(1));
386 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
387 const int children = item->childCount();
388 for (int i = 0; i < children; i++) {
389 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
390 child->setProperty("groupname", item->text(1));
393 if (clip->referencedClip()) {
394 QMap <QString, QString> oldprops;
395 QMap <QString, QString> newprops;
396 oldprops["name"] = clip->referencedClip()->getProperty("name");
397 newprops["name"] = item->text(1);
398 slotUpdateClipProperties(clip, newprops);
399 emit projectModified();
400 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
401 m_commandStack->push(command);
407 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
413 m_editAction->setEnabled(enable);
414 m_deleteAction->setEnabled(enable);
415 m_reloadAction->setEnabled(enable);
416 m_transcodeAction->setEnabled(enable);
418 ProjectItem *clip = static_cast <ProjectItem*>(item);
419 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
420 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
421 m_openAction->setEnabled(true);
422 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
423 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
424 m_openAction->setEnabled(true);
425 } else m_openAction->setEnabled(false);
426 } else m_openAction->setEnabled(false);
430 void ProjectList::slotRemoveClip()
432 if (!m_listView->currentItem()) return;
434 QMap <QString, QString> folderids;
435 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
437 for (int i = 0; i < selected.count(); i++) {
438 item = static_cast <ProjectItem *>(selected.at(i));
439 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
440 else ids << item->clipId();
441 if (item->numReferences() > 0) {
442 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;
443 } else if (item->isGroup() && item->childCount() > 0) {
444 int children = item->childCount();
445 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;
446 for (int i = 0; i < children; ++i) {
447 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
448 ids << child->clipId();
452 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
453 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
454 if (m_listView->topLevelItemCount() == 0) {
455 m_editAction->setEnabled(false);
456 m_deleteAction->setEnabled(false);
457 m_openAction->setEnabled(false);
458 m_reloadAction->setEnabled(false);
459 m_transcodeAction->setEnabled(false);
463 void ProjectList::selectItemById(const QString &clipId)
465 ProjectItem *item = getItemById(clipId);
466 if (item) m_listView->setCurrentItem(item);
470 void ProjectList::slotDeleteClip(const QString &clipId)
472 ProjectItem *item = getItemById(clipId);
474 kDebug() << "/// Cannot find clip to delete";
477 m_listView->blockSignals(true);
479 m_doc->clipManager()->deleteClip(clipId);
480 m_listView->blockSignals(false);
485 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
487 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
488 m_commandStack->push(command);
489 m_doc->setModified(true);
492 void ProjectList::slotAddFolder()
494 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
495 m_commandStack->push(command);
498 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
501 ProjectItem *item = getFolderItemById(clipId);
503 m_doc->clipManager()->deleteFolder(clipId);
508 ProjectItem *item = getFolderItemById(clipId);
510 m_listView->blockSignals(true);
511 item->setGroupName(foldername);
512 m_listView->blockSignals(false);
513 m_doc->clipManager()->addFolder(clipId, foldername);
514 const int children = item->childCount();
515 for (int i = 0; i < children; i++) {
516 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
517 child->setProperty("groupname", foldername);
522 text << QString() << foldername;
523 m_listView->blockSignals(true);
524 m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId));
525 m_doc->clipManager()->addFolder(clipId, foldername);
526 m_listView->blockSignals(false);
533 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
535 QMapIterator<QString, QString> i(map);
536 QUndoCommand *delCommand = new QUndoCommand();
537 delCommand->setText(i18n("Delete Folder"));
538 while (i.hasNext()) {
540 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
542 m_commandStack->push(delCommand);
543 m_doc->setModified(true);
546 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
548 m_listView->setEnabled(false);
550 m_listView->blockSignals(true);
552 // remove file_hash so that we load all properties for the clip
553 QDomElement e = clip->toXML().cloneNode().toElement();
554 e.removeAttribute("file_hash");
555 m_infoQueue.insert(clip->getId(), e);
556 //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
558 const QString parent = clip->getProperty("groupid");
559 ProjectItem *item = NULL;
560 if (!parent.isEmpty()) {
561 ProjectItem *parentitem = getFolderItemById(parent);
564 QString groupName = clip->getProperty("groupname");
565 //kDebug() << "Adding clip to new group: " << groupName;
566 if (groupName.isEmpty()) groupName = i18n("Folder");
567 text << QString() << groupName;
568 parentitem = new ProjectItem(m_listView, text, parent);
570 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
572 if (parentitem) item = new ProjectItem(parentitem, clip);
574 if (item == NULL) item = new ProjectItem(m_listView, clip);
575 KUrl url = clip->fileURL();
577 if (getProperties == false && !clip->getClipHash().isEmpty()) {
578 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
579 if (QFile::exists(cachedPixmap)) {
580 item->setIcon(0, QPixmap(cachedPixmap));
584 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
585 // if file has Nepomuk comment, use it
586 Nepomuk::Resource f(url.path());
587 QString annotation = f.description();
588 if (!annotation.isEmpty()) item->setText(2, annotation);
589 item->setText(3, QString::number(f.rating()));
591 if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
592 if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
595 void ProjectList::slotResetProjectList()
598 emit clipSelected(NULL);
599 m_thumbnailQueue.clear();
604 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
607 m_infoQueue.insert(id, xml);
608 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
611 void ProjectList::slotProcessNextClipInQueue()
613 if (m_infoQueue.isEmpty()) {
614 slotProcessNextThumbnail();
618 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
619 if (j != m_infoQueue.constEnd()) {
620 const QDomElement dom = j.value();
621 const QString id = j.key();
622 m_infoQueue.remove(j.key());
623 emit getFileProperties(dom, id, false);
625 //if (!m_infoQueue.isEmpty() && !m_queueTimer.isActive()) m_queueTimer.start();
628 void ProjectList::slotUpdateClip(const QString &id)
630 ProjectItem *item = getItemById(id);
631 m_listView->blockSignals(true);
632 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
633 m_listView->blockSignals(false);
636 void ProjectList::updateAllClips()
638 m_listView->setSortingEnabled(false);
640 QTreeWidgetItemIterator it(m_listView);
643 m_listView->blockSignals(true);
645 item = static_cast <ProjectItem *>(*it);
646 if (!item->isGroup()) {
647 clip = item->referencedClip();
648 if (item->referencedClip()->producer() == NULL) {
649 if (clip->isPlaceHolder() == false) {
650 requestClipInfo(clip->toXML(), clip->getId());
651 } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
653 if (item->icon(0).isNull()) {
654 requestClipThumbnail(clip->getId());
656 if (item->data(1, DurationRole).toString().isEmpty()) {
657 item->changeDuration(item->referencedClip()->producer()->get_playtime());
660 item->setData(1, UsageRole, QString::number(item->numReferences()));
661 //qApp->processEvents();
665 qApp->processEvents();
666 if (!m_queueTimer.isActive()) m_queueTimer.start();
668 if (m_listView->isEnabled()) m_listView->blockSignals(false);
669 m_listView->setSortingEnabled(true);
670 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
673 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
675 if (!m_commandStack) {
676 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
679 if (givenList.isEmpty()) {
680 // Build list of mime types
681 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";
683 QString allExtensions;
684 foreach(const QString& mimeType, mimeTypes) {
685 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
687 allExtensions.append(mime->patterns().join(" "));
688 allExtensions.append(' ');
691 const QString dialogFilter = allExtensions.simplified() + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
692 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
695 for (int i = 0; i < givenList.count(); i++)
696 list << givenList.at(i);
698 if (list.isEmpty()) return;
700 if (givenList.isEmpty()) {
701 QStringList groupInfo = getGroup();
702 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
703 } else m_doc->slotAddClipList(list, groupName, groupId);
706 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
708 ProjectItem *item = getItemById(id);
709 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
711 const QString path = item->referencedClip()->fileURL().path();
712 if (!path.isEmpty()) {
713 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
715 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;
720 if (replace) m_doc->deleteProjectClip(ids);
724 void ProjectList::slotAddColorClip()
726 if (!m_commandStack) {
727 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
729 QDialog *dia = new QDialog(this);
730 Ui::ColorClip_UI dia_ui;
732 dia_ui.clip_name->setText(i18n("Color Clip"));
733 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
734 if (dia->exec() == QDialog::Accepted) {
735 QString color = dia_ui.clip_color->color().name();
736 color = color.replace(0, 1, "0x") + "ff";
737 QStringList groupInfo = getGroup();
738 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
744 void ProjectList::slotAddSlideshowClip()
746 if (!m_commandStack) {
747 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
749 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
751 if (dia->exec() == QDialog::Accepted) {
752 QStringList groupInfo = getGroup();
753 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));
758 void ProjectList::slotAddTitleClip()
760 QStringList groupInfo = getGroup();
761 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
764 void ProjectList::slotAddTitleTemplateClip()
766 QStringList groupInfo = getGroup();
767 if (!m_commandStack) {
768 kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
771 // Get the list of existing templates
773 filter << "*.kdenlivetitle";
774 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
775 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
777 QDialog *dia = new QDialog(this);
778 Ui::TemplateClip_UI dia_ui;
780 for (int i = 0; i < templateFiles.size(); ++i) {
781 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
783 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
784 //warning: setting base directory doesn't work??
786 dia_ui.template_list->fileDialog()->setUrl(startDir);
787 dia_ui.text_box->setHidden(true);
788 if (dia->exec() == QDialog::Accepted) {
789 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
790 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
791 // Create a cloned template clip
792 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
797 QStringList ProjectList::getGroup() const
800 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
801 if (item && !item->isGroup()) {
802 while (item->parent()) {
803 item = static_cast <ProjectItem*>(item->parent());
804 if (item->isGroup()) break;
807 if (item && item->isGroup()) {
808 result << item->groupName();
809 result << item->clipId();
810 } else result << QString() << QString();
814 void ProjectList::setDocument(KdenliveDoc *doc)
816 m_listView->blockSignals(true);
818 m_listView->setSortingEnabled(false);
819 emit clipSelected(NULL);
820 m_thumbnailQueue.clear();
824 m_timecode = doc->timecode();
825 m_commandStack = doc->commandStack();
828 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
829 QMapIterator<QString, QString> f(flist);
830 while (f.hasNext()) {
832 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
835 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
836 for (int i = 0; i < list.count(); i++) {
837 slotAddClip(list.at(i), false);
840 m_listView->blockSignals(false);
841 m_toolbar->setEnabled(true);
842 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
843 connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
846 QDomElement ProjectList::producersList()
849 QDomElement prods = doc.createElement("producerlist");
850 doc.appendChild(prods);
851 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
852 QTreeWidgetItemIterator it(m_listView);
854 if (!((ProjectItem *)(*it))->isGroup())
855 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
861 void ProjectList::slotCheckForEmptyQueue()
863 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
865 emit loadingIsOver();
866 emit displayMessage(QString(), -1);
867 m_listView->blockSignals(false);
868 m_listView->setEnabled(true);
869 } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
872 void ProjectList::reloadClipThumbnails()
874 kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!";
875 m_thumbnailQueue.clear();
876 QTreeWidgetItemIterator it(m_listView);
878 if (!((ProjectItem *)(*it))->isGroup())
879 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
882 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
885 void ProjectList::requestClipThumbnail(const QString id)
887 if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
890 void ProjectList::slotProcessNextThumbnail()
892 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
893 slotCheckForEmptyQueue();
896 if (!m_infoQueue.isEmpty()) {
897 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
900 if (m_thumbnailQueue.count() > 1) {
901 int max = m_doc->clipManager()->clipsCount();
902 emit displayMessage(i18n("Loading thumbnails"), (int)(100 * (max - m_thumbnailQueue.count()) / max));
904 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
907 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
909 ProjectItem *item = getItemById(clipId);
910 if (item) slotRefreshClipThumbnail(item, update);
911 else slotProcessNextThumbnail();
914 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
917 DocClipBase *clip = item->referencedClip();
919 slotProcessNextThumbnail();
924 int width = (int)(height * m_render->dar());
925 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
926 else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
927 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
929 m_listView->blockSignals(true);
930 item->setIcon(0, pix);
931 if (m_listView->isEnabled()) m_listView->blockSignals(false);
932 m_doc->cachePixmap(item->getClipHash(), pix);
934 if (update) emit projectModified();
935 QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail()));
939 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
941 ProjectItem *item = getItemById(clipId);
942 if (item && producer) {
943 m_listView->blockSignals(true);
944 item->setProperties(properties, metadata);
945 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
946 item->referencedClip()->setProducer(producer, replace);
947 //emit receivedClipDuration(clipId);
948 if (m_listView->isEnabled() && replace) {
949 // update clip in clip monitor
950 emit clipSelected(NULL);
951 emit clipSelected(item->referencedClip());
954 // Check if duration changed.
955 emit receivedClipDuration(clipId);
958 if (m_listView->isEnabled()) m_listView->blockSignals(false);
959 if (item->icon(0).isNull()) {
960 requestClipThumbnail(clipId);
962 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
963 int max = m_doc->clipManager()->clipsCount();
964 emit displayMessage(i18n("Loading clips"), (int)(100 * (max - m_infoQueue.count()) / max));
965 // small delay so that the app can display the progress info
966 QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
969 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
971 ProjectItem *item = getItemById(clipId);
972 if (item && !pix.isNull()) {
973 m_listView->blockSignals(true);
974 item->setIcon(0, pix);
975 m_doc->cachePixmap(item->getClipHash(), pix);
976 if (m_listView->isEnabled()) m_listView->blockSignals(false);
980 ProjectItem *ProjectList::getItemById(const QString &id)
983 QTreeWidgetItemIterator it(m_listView);
985 item = static_cast<ProjectItem *>(*it);
986 if (item->clipId() == id && item->clipType() != FOLDER)
993 ProjectItem *ProjectList::getFolderItemById(const QString &id)
996 QTreeWidgetItemIterator it(m_listView);
998 item = static_cast<ProjectItem *>(*it);
999 if (item->clipId() == id && item->clipType() == FOLDER)
1006 void ProjectList::slotSelectClip(const QString &ix)
1008 ProjectItem *clip = getItemById(ix);
1010 m_listView->setCurrentItem(clip);
1011 m_listView->scrollToItem(clip);
1012 m_editAction->setEnabled(true);
1013 m_deleteAction->setEnabled(true);
1014 m_reloadAction->setEnabled(true);
1015 m_transcodeAction->setEnabled(true);
1016 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
1017 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
1018 m_openAction->setEnabled(true);
1019 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
1020 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
1021 m_openAction->setEnabled(true);
1022 } else m_openAction->setEnabled(false);
1026 QString ProjectList::currentClipUrl() const
1028 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
1029 if (item == NULL) return QString();
1030 return item->clipUrl().path();
1033 void ProjectList::regenerateTemplate(const QString &id)
1035 ProjectItem *clip = getItemById(id);
1036 if (clip) regenerateTemplate(clip);
1039 void ProjectList::regenerateTemplate(ProjectItem *clip)
1041 //TODO: remove this unused method, only force_reload is necessary
1042 clip->referencedClip()->producer()->set("force_reload", 1);
1045 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1049 if (!file.open(QIODevice::ReadOnly)) {
1050 kWarning() << "ERROR, CANNOT READ: " << path;
1053 if (!doc.setContent(&file)) {
1054 kWarning() << "ERROR, CANNOT READ: " << path;
1059 QDomNodeList texts = doc.elementsByTagName("content");
1060 for (int i = 0; i < texts.count(); i++) {
1061 QString data = texts.item(i).firstChild().nodeValue();
1062 data.replace("%s", replaceString);
1063 texts.item(i).firstChild().setNodeValue(data);
1068 #include "projectlist.moc"