epub audio support

This commit is contained in:
Jaydeep Solanki 2013-10-22 21:38:17 +05:30 committed by Albert Astals Cid
parent e9ccc4867b
commit e95b1db23c
6 changed files with 50 additions and 2 deletions

View file

@ -21,6 +21,7 @@
#include <core/action.h>
#include <core/movie.h>
#include <core/sound.h>
#include <core/annotations.h>
using namespace Epub;
@ -197,9 +198,12 @@ QTextDocument* Converter::convert( const QString &fileName )
// if the background color of the document is non-white it will be handled by QTextDocument::setHtml()
bool firstPage = true;
QVector<Okular::MovieAnnotation *> movieAnnots;
QVector<Okular::SoundAction *> soundActions;
const QSize videoSize(320, 240);
do{
movieAnnots.clear();
soundActions.clear();
if(epub_it_get_curr(it)) {
const QString link = QString::fromUtf8(epub_it_get_curr_url(it));
mTextDocument->setCurrentSubDocument(link);
@ -257,11 +261,28 @@ QTextDocument* Converter::convert( const QString &fileName )
movieAnnots.push_back(annot);
QDomDocument tempDoc;
tempDoc.setContent(QString("<pre>&lt;video&gt;&lt;/video&gt;</pre>"));
qDebug() << "replacing";
videoTags.at(i).parentNode().replaceChild(tempDoc.documentElement(),videoTags.at(i));
}
}
}
//handle embedded audio
QDomNodeList audioTags = dom.elementsByTagName("audio");
if(!audioTags.isEmpty()) {
for (int i = 0; i < audioTags.size(); ++i) {
QString lnk = audioTags.at(i).toElement().attribute("src");
Okular::Sound *sound = new Okular::Sound(mTextDocument->loadResource(
EpubDocument::AudioResource, QUrl(lnk)).toByteArray());
Okular::SoundAction *soundAction = new Okular::SoundAction(1.0,true,true,false,sound);
soundActions.push_back(soundAction);
QDomDocument tempDoc;
tempDoc.setContent(QString("<pre>&lt;audio&gt;&lt;/audio&gt;</pre>"));
audioTags.at(i).parentNode().replaceChild(tempDoc.documentElement(),audioTags.at(i));
}
}
htmlContent = dom.toString();
}
@ -297,6 +318,19 @@ QTextDocument* Converter::convert( const QString &fileName )
csr.movePosition(QTextCursor::NextWord);
}
csr.movePosition(QTextCursor::Start);
index = 0;
const QString keyToSearch("<audio></audio>");
while( !(csr = mTextDocument->find(keyToSearch, csr)).isNull() ) {
const int posStart = csr.position() - keyToSearch.size();
const QImage img(KStandardDirs::locate("data", "okular/pics/okular-epub-sound-icon.png"));
csr.insertImage(img);
const int posEnd = csr.position();
qDebug() << posStart << posEnd;;
emit addAction(soundActions[index++],posStart,posEnd);
csr.movePosition(QTextCursor::NextWord);
}
mSectionMap.insert(link, before);
_handle_anchors(before, link);

View file

@ -1,4 +1,5 @@
install(FILES
okular-epub-sound-icon.png
okular-epub-movie.png
DESTINATION ${DATA_INSTALL_DIR}/okular/pics)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -113,6 +113,11 @@ QVariant EpubDocument::loadResource(int type, const QUrl &name)
resource.setValue(tmp->fileName());
break;
}
case EpubDocument::AudioResource: {
QByteArray ba(data,size);
resource.setValue(ba);
break;
}
default:
resource.setValue(QString::fromUtf8(data));
break;

View file

@ -29,7 +29,7 @@ namespace Epub {
void setCurrentSubDocument(const QString &doc);
int maxContentHeight() const;
int maxContentWidth() const;
enum Multimedia { MovieResource = 4 };
enum Multimedia { MovieResource = 4, AudioResource = 5 };
protected:
virtual QVariant loadResource(int type, const QUrl &name);

View file

@ -77,6 +77,7 @@
#include "core/misc.h"
#include "core/generator.h"
#include "core/movie.h"
#include "core/audioplayer.h"
#include "core/sourcereference.h"
#include "core/tile.h"
#include "settings.h"
@ -2380,6 +2381,9 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
// creating the menu and its actions
KMenu menu( this );
QAction * actProcessLink = menu.addAction( i18n( "Follow This Link" ) );
QAction * actStopSound = 0;
if ( link->actionType() == Okular::Action::Sound )
actStopSound = menu.addAction( i18n( "Stop Sound" ) );
QAction * actCopyLinkLocation = 0;
if ( dynamic_cast< const Okular::BrowseAction * >( link ) )
actCopyLinkLocation = menu.addAction( KIcon( "edit-copy" ), i18n( "Copy Link Address" ) );
@ -2398,6 +2402,10 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
if ( cb->supportsSelection() )
cb->setText( browseLink->url(), QClipboard::Selection );
}
else if ( res == actStopSound )
{
Okular::AudioPlayer::instance()->stopPlaybacks();
}
}
}
else