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 00000000..80e4389a Binary files /dev/null and b/icons/video.png differ diff --git a/resources.qrc b/resources.qrc index 7e9ae4b6..b121f7b4 100644 --- a/resources.qrc +++ b/resources.qrc @@ -71,5 +71,6 @@ icons/expand_article.png icons/collapse_article_hovered.png icons/collapse_article.png + icons/video.png