]> git.sesse.net Git - kdenlive/blob - src/dvdwizardchapters.cpp
Fix compilation warnings
[kdenlive] / src / dvdwizardchapters.cpp
1 /***************************************************************************
2  *   Copyright (C) 2009 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20 #include "dvdwizardchapters.h"
21
22 #include <KDebug>
23
24 #include <QFile>
25
26 DvdWizardChapters::DvdWizardChapters(bool isPal, QWidget *parent) :
27         QWizardPage(parent),
28         m_isPal(isPal)
29
30 {
31     m_view.setupUi(this);
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()));
36
37     // Build monitor for chapters
38
39     if (m_isPal) m_tc.setFormat(25);
40     else m_tc.setFormat(30, true);
41
42     m_manager = new MonitorManager(this);
43     m_manager->resetProfiles(m_tc);
44     m_monitor = new Monitor("chapter", m_manager, this);
45     m_monitor->start();
46
47     QVBoxLayout *vbox = new QVBoxLayout;
48     vbox->addWidget(m_monitor);
49     m_view.monitor_frame->setLayout(vbox);
50
51
52 }
53
54 DvdWizardChapters::~DvdWizardChapters()
55 {
56     delete m_monitor;
57     delete m_manager;
58 }
59
60 // virtual
61
62 bool DvdWizardChapters::isComplete() const
63 {
64     return true;
65 }
66
67 void DvdWizardChapters::slotUpdateChaptersList()
68 {
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();
72
73     // insert chapters
74     QStringList chaptersString;
75     for (int i = 0; i < currentChaps.count(); i++) {
76         chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps()));
77     }
78     m_view.chapters_list->clear();
79     m_view.chapters_list->addItems(chaptersString);
80
81     //bool modified = m_view.vob_list->itemData(m_view.vob_list->currentIndex(), Qt::UserRole + 2).toInt();
82 }
83
84 void DvdWizardChapters::slotAddChapter()
85 {
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());
93     qSort(chapterTimes);
94
95     // rebuild chapters
96     QStringList chaptersString;
97     currentChaps.clear();
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)));
101     }
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);
108 }
109
110 void DvdWizardChapters::slotRemoveChapter()
111 {
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);
115
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);
120
121     // rebuild chapters
122     QStringList chaptersString;
123     for (int i = 0; i < currentChaps.count(); i++) {
124         chaptersString.append(Timecode::getStringTimecode(currentChaps.at(i).toInt(), m_tc.fps()));
125     }
126     m_view.chapters_list->clear();
127     m_view.chapters_list->addItems(chaptersString);
128 }
129
130 void DvdWizardChapters::slotGoToChapter()
131 {
132     m_monitor->setTimePos(m_view.chapters_list->currentItem()->text() + ":00");
133 }
134
135 void DvdWizardChapters::setVobFiles(bool isPal, const QStringList movies, const QStringList durations, const QStringList chapters)
136 {
137     m_isPal = isPal;
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();
142
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);
147     }
148     slotUpdateChaptersList();
149 }
150
151 QMap <QString, QString> DvdWizardChapters::chaptersData() const
152 {
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);
158     }
159     return result;
160 }
161
162 QStringList DvdWizardChapters::selectedTitles() const
163 {
164     QStringList result;
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()));
171         }
172     }
173     return result;
174 }
175
176 QStringList DvdWizardChapters::chapters(int ix) const
177 {
178     QStringList result;
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()));
182     }
183     return result;
184 }
185
186 QStringList DvdWizardChapters::selectedTargets() const
187 {
188     QStringList result;
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));
195         }
196     }
197     return result;
198 }
199
200
201 QDomElement DvdWizardChapters::toXml() const
202 {
203     QDomDocument doc;
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);
211     }
212     return doc.documentElement();
213 }