]> git.sesse.net Git - kdenlive/blob - src/dvdwizardvob.cpp
Fix compilation with KDE < 4.2
[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
29 DvdWizardVob::DvdWizardVob(QWidget *parent): QWizardPage(parent) {
30     m_view.setupUi(this);
31     m_view.intro_vob->setEnabled(false);
32     m_view.vob_1->setFilter("video/mpeg");
33     m_view.intro_vob->setFilter("video/mpeg");
34     connect(m_view.use_intro, SIGNAL(toggled(bool)), m_view.intro_vob, SLOT(setEnabled(bool)));
35     connect(m_view.vob_1, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
36     if (KStandardDirs::findExe("dvdauthor").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.", i18n("dvdauthor")));
37     if (KStandardDirs::findExe("mkisofs").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.", i18n("mkisofs")));
38     if (m_errorMessage.isEmpty()) m_view.error_message->setVisible(false);
39     else m_view.error_message->setText(m_errorMessage);
40
41 #if KDE_IS_VERSION(4,2,0)
42     m_capacityBar = new KCapacityBar(KCapacityBar::DrawTextInline, this);
43     QHBoxLayout *layout = new QHBoxLayout;
44     layout->addWidget(m_capacityBar);
45     m_view.size_box->setLayout(layout);
46 #else
47     m_view.size_box->setHidden(true);
48 #endif
49 }
50
51 DvdWizardVob::~DvdWizardVob() {
52     QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
53     qDeleteAll(allUrls);
54 #if KDE_IS_VERSION(4,2,0)
55     delete m_capacityBar;
56 #endif
57 }
58
59 // virtual
60
61 bool DvdWizardVob::isComplete() const {
62     if (!m_view.error_message->text().isEmpty()) return false;
63     if (m_view.vob_1->url().path().isEmpty()) return false;
64     if (QFile::exists(m_view.vob_1->url().path())) return true;
65     return false;
66 }
67
68 void DvdWizardVob::setUrl(const QString &url) {
69     m_view.vob_1->setPath(url);
70 }
71
72 QStringList DvdWizardVob::selectedUrls() const {
73     QStringList result;
74     QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
75     for (int i = 0; i < allUrls.count(); i++) {
76         if (!allUrls.at(i)->url().path().isEmpty()) {
77             result.append(allUrls.at(i)->url().path());
78         }
79     }
80     return result;
81 }
82
83 QString DvdWizardVob::introMovie() const {
84     if (!m_view.use_intro->isChecked()) return QString();
85     return m_view.intro_vob->url().path();
86 }
87
88 void DvdWizardVob::slotCheckVobList(const QString &text) {
89     emit completeChanged();
90     QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
91     int count = allUrls.count();
92     kDebug() << "// FOUND " << count << " URLS";
93     if (count == 1) {
94         if (text.isEmpty()) return;
95         // insert second urlrequester
96         KUrlRequester *vob = new KUrlRequester(this);
97         vob->setFilter("video/mpeg");
98         m_view.vob_list->layout()->addWidget(vob);
99         connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
100     } else if (text.isEmpty()) {
101         if (allUrls.at(count - 1)->url().path().isEmpty() && allUrls.at(count - 2)->url().path().isEmpty()) {
102             // The last 2 urlrequesters are empty, remove last one
103             KUrlRequester *vob = allUrls.takeLast();
104             delete vob;
105         }
106     } else {
107         if (allUrls.at(count - 1)->url().path().isEmpty()) return;
108         KUrlRequester *vob = new KUrlRequester(this);
109         vob->setFilter("video/mpeg");
110         m_view.vob_list->layout()->addWidget(vob);
111         connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
112     }
113     qint64 maxSize = (qint64) 47000 * 100000;
114     qint64 totalSize = 0;
115     for (int i = 0; i < allUrls.count(); i++) {
116         QFile f(allUrls.at(i)->url().path());
117         totalSize += f.size();
118     }
119
120 #if KDE_IS_VERSION(4,2,0)
121     m_capacityBar->setValue(100 * totalSize / maxSize);
122     m_capacityBar->setText(KIO::convertSize(totalSize));
123 #endif
124 }
125