]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
adapt to latest MLT changes
[kdenlive] / src / projectlist.cpp
index 9bec68fbdb39bbb28558d567e11671bf88edb6f7..7fe59f7cb1c716124fc093bed50229f200ef31bb 100644 (file)
 #include <KAction>
 #include <KLocale>
 #include <KFileDialog>
-#include <nepomuk/resourcemanager.h>
+#include <KInputDialog>
 #include <kio/netaccess.h>
+#include <KMessageBox>
+
+#include <nepomuk/global.h>
+#include <nepomuk/resource.h>
+#include <nepomuk/tag.h>
 
 #include "projectlist.h"
 #include "projectitem.h"
 #include "ui_colorclip_ui.h"
 
 #include "addclipcommand.h"
+#include "definitions.h"
 
 #include <QtGui>
 
-  const int NameRole = Qt::UserRole;
-  const int DurationRole = NameRole + 1;
-  const int FullPathRole = NameRole + 2;
-  const int ClipTypeRole = NameRole + 3;
-
-class ItemDelegate: public QItemDelegate
-{
-  public:
-    ItemDelegate(QObject* parent = 0): QItemDelegate(parent)
-    {
-    }
-
-void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
-{
-  if (index.column() == 1)
-  {
-    const bool hover = option.state & (QStyle::State_Selected|QStyle::State_MouseOver|QStyle::State_HasFocus);
-    QRect r1 = option.rect;
-    painter->save();
-    if (hover) {
-        painter->setPen(option.palette.color(QPalette::HighlightedText));
-        QColor backgroundColor = option.palette.color(QPalette::Highlight);
-        painter->setBrush(QBrush(backgroundColor));
-       painter->fillRect(r1, QBrush(backgroundColor));
-    }
-    QFont font = painter->font();
-    font.setPointSize(font.pointSize() - 1 );
-    font.setBold(true);
-    painter->setFont(font);
-    int mid = (int) ((r1.height() / 2 ));
-    r1.setBottom(r1.y() + mid);
-    QRect r2 = option.rect;
-    r2.setTop(r2.y() + mid);
-    painter->drawText(r1, Qt::AlignLeft | Qt::AlignBottom , index.data().toString());
-    //painter->setPen(Qt::green);
-    font.setBold(false);
-    painter->setFont(font);
-    painter->drawText(r2, Qt::AlignLeft | Qt::AlignVCenter , index.data(DurationRole).toString());
-    painter->restore();
-  }
-  else
-  {
-    QItemDelegate::paint(painter, option, index);
-  }
-}
-};
-
-
 ProjectList::ProjectList(QWidget *parent)
     : QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(NULL)
 {
@@ -107,7 +65,7 @@ ProjectList::ProjectList(QWidget *parent)
   addButton->setMenu( addMenu );
   addButton->setPopupMode(QToolButton::MenuButtonPopup);
   m_toolbar->addWidget (addButton);
-  
+
   QAction *addClipButton = addMenu->addAction (KIcon("document-new"), i18n("Add Clip"));
   connect(addClipButton, SIGNAL(triggered()), this, SLOT(slotAddClip()));
 
@@ -120,6 +78,9 @@ ProjectList::ProjectList(QWidget *parent)
   m_editAction = m_toolbar->addAction (KIcon("document-properties"), i18n("Edit Clip"));
   connect(m_editAction, SIGNAL(triggered()), this, SLOT(slotEditClip()));
 
+  QAction *addFolderButton = addMenu->addAction (KIcon("folder-new"), i18n("Create Folder"));
+  connect(addFolderButton, SIGNAL(triggered()), this, SLOT(slotAddFolder()));
+
   addButton->setDefaultAction( addClipButton );
 
   layout->addWidget( m_toolbar );
@@ -129,8 +90,6 @@ ProjectList::ProjectList(QWidget *parent)
 
   searchView->setTreeWidget(listView);
   listView->setColumnCount(3);
-  listView->setDragEnabled(true);
-  listView->setDragDropMode(QAbstractItemView::DragDrop);
   QStringList headers;
   headers<<i18n("Thumbnail")<<i18n("Filename")<<i18n("Description");
   listView->setHeaderLabels(headers);
@@ -141,16 +100,18 @@ ProjectList::ProjectList(QWidget *parent)
   m_menu->addAction(addColorClip);
   m_menu->addAction(m_editAction);
   m_menu->addAction(m_deleteAction);
+  m_menu->addAction(addFolderButton);
   m_menu->insertSeparator(m_deleteAction);
 
   connect(listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
   connect(listView, SIGNAL(requestMenu ( const QPoint &, QTreeWidgetItem * )), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
+  connect(listView, SIGNAL(addClip ()), this, SLOT(slotAddClip()));
+  connect(listView, SIGNAL(addClip (QUrl, const QString &)), this, SLOT(slotAddClip(QUrl, const QString &)));
 
-
-  listView->setItemDelegate(new ItemDelegate(listView));
+  m_listViewDelegate = new ItemDelegate(listView);
+  listView->setItemDelegate(m_listViewDelegate);
   listView->setIconSize(QSize(60, 40));
   listView->setSortingEnabled (true);
-
 }
 
 ProjectList::~ProjectList()
@@ -185,6 +146,17 @@ void ProjectList::slotContextMenu( const QPoint &pos, QTreeWidgetItem *item )
 {
   bool enable = false;
   if (item) {
+    QFrame *w = new QFrame;
+    w->setFrameShape(QFrame::StyledPanel);
+    w->setLineWidth(2);
+    w->setAutoFillBackground(true);
+    QHBoxLayout *layout = new QHBoxLayout;
+    layout->addWidget( new QLabel(i18n("Color:")));
+    layout->addWidget( new KColorButton());
+    layout->addWidget( new QLabel(i18n("Duration:")));
+    layout->addWidget( new KRestrictedLine());
+    w->setLayout( layout );
+    m_listViewDelegate->extendItem(w, listView->currentIndex());
     enable = true;
   }
   m_editAction->setEnabled(enable);
@@ -198,9 +170,10 @@ void ProjectList::slotRemoveClip()
   if (!m_commandStack) kDebug()<<"!!!!!!!!!!!!!!!!  NO CMD STK";
   if (!listView->currentItem()) return;
   ProjectItem *item = ((ProjectItem *)listView->currentItem());
-  AddClipCommand *command = new AddClipCommand(this, item->names(), item->toXml(), item->clipId(), KUrl(item->data(1, FullPathRole).toString()), false);
+  if (!item) kDebug()<<"///////////////  ERROR NOT FOUND";
+  if (KMessageBox::questionYesNo(this, i18n("Delete clip <b>%1</b> ?").arg(item->names().at(1)), i18n("Delete Clip")) != KMessageBox::Yes) return;
+  AddClipCommand *command = new AddClipCommand(this, item->names(), item->toXml(), item->clipId(), item->clipUrl(), item->groupName(), false);
   m_commandStack->push(command);
-
 }
 
 void ProjectList::selectItemById(const int clipId)
@@ -209,24 +182,36 @@ void ProjectList::selectItemById(const int clipId)
   if (item) listView->setCurrentItem(item);
 }
 
-void ProjectList::addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url, int parentId)
+void ProjectList::addClip(const QStringList &name, const QDomElement &elem, const int clipId, const KUrl &url, const QString &group, int parentId)
 {
   kDebug()<<"/////////  ADDING VCLIP=: "<<name;
   ProjectItem *item;
   ProjectItem *groupItem = NULL;
-  QString group = elem.attribute("group", QString::null);
+  QString groupName;
+  if (group.isEmpty()) groupName = elem.attribute("group", QString::null);
+  else groupName = group;
+  if (elem.isNull() && url.isEmpty()) {
+    // this is a folder
+    groupName = name.at(1);
+    QList<QTreeWidgetItem *> groupList = listView->findItems(groupName, Qt::MatchExactly, 1);
+    if (groupList.isEmpty())  {
+       (void) new ProjectItem(listView, name, clipId);
+    }
+    return;
+  }
+
   if (parentId != -1) {
     groupItem = getItemById(parentId);
   }
-  else if (!group.isEmpty()) {
+  else if (!groupName.isEmpty()) {
     // Clip is in a group
-    QList<QTreeWidgetItem *> groupList = listView->findItems(group, Qt::MatchExactly, 1);
+    QList<QTreeWidgetItem *> groupList = listView->findItems(groupName, Qt::MatchExactly, 1);
 
     if (groupList.isEmpty())  {
-       QStringList groupName;
-       groupName<<QString::null<<group;
-       kDebug()<<"-------  CREATING NEW GRP: "<<groupName;
-       groupItem = new ProjectItem(listView, groupName);
+       QStringList itemName;
+       itemName<<QString::null<<groupName;
+       kDebug()<<"-------  CREATING NEW GRP: "<<itemName;
+       groupItem = new ProjectItem(listView, itemName, m_clipIdCounter++);
     }
     else groupItem = (ProjectItem *) groupList.first();
   }
@@ -234,9 +219,10 @@ void ProjectList::addClip(const QStringList &name, const QDomElement &elem, cons
   else item = new ProjectItem(listView, name, elem, clipId);
   if (!url.isEmpty()) {
     item->setData(1, FullPathRole, url.path());
-/*    Nepomuk::File f( url.path() );
-    QString annotation = f.getAnnotation();
-    if (!annotation.isEmpty()) item->setText(2, annotation);*/
+    // if file has Nepomuk comment, use it
+    Nepomuk::Resource f( url.path() );
+    QString annotation = f.description();
+    if (!annotation.isEmpty()) item->setText(2, annotation);
     QString resource = url.path();
     if (resource.endsWith("westley") || resource.endsWith("kdenlive")) {
        QString tmpfile;
@@ -279,10 +265,24 @@ void ProjectList::deleteClip(const int clipId)
   if (item) delete item;
 }
 
-void ProjectList::slotAddClip()
+void ProjectList::slotAddFolder()
+{
+  QString folderName = KInputDialog::getText(i18n("New Folder"), i18n("Enter new folder name: "));
+  if (folderName.isEmpty()) return;
+  QStringList itemEntry;
+  itemEntry.append(QString::null);
+  itemEntry.append(folderName);
+  AddClipCommand *command = new AddClipCommand(this, itemEntry, QDomElement(), m_clipIdCounter++, KUrl(), folderName, true);
+  m_commandStack->push(command);
+}
+
+void ProjectList::slotAddClip(QUrl givenUrl, const QString &group)
 {
   if (!m_commandStack) kDebug()<<"!!!!!!!!!!!!!!!!  NO CMD STK";
-  KUrl::List list = KFileDialog::getOpenUrls( KUrl(), "application/vnd.kde.kdenlive application/vnd.westley.scenelist application/flv application/vnd.rn-realmedia video/x-dv video/x-msvideo video/mpeg video/x-ms-wmv audio/x-mp3 audio/x-wav application/ogg *.m2t *.dv video/mp4 video/quicktime image/gif image/jpeg image/png image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr");
+  KUrl::List list;
+  if (givenUrl.isEmpty())
+    list = KFileDialog::getOpenUrls( KUrl(), "application/vnd.kde.kdenlive application/vnd.westley.scenelist application/flv application/vnd.rn-realmedia video/x-dv video/x-msvideo video/mpeg video/x-ms-wmv audio/x-mp3 audio/x-wav application/ogg *.m2t *.dv video/mp4 video/quicktime image/gif image/jpeg image/png image/x-bmp image/svg+xml image/tiff image/x-xcf-gimp image/x-vnd.adobe.photoshop image/x-pcx image/x-exr");
+  else list.append(givenUrl);
   if (list.isEmpty()) return;
   KUrl::List::Iterator it;
   KUrl url;
@@ -290,9 +290,18 @@ void ProjectList::slotAddClip()
 
   for (it = list.begin(); it != list.end(); it++) {
       QStringList itemEntry;
+      QDomDocument doc;
+      QDomElement prod = doc.createElement("producer");
+      prod.setAttribute("resource", (*it).path());
       itemEntry.append(QString::null);
       itemEntry.append((*it).fileName());
-      AddClipCommand *command = new AddClipCommand(this, itemEntry, QDomElement(), m_clipIdCounter++, *it, true);
+      KMimeType::Ptr type = KMimeType::findByUrl(*it);
+      if (type->name().startsWith("image/")) {
+       prod.setAttribute("type", (int) IMAGE);
+       prod.setAttribute("in", "0");
+       prod.setAttribute("out", m_timecode.getFrameCount(KdenliveSettings::image_duration(), m_fps));
+      }
+      AddClipCommand *command = new AddClipCommand(this, itemEntry, prod, m_clipIdCounter++, *it, group, true);
       m_commandStack->push(command);
       //item = new ProjectItem(listView, itemEntry, QDomElement());
       //item->setData(1, FullPathRole, (*it).path());
@@ -316,14 +325,14 @@ void ProjectList::slotAddColorClip()
     QString color = dia_ui->clip_color->color().name();
     color = color.replace(0, 1, "0x") + "ff";
     element.setAttribute("colour", color);
-    element.setAttribute("type", (int) DocClipBase::COLOR);
+    element.setAttribute("type", (int) COLOR);
     element.setAttribute("in", "0");
     element.setAttribute("out", m_timecode.getFrameCount(dia_ui->clip_duration->text(), m_fps));
     element.setAttribute("name", dia_ui->clip_name->text());
     QStringList itemEntry;
     itemEntry.append(QString::null);
     itemEntry.append(dia_ui->clip_name->text());
-    AddClipCommand *command = new AddClipCommand(this, itemEntry, element, m_clipIdCounter++, KUrl(), true);
+    AddClipCommand *command = new AddClipCommand(this, itemEntry, element, m_clipIdCounter++, KUrl(), QString::null, true);
     m_commandStack->push(command);
     // ProjectItem *item = new ProjectItem(listView, itemEntry, element, m_clipIdCounter++);
     /*QPixmap pix(60, 40);
@@ -375,7 +384,10 @@ QDomElement ProjectList::producersList()
 void ProjectList::slotReplyGetFileProperties(int clipId, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata)
 {
   ProjectItem *item = getItemById(clipId);
-  if (item) item->setProperties(properties, metadata);
+  if (item) {
+    item->setProperties(properties, metadata);
+    emit receivedClipDuration(clipId, item->clipMaxDuration());
+  }
 }
 
 
@@ -401,7 +413,7 @@ ProjectItem *ProjectList::getItemById(int id)
 void ProjectList::addProducer(QDomElement producer, int parentId)
 {
   if (!m_commandStack) kDebug()<<"!!!!!!!!!!!!!!!!  NO CMD STK";
-  DocClipBase::CLIPTYPE type = (DocClipBase::CLIPTYPE) producer.attribute("type").toInt();
+  CLIPTYPE type = (CLIPTYPE) producer.attribute("type").toInt();
 
     /*QDomDocument doc;
     QDomElement prods = doc.createElement("list");
@@ -411,17 +423,22 @@ void ProjectList::addProducer(QDomElement producer, int parentId)
 
   //kDebug()<<"//////  ADDING PRODUCER:\n "<<doc.toString()<<"\n+++++++++++++++++";
   int id = producer.attribute("id").toInt();
+  QString groupName = producer.attribute("group");
   if (id >= m_clipIdCounter) m_clipIdCounter = id + 1;
   else if (id == 0) id = m_clipIdCounter++;
 
-  if (type == DocClipBase::AUDIO || type == DocClipBase::VIDEO || type == DocClipBase::AV || type == DocClipBase::IMAGE  || type == DocClipBase::PLAYLIST)
+  if (parentId != -1) {
+    // item is a westley playlist, adjust subproducers ids 
+    id = (parentId + 1) * 10000 + id;
+  }
+  if (type == AUDIO || type == VIDEO || type == AV || type == IMAGE  || type == PLAYLIST)
   {
     KUrl resource = KUrl(producer.attribute("resource"));
     if (!resource.isEmpty()) {
       QStringList itemEntry;
       itemEntry.append(QString::null);
       itemEntry.append(resource.fileName());
-      addClip(itemEntry, producer, id, resource, parentId);
+      addClip(itemEntry, producer, id, resource, groupName, parentId);
       /*AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, id, resource, true);
       m_commandStack->push(command);*/
 
@@ -432,7 +449,7 @@ void ProjectList::addProducer(QDomElement producer, int parentId)
       
     }
   }
-  else if (type == DocClipBase::COLOR) {
+  else if (type == COLOR) {
     QString colour = producer.attribute("colour");
     QPixmap pix(60, 40);
     colour = colour.replace(0, 2, "#");
@@ -440,7 +457,7 @@ void ProjectList::addProducer(QDomElement producer, int parentId)
     QStringList itemEntry;
     itemEntry.append(QString::null);
     itemEntry.append(producer.attribute("name", i18n("Color clip")));
-    addClip(itemEntry, producer, id, KUrl(), parentId);
+    addClip(itemEntry, producer, id, KUrl(), groupName, parentId);
     /*AddClipCommand *command = new AddClipCommand(this, itemEntry, producer, id, KUrl(), true);
     m_commandStack->push(command);*/
     //ProjectItem *item = new ProjectItem(listView, itemEntry, producer);