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);
43 //m_view.monitor_frame->setVisible(false);
46 DvdWizardChapters::~DvdWizardChapters()
49 m_manager->removeMonitor(m_monitor);
57 bool DvdWizardChapters::isComplete() const
62 void DvdWizardChapters::stopMonitor()
64 if (m_monitor) m_monitor->stop();
67 void DvdWizardChapters::refreshMonitor()
69 if (m_monitor) m_monitor->refreshMonitor();
72 void DvdWizardChapters::slotUpdateChaptersList()
74 m_monitor->slotOpenFile(m_view.vob_list->currentText());
75 m_monitor->adjustRulerSize(m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole).toInt());
76 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
79 QStringList chaptersString;
80 for (int i = 0; i < currentChaps.count(); i++) {
81 chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps(), true));
83 m_view.chapters_list->clear();
84 m_view.chapters_list->addItems(chaptersString);
86 //bool modified = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 2).toInt();
89 void DvdWizardChapters::slotAddChapter()
91 int pos = m_monitor->position().frames(m_tc.fps());
92 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
93 if (currentChaps.contains(QString::number(pos))) return;
94 else currentChaps.append(QString::number(pos));
95 QList <int> chapterTimes;
96 for (int i = 0; i < currentChaps.count(); i++)
97 chapterTimes.append(currentChaps.at(i).toInt());
101 QStringList chaptersString;
102 currentChaps.clear();
103 for (int i = 0; i < chapterTimes.count(); i++) {
104 chaptersString.append(Timecode::getStringTimecode(chapterTimes.at(i), m_tc.fps(), true));
105 currentChaps.append(QString::number(chapterTimes.at(i)));
107 // Save item chapters
108 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), currentChaps, Qt::UserRole + 1);
109 // Mark item as modified
110 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), 1, Qt::UserRole + 2);
111 m_view.chapters_list->clear();
112 m_view.chapters_list->addItems(chaptersString);
115 void DvdWizardChapters::slotRemoveChapter()
117 int ix = m_view.chapters_list->currentRow();
118 QStringList currentChaps = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 1).toStringList();
119 currentChaps.removeAt(ix);
121 // Save item chapters
122 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), currentChaps, Qt::UserRole + 1);
123 // Mark item as modified
124 m_view.vob_list->setItemData(m_view.vob_list->currentIndex(), 1, Qt::UserRole + 2);
127 QStringList chaptersString;
128 for (int i = 0; i < currentChaps.count(); i++) {
129 chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps(), true));
131 m_view.chapters_list->clear();
132 m_view.chapters_list->addItems(chaptersString);
135 void DvdWizardChapters::slotGoToChapter()
137 if (m_view.chapters_list->currentItem()) m_monitor->setTimePos(m_tc.reformatSeparators(m_view.chapters_list->currentItem()->text()));
140 void DvdWizardChapters::createMonitor(DVDFORMAT format)
142 QString profile = DvdWizardVob::getDvdProfile(format);
143 if (m_monitor == NULL) {
144 m_monitor = new Monitor(Kdenlive::dvdMonitor, m_manager, profile, this);
145 //m_monitor->start();
146 QVBoxLayout *vbox = new QVBoxLayout;
147 vbox->addWidget(m_monitor);
148 m_view.video_frame->setLayout(vbox);
149 m_monitor->setSizePolicy(QSizePolicy ( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
150 m_manager->appendMonitor(m_monitor);
151 vbox->insertWidget(0, m_monitor, 10);
155 void DvdWizardChapters::setVobFiles(DVDFORMAT format, const QStringList &movies, const QStringList &durations, const QStringList &chapters)
158 QString profile = DvdWizardVob::getDvdProfile(format);
159 if (m_format == PAL || m_format == PAL_WIDE) {
162 m_tc.setFormat(30000.0 / 1001);
165 if (m_monitor == NULL) createMonitor(format);
166 m_monitor->setCustomProfile(profile, m_tc);
168 m_view.vob_list->blockSignals(true);
169 m_view.vob_list->clear();
170 for (int i = 0; i < movies.count(); i++) {
171 m_view.vob_list->addItem(movies.at(i), durations.at(i));
172 m_view.vob_list->setItemData(i, chapters.at(i).split(';'), Qt::UserRole + 1);
174 m_view.vob_list->blockSignals(false);
175 slotUpdateChaptersList();
176 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
179 m_manager->activateMonitor(Kdenlive::dvdMonitor);
180 m_monitor->refreshMonitor();
183 QMap <QString, QString> DvdWizardChapters::chaptersData() const
185 QMap <QString, QString> result;
186 int max = m_view.vob_list->count();
187 for (int i = 0; i < max; i++) {
188 QString chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList().join(";");
189 result.insert(m_view.vob_list->itemText(i), chapters);
194 QStringList DvdWizardChapters::selectedTitles() const
197 int max = m_view.vob_list->count();
198 for (int i = 0; i < max; i++) {
199 result.append(m_view.vob_list->itemText(i));
200 QStringList chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList();
201 for (int j = 0; j < chapters.count(); j++) {
202 result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps(), true));
208 QStringList DvdWizardChapters::chapters(int ix) const
211 QStringList chapters = m_view.vob_list->itemData(ix, Qt::UserRole + 1).toStringList();
212 for (int j = 0; j < chapters.count(); j++) {
213 result.append(Timecode::getStringTimecode(chapters.at(j).toInt(), m_tc.fps(), true));
218 QStringList DvdWizardChapters::selectedTargets() const
221 int max = m_view.vob_list->count();
222 for (int i = 0; i < max; i++) {
223 // rightJustified: fill with 0s to make menus with more than 9 buttons work (now up to 99 buttons possible)
224 result.append("jump title " + QString::number(i + 1).rightJustified(2, '0'));
225 QStringList chapters = m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList();
226 for (int j = 0; j < chapters.count(); j++) {
227 result.append("jump title " + QString::number(i + 1).rightJustified(2, '0') + " chapter " + QString::number(j + 1).rightJustified(2, '0'));
234 QDomElement DvdWizardChapters::toXml() const
237 QDomElement xml = doc.createElement("xml");
238 doc.appendChild(xml);
239 for (int i = 0; i < m_view.vob_list->count(); i++) {
240 QDomElement vob = doc.createElement("vob");
241 vob.setAttribute("file", m_view.vob_list->itemText(i));
242 vob.setAttribute("chapters", m_view.vob_list->itemData(i, Qt::UserRole + 1).toStringList().join(";"));
243 xml.appendChild(vob);
245 return doc.documentElement();