mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
Allow adding "ankisearch:" links in external programs. (#412)
* Add ankisearch link * auto indent * use raw string * refuse to run if ankiconnect is not enabled --------- Co-authored-by: GenjiFujimoto <dratschuk.d@gmail.com>
This commit is contained in:
parent
da57d82b47
commit
01c661b575
|
@ -50,6 +50,28 @@ void AnkiConnector::sendToAnki( QString const & word, QString const & text, QStr
|
||||||
Utils::json2String( fields ) );
|
Utils::json2String( fields ) );
|
||||||
|
|
||||||
// qDebug().noquote() << postData;
|
// qDebug().noquote() << postData;
|
||||||
|
postToAnki( postData );
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnkiConnector::ankiSearch( QString const & word )
|
||||||
|
{
|
||||||
|
if( !cfg.preferences.ankiConnectServer.enabled ) {
|
||||||
|
emit this->errorText( tr( "Anki search: AnkiConnect is not enabled." ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString postTemplate = R"anki({
|
||||||
|
"action": "guiBrowse",
|
||||||
|
"version": 6,
|
||||||
|
"params": {
|
||||||
|
"query": "%1"
|
||||||
|
}
|
||||||
|
})anki";
|
||||||
|
postToAnki( postTemplate.arg( word ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnkiConnector::postToAnki( QString const & postData )
|
||||||
|
{
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme( "http" );
|
url.setScheme( "http" );
|
||||||
url.setHost( cfg.preferences.ankiConnectServer.host );
|
url.setHost( cfg.preferences.ankiConnectServer.host );
|
||||||
|
|
|
@ -14,10 +14,12 @@ public:
|
||||||
explicit AnkiConnector( QObject * parent, Config::Class const & cfg );
|
explicit AnkiConnector( QObject * parent, Config::Class const & cfg );
|
||||||
|
|
||||||
void sendToAnki( QString const & word, QString const & text, QString const & sentence );
|
void sendToAnki( QString const & word, QString const & text, QString const & sentence );
|
||||||
|
void ankiSearch( QString const & word);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager * mgr;
|
QNetworkAccessManager * mgr;
|
||||||
Config::Class const & cfg;
|
Config::Class const & cfg;
|
||||||
|
void postToAnki( QString const & postData );
|
||||||
public :
|
public :
|
||||||
signals:
|
signals:
|
||||||
void errorText( QString const & );
|
void errorText( QString const & );
|
||||||
|
|
|
@ -1142,9 +1142,10 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
|
||||||
|
|
||||||
if( url.scheme().compare( "gdpicture" ) == 0 )
|
if( url.scheme().compare( "gdpicture" ) == 0 )
|
||||||
load( url );
|
load( url );
|
||||||
else
|
else if( url.scheme().compare( "ankisearch" ) == 0 ) {
|
||||||
if ( url.scheme().compare( "bword" ) == 0 || url.scheme().compare( "entry" ) == 0 )
|
ankiConnector->ankiSearch( url.path() );
|
||||||
{
|
}
|
||||||
|
else if( url.scheme().compare( "bword" ) == 0 || url.scheme().compare( "entry" ) == 0 ) {
|
||||||
if( Utils::Url::hasQueryItem( ref, "dictionaries" ) )
|
if( Utils::Url::hasQueryItem( ref, "dictionaries" ) )
|
||||||
{
|
{
|
||||||
QStringList dictsList = Utils::Url::queryItemValue( ref, "dictionaries" )
|
QStringList dictsList = Utils::Url::queryItemValue( ref, "dictionaries" )
|
||||||
|
|
Loading…
Reference in a new issue