]> git.sesse.net Git - kdenlive/commitdiff
Updated Dvd wizard
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 16 May 2009 18:10:47 +0000 (18:10 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sat, 16 May 2009 18:10:47 +0000 (18:10 +0000)
svn path=/trunk/kdenlive/; revision=3389

src/dvdwizard.cpp
src/dvdwizardmenu.cpp
src/dvdwizardmenu.h
src/dvdwizardvob.cpp
src/dvdwizardvob.h
src/mainwindow.cpp

index 5a38f92dd11f66d128be490503c6b4dec5c2c2a1..7d83c589bb4fd0dd67ff9b4e258f7cfa3195c617 100644 (file)
@@ -44,7 +44,7 @@ DvdWizard::DvdWizard(const QString &url, const QString &profile, QWidget *parent
 {
     //setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
     setAttribute(Qt::WA_DeleteOnClose);
-    m_pageVob = new DvdWizardVob(this);
+    m_pageVob = new DvdWizardVob(profile, this);
     m_pageVob->setTitle(i18n("Select Files For Your DVD"));
     addPage(m_pageVob);
 
@@ -116,6 +116,7 @@ void DvdWizard::slotPageChanged(int page)
     kDebug() << "// PAGE CHGD: " << page;
     if (page == 1) {
         m_pageMenu->setTargets(m_pageVob->selectedTitles(), m_pageVob->selectedTargets());
+        m_pageMenu->changeProfile(m_pageVob->isPal());
     } else if (page == 2) {
         //m_pageMenu->buttonsInfo();
     } else if (page == 3) {
@@ -397,20 +398,8 @@ void DvdWizard::generateDvd()
             vob.setAttribute("file", voburls.at(i));
             if (m_pageVob->useChapters()) {
                 // Add chapters
-                if (QFile::exists(voburls.at(i) + ".dvdchapter")) {
-                    QFile file(voburls.at(i) + ".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(chapters.at(j).toElement().attribute("time"));
-                        }
-                        if (!chaptersList.isEmpty()) vob.setAttribute("chapters", chaptersList.join(","));
-                    }
-                }
+                QStringList chaptersList = m_pageVob->chapter(i);
+                if (!chaptersList.isEmpty()) vob.setAttribute("chapters", chaptersList.join(","));
             }
             pgc2.appendChild(vob);
             if (m_pageMenu->createMenu()) {
index fbe794013eb78c0682a04a291571e5fadaf33311..bfd0e7037c7c861b254e3e9c3e693240bd1ae7b5 100644 (file)
@@ -41,14 +41,11 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
     m_view.add_button->setToolTip(i18n("Add new button"));
     m_view.delete_button->setToolTip(i18n("Delete current button"));
 
-    m_view.menu_profile->addItems(QStringList() << i18n("PAL") << i18n("NTSC"));
-
     if (profile == "dv_ntsc" || profile == "dv_ntsc_wide") {
-        m_view.menu_profile->setCurrentIndex(1);
-        m_isPal = false;
-    } else m_isPal = true;
+        changeProfile(false);
+    } else changeProfile(true);
+
 
-    changeProfile(m_view.menu_profile->currentIndex());
 
     // Create color background
     m_color = new QGraphicsRectItem(0, 0, m_width, m_height);
@@ -75,7 +72,6 @@ DvdWizardMenu::DvdWizardMenu(const QString &profile, QWidget *parent) :
 
     checkBackgroundType(0);
 
-    connect(m_view.menu_profile, SIGNAL(activated(int)), this, SLOT(changeProfile(int)));
 
     // create menu button
     DvdButton *button = new DvdButton(m_view.play_text->text());
@@ -250,21 +246,19 @@ void DvdWizardMenu::deleteButton()
     }
 }
 
-void DvdWizardMenu::changeProfile(int ix)
+void DvdWizardMenu::changeProfile(bool isPal)
 {
-    switch (ix) {
-    case 1:
+    m_isPal = isPal;
+    if (isPal == false) {
         m_width = 720;
         m_height = 480;
         m_isPal = false;
         updatePreview();
-        break;
-    default:
+    } else {
         m_width = 720;
         m_height = 576;
         m_isPal = true;
         updatePreview();
-        break;
     }
 }
 
index 68ba88fdc0f664ad1e5a721965e0690eb5e7e7ac..e2987ee356519d33b52ee8cd825e008c4b0fdfcc 100644 (file)
@@ -128,6 +128,7 @@ public:
     bool menuMovie() const;
     QString menuMoviePath() const;
     bool isPalMenu() const;
+    void changeProfile(bool isPal);
 
 private:
     Ui::DvdWizardMenu_UI m_view;
@@ -145,7 +146,6 @@ private slots:
     void buildImage();
     void checkBackground();
     void checkBackgroundType(int ix);
-    void changeProfile(int ix);
     void updatePreview();
     void buttonChanged();
     void addButton();
index 25fa8b5713598eb8e2f90a7ee3b17702e37ec26b..b436db9b408f0a52b377e14013c7d9680692e9a8 100644 (file)
  ***************************************************************************/
 
 #include "dvdwizardvob.h"
+#include "kthumb.h"
+#include "timecode.h"
+
+#include <mlt++/Mlt.h>
 
 #include <KUrlRequester>
 #include <KDebug>
 #include <KStandardDirs>
 #include <KFileItem>
+#include <KFileDialog>
 
 #include <QHBoxLayout>
 #include <QDomDocument>
+#include <QTreeWidgetItem>
 
-DvdWizardVob::DvdWizardVob(QWidget *parent) :
+DvdWizardVob::DvdWizardVob(const QString &profile, QWidget *parent) :
         QWizardPage(parent)
 {
     m_view.setupUi(this);
     m_view.intro_vob->setEnabled(false);
-    m_view.vob_1->setFilter("video/mpeg");
     m_view.intro_vob->setFilter("video/mpeg");
+    m_view.button_add->setIcon(KIcon("document-new"));
+    m_view.button_delete->setIcon(KIcon("edit-delete"));
+    m_view.button_up->setIcon(KIcon("go-up"));
+    m_view.button_down->setIcon(KIcon("go-down"));
     connect(m_view.use_intro, SIGNAL(toggled(bool)), m_view.intro_vob, SLOT(setEnabled(bool)));
-    connect(m_view.vob_1, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
+    connect(m_view.button_add, SIGNAL(clicked()), this, SLOT(slotAddVobFile()));
+    connect(m_view.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteVobFile()));
+    connect(m_view.button_up, SIGNAL(clicked()), this, SLOT(slotItemUp()));
+    connect(m_view.button_down, SIGNAL(clicked()), this, SLOT(slotItemDown()));
+    connect(m_view.vobs_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckVobList()));
+    m_view.vobs_list->setIconSize(QSize(60, 45));
+
     if (KStandardDirs::findExe("dvdauthor").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.", i18n("dvdauthor")));
     if (KStandardDirs::findExe("mkisofs").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.", i18n("mkisofs")));
     if (m_errorMessage.isEmpty()) m_view.error_message->setVisible(false);
     else m_view.error_message->setText(m_errorMessage);
 
+    m_view.dvd_profile->addItems(QStringList() << i18n("PAL") << i18n("NTSC"));
+    if (profile == "dv_ntsc" || profile == "dv_ntsc_wide") {
+        m_view.dvd_profile->setCurrentIndex(1);
+    }
+    connect(m_view.dvd_profile, SIGNAL(activated(int)), this, SLOT(changeFormat()));
+    m_view.vobs_list->header()->setStretchLastSection(false);
+    m_view.vobs_list->header()->setResizeMode(0, QHeaderView::Stretch);
+    m_view.vobs_list->header()->setResizeMode(1, QHeaderView::Custom);
+    m_view.vobs_list->header()->setResizeMode(2, QHeaderView::Custom);
+
 #if KDE_IS_VERSION(4,2,0)
     m_capacityBar = new KCapacityBar(KCapacityBar::DrawTextInline, this);
     QHBoxLayout *layout = new QHBoxLayout;
@@ -49,47 +74,128 @@ DvdWizardVob::DvdWizardVob(QWidget *parent) :
 #else
     m_view.size_box->setHidden(true);
 #endif
+    slotCheckVobList();
 }
 
 DvdWizardVob::~DvdWizardVob()
 {
-    QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
-    qDeleteAll(allUrls);
 #if KDE_IS_VERSION(4,2,0)
     delete m_capacityBar;
 #endif
 }
 
-// virtual
 
+void DvdWizardVob::slotAddVobFile(KUrl url)
+{
+    if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), "video/mpeg", this, i18n("Add new video file"));
+    if (url.isEmpty()) return;
+    QFile f(url.path());
+    qint64 fileSize = f.size();
+    QString profilename;
+    if (m_view.dvd_profile->currentIndex() == 0) profilename = "dv_pal";
+    else profilename = "dv_ntsc";
+    Mlt::Profile profile((char*) profilename.data());
+    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);
+
+    char *tmp = (char *) qstrdup(url.path().toUtf8().data());
+    Mlt::Producer *producer = new Mlt::Producer(profile, tmp);
+    delete[] tmp;
+
+    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()));
+    }
+    delete producer;
+
+    slotCheckVobList();
+}
+
+void DvdWizardVob::changeFormat()
+{
+    int max = m_view.vobs_list->topLevelItemCount();
+    QString profilename;
+    if (m_view.dvd_profile->currentIndex() == 0) profilename = "dv_pal";
+    else profilename = "dv_ntsc";
+    Mlt::Profile profile((char*) profilename.data());
+    QPixmap pix(180, 135);
+
+    for (int i = 0; i < max; i++) {
+        QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(i);
+        char *tmp = (char *) qstrdup(item->text(0).toUtf8().data());
+        Mlt::Producer *producer = new Mlt::Producer(profile, tmp);
+        delete[] tmp;
+
+        if (producer->is_blank() == false) {
+            //pix = KThumb::getFrame(producer, 0, 180, 135);
+            //item->setIcon(0, pix);
+            item->setText(1, Timecode::getStringTimecode(producer->get_playtime(), profile.fps()));
+        }
+        delete producer;
+        int submax = item->childCount();
+        for (int j = 0; j < submax; j++) {
+            QTreeWidgetItem *subitem = item->child(j);
+            subitem->setText(1, Timecode::getStringTimecode(subitem->data(1, Qt::UserRole).toInt(), profile.fps()));
+        }
+    }
+    slotCheckVobList();
+}
+
+void DvdWizardVob::slotDeleteVobFile()
+{
+    QTreeWidgetItem *item = m_view.vobs_list->currentItem();
+    if (item == NULL) return;
+    delete item;
+    slotCheckVobList();
+}
+
+
+// virtual
 bool DvdWizardVob::isComplete() const
 {
     if (!m_view.error_message->text().isEmpty()) return false;
-    if (m_view.vob_1->url().path().isEmpty()) return false;
-    if (QFile::exists(m_view.vob_1->url().path())) return true;
-    return false;
+    if (m_view.vobs_list->topLevelItemCount() == 0) return false;
+    return true;
 }
 
 bool DvdWizardVob::useChapters() const
 {
-    return m_view.use_chapters->isChecked();
+    return true; //m_view.use_chapters->isChecked();
 }
 
 void DvdWizardVob::setUrl(const QString &url)
 {
-    m_view.vob_1->setPath(url);
+    slotAddVobFile(KUrl(url));
 }
 
 QStringList DvdWizardVob::selectedUrls() const
 {
     QStringList result;
     QString path;
-    QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
-    for (int i = 0; i < allUrls.count(); i++) {
-        path = allUrls.at(i)->url().path();
-        if (!path.isEmpty()) {
-            result.append(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));
     }
     return result;
 }
