diff --git a/src/article_maker.cc b/src/article_maker.cc index 7b92805f..6684a767 100644 --- a/src/article_maker.cc +++ b/src/article_maker.cc @@ -246,6 +246,79 @@ std::string ArticleMaker::makeNotFoundBody( QString const & word, QString const return result; } +string ArticleMaker::makeWelcomePageHtml() const +{ + string result = makeHtmlHeader( tr( "Welcome!" ), QString(), cfg.alwaysExpandOptionalParts ); + //tooltip + result += R"()"; + result += R"()"; + result += R"()"; + + + result += + tr( + "

Welcome to GoldenDict!

" + "

To start working with the program, first visit Edit|Dictionaries to add some directory paths where to search " + "for the dictionary files, set up various Wikipedia sites or other sources, adjust dictionary order or create dictionary groups." + "

And then you're ready to look up your words! You can do that in this window " + "by using a pane to the left, or you can . " + "

To customize program, check out the available preferences at Edit|Preferences. " + "All settings there have tooltips, be sure to read them if you are in doubt about anything." + "

Should you need further help, have any questions, " + "suggestions or just wonder what the others think, you are welcome at the program's forum." + "

Check program's website for the updates. " + "

(c) 2008-2013 Konstantin Isakov. Licensed under GPLv3 or later." + + ) + .toUtf8() + .data(); + + result += R"(

"; + QString theme = ""; + if ( !GlobalBroadcaster::instance()->getPreference()->darkReaderMode ) { + theme = "light"; + } + + result += QString( + R"()" ) + .arg( theme ) + .toStdString(); + + result += ""; + + return result; +} + sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const & word, unsigned groupId, QMap< QString, QString > const & contexts, @@ -282,95 +355,26 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const & } if ( groupId == Instances::Group::HelpGroupId ) { - // This is a special group containing internal welcome/help pages - string result = makeHtmlHeader( word, QString(), cfg.alwaysExpandOptionalParts ); - if ( word == tr( "Welcome!" ) ) { - //tooltip - result += R"()"; - result += R"()"; - result += R"()"; + string welcome = makeWelcomePageHtml(); + sptr< Dictionary::DataRequestInstant > r = std::make_shared< Dictionary::DataRequestInstant >( true ); - - result += - tr( - "

Welcome to GoldenDict!

" - "

To start working with the program, first visit Edit|Dictionaries to add some directory paths where to search " - "for the dictionary files, set up various Wikipedia sites or other sources, adjust dictionary order or create dictionary groups." - "

And then you're ready to look up your words! You can do that in this window " - "by using a pane to the left, or you can . " - "

To customize program, check out the available preferences at Edit|Preferences. " - "All settings there have tooltips, be sure to read them if you are in doubt about anything." - "

Should you need further help, have any questions, " - "suggestions or just wonder what the others think, you are welcome at the program's forum." - "

Check program's website for the updates. " - "

(c) 2008-2013 Konstantin Isakov. Licensed under GPLv3 or later." - - ) - .toUtf8() - .data(); - - result += R"(

"; - QString theme = ""; - if ( !GlobalBroadcaster::instance()->getPreference()->darkReaderMode ) { - theme = "light"; - } - - result += QString( - R"()" ) - .arg( theme ) - .toStdString(); + r->appendString( welcome ); + return r; } else { // Not found return makeNotFoundTextFor( word, "help" ); } - - result += ""; - - sptr< Dictionary::DataRequestInstant > r = std::make_shared< Dictionary::DataRequestInstant >( true ); - - r->appendString( result ); - return r; } // Find the given group Instances::Group const * activeGroup = 0; - for ( unsigned x = 0; x < groups.size(); ++x ) - if ( groups[ x ].id == groupId ) { - activeGroup = &groups[ x ]; + for ( const auto & group : groups ) + if ( group.id == groupId ) { + activeGroup = &group; break; } @@ -426,17 +430,21 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeNotFoundTextFor( QString const sptr< Dictionary::DataRequest > ArticleMaker::makeEmptyPage() const { - string result = makeHtmlHeader( tr( "(untitled)" ), QString(), true ) + ""; - + string result = makeEmptyPageHtml(); sptr< Dictionary::DataRequestInstant > r = std::make_shared< Dictionary::DataRequestInstant >( true ); r->appendString( result ); return r; } +string ArticleMaker::makeEmptyPageHtml() const +{ + return makeHtmlHeader( tr( "(untitled)" ), QString(), true ) + ""; +} + sptr< Dictionary::DataRequest > ArticleMaker::makePicturePage( string const & url ) const { - string result = makeHtmlHeader( tr( "(picture)" ), QString(), true ) + string const result = makeHtmlHeader( tr( "(picture)" ), QString(), true ) + R"lit()lit" + R"()" + ""; diff --git a/src/article_maker.hh b/src/article_maker.hh index bff0d336..6b131bb1 100644 --- a/src/article_maker.hh +++ b/src/article_maker.hh @@ -62,6 +62,8 @@ public: /// Add base path to file path if it's relative and file not found /// Return true if path successfully adjusted static bool adjustFilePath( QString & fileName ); + string makeEmptyPageHtml() const; + string makeWelcomePageHtml() const; private: std::string readCssFile( QString const & fileName, std::string type ) const; diff --git a/src/article_netmgr.cc b/src/article_netmgr.cc index 550c5c72..5be0e1fb 100644 --- a/src/article_netmgr.cc +++ b/src/article_netmgr.cc @@ -239,6 +239,18 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co return new AllowFrameReply( reply ); } +string ArticleNetworkAccessManager::getHtml( ResourceType resourceType ) +{ + switch ( resourceType ) { + case ResourceType::UNTITLE: + return articleMaker.makeEmptyPageHtml(); + case ResourceType::WELCOME: + return articleMaker.makeWelcomePageHtml(); + default: + return {}; + } +} + sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( QUrl const & url, QString & contentType ) { qDebug() << "getResource:" << url.toString(); diff --git a/src/article_netmgr.hh b/src/article_netmgr.hh index 13c40202..e6fe7e0f 100644 --- a/src/article_netmgr.hh +++ b/src/article_netmgr.hh @@ -125,6 +125,10 @@ protected: } }; +enum class ResourceType { + UNTITLE, + WELCOME +}; class ArticleNetworkAccessManager: public QNetworkAccessManager { @@ -157,6 +161,7 @@ public: sptr< Dictionary::DataRequest > getResource( QUrl const & url, QString & contentType ); virtual QNetworkReply * getArticleReply( QNetworkRequest const & req ); + string getHtml( ResourceType resourceType ); }; class ArticleResourceReply: public QNetworkReply diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index ebc3804a..3981a53e 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -242,7 +242,9 @@ ArticleView::ArticleView( QWidget * parent, settings->setAttribute( QWebEngineSettings::PrintElementBackgrounds, false ); #endif - webview->load( QUrl( "gdlookup://localhost?word=(untitled)&blank=1" ) ); + auto html = articleNetMgr.getHtml( ResourceType::UNTITLE ); + + webview->setHtml( QString::fromStdString( html ) ); expandOptionalParts = cfg.preferences.alwaysExpandOptionalParts;