]> git.sesse.net Git - kdenlive/commitdiff
Improved Dvd Wizard (new chapters dialog)
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 18 May 2009 17:48:14 +0000 (17:48 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 18 May 2009 17:48:14 +0000 (17:48 +0000)
svn path=/trunk/kdenlive/; revision=3391

12 files changed:
src/CMakeLists.txt
src/dvdwizard.cpp
src/dvdwizard.h
src/dvdwizardchapters.cpp [new file with mode: 0644]
src/dvdwizardchapters.h [new file with mode: 0644]
src/dvdwizardvob.cpp
src/dvdwizardvob.h
src/monitor.cpp
src/monitor.h
src/monitormanager.cpp
src/timecode.cpp
src/timecode.h

index a365f8c9ba3ee65dc1fa8dc3d1011b3f76c1c8c7..a0a2690f7040a1d8e4bf3b8337b4334115483a92 100644 (file)
@@ -70,6 +70,7 @@ kde4_add_ui_files(kdenlive_UI
   widgets/dvdwizardmenu_ui.ui
   widgets/dvdwizardiso_ui.ui
   widgets/dvdwizardstatus_ui.ui
+  widgets/dvdwizardchapters_ui.ui
   widgets/missingclips_ui.ui
 )
  
@@ -157,6 +158,7 @@ set(kdenlive_SRCS
   splitaudiocommand.cpp
   changecliptypecommand.cpp
   documentchecker.cpp
+  dvdwizardchapters.cpp
 )
 
 add_definitions( ${KDE4_DEFINITIONS} )
index 7d83c589bb4fd0dd67ff9b4e258f7cfa3195c617..2cfe9dccbe582e6fdd88de923918c32ca7d3e38e 100644 (file)
@@ -21,6 +21,8 @@
 #include "dvdwizard.h"
 #include "kdenlivesettings.h"
 #include "profilesdialog.h"
+#include "timecode.h"
+#include "monitormanager.h"
 
 #include <KStandardDirs>
 #include <KLocale>
@@ -47,9 +49,15 @@ DvdWizard::DvdWizard(const QString &url, const QString &profile, QWidget *parent
     m_pageVob = new DvdWizardVob(profile, this);
     m_pageVob->setTitle(i18n("Select Files For Your DVD"));
     addPage(m_pageVob);
-
     if (!url.isEmpty()) m_pageVob->setUrl(url);
 
+
+    m_pageChapters = new DvdWizardChapters(m_pageVob->isPal(), this);
+    m_pageChapters->setTitle(i18n("DVD Chapters"));
+    addPage(m_pageChapters);
+
+
+
     m_pageMenu = new DvdWizardMenu(profile, this);
     m_pageMenu->setTitle(i18n("Create DVD Menu"));
     addPage(m_pageMenu);
@@ -113,13 +121,15 @@ DvdWizard::~DvdWizard()
 
 void DvdWizard::slotPageChanged(int page)
 {
-    kDebug() << "// PAGE CHGD: " << page;
+    kDebug() << "// PAGE CHGD: " << page << ", ID: " << visitedPages();
     if (page == 1) {
-        m_pageMenu->setTargets(m_pageVob->selectedTitles(), m_pageVob->selectedTargets());
-        m_pageMenu->changeProfile(m_pageVob->isPal());
+        m_pageChapters->setVobFiles(m_pageVob->isPal(), m_pageVob->selectedUrls(), m_pageVob->durations());
     } else if (page == 2) {
-        //m_pageMenu->buttonsInfo();
+        m_pageMenu->setTargets(m_pageChapters->selectedTitles(), m_pageChapters->selectedTargets());
+        m_pageMenu->changeProfile(m_pageVob->isPal());
     } else if (page == 3) {
+        //m_pageMenu->buttonsInfo();
+    } else if (page == 4) {
         // clear job icons
         for (int i = 0; i < m_status.job_progress->count(); i++)
             m_status.job_progress->item(i)->setIcon(KIcon());
@@ -396,11 +406,10 @@ void DvdWizard::generateDvd()
             titles.appendChild(pgc2);
             QDomElement vob = dvddoc.createElement("vob");
             vob.setAttribute("file", voburls.at(i));
-            if (m_pageVob->useChapters()) {
-                // Add chapters
-                QStringList chaptersList = m_pageVob->chapter(i);
-                if (!chaptersList.isEmpty()) vob.setAttribute("chapters", chaptersList.join(","));
-            }
+            // Add chapters
+            QStringList chaptersList = m_pageChapters->chapters(i);
+            if (!chaptersList.isEmpty()) vob.setAttribute("chapters", chaptersList.join(","));
+
             pgc2.appendChild(vob);
             if (m_pageMenu->createMenu()) {
                 QDomElement post = dvddoc.createElement("post");
@@ -564,3 +573,9 @@ void DvdWizard::slotBurn()
 
 
 
+
+
+
+
+
+
index 524d6e2b21629c1a54aba0b2030d7f644c7b34f5..46534bbbf7aa27e61796eebc76ed66ae97420e77 100644 (file)
 
 #include "dvdwizardvob.h"
 #include "dvdwizardmenu.h"
+#include "dvdwizardchapters.h"
 #include "ui_dvdwizardiso_ui.h"
 #include "ui_dvdwizardstatus_ui.h"
+#include "ui_dvdwizardchapters_ui.h"
 
 class DvdWizard : public QWizard
 {
@@ -48,6 +50,7 @@ private:
     DvdWizardMenu *m_pageMenu;
     Ui::DvdWizardIso_UI m_iso;
     Ui::DvdWizardStatus_UI m_status;
+    DvdWizardChapters *m_pageChapters;
     KTemporaryFile m_menuFile;
     KTemporaryFile m_authorFile;
     QProcess *m_dvdauthor;
diff --git a/src/dvdwizardchapters.cpp b/src/dvdwizardchapters.cpp
new file mode 100644 (file)
index 0000000..1eafceb
--- /dev/null
@@ -0,0 +1,208 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+#include "dvdwizardchapters.h"
+
+#include <KDebug>
+
+#include <QFile>
+
+DvdWizardChapters::DvdWizardChapters(bool isPal, QWidget *parent) :
+        QWizardPage(parent),
+        m_isPal(isPal)
+
+{
+    m_view.setupUi(this);
+    connect(m_view.vob_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateChaptersList()));
+    connect(m_view.button_add, SIGNAL(clicked()), this, SLOT(slotAddChapter()));
+    connect(m_view.button_delete, SIGNAL(clicked()), this, SLOT(slotRemoveChapter()));
+    connect(m_view.chapters_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotGoToChapter()));
+
+    // Build monitor for chapters
+
+    if (m_isPal) m_tc.setFormat(25);
+    else m_tc.setFormat(30, true);
+
+    m_manager = new MonitorManager(this);
+    m_manager->resetProfiles(m_tc);
+    m_monitor = new Monitor("chapter", m_manager, this);
+    m_monitor->start();
+
+    QVBoxLayout *vbox = new QVBoxLayout;
+    vbox->addWidget(m_monitor);
+    m_view.monitor_frame->setLayout(vbox);
+
+
+}
+
+DvdWizardChapters::~DvdWizardChapters()
+{
+    delete m_monitor;
+    delete m_manager;
+}
+
+// virtual
+
+bool DvdWizardChapters::isComplete() const
+{
+    return true;
+}
+
+void DvdWizardChapters::slotUpdateChaptersList()
+{
+    m_monitor->slotOpenFile(m_view.vob_list->currentText());
+    m_monitor->adjustRulerSize(m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole).toInt());
+    QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
+
+    // insert chapters
+    QStringList chaptersString;
+    for (int i = 0; i < currentChaps.count(); i++) {
+        chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps()));
+    }
+    m_view.chapters_list->clear();
+    m_view.chapters_list->addItems(chaptersString);
+}
+
+void DvdWizardChapters::slotAddChapter()
+{
+    int pos = m_monitor->position().frames(m_tc.fps());
+    QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
+    if (currentChaps.contains(QString::number(pos))) return;
+    else currentChaps.append(QString::number(pos));
+    QList <int> chapterTimes;
+    for (int i = 0; i < currentChaps.count(); i++)
+        chapterTimes.append(currentChaps.at(i).toInt());
+    qSort(chapterTimes);
+
+    // rebuild chapters
+    QStringList chaptersString;
+    currentChaps.clear();
+    for (int i = 0; i < chapterTimes.count(); i++) {
+        chaptersString.append(Timecode::getStringTimecode(chapterTimes.at(i), m_tc.fps()));
+        currentChaps.append(QString::number(chapterTimes.at(i)));
+    }
+    m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), currentChaps, Qt::UserRole + 1);
+    m_view.chapters_list->clear();
+    m_view.chapters_list->addItems(chaptersString);
+}
+
+void DvdWizardChapters::slotRemoveChapter()
+{
+    int ix = m_view.chapters_list->currentRow();
+    QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
+    currentChaps.removeAt(ix);
+    m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), currentChaps, Qt::UserRole + 1);
+
+    // rebuild chapters
+    QStringList chaptersString;
+    for (int i = 0; i < currentChaps.count(); i++) {
+        chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps()));
+    }
+    m_view.chapters_list->clear();
+    m_view.chapters_list->addItems(chaptersString);
+}
+
+void DvdWizardChapters::slotGoToChapter()
+{
+    m_monitor->setTimePos(m_view.chapters_list->currentItem()->text() + ":00");
+}
+
+void DvdWizardChapters::slotGetChaptersList(int ix)
+{
+    QString url = m_view.vob_list->itemText(ix);
+    if (QFile::exists(url + ".dvdchapter")) {
+        // insert chapters as children
+        QFile file(url + ".dvdchapter");
+        if (file.open(QIODevice::ReadOnly)) {
+            QDomDocument doc;
+            doc.setContent(&file);
+            file.close();
+            QDomNodeList chapters = doc.elementsByTagName("chapter");
+            QStringList chaptersList;
+            for (int j = 0; j < chapters.count(); j++) {
+                chaptersList.append(QString::number(chapters.at(j).toElement().attribute("time").toInt()));
+            }
+            m_view.vob_list->setItemData(ix, chaptersList, Qt::UserRole + 1);
+        }
+    }
+}
+
+void DvdWizardChapters::setVobFiles(bool isPal, const QStringList movies, const QStringList durations)
+{
+    m_isPal = isPal;
+    if (m_isPal) m_tc.setFormat(25);
+    else m_tc.setFormat(30, true);
+    m_manager->resetProfiles(m_tc);
+    m_monitor->resetProfile();
+
+    if (m_view.vob_list->count() == movies.count()) {
+        bool equal = true;
+        for (int i = 0; i < movies.count(); i++) {
+            if (movies.at(i) != m_view.vob_list->itemText(i)) {
+                equal = false;
+                break;
+            }
+        }
+        if (equal) return;
+    }
+    m_view.vob_list->clear();
+    for (int i = 0; i < movies.count(); i++) {
+        m_view.vob_list->addItem(movies.at(i), durations.at(i));
+        slotGetChaptersList(i);
+    }
+    slotUpdateChaptersList();
+}
+
+QStringList DvdWizardChapters::selectedTitles() const
+{
+    QStringList result;
+    int max = m_view.vob_list->count();
+    for (int i = 0; i < max; i++) {
+        result.append(m_view.vob_list->itemText(i));
+        QStringList chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList();
+        for (int j = 0; j < chapters.count(); j++) {
+            result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps()));
+        }
+    }
+    return result;
+}
+
+QStringList DvdWizardChapters::chapters(int ix) const
+{
+    QStringList result;
+    QStringList chapters = m_view.vob_list->itemData(ix, Qt::UserRole + 1).toStringList();
+    for (int j = 0; j < chapters.count(); j++) {
+        result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps()));
+    }
+    return result;
+}
+
+QStringList DvdWizardChapters::selectedTargets() const
+{
+    QStringList result;
+    int max = m_view.vob_list->count();
+    for (int i = 0; i < max; i++) {
+        result.append("jump title " + QString::number(i + 1));
+        QStringList chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList();
+        for (int j = 0; j < chapters.count(); j++) {
+            result.append("jump title " + QString::number(i + 1) + " chapter " + QString::number(j + 1));
+        }
+    }
+    return result;
+}
diff --git a/src/dvdwizardchapters.h b/src/dvdwizardchapters.h
new file mode 100644 (file)
index 0000000..7747102
--- /dev/null
@@ -0,0 +1,64 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#ifndef DVDWIZARDCHAPTERS_H
+#define DVDWIZARDCHAPTERS_H
+
+#include <QWizardPage>
+
+#include <KDebug>
+
+#include "ui_dvdwizardchapters_ui.h"
+#include "monitor.h"
+#include "monitormanager.h"
+
+class DvdWizardChapters : public QWizardPage
+{
+    Q_OBJECT
+
+public:
+    explicit DvdWizardChapters(bool isPal, QWidget * parent = 0);
+    virtual ~DvdWizardChapters();
+    virtual bool isComplete() const;
+    void changeProfile(bool isPal);
+    void slotGetChaptersList(int ix);
+    void setPal(bool isPal);
+    void setVobFiles(bool isPal, const QStringList movies, const QStringList durations);
+    QStringList selectedTitles() const;
+    QStringList selectedTargets() const;
+    QStringList chapters(int ix) const;
+
+private:
+    Ui::DvdWizardChapters_UI m_view;
+    bool m_isPal;
+    MonitorManager *m_manager;
+    Monitor *m_monitor;
+    Timecode m_tc;
+
+
+private slots:
+    void slotUpdateChaptersList();
+    void slotAddChapter();
+    void slotRemoveChapter();
+    void slotGoToChapter();
+};
+
+#endif
+
index b436db9b408f0a52b377e14013c7d9680692e9a8..8f44776081b934845a75f0a1ca3795533e928022 100644 (file)
@@ -98,22 +98,6 @@ void DvdWizardVob::slotAddVobFile(KUrl url)
     QTreeWidgetItem *item = new QTreeWidgetItem(m_view.vobs_list, QStringList() << url.path() << QString() << KIO::convertSize(fileSize));
     item->setData(0, Qt::UserRole, fileSize);
     item->setIcon(0, KIcon("video-x-generic"));