@@ -97,55 +203,47 @@ QStringList DvdWizardVob::selectedUrls() const
 QStringList DvdWizardVob::selectedTitles() const
 {
     QStringList result;
-    QString path;
-    QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
-    for (int i = 0; i < allUrls.count(); i++) {
-        path = allUrls.at(i)->url().path();
-        if (!path.isEmpty()) {
-            result.append(path);
-            if (useChapters() && QFile::exists(path + ".dvdchapter")) {
-                // insert chapters as targets
-                QFile file(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++) {
-                        result.append(QString::number(j) + " - " + chapters.at(j).toElement().attribute("title") + " " + chapters.at(j).toElement().attribute("time"));
-                    }
-                }
-
+    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));
             }
         }
     }
     return result;
 }
 
+QStringList DvdWizardVob::chapter(int ix) const
+{
+    QStringList result;
+    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;
-    QString path;
-    QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
-    for (int i = 0; i < allUrls.count(); i++) {
-        path = allUrls.at(i)->url().path();
-        if (!path.isEmpty()) {
+    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));
-            if (useChapters() && QFile::exists(path + ".dvdchapter")) {
-                // insert chapters as targets
-                QFile file(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++) {
-                        result.append("jump title " + QString::number(i + 1) + " chapter " + QString::number(j + 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));
             }
         }
     }
