From 50b48aec6ddd451a6d1709c0942477b503457663 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 3 Feb 2010 02:15:56 +0000 Subject: Added abandoned KDE3 version of K3B git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/k3b@1084400 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/rip/k3bvideocdinfo.cpp | 247 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 src/rip/k3bvideocdinfo.cpp (limited to 'src/rip/k3bvideocdinfo.cpp') diff --git a/src/rip/k3bvideocdinfo.cpp b/src/rip/k3bvideocdinfo.cpp new file mode 100644 index 0000000..ac30d40 --- /dev/null +++ b/src/rip/k3bvideocdinfo.cpp @@ -0,0 +1,247 @@ +/* +* +* $Id: k3bvideocdinfo.cpp 619556 2007-01-03 17:38:12Z trueg $ +* Copyright (C) 2003 Christian Kvasny +* +* This file is part of the K3b project. +* Copyright (C) 1998-2007 Sebastian Trueg +* +* 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 +#include +#include +#include +#include + +#include +#include +#include + +#include "k3bvideocdinfo.h" + +#include +#include + + +K3bVideoCdInfo::K3bVideoCdInfo( QObject* parent, const char* name ) + : QObject( parent, name ) +{ + m_process = 0L; + m_isXml = false; +} + + +K3bVideoCdInfo::~K3bVideoCdInfo() +{ + delete m_process; +} + +void K3bVideoCdInfo::cancelAll() +{ + if ( m_process->isRunning() ) { + m_process->disconnect( this ); + m_process->kill(); + } +} + +void K3bVideoCdInfo::info( const QString& device ) +{ + if ( !k3bcore ->externalBinManager() ->foundBin( "vcdxrip" ) ) { + kdDebug() << "(K3bVideoCdInfo::info) could not find vcdxrip executable" << endl; + emit infoFinished( false ); + return ; + } + + delete m_process; + m_process = new K3bProcess(); + + *m_process << k3bcore ->externalBinManager() ->binPath( "vcdxrip" ); + + *m_process << "-q" << "--norip" << "-i" << device << "-o" << "-"; + + connect( m_process, SIGNAL( receivedStderr( KProcess*, char*, int ) ), + this, SLOT( slotParseOutput( KProcess*, char*, int ) ) ); + connect( m_process, SIGNAL( receivedStdout( KProcess*, char*, int ) ), + this, SLOT( slotParseOutput( KProcess*, char*, int ) ) ); + connect( m_process, SIGNAL( processExited( KProcess* ) ), + this, SLOT( slotInfoFinished() ) ); + + if ( !m_process->start( KProcess::NotifyOnExit, KProcess::AllOutput ) ) { + kdDebug() << "(K3bVideoCdInfo::info) could not start vcdxrip" << endl; + cancelAll(); + emit infoFinished( false ); + } +} + +void K3bVideoCdInfo::slotParseOutput( KProcess*, char* output, int len ) +{ + QString buffer = QString::fromLocal8Bit( output, len ); + + // split to lines + QStringList lines = QStringList::split( "\n", buffer ); + QStringList::Iterator end( lines.end()); + for ( QStringList::Iterator str = lines.begin(); str != end; ++str ) { + + if ( ( *str ).contains( "" ) ) + m_isXml = false; + } +} + +void K3bVideoCdInfo::slotInfoFinished() +{ + if ( m_process->normalExit() ) { + // TODO: check the process' exitStatus() + switch ( m_process->exitStatus() ) { + case 0: + break; + default: + cancelAll(); + emit infoFinished( false ); + return ; + } + } else { + cancelAll(); + emit infoFinished( false ); + return ; + } + + if ( m_xmlData.isEmpty() ) { + emit infoFinished( false ); + return ; + } + + parseXmlData(); + emit infoFinished( true ); +} + +void K3bVideoCdInfo::parseXmlData() +{ + QDomDocument xml_doc; + QDomElement xml_root; + + m_Result.xmlData = m_xmlData; + + xml_doc.setContent( m_xmlData ); + xml_root = xml_doc.documentElement(); + + m_Result.type = xml_root.attribute( "class" ); + m_Result.version = xml_root.attribute( "version" ); + + for ( QDomNode node = xml_root.firstChild(); !node.isNull(); node = node.nextSibling() ) { + QDomElement el = node.toElement(); + QString tagName = el.tagName().lower(); + + if ( tagName == "pvd" ) { + for ( QDomNode snode = node.firstChild(); !snode.isNull(); snode = snode.nextSibling() ) { + QDomElement sel = snode.toElement(); + QString pvdElement = sel.tagName().lower(); + QString pvdElementText = sel.text(); + if ( pvdElement == "volume-id" ) + m_Result.volumeId = pvdElementText; + } + + } else if ( tagName == "sequence-items" ) { + for ( QDomNode snode = node.firstChild(); !snode.isNull(); snode = snode.nextSibling() ) { + QDomElement sel = snode.toElement(); + QString seqElement = sel.tagName().lower(); + m_Result.addEntry( K3bVideoCdInfoResultEntry( + sel.attribute( "src" ), + sel.attribute( "id" ) ), + K3bVideoCdInfoResult::SEQUENCE + ); + } + } else if ( tagName == "segment-items" ) { + for ( QDomNode snode = node.firstChild(); !snode.isNull(); snode = snode.nextSibling() ) { + QDomElement sel = snode.toElement(); + QString seqElement = sel.tagName().lower(); + m_Result.addEntry( K3bVideoCdInfoResultEntry( + sel.attribute( "src" ), + sel.attribute( "id" ) ), + K3bVideoCdInfoResult::SEGMENT + ); + } + } else { + kdDebug() << QString( "(K3bVideoCdInfo::parseXmlData) tagName '%1' not used" ).arg( tagName ) << endl; + } + } +} + +const K3bVideoCdInfoResult& K3bVideoCdInfo::result() const +{ + return m_Result; +} + +const K3bVideoCdInfoResultEntry& K3bVideoCdInfoResult::entry( unsigned int number, int type ) const +{ + switch ( type ) { + case K3bVideoCdInfoResult::FILE: + if ( number >= m_fileEntry.count() ) + return m_emptyEntry; + return m_fileEntry[ number ]; + case K3bVideoCdInfoResult::SEGMENT: + if ( number >= m_segmentEntry.count() ) + return m_emptyEntry; + return m_segmentEntry[ number ]; + case K3bVideoCdInfoResult::SEQUENCE: + if ( number >= m_sequenceEntry.count() ) + return m_emptyEntry; + return m_sequenceEntry[ number ]; + default: + kdDebug() << "(K3bVideoCdInfoResult::entry) not supported entrytype." << endl; + } + + return m_emptyEntry; + +} + + +void K3bVideoCdInfoResult::addEntry( const K3bVideoCdInfoResultEntry& entry, int type ) +{ + switch ( type ) { + case K3bVideoCdInfoResult::FILE: + m_fileEntry.append( entry ); + break; + case K3bVideoCdInfoResult::SEGMENT: + m_segmentEntry.append( entry ); + break; + case K3bVideoCdInfoResult::SEQUENCE: + m_sequenceEntry.append( entry ); + break; + default: + kdDebug() << "(K3bVideoCdInfoResult::addEntry) not supported entrytype." << endl; + } +} + +int K3bVideoCdInfoResult::foundEntries( int type ) const +{ + switch ( type ) { + case K3bVideoCdInfoResult::FILE: + return m_fileEntry.count(); + case K3bVideoCdInfoResult::SEGMENT: + return m_segmentEntry.count(); + case K3bVideoCdInfoResult::SEQUENCE: + return m_sequenceEntry.count(); + default: + kdDebug() << "(K3bVideoCdInfoResult::addEntry) not supported entrytype." << endl; + } + return 0; +} + +#include "k3bvideocdinfo.moc" + -- cgit v1.2.1