]> git.sesse.net Git - kdenlive/blob - src/dvdwizardvob.cpp
*Render dialog can now create xml files for dvd chapters based on guides (usable...
[kdenlive] / src / dvdwizardvob.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 "dvdwizardvob.h"
21
22 #include <KUrlRequester>
23 #include <KDebug>
24 #include <KStandardDirs>
25 #include <KFileItem>
26
27 #include <QHBoxLayout>
28 #include <QDomDocument>
29
30 DvdWizardVob::DvdWizardVob(QWidget *parent) :
31         QWizardPage(parent)
32 {
33     m_view.setupUi(this);
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);
43
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);
49 #else
50     m_view.size_box->setHidden(true);
51 #endif
52 }
53
54 DvdWizardVob::~DvdWizardVob()
55 {
56     QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
57     qDeleteAll(allUrls);
58 #if KDE_IS_VERSION(4,2,0)
59     delete m_capacityBar;
60 #endif
61 }
62
63 // virtual
64
65 bool DvdWizardVob::isComplete() const
66 {
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;
70     return false;
71 }
72
73 bool DvdWizardVob::useChapters() const
74 {
75     return m_view.use_chapters->isChecked();
76 }
77
78 void DvdWizardVob::setUrl(const QString &url)
79 {
80     m_view.vob_1->setPath(url);
81 }
82
83 QStringList DvdWizardVob::selectedUrls() const
84 {
85     QStringList result;
86     QString path;
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()) {
91             result.append(path);
92         }
93     }
94     return result;
95 }
96
97 QStringList DvdWizardVob::selectedTitles() const
98 {
99     QStringList result;
100     QString path;
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()) {
105             result.append(path);
106             if (useChapters() && QFile::exists(path + ".dvdchapter")) {
107                 // insert chapters as targets
108                 QFile file(path + ".dvdchapter");
109                 if (file.open(QIODevice::ReadOnly)) {
110                     QDomDocument doc;
111                     doc.setContent(&file);
112                     file.close();
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"));
117                     }
118                 }
119
120             }
121         }
122     }
123     return result;
124 }
125
126 QStringList DvdWizardVob::selectedTargets() const
127 {
128     QStringList result;
129     QString path;
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("title " + QString::number(i));
135             if (useChapters() && QFile::exists(path + ".dvdchapter")) {
136                 // insert chapters as targets
137                 QFile file(path + ".dvdchapter");
138                 if (file.open(QIODevice::ReadOnly)) {
139                     QDomDocument doc;
140                     doc.setContent(&file);
141                     file.close();
142                     QDomNodeList chapters = doc.elementsByTagName("chapter");
143                     QStringList chaptersList;
144                     for (int j = 0; j < chapters.count(); j++) {
145                         result.append("title " + QString::number(i + 1) + " chapter " + QString::number(j + 1));
146                     }
147                 }
148
149             }
150         }
151     }
152     return result;
153 }
154
155
156 QString DvdWizardVob::introMovie() const
157 {
158     if (!m_view.use_intro->isChecked()) return QString();
159     return m_view.intro_vob->url().path();
160 }
161
162 void DvdWizardVob::slotCheckVobList(const QString &text)
163 {
164     emit completeChanged();
165     QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
166     int count = allUrls.count();
167     kDebug() << "// FOUND " << count << " URLS";
168     if (count == 1) {
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();
179         }
180     } else {
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 &)));
186     }
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();
192     }
193
194 #if KDE_IS_VERSION(4,2,0)
195     m_capacityBar->setValue(100 * totalSize / maxSize);
196     m_capacityBar->setText(KIO::convertSize(totalSize));
197 #endif
198 }
199