]> git.sesse.net Git - kdenlive/commitdiff
Load & save markers (audacity compatible):
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 22 Sep 2012 15:17:24 +0000 (17:17 +0200)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 22 Sep 2012 15:17:24 +0000 (17:17 +0200)
http://kdenlive.org/mantis/view.php?id=2742

src/clipproperties.cpp
src/clipproperties.h
src/customtrackview.cpp
src/customtrackview.h
src/mainwindow.cpp
src/widgets/clipproperties_ui.ui

index ed52808bf6b4e0b1d3e1887c6d18fab27c88a46b..ad2b0c427795e0e3ed718f60c7a68c4072d59755 100644 (file)
@@ -466,6 +466,10 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg
     m_view.marker_edit->setToolTip(i18n("Edit marker"));
     m_view.marker_delete->setIcon(KIcon("trash-empty"));
     m_view.marker_delete->setToolTip(i18n("Delete marker"));
+    m_view.marker_save->setIcon(KIcon("document-save-as"));
+    m_view.marker_save->setToolTip(i18n("Save markers"));
+    m_view.marker_load->setIcon(KIcon("document-open"));
+    m_view.marker_load->setToolTip(i18n("Load markers"));
 
         // Check for Nepomuk metadata
 #ifdef USE_NEPOMUK
@@ -492,10 +496,12 @@ ClipProperties::ClipProperties(DocClipBase *clip, Timecode tc, double fps, QWidg
     m_view.clip_license->setHidden(true);
 #endif
     
-    slotFillMarkersList();
+    slotFillMarkersList(m_clip);
     connect(m_view.marker_new, SIGNAL(clicked()), this, SLOT(slotAddMarker()));
     connect(m_view.marker_edit, SIGNAL(clicked()), this, SLOT(slotEditMarker()));
     connect(m_view.marker_delete, SIGNAL(clicked()), this, SLOT(slotDeleteMarker()));
+    connect(m_view.marker_save, SIGNAL(clicked()), this, SLOT(slotSaveMarkers()));
+    connect(m_view.marker_load, SIGNAL(clicked()), this, SLOT(slotLoadMarkers()));
     connect(m_view.markers_list, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotEditMarker()));
 
     connect(this, SIGNAL(accepted()), this, SLOT(slotApplyProperties()));
@@ -703,8 +709,9 @@ void ClipProperties::slotEnableLumaFile(int state)
     m_view.label_softness->setEnabled(enable);
 }
 
-void ClipProperties::slotFillMarkersList()
+void ClipProperties::slotFillMarkersList(DocClipBase *clip)
 {
+    if (m_clip != clip) return;
     m_view.markers_list->clear();
     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
     for (int count = 0; count < marks.count(); ++count) {
@@ -723,10 +730,19 @@ void ClipProperties::slotAddMarker()
     if (d->exec() == QDialog::Accepted) {
         emit addMarker(m_clip->getId(), d->newMarker().time(), d->newMarker().comment());
     }
-    QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
     delete d;
 }
 
+void ClipProperties::slotSaveMarkers()
+{
+    emit saveMarkers(m_clip->getId());
+}
+
+void ClipProperties::slotLoadMarkers()
+{
+    emit loadMarkers(m_clip->getId());
+}
+
 void ClipProperties::slotEditMarker()
 {
     QList < CommentedTime > marks = m_clip->commentedSnapMarkers();
@@ -736,7 +752,6 @@ void ClipProperties::slotEditMarker()
     if (d.exec() == QDialog::Accepted) {
         emit addMarker(m_clip->getId(), d.newMarker().time(), d.newMarker().comment());
     }
-    QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
 }
 
 void ClipProperties::slotDeleteMarker()
@@ -745,8 +760,6 @@ void ClipProperties::slotDeleteMarker()
     int pos = m_view.markers_list->currentIndex().row();
     if (pos < 0 || pos > marks.count() - 1) return;
     emit addMarker(m_clip->getId(), marks.at(pos).time(), QString());
-
-    QTimer::singleShot(500, this, SLOT(slotFillMarkersList()));
 }
 
 const QString &ClipProperties::clipId() const
index 93cf57eb8a2aa919c15f905246e6dca6ea3be664..17f143ce3bad14dd32f1a36b9073028b2f0c3692 100644 (file)
@@ -55,13 +55,15 @@ public:
     bool needsTimelineRefresh() const;
     bool needsTimelineReload() const;
     void disableClipId(const QString &id);
