From 0cf8ccb25901725977ccc76f549333978cdd4734 Mon Sep 17 00:00:00 2001 From: Tvangeste Date: Sat, 22 Jun 2013 18:36:25 +0200 Subject: [PATCH] DSL: Support video resources --- article-style.css | 19 +++++++++++++++++++ article_netmgr.cc | 2 +- articleview.cc | 19 ++++++++++++++++++- dsl.cc | 11 +++++++++++ filetype.cc | 20 ++++++++++++++++++++ filetype.hh | 3 +++ icons/video.png | Bin 0 -> 1228 bytes resources.qrc | 1 + 8 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 icons/video.png diff --git a/article-style.css b/article-style.css index db747513..dde7dd45 100644 --- a/article-style.css +++ b/article-style.css @@ -449,6 +449,25 @@ div.xdxf vertical-align: text-bottom; } +.dsl_video .img +{ + display: inline-block; + background: url('qrcx://localhost/icons/video.png'); + background-repeat: no-repeat; + /* Ugly hack since "vertical-align: middle;" looks _terrible_ in Qt4's webkit: */ + vertical-align: -30%; + width: 22px; + height: 22px; + margin: 0; + padding: 0; +} + +.dsl_video .filename +{ + display: none; /* by default, the file name is hidden */ + padding-left: 5px; +} + /************* MDict dictionaries **************/ .mdict { diff --git a/article_netmgr.cc b/article_netmgr.cc index 9902c818..f6b7ec00 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -170,7 +170,7 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( return articleMaker.makeDefinitionFor( word, group, contexts, mutedDicts ); } - if ( ( url.scheme() == "bres" || url.scheme() == "gdau" || url.scheme() == "gico" ) && + if ( ( url.scheme() == "bres" || url.scheme() == "gdau" || url.scheme() == "gdvideo" || url.scheme() == "gico" ) && url.path().size() ) { //DPRINTF( "Get %s\n", req.url().host().toLocal8Bit().data() ); diff --git a/articleview.cc b/articleview.cc index fbb0339b..f8f478b7 100644 --- a/articleview.cc +++ b/articleview.cc @@ -688,6 +688,23 @@ void ArticleView::linkHovered ( const QString & link, const QString & , const QS msg = tr( "Picture" ); } else + if ( url.scheme() == "gdvideo" ) + { + if ( url.path().isEmpty() ) + { + msg = tr( "Video" ); + } + else + { + QString path = url.path(); + if ( path.startsWith( '/' ) ) + { + path = path.mid( 1 ); + } + msg = tr( "Video: %1" ).arg( path ); + } + } + else if (url.scheme() == "gdlookup" || url.scheme().compare( "bword" ) == 0) { QString def = url.path(); @@ -784,7 +801,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, } } else - if ( url.scheme() == "bres" || url.scheme() == "gdau" || + if ( url.scheme() == "bres" || url.scheme() == "gdau" || url.scheme() == "gdvideo" || Dictionary::WebMultimediaDownload::isAudioUrl( url ) ) { // Download it diff --git a/dsl.cc b/dsl.cc index a215f2f1..78bde982 100644 --- a/dsl.cc +++ b/dsl.cc @@ -861,6 +861,17 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node ) + "\" alt=\"" + Html::escape( filename ) + "\"/>"; } else + if ( Filetype::isNameOfVideo( filename ) ) { + QUrl url; + url.setScheme( "gdvideo" ); + url.setHost( QString::fromUtf8( getId().c_str() ) ); + url.setPath( QString::fromUtf8( filename.c_str() ) ); + + result += string( "" + + "" + + "" + processNodeChildren( node ) + "" + ""; + } + else { // Unknown file type, downgrade to a hyperlink diff --git a/filetype.cc b/filetype.cc index 461878e0..18c98c3f 100644 --- a/filetype.cc +++ b/filetype.cc @@ -66,6 +66,26 @@ bool isNameOfSound( string const & name ) endsWith( s, ".spx" ); } +bool isNameOfVideo( string const & name ) +{ + string s = simplifyString( name ); + + return + endsWith( s, ".mpg" ) || + endsWith( s, ".mpeg" )|| + endsWith( s, ".mpe" ) || + endsWith( s, ".ogv" ) || + endsWith( s, ".avi" ) || + endsWith( s, ".m4v" ) || + endsWith( s, ".mkv" ) || + endsWith( s, ".wmv" ) || + endsWith( s, ".sfw" ) || + endsWith( s, ".flv" ) || + endsWith( s, ".divx" ) || + endsWith( s, ".3gp" ) || + endsWith( s, ".mov" ); +} + bool isNameOfPicture( string const & name ) { string s = simplifyString( name ); diff --git a/filetype.hh b/filetype.hh index 07b7fa75..35445c8b 100644 --- a/filetype.hh +++ b/filetype.hh @@ -14,6 +14,9 @@ using std::string; /// Returns true if the name resembles the one of a sound file (i.e. ends /// with .wav, .ogg and such). bool isNameOfSound( string const & ); +/// Returns true if the name resembles the one of a video file (i.e. ends +/// with .mpg, .ogv and such). +bool isNameOfVideo( string const & ); /// Returns true if the name resembles the one of a picture file (i.e. ends /// with .jpg, .png and such). bool isNameOfPicture( string const & ); diff --git a/icons/video.png b/icons/video.png new file mode 100644 index 0000000000000000000000000000000000000000..80e4389a73251ff3307ab8b601e59144fecd316d GIT binary patch literal 1228 zcmV;-1T*`IP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv000C#Nkl8#z&$? zj5UdkMr~@xS6&mH)JI}!t0Go66&FJ3K#LDVu%nB*aG|@wcIYV1m=;Hk?M@WL#k7J8 ztrmPhl@5|w_+ZAwN1cDqy~#ApL%Qms2Y#IUefhrsckln4laT*sbaiz}Yiep*s;jFB zM~lH#e&SGA~C@PtP^ET)vx?l?AOwF(;Nb8O83i`jro6CB zoZ*J+FIZfc0oeKirb#bkg=TDRZQ=Cv6jrMh#l^+n1muEIRaM1>kB*LrV`vNxSRWpu zWMmsf-|eB~?rxBgKTvdU5Ap&teqH_rdwaXESj;dO40qbw+m&Rga(sMT!iDX2dxJnA zKvPo_J|$w(GLe{b9nyF?BvKjP4ih6xoCJY58R3*8qEiqdjz`qBL{3Ds6as+|adB~w z$z%*qeSN)x3$vU1`}-WW`_$A_csw5LJ^mB#l-N)@>4ACT35*Y(!0^BW<9!cIEEAT8 zkCCh|!}9Vne}~mduh(~TVJZOknAt&vo71U0M*Ozi(!zc-l z;Ux^CmoQP0+9Iq*nm_jg+igg_VzY@qkBq| z{YqgY6Ly_Je!Uv=^Yhr;+=ND>fl8(F@0eL}NUe5!e9Wy#OH1Re zc6N5yZvDa)6%}u^!sqkhsn3ffMH*6WHY54N&w`Y{Shpa>)=ayU@tVBo3NGB%)>bSQ zi_zEDhyMP4h(sd9#Kd55aFAci^UGkJzJU2YjrD^|mIq>(nV^`Q@Og!_d$W zp9Ai3XJ_YIg@uJ*)5Rm|zehA2zq1KiTwKK5+#D1oRsY%*vV1#SE*F-TmiP>C;a8)q ztn6d(e%%=qS;wD!SXB2 qxJ5q^Gn^Tb+wBeyy#8NBNXXxY-Zvk`cWqt(0000icons/expand_article.png icons/collapse_article_hovered.png icons/collapse_article.png + icons/video.png