-    if (QFile::exists(url.path() + ".dvdchapter")) {
-        // insert chapters as children
-        QFile file(url.path() + ".dvdchapter");
-        if (file.open(QIODevice::ReadOnly)) {
-            QDomDocument doc;
-            doc.setContent(&file);
-            file.close();
-            QDomNodeList chapters = doc.elementsByTagName("chapter");
-            QStringList chaptersList;
-            for (int j = 0; j < chapters.count(); j++) {
-                QTreeWidgetItem *sub = new QTreeWidgetItem(item, QStringList() << QString::number(j) + " - " + chapters.at(j).toElement().attribute("title"));
-                sub->setText(1, Timecode::getStringTimecode(chapters.at(j).toElement().attribute("time").toInt(), profile.fps()));
-                sub->setData(1, Qt::UserRole, chapters.at(j).toElement().attribute("time").toInt());
-            }
-        }
-    }
 
     QPixmap pix(60, 45);
 
@@ -124,7 +108,9 @@ void DvdWizardVob::slotAddVobFile(KUrl url)
     if (producer->is_blank() == false) {
         pix = KThumb::getFrame(producer, 0, 60, 45);
         item->setIcon(0, pix);
-        item->setText(1, Timecode::getStringTimecode(producer->get_playtime(), profile.fps()));
+        int playTime = producer->get_playtime();
+        item->setText(1, Timecode::getStringTimecode(playTime, profile.fps()));
+        item->setData(1, Qt::UserRole, playTime);
     }
     delete producer;
 