+
+public slots:
+    void slotFillMarkersList(DocClipBase *clip);
     
 private slots:
     void parseFolder();
     void slotAddMarker();
     void slotEditMarker();
     void slotDeleteMarker();
-    void slotFillMarkersList();
     void slotCheckMaxLength();
     void slotEnableLuma(int state);
     void slotEnableLumaFile(int state);
@@ -70,6 +72,8 @@ private slots:
     void slotModified();
     void slotDeleteProxy();
     void slotOpenUrl(const QString &url);
+    void slotSaveMarkers();
+    void slotLoadMarkers();
 
 private:
     Ui::ClipProperties_UI m_view;
@@ -90,6 +94,8 @@ signals:
     void addMarker(const QString &, GenTime, QString);
     void deleteProxy(const QString);
     void applyNewClipProperties(const QString, QMap <QString, QString> , QMap <QString, QString> , bool, bool);
+    void saveMarkers(const QString &);
+    void loadMarkers(const QString &);
 };
 
 
index 1edb555b9e51ab6b0c9782a6e5d60608108ed8e0..9ed99e8db4c04ee89a45a3fee2984346a6ed7e38 100644 (file)
@@ -73,6 +73,7 @@
 #include <KCursor>
 #include <KMessageBox>
 #include <KIO/NetAccess>
+#include <KFileDialog>
 
 #include <QMouseEvent>
 #include <QStylePainter>
@@ -5195,11 +5196,11 @@ void CustomTrackView::clipEnd()
     }
 }
 
-void CustomTrackView::slotAddClipMarker(const QString &id, GenTime t, QString c)
+void CustomTrackView::slotAddClipMarker(const QString &id, GenTime t, QString c, QUndoCommand *groupCommand)
 {
     QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
-    AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t);
-    m_commandStack->push(command);
+    AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t, groupCommand);
+    if (!groupCommand) m_commandStack->push(command);
 }
 
 void CustomTrackView::slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position)
@@ -5226,6 +5227,85 @@ void CustomTrackView::slotDeleteAllClipMarkers(const QString &id)
     m_commandStack->push(deleteMarkers);
 }
 
