X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fdvdwizardvob.cpp;h=c982917321728ed1d0b3a813b200779893024a23;hb=d5577be106561d978a574f393fadc27ae8fcbd2a;hp=c49d116ef6197d994cd036c5bb1621bede86b8c9;hpb=40a2b375a7c1085a6f791e05cdd81350916a2a64;p=kdenlive diff --git a/src/dvdwizardvob.cpp b/src/dvdwizardvob.cpp index c49d116e..c9829173 100644 --- a/src/dvdwizardvob.cpp +++ b/src/dvdwizardvob.cpp @@ -18,29 +18,56 @@ ***************************************************************************/ #include "dvdwizardvob.h" +#include "kthumb.h" +#include "timecode.h" + +#include #include #include #include #include +#include #include #include +#include +#include -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 &))); - if (KStandardDirs::findExe("dvdauthor").isEmpty()) m_errorMessage.append(i18n("Program %1 is required for the DVD wizard.", i18n("dvdauthor"))); - if (KStandardDirs::findExe("mkisofs").isEmpty()) m_errorMessage.append(i18n("Program %1 is required for the DVD wizard.", i18n("mkisofs"))); + 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("Program %1 is required for the DVD wizard.", i18n("dvdauthor"))); + if (KStandardDirs::findExe("mkisofs").isEmpty()) m_errorMessage.append(i18n("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 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; @@ -49,105 +76,203 @@ DvdWizardVob::DvdWizardVob(QWidget *parent) : #else m_view.size_box->setHidden(true); #endif + slotCheckVobList(); } DvdWizardVob::~DvdWizardVob() { - QList allUrls = m_view.vob_list->findChildren(); - qDeleteAll(allUrls); #if KDE_IS_VERSION(4,2,0) delete m_capacityBar; #endif } -// virtual -bool DvdWizardVob::isComplete() const +void DvdWizardVob::slotAddVobFile(KUrl url, const QString &chapters) { - 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 (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; + 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; + } + + char *tmp = (char*) qstrdup(profilename.toUtf8().data()); + Mlt::Profile profile(tmp); + delete[] tmp; + 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); + + tmp = (char *) qstrdup(url.path().toUtf8().data()); + Mlt::Producer *producer = new Mlt::Producer(profile, tmp); + delete[] tmp; + + if (producer->is_blank() == false) { + int width = 45.0 * profile.dar(); + if (width % 2 == 1) width++; + item->setIcon(0, QPixmap::fromImage(KThumb::getFrame(producer, 0, 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; + 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())); + } + 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(); } -bool DvdWizardVob::useChapters() const +void DvdWizardVob::changeFormat() { - return m_view.use_chapters->isChecked(); + int max = m_view.vobs_list->topLevelItemCount(); + QString profilename; + 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; + } + + char *tmp = (char*) qstrdup(profilename.toUtf8().data()); + Mlt::Profile profile(tmp); + delete[] tmp; + QPixmap pix(180, 135); + + for (int i = 0; i < max; i++) { + QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(i); + 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, 135 * profile.dar(), 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.vobs_list->topLevelItemCount() == 0) return false; + return true; } void DvdWizardVob::setUrl(const QString &url) { - m_view.vob_1->setPath(url); + slotAddVobFile(KUrl(url)); } QStringList DvdWizardVob::selectedUrls() const { QStringList result; QString path; - QList allUrls = m_view.vob_list->findChildren(); - 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; } -QStringList DvdWizardVob::selectedTitles() const + +QStringList DvdWizardVob::durations() const { QStringList result; QString path; - QList allUrls = m_view.vob_list->findChildren(); - 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(QString::number(item->data(1, Qt::UserRole).toInt())); } return result; } -QStringList DvdWizardVob::selectedTargets() const +QStringList DvdWizardVob::chapters() const { QStringList result; QString path; - QList allUrls = m_view.vob_list->findChildren(); - for (int i = 0; i < allUrls.count(); i++) { - path = allUrls.at(i)->url().path(); - if (!path.isEmpty()) { - result.append("title " + QString::number(i)); - 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("title " + QString::number(i + 1) + " chapter " + QString::number(j + 1)); - } - } + 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 chaptersdata) +{ + int max = m_view.vobs_list->topLevelItemCount(); + for (int i = 0; i < max; i++) { + QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(i); + item->setData(1, Qt::UserRole + 1, chaptersdata.value(item->text(0))); + } +} + +int DvdWizardVob::duration(int ix) const +{ + int result = -1; + QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(ix); + if (item) { + result = item->data(1, Qt::UserRole).toInt(); } return result; } @@ -159,41 +284,77 @@ QString DvdWizardVob::introMovie() const return m_view.intro_vob->url().path(); } -void DvdWizardVob::slotCheckVobList(const QString &text) +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(); - QList allUrls = m_view.vob_list->findChildren(); - 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() < 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(); +}