From e95b1db23c275ebeecc75263a7bf79999fcbb215 Mon Sep 17 00:00:00 2001 From: Jaydeep Solanki Date: Tue, 22 Oct 2013 21:38:17 +0530 Subject: [PATCH] epub audio support --- generators/epub/converter.cpp | 36 +++++++++++++++++- generators/epub/data/CMakeLists.txt | 1 + .../epub/data/okular-epub-sound-icon.png | Bin 0 -> 2194 bytes generators/epub/epubdocument.cpp | 5 +++ generators/epub/epubdocument.h | 2 +- ui/pageview.cpp | 8 ++++ 6 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 generators/epub/data/okular-epub-sound-icon.png diff --git a/generators/epub/converter.cpp b/generators/epub/converter.cpp index eeb479c39..394d85225 100644 --- a/generators/epub/converter.cpp +++ b/generators/epub/converter.cpp @@ -21,6 +21,7 @@ #include #include +#include #include 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 movieAnnots; + QVector 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("
<video></video>
")); - 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("
<audio></audio>
")); + 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(""); + 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); diff --git a/generators/epub/data/CMakeLists.txt b/generators/epub/data/CMakeLists.txt index e57a3be8b..c6af20918 100644 --- a/generators/epub/data/CMakeLists.txt +++ b/generators/epub/data/CMakeLists.txt @@ -1,4 +1,5 @@ install(FILES + okular-epub-sound-icon.png okular-epub-movie.png DESTINATION ${DATA_INSTALL_DIR}/okular/pics) diff --git a/generators/epub/data/okular-epub-sound-icon.png b/generators/epub/data/okular-epub-sound-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..6587a74b272ddaf35128818d55932535c62bc5f0 GIT binary patch literal 2194 zcmV;D2yOR?P)gUIaJvm@sJ$ecNIEauLg8<{t6UL-3kD>8rne2WDO7FaA?xUfX% zcRJ4?ck<-PE9=y$^XGCC(6(*czrK3)N}fM|E-zlZke4rC%Inv!<;|Nn^7idpdH?>s zl-GFo?wuSvc1(^RKVI0hY18iIA|N?AIraYi`*P>b9gBPS?#Y7(52UcLP#!*fD32dM zmM2f1$kV4!zaPhj@0rK^n>TOD;>C;Q(W6Il_@wrc9B`moMAYWR0s=uS!~4+G0Z`_JalBeFXT^$M5|h z@(=(;H4?c2A@h7B8J z_3G8Kbm>wtdxV(%Mk0}j3>h+HQ<(&45tk%@C@6Wp#hYu^tg-DeJ3CvJEn6mAwrsH- zM@3aAZCvDCH{yu&Bw46PA z))q5aVCHWuvw)KJ0ZpOJn>UL&63CJzOKe*3Uh9GPw8r)8*UQwYQ*BfzQfwlIcb6_* zvd=DDxM0EGfaiP{N-X zT8FR>>4XsK0x>EGu%0iMrq!HAC7_^mLkm0|(kJ13~Pwj*4)F zlvw}Kc18HR5}>bB$ZS3* zPMok_)*^SoGv0A*Chs}pOqeji{<<~b_rA8#Q2PJ^FrsZtMY#3Af*AIWz0$sYdl@`< zu#E)IgFxzV&N246v{>)^3)m&E`$FiA3;`IS$78@B2^B)<*}RgHlB7k87Sg3l7h4yQ zVo^WnM59KHk|s@>NaMzhWx#*|HZnn;SMqQm(&o+(P5?#-cS#~xoD*cDMvW|?1`Qh6 zBZU^F3j{E~bLY-haJ_o30EMLCd7Pp@~>nV9SFh8^a2)hTWAR#P_ zce-`!CUJ3b7Cn3REIJ;zAl))EGo@dbBPC$=dQrqPy$-EY?+E7CIeT5 zUkJd9dPdS>b)%#nCKZST-w_qphM%~S=Td_M%q1zD0E{silqAGWtuRp1O5E>tUHiSuU`H4p@|2K z7;{wUWLnwUf`WoqbOpTVrkB57ii7*DJ6{XioNWJ1^i39gT^_{0GfXI(nbYUoyu7?Z zLQGC8kuYHIKoB+%ke!{qi)foo?#qut+&|2bpsv}tzS+8U>qWdr=ppre;NCzAk&gNK z`Oh;lGS)O~*zhmLWXumj+&?N-tQgm|YuCT$IZ3u$IX5C?yzCQGHcbU z)#Q_qE@u2BIXO8cD=TZ8A^VP~kSY+@y~12zF7)cvYh;xwRce1~vLz04WKK>`PyeTB zfsaTRb8J3fE<3#|RjTy!ADT;4h5zQ}j}3lm0D-Co)eUMG{Kf!pCK~*~ppijigCv8d zCPn_%tXZ>f%-`+3cYpMdlyx;C*~Ih zah@Ou)bz;w)&nActsoWB>pF literal 0 HcmV?d00001 diff --git a/generators/epub/epubdocument.cpp b/generators/epub/epubdocument.cpp index a1f88113b..92fafbbfe 100644 --- a/generators/epub/epubdocument.cpp +++ b/generators/epub/epubdocument.cpp @@ -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; diff --git a/generators/epub/epubdocument.h b/generators/epub/epubdocument.h index 28c8fa015..f0d55b0ea 100644 --- a/generators/epub/epubdocument.h +++ b/generators/epub/epubdocument.h @@ -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); diff --git a/ui/pageview.cpp b/ui/pageview.cpp index a1ab5bd63..96104e01a 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -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