@@ -178,11 +164,6 @@ bool DvdWizardVob::isComplete() const
     return true;
 }
 
-bool DvdWizardVob::useChapters() const
-{
-    return true; //m_view.use_chapters->isChecked();
-}
-
 void DvdWizardVob::setUrl(const QString &url)
 {
     slotAddVobFile(KUrl(url));
@@ -200,52 +181,25 @@ QStringList DvdWizardVob::selectedUrls() const
     return result;
 }
 
-QStringList DvdWizardVob::selectedTitles() const
+
+QStringList DvdWizardVob::durations() const
 {
     QStringList result;
+    QString path;
     int max = m_view.vobs_list->topLevelItemCount();
     for (int i = 0; i < max; i++) {
         QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(i);
-        if (item) {
-            result.append(item->text(0));
-            int submax = item->childCount();
-            for (int j = 0; j < submax; j++) {
-                QTreeWidgetItem *subitem = item->child(j);
-                result.append(subitem->text(0) + ' ' + subitem->text(1));
-            }
-        }
+        if (item) result.append(QString::number(item->data(1, Qt::UserRole).toInt()));
     }
     return result;
 }
 
-QStringList DvdWizardVob::chapter(int ix) const
+int DvdWizardVob::duration(int ix) const
 {
-    QStringList result;
+    int result = -1;
     QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(ix);
     if (item) {
-        int submax = item->childCount();
-        for (int j = 0; j < submax; j++) {
-            QTreeWidgetItem *subitem = item->child(j);
-            result.append(subitem->text(1));
-        }
-    }
-    return result;
-}
-
-QStringList DvdWizardVob::selectedTargets() const
-{
-    QStringList result;
-    int max = m_view.vobs_list->topLevelItemCount();
-    for (int i = 0; i < max; i++) {
-        QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(i);
-        if (item) {
-            result.append("jump title " + QString::number(i + 1));
-            int submax = item->childCount();
-            for (int j = 0; j < submax; j++) {
-                QTreeWidgetItem *subitem = item->child(j);
-                result.append("jump title " + QString::number(i + 1) + " chapter " + QString::number(j + 1));
-            }
-        }
+        result = item->data(1, Qt::UserRole).toInt();
     }
     return result;
 }
