#include <QFile>
-DvdWizardChapters::DvdWizardChapters(bool isPal, QWidget *parent) :
+DvdWizardChapters::DvdWizardChapters(DVDFORMAT format, QWidget *parent) :
QWizardPage(parent),
- m_isPal(isPal)
+ m_format(format),
+ m_monitor(NULL)
{
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.button_save, SIGNAL(clicked()), this, SLOT(slotSaveChapter()));
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);
+ if (m_format == PAL || m_format == PAL_WIDE) m_tc.setFormat(25);
+ else m_tc.setFormat(30000.0 / 1001);
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);
-
-
+ //m_view.monitor_frame->setVisible(false);
}
DvdWizardChapters::~DvdWizardChapters()
{
- delete m_monitor;
+ if (m_monitor) {
+ m_monitor->stop();
+ delete m_monitor;
+ }
delete m_manager;
}
return true;
}
+void DvdWizardChapters::stopMonitor()
+{
+ if (m_monitor) m_monitor->stop();
+}
+
void DvdWizardChapters::slotUpdateChaptersList()
{
m_monitor->slotOpenFile(m_view.vob_list->currentText());
// insert chapters
QStringList chaptersString;
for (int i = 0; i < currentChaps.count(); i++) {
- chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps()));
+ chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps(), true));
}
m_view.chapters_list->clear();
m_view.chapters_list->addItems(chaptersString);
- bool modified = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 2).toInt();
- m_view.button_save->setEnabled(modified);
+ //bool modified = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 2).toInt();
}
void DvdWizardChapters::slotAddChapter()
QStringList chaptersString;
currentChaps.clear();
for (int i = 0; i < chapterTimes.count(); i++) {
- chaptersString.append(Timecode::getStringTimecode(chapterTimes.at(i), m_tc.fps()));
+ chaptersString.append(Timecode::getStringTimecode(chapterTimes.at(i), m_tc.fps(), true));
currentChaps.append(QString::number(chapterTimes.at(i)));
}
// Save item chapters
m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), 1, Qt::UserRole + 2);
m_view.chapters_list->clear();
m_view.chapters_list->addItems(chaptersString);
- m_view.button_save->setEnabled(true);
}
void DvdWizardChapters::slotRemoveChapter()
// rebuild chapters
QStringList chaptersString;
for (int i = 0; i < currentChaps.count(); i++) {
- chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps()));
+ chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps(), true));
}
m_view.chapters_list->clear();
m_view.chapters_list->addItems(chaptersString);
- m_view.button_save->setEnabled(true);
}
void DvdWizardChapters::slotGoToChapter()
{
- m_monitor->setTimePos(m_view.chapters_list->currentItem()->text() + ":00");
+ if (m_view.chapters_list->currentItem()) m_monitor->setTimePos(m_tc.reformatSeparators(m_view.chapters_list->currentItem()->text()));
}
-void DvdWizardChapters::slotGetChaptersList(int ix)
+void DvdWizardChapters::setVobFiles(DVDFORMAT format, const QStringList &movies, const QStringList &durations, const QStringList &chapters)
{
- 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);
- }
+ m_format = format;
+ QString profile = DvdWizardVob::getDvdProfile(format);
+ if (m_format == PAL || m_format == PAL_WIDE) {
+ m_tc.setFormat(25);
+ } else {
+ m_tc.setFormat(30000.0 / 1001);
}
-}
-
-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;
- }
+ if (m_monitor == NULL) {
+ m_monitor = new Monitor(Kdenlive::dvdMonitor, m_manager, profile, this);
+ //m_monitor->start();
+ QVBoxLayout *vbox = new QVBoxLayout;
+ vbox->addWidget(m_monitor);
+ m_view.monitor_frame->setLayout(vbox);
+ /*updateGeometry();
+ m_view.monitor_frame->adjustSize();*/
+ } else m_monitor->resetProfile(profile);
+
+ m_view.vob_list->blockSignals(true);
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);
+ m_view.vob_list->setItemData(i, chapters.at(i).split(';'), Qt::UserRole + 1);
}
+ m_view.vob_list->blockSignals(false);
slotUpdateChaptersList();
}
+QMap <QString, QString> DvdWizardChapters::chaptersData() const
+{
+ QMap <QString, QString> result;
+ int max = m_view.vob_list->count();
+ for (int i = 0; i < max; i++) {
+ QString chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList().join(";");
+ result.insert(m_view.vob_list->itemText(i), chapters);
+ }
+ return result;
+}
+
QStringList DvdWizardChapters::selectedTitles() const
{
QStringList result;
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()));
+ result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps(), true));
}
}
return result;
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()));
+ result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps(), true));
}
return result;
}
QStringList result;
int max = m_view.vob_list->count();
for (int i = 0; i < max; i++) {
- result.append("jump title " + QString::number(i + 1));
+ // rightJustified: fill with 0s to make menus with more than 9 buttons work (now up to 99 buttons possible)
+ result.append("jump title " + QString::number(i + 1).rightJustified(2, '0'));
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));
+ result.append("jump title " + QString::number(i + 1).rightJustified(2, '0') + " chapter " + QString::number(j + 1).rightJustified(2, '0'));
}
}
return result;
}
-void DvdWizardChapters::slotSaveChapter()
+
+QDomElement DvdWizardChapters::toXml() const
{
QDomDocument doc;
- QDomElement chapters = doc.createElement("chapters");
- chapters.setAttribute("fps", m_tc.fps());
- doc.appendChild(chapters);
-
- QStringList chaptersList = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
-
- for (int i = 0; i < chaptersList.count(); i++) {
- QDomElement chapter = doc.createElement("chapter");
- chapters.appendChild(chapter);
- chapter.setAttribute("title", i18n("Chapter %1", i));
- chapter.setAttribute("time", chaptersList.at(i));
- }
- // save chapters file
- QFile file(m_view.vob_list->currentText() + ".dvdchapter");
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- kWarning() << "////// ERROR writing DVD CHAPTER file: " << m_view.vob_list->currentText() + ".dvdchapter";
- } else {
- file.write(doc.toString().toUtf8());
- if (file.error() != QFile::NoError)
- kWarning() << "////// ERROR writing DVD CHAPTER file: " << m_view.vob_list->currentText() + ".dvdchapter";
- else {
- m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), 0, Qt::UserRole + 2);
- m_view.button_save->setEnabled(false);
- }
- file.close();
+ QDomElement xml = doc.createElement("xml");
+ doc.appendChild(xml);
+ for (int i = 0; i < m_view.vob_list->count(); i++) {
+ QDomElement vob = doc.createElement("vob");
+ vob.setAttribute("file", m_view.vob_list->itemText(i));
+ vob.setAttribute("chapters", m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList().join(";"));
+ xml.appendChild(vob);
}
+ return doc.documentElement();
}