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);
81 bool modified = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 2).toInt();
84 void DvdWizardChapters::slotAddChapter()
86 int pos = m_monitor->position().frames(m_tc.fps());
87 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
88 if (currentChaps.contains(QString::number(pos))) return;
89 else currentChaps.append(QString::number(pos));
90 QList <int> chapterTimes;
91 for (int i = 0; i < currentChaps.count(); i++)
92 chapterTimes.append(currentChaps.at(i).toInt());
96 QStringList chaptersString;
98 for (int i = 0; i < chapterTimes.count(); i++) {
99 chaptersString.append(Timecode::getStringTimecode(chapterTimes.at(i), m_tc.fps()));
100 currentChaps.append(QString::number(chapterTimes.at(i)));
102 // Save item chapters
103 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), currentChaps, Qt::UserRole + 1);
104 // Mark item as modified
105 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), 1, Qt::UserRole + 2);
106 m_view.chapters_list->clear();
107 m_view.chapters_list->addItems(chaptersString);
110 void DvdWizardChapters::slotRemoveChapter()
112 int ix = m_view.chapters_list->currentRow();
113 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
114 currentChaps.removeAt(ix);
116 // Save item chapters
117 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), currentChaps, Qt::UserRole + 1);
118 // Mark item as modified
119 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), 1, Qt::UserRole + 2);
122 QStringList chaptersString;
123 for (int i = 0; i < currentChaps.count(); i++) {
124 chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps()));
126 m_view.chapters_list->clear();
127 m_view.chapters_list->addItems(chaptersString);
130 void DvdWizardChapters::slotGoToChapter()
132 m_monitor->setTimePos(m_view.chapters_list->currentItem()->text() + ":00");
135 void DvdWizardChapters::setVobFiles(bool isPal, const QStringList movies, const QStringList durations, const QStringList chapters)
138 if (m_isPal) m_tc.setFormat(25);
139 else m_tc.setFormat(30, true);
140 m_manager->resetProfiles(m_tc);
141 m_monitor->resetProfile();
143 m_view.vob_list->clear();
144 for (int i = 0; i < movies.count(); i++) {
145 m_view.vob_list->addItem(movies.at(i), durations.at(i));
146 m_view.vob_list->setItemData(i, chapters.at(i).split(';'), Qt::UserRole + 1);
148 slotUpdateChaptersList();
151 QMap <QString, QString> DvdWizardChapters::chaptersData() const
153 QMap <QString, QString> result;
154 int max = m_view.vob_list->count();
155 for (int i = 0; i < max; i++) {
156 QString chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList().join(";");
157 result.insert(m_view.vob_list->itemText(i), chapters);
162 QStringList DvdWizardChapters::selectedTitles() const
165 int max = m_view.vob_list->count();
166 for (int i = 0; i < max; i++) {
167 result.append(m_view.vob_list->itemText(i));
168 QStringList chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList();
169 for (int j = 0; j < chapters.count(); j++) {
170 result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps()));
176 QStringList DvdWizardChapters::chapters(int ix) const
179 QStringList chapters = m_view.vob_list->itemData(ix, Qt::UserRole + 1).toStringList();
180 for (int j = 0; j < chapters.count(); j++) {
181 result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps()));
186 QStringList DvdWizardChapters::selectedTargets() const
189 int max = m_view.vob_list->count();
190 for (int i = 0; i < max; i++) {
191 result.append("jump title " + QString::number(i + 1));
192 QStringList chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList();
193 for (int j = 0; j < chapters.count(); j++) {
194 result.append("jump title " + QString::number(i + 1) + " chapter " + QString::number(j + 1));
201 QDomElement DvdWizardChapters::toXml() const
204 QDomElement xml = doc.createElement("xml");
205 doc.appendChild(xml);
206 for (int i = 0; i < m_view.vob_list->count(); i++) {
207 QDomElement vob = doc.createElement("vob");
208 vob.setAttribute("file", m_view.vob_list->itemText(i));
209 vob.setAttribute("chapters", m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList().join(";"));
210 xml.appendChild(vob);
212 return doc.documentElement();