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 __MAINWINDOW_HH_INCLUDED__
|
|
|
|
#define __MAINWINDOW_HH_INCLUDED__
|
|
|
|
|
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QToolButton>
|
2009-02-05 20:55:00 +00:00
|
|
|
#include <QSystemTrayIcon>
|
2009-03-26 19:00:08 +00:00
|
|
|
#include <QNetworkAccessManager>
|
2009-01-28 20:55:45 +00:00
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include "folding.hh"
|
|
|
|
#include "config.hh"
|
|
|
|
#include "dictionary.hh"
|
|
|
|
#include "initializing.hh"
|
|
|
|
#include "article_netmgr.hh"
|
|
|
|
#include "instances.hh"
|
|
|
|
#include "article_maker.hh"
|
|
|
|
#include "scanpopup.hh"
|
|
|
|
#include "articleview.hh"
|
2009-01-29 19:16:25 +00:00
|
|
|
#include "wordfinder.hh"
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
class LoadDictionaries: public QThread, public Dictionary::Initializing
|
2009-01-28 20:55:45 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2009-03-28 22:37:03 +00:00
|
|
|
Config::Paths const & paths;
|
2009-04-04 16:06:06 +00:00
|
|
|
Config::SoundDirs const & soundDirs;
|
2009-04-09 14:15:01 +00:00
|
|
|
Config::Hunspell const & hunspell;
|
2009-01-28 20:55:45 +00:00
|
|
|
vector< sptr< Dictionary::Class > > dictionaries;
|
2009-03-29 13:34:39 +00:00
|
|
|
string exceptionText;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2009-04-04 16:06:06 +00:00
|
|
|
LoadDictionaries( Config::Class const & cfg );
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
virtual void run();
|
|
|
|
|
|
|
|
vector< sptr< Dictionary::Class > > const & getDictionaries() const
|
|
|
|
{ return dictionaries; }
|
|
|
|
|
2009-03-29 13:34:39 +00:00
|
|
|
/// Empty string means to exception occured
|
|
|
|
string const & getExceptionText() const
|
|
|
|
{ return exceptionText; }
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void indexingDictionarySignal( QString dictionaryName );
|
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
public:
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
virtual void indexingDictionary( string const & dictionaryName ) throw();
|
2009-03-28 22:37:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void handlePath( Config::Path const & );
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class MainWindow: public QMainWindow
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2009-04-12 20:46:25 +00:00
|
|
|
MainWindow( Config::Class & cfg );
|
2009-02-06 17:04:11 +00:00
|
|
|
~MainWindow();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
QSystemTrayIcon * trayIcon;
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
Ui::MainWindow ui;
|
2009-04-12 22:36:47 +00:00
|
|
|
QAction focusTranslateLineAction, addTabAction, closeCurrentTabAction,
|
2009-04-09 22:11:38 +00:00
|
|
|
switchToNextTabAction, switchToPrevTabAction;
|
2009-01-28 20:55:45 +00:00
|
|
|
QToolBar * navToolbar;
|
2009-04-10 21:07:03 +00:00
|
|
|
QAction * navBack, * navForward, * navPronounce, * enableScanPopup;
|
2009-02-08 20:20:02 +00:00
|
|
|
QMenu trayIconMenu;
|
2009-01-28 20:55:45 +00:00
|
|
|
QToolButton addTab;
|
2009-04-12 20:46:25 +00:00
|
|
|
Config::Class & cfg;
|
2009-01-28 20:55:45 +00:00
|
|
|
vector< sptr< Dictionary::Class > > dictionaries;
|
|
|
|
vector< Instances::Group > groupInstances;
|
|
|
|
ArticleMaker articleMaker;
|
|
|
|
ArticleNetworkAccessManager articleNetMgr;
|
2009-03-26 19:00:08 +00:00
|
|
|
QNetworkAccessManager dictNetMgr; // We give dictionaries a separate manager,
|
|
|
|
// since their requests can be destroyed
|
|
|
|
// in a separate thread
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-01-29 19:16:25 +00:00
|
|
|
WordFinder wordFinder;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-01 00:08:08 +00:00
|
|
|
sptr< ScanPopup > scanPopup;
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
::Initializing * initializing;
|
|
|
|
|
2009-02-05 20:55:00 +00:00
|
|
|
/// Creates, destroys or otherwise updates tray icon, according to the
|
|
|
|
/// current configuration and situation.
|
|
|
|
void updateTrayIcon();
|
|
|
|
|
|
|
|
void closeEvent( QCloseEvent * );
|
|
|
|
|
2009-04-03 17:10:27 +00:00
|
|
|
void applyProxySettings();
|
2009-01-28 20:55:45 +00:00
|
|
|
void makeDictionaries();
|
|
|
|
void updateStatusLine();
|
|
|
|
void updateGroupList();
|
2009-02-01 00:08:08 +00:00
|
|
|
void makeScanPopup();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
void updateMatchResults( bool finished );
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
void updatePronounceAvailability();
|
|
|
|
|
2009-03-29 17:38:54 +00:00
|
|
|
virtual bool eventFilter( QObject *, QEvent * );
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
/// Returns the reference to dictionaries stored in the currently active
|
|
|
|
/// group, or to all dictionaries if there are no groups.
|
|
|
|
vector< sptr< Dictionary::Class > > const & getActiveDicts();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
// Executed in response to a user click on an 'add tab' tool button
|
|
|
|
void addNewTab();
|
|
|
|
// Executed in response to a user click on an 'close' button on a tab
|
|
|
|
void tabCloseRequested( int );
|
2009-04-09 22:11:38 +00:00
|
|
|
// Closes current tab.
|
|
|
|
void closeCurrentTab();
|
|
|
|
void switchToNextTab();
|
|
|
|
void switchToPrevTab();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
|
|
|
/// Triggered by the actions in the nav toolbar
|
|
|
|
void backClicked();
|
|
|
|
void forwardClicked();
|
|
|
|
|
|
|
|
/// ArticleView's title has changed
|
|
|
|
void titleChanged( ArticleView *, QString const & );
|
|
|
|
/// ArticleView's icon has changed
|
|
|
|
void iconChanged( ArticleView *, QIcon const & );
|
|
|
|
|
2009-04-10 21:07:03 +00:00
|
|
|
void pageLoaded();
|
|
|
|
void tabSwitched( int );
|
|
|
|
|
|
|
|
/// Pronounces the currently displayed word by playing its first audio
|
|
|
|
/// reference, if it has any.
|
|
|
|
void pronounce();
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void editSources();
|
|
|
|
void editGroups();
|
2009-02-05 20:55:00 +00:00
|
|
|
void editPreferences();
|
2009-01-28 20:55:45 +00:00
|
|
|
void indexingDictionary( QString dictionaryName );
|
|
|
|
|
2009-02-06 17:04:11 +00:00
|
|
|
void currentGroupChanged( QString const & );
|
2009-01-28 20:55:45 +00:00
|
|
|
void translateInputChanged( QString const & );
|
2009-02-08 14:02:27 +00:00
|
|
|
void translateInputFinished();
|
2009-03-26 19:00:08 +00:00
|
|
|
|
2009-04-12 22:36:47 +00:00
|
|
|
/// Gives the keyboard focus to the translateLine and selects all the text
|
|
|
|
/// it has.
|
|
|
|
void focusTranslateLine();
|
2009-04-08 22:25:46 +00:00
|
|
|
|
2009-03-26 19:00:08 +00:00
|
|
|
void prefixMatchUpdated();
|
|
|
|
void prefixMatchFinished();
|
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void wordListItemActivated( QListWidgetItem * );
|
2009-02-08 14:02:27 +00:00
|
|
|
void wordListSelectionChanged();
|
2009-01-28 20:55:45 +00:00
|
|
|
|
2009-02-08 15:49:17 +00:00
|
|
|
void openLinkInNewTab( QUrl const &, QUrl const & );
|
2009-04-10 12:48:40 +00:00
|
|
|
void showDefinitionInNewTab( QString const & word, unsigned group );
|
2009-02-08 15:49:17 +00:00
|
|
|
|
2009-01-28 20:55:45 +00:00
|
|
|
void showTranslationFor( QString const & );
|
2009-02-05 20:55:00 +00:00
|
|
|
|
|
|
|
void trayIconActivated( QSystemTrayIcon::ActivationReason );
|
2009-02-08 14:02:27 +00:00
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
void scanEnableToggled( bool );
|
|
|
|
|
|
|
|
void showMainWindow();
|
|
|
|
|
2009-02-08 14:02:27 +00:00
|
|
|
void visitHomepage();
|
|
|
|
void visitForum();
|
|
|
|
void showAbout();
|
2009-01-28 20:55:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|