1 /***************************************************************************
2 * Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "dvdwizardchapters.h"
26 DvdWizardChapters::DvdWizardChapters(bool isPal, QWidget *parent) :
32 connect(m_view.vob_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateChaptersList()));
33 connect(m_view.button_add, SIGNAL(clicked()), this, SLOT(slotAddChapter()));
34 connect(m_view.button_delete, SIGNAL(clicked()), this, SLOT(slotRemoveChapter()));
35 connect(m_view.chapters_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotGoToChapter()));
37 // Build monitor for chapters
39 if (m_isPal) m_tc.setFormat(25);
40 else m_tc.setFormat(30, true);
42 m_manager = new MonitorManager(this);
43 m_manager->resetProfiles(m_tc);
44 m_monitor = new Monitor("chapter", m_manager, this);
47 QVBoxLayout *vbox = new QVBoxLayout;
48 vbox->addWidget(m_monitor);
49 m_view.monitor_frame->setLayout(vbox);
54 DvdWizardChapters::~DvdWizardChapters()
62 bool DvdWizardChapters::isComplete() const
67 void DvdWizardChapters::slotUpdateChaptersList()
69 m_monitor->slotOpenFile(m_view.vob_list->currentText());
70 m_monitor->adjustRulerSize(m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole).toInt());
71 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
74 QStringList chaptersString;
75 for (int i = 0; i < currentChaps.count(); i++) {
76 chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps()));
78 m_view.chapters_list->clear();
79 m_view.chapters_list->addItems(chaptersString);
82 void DvdWizardChapters::slotAddChapter()
84 int pos = m_monitor->position().frames(m_tc.fps());
85 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
86 if (currentChaps.contains(QString::number(pos))) return;
87 else currentChaps.append(QString::number(pos));
88 QList <int> chapterTimes;
89 for (int i = 0; i < currentChaps.count(); i++)
90 chapterTimes.append(currentChaps.at(i).toInt());
94 QStringList chaptersString;
96 for (int i = 0; i < chapterTimes.count(); i++) {
97 chaptersString.append(Timecode::getStringTimecode(chapterTimes.at(i), m_tc.fps()));
98 currentChaps.append(QString::number(chapterTimes.at(i)));
100 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), currentChaps, Qt::UserRole + 1);
101 m_view.chapters_list->clear();
102 m_view.chapters_list->addItems(chaptersString);
105 void DvdWizardChapters::slotRemoveChapter()
107 int ix = m_view.chapters_list->currentRow();
108 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
109 currentChaps.removeAt(ix);
110 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), currentChaps, Qt::UserRole + 1);
113 QStringList chaptersString;
114 for (int i = 0; i < currentChaps.count(); i++) {
115 chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps()));
117 m_view.chapters_list->clear();
118 m_view.chapters_list->addItems(chaptersString);
121 void DvdWizardChapters::slotGoToChapter()
123 m_monitor->setTimePos(m_view.chapters_list->currentItem()->text() + ":00");
126 void DvdWizardChapters::slotGetChaptersList(int ix)
128 QString url = m_view.vob_list->itemText(ix);
129 if (QFile::exists(url + ".dvdchapter")) {
130 // insert chapters as children
131 QFile file(url + ".dvdchapter");
132 if (file.open(QIODevice::ReadOnly)) {
134 doc.setContent(&file);
136 QDomNodeList chapters = doc.elementsByTagName("chapter");
137 QStringList chaptersList;
138 for (int j = 0; j < chapters.count(); j++) {
139 chaptersList.append(QString::number(chapters.at(j).toElement().attribute("time").toInt()));
141 m_view.vob_list->setItemData(ix, chaptersList, Qt::UserRole + 1);
146 void DvdWizardChapters::setVobFiles(bool isPal, const QStringList movies, const QStringList durations)
149 if (m_isPal) m_tc.setFormat(25);
150 else m_tc.setFormat(30, true);
151 m_manager->resetProfiles(m_tc);
152 m_monitor->resetProfile();
154 if (m_view.vob_list->count() == movies.count()) {
156 for (int i = 0; i < movies.count(); i++) {
157 if (movies.at(i) != m_view.vob_list->itemText(i)) {
164 m_view.vob_list->clear();
165 for (int i = 0; i < movies.count(); i++) {
166 m_view.vob_list->addItem(movies.at(i), durations.at(i));
167 slotGetChaptersList(i);
169 slotUpdateChaptersList();
172 QStringList DvdWizardChapters::selectedTitles() const
175 int max = m_view.vob_list->count();
176 for (int i = 0; i < max; i++) {
177 result.append(m_view.vob_list->itemText(i));
178 QStringList chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList();
179 for (int j = 0; j < chapters.count(); j++) {
180 result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps()));
186 QStringList DvdWizardChapters::chapters(int ix) const
189 QStringList chapters = m_view.vob_list->itemData(ix, Qt::UserRole + 1).toStringList();
190 for (int j = 0; j < chapters.count(); j++) {
191 result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps()));
196 QStringList DvdWizardChapters::selectedTargets() const
199 int max = m_view.vob_list->count();
200 for (int i = 0; i < max; i++) {
201 result.append("jump title " + QString::number(i + 1));
202 QStringList chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList();
203 for (int j = 0; j < chapters.count(); j++) {
204 result.append("jump title " + QString::number(i + 1) + " chapter " + QString::number(j + 1));