]> git.sesse.net Git - kdenlive/blobdiff - src/dvdwizardvob.cpp
Do not switch monitor when not necessary, make sure we refresh monitor when adding...
[kdenlive] / src / dvdwizardvob.cpp
index 8f44776081b934845a75f0a1ca3795533e928022..1caae7f8180dbfd676da45abc180ee62cc17fdc9 100644 (file)
@@ -32,6 +32,7 @@
 #include <QHBoxLayout>
 #include <QDomDocument>
 #include <QTreeWidgetItem>
+#include <QHeaderView>
 
 DvdWizardVob::DvdWizardVob(const QString &profile, QWidget *parent) :
         QWizardPage(parent)
@@ -51,69 +52,100 @@ DvdWizardVob::DvdWizardVob(const QString &profile, QWidget *parent) :
     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 (KStandardDirs::findExe("dvdauthor").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.</strong>", i18n("dvdauthor")));
+    if (KStandardDirs::findExe("mkisofs").isEmpty() && KStandardDirs::findExe("genisoimage").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 or %2 is required for the DVD wizard.</strong>", i18n("mkisofs"), i18n("genisoimage")));
     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);
-    }
+    m_view.dvd_profile->addItems(QStringList() << i18n("PAL 4:3") << i18n("PAL 16:9") << i18n("NTSC 4:3") << i18n("NTSC 16:9"));
+    if (profile == "dv_pal_wide") m_view.dvd_profile->setCurrentIndex(1);
+    else if (profile == "dv_ntsc") m_view.dvd_profile->setCurrentIndex(2);
+    else if (profile == "dv_ntsc_wide") m_view.dvd_profile->setCurrentIndex(3);
+
     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;
     layout->addWidget(m_capacityBar);
     m_view.size_box->setLayout(layout);
-#else
-    m_view.size_box->setHidden(true);
-#endif
     slotCheckVobList();
 }
 
 DvdWizardVob::~DvdWizardVob()
 {
-#if KDE_IS_VERSION(4,2,0)
     delete m_capacityBar;
-#endif
 }
 
 
-void DvdWizardVob::slotAddVobFile(KUrl url)
+void DvdWizardVob::slotAddVobFile(KUrl url, const QString &chapters)
 {
     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());
+    switch (m_view.dvd_profile->currentIndex()) {
+    case 1:
+        profilename = "dv_pal_wide";
+        break;
+    case 2:
+        profilename = "dv_ntsc";
+        break;
+    case 3:
+        profilename = "dv_ntsc_wide";
+        break;
+    default:
+        profilename = "dv_pal";
+        break;
+    }
+
+    Mlt::Profile profile(profilename.toUtf8().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"));
 
     QPixmap pix(60, 45);
 
-    char *tmp = (char *) qstrdup(url.path().toUtf8().data());
-    Mlt::Producer *producer = new Mlt::Producer(profile, tmp);
-    delete[] tmp;
+    Mlt::Producer *producer = new Mlt::Producer(profile, url.path().toUtf8().data());
 
     if (producer->is_blank() == false) {
-        pix = KThumb::getFrame(producer, 0, 60, 45);
-        item->setIcon(0, pix);
+        int width = 45.0 * profile.dar();
+        int swidth = 45.0 * profile.width() / profile.height();
+        if (width % 2 == 1) width++;
+        item->setIcon(0, QPixmap::fromImage(KThumb::getFrame(producer, 0, swidth, width, 45)));
         int playTime = producer->get_playtime();
         item->setText(1, Timecode::getStringTimecode(playTime, profile.fps()));
         item->setData(1, Qt::UserRole, playTime);
     }
     delete producer;
 
+    if (chapters.isEmpty() == false) {
+        item->setData(1, Qt::UserRole + 1, chapters);
+    }
+    else if (QFile::exists(url.path() + ".dvdchapter")) {
+        // insert chapters as children
+        QFile file(url.path() + ".dvdchapter");
+        if (file.open(QIODevice::ReadOnly)) {
+            QDomDocument doc;
+            if (doc.setContent(&file) == false) {
+                file.close();
+                return;
+            }
+            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()));
+            }
+            item->setData(1, Qt::UserRole + 1, chaptersList.join(";"));
+        }
+    } else // Explicitly add a chapter at 00:00:00:00
+        item->setData(1, Qt::UserRole + 1, "0");
+
     slotCheckVobList();
 }
 