index 028ce85402cf48b85abb60783a5b20cd88af7711..40f69a69ae6e58e3c55fd2b1e9d4b69aeb201644 100644 (file)
@@ -42,13 +42,11 @@ public:
     virtual ~DvdWizardVob();
     virtual bool isComplete() const;
     QStringList selectedUrls() const;
-    QStringList selectedTitles() const;
-    QStringList selectedTargets() const;
     void setUrl(const QString &url);
     QString introMovie() const;
-    bool useChapters() const;
     bool isPal() const;
-    QStringList chapter(int ix) const;
+    int duration(int ix) const;
+    QStringList durations() const;
 
 private:
     Ui::DvdWizardVob_UI m_view;
index b7b40c475a6b776596c841ed5280a19ae3db1aad..571fb884d75abb273fd23653c0f36e93785b6ddc 100644 (file)
@@ -436,6 +436,12 @@ void Monitor::activateMonitor()
     if (!m_isActive) m_monitorManager->switchMonitors(); //m_monitorManager->activateMonitor(m_name);
 }
 
+void Monitor::setTimePos(const QString &pos)
+{
+    m_timePos->setText(pos);
+    slotSeek();
+}
+
 void Monitor::slotSeek()
 {
     const int frames = m_monitorManager->timecode().getFrameCount(m_timePos->text(), m_monitorManager->timecode().fps());
index 34091bd0f8e8b60baa17025bb8f0fa5d4b6f251d..bd0c0dda26141bdf84502a655dfa8a58aa647a14 100644 (file)
@@ -153,6 +153,7 @@ public slots:
     void slotSeekToNextSnap();
     void slotSeekToPreviousSnap();
     void adjustRulerSize(int length);
+    void setTimePos(const QString &pos);
 
 signals:
     void renderPosition(int);
index 9a94f2379d8a2a3c213c813658bea3a1c4370a55..923f08ccb609dbdf239bd112dbb95500f648f620 100644 (file)
@@ -28,7 +28,9 @@
 
 
 MonitorManager::MonitorManager(QWidget *parent) :
-        QObject(parent)
+        QObject(parent),
+        m_clipMonitor(NULL),
+        m_projectMonitor(NULL)
 {
 }
 
@@ -155,6 +157,7 @@ void MonitorManager::resetProfiles(Timecode tc)
 
 void MonitorManager::slotResetProfiles()
 {
+    if (m_projectMonitor == NULL || m_clipMonitor == NULL) return;
     activateMonitor("clip");
     m_clipMonitor->resetProfile();
     activateMonitor("project");
index cc429252ca8eace7a3c3d5237a6b0adbae2c638a..e2fe09e26a0eb38d0ece6b2ce324e33e6db3a577 100644 (file)
@@ -30,7 +30,7 @@ Timecode::~Timecode()
 {
 }
 
-int Timecode::fps()
+int Timecode::fps() const
 {
     return m_displayedFramesPerSecond;
 }
index 15c8167d7d74151f3302bc4901eb17d706c360c6..c431b6f5bcadd3ccfd026844303ac03617298a14 100644 (file)
@@ -53,7 +53,7 @@ public:
     static QString getEasyTimecode(const GenTime & time, const double &fps);
     static QString getStringTimecode(int frames, const double &fps);
     QString getTimecodeFromFrames(int frames);
-    int fps();
+    int fps() const;
 
 private:
     Formats m_format;