Commit e6e56dfe authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Start re-implementing folders

parent 66ab7390
......@@ -7,4 +7,4 @@ set(kdenlive_SRCS
bin/projectfolder.cpp
bin/projectsortproxymodel.cpp
PARENT_SCOPE
)
\ No newline at end of file
)
......@@ -29,24 +29,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QDebug>
AbstractProjectItem::AbstractProjectItem(const QString &id, AbstractProjectItem* parent) :
AbstractProjectItem::AbstractProjectItem(PROJECTITEMTYPE type, const QString &id, AbstractProjectItem* parent) :
QObject()
, m_parent(NULL)
, m_id(id)
, m_isCurrent(false)
, m_jobProgress(0)
, m_jobType(AbstractClipJob::NOJOBTYPE)
, m_itemType(type)
{
setParent(parent);
}
AbstractProjectItem::AbstractProjectItem(const QDomElement& description, AbstractProjectItem* parent) :
AbstractProjectItem::AbstractProjectItem(PROJECTITEMTYPE type, const QDomElement& description, AbstractProjectItem* parent) :
QObject()
, m_parent(NULL)
, m_id(description.attribute("id"))
, m_isCurrent(false)
, m_jobProgress(0)
, m_jobType(AbstractClipJob::NOJOBTYPE)
, m_itemType(type)
{
setParent(parent);
}
......@@ -129,9 +131,9 @@ void AbstractProjectItem::finishInsert(AbstractProjectItem* parent)
void AbstractProjectItem::addChild(AbstractProjectItem* child)
{
if (child && !contains(child)) {
bin()->emitAboutToAddItem(child);
if (bin()) bin()->emitAboutToAddItem(child);
append(child);
bin()->emitItemAdded(this);
if (bin()) bin()->emitItemAdded(this);
}
}
......@@ -153,6 +155,11 @@ int AbstractProjectItem::index() const
return 0;
}
bool AbstractProjectItem::isFolder() const
{
return m_itemType == FolderItem;
}
QVariant AbstractProjectItem::data(DataType type) const
{
QVariant data;
......
......@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class ProjectClip;
class ProjectFolder;
class Bin;
class QDomElement;
class QDomDocument;
......@@ -50,11 +51,17 @@ class AbstractProjectItem : public QObject, public QList<AbstractProjectItem *>
Q_OBJECT
public:
enum PROJECTITEMTYPE {
FolderItem = 0,
ClipItem = 1
};
/**
* @brief Constructor.
* @param parent parent this item should be added to
*/
AbstractProjectItem(const QString &id, AbstractProjectItem *parent = 0);
AbstractProjectItem(PROJECTITEMTYPE type, const QString &id, AbstractProjectItem *parent = 0);
/**
* @brief Creates a project item upon project load.
* @param description element for this item.
......@@ -62,7 +69,7 @@ public:
*
* We try to read the attributes "name" and "description"
*/
AbstractProjectItem(const QDomElement &description, AbstractProjectItem* parent = 0);
AbstractProjectItem(PROJECTITEMTYPE type, const QDomElement &description, AbstractProjectItem* parent = 0);
virtual ~AbstractProjectItem();
bool operator==(const AbstractProjectItem *projectItem) const;
......@@ -94,9 +101,14 @@ public:
/** @brief Returns the index this item has in its parent's child list. */
int index() const;
/** @brief Returns true if current item is a folder. */
bool isFolder() const;
/** @brief Used to search for a clip with a specific id. */
virtual ProjectClip *clip(const QString &id) = 0;
/** @brief Used to search for a folder with a specific id. */
virtual ProjectFolder* folder(const QString &id) = 0;
virtual ProjectClip *clipAt(int ix) = 0;
/** @brief Returns the clip's id. */
......@@ -160,6 +172,7 @@ protected:
AbstractClipJob::JOBTYPE m_jobType;
int m_jobProgress;
QString m_jobMessage;
PROJECTITEMTYPE m_itemType;
/** @brief Returns a rounded border pixmap from the @param source pixmap. */
QPixmap roundedPixmap(const QPixmap &source);
......
......@@ -41,6 +41,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QVBoxLayout>
#include <QSlider>
#include <QMenu>
#include <QDebug>
#include <QTableWidget>
......@@ -193,7 +194,23 @@ Monitor *Bin::monitor()
void Bin::slotAddClip()
{
pCore->projectManager()->current()->clipManager()->slotAddClip(QString(), QString(), QString());
// Check if we are in a folder
QString folderName;
QString folderId;
QModelIndex ix = m_proxyModel->selectionModel()->currentIndex();
if (ix.isValid()) {
AbstractProjectItem *currentItem = static_cast<AbstractProjectItem *>(m_proxyModel->mapToSource(ix).internalPointer());
while (!currentItem->isFolder()) {
currentItem = currentItem->parent();
}
if (currentItem == m_rootFolder) {
// clip was added to root folder, leave folder info empty
} else {
folderName = currentItem->name();
folderId = currentItem->clipId();
}
}
pCore->projectManager()->current()->clipManager()->slotAddClip(QString(), folderName, folderId);
}
void Bin::deleteClip(const QString &id)
......@@ -219,7 +236,6 @@ void Bin::slotDeleteClip()
}
// For some reason, we get duplicates, which is not expected
//ids.removeDuplicates();
qDebug()<<"++++++++++++++++++\nBIN DELETE IDS: "<<ids;
pCore->projectManager()->deleteProjectClips(ids);
}
......@@ -248,6 +264,11 @@ void Bin::setMonitor(Monitor *monitor)
connect(m_eventEater, SIGNAL(focusClipMonitor()), m_monitor, SLOT(slotActivateMonitor()), Qt::UniqueConnection);
}
int Bin::getFreeFolderId()
{
return m_folderCounter++;
}
int Bin::getFreeClipId()
{
return m_clipCounter++;
......@@ -266,13 +287,14 @@ void Bin::setDocument(KdenliveDoc* project)
delete m_jobManager;
delete m_rootFolder;
m_clipCounter = 1;
m_folderCounter = 1;
m_doc = project;
m_openedProducer.clear();
int iconHeight = style()->pixelMetric(QStyle::PM_ToolBarIconSize) * 2;
m_iconSize = QSize(iconHeight * m_doc->dar(), iconHeight);
m_itemModel->setIconSize(m_iconSize);
m_jobManager = new JobManager(this, project->fps());
m_rootFolder = new ProjectFolder(this);
m_rootFolder = new ProjectFolder(this);
connect(this, SIGNAL(producerReady(QString)), m_doc->renderer(), SLOT(slotProcessingDone(QString)));
//connect(m_itemModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), m_itemView
//connect(m_itemModel, SIGNAL(updateCurrentItem()), this, SLOT(autoSelect()));
......@@ -282,12 +304,42 @@ void Bin::setDocument(KdenliveDoc* project)
void Bin::createClip(QDomElement xml)
{
ProjectClip *newItem = new ProjectClip(xml, m_rootFolder);
// Check if clip should be in a folder
QString groupId = xml.attribute("groupid");
ProjectFolder *parentFolder = m_rootFolder;
if (!groupId.isEmpty()) {
QString groupName = xml.attribute("group");
parentFolder = m_rootFolder->folder(groupId);
if (!parentFolder) {
// parent folder does not exist, put in root folder
parentFolder = m_rootFolder;
}
}
ProjectClip *newItem = new ProjectClip(xml, parentFolder);
}
void Bin::slotAddFolder()
{
ProjectFolder *newItem = new ProjectFolder(m_rootFolder);
// Check parent item
QString folderName;
QString folderId;
QModelIndex ix = m_proxyModel->selectionModel()->currentIndex();
ProjectFolder *parentFolder = m_rootFolder;
if (ix.isValid()) {
AbstractProjectItem *currentItem = static_cast<AbstractProjectItem *>(m_proxyModel->mapToSource(ix).internalPointer());
while (!currentItem->isFolder()) {
currentItem = currentItem->parent();
}
if (currentItem->isFolder()) {
parentFolder = static_cast<ProjectFolder *>(currentItem);
}
if (parentFolder != m_rootFolder) {
// clip was added to a sub folder, set info
folderName = currentItem->name();
folderId = currentItem->clipId();
}
}
ProjectFolder *newItem = new ProjectFolder(QString::number(getFreeFolderId()), i18n("Folder"), parentFolder);
}
void Bin::emitAboutToAddItem(AbstractProjectItem* item)
......@@ -312,8 +364,11 @@ void Bin::emitItemRemoved(AbstractProjectItem* item)
void Bin::rowsInserted(const QModelIndex &/*parent*/, int /*start*/, int end)
{
const QModelIndex id = m_itemModel->index(end, 0, QModelIndex());
m_proxyModel->selectionModel()->select(m_proxyModel->mapFromSource(id), QItemSelectionModel::Select);
QModelIndexList indexes = m_proxyModel->selectionModel()->selectedIndexes();
if (indexes.isEmpty()) {
const QModelIndex id = m_itemModel->index(end, 0, QModelIndex());
m_proxyModel->selectionModel()->select(m_proxyModel->mapFromSource(id), QItemSelectionModel::Select);
}
//selectModel(id);
}
......@@ -326,7 +381,6 @@ void Bin::rowsRemoved(const QModelIndex &/*parent*/, int start, int /*end*/)
void Bin::selectModel(const QModelIndex &id)
{
qDebug()<<"* * * * * SELECT MODEL CALLED * * * * * *";
m_proxyModel->selectionModel()->select(m_proxyModel->mapFromSource(id), QItemSelectionModel::Select);
/*if (id.isValid()) {
AbstractProjectItem *currentItem = static_cast<AbstractProjectItem*>(id.internalPointer());
......@@ -338,7 +392,6 @@ void Bin::selectModel(const QModelIndex &id)
void Bin::selectProxyModel(const QModelIndex &id)
{
qDebug()<<"* * * * * SELECT PROXY MODEL CALLED * * * * * *";
if (id.isValid()) {
ProjectClip *currentItem = static_cast<ProjectClip*>(m_proxyModel->mapToSource(id).internalPointer());
if (currentItem) {
......@@ -583,20 +636,32 @@ ProjectClip *Bin::getBinClip(const QString &id)
return clip;
}
void Bin::slotProducerReady(const QString &id, bool replaceProducer, Mlt::Producer *producer)
void Bin::slotProducerReady(requestClipInfo info, Mlt::Producer *producer)
{
ProjectClip *clip = m_rootFolder->clip(id);
ProjectClip *clip = m_rootFolder->clip(info.clipId);
if (clip) {
clip->setProducer(producer, replaceProducer);
emit producerReady(id);
if (m_openedProducer == id ) {
clip->setProducer(producer, info.replaceProducer);
emit producerReady(info.clipId);
if (m_openedProducer == info.clipId) {
m_monitor->open(clip->producer());
}
}
else {
// Clip not found, create it
ProjectClip *newItem = new ProjectClip(id, producer, m_rootFolder);
if (id.toInt() >= m_clipCounter) m_clipCounter = id.toInt() + 1;
QString groupId = producer->get("groupid");
ProjectFolder *parentFolder;
if (!groupId.isEmpty()) {
QString groupName = producer->get("group");
parentFolder = m_rootFolder->folder(groupId);
if (!parentFolder) {
// parent folder does not exist, put in root folder
parentFolder = m_rootFolder;
}
if (groupId.toInt() >= m_folderCounter) m_folderCounter = groupId.toInt() + 1;
}
else parentFolder = m_rootFolder;
ProjectClip *newItem = new ProjectClip(info.clipId, producer, parentFolder);
if (info.clipId.toInt() >= m_clipCounter) m_clipCounter = info.clipId.toInt() + 1;
}
}
......
......@@ -266,8 +266,11 @@ public:
/** @brief Get the document's renderer frame size */
const QSize getRenderSize();
/** @brief Give a number available for a clip id, used when adding a new clip to the project. Clip ids must be unique */
/** @brief Give a number available for a clip id, used when adding a new clip to the project. Id must be unique */
int getFreeClipId();
/** @brief Give a number available for a folder id, used when adding a new folder to the project. Id must be unique */
int getFreeFolderId();
/** @brief Returns the id of the last inserted clip */
int lastClipId() const;
......@@ -306,7 +309,7 @@ public slots:
* @param replaceProducer If true, we replace the producer even if the clip already has one
* @param producer The MLT producer
*/
void slotProducerReady(const QString &id, bool replaceProducer, Mlt::Producer *producer);
void slotProducerReady(requestClipInfo info, Mlt::Producer *producer);
void slotDeleteClip();
void slotShowClipProperties();
void slotAddFolder();
......@@ -324,7 +327,10 @@ private:
KToolBar *m_toolbar;
KdenliveDoc* m_doc;
QSplitter *m_splitter;
/** @brief Holds an available unique id for a clip to be created */
int m_clipCounter;
/** @brief Holds an available unique id for a folder to be created */
int m_folderCounter;
/** @brief Default view type (icon, tree, ...) */
BinViewType m_listType;
/** @brief Default icon size for the views. */
......
......@@ -35,7 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
ProjectClip::ProjectClip(const QString &id, Mlt::Producer *producer, ProjectFolder* parent) :
AbstractProjectItem(id, parent),
AbstractProjectItem(AbstractProjectItem::ClipItem, id, parent),
m_producer(producer)
{
m_properties = QMap <QString, QString> ();
......@@ -52,7 +52,7 @@ ProjectClip::ProjectClip(const QString &id, Mlt::Producer *producer, ProjectFold
}
ProjectClip::ProjectClip(const QDomElement& description, ProjectFolder* parent) :
AbstractProjectItem(description, parent)
AbstractProjectItem(AbstractProjectItem::ClipItem, description, parent)
, m_producer(NULL)
{
Q_ASSERT(description.hasAttribute("id"));
......@@ -108,6 +108,11 @@ ProjectClip* ProjectClip::clip(const QString &id)
return NULL;
}
ProjectFolder* ProjectClip::folder(const QString &id)
{
return NULL;
}
ProjectClip* ProjectClip::clipAt(int ix)
{
if (ix == index()) {
......
......@@ -69,6 +69,8 @@ public:
/** @brief Returns this if @param id matches the clip's id or NULL otherwise. */
ProjectClip *clip(const QString &id);
ProjectFolder* folder(const QString &id);
/** @brief Returns this if @param ix matches the clip's index or NULL otherwise. */
ProjectClip* clipAt(int ix);
......
......@@ -27,21 +27,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QDomElement>
#include <KLocalizedString>
ProjectFolder::ProjectFolder(const QDomElement& description, ProjectFolder* parent) :
AbstractProjectItem(description, parent)
ProjectFolder::ProjectFolder(const QString &id, const QString &name, ProjectFolder* parent) :
AbstractProjectItem(AbstractProjectItem::FolderItem, id, parent)
, m_bin(NULL)
{
loadChildren(description);
}
ProjectFolder::ProjectFolder(ProjectFolder* parent) :
AbstractProjectItem(QDomElement(), parent)
{
m_name = i18n("Folder");
//loadChildren(description);
m_name = name;
m_thumbnail = QIcon::fromTheme("folder").pixmap(40, 40);
}
ProjectFolder::ProjectFolder(Bin *bin) :
AbstractProjectItem(QDomElement())
AbstractProjectItem(AbstractProjectItem::FolderItem, QString::number(-1))
, m_bin(bin)
{
}
......@@ -63,6 +59,19 @@ ProjectClip* ProjectFolder::clip(const QString &id)
return NULL;
}
ProjectFolder* ProjectFolder::folder(const QString &id)
{
if (m_id == id) return this;
ProjectFolder *folderItem;
for (int i = 0; i < count(); ++i) {
folderItem = at(i)->folder(id);
if (folderItem) {
return folderItem;
}
}
return NULL;
}
ProjectClip* ProjectFolder::clipAt(int index)
{
ProjectClip *clip;
......@@ -81,6 +90,9 @@ Bin* ProjectFolder::bin()
if (m_bin) {
return m_bin;
} else {
if (parent()) {
return parent()->bin();
}
return AbstractProjectItem::bin();
}
}
......@@ -97,7 +109,7 @@ QDomElement ProjectFolder::toXml(QDomDocument& document)
void ProjectFolder::loadChildren(const QDomElement& description)
{
QDomNodeList childen = description.childNodes();
/*QDomNodeList childen = description.childNodes();
for (int i = 0; i < childen.count(); ++i) {
QDomElement childElement = childen.at(i).toElement();
if (childElement.tagName() == "folder") {
......@@ -105,6 +117,6 @@ void ProjectFolder::loadChildren(const QDomElement& description)
} else {
childElement.setTagName("producer");
}
}
}*/
}
......@@ -44,10 +44,7 @@ public:
* @param description element describing the folder and its children
* @param parent parent folder
*/
ProjectFolder(const QDomElement &description, ProjectFolder* parent = 0);
/** @brief Creates an empty folder. */
ProjectFolder(ProjectFolder *parent = 0);
ProjectFolder(const QString &id, const QString &name, ProjectFolder* parent = 0);
/** @brief Creates an empty root folder. */
ProjectFolder(Bin *bin);
......@@ -60,6 +57,12 @@ public:
*/
ProjectClip *clip(const QString &id);
/**
* @brief Returns itself or a child folder that matches the requested id.
* @param id id of the child which should be returned
*/
ProjectFolder* folder(const QString &id);
/**
* @brief Returns the clip if it is a child (also indirect).
* @param index index of the child which should be returned
......
......@@ -71,7 +71,6 @@ public:
void onAboutToRemoveItem(AbstractProjectItem *item);
/** @brief Prepare some stuff after removing a new item */
void onItemRemoved(AbstractProjectItem *item);
public slots:
/** @brief An item in the list was modified, notify */
......
......@@ -133,6 +133,7 @@ MainWindow::MainWindow(const QString &MltPath, const QUrl &Url, const QString &
qRegisterMetaType<QVector<qint16> > ();
qRegisterMetaType<stringMap> ("stringMap");
qRegisterMetaType<audioByteArray> ("audioByteArray");
qRegisterMetaType<requestClipInfo> ("requestClipInfo");
Core::initialize(this);
......@@ -649,7 +650,7 @@ void MainWindow::slotConnectMonitors()
connect(m_projectMonitor->render, SIGNAL(replyGetImage(QString,QImage)), pCore->bin(), SLOT(slotThumbnailReady(QString,QImage)));
connect(m_projectMonitor->render, SIGNAL(gotFileProperties(const QString &,bool,Mlt::Producer *)), pCore->bin(), SLOT(slotProducerReady(const QString &,bool,Mlt::Producer *)));
connect(m_projectMonitor->render, SIGNAL(gotFileProperties(requestClipInfo,Mlt::Producer *)), pCore->bin(), SLOT(slotProducerReady(requestClipInfo,Mlt::Producer *)));
connect(m_projectMonitor->render, SIGNAL(replyGetFileProperties(requestClipInfo &,Mlt::Producer &,stringMap,stringMap)), m_projectList, SLOT(slotReplyGetFileProperties(requestClipInfo &,Mlt::Producer &,stringMap,stringMap)), Qt::DirectConnection);
//DirectConnection was necessary not to mess the analyze queue, but the monitor thread shouldn't show any UI widget (profile dialog), so adding an AutoConnection in between?
......@@ -1117,7 +1118,7 @@ void MainWindow::setupActions()
QMenu *addClips = new QMenu();
QAction *addClip = addAction("add_clip", i18n("Add Clip"), m_projectList, SLOT(slotAddClip()), QIcon::fromTheme("kdenlive-add-clip"));
QAction *addClip = addAction("add_clip", i18n("Add Clip"), pCore->bin(), SLOT(slotAddClip()), QIcon::fromTheme("kdenlive-add-clip"));
addClips->addAction(addClip);
addClips->addAction(addAction("add_color_clip", i18n("Add Color Clip"), m_projectList, SLOT(slotAddColorClip()),
QIcon::fromTheme("kdenlive-add-color-clip")));
......
......@@ -504,14 +504,15 @@ void ClipManager::slotAddClipList(const QList <QUrl> &givenList, const QString &
if (folderFiles.count() > 1) foldersList.append(folderFiles);
}
}
if (givenList.isEmpty() && !list.isEmpty()) {
/*if (givenList.isEmpty() && !list.isEmpty()) {
QStringList groupInfo; // = getGroup();
groupInfo << QString() << QString();
QMap <QString, QString> data;
data.insert("group", groupInfo.at(0));
data.insert("groupId", groupInfo.at(1));
doAddClipList(list, data);
} else if (!list.isEmpty()) {
} else*/
if (!list.isEmpty()) {
QMap <QString, QString> data;
data.insert("group", groupName);
data.insert("groupId", groupId);
......
......@@ -797,7 +797,7 @@ void Render::processFileProperties()
// replace clip
m_binController->removeBinClip(info.clipId);
m_binController->addClipToBin(info.clipId, *producer);
emit gotFileProperties(info.clipId, info.replaceProducer, producer);
emit gotFileProperties(info, producer);
//emit replyGetFileProperties(info, *producer, stringMap(), stringMap());
continue;
}
......@@ -1025,7 +1025,7 @@ void Render::processFileProperties()
}
producer->seek(0);
m_binController->addClipToBin(info.clipId, *producer);
emit gotFileProperties(info.clipId, info.replaceProducer, producer);
emit gotFileProperties(info, producer);
//emit replyGetFileProperties(info, *producer, filePropertyMap, metadataPropertyMap);
}
}
......@@ -1321,7 +1321,11 @@ int Render::setSceneList(QString playlist, int position)
m_blackClip = &original->parent();
}
else {
emit gotFileProperties(id, true, &original->parent());
requestClipInfo info;
// pass basic info, the others (folder, etc) will be taken from the producer itself
info.clipId = id;
info.replaceProducer = true;
emit gotFileProperties(info, &original->parent());
}
//delete original;
}
......
......@@ -419,7 +419,7 @@ signals:
/** @brief The renderer received a reply to a getFileProperties request. */
void replyGetFileProperties(requestClipInfo &, Mlt::Producer &, const stringMap &, const stringMap &);
void gotFileProperties(const QString&, bool, Mlt::Producer *);
void gotFileProperties(requestClipInfo,Mlt::Producer *);
/** @brief The renderer received a reply to a getImage request. */
void replyGetImage(const QString &, const QString &, int, int);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment