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(MonitorManager *manager, DVDFORMAT format, QWidget *parent) :
34 connect(m_view.vob_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateChaptersList()));
35 connect(m_view.button_add, SIGNAL(clicked()), this, SLOT(slotAddChapter()));
36 connect(m_view.button_delete, SIGNAL(clicked()), this, SLOT(slotRemoveChapter()));
37 connect(m_view.chapters_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotGoToChapter()));
39 // Build monitor for chapters
41 if (m_format == PAL || m_format == PAL_WIDE) m_tc.setFormat(25);
42 else m_tc.setFormat(30000.0 / 1001);
44 setVobFiles(format, QStringList(), QStringList(), QStringList());
46 //m_view.monitor_frame->setVisible(false);
49 DvdWizardChapters::~DvdWizardChapters()
59 bool DvdWizardChapters::isComplete() const
64 void DvdWizardChapters::stopMonitor()
66 if (m_monitor) m_monitor->stop();
69 void DvdWizardChapters::slotUpdateChaptersList()
71 m_monitor->slotOpenFile(m_view.vob_list->currentText());
72 m_monitor->adjustRulerSize(m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole).toInt());
73 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
76 QStringList chaptersString;
77 for (int i = 0; i < currentChaps.count(); i++) {
78 chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps(), true));
80 m_view.chapters_list->clear();
81 m_view.chapters_list->addItems(chaptersString);
83 //bool modified = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 2).toInt();
86 void DvdWizardChapters::slotAddChapter()
88 int pos = m_monitor->position().frames(m_tc.fps());
89 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
90 if (currentChaps.contains(QString::number(pos))) return;
91 else currentChaps.append(QString::number(pos));
92 QList <int> chapterTimes;
93 for (int i = 0; i < currentChaps.count(); i++)
94 chapterTimes.append(currentChaps.at(i).toInt());
98 QStringList chaptersString;
100 for (int i = 0; i < chapterTimes.count(); i++) {
101 chaptersString.append(Timecode::getStringTimecode(chapterTimes.at(i), m_tc.fps(), true));
102 currentChaps.append(QString::number(chapterTimes.at(i)));
104 // Save item chapters
105 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), currentChaps, Qt::UserRole + 1);
106 // Mark item as modified
107 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), 1, Qt::UserRole + 2);
108 m_view.chapters_list->clear();
109 m_view.chapters_list->addItems(chaptersString);
112 void DvdWizardChapters::slotRemoveChapter()
114 int ix = m_view.chapters_list->currentRow();
115 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
116 currentChaps.removeAt(ix);
118 // Save item chapters
119 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), currentChaps, Qt::UserRole + 1);
120 // Mark item as modified
121 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), 1, Qt::UserRole + 2);
124 QStringList chaptersString;
125 for (int i = 0; i < currentChaps.count(); i++) {
126 chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps(), true));
128 m_view.chapters_list->clear();
129 m_view.chapters_list->addItems(chaptersString);
132 void DvdWizardChapters::slotGoToChapter()
134 if (m_view.chapters_list->currentItem()) m_monitor->setTimePos(m_tc.reformatSeparators(m_view.chapters_list->currentItem()->text()));
137 void DvdWizardChapters::setVobFiles(DVDFORMAT format, const QStringList &movies, const QStringList &durations, const QStringList &chapters)
140 QString profile = DvdWizardVob::getDvdProfile(format);
141 if (m_format == PAL || m_format == PAL_WIDE) {
144 m_tc.setFormat(30000.0 / 1001);
146 if (m_monitor == NULL) {
147 m_monitor = new Monitor(Kdenlive::dvdMonitor, m_manager, profile, this);
148 //m_monitor->start();
149 /*QVBoxLayout *vbox = new QVBoxLayout;
150 vbox->addWidget(m_monitor);
151 m_view.monitor_frame->setLayout(vbox);*/
152 QVBoxLayout *lay = static_cast<QVBoxLayout *> (layout());
153 m_monitor->setSizePolicy(QSizePolicy ( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
154 lay->insertWidget(0, m_monitor, 10);
155 } else m_monitor->resetProfile(profile);
156 m_manager->activateMonitor(Kdenlive::dvdMonitor);
158 m_view.vob_list->blockSignals(true);
159 m_view.vob_list->clear();
160 for (int i = 0; i < movies.count(); i++) {
161 m_view.vob_list->addItem(movies.at(i), durations.at(i));
162 m_view.vob_list->setItemData(i, chapters.at(i).split(';'), Qt::UserRole + 1);
164 m_view.vob_list->blockSignals(false);
165 slotUpdateChaptersList();
168 QMap <QString, QString> DvdWizardChapters::chaptersData() const
170 QMap <QString, QString> result;
171 int max = m_view.vob_list->count();
172 for (int i = 0; i < max; i++) {
173 QString chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList().join(";");
174 result.insert(m_view.vob_list->itemText(i), chapters);
179 QStringList DvdWizardChapters::selectedTitles() const
182 int max = m_view.vob_list->count();
183 for (int i = 0; i < max; i++) {
184 result.append(m_view.vob_list->itemText(i));
185 QStringList chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList();
186 for (int j = 0; j < chapters.count(); j++) {
187 result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps(), true));
193 QStringList DvdWizardChapters::chapters(int ix) const
196 QStringList chapters = m_view.vob_list->itemData(ix, Qt::UserRole + 1).toStringList();
197 for (int j = 0; j < chapters.count(); j++) {
198 result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps(), true));
203 QStringList DvdWizardChapters::selectedTargets() const
206 int max = m_view.vob_list->count();
207 for (int i = 0; i < max; i++) {
208 // rightJustified: fill with 0s to make menus with more than 9 buttons work (now up to 99 buttons possible)
209 result.append("jump title " + QString::number(i + 1).rightJustified(2, '0'));
210 QStringList chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList();
211 for (int j = 0; j < chapters.count(); j++) {
212 result.append("jump title " + QString::number(i + 1).rightJustified(2, '0') + " chapter " + QString::number(j + 1).rightJustified(2, '0'));
219 QDomElement DvdWizardChapters::toXml() const
222 QDomElement xml = doc.createElement("xml");
223 doc.appendChild(xml);
224 for (int i = 0; i < m_view.vob_list->count(); i++) {
225 QDomElement vob = doc.createElement("vob");
226 vob.setAttribute("file", m_view.vob_list->itemText(i));
227 vob.setAttribute("chapters", m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList().join(";"));
228 xml.appendChild(vob);
230 return doc.documentElement();