From: Jean-Baptiste Mardelle Date: Sun, 19 Jul 2009 11:09:29 +0000 (+0000) Subject: Automatically update clips when they change on disk. It means you can now edit an... X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=9acf3acd7946f6ed7946629ad4bc6a8755e05387;p=kdenlive Automatically update clips when they change on disk. It means you can now edit an image clip with gimp, save it in gimp and Kdenlive immediatly updates the clip without user interaction (currently for image and audio clips) svn path=/trunk/kdenlive/; revision=3733 --- diff --git a/src/clipmanager.cpp b/src/clipmanager.cpp index c4436777..4764a650 100644 --- a/src/clipmanager.cpp +++ b/src/clipmanager.cpp @@ -43,6 +43,7 @@ ClipManager::ClipManager(KdenliveDoc *doc) : { m_clipIdCounter = 1; m_folderIdCounter = 1; + connect(&m_fileWatcher, SIGNAL(dirty(const QString &)), this, SLOT(slotClipModified(const QString &))); } ClipManager::~ClipManager() @@ -136,6 +137,10 @@ QMap ClipManager::documentFolderList() const void ClipManager::addClip(DocClipBase *clip) { m_clipList.append(clip); + if (clip->clipType() == IMAGE || clip->clipType() == AUDIO) { + // listen for file change + m_fileWatcher.addFile(clip->fileURL().path()); + } const QString id = clip->getId(); if (id.toInt() >= m_clipIdCounter) m_clipIdCounter = id.toInt() + 1; const QString gid = clip->getProperty("groupid"); @@ -155,6 +160,10 @@ void ClipManager::deleteClip(const QString &clipId) { for (int i = 0; i < m_clipList.count(); i++) { if (m_clipList.at(i)->getId() == clipId) { + if (m_clipList.at(i)->clipType() == IMAGE || m_clipList.at(i)->clipType() == AUDIO) { + // listen for file change + m_fileWatcher.removeFile(m_clipList.at(i)->fileURL().path()); + } delete m_clipList.takeAt(i); break; } @@ -444,3 +453,12 @@ QDomElement ClipManager::groupsXml() const } return doc.documentElement(); } + + +void ClipManager::slotClipModified(const QString &path) +{ + //kDebug()<<"// CLIP: "<getId()); +} \ No newline at end of file diff --git a/src/clipmanager.h b/src/clipmanager.h index 272016dd..4a7850f7 100644 --- a/src/clipmanager.h +++ b/src/clipmanager.h @@ -30,6 +30,7 @@ #include #include +#include #include #include "gentime.h" @@ -85,6 +86,9 @@ Q_OBJECT public: public slots: void updatePreviewSettings(); +private slots: + void slotClipModified(const QString &path); + private: // Private attributes /** the list of clips in the document */ QList m_clipList; @@ -98,7 +102,10 @@ private: // Private attributes int m_folderIdCounter; bool m_audioThumbsEnabled; QString m_generatingAudioId; + KDirWatch m_fileWatcher; +signals: + void reloadClip(const QString &); }; #endif diff --git a/src/projectlist.cpp b/src/projectlist.cpp index a36a0232..8668a1b8 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -207,9 +207,11 @@ void ProjectList::slotOpenClip() } } -void ProjectList::slotReloadClip() +void ProjectList::slotReloadClip(const QString &id) { - QList selected = m_listView->selectedItems(); + QList selected; + if (id.isEmpty()) selected = m_listView->selectedItems(); + else selected.append(getItemById(id)); ProjectItem *item; for (int i = 0; i < selected.count(); i++) { item = static_cast (selected.at(i)); @@ -761,6 +763,8 @@ void ProjectList::setDocument(KdenliveDoc *doc) m_commandStack = doc->commandStack(); m_doc = doc; + connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &))); + QMap flist = doc->clipManager()->documentFolderList(); QMapIterator f(flist); while (f.hasNext()) { diff --git a/src/projectlist.h b/src/projectlist.h index 9adaa8a5..60e283bf 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -149,7 +149,7 @@ public slots: void slotResetProjectList(); void slotOpenClip(); void slotEditClip(); - void slotReloadClip(); + void slotReloadClip(const QString &id = QString()); void slotAddColorClip(); void regenerateTemplate(const QString &id);