@@ -159,41 +257,55 @@ QString DvdWizardVob::introMovie() const
     return m_view.intro_vob->url().path();
 }
 
-void DvdWizardVob::slotCheckVobList(const QString &text)
+void DvdWizardVob::slotCheckVobList()
 {
     emit completeChanged();
-    QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
-    int count = allUrls.count();
-    kDebug() << "// FOUND " << count << " URLS";
-    if (count == 1) {
-        if (text.isEmpty()) return;
-        // insert second urlrequester
-        KUrlRequester *vob = new KUrlRequester(this);
-        vob->setFilter("video/mpeg");
-        m_view.vob_list->layout()->addWidget(vob);
-        connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
-    } else if (text.isEmpty()) {
-        if (allUrls.at(count - 1)->url().path().isEmpty() && allUrls.at(count - 2)->url().path().isEmpty()) {
-            // The last 2 urlrequesters are empty, remove last one
-            delete allUrls.takeLast();
-        }
-    } else {
-        if (allUrls.at(count - 1)->url().path().isEmpty()) return;
-        KUrlRequester *vob = new KUrlRequester(this);
-        vob->setFilter("video/mpeg");
-        m_view.vob_list->layout()->addWidget(vob);
-        connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
-    }
-    qint64 maxSize = (qint64) 47000 * 100000;
+    int max = m_view.vobs_list->topLevelItemCount();
+    QTreeWidgetItem *item = m_view.vobs_list->currentItem();
+    bool hasItem = true;
+    if (item == NULL) hasItem = false;
+    m_view.button_delete->setEnabled(hasItem);
+    if (hasItem && m_view.vobs_list->indexOfTopLevelItem(item) == 0) m_view.button_up->setEnabled(false);
+    else m_view.button_up->setEnabled(hasItem);
+    if (hasItem && m_view.vobs_list->indexOfTopLevelItem(item) == max - 1) m_view.button_down->setEnabled(false);
+    else m_view.button_down->setEnabled(hasItem);
+
+#if KDE_IS_VERSION(4,2,0)
     qint64 totalSize = 0;
-    for (int i = 0; i < allUrls.count(); i++) {
-        QFile f(allUrls.at(i)->url().path());
-        totalSize += f.size();
+    for (int i = 0; i < max; i++) {
+        item = m_view.vobs_list->topLevelItem(i);
+        if (item) totalSize += (qint64) item->data(0, Qt::UserRole).toInt();
     }
 
-#if KDE_IS_VERSION(4,2,0)
+    qint64 maxSize = (qint64) 47000 * 100000;
     m_capacityBar->setValue(100 * totalSize / maxSize);
     m_capacityBar->setText(KIO::convertSize(totalSize));
 #endif
 }
 
+void DvdWizardVob::slotItemUp()
+{
+    QTreeWidgetItem *item = m_view.vobs_list->currentItem();
+    if (item == NULL) return;
+    int index = m_view.vobs_list->indexOfTopLevelItem(item);
+    if (index == 0) return;
+    m_view.vobs_list->insertTopLevelItem(index - 1, m_view.vobs_list->takeTopLevelItem(index));
+}
+
+void DvdWizardVob::slotItemDown()
+{
+    int max = m_view.vobs_list->topLevelItemCount();
+    QTreeWidgetItem *item = m_view.vobs_list->currentItem();
+    if (item == NULL) return;
+    int index = m_view.vobs_list->indexOfTopLevelItem(item);
+    if (index == max - 1) return;
+    m_view.vobs_list->insertTopLevelItem(index + 1, m_view.vobs_list->takeTopLevelItem(index));
+}
+
+bool DvdWizardVob::isPal() const
+{
+    return m_view.dvd_profile->currentIndex() == 0;
+}
+
+
+
index 0ce4a29752f946c51dca96110f1ce38bd6b44893..028ce85402cf48b85abb60783a5b20cd88af7711 100644 (file)
@@ -29,6 +29,8 @@
 #include <kcapacitybar.h>
 #endif
 
+#include <KUrl>
+
 #include <QWizardPage>
 
 class DvdWizardVob : public QWizardPage
@@ -36,7 +38,7 @@ class DvdWizardVob : public QWizardPage
     Q_OBJECT
 
 public:
-    DvdWizardVob(QWidget * parent = 0);
+    DvdWizardVob(const QString &profile, QWidget * parent = 0);
     virtual ~DvdWizardVob();
     virtual bool isComplete() const;
     QStringList selectedUrls() const;
@@ -45,6 +47,8 @@ public:
     void setUrl(const QString &url);
     QString introMovie() const;
     bool useChapters() const;
+    bool isPal() const;
+    QStringList chapter(int ix) const;
 
 private:
     Ui::DvdWizardVob_UI m_view;
@@ -55,7 +59,12 @@ private:
 #endif
 
 private slots:
-    void slotCheckVobList(const QString &text);
+    void slotCheckVobList();
+    void slotAddVobFile(KUrl url = KUrl());
+    void slotDeleteVobFile();
+    void slotItemUp();
+    void slotItemDown();
+    void changeFormat();
 };
 
 #endif
index 7750bc5773231d42c2e4ab4a8fd47d5fef0ceb25..7d6d493d1fe663c3879e65025964e9f3a0c1033d 100644 (file)
@@ -1662,6 +1662,7 @@ void MainWindow::slotDoRender(const QStringList args, const QStringList overlay_
         if (createChapterFile) {
             QDomDocument doc;
             QDomElement chapters = doc.createElement("chapters");
+            chapters.setAttribute("fps", m_activeDocument->fps());
             doc.appendChild(chapters);
 
             QDomElement guidesxml = m_activeDocument->guidesXml();
@@ -1674,11 +1675,11 @@ void MainWindow::slotDoRender(const QStringList args, const QStringList overlay_
                     QString comment = e.attribute("comment");
                     int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
                     if (time >= in && time < out) {
-                       if (zoneOnly) time = time - in;
+                        if (zoneOnly) time = time - in;
                         QDomElement chapter = doc.createElement("chapter");
                         chapters.appendChild(chapter);
                         chapter.setAttribute("title", comment);
-                        chapter.setAttribute("time", Timecode::getStringTimecode(time, m_activeDocument->fps()));
+                        chapter.setAttribute("time", time);
                     }
                 }
             }