summaryrefslogtreecommitdiffstats
path: root/libk3b/projects/movixcd
diff options
context:
space:
mode:
Diffstat (limited to 'libk3b/projects/movixcd')
-rw-r--r--libk3b/projects/movixcd/Makefile.am23
-rw-r--r--libk3b/projects/movixcd/k3bmovixdoc.cpp445
-rw-r--r--libk3b/projects/movixcd/k3bmovixdoc.h125
-rw-r--r--libk3b/projects/movixcd/k3bmovixdocpreparer.cpp490
-rw-r--r--libk3b/projects/movixcd/k3bmovixdocpreparer.h67
-rw-r--r--libk3b/projects/movixcd/k3bmovixfileitem.cpp68
-rw-r--r--libk3b/projects/movixcd/k3bmovixfileitem.h52
-rw-r--r--libk3b/projects/movixcd/k3bmovixjob.cpp132
-rw-r--r--libk3b/projects/movixcd/k3bmovixjob.h60
-rw-r--r--libk3b/projects/movixcd/k3bmovixprogram.cpp339
-rw-r--r--libk3b/projects/movixcd/k3bmovixprogram.h103
11 files changed, 1904 insertions, 0 deletions
diff --git a/libk3b/projects/movixcd/Makefile.am b/libk3b/projects/movixcd/Makefile.am
new file mode 100644
index 0000000..d1b4f5d
--- /dev/null
+++ b/libk3b/projects/movixcd/Makefile.am
@@ -0,0 +1,23 @@
+# we need the ../datacd for the uic generated header files
+AM_CPPFLAGS= -I$(srcdir)/../../core \
+ -I$(srcdir)/../../../libk3bdevice \
+ -I$(srcdir)/../../../src \
+ -I$(srcdir)/../../tools \
+ -I$(srcdir)/../datacd \
+ -I$(srcdir)/.. \
+ -I../datacd \
+ $(all_includes)
+
+METASOURCES = AUTO
+
+noinst_LTLIBRARIES = libmovix.la
+
+libmovix_la_SOURCES = k3bmovixprogram.cpp \
+ k3bmovixdoc.cpp \
+ k3bmovixjob.cpp \
+ k3bmovixfileitem.cpp \
+ k3bmovixdocpreparer.cpp
+
+include_HEADERS = k3bmovixdoc.h \
+ k3bmovixjob.h \
+ k3bmovixfileitem.h
diff --git a/libk3b/projects/movixcd/k3bmovixdoc.cpp b/libk3b/projects/movixcd/k3bmovixdoc.cpp
new file mode 100644
index 0000000..f7b2198
--- /dev/null
+++ b/libk3b/projects/movixcd/k3bmovixdoc.cpp
@@ -0,0 +1,445 @@
+/*
+ *
+ * $Id: k3bmovixdoc.cpp 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+
+#include "k3bmovixdoc.h"
+#include "k3bmovixjob.h"
+#include "k3bmovixfileitem.h"
+
+#include <k3bdiritem.h>
+#include <k3bfileitem.h>
+#include <k3bglobals.h>
+
+#include <klocale.h>
+#include <kdebug.h>
+#include <kurl.h>
+#include <kinputdialog.h>
+#include <kmessagebox.h>
+#include <kconfig.h>
+#include <kapplication.h>
+
+#include <qdom.h>
+#include <qfileinfo.h>
+
+
+K3bMovixDoc::K3bMovixDoc( QObject* parent )
+ : K3bDataDoc( parent )
+{
+ connect( this, SIGNAL(itemRemoved(K3bDataItem*)),
+ this, SLOT(slotDataItemRemoved(K3bDataItem*)) );
+}
+
+
+K3bMovixDoc::~K3bMovixDoc()
+{
+}
+
+
+K3bBurnJob* K3bMovixDoc::newBurnJob( K3bJobHandler* hdl, QObject* parent )
+{
+ return new K3bMovixJob( this, hdl, parent );
+}
+
+
+bool K3bMovixDoc::newDocument()
+{
+ m_loopPlaylist = 1;
+ m_ejectDisk = false;
+ m_reboot = false;
+ m_shutdown = false;
+ m_randomPlay = false;
+
+ return K3bDataDoc::newDocument();
+}
+
+
+void K3bMovixDoc::addUrls( const KURL::List& urls )
+{
+ for( KURL::List::ConstIterator it = urls.begin(); it != urls.end(); ++it ) {
+ addMovixFile( *it );
+ }
+
+ emit newMovixFileItems();
+}
+
+
+void K3bMovixDoc::addMovixFile( const KURL& _url, int pos )
+{
+ KURL url = K3b::convertToLocalUrl( _url );
+
+ QFileInfo f( url.path() );
+ if( !f.isFile() || !url.isLocalFile() )
+ return;
+
+ QString newName = f.fileName();
+ if( nameAlreadyInDir( newName, root() ) ) {
+ kapp->config()->setGroup("Data project settings");
+ bool dropDoubles = kapp->config()->readBoolEntry( "Drop doubles", false );
+ if( dropDoubles )
+ return;
+
+ bool ok = true;
+ do {
+ newName = KInputDialog::getText( i18n("Enter New Filename"),
+ i18n("A file with that name already exists. Please enter a new name:"),
+ newName, &ok, 0 );
+ } while( ok && nameAlreadyInDir( newName, root() ) );
+
+ if( !ok )
+ return;
+ }
+
+ K3bMovixFileItem* newK3bItem = new K3bMovixFileItem( f.absFilePath(), this, root(), newName );
+ if( pos < 0 || pos > (int)m_movixFiles.count() )
+ pos = m_movixFiles.count();
+
+ m_movixFiles.insert( pos, newK3bItem );
+
+ emit newMovixFileItems();
+
+ setModified(true);
+}
+
+
+bool K3bMovixDoc::loadDocumentData( QDomElement* rootElem )
+{
+ if( !root() )
+ newDocument();
+
+ QDomNodeList nodes = rootElem->childNodes();
+
+ if( nodes.item(0).nodeName() != "general" ) {
+ kdDebug() << "(K3bMovixDoc) could not find 'general' section." << endl;
+ return false;
+ }
+ if( !readGeneralDocumentData( nodes.item(0).toElement() ) )
+ return false;
+
+
+ // parse options
+ // -----------------------------------------------------------------
+ if( nodes.item(1).nodeName() != "data_options" ) {
+ kdDebug() << "(K3bMovixDoc) could not find 'data_options' section." << endl;
+ return false;
+ }
+ if( !loadDocumentDataOptions( nodes.item(1).toElement() ) )
+ return false;
+ // -----------------------------------------------------------------
+
+
+
+ // parse header
+ // -----------------------------------------------------------------
+ if( nodes.item(2).nodeName() != "data_header" ) {
+ kdDebug() << "(K3bMovixDoc) could not find 'data_header' section." << endl;
+ return false;
+ }
+ if( !loadDocumentDataHeader( nodes.item(2).toElement() ) )
+ return false;
+ // -----------------------------------------------------------------
+
+
+
+ // parse movix options
+ // -----------------------------------------------------------------
+ if( nodes.item(3).nodeName() != "movix_options" ) {
+ kdDebug() << "(K3bMovixDoc) could not find 'movix_options' section." << endl;
+ return false;
+ }
+
+ // load the options
+ QDomNodeList optionList = nodes.item(3).childNodes();
+ for( uint i = 0; i < optionList.count(); i++ ) {
+
+ QDomElement e = optionList.item(i).toElement();
+ if( e.isNull() )
+ return false;
+
+ if( e.nodeName() == "shutdown")
+ setShutdown( e.attributeNode( "activated" ).value() == "yes" );
+ else if( e.nodeName() == "reboot")
+ setReboot( e.attributeNode( "activated" ).value() == "yes" );
+ else if( e.nodeName() == "eject_disk")
+ setEjectDisk( e.attributeNode( "activated" ).value() == "yes" );
+ else if( e.nodeName() == "random_play")
+ setRandomPlay( e.attributeNode( "activated" ).value() == "yes" );
+ else if( e.nodeName() == "no_dma")
+ setNoDma( e.attributeNode( "activated" ).value() == "yes" );
+ else if( e.nodeName() == "subtitle_fontset")
+ setSubtitleFontset( e.text() );
+ else if( e.nodeName() == "boot_message_language")
+ setBootMessageLanguage( e.text() );
+ else if( e.nodeName() == "audio_background")
+ setAudioBackground( e.text() );
+ else if( e.nodeName() == "keyboard_language")
+ setKeyboardLayout( e.text() );
+ else if( e.nodeName() == "codecs")
+ setCodecs( QStringList::split( ',', e.text() ) );
+ else if( e.nodeName() == "default_boot_label")
+ setDefaultBootLabel( e.text() );
+ else if( e.nodeName() == "additional_mplayer_options")
+ setAdditionalMPlayerOptions( e.text() );
+ else if( e.nodeName() == "unwanted_mplayer_options")
+ setUnwantedMPlayerOptions( e.text() );
+ else if( e.nodeName() == "loop_playlist")
+ setLoopPlaylist( e.text().toInt() );
+ else
+ kdDebug() << "(K3bMovixDoc) unknown movix option: " << e.nodeName() << endl;
+ }
+ // -----------------------------------------------------------------
+
+ // parse files
+ // -----------------------------------------------------------------
+ if( nodes.item(4).nodeName() != "movix_files" ) {
+ kdDebug() << "(K3bMovixDoc) could not find 'movix_files' section." << endl;
+ return false;
+ }
+
+ // load file items
+ QDomNodeList fileList = nodes.item(4).childNodes();
+ for( uint i = 0; i < fileList.count(); i++ ) {
+
+ QDomElement e = fileList.item(i).toElement();
+ if( e.isNull() )
+ return false;
+
+ if( e.nodeName() == "file" ) {
+ if( !e.hasAttribute( "name" ) ) {
+ kdDebug() << "(K3bMovixDoc) found file tag without name attribute." << endl;
+ return false;
+ }
+
+ QDomElement urlElem = e.firstChild().toElement();
+ if( urlElem.isNull() ) {
+ kdDebug() << "(K3bMovixDoc) found file tag without url child." << endl;
+ return false;
+ }
+
+ // create the item
+ K3bMovixFileItem* newK3bItem = new K3bMovixFileItem( urlElem.text(),
+ this,
+ root(),
+ e.attributeNode("name").value() );
+ m_movixFiles.append( newK3bItem );
+
+ // subtitle file?
+ QDomElement subTitleElem = e.childNodes().item(1).toElement();
+ if( !subTitleElem.isNull() && subTitleElem.nodeName() == "subtitle_file" ) {
+ urlElem = subTitleElem.firstChild().toElement();
+ if( urlElem.isNull() ) {
+ kdDebug() << "(K3bMovixDoc) found subtitle_file tag without url child." << endl;
+ return false;
+ }
+
+ QString name = K3bMovixFileItem::subTitleFileName( newK3bItem->k3bName() );
+ K3bFileItem* subItem = new K3bFileItem( urlElem.text(), this, root(), name );
+ newK3bItem->setSubTitleItem( subItem );
+ }
+ }
+ else {
+ kdDebug() << "(K3bMovixDoc) found " << e.nodeName() << " node where 'file' was expected." << endl;
+ return false;
+ }
+ }
+ // -----------------------------------------------------------------
+
+
+ emit newMovixFileItems();
+
+ return true;
+}
+
+
+bool K3bMovixDoc::saveDocumentData( QDomElement* docElem )
+{
+ QDomDocument doc = docElem->ownerDocument();
+
+ saveGeneralDocumentData( docElem );
+
+ QDomElement optionsElem = doc.createElement( "data_options" );
+ saveDocumentDataOptions( optionsElem );
+
+ QDomElement headerElem = doc.createElement( "data_header" );
+ saveDocumentDataHeader( headerElem );
+
+ QDomElement movixOptElem = doc.createElement( "movix_options" );
+ QDomElement movixFilesElem = doc.createElement( "movix_files" );
+
+
+ // save the movix options
+ QDomElement propElem = doc.createElement( "shutdown" );
+ propElem.setAttribute( "activated", shutdown() ? "yes" : "no" );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "reboot" );
+ propElem.setAttribute( "activated", reboot() ? "yes" : "no" );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "eject_disk" );
+ propElem.setAttribute( "activated", ejectDisk() ? "yes" : "no" );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "random_play" );
+ propElem.setAttribute( "activated", randomPlay() ? "yes" : "no" );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "no_dma" );
+ propElem.setAttribute( "activated", noDma() ? "yes" : "no" );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "subtitle_fontset" );
+ propElem.appendChild( doc.createTextNode( subtitleFontset() ) );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "boot_message_language" );
+ propElem.appendChild( doc.createTextNode( bootMessageLanguage() ) );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "audio_background" );
+ propElem.appendChild( doc.createTextNode( audioBackground() ) );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "keyboard_language" );
+ propElem.appendChild( doc.createTextNode( keyboardLayout() ) );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "codecs" );
+ propElem.appendChild( doc.createTextNode( codecs().join(",") ) );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "default_boot_label" );
+ propElem.appendChild( doc.createTextNode( defaultBootLabel() ) );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "additional_mplayer_options" );
+ propElem.appendChild( doc.createTextNode( additionalMPlayerOptions() ) );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "unwanted_mplayer_options" );
+ propElem.appendChild( doc.createTextNode( unwantedMPlayerOptions() ) );
+ movixOptElem.appendChild( propElem );
+
+ propElem = doc.createElement( "loop_playlist" );
+ propElem.appendChild( doc.createTextNode( QString::number(loopPlaylist()) ) );
+ movixOptElem.appendChild( propElem );
+
+
+ // save the movix items
+ for( QPtrListIterator<K3bMovixFileItem> it( m_movixFiles );
+ *it; ++it ) {
+ K3bMovixFileItem* item = *it;
+
+ QDomElement topElem = doc.createElement( "file" );
+ topElem.setAttribute( "name", item->k3bName() );
+ QDomElement urlElem = doc.createElement( "url" );
+ urlElem.appendChild( doc.createTextNode( item->localPath() ) );
+ topElem.appendChild( urlElem );
+ if( item->subTitleItem() ) {
+ QDomElement subElem = doc.createElement( "subtitle_file" );
+ urlElem = doc.createElement( "url" );
+ urlElem.appendChild( doc.createTextNode( item->subTitleItem()->localPath() ) );
+ subElem.appendChild( urlElem );
+ topElem.appendChild( subElem );
+ }
+
+ movixFilesElem.appendChild( topElem );
+ }
+
+ docElem->appendChild( optionsElem );
+ docElem->appendChild( headerElem );
+ docElem->appendChild( movixOptElem );
+ docElem->appendChild( movixFilesElem );
+
+ return true;
+}
+
+
+void K3bMovixDoc::slotDataItemRemoved( K3bDataItem* item )
+{
+ // check if it's a movix item
+ if( K3bMovixFileItem* fi = dynamic_cast<K3bMovixFileItem*>(item) )
+ if( m_movixFiles.containsRef( fi ) ) {
+ emit movixItemRemoved( fi );
+ m_movixFiles.removeRef( fi );
+ setModified(true);
+ }
+}
+
+
+int K3bMovixDoc::indexOf( K3bMovixFileItem* item )
+{
+ return m_movixFiles.findRef(item)+1;
+}
+
+
+void K3bMovixDoc::moveMovixItem( K3bMovixFileItem* item, K3bMovixFileItem* itemAfter )
+{
+ if( item == itemAfter )
+ return;
+
+ // set the current item to track
+ m_movixFiles.findRef( item );
+ // take the current item
+ item = m_movixFiles.take();
+
+ // if after == 0 findRef returnes -1
+ int pos = m_movixFiles.findRef( itemAfter );
+ m_movixFiles.insert( pos+1, item );
+
+ emit newMovixFileItems();
+
+ setModified(true);
+}
+
+
+void K3bMovixDoc::addSubTitleItem( K3bMovixFileItem* item, const KURL& url )
+{
+ if( item->subTitleItem() )
+ removeSubTitleItem( item );
+
+ QFileInfo f( url.path() );
+ if( !f.isFile() || !url.isLocalFile() )
+ return;
+
+ // check if there already is a file named like we want to name the subTitle file
+ QString name = K3bMovixFileItem::subTitleFileName( item->k3bName() );
+
+ if( nameAlreadyInDir( name, root() ) ) {
+ KMessageBox::error( 0, i18n("Could not rename subtitle file. File with requested name %1 already exists.").arg(name) );
+ return;
+ }
+
+ K3bFileItem* subItem = new K3bFileItem( f.absFilePath(), this, root(), name );
+ item->setSubTitleItem( subItem );
+
+ emit newMovixFileItems();
+
+ setModified(true);
+}
+
+
+void K3bMovixDoc::removeSubTitleItem( K3bMovixFileItem* item )
+{
+ if( item->subTitleItem() ) {
+ emit subTitleItemRemoved( item );
+
+ delete item->subTitleItem();
+ item->setSubTitleItem(0);
+
+ setModified(true);
+ }
+}
+
+#include "k3bmovixdoc.moc"
diff --git a/libk3b/projects/movixcd/k3bmovixdoc.h b/libk3b/projects/movixcd/k3bmovixdoc.h
new file mode 100644
index 0000000..53debfc
--- /dev/null
+++ b/libk3b/projects/movixcd/k3bmovixdoc.h
@@ -0,0 +1,125 @@
+/*
+ *
+ * $Id: k3bmovixdoc.h 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+
+#ifndef _K3B_MOVIX_DOC_H_
+#define _K3B_MOVIX_DOC_H_
+
+
+#include <k3bdatadoc.h>
+
+#include <qptrlist.h>
+#include "k3b_export.h"
+//class K3bView;
+class KURL;
+class QDomElement;
+class K3bFileItem;
+class K3bMovixFileItem;
+class K3bDataItem;
+class KConfig;
+
+
+class LIBK3B_EXPORT K3bMovixDoc : public K3bDataDoc
+{
+ Q_OBJECT
+
+ public:
+ K3bMovixDoc( QObject* parent = 0 );
+ virtual ~K3bMovixDoc();
+
+ virtual int type() const { return MOVIX; }
+
+ virtual K3bBurnJob* newBurnJob( K3bJobHandler* hdl, QObject* parent );
+
+ bool newDocument();
+
+ const QPtrList<K3bMovixFileItem>& movixFileItems() const { return m_movixFiles; }
+
+ int indexOf( K3bMovixFileItem* );
+
+
+ bool shutdown() const { return m_shutdown; }
+ bool reboot() const { return m_reboot; }
+ bool ejectDisk() const { return m_ejectDisk; }
+ bool randomPlay() const { return m_randomPlay; }
+ const QString& subtitleFontset() const { return m_subtitleFontset; }
+ const QString& bootMessageLanguage() const { return m_bootMessageLanguage; }
+ const QString& audioBackground() const { return m_audioBackground; }
+ const QString& keyboardLayout() const { return m_keyboardLayout; }
+ const QStringList& codecs() const { return m_codecs; }
+ const QString& defaultBootLabel() const { return m_defaultBootLabel; }
+ const QString& additionalMPlayerOptions() const { return m_additionalMPlayerOptions; }
+ const QString& unwantedMPlayerOptions() const { return m_unwantedMPlayerOptions; }
+ int loopPlaylist() const { return m_loopPlaylist; }
+ bool noDma() const { return m_noDma; }
+
+ void setShutdown( bool v ) { m_shutdown = v; }
+ void setReboot( bool v ) { m_reboot = v; }
+ void setEjectDisk( bool v ) { m_ejectDisk = v; }
+ void setRandomPlay( bool v ) { m_randomPlay = v; }
+ void setSubtitleFontset( const QString& v ) { m_subtitleFontset = v; }
+ void setBootMessageLanguage( const QString& v ) { m_bootMessageLanguage = v; }
+ void setAudioBackground( const QString& b ) { m_audioBackground = b; }
+ void setKeyboardLayout( const QString& l ) { m_keyboardLayout = l; }
+ void setCodecs( const QStringList& c ) { m_codecs = c; }
+ void setDefaultBootLabel( const QString& v ) { m_defaultBootLabel = v; }
+ void setAdditionalMPlayerOptions( const QString& v ) { m_additionalMPlayerOptions = v; }
+ void setUnwantedMPlayerOptions( const QString& v ) { m_unwantedMPlayerOptions = v; }
+ void setLoopPlaylist( int v ) { m_loopPlaylist = v; }
+ void setNoDma( bool b ) { m_noDma = b; }
+
+ signals:
+ void newMovixFileItems();
+ void movixItemRemoved( K3bMovixFileItem* );
+ void subTitleItemRemoved( K3bMovixFileItem* );
+
+ public slots:
+ void addUrls( const KURL::List& urls );
+ void addMovixFile( const KURL& url, int pos = -1 );
+ void moveMovixItem( K3bMovixFileItem* item, K3bMovixFileItem* itemAfter );
+ void addSubTitleItem( K3bMovixFileItem*, const KURL& );
+ void removeSubTitleItem( K3bMovixFileItem* );
+
+ protected:
+ /** reimplemented from K3bDoc */
+ bool loadDocumentData( QDomElement* root );
+ /** reimplemented from K3bDoc */
+ bool saveDocumentData( QDomElement* );
+
+ virtual QString typeString() const { return "movix"; }
+
+ private slots:
+ void slotDataItemRemoved( K3bDataItem* );
+
+ private:
+ QPtrList<K3bMovixFileItem> m_movixFiles;
+
+ bool m_shutdown;
+ bool m_reboot;
+ bool m_ejectDisk;
+ bool m_randomPlay;
+ QString m_subtitleFontset;
+ QString m_bootMessageLanguage;
+ QString m_audioBackground;
+ QString m_keyboardLayout;
+ QStringList m_codecs;
+ QString m_defaultBootLabel;
+ QString m_additionalMPlayerOptions;
+ QString m_unwantedMPlayerOptions;
+ int m_loopPlaylist;
+ bool m_noDma;
+};
+
+#endif
diff --git a/libk3b/projects/movixcd/k3bmovixdocpreparer.cpp b/libk3b/projects/movixcd/k3bmovixdocpreparer.cpp
new file mode 100644
index 0000000..57e18af
--- /dev/null
+++ b/libk3b/projects/movixcd/k3bmovixdocpreparer.cpp
@@ -0,0 +1,490 @@
+/*
+ *
+ * $Id: k3bmovixdocpreparer.cpp 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+#include "k3bmovixdocpreparer.h"
+#include "k3bmovixdoc.h"
+#include "k3bmovixprogram.h"
+#include "k3bmovixfileitem.h"
+
+
+#include <k3bcore.h>
+#include <k3bdiritem.h>
+#include <k3bfileitem.h>
+#include <k3bbootitem.h>
+#include <k3bexternalbinmanager.h>
+#include <k3bisoimager.h>
+
+#include <klocale.h>
+#include <kdebug.h>
+#include <ktempfile.h>
+#include <kio/global.h>
+
+#include <qtextstream.h>
+#include <qdir.h>
+
+
+class K3bMovixDocPreparer::Private
+{
+public:
+ Private()
+ : doc(0),
+ playlistFile(0),
+ isolinuxConfigFile(0),
+ movixRcFile(0),
+ isolinuxDir(0),
+ movixDir(0),
+ mplayerDir(0),
+ playlistFileItem(0),
+ structuresCreated(false) {
+ }
+
+ K3bMovixDoc* doc;
+ const K3bMovixBin* eMovixBin;
+
+ KTempFile* playlistFile;
+ KTempFile* isolinuxConfigFile;
+ KTempFile* movixRcFile;
+
+ K3bDirItem* isolinuxDir;
+ K3bDirItem* movixDir;
+ K3bDirItem* mplayerDir;
+ K3bFileItem* playlistFileItem;
+
+ QPtrList<K3bDataItem> newMovixItems;
+
+ bool structuresCreated;
+};
+
+
+K3bMovixDocPreparer::K3bMovixDocPreparer( K3bMovixDoc* doc, K3bJobHandler* jh, QObject* parent, const char* name )
+ : K3bJob( jh, parent, name )
+{
+ d = new Private();
+ d->doc = doc;
+}
+
+
+K3bMovixDocPreparer::~K3bMovixDocPreparer()
+{
+ removeMovixStructures();
+ delete d;
+}
+
+
+K3bMovixDoc* K3bMovixDocPreparer::doc() const
+{
+ return d->doc;
+}
+
+
+void K3bMovixDocPreparer::start()
+{
+ kdDebug() << k_funcinfo << endl;
+ jobStarted();
+
+ bool success = true;
+ if( d->structuresCreated )
+ removeMovixStructures();
+ else
+ success = createMovixStructures();
+
+ jobFinished(success);
+}
+
+
+void K3bMovixDocPreparer::cancel()
+{
+ // do nothing...
+}
+
+
+bool K3bMovixDocPreparer::createMovixStructures()
+{
+ kdDebug() << k_funcinfo << endl;
+ removeMovixStructures();
+
+ if( doc() ) {
+ doc()->setMultiSessionMode( K3bDataDoc::NONE );
+ doc()->prepareFilenames();
+ }
+
+ d->eMovixBin = dynamic_cast<const K3bMovixBin*>( k3bcore->externalBinManager()->binObject("eMovix") );
+ if( d->eMovixBin ) {
+ bool success = false;
+ if( d->eMovixBin->version >= K3bVersion( 0, 9, 0 ) )
+ success = addMovixFilesNew();
+ else
+ success = addMovixFiles();
+
+ d->structuresCreated = success;
+ return success;
+ }
+ else {
+ emit infoMessage( i18n("Could not find a valid eMovix installation."), ERROR );
+ return false;
+ }
+}
+
+
+void K3bMovixDocPreparer::removeMovixStructures()
+{
+ kdDebug() << k_funcinfo << endl;
+ // remove movix files from doc
+ // the dataitems do the cleanup in the doc
+ delete d->movixDir;
+ delete d->isolinuxDir;
+ delete d->mplayerDir;
+ delete d->playlistFileItem;
+
+ d->movixDir = 0;
+ d->isolinuxDir = 0;
+ d->mplayerDir = 0;
+ d->playlistFileItem = 0;
+
+ d->newMovixItems.setAutoDelete( true );
+ d->newMovixItems.clear();
+
+ // remove all the temp files
+ delete d->playlistFile;
+ delete d->isolinuxConfigFile;
+ delete d->movixRcFile;
+
+ d->playlistFile = 0;
+ d->isolinuxConfigFile = 0;
+ d->movixRcFile = 0;
+
+ d->structuresCreated = false;
+}
+
+
+bool K3bMovixDocPreparer::writePlaylistFile()
+{
+ delete d->playlistFile;
+ d->playlistFile = new KTempFile();
+ d->playlistFile->setAutoDelete(true);
+
+ if( QTextStream* s = d->playlistFile->textStream() ) {
+
+ const QPtrList<K3bMovixFileItem>& movixFileItems = d->doc->movixFileItems();
+
+ for( QPtrListIterator<K3bMovixFileItem> it( movixFileItems );
+ *it; ++it ) {
+ *s << "/cdrom/";
+ *s << it.current()->writtenName();
+ *s << endl;
+ }
+
+ d->playlistFile->close();
+ return true;
+ }
+ else {
+ emit infoMessage( i18n("Could not write to temporary file %1").arg(d->playlistFile->name()), ERROR );
+ return false;
+ }
+}
+
+
+bool K3bMovixDocPreparer::writeIsolinuxConfigFile( const QString& originalPath )
+{
+ delete d->isolinuxConfigFile;
+ d->isolinuxConfigFile = new KTempFile();
+ d->isolinuxConfigFile->setAutoDelete(true);
+
+ if( QTextStream* s = d->isolinuxConfigFile->textStream() ) {
+
+ // now open the default isolinux.cfg and copy everything except the first line which contains
+ // the default boot label
+ QFile f( originalPath );
+ if( f.open( IO_ReadOnly ) ) {
+
+ QTextStream isolinuxConfigOrig( &f );
+
+ if( d->doc->defaultBootLabel() != i18n("default") ) {
+ isolinuxConfigOrig.readLine(); // skip first line
+ *s << "default " << d->doc->defaultBootLabel() << endl;
+ }
+
+ QString line = isolinuxConfigOrig.readLine();
+ while( !line.isNull() ) {
+ *s << line << endl;
+ line = isolinuxConfigOrig.readLine();
+ }
+
+ d->isolinuxConfigFile->close();
+ return true;
+ }
+ else
+ return false;
+ }
+ else {
+ emit infoMessage( i18n("Could not write to temporary file %1").arg(d->isolinuxConfigFile->name()), ERROR );
+ return false;
+ }
+}
+
+
+bool K3bMovixDocPreparer::writeMovixRcFile()
+{
+ delete d->movixRcFile;
+ d->movixRcFile = new KTempFile();
+ d->movixRcFile->setAutoDelete(true);
+
+ if( QTextStream* s = d->movixRcFile->textStream() ) {
+
+ if( !d->doc->additionalMPlayerOptions().isEmpty() )
+ *s << "extra-mplayer-options=" << d->doc->additionalMPlayerOptions() << endl;
+ if( !d->doc->unwantedMPlayerOptions().isEmpty() )
+ *s << "unwanted-mplayer-options=" << d->doc->unwantedMPlayerOptions() << endl;
+ *s << "loop=" << d->doc->loopPlaylist() << endl;
+ if( d->doc->shutdown() )
+ *s << "shut=y" << endl;
+ if( d->doc->reboot() )
+ *s << "reboot=y" << endl;
+ if( d->doc->ejectDisk() )
+ *s << "eject=y" << endl;
+ if( d->doc->randomPlay() )
+ *s << "random=y" << endl;
+ if( d->doc->noDma() )
+ *s << "dma=n" << endl;
+
+ d->movixRcFile->close();
+ return true;
+ }
+ else {
+ emit infoMessage( i18n("Could not write to temporary file %1").arg(d->movixRcFile->name()), ERROR );
+ return false;
+ }
+}
+
+
+bool K3bMovixDocPreparer::addMovixFiles()
+{
+ // first of all we create the directories
+ d->isolinuxDir = new K3bDirItem( "isolinux", d->doc, d->doc->root() );
+ d->movixDir = new K3bDirItem( "movix", d->doc, d->doc->root() );
+ K3bDirItem* kernelDir = d->doc->addEmptyDir( "kernel", d->isolinuxDir );
+
+ // add the linux kernel
+ (void)new K3bFileItem( d->eMovixBin->path + "/isolinux/kernel/vmlinuz", d->doc, kernelDir );
+
+ // add the boot image
+ K3bBootItem* bootItem = d->doc->createBootItem( d->eMovixBin->path + "/isolinux/isolinux.bin",
+ d->isolinuxDir );
+ bootItem->setImageType( K3bBootItem::NONE );
+ bootItem->setLoadSize( 4 );
+ bootItem->setBootInfoTable(true);
+
+ // some sort weights as defined in isolinux
+ d->isolinuxDir->setSortWeight( 100 );
+ kernelDir->setSortWeight( 50 );
+ bootItem->setSortWeight( 200 );
+
+ // rename the boot catalog file
+ d->doc->bootCataloge()->setK3bName( "isolinux.boot" );
+
+ // the following sucks! Redesign it!
+
+ // add all the isolinux files
+ QStringList isolinuxFiles = d->eMovixBin->isolinuxFiles();
+ isolinuxFiles.remove( "isolinux.bin" );
+ isolinuxFiles.remove( "isolinux.cfg" );
+ isolinuxFiles.remove( "kernel/vmlinuz" );
+ for( QStringList::const_iterator it = isolinuxFiles.begin();
+ it != isolinuxFiles.end(); ++it ) {
+ QString path = d->eMovixBin->path + "/isolinux/" + *it;
+ (void)new K3bFileItem( path, d->doc, d->isolinuxDir );
+ }
+
+ const QStringList& movixFiles = d->eMovixBin->movixFiles();
+ for( QStringList::const_iterator it = movixFiles.begin();
+ it != movixFiles.end(); ++it ) {
+ QString path = d->eMovixBin->path + "/movix/" + *it;
+ (void)new K3bFileItem( path, d->doc, d->movixDir );
+ }
+
+ // add doku files
+ QString path = d->eMovixBin->languageDir( d->doc->bootMessageLanguage() );
+ QDir dir(path);
+ QStringList helpFiles = dir.entryList(QDir::Files);
+ for( QStringList::const_iterator it = helpFiles.begin();
+ it != helpFiles.end(); ++it ) {
+ // some emovix installations include backup-files, no one's perfect ;)
+ if( !(*it).endsWith( "~" ) )
+ (void)new K3bFileItem( path + "/" + *it, d->doc, d->isolinuxDir );
+ }
+
+
+ // add subtitle font dir
+ if( !d->doc->subtitleFontset().isEmpty() &&
+ d->doc->subtitleFontset() != i18n("none") ) {
+ d->mplayerDir = new K3bDirItem( "mplayer", d->doc, d->doc->root() );
+
+ QString fontPath = d->eMovixBin->subtitleFontDir( d->doc->subtitleFontset() );
+ QFileInfo fontType( fontPath );
+ if( fontType.isDir() ) {
+ K3bDirItem* fontDir = new K3bDirItem( "font", d->doc, d->mplayerDir );
+ QDir dir( fontPath );
+ QStringList fontFiles = dir.entryList( QDir::Files );
+ for( QStringList::const_iterator it = fontFiles.begin();
+ it != fontFiles.end(); ++it ) {
+ (void)new K3bFileItem( fontPath + "/" + *it, d->doc, fontDir );
+ }
+ }
+ else {
+ // just a ttf file
+ // needs to be named: subfont.ttf and needs to be placed in mplayer/
+ // instead of mplayer/font
+ (void)new K3bFileItem( fontPath,
+ d->doc,
+ d->mplayerDir,
+ "subfont.ttf" );
+ }
+ }
+
+
+ // add movix-config-file and boot-config file
+ if( writeMovixRcFile() &&
+ writeIsolinuxConfigFile( d->eMovixBin->path + "/isolinux/isolinux.cfg" ) &&
+ writePlaylistFile() ) {
+
+ (void)new K3bFileItem( d->movixRcFile->name(), d->doc, d->movixDir, "movixrc" );
+ (void)new K3bFileItem( d->isolinuxConfigFile->name(), d->doc, d->isolinuxDir, "isolinux.cfg" );
+ d->playlistFileItem = new K3bFileItem( d->playlistFile->name(), d->doc, d->doc->root(), "movix.list" );
+
+ return true;
+ }
+ else
+ return false;
+}
+
+
+bool K3bMovixDocPreparer::addMovixFilesNew()
+{
+ // 1. get a list of files from the movixbin
+ // 2. create file items (replace isolinux.cfg with the one created above)
+ // 3. add movixrc and movix.list files
+ // 4. set weights for isolinux files
+
+ // FIXME: use the settings from the doc
+ QStringList files = d->eMovixBin->files( d->doc->keyboardLayout(),
+ d->doc->subtitleFontset(),
+ d->doc->audioBackground(),
+ d->doc->bootMessageLanguage(),
+ "all" /*d->doc->codecs()*/ ); // for now we simply don't allow selection
+
+ for( QStringList::iterator it = files.begin(); it != files.end(); ++it ) {
+ QString docPath = (*it).section( ' ', 0, 0 );
+ QString filePath = (*it).section( ' ', 1, 1 );
+ QString fileName = filePath.section( '/', -1 );
+
+ if( fileName == "isolinux.cfg" ) {
+ // replace the local file with our modified one
+ if( writeIsolinuxConfigFile( filePath ) )
+ createItem( d->isolinuxConfigFile->name(), docPath )->setK3bName( "isolinux.cfg" );
+ else
+ return false;
+ }
+ else if( fileName == "isolinux.bin" ) {
+ // create boot item (no need to remember this since it's in a dir which will be removed
+ // anyway)
+ K3bBootItem* bootItem = d->doc->createBootItem( filePath, createDir(docPath) );
+ bootItem->setImageType( K3bBootItem::NONE );
+ bootItem->setLoadSize( 4 );
+ bootItem->setBootInfoTable(true);
+
+ // set the proper sort weight
+ bootItem->setSortWeight( 200 );
+ bootItem->parent()->setSortWeight( 100 );
+ }
+ else if( fileName != "movixrc" ) { // we create our own movixrc
+ K3bFileItem* item = createItem( filePath, docPath );
+
+ // Truetype subtitle fonts needs to be named subfont.ttf
+ if( fileName == d->doc->subtitleFontset() + ".ttf" ) {
+ item->setK3bName( "subfont.ttf" );
+ }
+ else if( fileName == "vmlinuz" )
+ item->setSortWeight( 50 );
+ }
+ }
+
+ // Some distributions (such as Gentoo for example) do use the win32codecs package instead of the
+ // eMovix supplied codecs. These codecs are not picked up by the movix-conf script
+ K3bDirItem* codecDir = dynamic_cast<K3bDirItem*>( d->doc->root()->findByPath( "/eMoviX/codecs" ) );
+ if( !codecDir || codecDir->isEmpty() ) {
+ QDir localCodecDir( d->eMovixBin->movixDataDir() + "/codecs" );
+ if( localCodecDir.exists() ) {
+ QStringList codecFiles = localCodecDir.entryList( QDir::Files );
+ for( QStringList::const_iterator it = codecFiles.begin(); it != codecFiles.end(); ++it )
+ createItem( localCodecDir.path() + '/' + *it, "/eMoviX/codecs" );
+ }
+ }
+
+ if( writePlaylistFile() && writeMovixRcFile() ) {
+ // add the two items that are not listed by the script
+ createItem( d->movixRcFile->name(), "/eMoviX/movix" )->setK3bName( "movixrc" );
+ createItem( d->playlistFile->name(), "/" )->setK3bName( "movix.list" );
+ return true;
+ }
+ else
+ return false;
+}
+
+
+K3bFileItem* K3bMovixDocPreparer::createItem( const QString& localPath, const QString& docPath )
+{
+ // make sure the path in the doc exists
+ K3bDirItem* dir = createDir( docPath );
+
+ // create the file in dir
+ K3bFileItem* item = new K3bFileItem( localPath, d->doc, dir );
+
+ // remember the item to remove it becasue the dir cannot be removed
+ if( dir == d->doc->root() )
+ d->newMovixItems.append( item );
+
+ return item;
+}
+
+
+K3bDirItem* K3bMovixDocPreparer::createDir( const QString& docPath )
+{
+ QStringList docPathSections = QStringList::split( '/', docPath );
+ K3bDirItem* dir = d->doc->root();
+ for( QStringList::iterator it = docPathSections.begin(); it != docPathSections.end(); ++it ) {
+ K3bDataItem* next = dir->find( *it );
+ if( !next )
+ dir = new K3bDirItem( *it, d->doc, dir );
+ else if( next->isDir() )
+ dir = static_cast<K3bDirItem*>( next );
+ else {
+ kdError() << "(K3bMovixDocPreparer) found non-dir item where a dir was needed." << endl;
+ return 0;
+ }
+ }
+
+ // remember the dir to remove it
+ if( dir != d->doc->root() ) {
+ K3bDirItem* delDir = dir;
+ while( delDir->parent() != d->doc->root() )
+ delDir = delDir->parent();
+ if( d->newMovixItems.findRef( delDir ) == -1 )
+ d->newMovixItems.append( delDir );
+ }
+
+ return dir;
+}
+
+#include "k3bmovixdocpreparer.moc"
diff --git a/libk3b/projects/movixcd/k3bmovixdocpreparer.h b/libk3b/projects/movixcd/k3bmovixdocpreparer.h
new file mode 100644
index 0000000..3844eae
--- /dev/null
+++ b/libk3b/projects/movixcd/k3bmovixdocpreparer.h
@@ -0,0 +1,67 @@
+/*
+ *
+ * $Id: k3bmovixdocpreparer.h 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+#ifndef _K3B_MOVIX_DOC_PREPARER_H_
+#define _K3B_MOVIX_DOC_PREPARER_H_
+
+#include <k3bjob.h>
+
+class K3bMovixDoc;
+class K3bFileItem;
+class K3bDirItem;
+
+
+/**
+ * This class creates the needed eMovix structures in an eMovix doc
+ * and removes them after creating the image.
+ */
+class K3bMovixDocPreparer : public K3bJob
+{
+ Q_OBJECT
+
+ public:
+ explicit K3bMovixDocPreparer( K3bMovixDoc* doc, K3bJobHandler*, QObject* parent = 0, const char* name = 0 );
+ ~K3bMovixDocPreparer();
+
+ K3bMovixDoc* doc() const;
+
+ bool createMovixStructures();
+ void removeMovixStructures();
+
+ public slots:
+ /**
+ * use createMovixStructures and removeMovixStructures instead.
+ */
+ void start();
+
+ /**
+ * Useless since this job works syncronously
+ */
+ void cancel();
+
+ private:
+ bool writePlaylistFile();
+ bool writeIsolinuxConfigFile( const QString& );
+ bool writeMovixRcFile();
+ bool addMovixFiles();
+ bool addMovixFilesNew();
+ K3bFileItem* createItem( const QString& localPath, const QString& docPath );
+ K3bDirItem* createDir( const QString& docPath );
+
+ class Private;
+ Private* d;
+};
+
+#endif
diff --git a/libk3b/projects/movixcd/k3bmovixfileitem.cpp b/libk3b/projects/movixcd/k3bmovixfileitem.cpp
new file mode 100644
index 0000000..12803a2
--- /dev/null
+++ b/libk3b/projects/movixcd/k3bmovixfileitem.cpp
@@ -0,0 +1,68 @@
+/*
+ *
+ * $Id: k3bmovixfileitem.cpp 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+
+#include "k3bmovixfileitem.h"
+#include "k3bmovixdoc.h"
+
+#include <k3bdiritem.h>
+
+
+K3bMovixFileItem::K3bMovixFileItem( const QString& fileName,
+ K3bMovixDoc* doc,
+ K3bDirItem* dir,
+ const QString& k3bName )
+ : K3bFileItem( fileName, doc, dir, k3bName ),
+ m_doc(doc),
+ m_subTitleItem(0)
+{
+}
+
+
+K3bMovixFileItem::~K3bMovixFileItem()
+{
+ if( m_subTitleItem )
+ m_doc->removeSubTitleItem( this );
+
+ // remove this from parentdir
+ // it is important to do it here and not
+ // rely on the K3bFileItem destructor becasue
+ // otherwise the doc is not informed early enough
+ if( parent() )
+ parent()->takeDataItem( this );
+}
+
+
+void K3bMovixFileItem::setK3bName( const QString& newName )
+{
+ K3bFileItem::setK3bName( newName );
+
+ // take care of the subTitle file
+ if( m_subTitleItem ) {
+ m_subTitleItem->setK3bName( subTitleFileName(k3bName()) );
+ }
+}
+
+
+QString K3bMovixFileItem::subTitleFileName( const QString& name )
+{
+ // remove ending from k3bName
+ QString subName = name;
+ int pos = subName.findRev(".");
+ if( pos > 0 )
+ subName.truncate( pos );
+ subName += ".sub";
+ return subName;
+}
diff --git a/libk3b/projects/movixcd/k3bmovixfileitem.h b/libk3b/projects/movixcd/k3bmovixfileitem.h
new file mode 100644
index 0000000..343f00b
--- /dev/null
+++ b/libk3b/projects/movixcd/k3bmovixfileitem.h
@@ -0,0 +1,52 @@
+/*
+ *
+ * $Id: k3bmovixfileitem.h 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+
+#ifndef _K3B_MOVIX_FILEITEM_H_
+#define _K3B_MOVIX_FILEITEM_H_
+
+#include <k3bfileitem.h>
+
+class K3bMovixDoc;
+
+
+class K3bMovixFileItem : public K3bFileItem
+{
+ public:
+ K3bMovixFileItem( const QString& fileName, K3bMovixDoc* doc, K3bDirItem* dir, const QString& k3bName = 0 );
+ ~K3bMovixFileItem();
+
+ K3bFileItem* subTitleItem() const { return m_subTitleItem; }
+ void setSubTitleItem( K3bFileItem* i ) { m_subTitleItem = i; }
+
+ /**
+ * reimplemented from K3bDataItem
+ * also renames the subTitleItem
+ */
+ void setK3bName( const QString& );
+
+ /**
+ * returnes the name that the subtitle file must have in
+ * order to work with mplayer
+ */
+ static QString subTitleFileName( const QString& );
+
+ private:
+ K3bMovixDoc* m_doc;
+
+ K3bFileItem* m_subTitleItem;
+};
+
+#endif
diff --git a/libk3b/projects/movixcd/k3bmovixjob.cpp b/libk3b/projects/movixcd/k3bmovixjob.cpp
new file mode 100644
index 0000000..2579453
--- /dev/null
+++ b/libk3b/projects/movixcd/k3bmovixjob.cpp
@@ -0,0 +1,132 @@
+/*
+ *
+ * $Id: k3bmovixjob.cpp 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+
+#include "k3bmovixjob.h"
+#include "k3bmovixdoc.h"
+#include "k3bmovixfileitem.h"
+#include "k3bmovixdocpreparer.h"
+
+#include <k3bcore.h>
+#include <k3bdatajob.h>
+#include <k3bdevice.h>
+
+#include <klocale.h>
+#include <kdebug.h>
+
+
+K3bMovixJob::K3bMovixJob( K3bMovixDoc* doc, K3bJobHandler* jh, QObject* parent )
+ : K3bBurnJob( jh, parent ),
+ m_doc(doc)
+{
+ m_dataJob = new K3bDataJob( doc, this, this );
+ m_movixDocPreparer = new K3bMovixDocPreparer( doc, this, this );
+
+ // pipe signals
+ connect( m_dataJob, SIGNAL(percent(int)), this, SIGNAL(percent(int)) );
+ connect( m_dataJob, SIGNAL(subPercent(int)), this, SIGNAL(subPercent(int)) );
+ connect( m_dataJob, SIGNAL(processedSubSize(int, int)), this, SIGNAL(processedSubSize(int, int)) );
+ connect( m_dataJob, SIGNAL(processedSize(int, int)), this, SIGNAL(processedSize(int, int)) );
+ connect( m_dataJob, SIGNAL(bufferStatus(int)), this, SIGNAL(bufferStatus(int)) );
+ connect( m_dataJob, SIGNAL(deviceBuffer(int)), this, SIGNAL(deviceBuffer(int)) );
+ connect( m_dataJob, SIGNAL(writeSpeed(int, int)), this, SIGNAL(writeSpeed(int, int)) );
+ connect( m_dataJob, SIGNAL(newTask(const QString&)), this, SIGNAL(newTask(const QString&)) );
+ connect( m_dataJob, SIGNAL(newSubTask(const QString&)), this, SIGNAL(newSubTask(const QString&)) );
+ connect( m_dataJob, SIGNAL(debuggingOutput(const QString&, const QString&)),
+ this, SIGNAL(debuggingOutput(const QString&, const QString&)) );
+ connect( m_dataJob, SIGNAL(infoMessage(const QString&, int)),
+ this, SIGNAL(infoMessage(const QString&, int)) );
+ connect( m_dataJob, SIGNAL(burning(bool)), this, SIGNAL(burning(bool)) );
+
+ // we need to clean up here
+ connect( m_dataJob, SIGNAL(finished(bool)), this, SLOT(slotDataJobFinished(bool)) );
+
+ connect( m_movixDocPreparer, SIGNAL(infoMessage(const QString&, int)),
+ this, SIGNAL(infoMessage(const QString&, int)) );
+}
+
+
+K3bMovixJob::~K3bMovixJob()
+{
+}
+
+
+K3bDevice::Device* K3bMovixJob::writer() const
+{
+ return m_dataJob->writer();
+}
+
+
+K3bDoc* K3bMovixJob::doc() const
+{
+ return m_doc;
+}
+
+
+void K3bMovixJob::start()
+{
+ jobStarted();
+
+ m_canceled = false;
+ m_dataJob->setWritingApp( writingApp() );
+
+ if( m_movixDocPreparer->createMovixStructures() ) {
+ m_dataJob->start();
+ }
+ else {
+ m_movixDocPreparer->removeMovixStructures();
+ jobFinished(false);
+ }
+}
+
+
+void K3bMovixJob::cancel()
+{
+ m_canceled = true;
+ m_dataJob->cancel();
+}
+
+
+void K3bMovixJob::slotDataJobFinished( bool success )
+{
+ m_movixDocPreparer->removeMovixStructures();
+
+ if( m_canceled || m_dataJob->hasBeenCanceled() )
+ emit canceled();
+
+ jobFinished( success );
+}
+
+
+QString K3bMovixJob::jobDescription() const
+{
+ if( m_doc->isoOptions().volumeID().isEmpty() )
+ return i18n("Writing eMovix CD");
+ else
+ return i18n("Writing eMovix CD (%1)").arg(m_doc->isoOptions().volumeID());
+}
+
+
+QString K3bMovixJob::jobDetails() const
+{
+ return ( i18n("1 file (%1) and about 8 MB eMovix data",
+ "%n files (%1) and about 8 MB eMovix data",
+ m_doc->movixFileItems().count()).arg(KIO::convertSize(m_doc->size()))
+ + ( m_doc->copies() > 1
+ ? i18n(" - %n copy", " - %n copies", m_doc->copies())
+ : QString::null ) );
+}
+
+#include "k3bmovixjob.moc"
diff --git a/libk3b/projects/movixcd/k3bmovixjob.h b/libk3b/projects/movixcd/k3bmovixjob.h
new file mode 100644
index 0000000..81dea8e
--- /dev/null
+++ b/libk3b/projects/movixcd/k3bmovixjob.h
@@ -0,0 +1,60 @@
+/*
+ *
+ * $Id: k3bmovixjob.h 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+
+#ifndef _K3B_MOVIX_JOB_H_
+#define _K3B_MOVIX_JOB_H_
+
+#include <k3bjob.h>
+
+class K3bMovixDoc;
+class K3bDevice::Device;
+class K3bDataJob;
+class KTempFile;
+class K3bMovixInstallation;
+class K3bMovixDocPreparer;
+class K3bDirItem;
+class K3bFileItem;
+
+class K3bMovixJob : public K3bBurnJob
+{
+ Q_OBJECT
+
+ public:
+ K3bMovixJob( K3bMovixDoc* doc, K3bJobHandler*, QObject* parent = 0 );
+ ~K3bMovixJob();
+
+ K3bDoc* doc() const;
+ K3bDevice::Device* writer() const;
+
+ QString jobDescription() const;
+ QString jobDetails() const;
+
+ public slots:
+ void start();
+ void cancel();
+
+ private slots:
+ void slotDataJobFinished( bool );
+
+ private:
+ K3bMovixDoc* m_doc;
+ K3bDataJob* m_dataJob;
+ K3bMovixDocPreparer* m_movixDocPreparer;
+
+ bool m_canceled;
+};
+
+#endif
diff --git a/libk3b/projects/movixcd/k3bmovixprogram.cpp b/libk3b/projects/movixcd/k3bmovixprogram.cpp
new file mode 100644
index 0000000..8720e8d
--- /dev/null
+++ b/libk3b/projects/movixcd/k3bmovixprogram.cpp
@@ -0,0 +1,339 @@
+/*
+ *
+ * $Id: k3bmovixprogram.cpp 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+
+#include "k3bmovixprogram.h"
+
+#include <k3bprocess.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+
+#include <qdir.h>
+#include <qfile.h>
+#include <qtextstream.h>
+
+
+K3bMovixProgram::K3bMovixProgram()
+ : K3bExternalProgram( "eMovix" )
+{
+}
+
+bool K3bMovixProgram::scan( const QString& p )
+{
+ if( p.isEmpty() )
+ return false;
+
+ QString path = p;
+ if( path[path.length()-1] != '/' )
+ path.append("/");
+
+ // first test if we have a version info (eMovix >= 0.8.0pre3)
+ if( !QFile::exists( path + "movix-version" ) )
+ return false;
+
+ K3bMovixBin* bin = 0;
+
+ //
+ // probe version and data dir
+ //
+ KProcess vp, dp;
+ vp << path + "movix-version";
+ dp << path + "movix-conf";
+ K3bProcessOutputCollector vout( &vp ), dout( &dp );
+ if( vp.start( KProcess::Block, KProcess::AllOutput ) && dp.start( KProcess::Block, KProcess::AllOutput ) ) {
+ // movix-version just gives us the version number on stdout
+ if( !vout.output().isEmpty() && !dout.output().isEmpty() ) {
+ bin = new K3bMovixBin( this );
+ bin->version = vout.output().stripWhiteSpace();
+ bin->path = path;
+ bin->m_movixPath = dout.output().stripWhiteSpace();
+ }
+ }
+ else {
+ kdDebug() << "(K3bMovixProgram) could not start " << path << "movix-version" << endl;
+ return false;
+ }
+
+ if( bin->version >= K3bVersion( 0, 9, 0 ) )
+ return scanNewEMovix( bin, path );
+ else
+ return scanOldEMovix( bin, path );
+}
+
+
+bool K3bMovixProgram::scanNewEMovix( K3bMovixBin* bin, const QString& path )
+{
+ QStringList files = bin->files();
+ for( QStringList::iterator it = files.begin();
+ it != files.end(); ++it ) {
+ if( (*it).contains( "isolinux.cfg" ) ) {
+ bin->m_supportedBootLabels = determineSupportedBootLabels( QStringList::split( " ", *it )[1] );
+ break;
+ }
+ }
+
+ // here we simply check for the movix-conf program
+ if( QFile::exists( path + "movix-conf" ) ) {
+ bin->addFeature( "newfiles" );
+ addBin(bin);
+ return true;
+ }
+ else {
+ delete bin;
+ return false;
+ }
+}
+
+
+bool K3bMovixProgram::scanOldEMovix( K3bMovixBin* bin, const QString& path )
+{
+ //
+ // first check if all necessary directories are present
+ //
+ QDir dir( bin->movixDataDir() );
+ QStringList subdirs = dir.entryList( QDir::Dirs );
+ if( !subdirs.contains( "boot-messages" ) ) {
+ kdDebug() << "(K3bMovixProgram) could not find subdir 'boot-messages'" << endl;
+ delete bin;
+ return false;
+ }
+ if( !subdirs.contains( "isolinux" ) ) {
+ kdDebug() << "(K3bMovixProgram) could not find subdir 'isolinux'" << endl;
+ delete bin;
+ return false;
+ }
+ if( !subdirs.contains( "movix" ) ) {
+ kdDebug() << "(K3bMovixProgram) could not find subdir 'movix'" << endl;
+ delete bin;
+ return false;
+ }
+ if( !subdirs.contains( "mplayer-fonts" ) ) {
+ kdDebug() << "(K3bMovixProgram) could not find subdir 'mplayer-fonts'" << endl;
+ delete bin;
+ return false;
+ }
+
+
+ //
+ // check if we have a version of eMovix which contains the movix-files script
+ //
+ if( QFile::exists( path + "movix-files" ) ) {
+ bin->addFeature( "files" );
+
+ KProcess p;
+ K3bProcessOutputCollector out( &p );
+ p << bin->path + "movix-files";
+ if( p.start( KProcess::Block, KProcess::AllOutput ) ) {
+ bin->m_movixFiles = QStringList::split( "\n", out.output() );
+ }
+ }
+
+ //
+ // fallback: to be compatible with 0.8.0rc2 we just add all files in the movix directory
+ //
+ if( bin->m_movixFiles.isEmpty() ) {
+ QDir dir( bin->movixDataDir() + "/movix" );
+ bin->m_movixFiles = dir.entryList(QDir::Files);
+ }
+
+ //
+ // these files are fixed. That should not be a problem
+ // since Isolinux is quite stable as far as I know.
+ //
+ bin->m_isolinuxFiles.append( "initrd.gz" );
+ bin->m_isolinuxFiles.append( "isolinux.bin" );
+ bin->m_isolinuxFiles.append( "isolinux.cfg" );
+ bin->m_isolinuxFiles.append( "kernel/vmlinuz" );
+ bin->m_isolinuxFiles.append( "movix.lss" );
+ bin->m_isolinuxFiles.append( "movix.msg" );
+
+
+ //
+ // check every single necessary file :(
+ //
+ for( QStringList::const_iterator it = bin->m_isolinuxFiles.begin();
+ it != bin->m_isolinuxFiles.end(); ++it ) {
+ if( !QFile::exists( bin->movixDataDir() + "/isolinux/" + *it ) ) {
+ kdDebug() << "(K3bMovixProgram) Could not find file " << *it << endl;
+ delete bin;
+ return false;
+ }
+ }
+
+ //
+ // now check the boot-messages languages
+ //
+ dir.cd( "boot-messages" );
+ bin->m_supportedLanguages = dir.entryList(QDir::Dirs);
+ bin->m_supportedLanguages.remove(".");
+ bin->m_supportedLanguages.remove("..");
+ bin->m_supportedLanguages.remove("CVS"); // the eMovix makefile stuff seems not perfect ;)
+ bin->m_supportedLanguages.prepend( i18n("default") );
+ dir.cdUp();
+
+ //
+ // now check the supported mplayer-fontsets
+ // FIXME: every font dir needs to contain the "font.desc" file!
+ //
+ dir.cd( "mplayer-fonts" );
+ bin->m_supportedSubtitleFonts = dir.entryList( QDir::Dirs );
+ bin->m_supportedSubtitleFonts.remove(".");
+ bin->m_supportedSubtitleFonts.remove("..");
+ bin->m_supportedSubtitleFonts.remove("CVS"); // the eMovix makefile stuff seems not perfect ;)
+ // new ttf fonts in 0.8.0rc2
+ bin->m_supportedSubtitleFonts += dir.entryList( "*.ttf", QDir::Files );
+ bin->m_supportedSubtitleFonts.prepend( i18n("none") );
+ dir.cdUp();
+
+ //
+ // now check the supported boot labels
+ //
+ dir.cd( "isolinux" );
+ bin->m_supportedBootLabels = determineSupportedBootLabels( dir.filePath("isolinux.cfg") );
+
+ //
+ // This seems to be a valid eMovix installation. :)
+ //
+
+ addBin(bin);
+ return true;
+}
+
+
+QStringList K3bMovixProgram::determineSupportedBootLabels( const QString& isoConfigFile ) const
+{
+ QStringList list( i18n("default") );
+
+ QFile f( isoConfigFile );
+ if( !f.open( IO_ReadOnly ) ) {
+ kdDebug() << "(K3bMovixProgram) could not open file '" << f.name() << "'" << endl;
+ }
+ else {
+ QTextStream fs( &f );
+ QString line = fs.readLine();
+ while( !line.isNull() ) {
+ if( line.startsWith( "label" ) )
+ list.append( line.mid( 5 ).stripWhiteSpace() );
+
+ line = fs.readLine();
+ }
+ f.close();
+ }
+
+ return list;
+}
+
+
+QString K3bMovixBin::subtitleFontDir( const QString& font ) const
+{
+ if( font == i18n("none" ) )
+ return "";
+ else if( m_supportedSubtitleFonts.contains( font ) )
+ return path + "/mplayer-fonts/" + font;
+ else
+ return "";
+}
+
+
+QString K3bMovixBin::languageDir( const QString& lang ) const
+{
+ if( lang == i18n("default") )
+ return languageDir( "en" );
+ else if( m_supportedLanguages.contains( lang ) )
+ return path + "/boot-messages/" + lang;
+ else
+ return "";
+}
+
+
+QStringList K3bMovixBin::supportedSubtitleFonts() const
+{
+ if( version >= K3bVersion( 0, 9, 0 ) )
+ return QStringList( i18n("default") ) += supported( "font" );
+ else
+ return m_supportedSubtitleFonts;
+}
+
+
+QStringList K3bMovixBin::supportedLanguages() const
+{
+ if( version >= K3bVersion( 0, 9, 0 ) )
+ return QStringList( i18n("default") ) += supported( "lang" );
+ else
+ return m_supportedLanguages;
+}
+
+
+// only used for eMovix >= 0.9.0
+QStringList K3bMovixBin::supportedKbdLayouts() const
+{
+ return QStringList( i18n("default") ) += supported( "kbd" );
+}
+
+
+// only used for eMovix >= 0.9.0
+QStringList K3bMovixBin::supportedBackgrounds() const
+{
+ return QStringList( i18n("default") ) += supported( "background" );
+}
+
+
+// only used for eMovix >= 0.9.0
+QStringList K3bMovixBin::supportedCodecs() const
+{
+ return supported( "codecs" );
+}
+
+
+QStringList K3bMovixBin::supported( const QString& type ) const
+{
+ KProcess p;
+ K3bProcessOutputCollector out( &p );
+ p << path + "movix-conf" << "--supported=" + type;
+ if( p.start( KProcess::Block, KProcess::AllOutput ) )
+ return QStringList::split( "\n", out.output() );
+ else
+ return QStringList();
+}
+
+
+QStringList K3bMovixBin::files( const QString& kbd,
+ const QString& font,
+ const QString& bg,
+ const QString& lang,
+ const QStringList& codecs ) const
+{
+ KProcess p;
+ K3bProcessOutputCollector out( &p );
+ p << path + "movix-conf" << "--files";
+
+
+ if( !kbd.isEmpty() && kbd != i18n("default") )
+ p << "--kbd" << kbd;
+ if( !font.isEmpty() && font != i18n("default") )
+ p << "--font" << font;
+ if( !bg.isEmpty() && bg != i18n("default") )
+ p << "--background" << bg;
+ if( !lang.isEmpty() && lang != i18n("default") )
+ p << "--lang" << lang;
+ if( !codecs.isEmpty() )
+ p << "--codecs" << codecs.join( "," );
+
+ if( p.start( KProcess::Block, KProcess::AllOutput ) )
+ return QStringList::split( "\n", out.output() );
+ else
+ return QStringList();
+}
diff --git a/libk3b/projects/movixcd/k3bmovixprogram.h b/libk3b/projects/movixcd/k3bmovixprogram.h
new file mode 100644
index 0000000..a6a9ac0
--- /dev/null
+++ b/libk3b/projects/movixcd/k3bmovixprogram.h
@@ -0,0 +1,103 @@
+/*
+ *
+ * $Id: k3bmovixprogram.h 619556 2007-01-03 17:38:12Z trueg $
+ * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This file is part of the K3b project.
+ * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * See the file "COPYING" for the exact licensing terms.
+ */
+
+#ifndef _K3B_MOVIX_PROGRAM_H_
+#define _K3B_MOVIX_PROGRAM_H_
+
+#include <k3bexternalbinmanager.h>
+#include "k3b_export.h"
+
+class LIBK3B_EXPORT K3bMovixBin : public K3bExternalBin
+{
+ public:
+ K3bMovixBin( K3bExternalProgram* p )
+ : K3bExternalBin( p ) {
+ }
+
+ const QString& movixDataDir() const { return m_movixPath; }
+
+ const QStringList& supportedBootLabels() const { return m_supportedBootLabels; }
+ QStringList supportedSubtitleFonts() const;
+ QStringList supportedLanguages() const;
+ QStringList supportedKbdLayouts() const;
+ QStringList supportedBackgrounds() const;
+ QStringList supportedCodecs() const;
+
+ /*
+ * Unused for eMovix versions 0.9.0 and above
+ */
+ const QStringList& movixFiles() const { return m_movixFiles; }
+
+ /*
+ * Unused for eMovix versions 0.9.0 and above
+ */
+ const QStringList& isolinuxFiles() const { return m_isolinuxFiles; }
+
+ /**
+ * returnes empty string if font was not found
+ *
+ * Unused for eMovix versions 0.9.0 and above
+ */
+ QString subtitleFontDir( const QString& font ) const;
+
+ /**
+ * returnes empty string if lang was not found
+ *
+ * Unused for eMovix versions 0.9.0 and above
+ */
+ QString languageDir( const QString& lang ) const;
+
+ /**
+ * Interface for the movix-conf --files interface for
+ * versions >= 0.9.0
+ */
+ QStringList files( const QString& kbd = QString::null,
+ const QString& font = QString::null,
+ const QString& bg = QString::null,
+ const QString& lang = QString::null,
+ const QStringList& codecs = QStringList() ) const;
+
+ private:
+ QStringList supported( const QString& ) const;
+
+ QString m_movixPath;
+ QStringList m_movixFiles;
+ QStringList m_isolinuxFiles;
+ QStringList m_supportedBootLabels;
+ QStringList m_supportedSubtitleFonts;
+ QStringList m_supportedLanguages;
+
+ friend class K3bMovixProgram;
+};
+
+
+class LIBK3B_EXPORT K3bMovixProgram : public K3bExternalProgram
+{
+ public:
+ K3bMovixProgram();
+
+ bool scan( const QString& );
+
+ bool supportsUserParameters() const { return false; }
+
+ private:
+ bool scanNewEMovix( K3bMovixBin* bin, const QString& );
+ bool scanOldEMovix( K3bMovixBin* bin, const QString& );
+ QStringList determineSupportedBootLabels( const QString& ) const;
+};
+
+
+
+#endif