+void CustomTrackView::slotSaveClipMarkers(const QString &id)
+{
+    DocClipBase *base = m_document->clipManager()->getClipById(id);
+    QList < CommentedTime > markers = base->commentedSnapMarkers();
+    QString data;
+    for (int i = 0; i < markers.count(); i++) {
+       data.append(QString::number(markers.at(i).time().seconds()));
+       data.append("\t");
+       data.append(QString::number(markers.at(i).time().seconds()));
+       data.append("\t");
+       data.append(markers.at(i).comment());
+       data.append("\n");
+    }
+    if (!data.isEmpty()) {
+       QString url = KFileDialog::getSaveFileName(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Save markers"));
+       if (url.isEmpty()) return;
+       QFile file(url);
+       if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+           emit displayMessage(i18n("Cannot open file %1", url), ErrorMessage);
+           return;
+       }
+       file.write(data.toUtf8());
+       file.close();
+    }
+}
+
+void CustomTrackView::slotLoadClipMarkers(const QString &id)
+{
+    KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Load marker file"));
+    if (url.isEmpty()) return;
+    QFile file(url.path());
+    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+       emit displayMessage(i18n("Cannot open file %1", url.fileName()), ErrorMessage);
+       return;
+    }
+    QString data = QString::fromUtf8(file.readAll());
+    file.close();
+    QStringList lines = data.split("\n", QString::SkipEmptyParts);
+    QStringList values;
+    bool ok;
+    QUndoCommand *command = new QUndoCommand();
+    command->setText("Load markers");
+    QString markerText;
+    foreach(QString line, lines) {
+       markerText.clear();
+       values = line.split("\t", QString::SkipEmptyParts);
+       double time1 = values.at(0).toDouble(&ok);
+       double time2 = -1;
+       if (!ok) continue;
+       if (values.count() >1) {
+           time2 = values.at(1).toDouble(&ok);
+           if (values.count() == 2) {
+               // Check if second value is a number or text
+               if (!ok) {
+                   time2 = -1;
+                   markerText = values.at(1);
+               }
+               else markerText = i18n("Marker");
+           }
+           else {
+               // We assume 3 values per line: in out name
+               if (!ok) {
+                   // 2nd value is not a number, drop
+               }
+               else {
+                   markerText = values.at(2);
+               }
+           }
+       }
+       if (!markerText.isEmpty()) {
+           // Marker found, add it
+           slotAddClipMarker(id, GenTime(time1), markerText, command);
+           if (time2 > 0 && time2 != time1) slotAddClipMarker(id, GenTime(time2), markerText, command);
+       }
+    }
+    if (command->childCount() > 0) m_commandStack->push(command);
+    else delete command;
+}
+
 void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QString &comment)
 {
     DocClipBase *base = m_document->clipManager()->getClipById(id);
index c493ceb68e6d20e1e6a8b6926c1dfc781a96a0c2..1f322854a481ad9acea0e726faea4152b31571bf 100644 (file)
@@ -231,7 +231,9 @@ public slots:
      * @param id Id of the marker's clip
      * @param t Position of the marker
      * @param c Comment of the marker */
-    void slotAddClipMarker(const QString &id, GenTime t, QString c);
+    void slotAddClipMarker(const QString &id, GenTime t, QString c, QUndoCommand *groupCommand = 0);
+    void slotLoadClipMarkers(const QString &id);
+    void slotSaveClipMarkers(const QString &id);
     bool addGuide(const GenTime &pos, const QString &comment);
 
     /** @brief Shows a dialog for adding a guide.
index e9e5861cf8a9aca2a11082c9cf1f8d033412b0f2..d7429b83ed0153f745b51f5317e3af75c5c96c93 100644 (file)
@@ -3310,6 +3310,9 @@ void MainWindow::slotShowClipProperties(DocClipBase *clip)
     // any type of clip but a title
     ClipProperties *dia = new ClipProperties(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
     connect(dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
+    connect(m_activeTimeline->projectView(), SIGNAL(updateClipMarkers(DocClipBase *)), dia, SLOT(slotFillMarkersList(DocClipBase *)));
+    connect(dia, SIGNAL(loadMarkers(const QString &)), m_activeTimeline->projectView(), SLOT(slotLoadClipMarkers(const QString &)));
+    connect(dia, SIGNAL(saveMarkers(const QString &)), m_activeTimeline->projectView(), SLOT(slotSaveClipMarkers(const QString &)));
     connect(dia, SIGNAL(deleteProxy(const QString)), m_projectList, SLOT(slotDeleteProxy(const QString)));
     connect(dia, SIGNAL(applyNewClipProperties(const QString, QMap <QString, QString> , QMap <QString, QString> , bool, bool)), this, SLOT(slotApplyNewClipProperties(const QString, QMap <QString, QString> , QMap <QString, QString> , bool, bool)));
     dia->show();
index 41cb747d8347e8de9b6844ed4e0f9bda8a4ce6f1..21544e814c2855d8cadf2efa263d604348d5c57d 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>298</width>
-    <height>512</height>
+    <width>306</width>
+    <height>539</height>
    </rect>
   </property>
   <property name="windowTitle">
        <string>Markers</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout_7">
-       <item row="0" column="0" colspan="4">
+       <item row="0" column="0" colspan="7">
         <widget class="QTreeWidget" name="markers_list">
          <property name="alternatingRowColors">
           <bool>true</bool>
          </property>
         </widget>
        </item>
-       <item row="1" column="3">
+       <item row="1" column="6">
         <spacer name="horizontalSpacer">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
         </spacer>
        </item>
+       <item row="1" column="3">
+        <widget class="KSeparator" name="kseparator">
+         <property name="orientation">
+          <enum>Qt::Vertical</enum>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="4">
+        <widget class="QToolButton" name="marker_save">
+         <property name="text">
+          <string>...</string>
+         </property>
+         <property name="autoRaise">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="5">
+        <widget class="QToolButton" name="marker_load">
+         <property name="text">
+          <string>...</string>
+         </property>
+         <property name="autoRaise">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="tab_5">
    <extends>QLineEdit</extends>
    <header>klineedit.h</header>
   </customwidget>
+  <customwidget>
+   <class>KSeparator</class>
+   <extends>QFrame</extends>
+   <header>kseparator.h</header>
+  </customwidget>
   <customwidget>
    <class>KUrlLabel</class>
    <extends>QLabel</extends>