Skip to content

Commit

Permalink
opt: rewrite the html of gdprg (#2080)
Browse files Browse the repository at this point in the history
* opt: rewrite the html of gdprg

* opt: rewrite the html of gdprg

* opt: rewrite the html of gdprg

* [autofix.ci] apply automated fixes

* opt: rewrite the html of gdprg

* opt: rewrite the html of gdprg

* [autofix.ci] apply automated fixes

* opt: lingualibre html

* opt: lingualibre html

* opt: forvo parse error message

* opt: forvo parse error message

* opt: forvo parse error message

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
xiaoyifang and autofix-ci[bot] authored Jan 17, 2025
1 parent 3d96c22 commit fa7e908
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 132 deletions.
27 changes: 16 additions & 11 deletions src/dict/forvo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,23 +313,28 @@ void ForvoArticleRequest::requestFinished( QNetworkReply * r )

if ( !errors.isNull() ) {
QString text( errors.namedItem( "error" ).toElement().text() );

if ( text == "Limit/day reached." && apiKey.simplified().isEmpty() ) {
// Give a hint that the user should apply for his own key.

text +=
"\n"
+ tr(
"Go to Edit|Dictionaries|Sources|Forvo and apply for our own API key to make this error disappear." );
}

setErrorString( text );
}
}
qDebug( "done." );
}
else {
setErrorString( netReply->errorString() );
//forvo return the error message with http status code=400.
QDomDocument dd;

QString errorStr;
int errorLine, errorColumn;

if ( !dd.setContent( netReply.get(), false, &errorStr, &errorLine, &errorColumn ) ) {
setErrorString( netReply->errorString() );
}
else {
QDomNode errors = dd.namedItem( "errors" );
if ( !errors.isNull() ) {
QString text( errors.namedItem( "error" ).toElement().text() );
setErrorString( text );
}
}
}
}

Expand Down
19 changes: 14 additions & 5 deletions src/dict/lingualibre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,23 +342,32 @@ void LinguaArticleRequest::requestFinished( QNetworkReply * r )

if ( resultJson.contains( "query" ) ) {

string articleBody = "<p>";
string articleBody = "<div class=\"audio-play\">";

for ( auto pageJsonVal : resultJson[ "query" ].toObject()[ "pages" ].toObject() ) {
auto pageJsonObj = pageJsonVal.toObject();
string title = pageJsonObj[ "title" ].toString().toHtmlEscaped().toStdString();
string audiolink =
pageJsonObj[ "imageinfo" ].toArray().at( 0 ).toObject()[ "url" ].toString().toHtmlEscaped().toStdString();
articleBody += addAudioLink( audiolink, dictionaryId );
addAudioLink( audiolink, dictionaryId );

articleBody += "<div class=\"audio-play-item\">";
//play icon
articleBody += R"(<a href=")";
articleBody += audiolink;
articleBody += R"(">)";
articleBody += R"(" role="button">)";
articleBody += R"(<img src="qrc:///icons/playsound.png" border="0" alt="Play"/>)";
articleBody += "</a>";
//text
articleBody += R"(<a href=")";
articleBody += audiolink;
articleBody += R"(" role="link">)";
articleBody += title;
articleBody += "</a><br>";
articleBody += "</a>";
articleBody += "</div>";
}

articleBody += "</p>";
articleBody += "</div>";

appendString( articleBody );

