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