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 __ARTICLEVIEW_HH_INCLUDED__
|
|
|
|
#define __ARTICLEVIEW_HH_INCLUDED__
|
|
|
|
|
|
|
|
#include <QWebView>
|
|
|
|
#include <QUrl>
|
2009-03-26 19:00:08 +00:00
|
|
|
#include <list>
|
2009-01-28 20:55:45 +00:00
|
|
|
#include "article_netmgr.hh"
|
|
|
|
#include "instances.hh"
|
|
|
|
#include "ui_articleview.h"
|
|
|
|
|
|
|
|
/// A widget with the web view tailored to view and handle articles -- it
|
|
|
|
/// uses the appropriate netmgr, handles link clicks, rmb clicks etc
|
|
|
|
class ArticleView: public QFrame
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
ArticleNetworkAccessManager & articleNetMgr;
|
2009-04-12 16:22:42 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries;
|
2009-01-28 20:55:45 +00:00
|
|
|
Instances::Groups const & groups;
|
|
|
|
bool popupView;
|
2009-04-10 21:07:03 +00:00
|
|
|
Config::Class const & cfg;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
Ui::ArticleView ui;
|
|
|
|
|
2009-02-06 15:37:37 +00:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
// Used in Windows only
|
|
|
|
vector< char > winWavData;
|
|
|
|
#endif
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
/// Any resource we've decided to download off the dictionary gets stored here.
|
|
|
|
/// Full vector capacity is used for search requests, where we have to make
|
|
|
|
/// a multitude of requests.
|
|
|
|
std::list< sptr< Dictionary::DataRequest > > resourceDownloadRequests;
|
|
|
|
/// Url of the resourceDownloadRequests
|
|
|
|
QUrl resourceDownloadUrl;
|
|
|
|
|
|
|
|
/// For resources opened via desktop services
|
2009-02-08 21:54:19 +00:00
|
|
|
QString desktopOpenedTempFile;
|
2009-02-08 14:40:26 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
public:
|
|
|
|
/// The popupView flag influences contents of the context menus to be
|
|
|
|
/// appropriate to the context of the view.
|
|
|
|
/// The groups aren't copied -- rather than that, the reference is kept
|
|
|
|
ArticleView( QWidget * parent,
|
|
|
|
ArticleNetworkAccessManager &,
|
2009-04-12 16:22:42 +00:00
|
|
|
std::vector< sptr< Dictionary::Class > > const & allDictionaries,
|
2009-01-28 20:55:45 +00:00
|
|
|
Instances::Groups const &,
|
2009-04-10 21:07:03 +00:00
|
|
|
bool popupView,
|
|
|
|
Config::Class const & cfg );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-06 15:37:37 +00:00
|
|
|
~ArticleView();
|
|
|
|
|
2009-05-11 19:14:28 +00:00
|
|
|
/// Shows the definition of the given word with the given group.
|
|
|
|
/// scrollTo can be optionally set to a "gdfrom-xxxx" identifier to position
|
|
|
|
/// the page to that article on load.
|
|
|
|
void showDefinition( QString const & word, unsigned group,
|
|
|
|
QString const & scrollTo = QString() );
|
2009-02-01 00:08:08 +00:00
|
|
|
|
2009-02-08 16:50:18 +00:00
|
|
|
/// Clears the view and sets the application-global waiting cursor,
|
|
|
|
/// which will be restored when some article loads eventually.
|
|
|
|
void showAnticipation();
|
2009-04-30 19:57:25 +00:00
|
|
|
|
2009-02-08 15:49:17 +00:00
|
|
|
/// Opens the given link. Supposed to be used in response to
|
|
|
|
/// openLinkInNewTab() signal. The link scheme is therefore supposed to be
|
|
|
|
/// one of the internal ones.
|
2009-05-11 19:14:28 +00:00
|
|
|
void openLink( QUrl const & url, QUrl const & referrer,
|
|
|
|
QString const & scrollTo = QString() );
|
2009-04-30 19:57:25 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Goes back in history
|
|
|
|
void back()
|
|
|
|
{ ui.definition->back(); }
|
|
|
|
|
|
|
|
/// Goes forward in history
|
|
|
|
void forward()
|
|
|
|
{ ui.definition->forward(); }
|
|
|
|
|
2009-03-29 17:38:54 +00:00
|
|
|
/// Takes the focus to the view
|
|
|
|
void focus()
|
|
|
|
{ ui.definition->setFocus( Qt::ShortcutFocusReason ); }
|
|
|
|
|
2009-05-11 11:03:36 +00:00
|
|
|
/// Reloads the view
|
|
|
|
void reload()
|
|
|
|
{ ui.definition->reload(); }
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
/// Returns true if there's an audio reference on the page, false otherwise.
|
|
|
|
bool hasSound();
|
|
|
|
|
|
|
|
/// Plays the first audio reference on the page, if any.
|
|
|
|
void playSound();
|
|
|
|
|
2009-04-30 19:57:25 +00:00
|
|
|
void setZoomFactor( qreal factor )
|
|
|
|
{ ui.definition->setZoomFactor( factor ); }
|
|
|
|
|
2009-05-01 11:17:29 +00:00
|
|
|
/// Returns current article's text in .html format
|
|
|
|
QString toHtml();
|
|
|
|
|
|
|
|
/// Returns current article's title
|
|
|
|
QString getTitle();
|
2009-05-01 12:20:33 +00:00
|
|
|
|
|
|
|
/// Prints current article
|
|
|
|
void print( QPrinter * ) const;
|
2009-05-01 11:17:29 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void iconChanged( ArticleView *, QIcon const & icon );
|
|
|
|
|
|
|
|
void titleChanged( ArticleView *, QString const & title );
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
void pageLoaded();
|
|
|
|
|
2009-02-08 15:49:17 +00:00
|
|
|
/// Singals that the following link was requested to be opened in new tab
|
2009-05-11 19:14:28 +00:00
|
|
|
void openLinkInNewTab( QUrl const &, QUrl const & referrer,
|
|
|
|
QString const & fromArticle );
|
2009-02-08 15:49:17 +00:00
|
|
|
/// Singals that the following definition was requested to be showed in new tab
|
2009-05-11 19:14:28 +00:00
|
|
|
void showDefinitionInNewTab( QString const & word, unsigned group,
|
|
|
|
QString const & fromArticle );
|
2009-02-08 15:49:17 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private slots:
|
|
|
|
|
2009-02-08 16:50:18 +00:00
|
|
|
void loadFinished( bool ok );
|
2009-01-28 20:55:45 +00:00
|
|
|
void handleTitleChanged( QString const & title );
|
|
|
|
void handleUrlChanged( QUrl const & url );
|
|
|
|
void linkClicked( QUrl const & );
|
|
|
|
void contextMenuRequested( QPoint const & );
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
void resourceDownloadFinished();
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/// Deduces group from the url. If there doesn't seem to be any group,
|
2009-04-10 12:48:40 +00:00
|
|
|
/// returns 0.
|
|
|
|
unsigned getGroup( QUrl const & );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-05-11 22:25:22 +00:00
|
|
|
/// Returns all articles current present in view, as a list of dictionary
|
|
|
|
/// string ids.
|
|
|
|
QStringList getArticlesList();
|
|
|
|
|
|
|
|
/// Returns current article in the view, in the form of "gdfrom-xxx" id.
|
2009-05-11 19:14:28 +00:00
|
|
|
QString getCurrentArticle();
|
|
|
|
|
2009-05-11 22:25:22 +00:00
|
|
|
/// Sets the current article by executing a javascript code.
|
|
|
|
void setCurrentArticle( QString const & );
|
|
|
|
|
2009-02-08 21:54:19 +00:00
|
|
|
/// Attempts removing last temporary file created.
|
|
|
|
void cleanupTemp();
|
2009-04-30 19:57:25 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
// We need this to hide the search bar when we're showed
|
|
|
|
void showEvent( QShowEvent * );
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|