Expand Down
22 changes: 11 additions & 11 deletions src/dict/lsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ sptr< Dictionary::DataRequest > LsaDictionary::getArticle( std::u32string const

multimap< std::u32string, string >::const_iterator i;

result += "<table class=\"lsa_play\">";
result += "<div class=\"audio-play\">";
for ( i = mainArticles.begin(); i != mainArticles.end(); ++i ) {
result += "<tr>";
result += "<div class=\"audio-play-item\">";

QUrl url;
url.setScheme( "gdau" );
Expand All @@ -269,15 +269,15 @@ sptr< Dictionary::DataRequest > LsaDictionary::getArticle( std::u32string const

string ref = string( "\"" ) + url.toEncoded().data() + "\"";

result += addAudioLink( url.toEncoded(), getId() );
addAudioLink( url.toEncoded(), getId() );

result += "<td><a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a></td>)";
result += "<td><a href=" + ref + ">" + i->second + "</a></td>";
result += "</tr>";
result += "<a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a>)";
result += "<a href=" + ref + ">" + i->second + "</a>";
result += "</div>";
}

for ( i = alternateArticles.begin(); i != alternateArticles.end(); ++i ) {
result += "<tr>";
result += "<div class=\"audio-play-item\">";

QUrl url;
url.setScheme( "gdau" );
Expand All @@ -288,12 +288,12 @@ sptr< Dictionary::DataRequest > LsaDictionary::getArticle( std::u32string const

result += addAudioLink( url.toEncoded(), getId() );

result += "<td><a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a></td>)";
result += "<td><a href=" + ref + ">" + i->second + "</a></td>";
result += "</tr>";
result += "<a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a>)";
result += "<a href=" + ref + ">" + i->second + "</a>";
result += "</div>";
}

result += "</table>";
result += "</div>";

auto * ret = new Dictionary::DataRequestInstant( true );

Expand Down
10 changes: 5 additions & 5 deletions src/dict/programs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ sptr< Dictionary::DataRequest > ProgramsDictionary::getArticle( std::u32string c

string wordUtf8( Text::toUtf8( word ) );

result += "<table class=\"programs_play\"><tr>";
result += "<div class=\"audio-play\"><div class=\"audio-play-item\">";

QUrl url;
url.setScheme( "gdprg" );
Expand All @@ -92,11 +92,11 @@ sptr< Dictionary::DataRequest > ProgramsDictionary::getArticle( std::u32string c

string ref = string( "\"" ) + url.toEncoded().data() + "\"";

result += addAudioLink( url.toEncoded(), getId() );
addAudioLink( url.toEncoded(), getId() );

result += "<td><a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a></td>)";
result += "<td><a href=" + ref + ">" + Html::escape( wordUtf8 ) + "</a></td>";
result += "</tr></table>";
result += "<a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a>)";
result += "<a href=" + ref + ">" + Html::escape( wordUtf8 ) + "</a>";
result += "</div></div>";

auto ret = std::make_shared< DataRequestInstant >( true );
ret->appendString( result );
Expand Down
22 changes: 11 additions & 11 deletions src/dict/sounddir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getArticle( std::u32string c
vector< char > chunk;
char * nameBlock;

result += "<table class=\"lsa_play\">";
result += "<div class=\"audio-play\">";

for ( i = mainArticles.begin(); i != mainArticles.end(); ++i ) {
uint32_t address = chain[ i->second ].articleOffset;
Expand Down Expand Up @@ -204,7 +204,7 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getArticle( std::u32string c
}
}

result += "<tr>";
result += "<div class=\"audio-play-item\">";
auto _displayName = Html::escape( displayedName );
QString file_name;
if ( !get_file_name( address, file_name ) ) {
Expand All @@ -221,9 +221,9 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getArticle( std::u32string c

result += addAudioLink( url.toEncoded(), getId() );

result += "<td><a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a></td>)";
result += "<td><a href=" + ref + ">" + _displayName + "</a></td>";
result += "</tr>";
result += "<a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a>)";
result += "<a href=" + ref + ">" + _displayName + "</a>";
result += "</div>";
}

for ( i = alternateArticles.begin(); i != alternateArticles.end(); ++i ) {
Expand Down Expand Up @@ -252,7 +252,7 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getArticle( std::u32string c
}
}

result += "<tr>";
result += "<div class=\"audio-play-item\">";
auto _displayName = Html::escape( displayedName );
QString file_name;
if ( !get_file_name( address, file_name ) ) {
Expand All @@ -267,14 +267,14 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getArticle( std::u32string c

string ref = string( "\"" ) + url.toEncoded().data() + "\"";

result += addAudioLink( url.toEncoded(), getId() );
addAudioLink( url.toEncoded(), getId() );

result += "<td><a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a></td>)";
result += "<td><a href=" + ref + ">" + _displayName + "</a></td>";
result += "</tr>";
result += "<a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a>)";
result += "<a href=" + ref + ">" + _displayName + "</a>";
result += "</div>";
}

result += "</table>";
result += "</div>";

auto ret = std::make_shared< Dictionary::DataRequestInstant >( true );

Expand Down
10 changes: 5 additions & 5 deletions src/dict/voiceengines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ VoiceEnginesDictionary::getArticle( u32string const & word, vector< u32string >
string result;
string wordUtf8( Text::toUtf8( word ) );

result += "<table class=\"voiceengines_play\"><tr>";
result += "<div class=\"audio-play\"><div class=\"audio-play-item\">";

QUrl url;
url.setScheme( "gdtts" );
Expand All @@ -96,11 +96,11 @@ VoiceEnginesDictionary::getArticle( u32string const & word, vector< u32string >

string encodedUrl = url.toEncoded().data();
string ref = string( "\"" ) + encodedUrl + "\"";
result += addAudioLink( encodedUrl, getId() );
addAudioLink( encodedUrl, getId() );

result += "<td><a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a></td>)";
result += "<td><a href=" + ref + ">" + Html::escape( wordUtf8 ) + "</a></td>";
result += "</tr></table>";
result += "<a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a>)";
result += "<a href=" + ref + ">" + Html::escape( wordUtf8 ) + "</a>";
result += "</div></div>";

auto ret = std::make_shared< DataRequestInstant >( true );
ret->appendString( result );
Expand Down
22 changes: 11 additions & 11 deletions src/dict/zipsounds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ sptr< Dictionary::DataRequest > ZipSoundsDictionary::getArticle( std::u32string

multimap< std::u32string, uint32_t >::const_iterator i;

result += "<table class=\"lsa_play\">";
result += "<div class=\"audio-play\">";

vector< char > chunk;
char * nameBlock;
Expand Down Expand Up @@ -247,7 +247,7 @@ sptr< Dictionary::DataRequest > ZipSoundsDictionary::getArticle( std::u32string
string displayedName =
mainArticles.size() + alternateArticles.size() > 1 ? name : Text::toUtf8( stripExtension( name ) );

result += "<tr>";
result += "<div class=\"audio-play-item\">";

QUrl url;
url.setScheme( "gdau" );
Expand All @@ -258,9 +258,9 @@ sptr< Dictionary::DataRequest > ZipSoundsDictionary::getArticle( std::u32string

result += addAudioLink( url.toEncoded(), getId() );

result += "<td><a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a></td>)";
result += "<td><a href=" + ref + ">" + Html::escape( displayedName ) + "</a></td>";
result += "</tr>";
result += "<a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a>)";
result += "<a href=" + ref + ">" + Html::escape( displayedName ) + "</a>";
result += "</div>";
}

for ( i = alternateArticles.begin(); i != alternateArticles.end(); ++i ) {
Expand Down Expand Up @@ -289,7 +289,7 @@ sptr< Dictionary::DataRequest > ZipSoundsDictionary::getArticle( std::u32string
string displayedName =
mainArticles.size() + alternateArticles.size() > 1 ? name : Text::toUtf8( stripExtension( name ) );

result += "<tr>";
result += "<div class=\"audio-play-item\">";

QUrl url;
url.setScheme( "gdau" );
Expand All @@ -298,14 +298,14 @@ sptr< Dictionary::DataRequest > ZipSoundsDictionary::getArticle( std::u32string

string ref = string( "\"" ) + url.toEncoded().data() + "\"";

result += addAudioLink( url.toEncoded(), getId() );
addAudioLink( url.toEncoded(), getId() );

result += "<td><a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a></td>)";
result += "<td><a href=" + ref + ">" + Html::escape( displayedName ) + "</a></td>";
result += "</tr>";
result += "<a href=" + ref + R"(><img src="qrc:///icons/playsound.png" border="0" alt="Play"/></a>)";
result += "<a href=" + ref + ">" + Html::escape( displayedName ) + "</a>";
result += "</div>";
}

result += "</table>";
result += "</div>";

auto ret = std::make_shared< Dictionary::DataRequestInstant >( true );
ret->appendString( result );
Expand Down
38 changes: 0 additions & 38 deletions src/stylesheets/article-style-st-classic.css
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,6 @@ div.xdxf {

/************* LSA audio archives **************/

/* A table which contains a play icon and a word's link */
.lsa_play {
margin-top: 8px;
margin-left: 8px;
}

.lsa_play a {
text-decoration: none;
}

/************* DSL dictionaries **************/

.dsl_u {
Expand Down Expand Up @@ -593,34 +583,6 @@ div.xdxf {
color: red;
}

/************* Programs **************/

/* A table which contains a play icon and a word's link */
.programs_play {
margin-top: 8px;
margin-left: 8px;
}

.programs_play a {
text-decoration: none;
}

.programs_plaintext,
.programs_html {
margin-top: 15px;
}

/************* Voice engines **************/

.voiceengines_play {
margin-top: 8px;
margin-left: 8px;
}

.voiceengines_play a {
text-decoration: none;
}

/************* MediaWiki articles *****************
The following consist of excerpts from different .css files edited
with a .mwiki prepended to each record.
Expand Down
Loading

0 comments on commit fa7e908

Please sign in to comment.