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 "dvdwizardvob.h"
22 #include <KUrlRequester>
24 #include <KStandardDirs>
27 #include <QHBoxLayout>
28 #include <QDomDocument>
30 DvdWizardVob::DvdWizardVob(QWidget *parent) :
34 m_view.intro_vob->setEnabled(false);
35 m_view.vob_1->setFilter("video/mpeg");
36 m_view.intro_vob->setFilter("video/mpeg");
37 connect(m_view.use_intro, SIGNAL(toggled(bool)), m_view.intro_vob, SLOT(setEnabled(bool)));
38 connect(m_view.vob_1, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
39 if (KStandardDirs::findExe("dvdauthor").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.", i18n("dvdauthor")));
40 if (KStandardDirs::findExe("mkisofs").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.", i18n("mkisofs")));
41 if (m_errorMessage.isEmpty()) m_view.error_message->setVisible(false);
42 else m_view.error_message->setText(m_errorMessage);
44 #if KDE_IS_VERSION(4,2,0)
45 m_capacityBar = new KCapacityBar(KCapacityBar::DrawTextInline, this);
46 QHBoxLayout *layout = new QHBoxLayout;
47 layout->addWidget(m_capacityBar);
48 m_view.size_box->setLayout(layout);
50 m_view.size_box->setHidden(true);
54 DvdWizardVob::~DvdWizardVob()
56 QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
58 #if KDE_IS_VERSION(4,2,0)
65 bool DvdWizardVob::isComplete() const
67 if (!m_view.error_message->text().isEmpty()) return false;
68 if (m_view.vob_1->url().path().isEmpty()) return false;
69 if (QFile::exists(m_view.vob_1->url().path())) return true;
73 bool DvdWizardVob::useChapters() const
75 return m_view.use_chapters->isChecked();
78 void DvdWizardVob::setUrl(const QString &url)
80 m_view.vob_1->setPath(url);
83 QStringList DvdWizardVob::selectedUrls() const
87 QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
88 for (int i = 0; i < allUrls.count(); i++) {
89 path = allUrls.at(i)->url().path();
90 if (!path.isEmpty()) {
97 QStringList DvdWizardVob::selectedTitles() const
101 QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
102 for (int i = 0; i < allUrls.count(); i++) {
103 path = allUrls.at(i)->url().path();
104 if (!path.isEmpty()) {
106 if (useChapters() && QFile::exists(path + ".dvdchapter")) {
107 // insert chapters as targets
108 QFile file(path + ".dvdchapter");
109 if (file.open(QIODevice::ReadOnly)) {
111 doc.setContent(&file);
113 QDomNodeList chapters = doc.elementsByTagName("chapter");
114 QStringList chaptersList;
115 for (int j = 0; j < chapters.count(); j++) {
116 result.append(QString::number(j) + " - " + chapters.at(j).toElement().attribute("title") + " " + chapters.at(j).toElement().attribute("time"));
126 QStringList DvdWizardVob::selectedTargets() const
130 QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
131 for (int i = 0; i < allUrls.count(); i++) {
132 path = allUrls.at(i)->url().path();
133 if (!path.isEmpty()) {
134 result.append("jump title " + QString::number(i + 1));
135 if (useChapters() && QFile::exists(path + ".dvdchapter")) {
136 // insert chapters as targets
137 QFile file(path + ".dvdchapter");
138 if (file.open(QIODevice::ReadOnly)) {
140 doc.setContent(&file);
142 QDomNodeList chapters = doc.elementsByTagName("chapter");
143 QStringList chaptersList;
144 for (int j = 0; j < chapters.count(); j++) {
145 result.append("jump title " + QString::number(i + 1) + " chapter " + QString::number(j + 1));
156 QString DvdWizardVob::introMovie() const
158 if (!m_view.use_intro->isChecked()) return QString();
159 return m_view.intro_vob->url().path();
162 void DvdWizardVob::slotCheckVobList(const QString &text)
164 emit completeChanged();
165 QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
166 int count = allUrls.count();
167 kDebug() << "// FOUND " << count << " URLS";
169 if (text.isEmpty()) return;
170 // insert second urlrequester
171 KUrlRequester *vob = new KUrlRequester(this);
172 vob->setFilter("video/mpeg");
173 m_view.vob_list->layout()->addWidget(vob);
174 connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
175 } else if (text.isEmpty()) {
176 if (allUrls.at(count - 1)->url().path().isEmpty() && allUrls.at(count - 2)->url().path().isEmpty()) {
177 // The last 2 urlrequesters are empty, remove last one
178 delete allUrls.takeLast();
181 if (allUrls.at(count - 1)->url().path().isEmpty()) return;
182 KUrlRequester *vob = new KUrlRequester(this);
183 vob->setFilter("video/mpeg");
184 m_view.vob_list->layout()->addWidget(vob);
185 connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
187 qint64 maxSize = (qint64) 47000 * 100000;
188 qint64 totalSize = 0;
189 for (int i = 0; i < allUrls.count(); i++) {
190 QFile f(allUrls.at(i)->url().path());
191 totalSize += f.size();
194 #if KDE_IS_VERSION(4,2,0)
195 m_capacityBar->setValue(100 * totalSize / maxSize);
196 m_capacityBar->setText(KIO::convertSize(totalSize));