2009-02-05 14:21:47 +00:00
|
|
|
/* This file is (c) 2008-2009 Konstantin Isakov <ikm@users.berlios.de>
|
2009-01-28 20:55:45 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#ifndef __ARTICLE_MAKER_HH_INCLUDED__
|
|
|
|
#define __ARTICLE_MAKER_HH_INCLUDED__
|
|
|
|
|
2009-02-01 00:08:08 +00:00
|
|
|
#include <QObject>
|
2009-03-26 19:00:08 +00:00
|
|
|
#include <set>
|
|
|
|
#include <list>
|
2009-01-28 20:55:45 +00:00
|
|
|
#include "dictionary.hh"
|
|
|
|
#include "instances.hh"
|
2009-04-17 13:51:50 +00:00
|
|
|
#include "wordfinder.hh"
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// This class generates the article's body for the given lookup request
|
2009-02-01 00:08:08 +00:00
|
|
|
class ArticleMaker: public QObject
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
2009-02-01 00:08:08 +00:00
|
|
|
Q_OBJECT // We make it QObject to use tr() conveniently
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const & dictionaries;
|
|
|
|
std::vector< Instances::Group > const & groups;
|
|
|
|
|
2009-05-11 11:03:36 +00:00
|
|
|
QString displayStyle;
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/// On construction, a reference to all dictionaries and a reference all
|
|
|
|
/// groups' instances are to be passed. Those references are kept stored as
|
|
|
|
/// references, and as such, any changes to them would reflect on the results
|
|
|
|
/// of the inquiries, altthough those changes are perfectly legal.
|
|
|
|
ArticleMaker( std::vector< sptr< Dictionary::Class > > const & dictionaries,
|
2009-05-11 11:03:36 +00:00
|
|
|
std::vector< Instances::Group > const & groups,
|
|
|
|
QString const & displayStyle );
|
|
|
|
|
|
|
|
/// Sets the display style to use for any new requests. This affects the
|
|
|
|
/// choice of the stylesheet file.
|
|
|
|
void setDisplayStyle( QString const & );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// Looks up the given word within the given group, and creates a full html
|
|
|
|
/// page text containing its definition.
|
2009-03-26 19:00:08 +00:00
|
|
|
/// The result is returned as Dictionary::DataRequest just like dictionaries
|
|
|
|
/// themselves do. The difference is that the result is a complete html page
|
|
|
|
/// with all definitions from all the relevant dictionaries.
|
2009-04-10 12:48:40 +00:00
|
|
|
sptr< Dictionary::DataRequest > makeDefinitionFor( QString const & word, unsigned groupId ) const;
|
2009-02-01 00:08:08 +00:00
|
|
|
|
|
|
|
/// Makes up a text which states that no translation for the given word
|
|
|
|
/// was found. Sometimes it's better to call this directly when it's already
|
|
|
|
/// known that there's no translation.
|
2009-03-26 19:00:08 +00:00
|
|
|
sptr< Dictionary::DataRequest > makeNotFoundTextFor( QString const & word, QString const & group ) const;
|
2009-02-01 00:08:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/// Makes everything up to and including the opening body tag.
|
2009-05-11 11:03:36 +00:00
|
|
|
std::string makeHtmlHeader( QString const & word, QString const & icon ) const;
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
/// Makes the html body for makeNotFoundTextFor()
|
|
|
|
static std::string makeNotFoundBody( QString const & word, QString const & group );
|
|
|
|
|
|
|
|
friend class ArticleRequest; // Allow it calling makeNotFoundBody()
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
/// The request specific to article maker. This should really be private,
|
|
|
|
/// but we need it to be handled by moc.
|
|
|
|
class ArticleRequest: public Dictionary::DataRequest
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
QString word, group;
|
|
|
|
std::vector< sptr< Dictionary::Class > > const & activeDicts;
|
|
|
|
|
2009-04-18 17:20:12 +00:00
|
|
|
std::set< gd::wstring > alts; // Accumulated main forms
|
2009-03-26 19:00:08 +00:00
|
|
|
std::list< sptr< Dictionary::WordSearchRequest > > altSearches;
|
|
|
|
bool altsDone, bodyDone;
|
|
|
|
std::list< sptr< Dictionary::DataRequest > > bodyRequests;
|
|
|
|
bool foundAnyDefinitions;
|
2009-04-12 16:22:42 +00:00
|
|
|
bool closePrevSpan; // Indicates whether the last opened article span is to
|
|
|
|
// be closed after the article ends.
|
2009-04-17 13:51:50 +00:00
|
|
|
sptr< WordFinder > stemmedWordFinder; // Used when there're no results
|
2009-03-26 19:00:08 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ArticleRequest( QString const & word, QString const & group,
|
|
|
|
std::vector< sptr< Dictionary::Class > > const & activeDicts,
|
|
|
|
std::string const & header );
|
|
|
|
|
|
|
|
virtual void cancel()
|
|
|
|
{ finish(); } // Add our own requests cancellation here
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
void altSearchFinished();
|
|
|
|
void bodyFinished();
|
2009-04-17 13:51:50 +00:00
|
|
|
void stemmedSearchFinished();
|
2009-03-26 19:00:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
#endif
|