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) :
72 m_listView = new ProjectListView(this);;
73 QVBoxLayout *layout = new QVBoxLayout;
74 layout->setContentsMargins(0, 0, 0, 0);
77 KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this);
78 m_toolbar = new QToolBar("projectToolBar", this);
79 m_toolbar->addWidget(searchView);
80 searchView->setTreeWidget(m_listView);
82 m_addButton = new QToolButton(m_toolbar);
83 m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
84 m_toolbar->addWidget(m_addButton);
86 layout->addWidget(m_toolbar);
87 layout->addWidget(m_listView);
92 connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
93 connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected()));
94 connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
95 connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
96 connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
97 connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
98 connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
99 connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
101 ItemDelegate *listViewDelegate = new ItemDelegate(m_listView);
102 m_listView->setItemDelegate(listViewDelegate);
104 if (KdenliveSettings::activate_nepomuk()) {
105 Nepomuk::ResourceManager::instance()->init();
106 if (!Nepomuk::ResourceManager::instance()->initialized()) {
107 kDebug() << "Cannot communicate with Nepomuk, DISABLING it";
108 KdenliveSettings::setActivate_nepomuk(false);
113 ProjectList::~ProjectList()
119 void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
121 QList <QAction *> actions = addMenu->actions();
122 for (int i = 0; i < actions.count(); i++) {
123 if (actions.at(i)->data().toString() == "clip_properties") {
124 m_editAction = actions.at(i);
125 m_toolbar->addAction(m_editAction);
128 } else if (actions.at(i)->data().toString() == "delete_clip") {
129 m_deleteAction = actions.at(i);
130 m_toolbar->addAction(m_deleteAction);
133 } else if (actions.at(i)->data().toString() == "edit_clip") {
134 m_openAction = actions.at(i);
137 } else if (actions.at(i)->data().toString() == "reload_clip") {
138 m_reloadAction = actions.at(i);
144 QMenu *m = new QMenu();
145 m->addActions(actions);
146 m_addButton->setMenu(m);
147 m_addButton->setDefaultAction(defaultAction);
148 m_menu = new QMenu();
149 m_menu->addActions(addMenu->actions());
152 void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu)
154 if (!addMenu) return;
155 QMenu *menu = m_addButton->menu();
156 menu->addMenu(addMenu);
157 m_addButton->setMenu(menu);
159 m_menu->addMenu(addMenu);
160 if (addMenu->isEmpty()) addMenu->setEnabled(false);
161 m_menu->addMenu(transcodeMenu);
162 if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false);
163 m_menu->addAction(m_reloadAction);
164 m_menu->addAction(m_editAction);
165 m_menu->addAction(m_openAction);
166 m_menu->addAction(m_deleteAction);
167 m_menu->insertSeparator(m_deleteAction);
171 QByteArray ProjectList::headerInfo() const
173 return m_listView->header()->saveState();
176 void ProjectList::setHeaderInfo(const QByteArray &state)
178 m_listView->header()->restoreState(state);
181 void ProjectList::slotEditClip()
183 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
184 if (!(item->flags() & Qt::ItemIsDragEnabled)) return;
185 if (item && !item->isGroup()) {
186 emit clipSelected(item->referencedClip());
187 emit showClipProperties(item->referencedClip());
191 void ProjectList::slotOpenClip()
193 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
194 if (item && !item->isGroup()) {
195 if (item->clipType() == IMAGE) {
196 if (KdenliveSettings::defaultimageapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog"));
197 else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path());
199 if (item->clipType() == AUDIO) {
200 if (KdenliveSettings::defaultaudioapp().isEmpty()) KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog"));
201 else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path());
206 void ProjectList::slotReloadClip()
208 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
210 for (int i = 0; i < selected.count(); i++) {
211 item = static_cast <ProjectItem *>(selected.at(i));
212 if (item && !item->isGroup()) {
213 if (item->clipType() == IMAGE) {
214 item->referencedClip()->producer()->set("force_reload", 1);
215 } else if (item->clipType() == TEXT) {
216 if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item);
218 //requestClipInfo(item->toXml(), item->clipId(), true);
219 emit getFileProperties(item->toXml(), item->clipId(), true);
224 void ProjectList::setRenderer(Render *projectRender)
226 m_render = projectRender;
227 m_listView->setIconSize(QSize(40 * m_render->dar(), 40));
230 void ProjectList::slotClipSelected()
232 if (m_listView->currentItem()) {
233 ProjectItem *clip = static_cast <ProjectItem*>(m_listView->currentItem());
234 if (!clip->isGroup()) {
235 m_selectedItem = clip;
236 emit clipSelected(clip->referencedClip());
238 m_editAction->setEnabled(true);
239 m_deleteAction->setEnabled(true);
240 m_reloadAction->setEnabled(true);
241 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
242 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
243 m_openAction->setEnabled(true);
244 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
245 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
246 m_openAction->setEnabled(true);
247 } else m_openAction->setEnabled(false);
249 emit clipSelected(NULL);
250 m_editAction->setEnabled(false);
251 m_deleteAction->setEnabled(false);
252 m_openAction->setEnabled(false);
253 m_reloadAction->setEnabled(false);
257 void ProjectList::slotPauseMonitor()
259 if (m_render) m_render->pause();
262 void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties)
264 ProjectItem *item = getItemById(id);
266 slotUpdateClipProperties(item, properties);
267 if (properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio")) {
268 slotRefreshClipThumbnail(item);
271 if (properties.contains("out")) item->changeDuration(properties.value("out").toInt());
275 void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QString> properties)
278 if (!clip->isGroup()) clip->setProperties(properties);
279 if (properties.contains("xmldata")) regenerateTemplateImage(clip);
280 if (properties.contains("name")) {
281 m_listView->blockSignals(true);
282 clip->setText(1, properties.value("name"));
283 m_listView->blockSignals(false);
284 emit clipNameChanged(clip->clipId(), properties.value("name"));
286 if (properties.contains("description")) {
287 CLIPTYPE type = clip->clipType();
288 m_listView->blockSignals(true);
289 clip->setText(2, properties.value("description"));
290 m_listView->blockSignals(false);
291 if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
292 // Use Nepomuk system to store clip description
293 Nepomuk::Resource f(clip->clipUrl().path());
294 f.setDescription(properties.value("description"));
296 emit projectModified();
300 void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
302 ProjectItem *clip = static_cast <ProjectItem*>(item);
304 if (clip->referencedClip()) {
305 QMap <QString, QString> oldprops;
306 QMap <QString, QString> newprops;
307 oldprops["description"] = clip->referencedClip()->getProperty("description");
308 newprops["description"] = item->text(2);
310 if (clip->clipType() == TEXT && !clip->referencedClip()->getProperty("xmltemplate").isEmpty()) {
311 // This is a text template clip, update the image
312 oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata"));
313 newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());
316 slotUpdateClipProperties(clip->clipId(), newprops);
317 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
318 m_commandStack->push(command);
320 } else if (column == 1) {
321 if (clip->isGroup()) {
322 editFolder(item->text(1), clip->groupName(), clip->clipId());
323 clip->setGroupName(item->text(1));
324 m_doc->clipManager()->addFolder(clip->clipId(), item->text(1));
325 const int children = item->childCount();
326 for (int i = 0; i < children; i++) {
327 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
328 child->setProperty("groupname", item->text(1));
331 if (clip->referencedClip()) {
332 QMap <QString, QString> oldprops;
333 QMap <QString, QString> newprops;
334 oldprops["name"] = clip->referencedClip()->getProperty("name");
335 newprops["name"] = item->text(1);
336 slotUpdateClipProperties(clip, newprops);
337 emit projectModified();
338 EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false);
339 m_commandStack->push(command);
345 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
351 m_editAction->setEnabled(enable);
352 m_deleteAction->setEnabled(enable);
353 m_reloadAction->setEnabled(enable);
355 ProjectItem *clip = static_cast <ProjectItem*>(item);
356 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
357 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
358 m_openAction->setEnabled(true);
359 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
360 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
361 m_openAction->setEnabled(true);
362 } else m_openAction->setEnabled(false);
363 } else m_openAction->setEnabled(false);
367 void ProjectList::slotRemoveClip()
369 if (!m_listView->currentItem()) return;
371 QMap <QString, QString> folderids;
372 QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
374 for (int i = 0; i < selected.count(); i++) {
375 item = static_cast <ProjectItem *>(selected.at(i));
376 if (item->isGroup()) folderids[item->groupName()] = item->clipId();
377 else ids << item->clipId();
378 if (item->numReferences() > 0) {
379 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;
380 } else if (item->isGroup() && item->childCount() > 0) {
381 int children = item->childCount();
382 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;
383 for (int i = 0; i < children; ++i) {
384 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
385 ids << child->clipId();
389 if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
390 if (!folderids.isEmpty()) deleteProjectFolder(folderids);
391 if (m_listView->topLevelItemCount() == 0) {
392 m_editAction->setEnabled(false);
393 m_deleteAction->setEnabled(false);
394 m_openAction->setEnabled(false);
395 m_reloadAction->setEnabled(false);
399 void ProjectList::selectItemById(const QString &clipId)
401 ProjectItem *item = getItemById(clipId);
402 if (item) m_listView->setCurrentItem(item);
406 void ProjectList::slotDeleteClip(const QString &clipId)
408 ProjectItem *item = getItemById(clipId);
410 kDebug() << "/// Cannot find clip to delete";
417 void ProjectList::editFolder(const QString folderName, const QString oldfolderName, const QString &clipId)
419 EditFolderCommand *command = new EditFolderCommand(this, folderName, oldfolderName, clipId, false);
420 m_commandStack->push(command);
421 m_doc->setModified(true);
424 void ProjectList::slotAddFolder()
426 AddFolderCommand *command = new AddFolderCommand(this, i18n("Folder"), QString::number(m_doc->clipManager()->getFreeFolderId()), true);
427 m_commandStack->push(command);
430 void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit)
433 ProjectItem *item = getFolderItemById(clipId);
435 m_doc->clipManager()->deleteFolder(clipId);
440 ProjectItem *item = getFolderItemById(clipId);
441 QTreeWidgetItemIterator it(m_listView);
443 m_listView->blockSignals(true);
444 item->setGroupName(foldername);
445 m_listView->blockSignals(false);
446 m_doc->clipManager()->addFolder(clipId, foldername);
447 const int children = item->childCount();
448 for (int i = 0; i < children; i++) {
449 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
450 child->setProperty("groupname", foldername);
455 text << QString() << foldername;
456 m_listView->blockSignals(true);
457 (void) new ProjectItem(m_listView, text, clipId);
458 m_doc->clipManager()->addFolder(clipId, foldername);
459 m_listView->blockSignals(false);
466 void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
468 QMapIterator<QString, QString> i(map);
469 QUndoCommand *delCommand = new QUndoCommand();
470 delCommand->setText(i18n("Delete Folder"));
471 while (i.hasNext()) {
473 new AddFolderCommand(this, i.key(), i.value(), false, delCommand);
475 m_commandStack->push(delCommand);
476 m_doc->setModified(true);
479 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
481 if (getProperties) m_listView->setEnabled(false);
482 m_listView->blockSignals(true);
483 const QString parent = clip->getProperty("groupid");
484 kDebug() << "Adding clip with groupid: " << parent;
485 ProjectItem *item = NULL;
486 if (!parent.isEmpty()) {
487 ProjectItem *parentitem = getFolderItemById(parent);
490 QString groupName = clip->getProperty("groupname");
491 //kDebug() << "Adding clip to new group: " << groupName;
492 if (groupName.isEmpty()) groupName = i18n("Folder");
493 text << QString() << groupName;
494 parentitem = new ProjectItem(m_listView, text, parent);
496 //kDebug() << "Adding clip to existing group: " << parentitem->groupName();
498 if (parentitem) item = new ProjectItem(parentitem, clip);
500 if (item == NULL) item = new ProjectItem(m_listView, clip);
502 KUrl url = clip->fileURL();
503 if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
504 // if file has Nepomuk comment, use it
505 Nepomuk::Resource f(url.path());
506 QString annotation = f.description();
507 if (!annotation.isEmpty()) item->setText(2, annotation);
508 item->setText(3, QString::number(f.rating()));
510 m_listView->blockSignals(false);
513 void ProjectList::slotResetProjectList()
516 emit clipSelected(NULL);
517 m_thumbnailQueue.clear();
522 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
524 kDebug() << " PRG LISTĀ REQUEST CLP INFO: " << id;
525 m_infoQueue.insert(id, xml);
526 m_listView->setEnabled(false);
527 if (m_infoQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
530 void ProjectList::slotProcessNextClipInQueue()
532 if (m_infoQueue.isEmpty()) {
533 m_listView->setEnabled(true);
536 QMap<QString, QDomElement>::const_iterator i = m_infoQueue.constBegin();
537 if (i != m_infoQueue.constEnd()) {
538 const QDomElement dom = i.value();
539 const QString id = i.key();
540 m_infoQueue.remove(i.key());
541 emit getFileProperties(dom, id, false);
543 if (m_infoQueue.isEmpty()) m_listView->setEnabled(true);
546 void ProjectList::slotUpdateClip(const QString &id)
548 ProjectItem *item = getItemById(id);
549 m_listView->blockSignals(true);
550 if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
551 m_listView->blockSignals(false);
554 void ProjectList::updateAllClips()
556 QTreeWidgetItemIterator it(m_listView);
558 ProjectItem *item = static_cast <ProjectItem *>(*it);
559 if (!item->isGroup()) {
560 if (item->referencedClip()->producer() == NULL) {
561 DocClipBase *clip = item->referencedClip();
562 if (clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
563 // regenerate text clip image if required
564 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
566 doc.setContent(clip->getProperty("xmldata"));
568 QImage pix = dia_ui->renderedPixmap();
569 pix.save(clip->fileURL().path());
572 if (clip->isPlaceHolder() == false) requestClipInfo(clip->toXML(), clip->getId());
573 else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
575 QString cachedPixmap = m_doc->projectFolder().path() + "/thumbs/" + item->getClipHash() + ".png";
576 if (QFile::exists(cachedPixmap)) {
577 //kDebug()<<"// USING CACHED PIX: "<<cachedPixmap;
578 m_listView->blockSignals(true);
579 item->setIcon(0, QPixmap(cachedPixmap));
580 m_listView->blockSignals(false);
581 } else requestClipThumbnail(item->clipId());
583 if (item->data(1, DurationRole).toString().isEmpty()) {
584 m_listView->blockSignals(true);
585 item->changeDuration(item->referencedClip()->producer()->get_playtime());
586 m_listView->blockSignals(false);
589 m_listView->blockSignals(true);
590 item->setData(1, UsageRole, QString::number(item->numReferences()));
591 m_listView->blockSignals(false);
592 qApp->processEvents();
596 QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
599 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
601 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
603 if (givenList.isEmpty()) {
604 // Build list of mime types
605 QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/mpeg" << "video/x-ms-wmv" << "audio/mpeg" << "audio/x-mp3" << "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" << "video/mlt-playlist" << "audio/x-flac" << "audio/mp4" << "video/x-matroska" << "audio/x-matroska" << "video/ogg" << "audio/ogg";
607 QString allExtensions;
608 foreach(const QString& mimeType, mimeTypes) {
609 KMimeType::Ptr mime(KMimeType::mimeType(mimeType));
611 allExtensions.append(mime->patterns().join(" "));
612 allExtensions.append(' ');
615 QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files");
616 dialogFilter.append("\n*" + QLatin1Char('|') + i18n("All Files"));
617 list = KFileDialog::getOpenUrls(KUrl("kfiledialog:///clipfolder"), dialogFilter, this);
620 for (int i = 0; i < givenList.count(); i++)
621 list << givenList.at(i);
623 if (list.isEmpty()) return;
625 if (givenList.isEmpty()) {
626 QStringList groupInfo = getGroup();
627 m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1));
628 } else m_doc->slotAddClipList(list, groupName, groupId);
631 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
633 ProjectItem *item = getItemById(id);
635 const QString path = item->referencedClip()->fileURL().path();
636 if (!path.isEmpty()) {
637 if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
639 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;
644 if (replace) m_doc->deleteProjectClip(ids);
646 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
647 else m_listView->setEnabled(true);
650 void ProjectList::slotAddColorClip()
652 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
653 QDialog *dia = new QDialog(this);
654 Ui::ColorClip_UI dia_ui;
656 dia_ui.clip_name->setText(i18n("Color Clip"));
657 dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
658 if (dia->exec() == QDialog::Accepted) {
659 QString color = dia_ui.clip_color->color().name();
660 color = color.replace(0, 1, "0x") + "ff";
661 QStringList groupInfo = getGroup();
662 m_doc->clipManager()->slotAddColorClipFile(dia_ui.clip_name->text(), color, dia_ui.clip_duration->text(), groupInfo.at(0), groupInfo.at(1));
663 m_doc->setModified(true);
669 void ProjectList::slotAddSlideshowClip()
671 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
672 SlideshowClip *dia = new SlideshowClip(m_timecode, this);
674 if (dia->exec() == QDialog::Accepted) {
675 QStringList groupInfo = getGroup();
676 m_doc->clipManager()->slotAddSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->fade(), dia->lumaDuration(), dia->lumaFile(), dia->softness(), groupInfo.at(0), groupInfo.at(1));
677 m_doc->setModified(true);
682 void ProjectList::slotAddTitleClip()
684 QStringList groupInfo = getGroup();
685 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1));
688 void ProjectList::slotAddTitleTemplateClip()
690 QStringList groupInfo = getGroup();
691 if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
693 // Get the list of existing templates
695 filter << "*.kdenlivetitle";
696 const QString path = m_doc->projectFolder().path() + "/titles/";
697 QStringList templateFiles = QDir(path).entryList(filter, QDir::Files);
699 QDialog *dia = new QDialog(this);
700 Ui::TemplateClip_UI dia_ui;
702 for (int i = 0; i < templateFiles.size(); ++i) {
703 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i));
705 dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
706 //warning: setting base directory doesn't work??
708 dia_ui.template_list->fileDialog()->setUrl(startDir);
709 dia_ui.description->setHidden(true);
710 if (dia->exec() == QDialog::Accepted) {
711 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
712 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
713 if (dia_ui.normal_clip->isChecked()) {
714 // Create a normal title clip
715 m_doc->slotCreateTextClip(groupInfo.at(0), groupInfo.at(1), textTemplate);
717 // Create a cloned template clip
718 m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate));
724 QStringList ProjectList::getGroup() const
727 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
728 if (item && !item->isGroup()) {
729 while (item->parent()) {
730 item = static_cast <ProjectItem*>(item->parent());
731 if (item->isGroup()) break;
734 if (item && item->isGroup()) {
735 result << item->groupName();
736 result << item->clipId();
737 } else result << QString() << QString();
741 void ProjectList::setDocument(KdenliveDoc *doc)
743 m_listView->blockSignals(true);
745 emit clipSelected(NULL);
746 m_thumbnailQueue.clear();
749 QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
750 QMapIterator<QString, QString> f(flist);
751 while (f.hasNext()) {
753 (void) new ProjectItem(m_listView, QStringList() << QString() << f.value(), f.key());
756 QList <DocClipBase*> list = doc->clipManager()->documentClipList();
757 for (int i = 0; i < list.count(); i++) {
758 slotAddClip(list.at(i), false);
762 m_timecode = doc->timecode();
763 m_commandStack = doc->commandStack();
765 QTreeWidgetItem *first = m_listView->topLevelItem(0);
766 if (first) m_listView->setCurrentItem(first);
767 m_listView->blockSignals(false);
768 m_toolbar->setEnabled(true);
771 QDomElement ProjectList::producersList()
774 QDomElement prods = doc.createElement("producerlist");
775 doc.appendChild(prods);
776 kDebug() << "//////////// PRO LISTĀ BUILD PRDSLIST ";
777 QTreeWidgetItemIterator it(m_listView);
779 if (!((ProjectItem *)(*it))->isGroup())
780 prods.appendChild(doc.importNode(((ProjectItem *)(*it))->toXml(), true));
786 void ProjectList::slotCheckForEmptyQueue()
788 if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
790 emit loadingIsOver();
791 } else QTimer::singleShot(500, this, SLOT(slotCheckForEmptyQueue()));
794 void ProjectList::reloadClipThumbnails()
796 m_thumbnailQueue.clear();
797 QTreeWidgetItemIterator it(m_listView);
799 if (!((ProjectItem *)(*it))->isGroup())
800 m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
803 QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
806 void ProjectList::requestClipThumbnail(const QString &id)
808 m_thumbnailQueue.append(id);
809 if (m_thumbnailQueue.count() == 1) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
812 void ProjectList::slotProcessNextThumbnail()
814 if (m_thumbnailQueue.isEmpty()) {
817 slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
820 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
822 ProjectItem *item = getItemById(clipId);
823 if (item) slotRefreshClipThumbnail(item, update);
824 else slotProcessNextThumbnail();
827 void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
830 if (!item->referencedClip()) return;
832 int width = (int)(height * m_render->dar());
833 DocClipBase *clip = item->referencedClip();
834 if (!clip) slotProcessNextThumbnail();
836 if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
837 else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
838 m_listView->blockSignals(true);
839 item->setIcon(0, pix);
840 m_listView->blockSignals(false);
841 m_doc->cachePixmap(item->getClipHash(), pix);
842 if (update) emit projectModified();
843 if (!m_thumbnailQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
847 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
849 ProjectItem *item = getItemById(clipId);
850 if (item && producer) {
851 m_listView->blockSignals(true);
852 item->setProperties(properties, metadata);
853 Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
854 item->referencedClip()->setProducer(producer, replace);
855 emit receivedClipDuration(clipId);
857 // update clip in clip monitor
858 emit clipSelected(NULL);
859 emit clipSelected(item->referencedClip());
862 // Check if duration changed.
863 emit receivedClipDuration(clipId);
866 m_listView->blockSignals(false);
867 } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
868 if (!m_infoQueue.isEmpty()) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
869 else m_listView->setEnabled(true);
872 void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
874 ProjectItem *item = getItemById(clipId);
876 m_listView->blockSignals(true);
877 item->setIcon(0, pix);
878 m_doc->cachePixmap(item->getClipHash(), pix);
879 m_listView->blockSignals(false);
883 ProjectItem *ProjectList::getItemById(const QString &id)
886 QTreeWidgetItemIterator it(m_listView);
888 item = static_cast<ProjectItem *>(*it);
889 if (item->clipId() == id && item->clipType() != FOLDER)
896 ProjectItem *ProjectList::getFolderItemById(const QString &id)
899 QTreeWidgetItemIterator it(m_listView);
901 item = static_cast<ProjectItem *>(*it);
902 if (item->clipId() == id && item->clipType() == FOLDER)
909 void ProjectList::slotSelectClip(const QString &ix)
911 ProjectItem *clip = getItemById(ix);
913 m_listView->setCurrentItem(clip);
914 m_listView->scrollToItem(clip);
915 m_editAction->setEnabled(true);
916 m_deleteAction->setEnabled(true);
917 m_reloadAction->setEnabled(true);
918 if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
919 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
920 m_openAction->setEnabled(true);
921 } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) {
922 m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp()));
923 m_openAction->setEnabled(true);
924 } else m_openAction->setEnabled(false);
928 QString ProjectList::currentClipUrl() const
930 ProjectItem *item = static_cast <ProjectItem*>(m_listView->currentItem());
931 if (item == NULL) return QString();
932 return item->clipUrl().path();
935 void ProjectList::regenerateTemplate(const QString &id)
937 ProjectItem *clip = getItemById(id);
938 if (clip) regenerateTemplate(clip);
941 void ProjectList::regenerateTemplate(ProjectItem *clip)
943 // Generate image for template clip
944 const QString comment = clip->referencedClip()->getProperty("description");
945 const QString path = clip->referencedClip()->getProperty("xmltemplate");
946 QDomDocument doc = generateTemplateXml(path, comment);
947 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
949 QImage pix = dia_ui->renderedPixmap();
950 pix.save(clip->clipUrl().path());
952 clip->referencedClip()->producer()->set("force_reload", 1);
955 void ProjectList::regenerateTemplateImage(ProjectItem *clip)
957 // Generate image for template clip
958 TitleWidget *dia_ui = new TitleWidget(KUrl(), QString(), m_render, this);
960 doc.setContent(clip->referencedClip()->getProperty("xmldata"));
962 QImage pix = dia_ui->renderedPixmap();
963 pix.save(clip->clipUrl().path());
967 QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
971 if (!file.open(QIODevice::ReadOnly)) {
972 kWarning() << "ERROR, CANNOT READ: " << path;
975 if (!doc.setContent(&file)) {
976 kWarning() << "ERROR, CANNOT READ: " << path;
981 QDomNodeList texts = doc.elementsByTagName("content");
982 for (int i = 0; i < texts.count(); i++) {
983 QString data = texts.item(i).firstChild().nodeValue();
984 data.replace("%s", replaceString);
985 texts.item(i).firstChild().setNodeValue(data);
990 #include "projectlist.moc"