]> git.sesse.net Git - kdenlive/blob - src/dvdwizardvob.cpp
start improving dvd wizard
[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 <KUrlRequester>
21 #include <KDebug>
22
23 #include "dvdwizardvob.h"
24
25 DvdWizardVob::DvdWizardVob(QWidget *parent): QWizardPage(parent) {
26     m_view.setupUi(this);
27     m_view.intro_vob->setEnabled(false);
28     m_view.vob_1->setFilter("video/mpeg");
29     m_view.intro_vob->setFilter("video/mpeg");
30     connect(m_view.use_intro, SIGNAL(toggled(bool)), m_view.intro_vob, SLOT(setEnabled(bool)));
31     connect(m_view.vob_1, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
32
33 }
34
35 DvdWizardVob::~DvdWizardVob() {
36     QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
37     qDeleteAll(allUrls);
38 }
39
40 // virtual
41
42 bool DvdWizardVob::isComplete() const {
43     if (m_view.vob_1->url().path().isEmpty()) return false;
44     if (QFile::exists(m_view.vob_1->url().path())) return true;
45     return false;
46 }
47
48 void DvdWizardVob::setUrl(const QString &url) {
49     m_view.vob_1->setPath(url);
50 }
51
52 QStringList DvdWizardVob::selectedUrls() const {
53     QStringList result;
54     QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
55     for (int i = 0; i < allUrls.count(); i++) {
56         if (!allUrls.at(i)->url().path().isEmpty()) {
57             result.append(allUrls.at(i)->url().path());
58         }
59     }
60 }
61
62 void DvdWizardVob::slotCheckVobList(const QString &text) {
63     emit completeChanged();
64     QList<KUrlRequester *> allUrls = m_view.vob_list->findChildren<KUrlRequester *>();
65     int count = allUrls.count();
66     kDebug() << "// FOUND " << count << " URLS";
67     if (count == 1) {
68         if (text.isEmpty()) return;
69         // insert second urlrequester
70         KUrlRequester *vob = new KUrlRequester(this);
71         vob->setFilter("video/mpeg");
72         m_view.vob_list->layout()->addWidget(vob);
73         connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
74     } else if (text.isEmpty()) {
75         if (allUrls.at(count - 1)->url().path().isEmpty() && allUrls.at(count - 2)->url().path().isEmpty()) {
76             // The last 2 urlrequesters are empty, remove last one
77             KUrlRequester *vob = allUrls.takeLast();
78             delete vob;
79         }
80     } else {
81         if (allUrls.at(count - 1)->url().path().isEmpty()) return;
82         KUrlRequester *vob = new KUrlRequester(this);
83         vob->setFilter("video/mpeg");
84         m_view.vob_list->layout()->addWidget(vob);
85         connect(vob, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckVobList(const QString &)));
86     }
87 }
88