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"
24 #include <mlt++/Mlt.h>
26 #include <KUrlRequester>
28 #include <KStandardDirs>
30 #include <KFileDialog>
32 #include <QHBoxLayout>
33 #include <QDomDocument>
34 #include <QTreeWidgetItem>
36 DvdWizardVob::DvdWizardVob(const QString &profile, QWidget *parent) :
40 m_view.intro_vob->setEnabled(false);
41 m_view.intro_vob->setFilter("video/mpeg");
42 m_view.button_add->setIcon(KIcon("document-new"));
43 m_view.button_delete->setIcon(KIcon("edit-delete"));
44 m_view.button_up->setIcon(KIcon("go-up"));
45 m_view.button_down->setIcon(KIcon("go-down"));
46 connect(m_view.use_intro, SIGNAL(toggled(bool)), m_view.intro_vob, SLOT(setEnabled(bool)));
47 connect(m_view.button_add, SIGNAL(clicked()), this, SLOT(slotAddVobFile()));
48 connect(m_view.button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteVobFile()));
49 connect(m_view.button_up, SIGNAL(clicked()), this, SLOT(slotItemUp()));
50 connect(m_view.button_down, SIGNAL(clicked()), this, SLOT(slotItemDown()));
51 connect(m_view.vobs_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckVobList()));
52 m_view.vobs_list->setIconSize(QSize(60, 45));
54 if (KStandardDirs::findExe("dvdauthor").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.", i18n("dvdauthor")));
55 if (KStandardDirs::findExe("mkisofs").isEmpty()) m_errorMessage.append(i18n("<strong>Program %1 is required for the DVD wizard.", i18n("mkisofs")));
56 if (m_errorMessage.isEmpty()) m_view.error_message->setVisible(false);
57 else m_view.error_message->setText(m_errorMessage);
59 m_view.dvd_profile->addItems(QStringList() << i18n("PAL") << i18n("NTSC"));
60 if (profile == "dv_ntsc" || profile == "dv_ntsc_wide") {
61 m_view.dvd_profile->setCurrentIndex(1);
63 connect(m_view.dvd_profile, SIGNAL(activated(int)), this, SLOT(changeFormat()));
64 m_view.vobs_list->header()->setStretchLastSection(false);
65 m_view.vobs_list->header()->setResizeMode(0, QHeaderView::Stretch);
66 m_view.vobs_list->header()->setResizeMode(1, QHeaderView::Custom);
67 m_view.vobs_list->header()->setResizeMode(2, QHeaderView::Custom);
69 #if KDE_IS_VERSION(4,2,0)
70 m_capacityBar = new KCapacityBar(KCapacityBar::DrawTextInline, this);
71 QHBoxLayout *layout = new QHBoxLayout;
72 layout->addWidget(m_capacityBar);
73 m_view.size_box->setLayout(layout);
75 m_view.size_box->setHidden(true);
80 DvdWizardVob::~DvdWizardVob()
82 #if KDE_IS_VERSION(4,2,0)
88 void DvdWizardVob::slotAddVobFile(KUrl url)
90 if (url.isEmpty()) url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), "video/mpeg", this, i18n("Add new video file"));
91 if (url.isEmpty()) return;
93 qint64 fileSize = f.size();
95 if (m_view.dvd_profile->currentIndex() == 0) profilename = "dv_pal";
96 else profilename = "dv_ntsc";
97 Mlt::Profile profile((char*) profilename.data());
98 QTreeWidgetItem *item = new QTreeWidgetItem(m_view.vobs_list, QStringList() << url.path() << QString() << KIO::convertSize(fileSize));
99 item->setData(0, Qt::UserRole, fileSize);
100 item->setIcon(0, KIcon("video-x-generic"));
104 char *tmp = (char *) qstrdup(url.path().toUtf8().data());
105 Mlt::Producer *producer = new Mlt::Producer(profile, tmp);
108 if (producer->is_blank() == false) {
109 pix = KThumb::getFrame(producer, 0, 60, 45);
110 item->setIcon(0, pix);
111 int playTime = producer->get_playtime();
112 item->setText(1, Timecode::getStringTimecode(playTime, profile.fps()));
113 item->setData(1, Qt::UserRole, playTime);
120 void DvdWizardVob::changeFormat()
122 int max = m_view.vobs_list->topLevelItemCount();
124 if (m_view.dvd_profile->currentIndex() == 0) profilename = "dv_pal";
125 else profilename = "dv_ntsc";
126 Mlt::Profile profile((char*) profilename.data());
127 QPixmap pix(180, 135);
129 for (int i = 0; i < max; i++) {
130 QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(i);
131 char *tmp = (char *) qstrdup(item->text(0).toUtf8().data());
132 Mlt::Producer *producer = new Mlt::Producer(profile, tmp);
135 if (producer->is_blank() == false) {
136 //pix = KThumb::getFrame(producer, 0, 180, 135);
137 //item->setIcon(0, pix);
138 item->setText(1, Timecode::getStringTimecode(producer->get_playtime(), profile.fps()));
141 int submax = item->childCount();
142 for (int j = 0; j < submax; j++) {
143 QTreeWidgetItem *subitem = item->child(j);
144 subitem->setText(1, Timecode::getStringTimecode(subitem->data(1, Qt::UserRole).toInt(), profile.fps()));
150 void DvdWizardVob::slotDeleteVobFile()
152 QTreeWidgetItem *item = m_view.vobs_list->currentItem();
153 if (item == NULL) return;
160 bool DvdWizardVob::isComplete() const
162 if (!m_view.error_message->text().isEmpty()) return false;
163 if (m_view.vobs_list->topLevelItemCount() == 0) return false;
167 void DvdWizardVob::setUrl(const QString &url)
169 slotAddVobFile(KUrl(url));
172 QStringList DvdWizardVob::selectedUrls() const
176 int max = m_view.vobs_list->topLevelItemCount();
177 for (int i = 0; i < max; i++) {
178 QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(i);
179 if (item) result.append(item->text(0));
185 QStringList DvdWizardVob::durations() const
189 int max = m_view.vobs_list->topLevelItemCount();
190 for (int i = 0; i < max; i++) {
191 QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(i);
192 if (item) result.append(QString::number(item->data(1, Qt::UserRole).toInt()));
197 int DvdWizardVob::duration(int ix) const
200 QTreeWidgetItem *item = m_view.vobs_list->topLevelItem(ix);
202 result = item->data(1, Qt::UserRole).toInt();
208 QString DvdWizardVob::introMovie() const
210 if (!m_view.use_intro->isChecked()) return QString();
211 return m_view.intro_vob->url().path();
214 void DvdWizardVob::slotCheckVobList()
216 emit completeChanged();
217 int max = m_view.vobs_list->topLevelItemCount();
218 QTreeWidgetItem *item = m_view.vobs_list->currentItem();
220 if (item == NULL) hasItem = false;
221 m_view.button_delete->setEnabled(hasItem);
222 if (hasItem && m_view.vobs_list->indexOfTopLevelItem(item) == 0) m_view.button_up->setEnabled(false);
223 else m_view.button_up->setEnabled(hasItem);
224 if (hasItem && m_view.vobs_list->indexOfTopLevelItem(item) == max - 1) m_view.button_down->setEnabled(false);
225 else m_view.button_down->setEnabled(hasItem);
227 #if KDE_IS_VERSION(4,2,0)
228 qint64 totalSize = 0;
229 for (int i = 0; i < max; i++) {
230 item = m_view.vobs_list->topLevelItem(i);
231 if (item) totalSize += (qint64) item->data(0, Qt::UserRole).toInt();
234 qint64 maxSize = (qint64) 47000 * 100000;
235 m_capacityBar->setValue(100 * totalSize / maxSize);
236 m_capacityBar->setText(KIO::convertSize(totalSize));
240 void DvdWizardVob::slotItemUp()
242 QTreeWidgetItem *item = m_view.vobs_list->currentItem();
243 if (item == NULL) return;
244 int index = m_view.vobs_list->indexOfTopLevelItem(item);
245 if (index == 0) return;
246 m_view.vobs_list->insertTopLevelItem(index - 1, m_view.vobs_list->takeTopLevelItem(index));
249 void DvdWizardVob::slotItemDown()
251 int max = m_view.vobs_list->topLevelItemCount();
252 QTreeWidgetItem *item = m_view.vobs_list->currentItem();
253 if (item == NULL) return;
254 int index = m_view.vobs_list->indexOfTopLevelItem(item);
255 if (index == max - 1) return;
256 m_view.vobs_list->insertTopLevelItem(index + 1, m_view.vobs_list->takeTopLevelItem(index));
259 bool DvdWizardVob::isPal() const
261 return m_view.dvd_profile->currentIndex() == 0;