]> git.sesse.net Git - kdenlive/blob - src/dvdwizardvob.cpp
Reformat initializer lists in all constructors.
[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) :
30         QWizardPage(parent)
31 {
32     m_view.setupUi(this);
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);
42
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);
48 #else
49     m_view.size_box->setHidden(true);
50 #endif
51 }
52
53 DvdWizardVob::~DvdWizardVob()
54 {
55     QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
56     qDeleteAll(allUrls);
57 #if KDE_IS_VERSION(4,2,0)
58     delete m_capacityBar;
59 #endif
60 }
61
62 // virtual
63
64 bool DvdWizardVob::isComplete() const
65 {
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;
69     return false;
70 }
71
72 void DvdWizardVob::setUrl(const QString &url)
73 {
74     m_view.vob_1->setPath(url);
75 }
76
77 QStringList DvdWizardVob::selectedUrls() const
78 {
79     QStringList result;
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());
84         }
85     }
86     return result;
87 }
88
89 QString DvdWizardVob::introMovie() const
90 {
91     if (!m_view.use_intro->isChecked()) return QString();
92     return m_view.intro_vob->url().path();
93 }
94
95 void DvdWizardVob::slotCheckVobList(const QString &text)
96 {
97     emit completeChanged();
98     QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
99     int count = allUrls.count();
100     kDebug() << "// FOUND " << count << " URLS";
101     if (count == 1) {
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             KUrlRequester *vob = allUrls.takeLast();
112             delete vob;
113         }
114     } else {
115         if (allUrls.at(count - 1)->url().path().isEmpty()) return;
116         KUrlRequester *vob = new KUrlRequester(this);
117         vob->setFilter("video/mpeg");
118         m_view.vob_list->layout()->addWidget(vob);
119         connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
120     }
121     qint64 maxSize = (qint64) 47000 * 100000;
122     qint64 totalSize = 0;
123     for (int i = 0; i < allUrls.count(); i++) {
124         QFile f(allUrls.at(i)->url().path());
125         totalSize += f.size();
126     }
127
128 #if KDE_IS_VERSION(4,2,0)
129     m_capacityBar->setValue(100 * totalSize / maxSize);
130     m_capacityBar->setText(KIO::convertSize(totalSize));
131 #endif
132 }
133