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 ItemDelegate *listViewDelegate = new ItemDelegate(m_listView);
107 m_listView->setItemDelegate(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()
124 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
126 QList <QAction *> actions = addMenu->actions();
127 for (int i = 0; i < actions.count(); i++) {
128 if (actions.at(i)->data().toString() == "clip_properties") {
129 m_editAction = actions.at(i);
130 m_toolbar->addAction(m_editAction);
133 } else if (actions.at(i)->data().toString() == "delete_clip") {
134 m_deleteAction = actions.at(i);
135 m_toolbar->addAction(m_deleteAction);
138 } else if (actions.at(i)->data().toString() == "edit_clip") {
139 m_openAction = actions.at(i);
142 } else if (actions.at(i)->data().toString() == "reload_clip") {
143 m_reloadAction = actions.at(i);
149 QMenu *m = new QMenu();
150 m->addActions(actions);
151 m_addButton->setMenu(m);
152 m_addButton->setDefaultAction(defaultAction);
153 m_menu = new QMenu();
154 m_menu->addActions(addMenu->actions());
157 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
159 if (!addMenu) return;
160 QMenu *menu = m_addButton->menu();
161 menu->addMenu(addMenu);
162 m_addButton->setMenu(menu);
164 m_menu->addMenu(addMenu);
165 if (addMenu->isEmpty()) addMenu->setEnabled(false);
166 m_menu->addMenu(transcodeMenu);
167 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
168 m_transcodeAction = transcodeMenu;
169 m_menu->addAction(m_reloadAction);
170 m_menu->addAction(m_editAction);
171 m_menu->addAction(m_openAction);
172 m_menu->addAction(m_deleteAction);
173 m_menu->insertSeparator(m_deleteAction);
177 QByteArray ProjectList::headerInfo() const
179 return m_listView->header()->saveState();
182 void ProjectList::setHeaderInfo(const QByteArray &state)
184 m_listView->header()->restoreState(state);
187 void ProjectList::slotEditClip()
189 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
190 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
191 if (item && !item->isGroup()) {
192 emit clipSelected(item->referencedClip());
193 emit showClipProperties(item->referencedClip());
197 void ProjectList::slotOpenClip()
199 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
200 if (item && !item->isGroup()) {
201 if (item->clipType() == IMAGE) {
202 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
203 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
205 if (item->clipType() == AUDIO) {
206 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
207 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
212 void ProjectList::slotReloadClip(const QString &id)
214 QList<QTreeWidgetItem *> selected;
215 if (id.isEmpty()) selected = m_listView->selectedItems();
216 else selected.append(getItemById(id));
218 for (int i = 0; i < selected.count(); i++) {
219 item = static_cast <ProjectItem *>(selected.at(i));
220 if (item && !item->isGroup()) {
221 if (item->clipType() == IMAGE) {
222 item->referencedClip()->producer()->set("force_reload", 1);
223 } else if (item->clipType() == TEXT) {
224 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
226 //requestClipInfo(item->toXml(), item->clipId(), true);
227 // Clear the file_hash value, which will cause a complete reload of the clip
228 emit getFileProperties(item->toXml(), item->clipId(), true);
233 void ProjectList::setRenderer(Render *projectRender)
235 m_render = projectRender;
236 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
239 void ProjectList::slotClipSelected()
241 if (m_listView->currentItem()) {
242 ProjectItem *clip = static_cast <ProjectItem*>(m_listView->currentItem());
243 if (!clip->isGroup()) {
244 m_selectedItem = clip;
245 emit clipSelected(clip->referencedClip());
247 m_editAction->setEnabled(true);
248 m_deleteAction->setEnabled(true);
249 m_reloadAction->setEnabled(true);
250 m_transcodeAction->setEnabled(true);
251 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
252 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
253 m_openAction->setEnabled(true);
254 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
255 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
256 m_openAction->setEnabled(true);
257 } else m_openAction->setEnabled(false);
259 emit clipSelected(NULL);
260 m_editAction->setEnabled(false);
261 m_deleteAction->setEnabled(false);
262 m_openAction->setEnabled(false);
263 m_reloadAction->setEnabled(false);
264 m_transcodeAction->setEnabled(false);
268 void ProjectList::slotPauseMonitor()
270 if (m_render) m_render->pause();
273 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
275 ProjectItem *item = getItemById(id);
277 slotUpdateClipProperties(item, properties);
278 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) {
279 slotRefreshClipThumbnail(item);
282 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
286 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
289 if (!clip->isGroup()) clip->setProperties(properties);
290 //if (properties.contains("xmldata")) regenerateTemplateImage(clip);
291 if (properties.contains("name")) {
292 m_listView->blockSignals(true);
293 clip->setText(1, properties.value("name"));
294 m_listView->blockSignals(false);
295 emit clipNameChanged(clip->clipId(), properties.value("name"));
297 if (properties.contains("description")) {
298 CLIPTYPE type = clip->clipType();
299 m_listView->blockSignals(true);
300 clip->setText(2, properties.value("description"));
301 m_listView->blockSignals(false);
302 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
303 // Use Nepomuk system to store clip description
304 Nepomuk::Resource f(clip->clipUrl().path());
305 f.setDescription(properties.value("description"));
307 emit projectModified();
311 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
313 ProjectItem *clip = static_cast <ProjectItem*>(item);
315 if (clip->referencedClip()) {
316 QMap <QString, QString> oldprops;
317 QMap <QString, QString> newprops;
318 oldprops["description"] = clip->referencedClip()->getProperty("description");
319 newprops["description"] = item->text(2);
321 if (clip->clipType() == TEXT && !clip->referencedClip()->getProperty("xmldata").isEmpty()) {
322 // This is a text template clip, update the image
323 /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
324 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/
325 oldprops.insert("templatetext", clip->referencedClip()->getProperty("templatetext"));
326 newprops.insert("templatetext", item->text(2));
329 slotUpdateClipProperties(clip->clipId(), newprops);
330 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
331 m_commandStack->push(command);
333 } else if (column == 1) {
334 if (clip->isGroup()) {
335 editFolder(item->text(1), clip->groupName(), clip->clipId());
336 clip->setGroupName(item->text(1));
337 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
338 const int children = item->childCount();
339 for (int i = 0; i < children; i++) {
340 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
341 child->setProperty("groupname", item->text(1));
344 if (clip->referencedClip()) {
345 QMap <QString, QString> oldprops;
346 QMap <QString, QString> newprops;
347 oldprops["name"] = clip->referencedClip()->getProperty("name");
348 newprops["name"] = item->text(1);
349 slotUpdateClipProperties(clip, newprops);
350 emit projectModified();
351 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
352 m_commandStack->push(command);
358 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
364 m_editAction->setEnabled(enable);
365 m_deleteAction->setEnabled(enable);
366 m_reloadAction->setEnabled(enable);
367 m_transcodeAction->setEnabled(enable);
369 ProjectItem *clip = static_cast <ProjectItem*>(item);
370 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
371 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
372 m_openAction->setEnabled(true);
373 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
374 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
375 m_openAction->setEnabled(true);
376 } else m_openAction->setEnabled(false);
377 } else m_openAction->setEnabled(false);
381 void ProjectList::slotRemoveClip()
383 if (!m_listView->currentItem()) return;
385 QMap <QString, QString> folderids;
386 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
388 for (int i = 0; i < selected.count(); i++) {
389 item = static_cast <ProjectItem *>(selected.at(i));
390 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
391 else ids << item->clipId();
392 if (item->numReferences() > 0) {
393 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;
394 } else if (item->isGroup() && item->childCount() > 0) {
395 int children = item->childCount();
396 if (KMessageBox::questionYesNo(this, i18n("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;
397 for (int i = 0; i < children; ++i) {
398 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
399 ids << child->clipId();
403 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
404 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
405 if (m_listView->topLevelItemCount() == 0) {
406 m_editAction->setEnabled(false);
407 m_deleteAction->setEnabled(false);
408 m_openAction->setEnabled(false);
409 m_reloadAction->setEnabled(false);
410 m_transcodeAction->setEnabled(false);
414 void ProjectList::selectItemById(const QString &clipId)
416 ProjectItem *item = getItemById(clipId);
417 if (item) m_listView->setCurrentItem(item);
421 void ProjectList::slotDeleteClip(const QString &clipId)
423 ProjectItem *item = getItemById(clipId);
425 kDebug() << "/// Cannot find clip to delete";
428 m_listView->blockSignals(true);
430 m_doc->clipManager()->deleteClip(clipId);
431 m_listView->blockSignals(false);
436 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
438 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
439 m_commandStack->push(command);
440 m_doc->setModified(true);
443 void ProjectList::slotAddFolder()
445 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
446 m_commandStack->push(command);
449 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
452 ProjectItem *item = getFolderItemById(clipId);
454 m_doc->clipManager()->deleteFolder(clipId);
459 ProjectItem *item = getFolderItemById(clipId);
460 QTreeWidgetItemIterator it(m_listView);
462 m_listView->blockSignals(true);
463 item->setGroupName(foldername);
464 m_listView->blockSignals(false);
465 m_doc->clipManager()->addFolder(clipId, foldername);
466 const int children = item->childCount();
467 for (int i = 0; i < children; i++) {
468 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
469 child->setProperty("groupname", foldername);
474 text << QString() << foldername;
475 m_listView->blockSignals(true);
476 m_listView->setCurrentItem(new ProjectItem(m_listView, text, clipId));
477 m_doc->clipManager()->addFolder(clipId, foldername);
478 m_listView->blockSignals(false);
485 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
487 QMapIterator<QString, QString> i(map);
488 QUndoCommand *delCommand = new QUndoCommand();
489 delCommand->setText(i18n("Delete Folder"));
490 while (i.hasNext()) {
492 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
494 m_commandStack->push(delCommand);
495 m_doc->setModified(true);
498 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
500 if (getProperties) m_listView->setEnabled(false);
501 m_listView->blockSignals(true);
502 const QString parent = clip->getProperty("groupid");
503 kDebug() << "Adding clip with groupid: " << parent;
504 ProjectItem *item = NULL;
505 if (!parent.isEmpty()) {
506 ProjectItem *parentitem = getFolderItemById(parent);
509 QString groupName = clip->getProperty("groupname");
510 //kDebug() << "Adding clip to new group: " << groupName;
511 if (groupName.isEmpty()) groupName = i18n("Folder");
512 text << QString() << groupName;
513 parentitem = new ProjectItem(m_listView, text, parent);
515 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
517 if (parentitem) item = new ProjectItem(parentitem, clip);
519 if (item == NULL) item = new ProjectItem(m_listView, clip);
520 KUrl url = clip->fileURL();
522 if (getProperties == false && !clip->getClipHash().isEmpty()) {
523 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
524 if (QFile::exists(cachedPixmap)) {
525 item->setIcon(0, QPixmap(cachedPixmap));
529 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
530 // if file has Nepomuk comment, use it
531 Nepomuk::Resource f(url.path());
532 QString annotation = f.description();
533 if (!annotation.isEmpty()) item->setText(2, annotation);
534 item->setText(3, QString::number(f.rating()));
536 m_listView->blockSignals(false);
539 void ProjectList::slotResetProjectList()
542 emit clipSelected(NULL);
543 m_thumbnailQueue.clear();
548 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
550 m_infoQueue.insert(id, xml);
551 m_listView->setEnabled(false);
552 if (!m_queueTimer.isActive()) m_queueTimer.start();
553 //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
556 void ProjectList::slotProcessNextClipInQueue()
558 if (m_infoQueue.isEmpty()) {
559 slotProcessNextThumbnail();
563 QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
564 if (j != m_infoQueue.constEnd()) {
565 const QDomElement dom = j.value();
566 const QString id = j.key();
567 m_infoQueue.remove(j.key());
568 emit getFileProperties(dom, id, false);
570 if (!m_infoQueue.isEmpty()) m_queueTimer.start();
573 void ProjectList::slotUpdateClip(const QString &id)
575 ProjectItem *item = getItemById(id);
576 m_listView->blockSignals(true);
577 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
578 m_listView->blockSignals(false);
581 void ProjectList::updateAllClips()
583 QTreeWidgetItemIterator it(m_listView);
585 ProjectItem *item = static_cast <ProjectItem *>(*it);
586 if (!item->isGroup()) {
587 DocClipBase *clip = item->referencedClip();
588 /*if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
589 // regenerate text clip image if required
590 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
592 doc.setContent(clip->getProperty("xmldata"));
594 QImage pix = dia_ui->renderedPixmap();
595 pix.save(clip->fileURL().path());
599 if (item->referencedClip()->producer() == NULL) {
600 if (clip->isPlaceHolder() == false) requestClipInfo(clip->toXML(), clip->getId());
601 else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
603 if (item->icon(0).isNull()) {
604 requestClipThumbnail(clip->getId());
606 if (item->data(1, DurationRole).toString().isEmpty()) {
607 m_listView->blockSignals(true);
608 item->changeDuration(item->referencedClip()->producer()->get_playtime());
609 m_listView->blockSignals(false);
612 m_listView->blockSignals(true);
613 item->setData(1, UsageRole, QString::number(item->numReferences()));
614 m_listView->blockSignals(false);
615 qApp->processEvents();
619 if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
622 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
624 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
626 if (givenList.isEmpty()) {
627 // Build list of mime types
628 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";
630 QString allExtensions;
631 foreach(const QString& mimeType, mimeTypes) {
632 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
634 allExtensions.append(mime->patterns().join(" "));
635 allExtensions.append(' ');
638 QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files");
639 dialogFilter.append("\n*" + QLatin1Char('|') + i18n("All Files"));
640 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
643 for (int i = 0; i < givenList.count(); i++)
644 list << givenList.at(i);
646 if (list.isEmpty()) return;
648 if (givenList.isEmpty()) {
649 QStringList groupInfo = getGroup();
650 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
651 } else m_doc->slotAddClipList(list, groupName, groupId);
654 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
656 ProjectItem *item = getItemById(id);
657 QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
659 const QString path = item->referencedClip()->fileURL().path();
660 if (!path.isEmpty()) {
661 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
663 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;
668 if (replace) m_doc->deleteProjectClip(ids);
672 void ProjectList::slotAddColorClip()
674 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
675 QDialog *dia = new QDialog(this);
676 Ui::ColorClip_UI dia_ui;
678 dia_ui.clip_name->setText(i18n("Color Clip"));
679 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
680 if (dia->exec() == QDialog::Accepted) {
681 QString color = dia_ui.clip_color->color().name();
682 color = color.replace(0, 1, "0x") + "ff";
683 QStringList groupInfo = getGroup();
684 m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
690 void ProjectList::slotAddSlideshowClip()
692 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
693 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
695 if (dia->exec() == QDialog::Accepted) {
696 QStringList groupInfo = getGroup();
697 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));
702 void ProjectList::slotAddTitleClip()
704 QStringList groupInfo = getGroup();
705 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
708 void ProjectList::slotAddTitleTemplateClip()
710 QStringList groupInfo = getGroup();
711 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
713 // Get the list of existing templates
715 filter << "*.kdenlivetitle";
716 const QString path = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
717 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
719 QDialog *dia = new QDialog(this);
720 Ui::TemplateClip_UI dia_ui;
722 for (int i = 0; i < templateFiles.size(); ++i) {
723 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
725 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
726 //warning: setting base directory doesn't work??
728 dia_ui.template_list->fileDialog()->setUrl(startDir);
729 dia_ui.description->setHidden(true);
730 if (dia->exec() == QDialog::Accepted) {
731 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
732 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
733 if (dia_ui.normal_clip->isChecked()) {
734 // Create a normal title clip
735 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1), textTemplate);
737 // Create a cloned template clip
738 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
744 QStringList ProjectList::getGroup() const
747 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
748 if (item && !item->isGroup()) {
749 while (item->parent()) {
750 item = static_cast <ProjectItem*>(item->parent());
751 if (item->isGroup()) break;
754 if (item && item->isGroup()) {
755 result << item->groupName();
756 result << item->clipId();
757 } else result << QString() << QString();
761 void ProjectList::setDocument(KdenliveDoc *doc)
763 m_listView->blockSignals(true);
765 emit clipSelected(NULL);
766 m_thumbnailQueue.clear();
770 m_timecode = doc->timecode();
771 m_commandStack = doc->commandStack();
774 connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &)));
776 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
777 QMapIterator<QString, QString> f(flist);
778 while (f.hasNext()) {
780 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
783 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
784 for (int i = 0; i < list.count(); i++) {
785 slotAddClip(list.at(i), false);
788 m_listView->blockSignals(false);
789 m_toolbar->setEnabled(true);
792 QDomElement ProjectList::producersList()
795 QDomElement prods = doc.createElement("producerlist");
796 doc.appendChild(prods);
797 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
798 QTreeWidgetItemIterator it(m_listView);
800 if (!((ProjectItem *)(*it))->isGroup())
801 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
807 void ProjectList::slotCheckForEmptyQueue()
809 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
811 emit loadingIsOver();
812 } else QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
815 void ProjectList::reloadClipThumbnails()
817 m_thumbnailQueue.clear();
818 QTreeWidgetItemIterator it(m_listView);
820 if (!((ProjectItem *)(*it))->isGroup())
821 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
824 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
827 void ProjectList::requestClipThumbnail(const QString id)
829 m_thumbnailQueue.append(id);
832 void ProjectList::slotProcessNextThumbnail()
834 if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
835 m_listView->setEnabled(true);
836 slotCheckForEmptyQueue();
839 if (!m_infoQueue.isEmpty()) {
840 //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
843 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
846 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
848 ProjectItem *item = getItemById(clipId);
849 if (item) slotRefreshClipThumbnail(item, update);
850 else slotProcessNextThumbnail();
853 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
857 int width = (int)(height * m_render->dar());
858 DocClipBase *clip = item->referencedClip();
859 if (!clip) slotProcessNextThumbnail();
861 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
862 else if (clip->clipType() == TEXT || clip->clipType() == IMAGE) pix = KThumb::getFrame(item->referencedClip()->producer(), 0, width, height);
863 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
865 m_listView->blockSignals(true);
866 item->setIcon(0, pix);
867 m_listView->blockSignals(false);
868 m_doc->cachePixmap(item->getClipHash(), pix);
870 if (update) emit projectModified();
871 QTimer::singleShot(100, this, SLOT(slotProcessNextThumbnail()));
875 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
877 ProjectItem *item = getItemById(clipId);
878 if (item && producer) {
879 m_listView->blockSignals(true);
880 item->setProperties(properties, metadata);
881 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
882 item->referencedClip()->setProducer(producer, replace);
883 emit receivedClipDuration(clipId);
885 // update clip in clip monitor
886 emit clipSelected(NULL);
887 emit clipSelected(item->referencedClip());
890 // Check if duration changed.
891 emit receivedClipDuration(clipId);
894 m_listView->blockSignals(false);
895 if (item->icon(0).isNull()) {
896 requestClipThumbnail(clipId);
898 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
900 slotProcessNextClipInQueue();
903 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
905 ProjectItem *item = getItemById(clipId);
906 if (item && !pix.isNull()) {
907 m_listView->blockSignals(true);
908 item->setIcon(0, pix);
909 m_doc->cachePixmap(item->getClipHash(), pix);
910 m_listView->blockSignals(false);
914 ProjectItem *ProjectList::getItemById(const QString &id)
917 QTreeWidgetItemIterator it(m_listView);
919 item = static_cast<ProjectItem *>(*it);
920 if (item->clipId() == id && item->clipType() != FOLDER)
927 ProjectItem *ProjectList::getFolderItemById(const QString &id)
930 QTreeWidgetItemIterator it(m_listView);
932 item = static_cast<ProjectItem *>(*it);
933 if (item->clipId() == id && item->clipType() == FOLDER)
940 void ProjectList::slotSelectClip(const QString &ix)
942 ProjectItem *clip = getItemById(ix);
944 m_listView->setCurrentItem(clip);
945 m_listView->scrollToItem(clip);
946 m_editAction->setEnabled(true);
947 m_deleteAction->setEnabled(true);
948 m_reloadAction->setEnabled(true);
949 m_transcodeAction->setEnabled(true);
950 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
951 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
952 m_openAction->setEnabled(true);
953 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
954 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
955 m_openAction->setEnabled(true);
956 } else m_openAction->setEnabled(false);
960 QString ProjectList::currentClipUrl() const
962 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
963 if (item == NULL) return QString();
964 return item->clipUrl().path();
967 void ProjectList::regenerateTemplate(const QString &id)
969 ProjectItem *clip = getItemById(id);
970 if (clip) regenerateTemplate(clip);
973 void ProjectList::regenerateTemplate(ProjectItem *clip)
975 //TODO: remove this unused method, only force_reload is necessary
976 // Generate image for template clip
977 /*const QString comment = clip->referencedClip()->getProperty("description");
978 const QString path = clip->referencedClip()->getProperty("resource");
979 QDomDocument doc = generateTemplateXml(path, comment);
980 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
982 QImage pix = dia_ui->renderedPixmap();
983 pix.save(clip->clipUrl().path());
985 clip->referencedClip()->producer()->set("force_reload", 1);
988 void ProjectList::regenerateTemplateImage(ProjectItem *clip)
990 //TODO: remove this unused method
991 // Generate image for template clip
992 /*TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
994 doc.setContent(clip->referencedClip()->getProperty("xmldata"));
996 QImage pix = dia_ui->renderedPixmap();
997 pix.save(clip->clipUrl().path());
1001 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
1005 if (!file.open(QIODevice::ReadOnly)) {
1006 kWarning() << "ERROR, CANNOT READ: " << path;
1009 if (!doc.setContent(&file)) {
1010 kWarning() << "ERROR, CANNOT READ: " << path;
1015 QDomNodeList texts = doc.elementsByTagName("content");
1016 for (int i = 0; i < texts.count(); i++) {
1017 QString data = texts.item(i).firstChild().nodeValue();
1018 data.replace("%s", replaceString);
1019 texts.item(i).firstChild().setNodeValue(data);
1024 #include "projectlist.moc"