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>
29 DvdWizardVob::DvdWizardVob(QWidget *parent) :
33 m_view.intro_vob->setEnabled(false);
34 m_view.vob_1->setFilter("video/mpeg");
35 m_view.intro_vob->setFilter("video/mpeg");
36 connect(m_view.use_intro, SIGNAL(toggled(bool)), m_view.intro_vob, SLOT(setEnabled(bool)));
37 connect(m_view.vob_1, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
38 if (KStandardDirs::findExe("dvdauthor").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.", i18n("dvdauthor")));
39 if (KStandardDirs::findExe("mkisofs").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.", i18n("mkisofs")));
40 if (m_errorMessage.isEmpty()) m_view.error_message->setVisible(false);
41 else m_view.error_message->setText(m_errorMessage);
43 #if KDE_IS_VERSION(4,2,0)
44 m_capacityBar = new KCapacityBar(KCapacityBar::DrawTextInline, this);
45 QHBoxLayout *layout = new QHBoxLayout;
46 layout->addWidget(m_capacityBar);
47 m_view.size_box->setLayout(layout);
49 m_view.size_box->setHidden(true);
53 DvdWizardVob::~DvdWizardVob()
55 QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
57 #if KDE_IS_VERSION(4,2,0)
64 bool DvdWizardVob::isComplete() const
66 if (!m_view.error_message->text().isEmpty()) return false;
67 if (m_view.vob_1->url().path().isEmpty()) return false;
68 if (QFile::exists(m_view.vob_1->url().path())) return true;
72 void DvdWizardVob::setUrl(const QString &url)
74 m_view.vob_1->setPath(url);
77 QStringList DvdWizardVob::selectedUrls() const
80 QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
81 for (int i = 0; i < allUrls.count(); i++) {
82 if (!allUrls.at(i)->url().path().isEmpty()) {
83 result.append(allUrls.at(i)->url().path());
89 QString DvdWizardVob::introMovie() const
91 if (!m_view.use_intro->isChecked()) return QString();
92 return m_view.intro_vob->url().path();
95 void DvdWizardVob::slotCheckVobList(const QString &text)
97 emit completeChanged();
98 QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
99 int count = allUrls.count();
100 kDebug() << "// FOUND " << count << " URLS";
102 if (text.isEmpty()) return;
103 // insert second urlrequester
104 KUrlRequester *vob = new KUrlRequester(this);
105 vob->setFilter("video/mpeg");
106 m_view.vob_list->layout()->addWidget(vob);
107 connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
108 } else if (text.isEmpty()) {
109 if (allUrls.at(count - 1)->url().path().isEmpty() && allUrls.at(count - 2)->url().path().isEmpty()) {
110 // The last 2 urlrequesters are empty, remove last one
111 delete allUrls.takeLast();
114 if (allUrls.at(count - 1)->url().path().isEmpty()) return;
115 KUrlRequester *vob = new KUrlRequester(this);
116 vob->setFilter("video/mpeg");
117 m_view.vob_list->layout()->addWidget(vob);
118 connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
120 qint64 maxSize = (qint64) 47000 * 100000;
121 qint64 totalSize = 0;
122 for (int i = 0; i < allUrls.count(); i++) {
123 QFile f(allUrls.at(i)->url().path());
124 totalSize += f.size();
127 #if KDE_IS_VERSION(4,2,0)
128 m_capacityBar->setValue(100 * totalSize / maxSize);
129 m_capacityBar->setText(KIO::convertSize(totalSize));