@@ -121,19 +153,30 @@ 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());
+    switch (m_view.dvd_profile->currentIndex()) {
+    case 1:
+        profilename = "dv_pal_wide";
+        break;
+    case 2:
+        profilename = "dv_ntsc";
+        break;
+    case 3:
+        profilename = "dv_ntsc_wide";
+        break;
+    default:
+        profilename = "dv_pal";
+        break;
+    }
+
+    Mlt::Profile profile(profilename.toUtf8().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;
+        Mlt::Producer *producer = new Mlt::Producer(profile, item->text(0).toUtf8().data());
 
         if (producer->is_blank() == false) {
-            //pix = KThumb::getFrame(producer, 0, 180, 135);
+            //pix = KThumb::getFrame(producer, 0, 135 * profile.dar(), 135);
             //item->setIcon(0, pix);
             item->setText(1, Timecode::getStringTimecode(producer->get_playtime(), profile.fps()));
         }
@@ -194,6 +237,29 @@ QStringList DvdWizardVob::durations() const
     return result;
 }
 
+QStringList DvdWizardVob::chapters() 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->data(1, Qt::UserRole + 1).toString());
+        }
+    }
+    return result;
+}
+
+void DvdWizardVob::updateChapters(QMap <QString, QString> chaptersdata)
+{
+    int max = m_view.vobs_list->topLevelItemCount();
+    for (int i = 0; i < max; i++) {
+        QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(i);
+        if (chaptersdata.contains(item->text(0))) item->setData(1, Qt::UserRole + 1, chaptersdata.value(item->text(0)));
+    }
+}
+
 int DvdWizardVob::duration(int ix) const
 {
     int result = -1;
@@ -211,6 +277,13 @@ QString DvdWizardVob::introMovie() const
     return m_view.intro_vob->url().path();
 }
 
+void DvdWizardVob::setIntroMovie(const QString& path)
+{
+    m_view.intro_vob->setUrl(KUrl(path));
+    m_view.use_intro->setChecked(path.isEmpty() == false);
+}
+
+
 void DvdWizardVob::slotCheckVobList()
 {
     emit completeChanged();
@@ -224,7 +297,6 @@ void DvdWizardVob::slotCheckVobList()
     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 < max; i++) {
         item = m_view.vobs_list->topLevelItem(i);
@@ -234,7 +306,6 @@ void DvdWizardVob::slotCheckVobList()
     qint64 maxSize = (qint64) 47000 * 100000;
     m_capacityBar->setValue(100 * totalSize / maxSize);
     m_capacityBar->setText(KIO::convertSize(totalSize));
-#endif
 }
 
 void DvdWizardVob::slotItemUp()
@@ -258,8 +329,23 @@ void DvdWizardVob::slotItemDown()
 
 bool DvdWizardVob::isPal() const
 {
-    return m_view.dvd_profile->currentIndex() == 0;
+    return m_view.dvd_profile->currentIndex() < 2;
 }
 
+bool DvdWizardVob::isWide() const
+{
+    return (m_view.dvd_profile->currentIndex() == 1 || m_view.dvd_profile->currentIndex() == 3);
+}
 
+void DvdWizardVob::setProfile(const QString& profile)
+{
+    if (profile == "dv_pal") m_view.dvd_profile->setCurrentIndex(0);
+    else if (profile == "dv_pal_wide") m_view.dvd_profile->setCurrentIndex(1);
+    else if (profile == "dv_ntsc") m_view.dvd_profile->setCurrentIndex(2);
+    else if (profile == "dv_ntsc_wide") m_view.dvd_profile->setCurrentIndex(3);
+}
 
+void DvdWizardVob::clear()
+{
+    m_view.vobs_list->clear();
+}