2012-02-20 21:47:14 +00:00
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
2009-01-28 20:55:45 +00:00
* Part of GoldenDict . Licensed under GPLv3 or later , see the LICENSE file */
# include "mainwindow.hh"
2009-04-30 15:29:03 +00:00
# include "editdictionaries.hh"
# include "loaddictionaries.hh"
2009-02-05 20:55:00 +00:00
# include "preferences.hh"
2010-11-14 16:28:50 +00:00
# include "about.hh"
2011-11-02 23:37:50 +00:00
# include "mruqmenu.hh"
2014-02-04 13:35:42 +00:00
# include "gestures.hh"
2014-02-28 12:36:28 +00:00
# include "dictheadwords.hh"
2009-04-10 12:48:40 +00:00
# include <limits.h>
2009-01-28 20:55:45 +00:00
# include <QDir>
# include <QMessageBox>
# include <QIcon>
2011-11-02 23:37:50 +00:00
# include <QList>
2009-01-28 20:55:45 +00:00
# include <QToolBar>
2009-02-05 20:55:00 +00:00
# include <QCloseEvent>
2009-02-08 14:02:27 +00:00
# include <QDesktopServices>
2009-01-28 20:55:45 +00:00
# include <set>
# include <map>
2013-11-16 18:34:09 +00:00
# include "gddebug.hh"
2011-06-27 18:54:15 +00:00
# include <QDebug>
2012-09-10 13:01:35 +00:00
# include <QTextStream>
2012-09-24 12:51:51 +00:00
# include "dictinfo.hh"
2012-11-28 19:32:37 +00:00
# include "fsencoding.hh"
# include <QProcess>
2013-01-17 09:08:53 +00:00
# include "historypanewidget.hh"
2013-05-27 11:18:13 +00:00
# include <QCryptographicHash>
2013-06-07 13:00:30 +00:00
# include <QRunnable>
# include <QThreadPool>
# include <QSslConfiguration>
2013-12-20 14:25:33 +00:00
# include <QDesktopWidget>
2014-04-03 14:21:02 +00:00
# include "ui_authentication.h"
2009-01-28 20:55:45 +00:00
2012-06-03 18:29:49 +00:00
# ifdef Q_OS_MAC
# include "lionsupport.h"
2013-12-26 14:13:10 +00:00
# include "macmouseover.hh"
2012-06-03 18:29:49 +00:00
# endif
2012-09-18 23:01:31 +00:00
# ifdef Q_OS_WIN32
# include <windows.h>
# include "mouseover_win32/GDDataTranfer.h"
2013-01-26 14:49:02 +00:00
# include "wstring.hh"
# include "wstring_qt.hh"
2013-12-20 14:25:33 +00:00
# define gdStoreNormalGeometryEvent ( ( QEvent::Type )( QEvent::User + 1 ) )
# define gdApplyNormalGeometryEvent ( ( QEvent::Type )( QEvent::User + 2 ) )
2012-09-18 23:01:31 +00:00
# endif
2012-12-29 10:01:36 +00:00
# ifdef Q_WS_X11
# include <QX11Info>
# include <X11/Xlib.h>
# endif
2014-04-18 12:33:44 +00:00
# define MIN_THREAD_COUNT 4
2009-01-28 20:55:45 +00:00
using std : : set ;
using std : : wstring ;
using std : : map ;
using std : : pair ;
2013-06-07 13:00:30 +00:00
# ifndef QT_NO_OPENSSL
class InitSSLRunnable : public QRunnable
{
virtual void run ( )
{
/// This action force SSL library initialisation which may continue a few seconds
QSslConfiguration : : setDefaultConfiguration ( QSslConfiguration : : defaultConfiguration ( ) ) ;
}
} ;
# endif
2009-04-12 20:46:25 +00:00
MainWindow : : MainWindow ( Config : : Class & cfg_ ) :
2010-06-28 15:14:07 +00:00
commitDataCompleted ( false ) ,
2009-02-05 20:55:00 +00:00
trayIcon ( 0 ) ,
2009-04-20 14:13:39 +00:00
groupLabel ( & searchPaneTitleBar ) ,
2011-06-05 11:49:50 +00:00
foundInDictsLabel ( & dictsPaneTitleBar ) ,
2010-04-27 07:49:37 +00:00
escAction ( this ) ,
2009-04-12 22:36:47 +00:00
focusTranslateLineAction ( this ) ,
2009-04-09 22:11:38 +00:00
addTabAction ( this ) ,
closeCurrentTabAction ( this ) ,
2010-09-16 18:52:40 +00:00
closeAllTabAction ( this ) ,
closeRestTabAction ( this ) ,
2009-04-09 22:11:38 +00:00
switchToNextTabAction ( this ) ,
switchToPrevTabAction ( this ) ,
2012-12-30 09:29:19 +00:00
showDictBarNamesAction ( tr ( " Show Names in Dictionary &Bar " ) , this ) ,
useSmallIconsInToolbarsAction ( tr ( " Show Small Icons in &Toolbars " ) , this ) ,
2011-06-26 11:53:28 +00:00
toggleMenuBarAction ( tr ( " &Menubar " ) , this ) ,
2012-09-16 10:19:47 +00:00
switchExpandModeAction ( this ) ,
2014-03-04 16:58:51 +00:00
focusHeadwordsDlgAction ( this ) ,
2009-02-08 20:20:02 +00:00
trayIconMenu ( this ) ,
2009-01-28 20:55:45 +00:00
addTab ( this ) ,
2009-04-12 20:46:25 +00:00
cfg ( cfg_ ) ,
2013-01-17 14:24:13 +00:00
history ( History : : Load ( ) , cfg_ . preferences . maxStringsInHistory , cfg_ . maxHeadwordSize ) ,
2013-06-11 18:31:01 +00:00
dictionaryBar ( this , configEvents , cfg . editDictionaryCommandLine , cfg . preferences . maxDictionaryRefsInContextMenu ) ,
2012-12-10 14:14:13 +00:00
articleMaker ( dictionaries , groupInstances , cfg . preferences . displayStyle ,
cfg . preferences . addonStyle ) ,
2009-08-31 12:18:08 +00:00
articleNetMgr ( this , dictionaries , articleMaker ,
2013-04-08 12:20:12 +00:00
cfg . preferences . disallowContentFromOtherSites , cfg . preferences . hideGoldenDictHeader ) ,
2009-03-26 19:00:08 +00:00
dictNetMgr ( this ) ,
2009-01-29 19:16:25 +00:00
wordFinder ( this ) ,
2012-11-25 11:37:57 +00:00
newReleaseCheckTimer ( this ) ,
2013-06-07 12:59:18 +00:00
latestReleaseReply ( 0 ) ,
2012-11-25 11:37:57 +00:00
wordListSelChanged ( false )
2013-01-23 20:36:53 +00:00
, wasMaximized ( false )
2013-01-31 13:01:08 +00:00
, blockUpdateWindowTitle ( false )
2014-03-03 13:46:41 +00:00
, headwordsDlg ( 0 )
2014-04-16 16:18:28 +00:00
, ftsIndexing ( dictionaries )
, ftsDlg ( 0 )
2012-12-13 16:17:44 +00:00
# ifdef Q_OS_WIN32
, gdAskMessage ( 0xFFFFFFFF )
# endif
2009-01-28 20:55:45 +00:00
{
2014-04-16 16:18:28 +00:00
if ( QThreadPool : : globalInstance ( ) - > maxThreadCount ( ) < MIN_THREAD_COUNT )
QThreadPool : : globalInstance ( ) - > setMaxThreadCount ( MIN_THREAD_COUNT ) ;
2013-06-07 13:00:30 +00:00
# ifndef QT_NO_OPENSSL
QThreadPool : : globalInstance ( ) - > start ( new InitSSLRunnable ) ;
# endif
2012-12-10 14:14:13 +00:00
applyQtStyleSheet ( cfg . preferences . displayStyle , cfg . preferences . addonStyle ) ;
2009-05-16 18:04:21 +00:00
2009-01-28 20:55:45 +00:00
ui . setupUi ( this ) ;
2013-06-02 11:20:33 +00:00
articleMaker . setCollapseParameters ( cfg . preferences . collapseBigArticles , cfg . preferences . articleSizeLimit ) ;
2014-02-04 13:35:42 +00:00
# if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
// Set own gesture recognizers
Gestures : : registerRecognizers ( ) ;
# endif
2011-06-27 18:54:15 +00:00
// use our own, cutsom statusbar
setStatusBar ( 0 ) ;
mainStatusBar = new MainStatusBar ( this ) ;
2009-01-28 20:55:45 +00:00
// Make the toolbar
2012-12-30 09:29:19 +00:00
navToolbar = addToolBar ( tr ( " &Navigation " ) ) ;
2009-04-03 21:24:07 +00:00
navToolbar - > setObjectName ( " navToolbar " ) ;
2009-01-28 20:55:45 +00:00
navBack = navToolbar - > addAction ( QIcon ( " :/icons/previous.png " ) , tr ( " Back " ) ) ;
2012-12-27 08:30:43 +00:00
navToolbar - > widgetForAction ( navBack ) - > setObjectName ( " backButton " ) ;
2009-01-28 20:55:45 +00:00
navForward = navToolbar - > addAction ( QIcon ( " :/icons/next.png " ) , tr ( " Forward " ) ) ;
2012-12-27 08:30:43 +00:00
navToolbar - > widgetForAction ( navForward ) - > setObjectName ( " forwardButton " ) ;
2009-04-18 18:47:01 +00:00
2013-02-07 15:24:24 +00:00
QWidget * translateBoxWidget = new QWidget ( this ) ;
QHBoxLayout * translateBoxLayout = new QHBoxLayout ( translateBoxWidget ) ;
translateBoxWidget - > setLayout ( translateBoxLayout ) ;
translateBoxLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
translateBoxLayout - > setSpacing ( 0 ) ;
2013-01-06 11:22:20 +00:00
// translate box
groupListInToolbar = new GroupComboBox ( navToolbar ) ;
2013-02-07 15:24:24 +00:00
groupListInToolbar - > setSizePolicy ( QSizePolicy : : Fixed , QSizePolicy : : Preferred ) ;
groupListInToolbar - > setSizeAdjustPolicy ( QComboBox : : AdjustToContents ) ;
translateBoxLayout - > addWidget ( groupListInToolbar ) ;
2013-01-06 11:22:20 +00:00
translateBox = new TranslateBox ( navToolbar ) ;
2013-02-07 18:15:34 +00:00
translateBox - > setSizePolicy ( QSizePolicy : : MinimumExpanding , QSizePolicy : : Fixed ) ;
2013-02-07 15:24:24 +00:00
translateBoxLayout - > addWidget ( translateBox ) ;
translateBoxToolBarAction = navToolbar - > addWidget ( translateBoxWidget ) ;
2013-01-06 11:22:20 +00:00
// scan popup
2012-12-26 13:46:04 +00:00
beforeScanPopupSeparator = navToolbar - > addSeparator ( ) ;
beforeScanPopupSeparator - > setVisible ( cfg . preferences . enableScanPopup ) ;
2012-12-27 08:30:43 +00:00
navToolbar - > widgetForAction ( beforeScanPopupSeparator ) - > setObjectName ( " beforeScanPopupSeparator " ) ;
2011-05-31 03:35:43 +00:00
2009-02-08 20:20:02 +00:00
enableScanPopup = navToolbar - > addAction ( QIcon ( " :/icons/wizard.png " ) , tr ( " Scan Popup " ) ) ;
enableScanPopup - > setCheckable ( true ) ;
enableScanPopup - > setVisible ( cfg . preferences . enableScanPopup ) ;
2013-01-06 11:22:20 +00:00
navToolbar - > widgetForAction ( enableScanPopup ) - > setObjectName ( " scanPopupButton " ) ;
2009-02-08 20:20:02 +00:00
if ( cfg . preferences . enableScanPopup & & cfg . preferences . startWithScanPopupOn )
enableScanPopup - > setChecked ( true ) ;
connect ( enableScanPopup , SIGNAL ( toggled ( bool ) ) ,
this , SLOT ( scanEnableToggled ( bool ) ) ) ;
2012-12-26 13:46:04 +00:00
afterScanPopupSeparator = navToolbar - > addSeparator ( ) ;
afterScanPopupSeparator - > setVisible ( cfg . preferences . enableScanPopup ) ;
2012-12-27 08:30:43 +00:00
navToolbar - > widgetForAction ( afterScanPopupSeparator ) - > setObjectName ( " afterScanPopupSeparator " ) ;
2012-12-26 13:46:04 +00:00
2013-01-06 11:22:20 +00:00
// sound
2013-08-21 08:02:46 +00:00
navPronounce = navToolbar - > addAction ( QIcon ( " :/icons/playsound_full.png " ) , tr ( " Pronounce Word (Alt+S) " ) ) ;
2009-05-14 19:46:25 +00:00
navPronounce - > setShortcut ( QKeySequence ( " Alt+S " ) ) ;
2009-04-10 21:07:03 +00:00
navPronounce - > setEnabled ( false ) ;
2012-12-27 08:30:43 +00:00
navToolbar - > widgetForAction ( navPronounce ) - > setObjectName ( " soundButton " ) ;
2009-04-10 21:07:03 +00:00
connect ( navPronounce , SIGNAL ( triggered ( ) ) ,
this , SLOT ( pronounce ( ) ) ) ;
2009-04-30 19:57:25 +00:00
// zooming
2012-12-26 17:16:21 +00:00
// named separator (to be able to hide it via CSS)
navToolbar - > widgetForAction ( navToolbar - > addSeparator ( ) ) - > setObjectName ( " separatorBeforeZoom " ) ;
2009-05-01 20:10:47 +00:00
zoomIn = navToolbar - > addAction ( QIcon ( " :/icons/icon32_zoomin.png " ) , tr ( " Zoom In " ) ) ;
2013-01-21 23:01:00 +00:00
zoomIn - > setShortcuts ( QList < QKeySequence > ( ) < <
QKeySequence : : ZoomIn < <
QKeySequence ( " Ctrl+= " ) ) ;
2012-12-26 17:16:21 +00:00
navToolbar - > widgetForAction ( zoomIn ) - > setObjectName ( " zoomInButton " ) ;
2009-05-01 20:10:47 +00:00
zoomOut = navToolbar - > addAction ( QIcon ( " :/icons/icon32_zoomout.png " ) , tr ( " Zoom Out " ) ) ;
2010-07-02 11:19:02 +00:00
zoomOut - > setShortcut ( QKeySequence : : ZoomOut ) ;
2012-12-26 17:16:21 +00:00
navToolbar - > widgetForAction ( zoomOut ) - > setObjectName ( " zoomOutButton " ) ;
2009-05-01 20:10:47 +00:00
zoomBase = navToolbar - > addAction ( QIcon ( " :/icons/icon32_zoombase.png " ) , tr ( " Normal Size " ) ) ;
2010-07-02 11:19:02 +00:00
zoomBase - > setShortcut ( QKeySequence ( " Ctrl+0 " ) ) ;
2012-12-26 17:16:21 +00:00
navToolbar - > widgetForAction ( zoomBase ) - > setObjectName ( " zoomBaseButton " ) ;
// named separator (to be able to hide it via CSS)
navToolbar - > widgetForAction ( navToolbar - > addSeparator ( ) ) - > setObjectName ( " separatorBeforeSave " ) ;
2009-04-30 19:57:25 +00:00
2012-12-26 13:46:04 +00:00
navToolbar - > addAction ( ui . saveArticle ) ;
2012-12-26 17:16:21 +00:00
navToolbar - > widgetForAction ( ui . saveArticle ) - > setObjectName ( " saveArticleButton " ) ;
2012-12-26 13:46:04 +00:00
navToolbar - > addAction ( ui . print ) ;
2012-12-26 17:16:21 +00:00
navToolbar - > widgetForAction ( ui . print ) - > setObjectName ( " printButton " ) ;
2012-12-26 13:46:04 +00:00
2012-12-29 18:46:43 +00:00
beforeOptionsSeparator = navToolbar - > addSeparator ( ) ;
navToolbar - > widgetForAction ( beforeOptionsSeparator ) - > setObjectName ( " beforeOptionsSeparator " ) ;
beforeOptionsSeparator - > setVisible ( cfg . preferences . hideMenubar ) ;
QMenu * buttonMenu = new QMenu ( this ) ;
buttonMenu - > addAction ( ui . dictionaries ) ;
buttonMenu - > addAction ( ui . preferences ) ;
buttonMenu - > addSeparator ( ) ;
buttonMenu - > addMenu ( ui . menuHistory ) ;
buttonMenu - > addSeparator ( ) ;
buttonMenu - > addMenu ( ui . menuFile ) ;
buttonMenu - > addMenu ( ui . menuView ) ;
2014-04-16 16:18:28 +00:00
buttonMenu - > addMenu ( ui . menuSearch ) ;
2012-12-29 18:46:43 +00:00
buttonMenu - > addMenu ( ui . menu_Help ) ;
2014-04-17 14:31:51 +00:00
ui . fullTextSearchAction - > setEnabled ( cfg . preferences . fts . enabled ) ;
2013-01-23 13:40:49 +00:00
menuButton = new QToolButton ( navToolbar ) ;
2012-12-29 18:46:43 +00:00
menuButton - > setPopupMode ( QToolButton : : InstantPopup ) ;
menuButton - > setMenu ( buttonMenu ) ;
menuButton - > setIcon ( QIcon ( " :/icons/menu_button.png " ) ) ;
menuButton - > addAction ( ui . menuOptions ) ;
menuButton - > setToolTip ( tr ( " Menu Button " ) ) ;
menuButton - > setObjectName ( " menuButton " ) ;
2012-12-31 18:23:14 +00:00
menuButton - > setFocusPolicy ( Qt : : NoFocus ) ;
2012-12-29 18:46:43 +00:00
menuButtonAction = navToolbar - > addWidget ( menuButton ) ;
menuButtonAction - > setVisible ( cfg . preferences . hideMenubar ) ;
2012-12-24 11:30:03 +00:00
// Make the search pane's titlebar
groupLabel . setText ( tr ( " Look up in: " ) ) ;
groupListInDock = new GroupComboBox ( & searchPaneTitleBar ) ;
searchPaneTitleBarLayout . setContentsMargins ( 8 , 5 , 8 , 4 ) ;
searchPaneTitleBarLayout . addWidget ( & groupLabel ) ;
searchPaneTitleBarLayout . addWidget ( groupListInDock ) ;
searchPaneTitleBarLayout . addStretch ( ) ;
searchPaneTitleBar . setLayout ( & searchPaneTitleBarLayout ) ;
ui . searchPane - > setTitleBarWidget ( & searchPaneTitleBar ) ;
2013-01-05 11:26:55 +00:00
connect ( ui . searchPane - > toggleViewAction ( ) , SIGNAL ( triggered ( bool ) ) ,
this , SLOT ( updateSearchPaneAndBar ( bool ) ) ) ;
2012-12-24 11:30:03 +00:00
2013-01-05 11:26:55 +00:00
if ( cfg . preferences . searchInDock )
2012-12-24 11:30:03 +00:00
{
groupList = groupListInDock ;
translateLine = ui . translateLine ;
wordList = ui . wordList ;
}
else
{
groupList = groupListInToolbar ;
translateLine = translateBox - > translateLine ( ) ;
wordList = translateBox - > wordList ( ) ;
}
2013-01-25 15:42:44 +00:00
wordList - > attachFinder ( & wordFinder ) ;
// for the old UI:
ui . wordList - > setTranslateLine ( ui . translateLine ) ;
2012-12-24 11:30:03 +00:00
groupList - > setFocusPolicy ( Qt : : ClickFocus ) ;
wordList - > setFocusPolicy ( Qt : : ClickFocus ) ;
wordListDefaultFont = wordList - > font ( ) ;
translateLineDefaultFont = translateLine - > font ( ) ;
// Make the dictionaries pane's titlebar
foundInDictsLabel . setText ( tr ( " Found in Dictionaries: " ) ) ;
dictsPaneTitleBarLayout . addWidget ( & foundInDictsLabel ) ;
2012-12-27 12:11:11 +00:00
dictsPaneTitleBarLayout . setContentsMargins ( 5 , 5 , 5 , 5 ) ;
2012-12-24 11:30:03 +00:00
dictsPaneTitleBar . setLayout ( & dictsPaneTitleBarLayout ) ;
2012-12-27 12:11:11 +00:00
dictsPaneTitleBar . setObjectName ( " dictsPaneTitleBar " ) ;
2012-12-24 11:30:03 +00:00
ui . dictsPane - > setTitleBarWidget ( & dictsPaneTitleBar ) ;
ui . dictsList - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui . dictsPane , SIGNAL ( visibilityChanged ( bool ) ) ,
this , SLOT ( dictsPaneVisibilityChanged ( bool ) ) ) ;
connect ( ui . dictsList , SIGNAL ( itemClicked ( QListWidgetItem * ) ) ,
this , SLOT ( foundDictsPaneClicked ( QListWidgetItem * ) ) ) ;
connect ( ui . dictsList , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) ,
this , SLOT ( foundDictsContextMenuRequested ( const QPoint & ) ) ) ;
2009-04-30 19:57:25 +00:00
connect ( zoomIn , SIGNAL ( triggered ( ) ) ,
this , SLOT ( zoomin ( ) ) ) ;
connect ( zoomOut , SIGNAL ( triggered ( ) ) ,
this , SLOT ( zoomout ( ) ) ) ;
connect ( zoomBase , SIGNAL ( triggered ( ) ) ,
this , SLOT ( unzoom ( ) ) ) ;
2010-07-02 11:19:02 +00:00
ui . menuZoom - > addAction ( zoomIn ) ;
ui . menuZoom - > addAction ( zoomOut ) ;
ui . menuZoom - > addAction ( zoomBase ) ;
ui . menuZoom - > addSeparator ( ) ;
wordsZoomIn = ui . menuZoom - > addAction ( QIcon ( " :/icons/icon32_zoomin.png " ) , tr ( " Words Zoom In " ) ) ;
2013-01-21 23:01:00 +00:00
wordsZoomIn - > setShortcuts ( QList < QKeySequence > ( ) < <
QKeySequence ( " Alt++ " ) < <
QKeySequence ( " Alt+= " ) ) ;
2010-07-02 11:19:02 +00:00
wordsZoomOut = ui . menuZoom - > addAction ( QIcon ( " :/icons/icon32_zoomout.png " ) , tr ( " Words Zoom Out " ) ) ;
wordsZoomOut - > setShortcut ( QKeySequence ( " Alt+- " ) ) ;
wordsZoomBase = ui . menuZoom - > addAction ( QIcon ( " :/icons/icon32_zoombase.png " ) , tr ( " Words Normal Size " ) ) ;
wordsZoomBase - > setShortcut ( QKeySequence ( " Alt+0 " ) ) ;
connect ( wordsZoomIn , SIGNAL ( triggered ( ) ) , this , SLOT ( doWordsZoomIn ( ) ) ) ;
connect ( wordsZoomOut , SIGNAL ( triggered ( ) ) , this , SLOT ( doWordsZoomOut ( ) ) ) ;
connect ( wordsZoomBase , SIGNAL ( triggered ( ) ) , this , SLOT ( doWordsZoomBase ( ) ) ) ;
2009-04-30 19:57:25 +00:00
// tray icon
2012-12-04 08:33:47 +00:00
connect ( trayIconMenu . addAction ( tr ( " Show &Main Window " ) ) , SIGNAL ( triggered ( ) ) ,
2009-02-08 20:20:02 +00:00
this , SLOT ( showMainWindow ( ) ) ) ;
trayIconMenu . addAction ( enableScanPopup ) ;
trayIconMenu . addSeparator ( ) ;
2012-12-04 08:33:47 +00:00
connect ( trayIconMenu . addAction ( tr ( " &Quit " ) ) , SIGNAL ( triggered ( ) ) ,
2009-02-08 20:20:02 +00:00
qApp , SLOT ( quit ( ) ) ) ;
2009-04-08 22:25:46 +00:00
2010-04-27 07:49:37 +00:00
escAction . setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
escAction . setShortcut ( QKeySequence ( " Esc " ) ) ;
connect ( & escAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( handleEsc ( ) ) ) ;
2009-04-12 22:36:47 +00:00
focusTranslateLineAction . setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
2010-01-13 18:04:39 +00:00
focusTranslateLineAction . setShortcuts ( QList < QKeySequence > ( ) < <
QKeySequence ( " Alt+D " ) < <
QKeySequence ( " Ctrl+L " ) ) ;
2009-04-08 22:25:46 +00:00
2009-04-12 22:36:47 +00:00
connect ( & focusTranslateLineAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( focusTranslateLine ( ) ) ) ;
2009-04-08 22:25:46 +00:00
2014-03-04 16:58:51 +00:00
focusHeadwordsDlgAction . setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
focusHeadwordsDlgAction . setShortcut ( QKeySequence ( " Ctrl+D " ) ) ;
connect ( & focusHeadwordsDlgAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( focusHeadwordsDialog ( ) ) ) ;
2010-04-27 07:49:37 +00:00
ui . centralWidget - > addAction ( & escAction ) ;
2011-06-05 11:49:50 +00:00
ui . dictsPane - > addAction ( & escAction ) ;
2010-04-27 07:49:37 +00:00
ui . searchPaneWidget - > addAction ( & escAction ) ;
2013-01-17 09:08:53 +00:00
ui . historyPane - > addAction ( & escAction ) ;
2012-12-24 11:30:03 +00:00
groupList - > addAction ( & escAction ) ;
2013-01-02 09:55:23 +00:00
translateBox - > addAction ( & escAction ) ;
2011-06-05 11:49:50 +00:00
2009-04-12 22:36:47 +00:00
ui . centralWidget - > addAction ( & focusTranslateLineAction ) ;
2011-06-05 11:49:50 +00:00
ui . dictsPane - > addAction ( & focusTranslateLineAction ) ;
2009-04-20 13:24:55 +00:00
ui . searchPaneWidget - > addAction ( & focusTranslateLineAction ) ;
2013-01-17 09:08:53 +00:00
ui . historyPane - > addAction ( & focusTranslateLineAction ) ;
2012-12-24 11:30:03 +00:00
groupList - > addAction ( & focusTranslateLineAction ) ;
2009-04-08 22:25:46 +00:00
2014-03-04 16:58:51 +00:00
ui . centralWidget - > addAction ( & focusHeadwordsDlgAction ) ;
ui . dictsPane - > addAction ( & focusHeadwordsDlgAction ) ;
ui . searchPaneWidget - > addAction ( & focusHeadwordsDlgAction ) ;
ui . historyPane - > addAction ( & focusHeadwordsDlgAction ) ;
groupList - > addAction ( & focusHeadwordsDlgAction ) ;
translateBox - > addAction ( & focusHeadwordsDlgAction ) ;
2014-04-16 16:18:28 +00:00
connect ( ui . fullTextSearchAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( showFullTextSearchDialog ( ) ) ) ;
ui . centralWidget - > addAction ( ui . fullTextSearchAction ) ;
ui . dictsPane - > addAction ( ui . fullTextSearchAction ) ;
ui . searchPaneWidget - > addAction ( ui . fullTextSearchAction ) ;
ui . historyPane - > addAction ( ui . fullTextSearchAction ) ;
groupList - > addAction ( ui . fullTextSearchAction ) ;
translateBox - > addAction ( ui . fullTextSearchAction ) ;
2009-04-09 22:11:38 +00:00
addTabAction . setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
addTabAction . setShortcut ( QKeySequence ( " Ctrl+T " ) ) ;
2010-09-16 18:52:40 +00:00
// Tab management
2011-11-02 23:37:50 +00:00
tabListMenu = new MRUQMenu ( tr ( " Opened tabs " ) , ui . tabWidget ) ;
connect ( tabListMenu , SIGNAL ( ctrlReleased ( ) ) , this , SLOT ( ctrlReleased ( ) ) ) ;
2010-09-16 18:52:40 +00:00
2009-04-09 22:11:38 +00:00
connect ( & addTabAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( addNewTab ( ) ) ) ;
2009-04-29 23:55:41 +00:00
addAction ( & addTabAction ) ;
2009-04-09 22:11:38 +00:00
closeCurrentTabAction . setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
closeCurrentTabAction . setShortcut ( QKeySequence ( " Ctrl+W " ) ) ;
2010-09-16 18:52:40 +00:00
closeCurrentTabAction . setText ( tr ( " Close current tab " ) ) ;
closeCurrentTabAction . setIcon ( QIcon ( " :/icons/closetab.png " ) ) ;
2009-04-09 22:11:38 +00:00
connect ( & closeCurrentTabAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( closeCurrentTab ( ) ) ) ;
2009-04-29 23:55:41 +00:00
addAction ( & closeCurrentTabAction ) ;
2009-04-09 22:11:38 +00:00
2010-09-16 18:52:40 +00:00
closeAllTabAction . setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
closeAllTabAction . setShortcut ( QKeySequence ( " Ctrl+Shift+W " ) ) ;
closeAllTabAction . setText ( tr ( " Close all tabs " ) ) ;
connect ( & closeAllTabAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( closeAllTabs ( ) ) ) ;
addAction ( & closeAllTabAction ) ;
closeRestTabAction . setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
closeRestTabAction . setText ( tr ( " Close all tabs except current " ) ) ;
connect ( & closeRestTabAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( closeRestTabs ( ) ) ) ;
addAction ( & closeRestTabAction ) ;
2009-04-09 22:11:38 +00:00
switchToNextTabAction . setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
switchToNextTabAction . setShortcut ( QKeySequence ( " Ctrl+PgDown " ) ) ;
connect ( & switchToNextTabAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( switchToNextTab ( ) ) ) ;
2009-04-29 23:55:41 +00:00
addAction ( & switchToNextTabAction ) ;
2009-04-09 22:11:38 +00:00
switchToPrevTabAction . setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
switchToPrevTabAction . setShortcut ( QKeySequence ( " Ctrl+PgUp " ) ) ;
connect ( & switchToPrevTabAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( switchToPrevTab ( ) ) ) ;
2009-04-29 23:55:41 +00:00
addAction ( & switchToPrevTabAction ) ;
2009-04-09 22:11:38 +00:00
2012-09-16 10:19:47 +00:00
switchExpandModeAction . setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
switchExpandModeAction . setShortcuts ( QList < QKeySequence > ( ) < <
QKeySequence ( Qt : : CTRL + Qt : : Key_8 ) < <
QKeySequence ( Qt : : CTRL + Qt : : Key_Asterisk ) < <
QKeySequence ( Qt : : CTRL + Qt : : SHIFT + Qt : : Key_8 ) ) ;
connect ( & switchExpandModeAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( switchExpandOptionalPartsMode ( ) ) ) ;
addAction ( & switchExpandModeAction ) ;
2009-10-12 12:41:20 +00:00
2010-09-16 18:52:40 +00:00
tabMenu = new QMenu ( this ) ;
tabMenu - > addAction ( & closeCurrentTabAction ) ;
tabMenu - > addAction ( & closeRestTabAction ) ;
tabMenu - > addSeparator ( ) ;
tabMenu - > addAction ( & closeAllTabAction ) ;
// Dictionary bar names
2009-10-12 12:41:20 +00:00
showDictBarNamesAction . setCheckable ( true ) ;
showDictBarNamesAction . setChecked ( cfg . showingDictBarNames ) ;
connect ( & showDictBarNamesAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( showDictBarNamesTriggered ( ) ) ) ;
2011-05-22 02:42:05 +00:00
// Use small icons in toolbars
useSmallIconsInToolbarsAction . setCheckable ( true ) ;
useSmallIconsInToolbarsAction . setChecked ( cfg . usingSmallIconsInToolbars ) ;
connect ( & useSmallIconsInToolbarsAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( useSmallIconsInToolbarsTriggered ( ) ) ) ;
2011-06-26 11:53:28 +00:00
// Toggle Menubar
toggleMenuBarAction . setCheckable ( true ) ;
2012-12-29 20:24:48 +00:00
toggleMenuBarAction . setChecked ( ! cfg . preferences . hideMenubar ) ;
2011-06-26 11:53:28 +00:00
toggleMenuBarAction . setShortcut ( QKeySequence ( " Ctrl+M " ) ) ;
connect ( & toggleMenuBarAction , SIGNAL ( triggered ( ) ) ,
this , SLOT ( toggleMenuBarTriggered ( ) ) ) ;
2011-05-22 02:42:05 +00:00
// Populate 'View' menu
2009-09-23 18:44:38 +00:00
2011-06-26 11:53:28 +00:00
ui . menuView - > addAction ( & toggleMenuBarAction ) ;
2013-01-17 09:08:53 +00:00
ui . menuView - > addSeparator ( ) ;
2009-09-23 18:44:38 +00:00
ui . menuView - > addAction ( ui . searchPane - > toggleViewAction ( ) ) ;
2012-12-30 10:06:58 +00:00
ui . searchPane - > toggleViewAction ( ) - > setShortcut ( QKeySequence ( " Ctrl+S " ) ) ;
2011-06-05 11:49:50 +00:00
ui . menuView - > addAction ( ui . dictsPane - > toggleViewAction ( ) ) ;
2012-12-30 10:06:58 +00:00
ui . dictsPane - > toggleViewAction ( ) - > setShortcut ( QKeySequence ( " Ctrl+R " ) ) ;
2013-01-17 09:08:53 +00:00
ui . menuView - > addAction ( ui . historyPane - > toggleViewAction ( ) ) ;
ui . historyPane - > toggleViewAction ( ) - > setShortcut ( QKeySequence ( " Ctrl+H " ) ) ;
2009-09-23 18:44:38 +00:00
ui . menuView - > addSeparator ( ) ;
ui . menuView - > addAction ( dictionaryBar . toggleViewAction ( ) ) ;
ui . menuView - > addAction ( navToolbar - > toggleViewAction ( ) ) ;
2009-10-12 12:41:20 +00:00
ui . menuView - > addSeparator ( ) ;
ui . menuView - > addAction ( & showDictBarNamesAction ) ;
2011-05-22 02:42:05 +00:00
ui . menuView - > addAction ( & useSmallIconsInToolbarsAction ) ;
2012-12-29 11:19:49 +00:00
ui . menuView - > addSeparator ( ) ;
ui . alwaysOnTop - > setChecked ( cfg . preferences . alwaysOnTop ) ;
ui . menuView - > addAction ( ui . alwaysOnTop ) ;
2009-09-23 18:44:38 +00:00
2009-09-21 17:50:03 +00:00
// Dictionary bar
2012-09-26 13:13:47 +00:00
Instances : : Group const * igrp = groupInstances . findGroup ( cfg . lastMainGroupId ) ;
if ( cfg . lastMainGroupId = = Instances : : Group : : AllGroupId )
{
if ( igrp )
igrp - > checkMutedDictionaries ( & cfg . mutedDictionaries ) ;
dictionaryBar . setMutedDictionaries ( & cfg . mutedDictionaries ) ;
}
else
{
Config : : Group * grp = cfg . getGroup ( cfg . lastMainGroupId ) ;
if ( igrp & & grp )
igrp - > checkMutedDictionaries ( & grp - > mutedDictionaries ) ;
dictionaryBar . setMutedDictionaries ( grp ? & grp - > mutedDictionaries : 0 ) ;
}
2009-10-12 12:41:20 +00:00
showDictBarNamesTriggered ( ) ; // Make update its state according to initial
// setting
2011-05-22 02:42:05 +00:00
useSmallIconsInToolbarsTriggered ( ) ;
2012-09-19 12:44:36 +00:00
connect ( this , SIGNAL ( clickOnDictPane ( QString const & ) ) ,
& dictionaryBar , SLOT ( dictsPaneClicked ( QString const & ) ) ) ;
2009-09-21 17:50:03 +00:00
addToolBar ( & dictionaryBar ) ;
2009-09-24 12:20:20 +00:00
connect ( dictionaryBar . toggleViewAction ( ) , SIGNAL ( triggered ( bool ) ) ,
this , SLOT ( dictionaryBarToggled ( bool ) ) ) ;
// This one will be disconnected once the slot is activated. It exists
// only to handle the initial appearance of the dictionary bar.
2009-09-23 18:44:38 +00:00
connect ( dictionaryBar . toggleViewAction ( ) , SIGNAL ( toggled ( bool ) ) ,
this , SLOT ( dictionaryBarToggled ( bool ) ) ) ;
2010-05-08 14:01:59 +00:00
connect ( & dictionaryBar , SIGNAL ( editGroupRequested ( ) ) ,
this , SLOT ( editCurrentGroup ( ) ) ) ;
2012-09-25 13:13:35 +00:00
connect ( & dictionaryBar , SIGNAL ( showDictionaryInfo ( QString const & ) ) ,
this , SLOT ( showDictionaryInfo ( QString const & ) ) ) ;
2014-03-01 13:11:14 +00:00
connect ( & dictionaryBar , SIGNAL ( showDictionaryHeadwords ( QString const & ) ) ,
this , SLOT ( showDictionaryHeadwords ( QString const & ) ) ) ;
2013-06-09 13:31:57 +00:00
connect ( & dictionaryBar , SIGNAL ( openDictionaryFolder ( QString const & ) ) ,
this , SLOT ( openDictionaryFolder ( QString const & ) ) ) ;
2009-10-21 19:37:07 +00:00
// History
2013-01-17 09:08:53 +00:00
ui . historyPaneWidget - > setUp ( & cfg , & history , ui . menuHistory ) ;
2012-09-11 13:03:10 +00:00
history . enableAdd ( cfg . preferences . storeHistory ) ;
2009-11-01 16:20:26 +00:00
2013-01-17 09:08:53 +00:00
connect ( ui . historyPaneWidget , SIGNAL ( historyItemRequested ( QString const & ) ) ,
this , SLOT ( showHistoryItem ( QString const & ) ) ) ;
connect ( ui . historyPane , SIGNAL ( visibilityChanged ( bool ) ) ,
this , SLOT ( updateHistoryMenu ( ) ) ) ;
connect ( ui . menuHistory , SIGNAL ( aboutToShow ( ) ) ,
this , SLOT ( updateHistoryMenu ( ) ) ) ;
2009-10-09 21:03:55 +00:00
// Show tray icon early so the user would be happy. It won't be functional
// though until the program inits fully.
2009-01-28 20:55:45 +00:00
2009-10-09 21:03:55 +00:00
if ( cfg . preferences . enableTrayIcon )
{
2013-07-19 17:07:32 +00:00
trayIcon = new QSystemTrayIcon ( QIcon ( " :/icons/programicon_old.png " ) , this ) ;
2009-02-08 20:20:02 +00:00
trayIcon - > setToolTip ( tr ( " Loading... " ) ) ;
2009-10-09 21:03:55 +00:00
trayIcon - > show ( ) ;
}
2009-04-18 18:47:01 +00:00
2012-12-04 08:33:47 +00:00
connect ( navBack , SIGNAL ( triggered ( ) ) ,
2009-01-28 20:55:45 +00:00
this , SLOT ( backClicked ( ) ) ) ;
2012-12-04 08:33:47 +00:00
connect ( navForward , SIGNAL ( triggered ( ) ) ,
2009-01-28 20:55:45 +00:00
this , SLOT ( forwardClicked ( ) ) ) ;
addTab . setAutoRaise ( true ) ;
2011-07-10 10:29:52 +00:00
addTab . setToolTip ( tr ( " New Tab " ) ) ;
2011-06-28 15:55:41 +00:00
addTab . setFocusPolicy ( Qt : : ClickFocus ) ;
2009-01-28 20:55:45 +00:00
addTab . setIcon ( QIcon ( " :/icons/addtab.png " ) ) ;
2011-06-23 14:17:09 +00:00
ui . tabWidget - > setHideSingleTab ( cfg . preferences . hideSingleTab ) ;
2009-01-28 20:55:45 +00:00
ui . tabWidget - > clear ( ) ;
ui . tabWidget - > setCornerWidget ( & addTab , Qt : : TopLeftCorner ) ;
//ui.tabWidget->setCornerWidget( &closeTab, Qt::TopRightCorner );
2009-04-29 23:18:26 +00:00
# if QT_VERSION >= 0x040500
2009-01-28 20:55:45 +00:00
ui . tabWidget - > setMovable ( true ) ;
2009-04-29 23:18:26 +00:00
# endif
# ifndef Q_OS_WIN32
2009-01-28 20:55:45 +00:00
ui . tabWidget - > setDocumentMode ( true ) ;
2009-04-29 23:18:26 +00:00
# endif
2009-01-28 20:55:45 +00:00
2010-09-16 18:52:40 +00:00
ui . tabWidget - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2009-01-28 20:55:45 +00:00
connect ( & addTab , SIGNAL ( clicked ( ) ) ,
this , SLOT ( addNewTab ( ) ) ) ;
2011-07-19 10:03:13 +00:00
connect ( ui . tabWidget , SIGNAL ( doubleClicked ( ) ) ,
this , SLOT ( addNewTab ( ) ) ) ;
2009-01-28 20:55:45 +00:00
connect ( ui . tabWidget , SIGNAL ( tabCloseRequested ( int ) ) ,
this , SLOT ( tabCloseRequested ( int ) ) ) ;
2009-04-10 21:07:03 +00:00
connect ( ui . tabWidget , SIGNAL ( currentChanged ( int ) ) ,
this , SLOT ( tabSwitched ( int ) ) ) ;
2010-09-16 18:52:40 +00:00
connect ( ui . tabWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) ,
this , SLOT ( tabMenuRequested ( QPoint ) ) ) ;
2009-04-29 23:18:26 +00:00
# if QT_VERSION >= 0x040500
2009-01-28 20:55:45 +00:00
ui . tabWidget - > setTabsClosable ( true ) ;
2009-04-29 23:18:26 +00:00
# endif
2009-01-28 20:55:45 +00:00
2012-12-04 08:33:47 +00:00
connect ( ui . quit , SIGNAL ( triggered ( ) ) ,
2009-02-05 20:55:00 +00:00
qApp , SLOT ( quit ( ) ) ) ;
2012-12-04 08:33:47 +00:00
connect ( ui . dictionaries , SIGNAL ( triggered ( ) ) ,
2009-04-30 15:29:03 +00:00
this , SLOT ( editDictionaries ( ) ) ) ;
2009-01-28 20:55:45 +00:00
2012-12-04 08:33:47 +00:00
connect ( ui . preferences , SIGNAL ( triggered ( ) ) ,
2009-02-05 20:55:00 +00:00
this , SLOT ( editPreferences ( ) ) ) ;
2009-04-18 18:47:01 +00:00
2012-12-04 08:33:47 +00:00
connect ( ui . visitHomepage , SIGNAL ( triggered ( ) ) ,
2009-02-08 14:02:27 +00:00
this , SLOT ( visitHomepage ( ) ) ) ;
2012-12-04 08:33:47 +00:00
connect ( ui . visitForum , SIGNAL ( triggered ( ) ) ,
2009-02-08 14:02:27 +00:00
this , SLOT ( visitForum ( ) ) ) ;
2012-12-04 08:33:47 +00:00
connect ( ui . openConfigFolder , SIGNAL ( triggered ( ) ) ,
2011-07-10 07:36:43 +00:00
this , SLOT ( openConfigFolder ( ) ) ) ;
2012-12-04 08:33:47 +00:00
connect ( ui . about , SIGNAL ( triggered ( ) ) ,
2009-02-08 14:02:27 +00:00
this , SLOT ( showAbout ( ) ) ) ;
2009-02-05 20:55:00 +00:00
2012-12-24 11:30:03 +00:00
connect ( groupListInDock , SIGNAL ( currentIndexChanged ( QString const & ) ) ,
this , SLOT ( currentGroupChanged ( QString const & ) ) ) ;
connect ( groupListInToolbar , SIGNAL ( currentIndexChanged ( QString const & ) ) ,
2009-02-06 17:04:11 +00:00
this , SLOT ( currentGroupChanged ( QString const & ) ) ) ;
2009-01-28 20:55:45 +00:00
connect ( ui . translateLine , SIGNAL ( textChanged ( QString const & ) ) ,
this , SLOT ( translateInputChanged ( QString const & ) ) ) ;
2009-04-18 18:47:01 +00:00
2012-12-24 11:30:03 +00:00
connect ( translateBox - > translateLine ( ) , SIGNAL ( textChanged ( QString const & ) ) ,
this , SLOT ( translateInputChanged ( QString const & ) ) ) ;
2009-02-08 14:02:27 +00:00
connect ( ui . translateLine , SIGNAL ( returnPressed ( ) ) ,
this , SLOT ( translateInputFinished ( ) ) ) ;
2009-01-28 20:55:45 +00:00
2012-12-24 11:30:03 +00:00
connect ( translateBox - > translateLine ( ) , SIGNAL ( returnPressed ( ) ) ,
this , SLOT ( translateInputFinished ( ) ) ) ;
2012-12-24 21:56:31 +00:00
connect ( ui . wordList , SIGNAL ( itemSelectionChanged ( ) ) ,
this , SLOT ( wordListSelectionChanged ( ) ) ) ;
connect ( translateBox - > wordList ( ) , SIGNAL ( itemDoubleClicked ( QListWidgetItem * ) ) ,
this , SLOT ( wordListItemActivated ( QListWidgetItem * ) ) ) ;
2009-04-18 18:47:01 +00:00
2012-11-25 11:37:57 +00:00
connect ( ui . wordList , SIGNAL ( itemClicked ( QListWidgetItem * ) ) ,
this , SLOT ( wordListItemActivated ( QListWidgetItem * ) ) ) ;
2013-01-25 15:42:44 +00:00
connect ( ui . wordList , SIGNAL ( statusBarMessage ( QString const & , int , QPixmap const & ) ) ,
this , SLOT ( showStatusBarMessage ( QString const & , int , QPixmap const & ) ) ) ;
connect ( translateBox - > wordList ( ) , SIGNAL ( statusBarMessage ( QString const & , int , QPixmap const & ) ) ,
this , SLOT ( showStatusBarMessage ( QString const & , int , QPixmap const & ) ) ) ;
2011-06-05 11:49:50 +00:00
connect ( ui . dictsList , SIGNAL ( itemSelectionChanged ( ) ) ,
this , SLOT ( dictsListSelectionChanged ( ) ) ) ;
2013-06-28 16:00:13 +00:00
connect ( ui . dictsList , SIGNAL ( itemDoubleClicked ( QListWidgetItem * ) ) ,
this , SLOT ( dictsListItemActivated ( QListWidgetItem * ) ) ) ;
2009-09-23 18:44:38 +00:00
connect ( & configEvents , SIGNAL ( mutedDictionariesChanged ( ) ) ,
this , SLOT ( mutedDictionariesChanged ( ) ) ) ;
2012-12-25 09:25:54 +00:00
this - > installEventFilter ( this ) ;
2009-03-29 17:38:54 +00:00
ui . translateLine - > installEventFilter ( this ) ;
2012-12-24 11:30:03 +00:00
translateBox - > translateLine ( ) - > installEventFilter ( this ) ;
2009-03-29 17:38:54 +00:00
ui . wordList - > installEventFilter ( this ) ;
2012-12-24 11:30:03 +00:00
translateBox - > wordList ( ) - > installEventFilter ( this ) ;
2011-06-07 08:26:49 +00:00
ui . wordList - > viewport ( ) - > installEventFilter ( this ) ;
2012-12-24 11:30:03 +00:00
translateBox - > wordList ( ) - > viewport ( ) - > installEventFilter ( this ) ;
2011-06-07 08:26:49 +00:00
ui . dictsList - > installEventFilter ( this ) ;
ui . dictsList - > viewport ( ) - > installEventFilter ( this ) ;
2011-11-02 23:37:50 +00:00
//tabWidget doesn't propagate Ctrl+Tab to the parent widget unless event filter is installed
ui . tabWidget - > installEventFilter ( this ) ;
2009-03-29 17:38:54 +00:00
2013-01-17 09:08:53 +00:00
ui . historyList - > installEventFilter ( this ) ;
2013-02-04 14:10:37 +00:00
# ifdef Q_OS_WIN
2013-12-20 14:25:33 +00:00
if ( cfg . normalMainWindowGeometry . width ( ) < = 0 )
{
QRect r = QApplication : : desktop ( ) - > availableGeometry ( ) ;
cfg . normalMainWindowGeometry . setRect ( r . width ( ) / 4 , r . height ( ) / 4 , r . width ( ) / 2 , r . height ( ) / 2 ) ;
}
2013-01-29 19:20:53 +00:00
if ( cfg . maximizedMainWindowGeometry . width ( ) > 0 )
{
2013-12-20 14:25:33 +00:00
setGeometry ( cfg . maximizedMainWindowGeometry ) ;
2013-01-29 19:20:53 +00:00
if ( cfg . mainWindowGeometry . size ( ) )
restoreGeometry ( cfg . mainWindowGeometry ) ;
if ( cfg . mainWindowState . size ( ) )
restoreState ( cfg . mainWindowState , 1 ) ;
setWindowState ( windowState ( ) | Qt : : WindowMaximized ) ;
}
else
2013-02-04 14:10:37 +00:00
# endif
2013-01-29 19:20:53 +00:00
{
if ( cfg . mainWindowGeometry . size ( ) )
restoreGeometry ( cfg . mainWindowGeometry ) ;
if ( cfg . mainWindowState . size ( ) )
restoreState ( cfg . mainWindowState , 1 ) ;
}
2009-04-03 21:24:07 +00:00
2013-01-05 11:26:55 +00:00
updateSearchPaneAndBar ( cfg . preferences . searchInDock ) ;
ui . searchPane - > setVisible ( cfg . preferences . searchInDock ) ;
2009-04-03 17:10:27 +00:00
applyProxySettings ( ) ;
2011-05-08 21:19:08 +00:00
applyWebSettings ( ) ;
2009-04-03 17:10:27 +00:00
2014-04-03 14:21:02 +00:00
connect ( & dictNetMgr , SIGNAL ( proxyAuthenticationRequired ( QNetworkProxy , QAuthenticator * ) ) ,
this , SLOT ( proxyAuthentication ( QNetworkProxy , QAuthenticator * ) ) ) ;
connect ( & articleNetMgr , SIGNAL ( proxyAuthenticationRequired ( QNetworkProxy , QAuthenticator * ) ) ,
this , SLOT ( proxyAuthentication ( QNetworkProxy , QAuthenticator * ) ) ) ;
2009-01-28 20:55:45 +00:00
makeDictionaries ( ) ;
2009-10-21 19:37:07 +00:00
// After we have dictionaries and groups, we can populate history
2012-02-16 14:56:25 +00:00
// historyChanged();
2009-10-21 19:37:07 +00:00
2013-02-01 12:36:01 +00:00
setWindowTitle ( " GoldenDict " ) ;
2013-01-31 13:01:08 +00:00
blockUpdateWindowTitle = true ;
2009-01-28 20:55:45 +00:00
addNewTab ( ) ;
2009-01-29 19:16:25 +00:00
2010-09-16 18:52:40 +00:00
// Create tab list menu
createTabList ( ) ;
2009-02-08 18:35:29 +00:00
// Show the initial welcome text
{
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
2009-02-08 18:35:29 +00:00
2013-01-20 18:25:12 +00:00
history . enableAdd ( false ) ;
2013-01-31 13:01:08 +00:00
blockUpdateWindowTitle = true ;
2011-07-01 19:22:40 +00:00
view - > showDefinition ( tr ( " Welcome! " ) , Instances : : Group : : HelpGroupId ) ;
2013-01-20 18:25:12 +00:00
history . enableAdd ( cfg . preferences . storeHistory ) ;
2009-02-08 18:35:29 +00:00
}
2009-04-18 18:47:01 +00:00
2012-12-24 11:30:03 +00:00
translateLine - > setFocus ( ) ;
2009-02-05 20:55:00 +00:00
2009-10-09 21:03:55 +00:00
if ( trayIcon )
{
// Upgrade existing dummy tray icon into a full-functional one
trayIcon - > setContextMenu ( & trayIconMenu ) ;
trayIcon - > show ( ) ;
connect ( trayIcon , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) ,
this , SLOT ( trayIconActivated ( QSystemTrayIcon : : ActivationReason ) ) ) ;
}
2009-02-05 20:55:00 +00:00
updateTrayIcon ( ) ;
2009-04-30 22:09:04 +00:00
// Update zoomers
applyZoomFactor ( ) ;
2010-07-02 11:19:02 +00:00
applyWordsZoomLevel ( ) ;
2009-04-30 22:09:04 +00:00
2009-04-18 18:47:01 +00:00
// Update autostart info
setAutostart ( cfg . preferences . autoStart ) ;
2009-04-19 21:32:18 +00:00
// Initialize global hotkeys
2009-04-21 18:27:26 +00:00
installHotKeys ( ) ;
2009-04-19 21:32:18 +00:00
2012-12-29 11:19:49 +00:00
if ( cfg . preferences . alwaysOnTop )
{
on_alwaysOnTop_triggered ( true ) ;
}
2009-02-05 20:55:00 +00:00
// Only show window initially if it wasn't configured differently
if ( ! cfg . preferences . enableTrayIcon | | ! cfg . preferences . startToTray )
2009-05-13 13:47:51 +00:00
{
2009-02-05 20:55:00 +00:00
show ( ) ;
2009-05-13 13:47:51 +00:00
focusTranslateLine ( ) ;
}
2009-04-20 19:54:34 +00:00
connect ( & newReleaseCheckTimer , SIGNAL ( timeout ( ) ) ,
this , SLOT ( checkForNewRelease ( ) ) ) ;
2011-06-26 11:53:28 +00:00
if ( cfg . preferences . hideMenubar )
{
toggleMenuBarTriggered ( false ) ;
}
2009-04-20 19:54:34 +00:00
prepareNewReleaseChecks ( ) ;
2009-05-17 22:02:54 +00:00
// makeDictionaries() didn't do deferred init - we do it here, at the end.
doDeferredInit ( dictionaries ) ;
2011-06-27 18:54:15 +00:00
updateStatusLine ( ) ;
2012-06-03 18:29:49 +00:00
2013-04-12 14:30:24 +00:00
# ifdef Q_OS_MACX
2013-12-26 14:13:10 +00:00
if ( cfg . preferences . startWithScanPopupOn & & ! MacMouseOver : : isAXAPIEnabled ( ) )
2013-04-12 14:30:24 +00:00
mainStatusBar - > showMessage ( tr ( " Accessibility API is not enabled " ) , 10000 ,
QPixmap ( " :/icons/error.png " ) ) ;
# endif
2013-01-23 20:36:53 +00:00
wasMaximized = isMaximized ( ) ;
2013-02-05 12:51:23 +00:00
history . setSaveInterval ( cfg . preferences . historyStoreInterval ) ;
2012-06-03 18:29:49 +00:00
# ifdef Q_OS_MAC
LionSupport : : addFullscreen ( this ) ;
# endif
2012-09-18 23:01:31 +00:00
# ifdef Q_OS_WIN32
gdAskMessage = RegisterWindowMessage ( GD_MESSAGE_NAME ) ;
2014-03-17 14:53:47 +00:00
( static_cast < QHotkeyApplication * > ( qApp ) ) - > setMainWindow ( this ) ;
2012-09-18 23:01:31 +00:00
# endif
2014-02-04 13:35:42 +00:00
# if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
ui . centralWidget - > grabGesture ( Gestures : : GDPinchGestureType ) ;
ui . centralWidget - > grabGesture ( Gestures : : GDSwipeGestureType ) ;
# endif
2014-03-20 13:44:46 +00:00
if ( layoutDirection ( ) = = Qt : : RightToLeft )
{
// Adjust button icons for Right-To-Left layout
navBack - > setIcon ( QIcon ( " :/icons/next.png " ) ) ;
navForward - > setIcon ( QIcon ( " :/icons/previous.png " ) ) ;
}
2009-01-28 20:55:45 +00:00
}
2011-11-02 23:37:50 +00:00
void MainWindow : : ctrlTabPressed ( )
{
emit fillWindowsMenu ( ) ;
tabListButton - > click ( ) ;
}
2013-01-05 11:26:55 +00:00
void MainWindow : : updateSearchPaneAndBar ( bool searchInDock )
2012-12-24 11:30:03 +00:00
{
2013-01-23 19:11:39 +00:00
QString text = translateLine - > text ( ) ;
2013-01-05 11:26:55 +00:00
if ( searchInDock )
2012-12-24 11:30:03 +00:00
{
2013-01-05 11:26:55 +00:00
cfg . preferences . searchInDock = true ;
2012-12-24 11:30:03 +00:00
2013-01-21 20:50:57 +00:00
navToolbar - > setAllowedAreas ( Qt : : AllToolBarAreas ) ;
2012-12-24 11:30:03 +00:00
groupList = groupListInDock ;
translateLine = ui . translateLine ;
wordList = ui . wordList ;
2013-02-07 15:24:24 +00:00
translateBoxToolBarAction - > setVisible ( false ) ;
2012-12-24 11:30:03 +00:00
}
else
{
2013-01-05 11:26:55 +00:00
cfg . preferences . searchInDock = false ;
2012-12-24 11:30:03 +00:00
2013-01-21 20:50:57 +00:00
// handle the main toolbar, it must not be on the side, since it should
// contain the group widget and the translate line. Valid locations: Top and Bottom.
navToolbar - > setAllowedAreas ( Qt : : BottomToolBarArea | Qt : : TopToolBarArea ) ;
if ( toolBarArea ( navToolbar ) & ( Qt : : LeftToolBarArea | Qt : : RightToolBarArea ) )
{
if ( toolBarArea ( & dictionaryBar ) = = Qt : : TopToolBarArea )
{
insertToolBar ( & dictionaryBar , navToolbar ) ;
}
else
{
addToolBar ( Qt : : TopToolBarArea , navToolbar ) ;
}
}
2012-12-24 11:30:03 +00:00
groupList = groupListInToolbar ;
translateLine = translateBox - > translateLine ( ) ;
wordList = translateBox - > wordList ( ) ;
2013-02-07 15:24:24 +00:00
translateBoxToolBarAction - > setVisible ( true ) ;
2012-12-24 11:30:03 +00:00
}
2014-03-14 12:39:54 +00:00
translateLine - > setToolTip ( tr ( " String to search in dictionaries. The wildcards '*', '?' and sets of symbols '[...]' are allowed. \n To find '*', '?', '[', ']' symbols use ' \\ *', ' \\ ?', ' \\ [', ' \\ ]' respectively " ) ) ;
2014-03-12 13:43:52 +00:00
2013-02-08 17:09:37 +00:00
// reset the flag when switching UI modes
wordListSelChanged = false ;
2013-01-25 15:42:44 +00:00
wordList - > attachFinder ( & wordFinder ) ;
2012-12-24 11:30:03 +00:00
updateGroupList ( ) ;
2013-01-21 21:49:58 +00:00
applyWordsZoomLevel ( ) ;
2013-01-27 22:12:00 +00:00
if ( cfg . preferences . searchInDock )
translateLine - > setText ( text ) ;
else
translateBox - > setText ( text , false ) ;
2013-01-23 19:11:39 +00:00
focusTranslateLine ( ) ;
2012-12-24 11:30:03 +00:00
}
2009-07-31 11:40:54 +00:00
void MainWindow : : mousePressEvent ( QMouseEvent * event )
{
2011-06-07 08:26:49 +00:00
if ( handleBackForwardMouseButtons ( event ) )
{
return ;
}
2010-09-16 18:52:40 +00:00
if ( event - > button ( ) ! = Qt : : MidButton )
return QMainWindow : : mousePressEvent ( event ) ;
2011-06-07 08:26:49 +00:00
2010-09-16 18:52:40 +00:00
// middle clicked
2011-06-07 08:26:49 +00:00
QString subtype = " plain " ;
2010-09-16 18:52:40 +00:00
QString str = QApplication : : clipboard ( ) - > text ( subtype ,
QClipboard : : Selection ) ;
2012-12-24 11:30:03 +00:00
translateLine - > setText ( str ) ;
2009-07-31 11:40:54 +00:00
2011-06-09 07:29:21 +00:00
QKeyEvent ev ( QEvent : : KeyPress , Qt : : Key_Enter ,
2010-09-16 18:52:40 +00:00
Qt : : NoModifier ) ;
2012-12-24 11:30:03 +00:00
QApplication : : sendEvent ( translateLine , & ev ) ;
2009-07-31 11:40:54 +00:00
}
2009-02-06 17:04:11 +00:00
MainWindow : : ~ MainWindow ( )
{
2013-02-04 14:10:37 +00:00
# ifdef Q_OS_WIN
2013-01-29 19:20:53 +00:00
if ( isMaximized ( ) )
2013-12-20 14:25:33 +00:00
{
2013-01-29 19:20:53 +00:00
cfg . maximizedMainWindowGeometry = geometry ( ) ;
2013-12-20 14:25:33 +00:00
}
2013-01-29 19:20:53 +00:00
else
2013-12-20 14:25:33 +00:00
{
2013-01-29 19:20:53 +00:00
cfg . maximizedMainWindowGeometry = QRect ( ) ;
2013-12-20 14:25:33 +00:00
if ( ! isMinimized ( ) )
cfg . normalMainWindowGeometry = geometry ( ) ;
}
2013-02-04 14:10:37 +00:00
# endif
2013-01-29 19:20:53 +00:00
2014-03-03 13:46:41 +00:00
closeHeadwordsDialog ( ) ;
2014-04-16 16:18:28 +00:00
ftsIndexing . stopIndexing ( ) ;
2014-02-04 13:35:42 +00:00
# if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
ui . centralWidget - > ungrabGesture ( Gestures : : GDPinchGestureType ) ;
ui . centralWidget - > ungrabGesture ( Gestures : : GDSwipeGestureType ) ;
Gestures : : unregisterRecognizers ( ) ;
# endif
2009-05-23 14:19:57 +00:00
// Close all tabs -- they should be destroyed before network managers
// do.
while ( ui . tabWidget - > count ( ) )
{
QWidget * w = ui . tabWidget - > widget ( 0 ) ;
ui . tabWidget - > removeTab ( 0 ) ;
delete w ;
}
2012-02-16 14:56:25 +00:00
2013-05-30 02:18:28 +00:00
commitData ( ) ;
2009-02-06 17:04:11 +00:00
}
2010-06-28 15:14:07 +00:00
void MainWindow : : commitData ( QSessionManager & )
{
commitData ( ) ;
}
void MainWindow : : commitData ( )
{
if ( ! commitDataCompleted )
{
commitDataCompleted = true ;
// Save MainWindow state and geometry
cfg . mainWindowState = saveState ( 1 ) ;
cfg . mainWindowGeometry = saveGeometry ( ) ;
// Close the popup, so it would save its geometry to config
scanPopup . reset ( ) ;
// Save any changes in last chosen groups etc
Config : : save ( cfg ) ;
2014-04-08 18:57:07 +00:00
history . save ( ) ;
2010-06-28 15:14:07 +00:00
}
}
2009-11-11 09:40:32 +00:00
QPrinter & MainWindow : : getPrinter ( )
{
if ( printer . get ( ) )
return * printer ;
printer = new QPrinter ( QPrinter : : HighResolution ) ;
return * printer ;
}
2012-12-10 14:14:13 +00:00
void MainWindow : : applyQtStyleSheet ( QString const & displayStyle , QString const & addonStyle )
2009-05-11 11:03:36 +00:00
{
QFile builtInCssFile ( " :/qt-style.css " ) ;
builtInCssFile . open ( QFile : : ReadOnly ) ;
QByteArray css = builtInCssFile . readAll ( ) ;
2013-04-01 16:37:44 +00:00
# if defined(Q_OS_MAC)
QFile macCssFile ( " :/qt-style-macos.css " ) ;
macCssFile . open ( QFile : : ReadOnly ) ;
css + = macCssFile . readAll ( ) ;
# endif
2009-05-11 11:03:36 +00:00
if ( displayStyle . size ( ) )
{
// Load an additional stylesheet
QFile builtInCssFile ( QString ( " :/qt-style-st-%1.css " ) . arg ( displayStyle ) ) ;
builtInCssFile . open ( QFile : : ReadOnly ) ;
css + = builtInCssFile . readAll ( ) ;
}
// Try loading a style sheet if there's one
QFile cssFile ( Config : : getUserQtCssFileName ( ) ) ;
if ( cssFile . open ( QFile : : ReadOnly ) )
css + = cssFile . readAll ( ) ;
2012-12-10 14:14:13 +00:00
if ( ! addonStyle . isEmpty ( ) )
{
QString name = Config : : getStylesDir ( ) + addonStyle
+ QDir : : separator ( ) + " qt-style.css " ;
QFile addonCss ( name ) ;
if ( addonCss . open ( QFile : : ReadOnly ) )
css + = addonCss . readAll ( ) ;
}
2009-05-16 18:04:21 +00:00
setStyleSheet ( css ) ;
2009-05-11 11:03:36 +00:00
}
2009-01-28 20:55:45 +00:00
2009-02-05 20:55:00 +00:00
void MainWindow : : updateTrayIcon ( )
{
if ( ! trayIcon & & cfg . preferences . enableTrayIcon )
{
// Need to show it
2013-07-19 17:07:32 +00:00
trayIcon = new QSystemTrayIcon ( QIcon ( " :/icons/programicon_old.png " ) , this ) ;
2009-02-08 20:20:02 +00:00
trayIcon - > setContextMenu ( & trayIconMenu ) ;
2009-02-05 20:55:00 +00:00
trayIcon - > show ( ) ;
connect ( trayIcon , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) ,
this , SLOT ( trayIconActivated ( QSystemTrayIcon : : ActivationReason ) ) ) ;
}
else
if ( trayIcon & & ! cfg . preferences . enableTrayIcon )
{
// Need to hide it
delete trayIcon ;
trayIcon = 0 ;
}
if ( trayIcon )
2009-02-08 20:20:02 +00:00
{
// Update the icon to reflect the scanning mode
trayIcon - > setIcon ( QIcon (
enableScanPopup - > isChecked ( ) ?
" :/icons/programicon_scan.png " :
2013-07-19 17:07:32 +00:00
" :/icons/programicon_old.png " ) ) ;
2009-04-18 18:47:01 +00:00
2009-02-05 20:55:00 +00:00
trayIcon - > setToolTip ( " GoldenDict " ) ;
2009-02-08 20:20:02 +00:00
}
2009-04-20 12:25:26 +00:00
// The 'Close to tray' action is associated with the tray icon, so we hide
// or show it here.
ui . actionCloseToTray - > setVisible ( cfg . preferences . enableTrayIcon ) ;
2009-02-05 20:55:00 +00:00
}
2013-01-01 23:05:29 +00:00
void MainWindow : : wheelEvent ( QWheelEvent * ev )
{
if ( ev - > modifiers ( ) . testFlag ( Qt : : ControlModifier ) )
{
if ( ev - > delta ( ) > 0 )
{
zoomin ( ) ;
}
else if ( ev - > delta ( ) < 0 )
{
zoomout ( ) ;
}
ev - > accept ( ) ;
}
else
{
ev - > ignore ( ) ;
}
}
2009-02-05 20:55:00 +00:00
void MainWindow : : closeEvent ( QCloseEvent * ev )
{
if ( cfg . preferences . enableTrayIcon & & cfg . preferences . closeToTray )
{
ev - > ignore ( ) ;
hide ( ) ;
}
else
2010-05-08 13:57:41 +00:00
{
2009-02-05 20:55:00 +00:00
ev - > accept ( ) ;
2010-05-08 13:57:41 +00:00
qApp - > quit ( ) ;
}
2009-02-05 20:55:00 +00:00
}
2009-04-03 17:10:27 +00:00
void MainWindow : : applyProxySettings ( )
{
2014-04-01 17:00:13 +00:00
if ( cfg . preferences . proxyServer . enabled & & cfg . preferences . proxyServer . useSystemProxy )
{
2014-04-03 14:21:02 +00:00
QList < QNetworkProxy > proxies = QNetworkProxyFactory : : systemProxyForQuery ( ) ;
if ( ! cfg . preferences . proxyServer . systemProxyUser . isEmpty ( ) )
{
proxies . first ( ) . setUser ( cfg . preferences . proxyServer . systemProxyUser ) ;
proxies . first ( ) . setPassword ( cfg . preferences . proxyServer . systemProxyPassword ) ;
}
QNetworkProxy : : setApplicationProxy ( proxies . first ( ) ) ;
2014-04-01 17:00:13 +00:00
return ;
}
2009-04-13 17:31:05 +00:00
QNetworkProxy : : ProxyType type = QNetworkProxy : : NoProxy ;
2009-04-03 17:10:27 +00:00
2009-04-13 17:31:05 +00:00
if ( cfg . preferences . proxyServer . enabled )
{
switch ( cfg . preferences . proxyServer . type )
{
case Config : : ProxyServer : : Socks5 :
type = QNetworkProxy : : Socks5Proxy ;
break ;
case Config : : ProxyServer : : HttpConnect :
type = QNetworkProxy : : HttpProxy ;
break ;
case Config : : ProxyServer : : HttpGet :
type = QNetworkProxy : : HttpCachingProxy ;
break ;
default :
break ;
}
}
QNetworkProxy proxy ( type ) ;
if ( cfg . preferences . proxyServer . enabled )
{
2009-04-03 17:10:27 +00:00
proxy . setHostName ( cfg . preferences . proxyServer . host ) ;
proxy . setPort ( cfg . preferences . proxyServer . port ) ;
2009-04-18 18:47:01 +00:00
2009-04-03 17:10:27 +00:00
if ( cfg . preferences . proxyServer . user . size ( ) )
proxy . setUser ( cfg . preferences . proxyServer . user ) ;
2009-04-18 18:47:01 +00:00
2009-04-03 17:10:27 +00:00
if ( cfg . preferences . proxyServer . password . size ( ) )
proxy . setPassword ( cfg . preferences . proxyServer . password ) ;
2009-04-13 17:31:05 +00:00
}
2009-04-18 18:47:01 +00:00
2009-04-13 17:31:05 +00:00
QNetworkProxy : : setApplicationProxy ( proxy ) ;
2009-04-03 17:10:27 +00:00
}
2011-05-08 21:19:08 +00:00
void MainWindow : : applyWebSettings ( )
{
QWebSettings * defaultSettings = QWebSettings : : globalSettings ( ) ;
defaultSettings - > setAttribute ( QWebSettings : : PluginsEnabled , cfg . preferences . enableWebPlugins ) ;
2013-05-30 02:18:28 +00:00
defaultSettings - > setAttribute ( QWebSettings : : DeveloperExtrasEnabled , true ) ;
2011-05-08 21:19:08 +00:00
}
2009-01-28 20:55:45 +00:00
void MainWindow : : makeDictionaries ( )
{
2009-03-26 19:00:08 +00:00
scanPopup . reset ( ) ;
wordFinder . clear ( ) ;
2009-09-23 18:44:38 +00:00
dictionariesUnmuted . clear ( ) ;
2014-04-16 16:18:28 +00:00
ftsIndexing . stopIndexing ( ) ;
2014-04-17 14:18:15 +00:00
ftsIndexing . clearDictionaries ( ) ;
2014-04-16 16:18:28 +00:00
2009-05-17 22:02:54 +00:00
loadDictionaries ( this , isVisible ( ) , cfg , dictionaries , dictNetMgr , false ) ;
2009-01-28 20:55:45 +00:00
2014-04-17 14:31:51 +00:00
for ( unsigned x = 0 ; x < dictionaries . size ( ) ; x + + )
dictionaries [ x ] - > setFTSParameters ( cfg . preferences . fts ) ;
2014-04-17 14:18:15 +00:00
ftsIndexing . setDictionaries ( dictionaries ) ;
2014-04-16 16:18:28 +00:00
ftsIndexing . doIndexing ( ) ;
2009-01-28 20:55:45 +00:00
updateStatusLine ( ) ;
updateGroupList ( ) ;
2009-02-01 00:08:08 +00:00
makeScanPopup ( ) ;
2009-01-28 20:55:45 +00:00
}
void MainWindow : : updateStatusLine ( )
{
unsigned articleCount = 0 , wordCount = 0 ;
for ( unsigned x = dictionaries . size ( ) ; x - - ; )
{
articleCount + = dictionaries [ x ] - > getArticleCount ( ) ;
wordCount + = dictionaries [ x ] - > getWordCount ( ) ;
}
2011-06-27 18:54:15 +00:00
mainStatusBar - > showMessage ( tr ( " %1 dictionaries, %2 articles, %3 words " ) .
2009-01-28 20:55:45 +00:00
arg ( dictionaries . size ( ) ) . arg ( articleCount ) .
2011-06-27 18:54:15 +00:00
arg ( wordCount ) , 10000 ) ;
2009-01-28 20:55:45 +00:00
}
void MainWindow : : updateGroupList ( )
{
bool haveGroups = cfg . groups . size ( ) ;
2012-12-24 11:30:03 +00:00
groupList - > setVisible ( haveGroups ) ;
2009-01-28 20:55:45 +00:00
2009-04-20 14:13:39 +00:00
groupLabel . setText ( haveGroups ? tr ( " Look up in: " ) : tr ( " Look up: " ) ) ;
2009-01-28 20:55:45 +00:00
2009-02-06 17:04:11 +00:00
// currentIndexChanged() signal is very trigger-happy. To avoid triggering
// it, we disconnect it while we're clearing and filling back groups.
2012-12-24 11:30:03 +00:00
disconnect ( groupList , SIGNAL ( currentIndexChanged ( QString const & ) ) ,
2009-02-06 17:04:11 +00:00
this , SLOT ( currentGroupChanged ( QString const & ) ) ) ;
2009-03-26 19:00:08 +00:00
groupInstances . clear ( ) ;
2009-05-18 18:01:50 +00:00
// Add dictionaryOrder first, as the 'All' group.
2009-04-01 12:00:28 +00:00
{
2009-05-18 18:01:50 +00:00
Instances : : Group g ( cfg . dictionaryOrder , dictionaries ) ;
2009-01-28 20:55:45 +00:00
2009-05-23 14:19:57 +00:00
// Add any missing entries to dictionary order
Instances : : complementDictionaryOrder ( g ,
Instances : : Group ( cfg . inactiveDictionaries , dictionaries ) ,
dictionaries ) ;
2009-05-18 18:01:50 +00:00
g . name = tr ( " All " ) ;
2010-05-08 14:01:59 +00:00
g . id = Instances : : Group : : AllGroupId ;
2009-05-18 18:01:50 +00:00
g . icon = " folder.png " ;
groupInstances . push_back ( g ) ;
2009-04-01 12:00:28 +00:00
}
2012-12-10 12:49:45 +00:00
for ( int x = 0 ; x < cfg . groups . size ( ) ; + + x )
2009-05-18 18:01:50 +00:00
groupInstances . push_back ( Instances : : Group ( cfg . groups [ x ] , dictionaries ) ) ;
// Update names for dictionaries that are present, so that they could be
// found in case they got moved.
Instances : : updateNames ( cfg , dictionaries ) ;
2012-12-24 11:30:03 +00:00
groupList - > fill ( groupInstances ) ;
groupList - > setCurrentGroup ( cfg . lastMainGroupId ) ;
2010-11-15 15:22:35 +00:00
updateCurrentGroupProperty ( ) ;
2009-02-06 17:04:11 +00:00
2009-09-21 17:50:03 +00:00
updateDictionaryBar ( ) ;
2013-09-20 14:25:44 +00:00
# ifdef QT_DEBUG
2013-06-10 21:39:40 +00:00
qDebug ( ) < < " Reloading all the tabs... " ;
2013-09-20 14:25:44 +00:00
# endif
2013-06-10 21:39:40 +00:00
for ( int i = 0 ; i < ui . tabWidget - > count ( ) ; + + i )
{
ArticleView & view =
dynamic_cast < ArticleView & > ( * ( ui . tabWidget - > widget ( i ) ) ) ;
view . reload ( ) ;
}
2012-12-24 11:30:03 +00:00
connect ( groupList , SIGNAL ( currentIndexChanged ( QString const & ) ) ,
2009-02-06 17:04:11 +00:00
this , SLOT ( currentGroupChanged ( QString const & ) ) ) ;
2009-02-01 00:08:08 +00:00
}
2009-01-28 20:55:45 +00:00
2009-09-21 17:50:03 +00:00
void MainWindow : : updateDictionaryBar ( )
{
2009-09-23 18:44:38 +00:00
if ( ! dictionaryBar . toggleViewAction ( ) - > isChecked ( ) )
return ; // It's not enabled, therefore hidden -- don't waste time
2012-12-24 11:30:03 +00:00
unsigned currentId = groupList - > getCurrentGroup ( ) ;
2012-09-26 13:59:48 +00:00
Instances : : Group * grp = groupInstances . findGroup ( currentId ) ;
2009-09-21 17:50:03 +00:00
2012-11-17 08:20:18 +00:00
dictionaryBar . setMutedDictionaries ( 0 ) ;
2012-09-26 13:59:48 +00:00
if ( grp ) { // Should always be !0, but check as a safeguard
2012-09-26 13:13:47 +00:00
if ( currentId = = Instances : : Group : : AllGroupId )
dictionaryBar . setMutedDictionaries ( & cfg . mutedDictionaries ) ;
else
{
Config : : Group * grp = cfg . getGroup ( currentId ) ;
dictionaryBar . setMutedDictionaries ( grp ? & grp - > mutedDictionaries : 0 ) ;
}
2011-05-22 02:42:05 +00:00
2012-11-17 08:20:18 +00:00
dictionaryBar . setDictionaries ( grp - > dictionaries ) ;
2011-05-22 02:42:05 +00:00
if ( useSmallIconsInToolbarsAction . isChecked ( ) ) {
int extent = QApplication : : style ( ) - > pixelMetric ( QStyle : : PM_SmallIconSize ) ;
2012-11-07 15:18:56 +00:00
dictionaryBar . setDictionaryIconSize ( extent ) ;
2011-05-22 02:42:05 +00:00
}
}
2009-09-21 17:50:03 +00:00
}
2009-02-01 00:08:08 +00:00
void MainWindow : : makeScanPopup ( )
{
scanPopup . reset ( ) ;
2009-01-28 20:55:45 +00:00
2009-04-21 18:27:26 +00:00
if ( ! cfg . preferences . enableScanPopup & &
! cfg . preferences . enableClipboardHotkey )
2009-02-08 20:20:02 +00:00
return ;
2009-04-18 18:47:01 +00:00
2009-10-21 19:37:07 +00:00
scanPopup = new ScanPopup ( 0 , cfg , articleNetMgr , dictionaries , groupInstances ,
history ) ;
2009-04-18 18:47:01 +00:00
2009-05-16 18:04:21 +00:00
scanPopup - > setStyleSheet ( styleSheet ( ) ) ;
2009-04-21 18:27:26 +00:00
if ( cfg . preferences . enableScanPopup & & enableScanPopup - > isChecked ( ) )
2009-02-08 20:20:02 +00:00
scanPopup - > enableScanning ( ) ;
2010-05-08 14:01:59 +00:00
2012-09-16 10:19:47 +00:00
connect ( scanPopup . get ( ) , SIGNAL ( editGroupRequested ( unsigned ) ) ,
this , SLOT ( editDictionaries ( unsigned ) ) , Qt : : QueuedConnection ) ;
connect ( scanPopup . get ( ) , SIGNAL ( sendWordToMainWindow ( QString const & ) ) ,
this , SLOT ( wordReceived ( QString const & ) ) , Qt : : QueuedConnection ) ;
connect ( this , SIGNAL ( setExpandOptionalParts ( bool ) ) ,
scanPopup . get ( ) , SIGNAL ( setViewExpandMode ( bool ) ) ) ;
connect ( scanPopup . get ( ) , SIGNAL ( setExpandMode ( bool ) ) ,
this , SLOT ( setExpandMode ( bool ) ) ) ;
2012-09-16 10:30:14 +00:00
connect ( scanPopup . get ( ) , SIGNAL ( forceAddWordToHistory ( const QString & ) ) ,
this , SLOT ( forceAddWordToHistory ( const QString & ) ) ) ;
2012-09-24 13:20:58 +00:00
2012-09-25 13:13:35 +00:00
connect ( scanPopup . get ( ) , SIGNAL ( showDictionaryInfo ( const QString & ) ) ,
this , SLOT ( showDictionaryInfo ( const QString & ) ) ) ;
2013-06-09 13:31:57 +00:00
connect ( scanPopup . get ( ) , SIGNAL ( openDictionaryFolder ( const QString & ) ) ,
this , SLOT ( openDictionaryFolder ( const QString & ) ) ) ;
2012-11-12 13:52:54 +00:00
connect ( scanPopup . get ( ) , SIGNAL ( sendWordToHistory ( QString ) ) ,
this , SLOT ( addWordToHistory ( QString ) ) ) ;
2012-09-24 13:20:58 +00:00
# ifdef Q_OS_WIN32
connect ( scanPopup . get ( ) , SIGNAL ( isGoldenDictWindow ( HWND ) ) ,
this , SLOT ( isGoldenDictWindow ( HWND ) ) ) ;
# endif
2009-01-28 20:55:45 +00:00
}
vector < sptr < Dictionary : : Class > > const & MainWindow : : getActiveDicts ( )
2010-09-16 18:52:40 +00:00
{
2009-05-18 18:01:50 +00:00
if ( groupInstances . empty ( ) )
2009-01-28 20:55:45 +00:00
return dictionaries ;
2012-12-24 11:30:03 +00:00
int current = groupList - > currentIndex ( ) ;
2009-01-28 20:55:45 +00:00
if ( current < 0 | | current > = ( int ) groupInstances . size ( ) )
{
// This shouldn't ever happen
return dictionaries ;
}
2012-09-26 13:13:47 +00:00
Config : : MutedDictionaries const * mutedDictionaries = dictionaryBar . getMutedDictionaries ( ) ;
if ( ! dictionaryBar . toggleViewAction ( ) - > isChecked ( ) | | mutedDictionaries = = 0 )
2009-09-23 18:44:38 +00:00
return groupInstances [ current ] . dictionaries ;
else
{
vector < sptr < Dictionary : : Class > > const & activeDicts =
groupInstances [ current ] . dictionaries ;
// Populate the special dictionariesUnmuted array with only unmuted
// dictionaries
dictionariesUnmuted . clear ( ) ;
dictionariesUnmuted . reserve ( activeDicts . size ( ) ) ;
for ( unsigned x = 0 ; x < activeDicts . size ( ) ; + + x )
2012-09-26 13:13:47 +00:00
if ( ! mutedDictionaries - > contains (
2009-09-23 18:44:38 +00:00
QString : : fromStdString ( activeDicts [ x ] - > getId ( ) ) ) )
dictionariesUnmuted . push_back ( activeDicts [ x ] ) ;
return dictionariesUnmuted ;
}
2009-01-28 20:55:45 +00:00
}
2010-09-16 18:52:40 +00:00
void MainWindow : : createTabList ( )
{
tabListMenu - > setIcon ( QIcon ( " :/icons/windows-list.png " ) ) ;
connect ( tabListMenu , SIGNAL ( aboutToShow ( ) ) , this , SLOT ( fillWindowsMenu ( ) ) ) ;
connect ( tabListMenu , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( switchToWindow ( QAction * ) ) ) ;
tabListButton = new QToolButton ( ui . tabWidget ) ;
tabListButton - > setAutoRaise ( true ) ;
tabListButton - > setIcon ( tabListMenu - > icon ( ) ) ;
tabListButton - > setMenu ( tabListMenu ) ;
2011-07-10 10:29:52 +00:00
tabListButton - > setToolTip ( tr ( " Open Tabs List " ) ) ;
2010-09-16 18:52:40 +00:00
tabListButton - > setPopupMode ( QToolButton : : InstantPopup ) ;
ui . tabWidget - > setCornerWidget ( tabListButton ) ;
2011-06-28 15:55:41 +00:00
tabListButton - > setFocusPolicy ( Qt : : ClickFocus ) ;
2010-09-16 18:52:40 +00:00
}
void MainWindow : : fillWindowsMenu ( )
{
tabListMenu - > clear ( ) ;
2011-11-02 23:37:50 +00:00
if ( cfg . preferences . mruTabOrder )
2010-09-16 18:52:40 +00:00
{
2011-11-02 23:37:50 +00:00
for ( int i = 0 ; i < mruList . count ( ) ; i + + )
2010-09-16 18:52:40 +00:00
{
2011-11-02 23:37:50 +00:00
QAction * act = tabListMenu - > addAction ( ui . tabWidget - > tabIcon ( ui . tabWidget - > indexOf ( mruList . at ( i ) ) ) , ui . tabWidget - > tabText ( ui . tabWidget - > indexOf ( mruList . at ( i ) ) ) ) ;
//remember the index of the Tab to be later used in ctrlReleased()
act - > setData ( ui . tabWidget - > indexOf ( mruList . at ( i ) ) ) ;
if ( ui . tabWidget - > currentIndex ( ) = = ui . tabWidget - > indexOf ( mruList . at ( i ) ) )
{
QFont f ( act - > font ( ) ) ;
f . setBold ( true ) ;
act - > setFont ( f ) ;
}
}
if ( tabListMenu - > actions ( ) . size ( ) > 1 )
{
tabListMenu - > setActiveAction ( tabListMenu - > actions ( ) . at ( 1 ) ) ;
2010-09-16 18:52:40 +00:00
}
}
2011-11-02 23:37:50 +00:00
else
2010-09-16 18:52:40 +00:00
{
2011-11-02 23:37:50 +00:00
for ( int i = 0 ; i < ui . tabWidget - > count ( ) ; i + + )
2010-09-16 18:52:40 +00:00
{
2011-11-02 23:37:50 +00:00
QAction * act = tabListMenu - > addAction ( ui . tabWidget - > tabIcon ( i ) ,
ui . tabWidget - > tabText ( i ) ) ;
act - > setData ( i ) ;
if ( ui . tabWidget - > currentIndex ( ) = = i )
{
QFont f ( act - > font ( ) ) ;
f . setBold ( true ) ;
act - > setFont ( f ) ;
}
2010-09-16 18:52:40 +00:00
}
}
2011-11-02 23:37:50 +00:00
return ;
2010-09-16 18:52:40 +00:00
}
void MainWindow : : switchToWindow ( QAction * act )
{
int idx = act - > data ( ) . toInt ( ) ;
ui . tabWidget - > setCurrentIndex ( idx ) ;
}
2009-01-28 20:55:45 +00:00
void MainWindow : : addNewTab ( )
2009-04-13 12:51:25 +00:00
{
createNewTab ( true , tr ( " (untitled) " ) ) ;
}
ArticleView * MainWindow : : createNewTab ( bool switchToIt ,
QString const & name )
2009-01-28 20:55:45 +00:00
{
2009-04-12 16:22:42 +00:00
ArticleView * view = new ArticleView ( this , articleNetMgr , dictionaries ,
2009-09-23 18:44:38 +00:00
groupInstances , false , cfg ,
2014-04-16 16:18:28 +00:00
* ui . searchInPageAction ,
2009-09-23 18:44:38 +00:00
dictionaryBar . toggleViewAction ( ) ,
2012-12-24 11:30:03 +00:00
groupList ) ;
2009-01-28 20:55:45 +00:00
connect ( view , SIGNAL ( titleChanged ( ArticleView * , QString const & ) ) ,
this , SLOT ( titleChanged ( ArticleView * , QString const & ) ) ) ;
connect ( view , SIGNAL ( iconChanged ( ArticleView * , QIcon const & ) ) ,
this , SLOT ( iconChanged ( ArticleView * , QIcon const & ) ) ) ;
2009-05-14 19:27:19 +00:00
connect ( view , SIGNAL ( pageLoaded ( ArticleView * ) ) ,
this , SLOT ( pageLoaded ( ArticleView * ) ) ) ;
2009-04-10 21:07:03 +00:00
2009-05-29 19:48:50 +00:00
connect ( view , SIGNAL ( openLinkInNewTab ( QUrl const & , QUrl const & , QString const & , ArticleView : : Contexts const & ) ) ,
this , SLOT ( openLinkInNewTab ( QUrl const & , QUrl const & , QString const & , ArticleView : : Contexts const & ) ) ) ;
2009-04-13 12:51:25 +00:00
2009-05-29 19:48:50 +00:00
connect ( view , SIGNAL ( showDefinitionInNewTab ( QString const & , unsigned , QString const & , ArticleView : : Contexts const & ) ) ,
this , SLOT ( showDefinitionInNewTab ( QString const & , unsigned , QString const & , ArticleView : : Contexts const & ) ) ) ;
2009-01-28 20:55:45 +00:00
2009-05-12 13:25:18 +00:00
connect ( view , SIGNAL ( typingEvent ( QString const & ) ) ,
this , SLOT ( typingEvent ( QString const & ) ) ) ;
2014-02-09 15:00:48 +00:00
connect ( view , SIGNAL ( activeArticleChanged ( ArticleView const * , const QString & ) ) ,
this , SLOT ( activeArticleChanged ( ArticleView const * , const QString & ) ) ) ;
2011-07-03 12:27:08 +00:00
2011-07-14 20:11:57 +00:00
connect ( view , SIGNAL ( statusBarMessage ( QString const & , int , QPixmap const & ) ) ,
this , SLOT ( showStatusBarMessage ( QString const & , int , QPixmap const & ) ) ) ;
2011-07-02 13:04:49 +00:00
2011-07-31 00:11:07 +00:00
connect ( view , SIGNAL ( showDictsPane ( ) ) , this , SLOT ( showDictsPane ( ) ) ) ;
2012-09-12 14:11:30 +00:00
connect ( view , SIGNAL ( forceAddWordToHistory ( const QString & ) ) ,
this , SLOT ( forceAddWordToHistory ( const QString & ) ) ) ;
2012-09-16 10:19:47 +00:00
connect ( this , SIGNAL ( setExpandOptionalParts ( bool ) ) ,
view , SLOT ( receiveExpandOptionalParts ( bool ) ) ) ;
connect ( view , SIGNAL ( setExpandMode ( bool ) ) , this , SLOT ( setExpandMode ( bool ) ) ) ;
2012-11-12 13:52:54 +00:00
connect ( view , SIGNAL ( sendWordToHistory ( QString ) ) ,
this , SLOT ( addWordToHistory ( QString ) ) ) ;
2012-11-26 13:13:13 +00:00
connect ( view , SIGNAL ( sendWordToInputLine ( QString const & ) ) ,
2013-02-22 12:44:23 +00:00
this , SLOT ( sendWordToInputLine ( QString const & ) ) ) ;
connect ( view , SIGNAL ( storeResourceSavePath ( QString const & ) ) ,
this , SLOT ( storeResourceSavePath ( QString const & ) ) ) ;
2012-11-26 13:13:13 +00:00
2014-02-04 13:35:42 +00:00
connect ( view , SIGNAL ( zoomIn ( ) ) , this , SLOT ( zoomin ( ) ) ) ;
connect ( view , SIGNAL ( zoomOut ( ) ) , this , SLOT ( zoomout ( ) ) ) ;
2012-09-26 14:12:18 +00:00
view - > setSelectionBySingleClick ( cfg . preferences . selectWordBySingleClick ) ;
2009-04-13 12:51:25 +00:00
int index = cfg . preferences . newTabsOpenAfterCurrentOne ?
ui . tabWidget - > currentIndex ( ) + 1 : ui . tabWidget - > count ( ) ;
QString escaped = name ;
escaped . replace ( " & " , " && " ) ;
ui . tabWidget - > insertTab ( index , view , escaped ) ;
2011-11-02 23:37:50 +00:00
mruList . append ( dynamic_cast < QWidget * > ( view ) ) ;
2009-04-13 12:51:25 +00:00
if ( switchToIt )
ui . tabWidget - > setCurrentIndex ( index ) ;
2009-04-30 19:57:25 +00:00
view - > setZoomFactor ( cfg . preferences . zoomFactor ) ;
2012-09-18 23:01:31 +00:00
# ifdef Q_OS_WIN32
view - > installEventFilter ( this ) ;
# endif
2009-04-13 12:51:25 +00:00
return view ;
2009-01-28 20:55:45 +00:00
}
void MainWindow : : tabCloseRequested ( int x )
{
QWidget * w = ui . tabWidget - > widget ( x ) ;
2011-11-02 23:37:50 +00:00
mruList . removeOne ( w ) ;
2013-06-07 13:58:27 +00:00
// In MRU case: First, we switch to the appropriate tab
// and only then remove the old one.
2010-09-16 18:52:40 +00:00
2011-11-02 23:37:50 +00:00
//activate a tab in accordance with MRU
2013-06-07 13:58:27 +00:00
if ( cfg . preferences . mruTabOrder & & mruList . size ( ) > 0 ) {
2012-03-27 01:38:41 +00:00
ui . tabWidget - > setCurrentWidget ( mruList . at ( 0 ) ) ;
}
2011-11-02 23:37:50 +00:00
2013-06-07 13:58:27 +00:00
ui . tabWidget - > removeTab ( x ) ;
delete w ;
// if everything is closed, add a new tab
2010-09-16 18:52:40 +00:00
if ( ui . tabWidget - > count ( ) = = 0 )
addNewTab ( ) ;
2009-01-28 20:55:45 +00:00
}
2009-04-09 22:11:38 +00:00
void MainWindow : : closeCurrentTab ( )
{
tabCloseRequested ( ui . tabWidget - > currentIndex ( ) ) ;
}
2010-09-16 18:52:40 +00:00
void MainWindow : : closeAllTabs ( )
{
while ( ui . tabWidget - > count ( ) > 1 )
closeCurrentTab ( ) ;
// close last tab
closeCurrentTab ( ) ;
}
void MainWindow : : closeRestTabs ( )
{
if ( ui . tabWidget - > count ( ) < 2 )
return ;
int idx = ui . tabWidget - > currentIndex ( ) ;
for ( int i = 0 ; i < idx ; i + + )
tabCloseRequested ( 0 ) ;
ui . tabWidget - > setCurrentIndex ( 0 ) ;
while ( ui . tabWidget - > count ( ) > 1 )
tabCloseRequested ( 1 ) ;
}
2009-04-09 22:11:38 +00:00
void MainWindow : : switchToNextTab ( )
{
if ( ui . tabWidget - > count ( ) < 2 )
return ;
ui . tabWidget - > setCurrentIndex ( ( ui . tabWidget - > currentIndex ( ) + 1 ) % ui . tabWidget - > count ( ) ) ;
}
void MainWindow : : switchToPrevTab ( )
{
if ( ui . tabWidget - > count ( ) < 2 )
return ;
if ( ! ui . tabWidget - > currentIndex ( ) )
ui . tabWidget - > setCurrentIndex ( ui . tabWidget - > count ( ) - 1 ) ;
else
ui . tabWidget - > setCurrentIndex ( ui . tabWidget - > currentIndex ( ) - 1 ) ;
}
2011-11-02 23:37:50 +00:00
//emitted by tabListMenu when user releases Ctrl
void MainWindow : : ctrlReleased ( )
{
if ( tabListMenu - > actions ( ) . size ( ) > 1 )
{
ui . tabWidget - > setCurrentIndex ( tabListMenu - > activeAction ( ) - > data ( ) . toInt ( ) ) ;
}
tabListMenu - > hide ( ) ;
}
2009-01-28 20:55:45 +00:00
void MainWindow : : backClicked ( )
{
2011-06-19 18:50:11 +00:00
DPRINTF ( " Back \n " ) ;
2009-01-28 20:55:45 +00:00
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
2009-01-28 20:55:45 +00:00
2011-07-01 19:22:40 +00:00
view - > back ( ) ;
2009-01-28 20:55:45 +00:00
}
void MainWindow : : forwardClicked ( )
{
2011-06-19 18:50:11 +00:00
DPRINTF ( " Forward \n " ) ;
2009-01-28 20:55:45 +00:00
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
2009-01-28 20:55:45 +00:00
2011-07-01 19:22:40 +00:00
view - > forward ( ) ;
2009-01-28 20:55:45 +00:00
}
void MainWindow : : titleChanged ( ArticleView * view , QString const & title )
{
2009-04-10 21:37:16 +00:00
QString escaped = title ;
escaped . replace ( " & " , " && " ) ;
2013-07-06 21:45:13 +00:00
if ( escaped . isRightToLeft ( ) )
{
escaped . insert ( 0 , ( ushort ) 0x202E ) ; // RLE, Right-to-Left Embedding
escaped . append ( ( ushort ) 0x202C ) ; // PDF, POP DIRECTIONAL FORMATTING
}
2009-04-10 21:37:16 +00:00
ui . tabWidget - > setTabText ( ui . tabWidget - > indexOf ( view ) , escaped ) ;
2011-06-25 07:53:45 +00:00
updateWindowTitle ( ) ;
2009-01-28 20:55:45 +00:00
}
void MainWindow : : iconChanged ( ArticleView * view , QIcon const & icon )
{
2009-05-18 18:01:50 +00:00
ui . tabWidget - > setTabIcon ( ui . tabWidget - > indexOf ( view ) , groupInstances . size ( ) > 1 ? icon : QIcon ( ) ) ;
2009-01-28 20:55:45 +00:00
}
2011-06-25 07:53:45 +00:00
void MainWindow : : updateWindowTitle ( )
{
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
if ( view )
{
2013-01-31 13:01:08 +00:00
QString str = view - > getTitle ( ) ;
if ( ! str . isEmpty ( ) )
{
2013-07-06 21:45:13 +00:00
if ( str . isRightToLeft ( ) )
{
str . insert ( 0 , ( ushort ) 0x202E ) ; // RLE, Right-to-Left Embedding
str . append ( ( ushort ) 0x202C ) ; // PDF, POP DIRECTIONAL FORMATTING
}
2013-01-31 13:01:08 +00:00
if ( ! blockUpdateWindowTitle )
2013-02-01 12:36:01 +00:00
setWindowTitle ( tr ( " %1 - %2 " ) . arg ( str , " GoldenDict " ) ) ;
2013-01-31 13:01:08 +00:00
blockUpdateWindowTitle = false ;
}
2011-07-01 19:22:40 +00:00
}
2011-06-25 07:53:45 +00:00
}
2009-05-14 19:27:19 +00:00
void MainWindow : : pageLoaded ( ArticleView * view )
2009-04-10 21:07:03 +00:00
{
2014-02-09 15:00:48 +00:00
if ( view ! = getCurrentArticleView ( ) )
return ; // It was background action
2011-06-07 11:27:19 +00:00
updateBackForwardButtons ( ) ;
2009-04-10 21:07:03 +00:00
updatePronounceAvailability ( ) ;
if ( cfg . preferences . pronounceOnLoadMain )
2009-05-14 19:27:19 +00:00
pronounce ( view ) ;
2011-06-05 11:49:50 +00:00
updateFoundInDictsList ( ) ;
2009-04-10 21:07:03 +00:00
}
2011-07-14 20:11:57 +00:00
void MainWindow : : showStatusBarMessage ( QString const & message , int timeout , QPixmap const & icon )
2011-07-02 13:04:49 +00:00
{
2011-07-14 20:11:57 +00:00
mainStatusBar - > showMessage ( message , timeout , icon ) ;
2011-07-02 13:04:49 +00:00
}
2009-04-10 21:07:03 +00:00
void MainWindow : : tabSwitched ( int )
{
2013-01-27 22:12:00 +00:00
translateBox - > setPopupEnabled ( false ) ;
2011-06-07 11:27:19 +00:00
updateBackForwardButtons ( ) ;
2009-04-10 21:07:03 +00:00
updatePronounceAvailability ( ) ;
2011-06-05 11:49:50 +00:00
updateFoundInDictsList ( ) ;
2011-06-25 07:53:45 +00:00
updateWindowTitle ( ) ;
2011-11-02 23:37:50 +00:00
if ( mruList . size ( ) > 1 )
{
2013-05-29 06:17:12 +00:00
int from = mruList . indexOf ( ui . tabWidget - > widget ( ui . tabWidget - > currentIndex ( ) ) ) ;
if ( from > 0 )
mruList . move ( from , 0 ) ;
2011-11-02 23:37:50 +00:00
}
2009-04-10 21:07:03 +00:00
}
2010-09-16 18:52:40 +00:00
void MainWindow : : tabMenuRequested ( QPoint pos )
{
// // dont show this menu for single tab
// if ( ui.tabWidget->count() < 2 )
// return;
tabMenu - > popup ( ui . tabWidget - > mapToGlobal ( pos ) ) ;
}
2009-09-23 18:44:38 +00:00
void MainWindow : : dictionaryBarToggled ( bool )
{
2009-09-24 12:20:20 +00:00
// From now on, only the triggered() signal is interesting to us
disconnect ( dictionaryBar . toggleViewAction ( ) , SIGNAL ( toggled ( bool ) ) ,
this , SLOT ( dictionaryBarToggled ( bool ) ) ) ;
2009-09-23 18:44:38 +00:00
updateDictionaryBar ( ) ; // Updates dictionary bar contents if it's shown
applyMutedDictionariesState ( ) ; // Visibility change affects searches and results
}
2009-05-14 19:27:19 +00:00
void MainWindow : : pronounce ( ArticleView * view )
2009-04-10 21:07:03 +00:00
{
2009-05-14 19:27:19 +00:00
if ( view )
view - > playSound ( ) ;
else
2011-07-01 19:22:40 +00:00
getCurrentArticleView ( ) - > playSound ( ) ;
2009-04-10 21:07:03 +00:00
}
2011-07-31 00:11:07 +00:00
void MainWindow : : showDictsPane ( )
{
if ( ! ui . dictsPane - > isVisible ( ) )
ui . dictsPane - > show ( ) ;
}
2011-06-05 11:49:50 +00:00
void MainWindow : : dictsPaneVisibilityChanged ( bool visible )
{
if ( visible ) {
updateFoundInDictsList ( ) ;
}
}
void MainWindow : : updateFoundInDictsList ( )
{
if ( ! ui . dictsList - > isVisible ( ) )
{
// nothing to do, the list is not visible
return ;
}
ui . dictsList - > clear ( ) ;
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
2011-06-05 11:49:50 +00:00
2011-07-01 19:22:40 +00:00
if ( view )
{
QStringList ids = view - > getArticlesList ( ) ;
2011-07-03 12:27:08 +00:00
QString activeId = view - > getActiveArticleId ( ) ;
2011-06-05 11:49:50 +00:00
for ( QStringList : : const_iterator i = ids . constBegin ( ) ; i ! = ids . constEnd ( ) ; + + i )
{
// Find this dictionary
for ( unsigned x = dictionaries . size ( ) ; x - - ; )
{
if ( dictionaries [ x ] - > getId ( ) = = i - > toUtf8 ( ) . data ( ) )
{
QString dictName = QString : : fromUtf8 ( dictionaries [ x ] - > getName ( ) . c_str ( ) ) ;
2011-07-03 12:27:08 +00:00
QString dictId = QString : : fromUtf8 ( dictionaries [ x ] - > getId ( ) . c_str ( ) ) ;
2011-06-05 11:49:50 +00:00
QListWidgetItem * item =
new QListWidgetItem (
2011-07-15 12:11:08 +00:00
dictionaries [ x ] - > getIcon ( ) . pixmap ( 32 ) . scaledToHeight ( 21 , Qt : : SmoothTransformation ) ,
2011-06-05 11:49:50 +00:00
dictName ,
ui . dictsList , QListWidgetItem : : Type ) ;
2011-07-03 12:27:08 +00:00
item - > setData ( Qt : : UserRole , QVariant ( dictId ) ) ;
2011-06-05 11:49:50 +00:00
item - > setToolTip ( dictName ) ;
ui . dictsList - > addItem ( item ) ;
2011-07-03 12:27:08 +00:00
if ( dictId = = activeId )
{
ui . dictsList - > setCurrentItem ( item ) ;
}
2011-06-05 11:49:50 +00:00
break ;
}
}
}
}
}
2011-06-07 11:27:19 +00:00
void MainWindow : : updateBackForwardButtons ( )
{
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
if ( view )
2011-06-07 11:27:19 +00:00
{
2011-07-01 19:22:40 +00:00
navBack - > setEnabled ( view - > canGoBack ( ) ) ;
navForward - > setEnabled ( view - > canGoForward ( ) ) ;
2011-06-07 11:27:19 +00:00
}
}
2009-04-10 21:07:03 +00:00
void MainWindow : : updatePronounceAvailability ( )
{
2009-04-18 18:47:01 +00:00
bool pronounceEnabled = ui . tabWidget - > count ( ) > 0 & &
2011-07-01 19:22:40 +00:00
getCurrentArticleView ( ) - > hasSound ( ) ;
2009-04-10 21:07:03 +00:00
navPronounce - > setEnabled ( pronounceEnabled ) ;
}
2010-05-08 14:01:59 +00:00
void MainWindow : : editDictionaries ( unsigned editDictionaryGroup )
2009-01-28 20:55:45 +00:00
{
2009-04-30 15:29:03 +00:00
hotkeyWrapper . reset ( ) ; // No hotkeys while we're editing dictionaries
scanPopup . reset ( ) ; // No scan popup either. No one should use dictionaries.
2014-04-10 14:00:12 +00:00
closeHeadwordsDialog ( ) ;
2014-04-16 16:18:28 +00:00
closeFullTextSearchDialog ( ) ;
2009-04-30 19:57:25 +00:00
2014-04-17 14:18:15 +00:00
ftsIndexing . stopIndexing ( ) ;
ftsIndexing . clearDictionaries ( ) ;
2009-09-23 18:44:38 +00:00
wordFinder . clear ( ) ;
dictionariesUnmuted . clear ( ) ;
2012-12-22 17:46:53 +00:00
{ // Limit existence of newCfg
2012-09-26 13:13:47 +00:00
Config : : Class newCfg = cfg ;
EditDictionaries dicts ( this , newCfg , dictionaries , groupInstances , dictNetMgr ) ;
2009-01-28 20:55:45 +00:00
2013-07-07 08:09:46 +00:00
connect ( & dicts , SIGNAL ( showDictionaryInfo ( QString const & ) ) ,
this , SLOT ( showDictionaryInfo ( QString const & ) ) ) ;
2014-03-01 13:11:14 +00:00
connect ( & dicts , SIGNAL ( showDictionaryHeadwords ( QString const & ) ) ,
this , SLOT ( showDictionaryHeadwords ( QString const & ) ) ) ;
2010-05-08 14:01:59 +00:00
if ( editDictionaryGroup ! = Instances : : Group : : NoGroupId )
dicts . editGroup ( editDictionaryGroup ) ;
2009-04-30 15:29:03 +00:00
dicts . exec ( ) ;
2009-04-30 19:57:25 +00:00
2009-04-30 15:29:03 +00:00
if ( dicts . areDictionariesChanged ( ) | | dicts . areGroupsChanged ( ) )
2009-03-26 19:00:08 +00:00
{
2012-09-26 13:13:47 +00:00
// Set muted dictionaries from old groups
2012-12-10 12:49:45 +00:00
for ( int x = 0 ; x < newCfg . groups . size ( ) ; x + + )
2012-09-26 13:13:47 +00:00
{
unsigned id = newCfg . groups [ x ] . id ;
if ( id ! = Instances : : Group : : NoGroupId )
{
Config : : Group const * grp = cfg . getGroup ( id ) ;
if ( grp )
{
newCfg . groups [ x ] . mutedDictionaries = grp - > mutedDictionaries ;
newCfg . groups [ x ] . popupMutedDictionaries = grp - > popupMutedDictionaries ;
}
}
}
cfg = newCfg ;
2009-04-30 15:29:03 +00:00
updateGroupList ( ) ;
2009-04-30 19:57:25 +00:00
2009-03-26 19:00:08 +00:00
Config : : save ( cfg ) ;
2013-09-24 13:55:12 +00:00
translateInputChanged ( translateLine - > text ( ) ) ;
2009-01-28 20:55:45 +00:00
}
2009-04-30 19:57:25 +00:00
2012-12-22 17:46:53 +00:00
}
2009-02-01 00:08:08 +00:00
makeScanPopup ( ) ;
2009-04-30 15:29:03 +00:00
installHotKeys ( ) ;
2014-04-17 14:18:15 +00:00
ftsIndexing . setDictionaries ( dictionaries ) ;
ftsIndexing . doIndexing ( ) ;
2009-01-28 20:55:45 +00:00
}
2010-05-08 14:01:59 +00:00
void MainWindow : : editCurrentGroup ( )
{
2012-12-24 11:30:03 +00:00
editDictionaries ( groupList - > getCurrentGroup ( ) ) ;
2010-05-08 14:01:59 +00:00
}
2009-02-05 20:55:00 +00:00
void MainWindow : : editPreferences ( )
{
2009-04-21 18:27:26 +00:00
hotkeyWrapper . reset ( ) ; // So we could use the keys it hooks
2013-05-17 12:34:28 +00:00
scanPopup . reset ( ) ; // No scan popup either. No one should use dictionaries.
2014-04-10 14:00:12 +00:00
closeHeadwordsDialog ( ) ;
2014-04-16 16:18:28 +00:00
closeFullTextSearchDialog ( ) ;
2009-04-21 18:27:26 +00:00
2014-04-17 14:18:15 +00:00
ftsIndexing . stopIndexing ( ) ;
ftsIndexing . clearDictionaries ( ) ;
2009-02-05 20:55:00 +00:00
Preferences preferences ( this , cfg . preferences ) ;
preferences . show ( ) ;
if ( preferences . exec ( ) = = QDialog : : Accepted )
{
2009-05-11 11:03:36 +00:00
Config : : Preferences p = preferences . getPreferences ( ) ;
2012-11-12 14:34:47 +00:00
// These parameters are not set in dialog
p . zoomFactor = cfg . preferences . zoomFactor ;
p . wordsZoomLevel = cfg . preferences . wordsZoomLevel ;
p . hideMenubar = cfg . preferences . hideMenubar ;
2013-01-09 12:17:15 +00:00
p . searchInDock = cfg . preferences . searchInDock ;
p . alwaysOnTop = cfg . preferences . alwaysOnTop ;
2014-01-09 14:17:50 +00:00
# ifndef Q_WS_X11
p . trackClipboardChanges = cfg . preferences . trackClipboardChanges ;
# endif
2014-04-03 14:21:02 +00:00
p . proxyServer . systemProxyUser = cfg . preferences . proxyServer . systemProxyUser ;
p . proxyServer . systemProxyPassword = cfg . preferences . proxyServer . systemProxyPassword ;
2012-11-12 14:34:47 +00:00
2014-04-17 14:31:51 +00:00
p . fts . dialogGeometry = cfg . preferences . fts . dialogGeometry ;
p . fts . matchCase = cfg . preferences . fts . matchCase ;
p . fts . maxArticlesPerDictionary = cfg . preferences . fts . maxArticlesPerDictionary ;
p . fts . maxDistanceBetweenWords = cfg . preferences . fts . maxDistanceBetweenWords ;
p . fts . searchMode = cfg . preferences . fts . searchMode ;
p . fts . useMaxArticlesPerDictionary = cfg . preferences . fts . useMaxArticlesPerDictionary ;
p . fts . useMaxDistanceBetweenWords = cfg . preferences . fts . useMaxDistanceBetweenWords ;
2012-09-16 10:19:47 +00:00
bool needReload = false ;
2009-05-11 11:03:36 +00:00
// See if we need to reapply stylesheets
2012-12-10 14:14:13 +00:00
if ( cfg . preferences . displayStyle ! = p . displayStyle | | cfg . preferences . addonStyle ! = p . addonStyle )
2009-05-11 11:03:36 +00:00
{
2012-12-10 14:14:13 +00:00
applyQtStyleSheet ( p . displayStyle , p . addonStyle ) ;
articleMaker . setDisplayStyle ( p . displayStyle , p . addonStyle ) ;
2012-09-16 10:19:47 +00:00
needReload = true ;
}
2009-05-11 11:03:36 +00:00
2013-06-02 11:20:33 +00:00
if ( cfg . preferences . collapseBigArticles ! = p . collapseBigArticles
| | cfg . preferences . articleSizeLimit ! = p . articleSizeLimit )
{
articleMaker . setCollapseParameters ( p . collapseBigArticles , p . articleSizeLimit ) ;
}
2012-09-16 10:19:47 +00:00
// See if we need to reapply expand optional parts mode
if ( cfg . preferences . alwaysExpandOptionalParts ! = p . alwaysExpandOptionalParts )
{
emit setExpandOptionalParts ( p . alwaysExpandOptionalParts ) ;
// Signal setExpandOptionalParts reload all articles
needReload = false ;
}
2012-09-26 13:59:48 +00:00
for ( int x = 0 ; x < ui . tabWidget - > count ( ) ; + + x )
2012-09-16 10:19:47 +00:00
{
2012-09-26 13:59:48 +00:00
ArticleView & view =
dynamic_cast < ArticleView & > ( * ( ui . tabWidget - > widget ( x ) ) ) ;
view . setSelectionBySingleClick ( p . selectWordBySingleClick ) ;
2009-05-11 11:03:36 +00:00
2012-09-26 13:59:48 +00:00
if ( needReload )
2009-05-11 11:03:36 +00:00
view . reload ( ) ;
}
2013-02-05 12:51:23 +00:00
if ( cfg . preferences . historyStoreInterval ! = p . historyStoreInterval )
history . setSaveInterval ( p . historyStoreInterval ) ;
2009-05-11 11:03:36 +00:00
cfg . preferences = p ;
2009-04-18 18:47:01 +00:00
2012-12-26 13:46:04 +00:00
beforeScanPopupSeparator - > setVisible ( cfg . preferences . enableScanPopup ) ;
2009-02-08 20:20:02 +00:00
enableScanPopup - > setVisible ( cfg . preferences . enableScanPopup ) ;
2012-12-26 13:46:04 +00:00
afterScanPopupSeparator - > setVisible ( cfg . preferences . enableScanPopup ) ;
2009-02-08 20:20:02 +00:00
if ( ! cfg . preferences . enableScanPopup )
enableScanPopup - > setChecked ( false ) ;
2009-04-18 18:47:01 +00:00
2009-02-05 20:55:00 +00:00
updateTrayIcon ( ) ;
2009-04-03 17:10:27 +00:00
applyProxySettings ( ) ;
2011-05-08 21:19:08 +00:00
applyWebSettings ( ) ;
2009-02-08 20:20:02 +00:00
makeScanPopup ( ) ;
2009-04-18 18:47:01 +00:00
2011-06-23 14:17:09 +00:00
ui . tabWidget - > setHideSingleTab ( cfg . preferences . hideSingleTab ) ;
2009-04-20 19:54:34 +00:00
setAutostart ( cfg . preferences . autoStart ) ;
prepareNewReleaseChecks ( ) ;
2009-04-18 18:47:01 +00:00
2012-09-11 13:03:10 +00:00
history . enableAdd ( cfg . preferences . storeHistory ) ;
2013-01-17 09:08:53 +00:00
history . setMaxSize ( cfg . preferences . maxStringsInHistory ) ;
ui . historyPaneWidget - > updateHistoryCounts ( ) ;
2012-09-11 13:03:10 +00:00
2014-04-17 14:31:51 +00:00
for ( unsigned x = 0 ; x < dictionaries . size ( ) ; x + + )
dictionaries [ x ] - > setFTSParameters ( cfg . preferences . fts ) ;
ui . fullTextSearchAction - > setEnabled ( cfg . preferences . fts . enabled ) ;
2009-02-05 20:55:00 +00:00
Config : : save ( cfg ) ;
}
2009-04-21 18:27:26 +00:00
2013-05-17 12:34:28 +00:00
makeScanPopup ( ) ;
2009-04-21 18:27:26 +00:00
installHotKeys ( ) ;
2014-04-17 14:18:15 +00:00
ftsIndexing . setDictionaries ( dictionaries ) ;
ftsIndexing . doIndexing ( ) ;
2009-02-05 20:55:00 +00:00
}
2009-04-10 12:48:40 +00:00
void MainWindow : : currentGroupChanged ( QString const & )
2009-02-06 17:04:11 +00:00
{
2012-12-24 11:30:03 +00:00
cfg . lastMainGroupId = groupList - > getCurrentGroup ( ) ;
2012-09-26 13:13:47 +00:00
Instances : : Group const * igrp = groupInstances . findGroup ( cfg . lastMainGroupId ) ;
if ( cfg . lastMainGroupId = = Instances : : Group : : AllGroupId )
{
if ( igrp )
igrp - > checkMutedDictionaries ( & cfg . mutedDictionaries ) ;
dictionaryBar . setMutedDictionaries ( & cfg . mutedDictionaries ) ;
}
else
{
Config : : Group * grp = cfg . getGroup ( cfg . lastMainGroupId ) ;
if ( grp )
{
if ( igrp )
igrp - > checkMutedDictionaries ( & grp - > mutedDictionaries ) ;
dictionaryBar . setMutedDictionaries ( & grp - > mutedDictionaries ) ;
}
else
dictionaryBar . setMutedDictionaries ( 0 ) ;
}
2009-02-06 17:04:11 +00:00
2009-09-21 17:50:03 +00:00
updateDictionaryBar ( ) ;
2009-02-06 17:04:11 +00:00
// Update word search results
2013-01-27 22:12:00 +00:00
translateBox - > setPopupEnabled ( false ) ;
2013-01-17 09:08:53 +00:00
translateInputChanged ( translateLine - > text ( ) ) ;
translateInputFinished ( false ) ;
2010-11-15 15:22:35 +00:00
updateCurrentGroupProperty ( ) ;
2014-04-16 16:18:28 +00:00
if ( ftsDlg )
ftsDlg - > setCurrentGroup ( cfg . lastMainGroupId ) ;
2010-11-15 15:22:35 +00:00
}
void MainWindow : : updateCurrentGroupProperty ( )
{
// We maintain currentGroup property so styles could use that to change
// fonts based on group names
Instances : : Group * grp =
2012-12-24 11:30:03 +00:00
groupInstances . findGroup ( groupList - > getCurrentGroup ( ) ) ;
2010-11-15 15:22:35 +00:00
2012-12-24 11:30:03 +00:00
if ( grp & & translateLine - > property ( " currentGroup " ) . toString ( ) ! =
2010-11-15 15:22:35 +00:00
grp - > name )
{
2012-12-24 11:30:03 +00:00
translateLine - > setProperty ( " currentGroup " , grp - > name ) ;
wordList - > setProperty ( " currentGroup " , grp - > name ) ;
2010-11-15 15:22:35 +00:00
QString ss = styleSheet ( ) ;
// Only update stylesheet if it mentions currentGroup, as updating the
// stylesheet is a slow operation
if ( ss . contains ( " currentGroup " ) )
setStyleSheet ( ss ) ;
}
2009-02-06 17:04:11 +00:00
}
2009-01-29 19:16:25 +00:00
void MainWindow : : translateInputChanged ( QString const & newValue )
2009-01-28 20:55:45 +00:00
{
2009-03-26 19:00:08 +00:00
// If there's some status bar message present, clear it since it may be
// about the previous search that has failed.
2011-06-27 18:54:15 +00:00
if ( ! mainStatusBar - > currentMessage ( ) . isEmpty ( ) )
{
mainStatusBar - > clearMessage ( ) ;
}
2009-03-26 19:00:08 +00:00
2009-10-21 20:23:03 +00:00
// If some word is selected in the word list, unselect it. This prevents
// triggering a set of spurious activation signals when the list changes.
2012-12-24 11:30:03 +00:00
if ( wordList - > selectionModel ( ) - > hasSelection ( ) )
wordList - > setCurrentItem ( 0 , QItemSelectionModel : : Clear ) ;
2009-10-21 20:23:03 +00:00
2009-01-29 19:16:25 +00:00
QString req = newValue . trimmed ( ) ;
2009-01-28 20:55:45 +00:00
2009-01-29 19:16:25 +00:00
if ( ! req . size ( ) )
{
// An empty request always results in an empty result
2009-03-26 19:00:08 +00:00
wordFinder . cancel ( ) ;
2012-12-24 11:30:03 +00:00
wordList - > clear ( ) ;
wordList - > unsetCursor ( ) ;
2009-01-28 20:55:45 +00:00
2009-03-26 19:00:08 +00:00
// Reset the noResults mark if it's on right now
2012-12-24 11:30:03 +00:00
if ( translateLine - > property ( " noResults " ) . toBool ( ) )
2009-03-26 19:00:08 +00:00
{
2012-12-24 11:30:03 +00:00
translateLine - > setProperty ( " noResults " , false ) ;
2009-05-16 18:04:21 +00:00
setStyleSheet ( styleSheet ( ) ) ;
2009-03-26 19:00:08 +00:00
}
2009-01-28 20:55:45 +00:00
return ;
2009-01-29 19:16:25 +00:00
}
2009-01-28 20:55:45 +00:00
2012-12-24 11:30:03 +00:00
wordList - > setCursor ( Qt : : WaitCursor ) ;
2009-01-28 20:55:45 +00:00
2009-03-26 19:00:08 +00:00
wordFinder . prefixMatch ( req , getActiveDicts ( ) ) ;
2009-01-29 19:16:25 +00:00
}
2009-01-28 20:55:45 +00:00
2012-09-03 12:42:43 +00:00
void MainWindow : : translateInputFinished ( bool checkModifiers )
2009-02-08 14:02:27 +00:00
{
2012-12-24 11:30:03 +00:00
QString word = translateLine - > text ( ) ;
2009-03-29 17:38:54 +00:00
if ( word . size ( ) )
2009-05-05 20:12:20 +00:00
{
Qt : : KeyboardModifiers mods = QApplication : : keyboardModifiers ( ) ;
2012-09-03 12:42:43 +00:00
if ( checkModifiers & & ( mods & ( Qt : : ControlModifier | Qt : : ShiftModifier ) ) )
2009-05-05 20:12:20 +00:00
addNewTab ( ) ;
2009-03-29 17:38:54 +00:00
showTranslationFor ( word ) ;
2009-05-12 13:25:18 +00:00
2013-01-05 11:26:55 +00:00
if ( cfg . preferences . searchInDock )
2012-12-24 11:30:03 +00:00
{
if ( ui . searchPane - > isFloating ( ) )
activateWindow ( ) ;
}
2009-05-13 13:47:51 +00:00
2011-07-01 19:22:40 +00:00
getCurrentArticleView ( ) - > focus ( ) ;
2009-05-05 20:12:20 +00:00
}
2009-02-08 14:02:27 +00:00
}
2010-04-27 07:49:37 +00:00
void MainWindow : : handleEsc ( )
2009-04-08 22:25:46 +00:00
{
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
if ( view & & view - > closeSearch ( ) )
2009-05-16 11:14:43 +00:00
return ;
2011-05-07 13:42:49 +00:00
if ( cfg . preferences . escKeyHidesMainWindow )
2011-05-30 00:44:12 +00:00
{
2011-06-24 19:03:03 +00:00
toggleMainWindow ( ) ;
2011-05-30 00:44:12 +00:00
}
2011-05-07 13:42:49 +00:00
else
focusTranslateLine ( ) ;
2010-04-27 07:49:37 +00:00
}
void MainWindow : : focusTranslateLine ( )
{
2013-01-05 11:26:55 +00:00
if ( cfg . preferences . searchInDock )
2012-12-24 11:30:03 +00:00
{
if ( ui . searchPane - > isFloating ( ) )
ui . searchPane - > activateWindow ( ) ;
}
2013-01-17 09:08:53 +00:00
else
{
if ( ! isActiveWindow ( ) )
activateWindow ( ) ;
}
2009-05-13 13:47:51 +00:00
2012-12-24 11:30:03 +00:00
translateLine - > setFocus ( ) ;
translateLine - > selectAll ( ) ;
2009-04-08 22:25:46 +00:00
}
2009-09-23 18:44:38 +00:00
void MainWindow : : applyMutedDictionariesState ( )
{
2013-01-27 22:12:00 +00:00
translateBox - > setPopupEnabled ( false ) ;
2009-09-23 18:44:38 +00:00
// Redo the current search request
2013-01-17 09:08:53 +00:00
translateInputChanged ( translateLine - > text ( ) ) ;
2009-09-23 18:44:38 +00:00
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
if ( view )
2011-06-11 04:50:19 +00:00
{
// Update active article view
2011-07-01 19:22:40 +00:00
view - > updateMutedContents ( ) ;
2011-06-11 04:50:19 +00:00
}
2009-09-23 18:44:38 +00:00
}
2011-06-07 08:26:49 +00:00
bool MainWindow : : handleBackForwardMouseButtons ( QMouseEvent * event ) {
if ( event - > button ( ) = = Qt : : XButton1 ) {
backClicked ( ) ;
return true ;
}
else
if ( event - > button ( ) = = Qt : : XButton2 ) {
forwardClicked ( ) ;
return true ;
}
else
return false ;
}
2009-03-29 17:38:54 +00:00
bool MainWindow : : eventFilter ( QObject * obj , QEvent * ev )
{
2013-12-20 14:25:33 +00:00
# ifdef Q_OS_WIN
if ( obj = = this & & ev - > type ( ) = = gdStoreNormalGeometryEvent )
{
if ( ! isMaximized ( ) & & ! isMinimized ( ) & & ! isFullScreen ( ) )
cfg . normalMainWindowGeometry = normalGeometry ( ) ;
ev - > accept ( ) ;
return true ;
}
if ( obj = = this & & ev - > type ( ) = = gdApplyNormalGeometryEvent )
{
if ( ! isMaximized ( ) & & ! isMinimized ( ) & & ! isFullScreen ( ) )
setGeometry ( cfg . normalMainWindowGeometry ) ;
ev - > accept ( ) ;
return true ;
}
# endif
2014-04-23 13:46:48 +00:00
if ( ev - > type ( ) = = QEvent : : ShortcutOverride
| | ev - > type ( ) = = QEvent : : KeyPress )
{
2013-01-23 18:36:45 +00:00
// Handle Ctrl+H to show the History Pane.
2013-01-17 09:08:53 +00:00
QKeyEvent * ke = static_cast < QKeyEvent * > ( ev ) ;
if ( ke - > key ( ) = = Qt : : Key_H & & ke - > modifiers ( ) = = Qt : : ControlModifier )
{
2014-04-23 13:46:48 +00:00
if ( ev - > type ( ) = = QEvent : : KeyPress )
on_showHideHistory_triggered ( ) ;
2013-01-17 09:08:53 +00:00
ev - > accept ( ) ;
return true ;
}
2013-01-23 18:36:45 +00:00
// Handle F3/Shift+F3 shortcuts
if ( ke - > key ( ) = = Qt : : Key_F3 )
{
ArticleView * view = getCurrentArticleView ( ) ;
if ( view & & view - > handleF3 ( obj , ev ) )
return true ;
}
2013-01-17 09:08:53 +00:00
}
2012-12-25 09:25:54 +00:00
// when the main window is moved or resized, hide the word list suggestions
if ( obj = = this & & ( ev - > type ( ) = = QEvent : : Move | | ev - > type ( ) = = QEvent : : Resize ) )
{
2013-12-20 14:25:33 +00:00
# ifdef Q_OS_WIN
if ( ! isMaximized ( ) & & ! isMinimized ( ) & & ! isFullScreen ( ) & & gdAskMessage ! = 0xFFFFFFFF )
{
QEvent * ev = new QEvent ( gdStoreNormalGeometryEvent ) ;
qApp - > postEvent ( this , ev ) ;
}
# endif
2013-01-05 11:26:55 +00:00
if ( ! cfg . preferences . searchInDock )
2012-12-25 09:25:54 +00:00
{
2013-01-27 22:12:00 +00:00
translateBox - > setPopupEnabled ( false ) ;
2012-12-25 09:25:54 +00:00
return false ;
}
}
2013-01-23 20:36:53 +00:00
if ( obj = = this & & ev - > type ( ) = = QEvent : : WindowStateChange )
{
QWindowStateChangeEvent * stev = static_cast < QWindowStateChangeEvent * > ( ev ) ;
wasMaximized = ( stev - > oldState ( ) = = Qt : : WindowMaximized & & isMinimized ( ) ) ;
2013-12-20 14:25:33 +00:00
# ifdef Q_OS_WIN
if ( stev - > oldState ( ) = = Qt : : WindowMaximized & & ! isMinimized ( ) & & cfg . normalMainWindowGeometry . width ( ) > 0 )
{
QEvent * ev = new QEvent ( gdApplyNormalGeometryEvent ) ;
qApp - > postEvent ( this , ev ) ;
}
# endif
2013-01-23 20:36:53 +00:00
}
2011-06-07 08:26:49 +00:00
if ( ev - > type ( ) = = QEvent : : MouseButtonPress ) {
QMouseEvent * event = static_cast < QMouseEvent * > ( ev ) ;
2012-12-25 20:38:28 +00:00
// clicks outside of the word list should hide it.
if ( obj ! = translateBox - > wordList ( ) & & obj ! = translateBox - > wordList ( ) - > viewport ( ) ) {
2013-01-27 22:12:00 +00:00
translateBox - > setPopupEnabled ( false ) ;
2012-12-25 20:38:28 +00:00
}
2011-06-07 08:26:49 +00:00
return handleBackForwardMouseButtons ( event ) ;
}
2011-11-02 23:37:50 +00:00
if ( ev - > type ( ) = = QEvent : : KeyPress )
{
QKeyEvent * keyevent = static_cast < QKeyEvent * > ( ev ) ;
if ( keyevent - > modifiers ( ) = = Qt : : ControlModifier & & keyevent - > key ( ) = = Qt : : Key_Tab )
{
if ( cfg . preferences . mruTabOrder )
{
2012-09-16 10:19:47 +00:00
ctrlTabPressed ( ) ;
return true ;
2011-11-02 23:37:50 +00:00
}
return false ;
}
}
2012-12-24 11:30:03 +00:00
if ( obj = = translateLine )
2009-03-29 17:38:54 +00:00
{
2011-06-09 07:29:21 +00:00
if ( ev - > type ( ) = = QEvent : : KeyPress )
2009-03-29 17:38:54 +00:00
{
QKeyEvent * keyEvent = static_cast < QKeyEvent * > ( ev ) ;
2009-04-18 18:47:01 +00:00
2013-01-05 11:26:55 +00:00
if ( cfg . preferences . searchInDock )
2009-03-29 17:38:54 +00:00
{
2012-12-24 11:30:03 +00:00
if ( keyEvent - > matches ( QKeySequence : : MoveToNextLine ) & & wordList - > count ( ) )
{
wordList - > setFocus ( Qt : : ShortcutFocusReason ) ;
2012-12-24 21:56:31 +00:00
wordList - > setCurrentRow ( 0 , QItemSelectionModel : : ClearAndSelect ) ;
2012-12-24 11:30:03 +00:00
return true ;
}
2009-03-29 17:38:54 +00:00
}
}
2012-12-24 11:30:03 +00:00
2011-06-09 07:29:21 +00:00
if ( ev - > type ( ) = = QEvent : : FocusIn ) {
2011-06-08 10:31:03 +00:00
QFocusEvent * focusEvent = static_cast < QFocusEvent * > ( ev ) ;
// select all on mouse click
if ( focusEvent - > reason ( ) = = Qt : : MouseFocusReason ) {
QTimer : : singleShot ( 0 , this , SLOT ( focusTranslateLine ( ) ) ) ;
}
return false ;
}
2012-12-24 11:30:03 +00:00
if ( ev - > type ( ) = = QEvent : : Resize ) {
QResizeEvent * resizeEvent = static_cast < QResizeEvent * > ( ev ) ;
groupList - > setFixedHeight ( resizeEvent - > size ( ) . height ( ) ) ;
return false ;
}
2009-03-29 17:38:54 +00:00
}
else
2012-12-24 11:30:03 +00:00
if ( obj = = wordList )
2009-03-29 17:38:54 +00:00
{
2011-06-09 07:29:21 +00:00
if ( ev - > type ( ) = = QEvent : : KeyPress )
2009-03-29 17:38:54 +00:00
{
QKeyEvent * keyEvent = static_cast < QKeyEvent * > ( ev ) ;
if ( keyEvent - > matches ( QKeySequence : : MoveToPreviousLine ) & &
2012-12-24 11:30:03 +00:00
! wordList - > currentRow ( ) )
2009-03-29 17:38:54 +00:00
{
2012-12-24 11:30:03 +00:00
wordList - > setCurrentRow ( 0 , QItemSelectionModel : : Clear ) ;
translateLine - > setFocus ( Qt : : ShortcutFocusReason ) ;
2009-03-29 17:38:54 +00:00
return true ;
}
if ( keyEvent - > matches ( QKeySequence : : InsertParagraphSeparator ) & &
2012-12-24 11:30:03 +00:00
wordList - > selectedItems ( ) . size ( ) )
2009-03-29 17:38:54 +00:00
{
2013-01-05 11:26:55 +00:00
if ( cfg . preferences . searchInDock )
2012-12-24 11:30:03 +00:00
{
if ( ui . searchPane - > isFloating ( ) )
activateWindow ( ) ;
}
2009-05-13 13:47:51 +00:00
2011-07-01 19:22:40 +00:00
getCurrentArticleView ( ) - > focus ( ) ;
2009-03-29 17:38:54 +00:00
2013-01-05 11:26:55 +00:00
return cfg . preferences . searchInDock ;
2009-03-29 17:38:54 +00:00
}
2009-04-29 23:18:26 +00:00
2009-12-13 17:15:34 +00:00
// Handle typing events used to initiate new lookups
2011-06-06 09:54:23 +00:00
// TODO: refactor to eliminate duplication (see below)
2009-12-13 17:15:34 +00:00
if ( keyEvent - > modifiers ( ) &
2011-06-05 11:49:50 +00:00
( Qt : : ControlModifier | Qt : : AltModifier | Qt : : MetaModifier ) )
return false ; // A non-typing modifier is pressed
if ( keyEvent - > key ( ) = = Qt : : Key_Space | |
keyEvent - > key ( ) = = Qt : : Key_Backspace | |
2011-07-04 08:35:56 +00:00
keyEvent - > key ( ) = = Qt : : Key_Tab | |
keyEvent - > key ( ) = = Qt : : Key_Backtab )
2011-06-05 11:49:50 +00:00
return false ; // Those key have other uses than to start typing
// or don't make sense
QString text = keyEvent - > text ( ) ;
if ( text . size ( ) )
{
typingEvent ( text ) ;
return true ;
}
}
}
else
if ( obj = = ui . dictsList ) {
2011-06-09 07:29:21 +00:00
if ( ev - > type ( ) = = QEvent : : KeyPress )
2011-06-05 11:49:50 +00:00
{
QKeyEvent * keyEvent = static_cast < QKeyEvent * > ( ev ) ;
// Handle typing events used to initiate new lookups
2011-06-06 09:54:23 +00:00
// TODO: refactor to eliminate duplication (see above)
2011-06-05 11:49:50 +00:00
if ( keyEvent - > modifiers ( ) &
( Qt : : ControlModifier | Qt : : AltModifier | Qt : : MetaModifier ) )
2009-12-13 17:15:34 +00:00
return false ; // A non-typing modifier is pressed
if ( keyEvent - > key ( ) = = Qt : : Key_Space | |
keyEvent - > key ( ) = = Qt : : Key_Backspace | |
2011-07-04 08:35:56 +00:00
keyEvent - > key ( ) = = Qt : : Key_Tab | |
keyEvent - > key ( ) = = Qt : : Key_Backtab )
2009-12-13 17:15:34 +00:00
return false ; // Those key have other uses than to start typing
// or don't make sense
QString text = keyEvent - > text ( ) ;
if ( text . size ( ) )
{
typingEvent ( text ) ;
return true ;
}
2009-03-29 17:38:54 +00:00
}
}
return QMainWindow : : eventFilter ( obj , ev ) ;
return false ;
}
2009-01-28 20:55:45 +00:00
void MainWindow : : wordListItemActivated ( QListWidgetItem * item )
{
2012-11-25 11:37:57 +00:00
if ( wordListSelChanged )
wordListSelChanged = false ;
2012-12-24 11:30:03 +00:00
else {
// TODO: code duplication with translateInputFinished!
Qt : : KeyboardModifiers mods = QApplication : : keyboardModifiers ( ) ;
if ( mods & ( Qt : : ControlModifier | Qt : : ShiftModifier ) )
addNewTab ( ) ;
2012-11-25 11:37:57 +00:00
showTranslationFor ( item - > text ( ) ) ;
2012-12-24 11:30:03 +00:00
getCurrentArticleView ( ) - > focus ( ) ;
}
2009-01-28 20:55:45 +00:00
}
2009-02-08 14:02:27 +00:00
void MainWindow : : wordListSelectionChanged ( )
{
2012-12-24 11:30:03 +00:00
QList < QListWidgetItem * > selected = wordList - > selectedItems ( ) ;
2009-02-08 14:02:27 +00:00
if ( selected . size ( ) )
2012-11-25 11:37:57 +00:00
{
wordListSelChanged = true ;
showTranslationFor ( selected . front ( ) - > text ( ) ) ;
}
2009-02-08 14:02:27 +00:00
}
2011-06-05 11:49:50 +00:00
void MainWindow : : dictsListItemActivated ( QListWidgetItem * item )
{
2013-06-28 16:00:13 +00:00
jumpToDictionary ( item , true ) ;
2011-06-05 11:49:50 +00:00
}
void MainWindow : : dictsListSelectionChanged ( )
{
QList < QListWidgetItem * > selected = ui . dictsList - > selectedItems ( ) ;
if ( selected . size ( ) )
2013-06-28 16:00:13 +00:00
jumpToDictionary ( selected . front ( ) ) ;
}
void MainWindow : : jumpToDictionary ( QListWidgetItem * item , bool force )
{
ArticleView * view = getCurrentArticleView ( ) ;
if ( view )
{
view - > jumpToDictionary ( item - > data ( Qt : : UserRole ) . toString ( ) , force ) ;
}
2011-06-05 11:49:50 +00:00
}
2009-02-08 15:49:17 +00:00
void MainWindow : : openLinkInNewTab ( QUrl const & url ,
2009-05-11 19:14:28 +00:00
QUrl const & referrer ,
2009-05-29 19:48:50 +00:00
QString const & fromArticle ,
ArticleView : : Contexts const & contexts )
2009-02-08 15:49:17 +00:00
{
2009-05-11 19:14:28 +00:00
createNewTab ( ! cfg . preferences . newTabsOpenInBackground , " " ) - >
2009-05-29 19:48:50 +00:00
openLink ( url , referrer , fromArticle , contexts ) ;
2009-02-08 15:49:17 +00:00
}
void MainWindow : : showDefinitionInNewTab ( QString const & word ,
2009-05-11 19:14:28 +00:00
unsigned group ,
2009-05-29 19:48:50 +00:00
QString const & fromArticle ,
ArticleView : : Contexts const & contexts )
2009-02-08 15:49:17 +00:00
{
2009-05-11 19:14:28 +00:00
createNewTab ( ! cfg . preferences . newTabsOpenInBackground , word ) - >
2009-05-29 19:48:50 +00:00
showDefinition ( word , group , fromArticle , contexts ) ;
2009-02-08 15:49:17 +00:00
}
2014-02-09 15:00:48 +00:00
void MainWindow : : activeArticleChanged ( ArticleView const * view , QString const & id )
2011-07-03 12:27:08 +00:00
{
2014-02-09 15:00:48 +00:00
if ( view ! = getCurrentArticleView ( ) )
return ; // It was background action
2011-07-03 12:27:08 +00:00
// select the row with the corresponding id
for ( int i = 0 ; i < ui . dictsList - > count ( ) ; + + i ) {
QListWidgetItem * w = ui . dictsList - > item ( i ) ;
QString dictId = w - > data ( Qt : : UserRole ) . toString ( ) ;
if ( dictId = = id )
{
// update the current row, but only if necessary
if ( i ! = ui . dictsList - > currentRow ( ) )
{
ui . dictsList - > setCurrentRow ( i ) ;
}
return ;
}
}
}
2009-05-12 13:25:18 +00:00
void MainWindow : : typingEvent ( QString const & t )
{
2009-05-12 15:54:37 +00:00
if ( t = = " \n " | | t = = " \r " )
2012-02-16 14:56:25 +00:00
{
2012-12-24 11:30:03 +00:00
if ( translateLine - > isEnabled ( ) )
2012-02-16 14:56:25 +00:00
focusTranslateLine ( ) ;
}
2009-05-12 15:54:37 +00:00
else
{
2013-01-05 11:26:55 +00:00
if ( ( cfg . preferences . searchInDock & & ui . searchPane - > isFloating ( ) ) | | ui . dictsPane - > isFloating ( ) )
2009-05-13 13:47:51 +00:00
ui . searchPane - > activateWindow ( ) ;
2012-12-24 11:30:03 +00:00
if ( translateLine - > isEnabled ( ) )
2012-02-16 14:56:25 +00:00
{
2012-12-24 11:30:03 +00:00
translateLine - > setFocus ( ) ;
2013-01-27 22:12:00 +00:00
if ( cfg . preferences . searchInDock )
translateLine - > setText ( t ) ;
else
translateBox - > setText ( t , true ) ;
2012-12-24 11:30:03 +00:00
translateLine - > setCursorPosition ( t . size ( ) ) ;
2012-02-16 14:56:25 +00:00
}
2009-05-12 15:54:37 +00:00
}
2009-05-12 13:25:18 +00:00
}
2009-09-23 18:44:38 +00:00
void MainWindow : : mutedDictionariesChanged ( )
{
if ( dictionaryBar . toggleViewAction ( ) - > isChecked ( ) )
applyMutedDictionariesState ( ) ;
}
2013-01-17 09:08:53 +00:00
void MainWindow : : showHistoryItem ( QString const & word )
{
// qDebug() << "Showing history item" << word;
history . enableAdd ( false ) ;
2013-01-27 22:12:00 +00:00
if ( cfg . preferences . searchInDock )
translateLine - > setText ( word ) ;
else
translateBox - > setText ( word , false ) ;
2013-01-17 09:08:53 +00:00
showTranslationFor ( word ) ;
history . enableAdd ( cfg . preferences . storeHistory ) ;
}
2009-10-21 19:37:07 +00:00
void MainWindow : : showTranslationFor ( QString const & inWord ,
2009-10-21 20:06:17 +00:00
unsigned inGroup )
2009-01-28 20:55:45 +00:00
{
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
2009-01-28 20:55:45 +00:00
2009-04-10 21:07:03 +00:00
navPronounce - > setEnabled ( false ) ;
2009-10-21 20:06:17 +00:00
unsigned group = inGroup ? inGroup :
2009-10-21 19:37:07 +00:00
( groupInstances . empty ( ) ? 0 :
2012-12-24 11:30:03 +00:00
groupInstances [ groupList - > currentIndex ( ) ] . id ) ;
2009-10-21 19:37:07 +00:00
2011-07-01 19:22:40 +00:00
view - > showDefinition ( inWord , group ) ;
2009-01-28 20:55:45 +00:00
2009-04-10 21:07:03 +00:00
updatePronounceAvailability ( ) ;
2011-06-05 11:49:50 +00:00
updateFoundInDictsList ( ) ;
2009-04-10 21:07:03 +00:00
2009-10-21 19:37:07 +00:00
// Add to history
2012-11-12 13:52:54 +00:00
addWordToHistory ( inWord ) ;
2009-10-21 19:37:07 +00:00
2011-06-07 11:27:19 +00:00
updateBackForwardButtons ( ) ;
2009-01-28 20:55:45 +00:00
#if 0
QUrl req ;
req . setScheme ( " gdlookup " ) ;
req . setHost ( " localhost " ) ;
req . addQueryItem ( " word " , inWord ) ;
req . addQueryItem ( " group " ,
cfg . groups . empty ( ) ? " " :
2012-12-24 11:30:03 +00:00
groupInstances [ groupList - > currentIndex ( ) ] . name ) ;
2009-01-28 20:55:45 +00:00
ui . definition - > load ( req ) ;
return ;
# endif
#if 0
wstring word = inWord . trimmed ( ) . toStdWString ( ) ;
// Where to look?
vector < sptr < Dictionary : : Class > > const & activeDicts = getActiveDicts ( ) ;
// Accumulate main forms
vector < wstring > alts ;
{
set < wstring > altsSet ;
2009-04-18 18:47:01 +00:00
2009-01-28 20:55:45 +00:00
for ( unsigned x = 0 ; x < activeDicts . size ( ) ; + + x )
{
vector < wstring > found = activeDicts [ x ] - > findHeadwordsForSynonym ( word ) ;
2009-04-18 18:47:01 +00:00
2009-01-28 20:55:45 +00:00
altsSet . insert ( found . begin ( ) , found . end ( ) ) ;
}
alts . insert ( alts . begin ( ) , altsSet . begin ( ) , altsSet . end ( ) ) ;
}
for ( unsigned x = 0 ; x < alts . size ( ) ; + + x )
{
2011-06-19 18:50:11 +00:00
DPRINTF ( " Alt: %ls \n " , alts [ x ] . c_str ( ) ) ;
2009-01-28 20:55:45 +00:00
}
string result =
" <html><head> "
" <meta http-equiv= \" Content-Type \" content= \" text/html; charset=utf-8 \" > " ;
QFile cssFile ( Config : : getUserCssFileName ( ) ) ;
if ( cssFile . open ( QFile : : ReadOnly ) )
{
result + = " <style type= \" text/css \" > \n " ;
result + = cssFile . readAll ( ) . data ( ) ;
result + = " </style> \n " ;
}
result + = " </head><body> " ;
for ( unsigned x = 0 ; x < activeDicts . size ( ) ; + + x )
{
try
{
string body = activeDicts [ x ] - > getArticle ( word , alts ) ;
2011-06-19 18:50:11 +00:00
DPRINTF ( " From %s: %s \n " , activeDicts [ x ] - > getName ( ) . c_str ( ) , body . c_str ( ) ) ;
2009-01-28 20:55:45 +00:00
result + = " <div class= \" gddictname \" >From " + activeDicts [ x ] - > getName ( ) + " </div> " + body ;
}
catch ( Dictionary : : exNoSuchWord & )
{
continue ;
}
}
result + = " </body></html> " ;
ArticleMaker am ( dictionaries , groupInstances ) ;
2009-04-19 21:32:18 +00:00
string result = am . makeDefinitionFor ( inWord , " En " ) ;
2009-01-28 20:55:45 +00:00
ui . definition - > setContent ( result . c_str ( ) , QString ( ) ) ;
# endif
//ui.tabWidget->setTabText( ui.tabWidget->indexOf(ui.tab), inWord.trimmed() );
}
2009-02-05 20:55:00 +00:00
2014-04-16 16:18:28 +00:00
void MainWindow : : showTranslationFor ( QString const & inWord ,
2014-04-22 13:47:02 +00:00
QStringList const & dictIDs ,
QRegExp const & searchRegExp )
2014-04-16 16:18:28 +00:00
{
ArticleView * view = getCurrentArticleView ( ) ;
navPronounce - > setEnabled ( false ) ;
2014-04-22 18:45:42 +00:00
view - > showDefinition ( inWord , dictIDs , searchRegExp ,
groupInstances [ groupList - > currentIndex ( ) ] . id ) ;
2014-04-16 16:18:28 +00:00
updatePronounceAvailability ( ) ;
updateFoundInDictsList ( ) ;
// Add to history
addWordToHistory ( inWord ) ;
updateBackForwardButtons ( ) ;
}
2013-03-11 12:56:26 +00:00
# ifdef Q_WS_X11
void MainWindow : : toggleMainWindow ( bool onlyShow , bool byIconClick )
# else
2009-04-20 12:25:26 +00:00
void MainWindow : : toggleMainWindow ( bool onlyShow )
2013-03-11 12:56:26 +00:00
# endif
2009-04-20 12:25:26 +00:00
{
2010-04-27 07:49:37 +00:00
bool shown = false ;
2009-04-20 12:25:26 +00:00
if ( ! isVisible ( ) )
2009-05-07 16:22:17 +00:00
{
2009-04-20 12:25:26 +00:00
show ( ) ;
2012-12-29 10:01:36 +00:00
qApp - > setActiveWindow ( this ) ;
2009-05-07 16:22:17 +00:00
activateWindow ( ) ;
raise ( ) ;
2010-04-27 07:49:37 +00:00
shown = true ;
2009-05-07 16:22:17 +00:00
}
2009-04-20 12:25:26 +00:00
else
if ( isMinimized ( ) )
{
2013-01-23 20:36:53 +00:00
if ( wasMaximized )
showMaximized ( ) ;
else
showNormal ( ) ;
2009-04-20 12:25:26 +00:00
activateWindow ( ) ;
raise ( ) ;
2010-04-27 07:49:37 +00:00
shown = true ;
2009-04-20 12:25:26 +00:00
}
else
if ( ! isActiveWindow ( ) )
{
activateWindow ( ) ;
raise ( ) ;
2010-04-27 07:49:37 +00:00
shown = true ;
2009-04-20 12:25:26 +00:00
}
else
if ( ! onlyShow )
2011-06-24 19:03:03 +00:00
{
if ( cfg . preferences . enableTrayIcon )
hide ( ) ;
else
showMinimized ( ) ;
2014-03-03 13:46:41 +00:00
if ( headwordsDlg )
headwordsDlg - > hide ( ) ;
2014-04-16 16:18:28 +00:00
if ( ftsDlg )
ftsDlg - > hide ( ) ;
2011-06-24 19:03:03 +00:00
}
2010-04-27 07:49:37 +00:00
if ( shown )
2012-12-29 10:01:36 +00:00
{
2014-03-03 13:46:41 +00:00
if ( headwordsDlg )
headwordsDlg - > show ( ) ;
2014-04-16 16:18:28 +00:00
if ( ftsDlg )
ftsDlg - > show ( ) ;
2010-04-27 07:49:37 +00:00
focusTranslateLine ( ) ;
2012-12-29 10:01:36 +00:00
# ifdef Q_WS_X11
Window wh = 0 ;
int rev = 0 ;
XGetInputFocus ( QX11Info : : display ( ) , & wh , & rev ) ;
2013-03-11 12:56:26 +00:00
if ( wh ! = translateLine - > internalWinId ( ) & & ! byIconClick )
2013-02-08 11:49:14 +00:00
{
QPoint p ( 1 , 1 ) ;
mapToGlobal ( p ) ;
XEvent event ;
memset ( & event , 0 , sizeof ( event ) ) ;
event . type = ButtonPress ;
event . xbutton . x = 1 ;
event . xbutton . y = 1 ;
event . xbutton . x_root = p . x ( ) ;
event . xbutton . y_root = p . y ( ) ;
event . xbutton . window = internalWinId ( ) ;
event . xbutton . root = QX11Info : : appRootWindow ( QX11Info : : appScreen ( ) ) ;
event . xbutton . state = Button1Mask ;
event . xbutton . button = Button1 ;
event . xbutton . same_screen = true ;
event . xbutton . time = CurrentTime ;
XSendEvent ( QX11Info : : display ( ) , internalWinId ( ) , true , 0xfff , & event ) ;
XFlush ( QX11Info : : display ( ) ) ;
event . type = ButtonRelease ;
XSendEvent ( QX11Info : : display ( ) , internalWinId ( ) , true , 0xfff , & event ) ;
XFlush ( QX11Info : : display ( ) ) ;
}
2012-12-29 10:01:36 +00:00
# endif
}
2009-04-20 12:25:26 +00:00
}
2009-04-21 18:27:26 +00:00
void MainWindow : : installHotKeys ( )
{
hotkeyWrapper . reset ( ) ; // Remove the old one
if ( cfg . preferences . enableMainWindowHotkey | |
cfg . preferences . enableClipboardHotkey )
{
try
{
hotkeyWrapper = new HotkeyWrapper ( this ) ;
}
catch ( HotkeyWrapper : : exInit & )
{
2013-02-01 12:36:01 +00:00
QMessageBox : : critical ( this , " GoldenDict " ,
2009-04-21 18:27:26 +00:00
tr ( " Failed to initialize hotkeys monitoring mechanism.<br> "
" Make sure your XServer has RECORD extension turned on. " ) ) ;
return ;
}
2010-03-19 14:17:45 +00:00
if ( cfg . preferences . enableMainWindowHotkey )
hotkeyWrapper - > setGlobalKey ( cfg . preferences . mainWindowHotkey . key1 ,
cfg . preferences . mainWindowHotkey . key2 ,
cfg . preferences . mainWindowHotkey . modifiers ,
0 ) ;
2009-04-21 18:27:26 +00:00
if ( cfg . preferences . enableClipboardHotkey & & scanPopup . get ( ) )
{
hotkeyWrapper - > setGlobalKey ( cfg . preferences . clipboardHotkey . key1 ,
cfg . preferences . clipboardHotkey . key2 ,
cfg . preferences . clipboardHotkey . modifiers ,
1 ) ;
}
connect ( hotkeyWrapper . get ( ) , SIGNAL ( hotkeyActivated ( int ) ) ,
this , SLOT ( hotKeyActivated ( int ) ) ) ;
}
}
void MainWindow : : hotKeyActivated ( int hk )
{
if ( ! hk )
2011-06-24 19:03:03 +00:00
toggleMainWindow ( ) ;
2009-04-21 18:27:26 +00:00
else
if ( scanPopup . get ( ) )
scanPopup - > translateWordFromClipboard ( ) ;
}
2009-04-20 19:54:34 +00:00
void MainWindow : : prepareNewReleaseChecks ( )
{
if ( cfg . preferences . checkForNewReleases )
{
QDateTime now = QDateTime : : currentDateTime ( ) ;
if ( ! cfg . timeForNewReleaseCheck . isValid ( ) | |
now . daysTo ( cfg . timeForNewReleaseCheck ) > 2 )
{
// The date is invalid, or the check is set to happen more than 2 days
// in the future -- fix that.
cfg . timeForNewReleaseCheck = now . addDays ( 2 ) ;
}
int secsToCheck = now . secsTo ( cfg . timeForNewReleaseCheck ) ;
if ( secsToCheck < 1 )
secsToCheck = 1 ;
newReleaseCheckTimer . setSingleShot ( true ) ;
newReleaseCheckTimer . start ( secsToCheck * 1000 ) ;
}
else
newReleaseCheckTimer . stop ( ) ; // In case it was started before
}
void MainWindow : : checkForNewRelease ( )
{
2013-06-07 12:59:18 +00:00
if ( latestReleaseReply )
latestReleaseReply - > deleteLater ( ) ;
2013-06-11 04:08:25 +00:00
latestReleaseReply = 0 ;
2009-04-20 19:54:34 +00:00
QNetworkRequest req (
2010-11-06 19:40:07 +00:00
QUrl ( " http://goldendict.org/latest_release.php?current= "
2009-04-20 20:59:50 +00:00
PROGRAM_VERSION " &platform= "
# ifdef Q_WS_X11
" x11 "
# endif
# ifdef Q_WS_MAC
" mac "
# endif
# ifdef Q_WS_QWS
" qws "
# endif
# ifdef Q_WS_WIN
" win "
# endif
) ) ;
2009-04-20 19:54:34 +00:00
latestReleaseReply = articleNetMgr . get ( req ) ;
2013-06-07 12:59:18 +00:00
connect ( latestReleaseReply , SIGNAL ( finished ( ) ) ,
2009-04-20 19:54:34 +00:00
this , SLOT ( latestReleaseReplyReady ( ) ) , Qt : : QueuedConnection ) ;
}
void MainWindow : : latestReleaseReplyReady ( )
{
2013-06-07 12:59:18 +00:00
if ( ! latestReleaseReply )
2009-04-20 19:54:34 +00:00
return ; // Some stray signal
bool success = false ;
QString latestVersion , downloadUrl ;
// See if we succeeded
if ( latestReleaseReply - > error ( ) = = QNetworkReply : : NoError )
{
QString latestReleaseInfo = QString : : fromUtf8 ( latestReleaseReply - > readLine ( ) ) . trimmed ( ) ;
QStringList parts = latestReleaseInfo . split ( ' ' ) ;
if ( parts . size ( ) = = 2 )
{
latestVersion = parts [ 0 ] ;
downloadUrl = parts [ 1 ] ;
success = true ;
}
}
2013-06-07 12:59:18 +00:00
latestReleaseReply - > deleteLater ( ) ;
latestReleaseReply = 0 ;
2009-04-20 19:54:34 +00:00
if ( ! success )
{
// Failed -- reschedule to check in two hours
newReleaseCheckTimer . start ( 2 * 60 * 60 * 1000 ) ;
2011-06-19 18:50:11 +00:00
DPRINTF ( " Failed to check program version, retry in two hours \n " ) ;
2009-04-20 19:54:34 +00:00
}
else
{
// Success -- reschedule for a normal check and save config
cfg . timeForNewReleaseCheck = QDateTime ( ) ;
prepareNewReleaseChecks ( ) ;
Config : : save ( cfg ) ;
2011-06-19 18:50:11 +00:00
DPRINTF ( " Program version's check successful, current version is %ls \n " ,
2009-04-20 19:54:34 +00:00
latestVersion . toStdWString ( ) . c_str ( ) ) ;
}
2009-05-14 17:59:49 +00:00
if ( success & & latestVersion > PROGRAM_VERSION & & latestVersion ! = cfg . skippedRelease )
2009-04-20 19:54:34 +00:00
{
QMessageBox msg ( QMessageBox : : Information ,
tr ( " New Release Available " ) ,
tr ( " Version <b>%1</b> of GoldenDict is now available for download.<br> "
" Click <b>Download</b> to get to the download page. " ) . arg ( latestVersion ) ,
QMessageBox : : NoButton ,
this ) ;
QPushButton * dload = msg . addButton ( tr ( " Download " ) , QMessageBox : : AcceptRole ) ;
2009-05-14 17:59:49 +00:00
QPushButton * skip = msg . addButton ( tr ( " Skip This Release " ) , QMessageBox : : DestructiveRole ) ;
2009-04-20 19:54:34 +00:00
msg . addButton ( QMessageBox : : Cancel ) ;
msg . exec ( ) ;
if ( msg . clickedButton ( ) = = dload )
QDesktopServices : : openUrl ( QUrl ( downloadUrl ) ) ;
2009-05-14 17:59:49 +00:00
else
if ( msg . clickedButton ( ) = = skip )
{
cfg . skippedRelease = latestVersion ;
Config : : save ( cfg ) ;
}
2009-04-20 19:54:34 +00:00
}
}
2009-02-08 20:20:02 +00:00
void MainWindow : : trayIconActivated ( QSystemTrayIcon : : ActivationReason r )
{
2010-09-16 18:52:40 +00:00
switch ( r ) {
case QSystemTrayIcon : : Trigger :
// Left click toggles the visibility of main window
2013-03-11 12:56:26 +00:00
# ifdef Q_WS_X11
toggleMainWindow ( false , true ) ;
# else
2010-09-16 18:52:40 +00:00
toggleMainWindow ( ) ;
2013-03-11 12:56:26 +00:00
# endif
2010-09-16 18:52:40 +00:00
break ;
2009-07-31 11:40:54 +00:00
2010-09-16 18:52:40 +00:00
case QSystemTrayIcon : : MiddleClick :
// Middle mouse click on Tray translates selection
// it is functional like as stardict
if ( scanPopup . get ( ) ) {
scanPopup - > translateWordFromSelection ( ) ;
}
break ;
default :
break ;
2009-07-31 11:40:54 +00:00
2010-09-16 18:52:40 +00:00
}
2009-02-08 20:20:02 +00:00
}
void MainWindow : : scanEnableToggled ( bool on )
{
2009-04-21 18:27:26 +00:00
if ( ! cfg . preferences . enableScanPopup )
return ;
2009-02-08 20:20:02 +00:00
if ( scanPopup )
{
if ( on )
2013-04-10 13:31:44 +00:00
{
2009-02-08 20:20:02 +00:00
scanPopup - > enableScanning ( ) ;
2013-04-10 13:31:44 +00:00
# ifdef Q_OS_MACX
2013-12-26 14:13:10 +00:00
if ( ! MacMouseOver : : isAXAPIEnabled ( ) )
2013-04-10 13:31:44 +00:00
mainStatusBar - > showMessage ( tr ( " Accessibility API is not enabled " ) , 10000 ,
QPixmap ( " :/icons/error.png " ) ) ;
# endif
}
2009-02-08 20:20:02 +00:00
else
scanPopup - > disableScanning ( ) ;
}
2009-04-18 18:47:01 +00:00
2009-02-08 20:20:02 +00:00
updateTrayIcon ( ) ;
}
void MainWindow : : showMainWindow ( )
2009-02-05 20:55:00 +00:00
{
2009-04-20 12:25:26 +00:00
toggleMainWindow ( true ) ;
2009-02-05 20:55:00 +00:00
}
2009-02-08 14:02:27 +00:00
void MainWindow : : visitHomepage ( )
{
2010-11-06 19:40:07 +00:00
QDesktopServices : : openUrl ( QUrl ( " http://goldendict.org/ " ) ) ;
2009-02-08 14:02:27 +00:00
}
2011-07-10 07:36:43 +00:00
void MainWindow : : openConfigFolder ( )
{
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( Config : : getConfigDir ( ) ) ) ;
}
2009-02-08 14:02:27 +00:00
void MainWindow : : visitForum ( )
{
2010-11-06 19:40:07 +00:00
QDesktopServices : : openUrl ( QUrl ( " http://goldendict.org/forum/ " ) ) ;
2009-02-08 14:02:27 +00:00
}
void MainWindow : : showAbout ( )
{
2010-11-14 16:28:50 +00:00
About about ( this ) ;
2009-04-12 22:02:15 +00:00
2009-02-08 14:02:27 +00:00
about . show ( ) ;
about . exec ( ) ;
}
2009-10-12 12:41:20 +00:00
void MainWindow : : showDictBarNamesTriggered ( )
{
bool show = showDictBarNamesAction . isChecked ( ) ;
dictionaryBar . setToolButtonStyle ( show ? Qt : : ToolButtonTextBesideIcon :
Qt : : ToolButtonIconOnly ) ;
cfg . showingDictBarNames = show ;
}
2011-05-22 02:42:05 +00:00
void MainWindow : : useSmallIconsInToolbarsTriggered ( )
{
bool useSmallIcons = useSmallIconsInToolbarsAction . isChecked ( ) ;
int extent = useSmallIcons ? QApplication : : style ( ) - > pixelMetric ( QStyle : : PM_SmallIconSize ) :
QApplication : : style ( ) - > pixelMetric ( QStyle : : PM_ToolBarIconSize ) ;
navToolbar - > setIconSize ( QSize ( extent , extent ) ) ;
2013-01-23 13:40:49 +00:00
// additional fix for #176
menuButton - > setIconSize ( QSize ( extent , extent ) ) ;
2011-05-22 02:42:05 +00:00
updateDictionaryBar ( ) ;
cfg . usingSmallIconsInToolbars = useSmallIcons ;
2013-02-27 13:12:46 +00:00
if ( scanPopup . get ( ) )
scanPopup - > setDictionaryIconSize ( ) ;
2011-05-22 02:42:05 +00:00
}
2011-06-26 11:53:28 +00:00
void MainWindow : : toggleMenuBarTriggered ( bool announce )
{
2013-01-04 21:42:25 +00:00
cfg . preferences . hideMenubar = ! toggleMenuBarAction . isChecked ( ) ;
2011-06-26 11:53:28 +00:00
2011-06-27 18:54:15 +00:00
if ( announce )
2011-06-26 11:53:28 +00:00
{
2011-06-27 18:54:15 +00:00
if ( cfg . preferences . hideMenubar )
{
mainStatusBar - > showMessage (
2011-07-09 11:55:44 +00:00
tr ( " You have chosen to hide a menubar. Use %1 to show it back. " )
. arg ( QString ( " <b>%1</b> " ) ) . arg ( tr ( " Ctrl+M " ) ) ,
10000 ,
QPixmap ( " :/icons/warning.png " ) ) ;
2011-06-27 18:54:15 +00:00
}
else
{
mainStatusBar - > clearMessage ( ) ;
}
2011-06-26 11:53:28 +00:00
}
2013-01-06 12:42:18 +00:00
// Obtain from the menubar all the actions with shortcuts
// and either add them to the main window or remove them,
// depending on the menubar state.
QList < QMenu * > allMenus = menuBar ( ) - > findChildren < QMenu * > ( ) ;
QListIterator < QMenu * > menuIter ( allMenus ) ;
while ( menuIter . hasNext ( ) )
{
QMenu * menu = menuIter . next ( ) ;
QList < QAction * > allMenuActions = menu - > actions ( ) ;
QListIterator < QAction * > actionsIter ( allMenuActions ) ;
while ( actionsIter . hasNext ( ) )
{
QAction * action = actionsIter . next ( ) ;
if ( ! action - > shortcut ( ) . isEmpty ( ) )
{
if ( cfg . preferences . hideMenubar )
{
// add all menubar actions to the main window,
// before we hide the menubar
addAction ( action ) ;
}
else
{
// remove all menubar actions from the main window
removeAction ( action ) ;
}
}
}
}
2011-06-26 11:53:28 +00:00
menuBar ( ) - > setVisible ( ! cfg . preferences . hideMenubar ) ;
2012-12-29 18:46:43 +00:00
beforeOptionsSeparator - > setVisible ( cfg . preferences . hideMenubar ) ;
menuButtonAction - > setVisible ( cfg . preferences . hideMenubar ) ;
2011-06-26 11:53:28 +00:00
}
2012-12-03 21:57:00 +00:00
void MainWindow : : on_clearHistory_triggered ( )
2009-10-21 19:37:07 +00:00
{
history . clear ( ) ;
2011-03-30 04:47:55 +00:00
history . save ( ) ;
2009-10-21 19:37:07 +00:00
}
2012-12-03 21:57:00 +00:00
void MainWindow : : on_newTab_triggered ( )
2011-06-25 07:34:28 +00:00
{
addNewTab ( ) ;
}
2009-04-18 18:47:01 +00:00
void MainWindow : : setAutostart ( bool autostart )
{
# ifdef Q_OS_WIN32
QSettings reg ( " HKEY_CURRENT_USER \\ Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Run " ,
QSettings : : NativeFormat ) ;
2009-04-19 21:32:18 +00:00
if ( autostart ) {
QString app_fname = QString ( " \" %1 \" " ) . arg ( QCoreApplication : : applicationFilePath ( ) ) ;
app_fname . replace ( " / " , " \\ " ) ;
reg . setValue ( QCoreApplication : : applicationName ( ) , app_fname ) ;
}
else {
2009-04-18 18:47:01 +00:00
reg . remove ( QCoreApplication : : applicationName ( ) ) ;
2009-04-19 21:32:18 +00:00
}
2009-04-18 18:47:01 +00:00
reg . sync ( ) ;
# else
// this is for KDE
QString app_fname = QFileInfo ( QCoreApplication : : applicationFilePath ( ) ) . baseName ( ) ;
QString lnk ( QDir : : homePath ( ) + " /.kde/Autostart/ " + app_fname ) ;
if ( autostart ) {
QFile f ( QCoreApplication : : applicationFilePath ( ) ) ;
f . link ( lnk ) ;
} else {
QFile : : remove ( lnk ) ;
}
# endif
}
2012-12-03 21:57:00 +00:00
void MainWindow : : on_actionCloseToTray_triggered ( )
2009-04-18 18:47:01 +00:00
{
2009-04-20 12:25:26 +00:00
toggleMainWindow ( ! cfg . preferences . enableTrayIcon ) ;
2009-04-18 18:47:01 +00:00
}
2009-04-30 19:57:25 +00:00
2012-12-03 21:57:00 +00:00
void MainWindow : : on_pageSetup_triggered ( )
2009-05-01 12:20:33 +00:00
{
2009-11-11 09:40:32 +00:00
if ( getPrinter ( ) . isValid ( ) )
2009-05-24 18:51:45 +00:00
{
2009-11-11 09:40:32 +00:00
QPageSetupDialog dialog ( & getPrinter ( ) , this ) ;
2009-05-01 12:20:33 +00:00
2009-05-24 18:51:45 +00:00
dialog . exec ( ) ;
}
else
QMessageBox : : critical ( this , tr ( " Page Setup " ) ,
tr ( " No printer is available. Please install one first. " ) ) ;
2009-05-01 12:20:33 +00:00
}
2012-12-03 21:57:00 +00:00
void MainWindow : : on_printPreview_triggered ( )
2009-05-01 12:20:33 +00:00
{
2009-11-11 09:40:32 +00:00
QPrintPreviewDialog dialog ( & getPrinter ( ) , this ) ;
2009-05-01 12:20:33 +00:00
connect ( & dialog , SIGNAL ( paintRequested ( QPrinter * ) ) ,
this , SLOT ( printPreviewPaintRequested ( QPrinter * ) ) ) ;
2013-02-27 23:37:36 +00:00
dialog . showMaximized ( ) ;
2009-05-01 12:20:33 +00:00
dialog . exec ( ) ;
}
2012-12-03 21:57:00 +00:00
void MainWindow : : on_print_triggered ( )
2009-05-01 12:20:33 +00:00
{
2009-11-11 09:40:32 +00:00
QPrintDialog dialog ( & getPrinter ( ) , this ) ;
2009-05-02 21:46:43 +00:00
2009-05-01 12:20:33 +00:00
dialog . setWindowTitle ( tr ( " Print Article " ) ) ;
2009-05-02 21:46:43 +00:00
2009-05-01 12:20:33 +00:00
if ( dialog . exec ( ) ! = QDialog : : Accepted )
return ;
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
2009-05-01 12:20:33 +00:00
2011-07-01 19:22:40 +00:00
view - > print ( & getPrinter ( ) ) ;
2009-05-01 12:20:33 +00:00
}
void MainWindow : : printPreviewPaintRequested ( QPrinter * printer )
{
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
2009-05-01 12:20:33 +00:00
2011-07-01 19:22:40 +00:00
view - > print ( printer ) ;
2009-05-01 12:20:33 +00:00
}
2013-05-27 11:18:13 +00:00
static void filterAndCollectResources ( QString & html , QRegExp & rx , const QString & sep ,
const QString & folder , set < QByteArray > & resourceIncluded ,
vector < pair < QUrl , QString > > & downloadResources )
{
int pos = 0 ;
while ( ( pos = rx . indexIn ( html , pos ) ) ! = - 1 )
{
QUrl url ( rx . cap ( 1 ) ) ;
QString host = url . host ( ) ;
QString resourcePath = QString : : fromLatin1 ( QUrl : : toPercentEncoding ( url . path ( ) , " / " ) ) ;
if ( ! host . startsWith ( ' / ' ) )
host . insert ( 0 , ' / ' ) ;
if ( ! resourcePath . startsWith ( ' / ' ) )
resourcePath . insert ( 0 , ' / ' ) ;
QCryptographicHash hash ( QCryptographicHash : : Md5 ) ;
hash . addData ( rx . cap ( ) . toUtf8 ( ) ) ;
if ( resourceIncluded . insert ( hash . result ( ) ) . second )
{
// Gather resouce information (url, filename) to be download later
downloadResources . push_back ( pair < QUrl , QString > ( url , folder + host + resourcePath ) ) ;
}
// Modify original url, set to the native one
QString newUrl = sep + QDir ( folder ) . dirName ( ) + host + resourcePath + sep ;
html . replace ( pos , rx . cap ( ) . length ( ) , newUrl ) ;
pos + = newUrl . length ( ) ;
}
}
2012-12-03 21:57:00 +00:00
void MainWindow : : on_saveArticle_triggered ( )
2009-05-01 11:17:29 +00:00
{
2011-07-01 19:22:40 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
2009-05-01 11:17:29 +00:00
2013-04-12 06:57:41 +00:00
QString fileName = view - > getTitle ( ) + " .html " ;
QString savePath ;
2009-05-01 11:17:29 +00:00
2013-04-12 06:57:41 +00:00
if ( cfg . articleSavePath . isEmpty ( ) )
savePath = QDir : : homePath ( ) ;
else
{
savePath = QDir : : fromNativeSeparators ( cfg . articleSavePath ) ;
if ( ! QDir ( savePath ) . exists ( ) )
savePath = QDir : : homePath ( ) ;
}
2009-05-02 21:46:43 +00:00
2013-05-27 11:18:13 +00:00
QFileDialog : : Options options = QFileDialog : : HideNameFilterDetails ;
QString selectedFilter ;
QStringList filters ;
filters . push_back ( tr ( " Article, Complete (*.html) " ) ) ;
filters . push_back ( tr ( " Article, HTML Only (*.html) " ) ) ;
2013-04-12 06:57:41 +00:00
fileName = savePath + " / " + fileName ;
fileName = QFileDialog : : getSaveFileName ( this , tr ( " Save Article As " ) ,
2013-05-27 11:18:13 +00:00
fileName ,
filters . join ( " ;; " ) ,
& selectedFilter , options ) ;
bool complete = ( selectedFilter = = filters [ 0 ] ) ;
2009-05-01 11:17:29 +00:00
2013-04-12 06:57:41 +00:00
if ( ! fileName . isEmpty ( ) )
2009-05-01 11:17:29 +00:00
{
2009-05-02 21:46:43 +00:00
2009-05-01 11:17:29 +00:00
QFile file ( fileName ) ;
if ( ! file . open ( QIODevice : : WriteOnly ) )
2013-04-12 06:57:41 +00:00
{
2009-05-01 11:17:29 +00:00
QMessageBox : : critical ( this , tr ( " Error " ) ,
tr ( " Can't save article: %1 " ) . arg ( file . errorString ( ) ) ) ;
2013-04-12 06:57:41 +00:00
}
2009-05-01 11:17:29 +00:00
else
2013-04-12 06:57:41 +00:00
{
2013-05-27 11:18:13 +00:00
QString html = view - > toHtml ( ) ;
QFileInfo fi ( fileName ) ;
cfg . articleSavePath = QDir : : toNativeSeparators ( fi . absoluteDir ( ) . absolutePath ( ) ) ;
if ( complete )
{
QString folder = fi . absoluteDir ( ) . absolutePath ( ) + " / " + fi . baseName ( ) + " _files " ;
QRegExp rx1 ( " \" ((?:bres|gico|gdau|qrcx) : / / [ ^ \ " ]+) \" " ) ;
QRegExp rx2 ( " '((?:bres|gico|gdau|qrcx) : / / [ ^ ' ] + ) ' " ) ;
set < QByteArray > resourceIncluded ;
vector < pair < QUrl , QString > > downloadResources ;
filterAndCollectResources ( html , rx1 , " \" " , folder , resourceIncluded , downloadResources ) ;
filterAndCollectResources ( html , rx2 , " ' " , folder , resourceIncluded , downloadResources ) ;
ArticleSaveProgressDialog * progressDialog = new ArticleSaveProgressDialog ( this ) ;
// reserve '1' for saving main html file
int maxVal = 1 ;
// Pull and save resources to files
for ( vector < pair < QUrl , QString > > : : const_iterator i = downloadResources . begin ( ) ;
i ! = downloadResources . end ( ) ; i + + )
{
vector < ResourceToSaveHandler * > handlerss = view - > saveResource ( i - > first , i - > second ) ;
maxVal + = handlerss . size ( ) ;
for ( vector < ResourceToSaveHandler * > : : iterator j = handlerss . begin ( ) ;
j ! = handlerss . end ( ) ; j + + )
{
connect ( * j , SIGNAL ( done ( ) ) , progressDialog , SLOT ( perform ( ) ) ) ;
}
}
progressDialog - > setLabelText ( tr ( " Saving article... " ) ) ;
progressDialog - > setRange ( 0 , maxVal ) ;
progressDialog - > setValue ( 0 ) ;
progressDialog - > show ( ) ;
file . write ( html . toUtf8 ( ) ) ;
progressDialog - > setValue ( 1 ) ;
}
else
{
file . write ( html . toUtf8 ( ) ) ;
}
2013-04-12 06:57:41 +00:00
}
2009-05-01 11:17:29 +00:00
}
}
2012-12-03 21:57:00 +00:00
void MainWindow : : on_rescanFiles_triggered ( )
2009-05-08 10:47:34 +00:00
{
hotkeyWrapper . reset ( ) ; // No hotkeys while we're editing dictionaries
scanPopup . reset ( ) ; // No scan popup either. No one should use dictionaries.
2014-04-10 14:00:12 +00:00
closeHeadwordsDialog ( ) ;
2014-04-16 16:18:28 +00:00
closeFullTextSearchDialog ( ) ;
2009-05-08 10:47:34 +00:00
2014-04-17 14:18:15 +00:00
ftsIndexing . stopIndexing ( ) ;
ftsIndexing . clearDictionaries ( ) ;
2009-05-15 12:15:08 +00:00
groupInstances . clear ( ) ; // Release all the dictionaries they hold
2013-02-19 18:56:05 +00:00
dictionaries . clear ( ) ;
dictionariesUnmuted . clear ( ) ;
dictionaryBar . setDictionaries ( dictionaries ) ;
2009-05-15 12:15:08 +00:00
2009-05-08 10:47:34 +00:00
loadDictionaries ( this , true , cfg , dictionaries , dictNetMgr ) ;
2014-04-17 14:18:15 +00:00
2014-04-17 14:31:51 +00:00
for ( unsigned x = 0 ; x < dictionaries . size ( ) ; x + + )
dictionaries [ x ] - > setFTSParameters ( cfg . preferences . fts ) ;
2014-04-17 14:18:15 +00:00
ftsIndexing . setDictionaries ( dictionaries ) ;
2014-04-16 16:18:28 +00:00
ftsIndexing . doIndexing ( ) ;
2010-09-16 18:52:40 +00:00
2009-05-08 10:47:34 +00:00
updateGroupList ( ) ;
makeScanPopup ( ) ;
installHotKeys ( ) ;
2013-05-30 13:54:47 +00:00
// Reload suggestion list
QString word = translateLine - > text ( ) ;
translateInputChanged ( word ) ;
2009-05-08 10:47:34 +00:00
}
2012-12-29 11:19:49 +00:00
void MainWindow : : on_alwaysOnTop_triggered ( bool checked )
{
cfg . preferences . alwaysOnTop = checked ;
bool wasVisible = isVisible ( ) ;
Qt : : WindowFlags flags = this - > windowFlags ( ) ;
if ( checked )
{
setWindowFlags ( flags | Qt : : CustomizeWindowHint | Qt : : WindowStaysOnTopHint ) ;
mainStatusBar - > showMessage (
tr ( " The main window is set to be always on top. " ) ,
10000 ,
QPixmap ( " :/icons/warning.png " ) ) ;
}
else
{
setWindowFlags ( flags ^ ( Qt : : CustomizeWindowHint | Qt : : WindowStaysOnTopHint ) ) ;
mainStatusBar - > clearMessage ( ) ;
}
if ( wasVisible )
{
show ( ) ;
}
installHotKeys ( ) ;
}
2009-04-30 19:57:25 +00:00
void MainWindow : : zoomin ( )
{
cfg . preferences . zoomFactor + = 0.1 ;
applyZoomFactor ( ) ;
}
void MainWindow : : zoomout ( )
{
cfg . preferences . zoomFactor - = 0.1 ;
applyZoomFactor ( ) ;
}
void MainWindow : : unzoom ( )
{
cfg . preferences . zoomFactor = 1 ;
applyZoomFactor ( ) ;
}
void MainWindow : : applyZoomFactor ( )
{
2012-12-03 13:13:13 +00:00
if ( cfg . preferences . zoomFactor > = 5 )
cfg . preferences . zoomFactor = 5 ;
2013-03-13 20:19:38 +00:00
else if ( cfg . preferences . zoomFactor < = 0.1 )
cfg . preferences . zoomFactor = 0.1 ;
2009-04-30 22:09:04 +00:00
2012-12-03 13:13:13 +00:00
zoomIn - > setEnabled ( cfg . preferences . zoomFactor < 5 ) ;
2013-03-13 20:19:38 +00:00
zoomOut - > setEnabled ( cfg . preferences . zoomFactor > 0.1 ) ;
2009-04-30 22:09:04 +00:00
zoomBase - > setEnabled ( cfg . preferences . zoomFactor ! = 1.0 ) ;
2009-04-30 19:57:25 +00:00
for ( int i = 0 ; i < ui . tabWidget - > count ( ) ; i + + )
{
ArticleView & view =
dynamic_cast < ArticleView & > ( * ( ui . tabWidget - > widget ( i ) ) ) ;
view . setZoomFactor ( cfg . preferences . zoomFactor ) ;
}
2009-04-30 20:20:05 +00:00
if ( scanPopup . get ( ) )
scanPopup - > applyZoomFactor ( ) ;
2009-04-30 19:57:25 +00:00
}
2010-07-02 11:19:02 +00:00
void MainWindow : : doWordsZoomIn ( )
{
+ + cfg . preferences . wordsZoomLevel ;
applyWordsZoomLevel ( ) ;
}
void MainWindow : : doWordsZoomOut ( )
{
- - cfg . preferences . wordsZoomLevel ;
applyWordsZoomLevel ( ) ;
}
void MainWindow : : doWordsZoomBase ( )
{
cfg . preferences . wordsZoomLevel = 0 ;
applyWordsZoomLevel ( ) ;
}
void MainWindow : : applyWordsZoomLevel ( )
{
QFont font ( wordListDefaultFont ) ;
int ps = font . pointSize ( ) ;
if ( cfg . preferences . wordsZoomLevel ! = 0 )
{
ps + = cfg . preferences . wordsZoomLevel ;
if ( ps < 1 )
ps = 1 ;
font . setPointSize ( ps ) ;
}
2012-12-24 11:30:03 +00:00
if ( wordList - > font ( ) . pointSize ( ) ! = ps )
wordList - > setFont ( font ) ;
2010-07-02 11:19:02 +00:00
font = translateLineDefaultFont ;
ps = font . pointSize ( ) ;
if ( cfg . preferences . wordsZoomLevel ! = 0 )
{
ps + = cfg . preferences . wordsZoomLevel ;
if ( ps < 1 )
ps = 1 ;
font . setPointSize ( ps ) ;
}
2012-12-24 11:30:03 +00:00
if ( translateLine - > font ( ) . pointSize ( ) ! = ps )
translateLine - > setFont ( font ) ;
groupList - > setFont ( font ) ;
2010-07-02 11:19:02 +00:00
wordsZoomBase - > setEnabled ( cfg . preferences . wordsZoomLevel ! = 0 ) ;
2012-12-24 11:30:03 +00:00
// groupList->setFixedHeight(translateLine->height());
groupList - > parentWidget ( ) - > layout ( ) - > activate ( ) ;
2010-07-02 11:19:02 +00:00
}
2010-11-20 13:43:55 +00:00
void MainWindow : : messageFromAnotherInstanceReceived ( QString const & message )
{
if ( message = = " bringToFront " )
2011-11-16 13:02:56 +00:00
{
2010-11-20 13:43:55 +00:00
toggleMainWindow ( true ) ;
2011-11-16 13:02:56 +00:00
return ;
}
if ( message . left ( 15 ) = = " translateWord: " )
{
if ( scanPopup . get ( ) )
scanPopup - > translateWord ( message . mid ( 15 ) ) ;
else
wordReceived ( message . mid ( 15 ) ) ;
}
2010-11-20 13:43:55 +00:00
else
qWarning ( ) < < " Unknown message received from another instance: " < < message ;
}
2011-07-01 19:22:40 +00:00
ArticleView * MainWindow : : getCurrentArticleView ( )
{
if ( QWidget * cw = ui . tabWidget - > currentWidget ( ) )
{
2013-06-30 07:41:23 +00:00
return dynamic_cast < ArticleView * > ( cw ) ;
2011-07-01 19:22:40 +00:00
}
return 0 ;
}
2011-11-16 12:52:25 +00:00
void MainWindow : : wordReceived ( const QString & word )
{
toggleMainWindow ( true ) ;
2012-12-24 11:30:03 +00:00
translateLine - > setText ( word ) ;
2014-01-09 14:15:51 +00:00
translateInputFinished ( false ) ;
2011-11-16 12:52:25 +00:00
}
2012-02-16 14:56:25 +00:00
2013-01-17 09:08:53 +00:00
void MainWindow : : updateHistoryMenu ( )
2012-02-16 14:56:25 +00:00
{
2013-01-17 09:08:53 +00:00
if ( ui . historyPane - > toggleViewAction ( ) - > isChecked ( ) )
{
ui . showHideHistory - > setText ( tr ( " &Hide " ) ) ;
}
else
{
ui . showHideHistory - > setText ( tr ( " &Show " ) ) ;
}
}
2012-09-12 12:32:29 +00:00
2013-01-17 09:08:53 +00:00
void MainWindow : : on_showHideHistory_triggered ( )
{
ui . historyPane - > toggleViewAction ( ) - > trigger ( ) ;
ui . historyPane - > raise ( ) ; // useful when the Pane is tabbed.
2012-02-16 14:56:25 +00:00
}
2012-02-17 12:01:52 +00:00
2012-12-03 21:57:00 +00:00
void MainWindow : : on_exportHistory_triggered ( )
2012-02-17 12:01:52 +00:00
{
2012-09-10 18:00:29 +00:00
QString exportPath ;
2012-09-12 17:19:21 +00:00
if ( cfg . historyExportPath . isEmpty ( ) )
2012-09-10 18:00:29 +00:00
exportPath = QDir : : homePath ( ) ;
else
{
2012-09-12 17:19:21 +00:00
exportPath = QDir : : fromNativeSeparators ( cfg . historyExportPath ) ;
2012-09-10 18:00:29 +00:00
if ( ! QDir ( exportPath ) . exists ( ) )
exportPath = QDir : : homePath ( ) ;
}
2012-02-17 12:01:52 +00:00
QString fileName = QFileDialog : : getSaveFileName ( this , tr ( " Export history to file " ) ,
2012-09-10 18:00:29 +00:00
exportPath ,
2012-02-17 12:01:52 +00:00
tr ( " Text files (*.txt);;All files (*.*) " ) ) ;
if ( fileName . size ( ) = = 0 )
return ;
2012-09-12 17:19:21 +00:00
cfg . historyExportPath = QDir : : toNativeSeparators ( QFileInfo ( fileName ) . absoluteDir ( ) . absolutePath ( ) ) ;
2012-02-17 12:01:52 +00:00
QFile file ( fileName ) ;
for ( ; ; )
{
if ( ! file . open ( QFile : : WriteOnly | QIODevice : : Text ) )
break ;
// Write UTF-8 BOM
QByteArray line ;
line . append ( 0xEF ) . append ( 0xBB ) . append ( 0xBF ) ;
if ( file . write ( line ) ! = line . size ( ) )
break ;
// Write history
QList < History : : Item > const & items = history . getItems ( ) ;
QList < History : : Item > : : const_iterator i ;
for ( i = items . constBegin ( ) ; i ! = items . constEnd ( ) ; + + i )
{
line = i - > word . toUtf8 ( ) ;
line . replace ( ' \n ' , ' ' ) ;
line . replace ( ' \r ' , ' ' ) ;
line + = " \n " ;
if ( file . write ( line ) ! = line . size ( ) )
break ;
}
if ( i ! = items . constEnd ( ) )
break ;
file . close ( ) ;
mainStatusBar - > showMessage ( tr ( " History export complete " ) , 5000 ) ;
return ;
}
2012-09-10 13:01:35 +00:00
QString errStr = QString ( tr ( " Export error: " ) ) + file . errorString ( ) ;
2012-02-17 12:01:52 +00:00
file . close ( ) ;
mainStatusBar - > showMessage ( errStr , 10000 , QPixmap ( " :/icons/error.png " ) ) ;
}
2012-09-10 13:01:35 +00:00
2013-01-17 09:08:53 +00:00
// TODO: consider moving parts of this method into History class.
2012-12-03 21:57:00 +00:00
void MainWindow : : on_importHistory_triggered ( )
2012-09-10 13:01:35 +00:00
{
2012-09-10 18:00:29 +00:00
QString importPath ;
2012-09-12 17:19:21 +00:00
if ( cfg . historyExportPath . isEmpty ( ) )
2012-09-10 18:00:29 +00:00
importPath = QDir : : homePath ( ) ;
else
{
2012-09-12 17:19:21 +00:00
importPath = QDir : : fromNativeSeparators ( cfg . historyExportPath ) ;
2012-09-10 18:00:29 +00:00
if ( ! QDir ( importPath ) . exists ( ) )
importPath = QDir : : homePath ( ) ;
}
2012-09-10 13:01:35 +00:00
QString fileName = QFileDialog : : getOpenFileName ( this , tr ( " Import history from file " ) ,
2012-09-10 18:00:29 +00:00
importPath ,
2012-09-10 13:01:35 +00:00
tr ( " Text files (*.txt);;All files (*.*) " ) ) ;
if ( fileName . size ( ) = = 0 )
return ;
2012-09-11 12:58:27 +00:00
QFileInfo fileInfo ( fileName ) ;
2012-09-12 17:19:21 +00:00
cfg . historyExportPath = QDir : : toNativeSeparators ( fileInfo . absoluteDir ( ) . absolutePath ( ) ) ;
2012-09-10 13:01:35 +00:00
QString errStr ;
QFile file ( fileName ) ;
for ( ; ; )
{
if ( ! file . open ( QFile : : ReadOnly | QIODevice : : Text ) )
break ;
QTextStream fileStream ( & file ) ;
QString itemStr , trimmedStr ;
QList < QString > itemList ;
history . clear ( ) ;
do
{
itemStr = fileStream . readLine ( ) ;
if ( fileStream . status ( ) > = QTextStream : : ReadCorruptData )
break ;
trimmedStr = itemStr . trimmed ( ) ;
if ( trimmedStr . isEmpty ( ) )
continue ;
2013-01-17 14:24:13 +00:00
if ( ( unsigned ) trimmedStr . size ( ) < = history . getMaxItemLength ( ) )
2012-09-10 13:01:35 +00:00
itemList . prepend ( trimmedStr ) ;
} while ( ! fileStream . atEnd ( ) & & itemList . size ( ) < ( int ) history . getMaxSize ( ) ) ;
2012-09-10 16:23:58 +00:00
history . enableAdd ( true ) ;
2013-01-17 09:08:53 +00:00
2012-09-10 13:01:35 +00:00
for ( QList < QString > : : const_iterator i = itemList . constBegin ( ) ; i ! = itemList . constEnd ( ) ; + + i )
history . addItem ( History : : Item ( 1 , * i ) ) ;
2013-01-17 09:08:53 +00:00
history . enableAdd ( cfg . preferences . storeHistory ) ;
2012-09-10 13:01:35 +00:00
if ( file . error ( ) ! = QFile : : NoError )
break ;
if ( fileStream . status ( ) > = QTextStream : : ReadCorruptData )
{
errStr = QString ( tr ( " Import error: invalid data in file " ) ) ;
mainStatusBar - > showMessage ( errStr , 10000 , QPixmap ( " :/icons/error.png " ) ) ;
}
else
mainStatusBar - > showMessage ( tr ( " History import complete " ) , 5000 ) ;
return ;
}
errStr = QString ( tr ( " Import error: " ) ) + file . errorString ( ) ;
file . close ( ) ;
mainStatusBar - > showMessage ( errStr , 10000 , QPixmap ( " :/icons/error.png " ) ) ;
}
2012-09-10 16:23:58 +00:00
void MainWindow : : fillWordListFromHistory ( )
{
ui . wordList - > setUpdatesEnabled ( false ) ;
ui . wordList - > clear ( ) ;
QList < History : : Item > const & items = history . getItems ( ) ;
for ( int x = 0 ; x < items . size ( ) ; + + x )
{
History : : Item const * i = & items [ x ] ;
QListWidgetItem * s = new QListWidgetItem ( i - > word , ui . wordList ) ;
if ( s - > text ( ) . at ( 0 ) . direction ( ) = = QChar : : DirR )
s - > setTextAlignment ( Qt : : AlignRight ) ;
if ( s - > text ( ) . at ( 0 ) . direction ( ) = = QChar : : DirL )
s - > setTextAlignment ( Qt : : AlignLeft ) ;
ui . wordList - > addItem ( s ) ;
}
ui . wordList - > setUpdatesEnabled ( true ) ;
}
2012-09-12 12:32:29 +00:00
void MainWindow : : focusWordList ( )
{
if ( ui . wordList - > count ( ) > 0 )
ui . wordList - > setFocus ( ) ;
}
2012-09-12 14:11:30 +00:00
2012-11-12 13:52:54 +00:00
void MainWindow : : addWordToHistory ( const QString & word )
{
2013-01-17 09:08:53 +00:00
history . addItem ( History : : Item ( 1 , word . trimmed ( ) ) ) ;
2012-11-12 13:52:54 +00:00
}
2012-09-12 14:11:30 +00:00
void MainWindow : : forceAddWordToHistory ( const QString & word )
{
history . enableAdd ( true ) ;
history . addItem ( History : : Item ( 1 , word . trimmed ( ) ) ) ;
history . enableAdd ( cfg . preferences . storeHistory ) ;
}
2012-09-16 10:19:47 +00:00
void MainWindow : : setExpandMode ( bool expand )
{
articleMaker . setExpandOptionalParts ( expand ) ;
}
void MainWindow : : switchExpandOptionalPartsMode ( )
{
ArticleView * view = getCurrentArticleView ( ) ;
if ( view )
view - > switchExpandOptionalParts ( ) ;
}
2012-09-18 23:01:31 +00:00
2012-09-24 12:51:51 +00:00
void MainWindow : : foundDictsPaneClicked ( QListWidgetItem * item )
2012-09-19 12:44:36 +00:00
{
if ( QApplication : : keyboardModifiers ( ) &
( Qt : : ControlModifier | Qt : : ShiftModifier ) )
{
QString id = item - > data ( Qt : : UserRole ) . toString ( ) ;
emit clickOnDictPane ( id ) ;
}
}
2012-09-25 13:13:35 +00:00
void MainWindow : : showDictionaryInfo ( const QString & id )
{
for ( unsigned x = 0 ; x < dictionaries . size ( ) ; x + + )
{
if ( dictionaries [ x ] - > getId ( ) = = id . toUtf8 ( ) . data ( ) )
{
2012-12-20 13:25:03 +00:00
DictInfo infoMsg ( cfg , this ) ;
2012-09-25 13:13:35 +00:00
infoMsg . showInfo ( dictionaries [ x ] ) ;
2013-06-11 15:40:45 +00:00
int result = infoMsg . exec ( ) ;
if ( result = = DictInfo : : OPEN_FOLDER )
{
openDictionaryFolder ( id ) ;
}
else if ( result = = DictInfo : : EDIT_DICTIONARY )
{
2013-06-11 19:31:58 +00:00
editDictionary ( dictionaries [ x ] . get ( ) ) ;
2013-06-11 15:40:45 +00:00
}
2014-02-28 12:36:28 +00:00
else if ( result = = DictInfo : : SHOW_HEADWORDS )
{
2014-03-01 13:11:14 +00:00
showDictionaryHeadwords ( dictionaries [ x ] . get ( ) ) ;
2014-02-28 12:36:28 +00:00
}
2013-06-11 15:40:45 +00:00
2012-09-25 13:13:35 +00:00
break ;
}
}
}
2014-03-01 13:11:14 +00:00
void MainWindow : : showDictionaryHeadwords ( const QString & id )
{
for ( unsigned x = 0 ; x < dictionaries . size ( ) ; x + + )
{
if ( dictionaries [ x ] - > getId ( ) = = id . toUtf8 ( ) . data ( ) )
{
showDictionaryHeadwords ( dictionaries [ x ] . get ( ) ) ;
break ;
}
}
}
void MainWindow : : showDictionaryHeadwords ( Dictionary : : Class * dict )
{
2014-03-03 13:46:41 +00:00
if ( headwordsDlg = = 0 )
{
headwordsDlg = new DictHeadwords ( this , cfg , dict ) ;
connect ( headwordsDlg , SIGNAL ( headwordSelected ( QString ) ) ,
this , SLOT ( wordReceived ( QString ) ) ) ;
connect ( headwordsDlg , SIGNAL ( closeDialog ( ) ) ,
this , SLOT ( closeHeadwordsDialog ( ) ) ) ;
}
else
headwordsDlg - > setup ( dict ) ;
2014-03-01 13:11:14 +00:00
2014-03-03 13:46:41 +00:00
headwordsDlg - > show ( ) ;
}
2014-03-01 13:11:14 +00:00
2014-03-03 13:46:41 +00:00
void MainWindow : : closeHeadwordsDialog ( )
{
if ( headwordsDlg )
{
delete headwordsDlg ;
headwordsDlg = NULL ;
}
2014-03-01 13:11:14 +00:00
}
2014-03-04 16:58:51 +00:00
void MainWindow : : focusHeadwordsDialog ( )
{
if ( headwordsDlg )
headwordsDlg - > activateWindow ( ) ;
}
2013-06-11 19:31:58 +00:00
void MainWindow : : editDictionary ( Dictionary : : Class * dict )
2013-06-11 15:40:45 +00:00
{
QString dictFilename = dict - > getMainFilename ( ) ;
if ( ! cfg . editDictionaryCommandLine . isEmpty ( ) & & ! dictFilename . isEmpty ( ) )
{
QString command ( cfg . editDictionaryCommandLine ) ;
command . replace ( " %GDDICT% " , " \" " + dictFilename + " \" " ) ;
if ( ! QProcess : : startDetached ( command ) )
QApplication : : beep ( ) ;
}
}
2013-06-09 13:31:57 +00:00
void MainWindow : : openDictionaryFolder ( const QString & id )
{
for ( unsigned x = 0 ; x < dictionaries . size ( ) ; x + + )
{
if ( dictionaries [ x ] - > getId ( ) = = id . toUtf8 ( ) . data ( ) )
{
if ( dictionaries [ x ] - > getDictionaryFilenames ( ) . size ( ) > 0 )
{
QString fileName = FsEncoding : : decode ( dictionaries [ x ] - > getDictionaryFilenames ( ) [ 0 ] . c_str ( ) ) ;
2013-06-11 10:11:10 +00:00
bool explorerLaunched = false ;
// Platform-dependent way to launch a file explorer and to select a file,
// currently only on Windows.
# if defined(Q_OS_WIN)
if ( ! QFileInfo ( fileName ) . isDir ( ) )
{
QString param = QLatin1String ( " explorer.exe " )
+ QLatin1String ( " /select, \" " ) + QDir : : toNativeSeparators ( fileName ) + QLatin1String ( " \" " ) ;
qDebug ( ) < < " Launching " < < param ;
// We use CreateProcess() directly instead of QProcess::startDetached() since
// startDetached() does some evil things with quotes breaking explorer arguments.
// E.g., the following file cannot be properly selected via startDetached(), due to equals sign,
// which explorer considers as separator:
// Z:\GoldenDict\content\-=MDict=-\Test.mdx
PROCESS_INFORMATION pinfo ;
STARTUPINFOW startupInfo = { sizeof ( STARTUPINFO ) , 0 , 0 , 0 ,
( ulong ) CW_USEDEFAULT , ( ulong ) CW_USEDEFAULT ,
( ulong ) CW_USEDEFAULT , ( ulong ) CW_USEDEFAULT ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
} ;
explorerLaunched = CreateProcess ( 0 , ( wchar_t * ) param . utf16 ( ) ,
0 , 0 , FALSE , CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_CONSOLE , 0 ,
0 , & startupInfo , & pinfo ) ;
if ( explorerLaunched ) {
CloseHandle ( pinfo . hThread ) ;
CloseHandle ( pinfo . hProcess ) ;
}
}
# endif
if ( ! explorerLaunched )
{
QString folder = QFileInfo ( fileName ) . absoluteDir ( ) . absolutePath ( ) ;
if ( ! folder . isEmpty ( ) )
2013-06-11 12:52:10 +00:00
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( folder ) ) ;
2013-06-11 10:11:10 +00:00
}
2013-06-09 13:31:57 +00:00
}
break ;
}
}
}
2012-09-24 12:51:51 +00:00
void MainWindow : : foundDictsContextMenuRequested ( const QPoint & pos )
{
QListWidgetItem * item = ui . dictsList - > itemAt ( pos ) ;
if ( item )
{
QString id = item - > data ( Qt : : UserRole ) . toString ( ) ;
2013-06-09 13:31:57 +00:00
Dictionary : : Class * pDict = NULL ;
2012-11-29 17:12:54 +00:00
2013-06-09 13:31:57 +00:00
for ( unsigned i = 0 ; i < dictionaries . size ( ) ; i + + )
2012-11-29 17:12:54 +00:00
{
2013-06-09 13:31:57 +00:00
if ( id . compare ( dictionaries [ i ] - > getId ( ) . c_str ( ) ) = = 0 )
2012-11-29 17:12:54 +00:00
{
2013-06-09 13:31:57 +00:00
pDict = dictionaries [ i ] . get ( ) ;
break ;
2012-11-29 17:12:54 +00:00
}
}
2013-06-09 13:31:57 +00:00
if ( pDict = = NULL )
return ;
if ( ! pDict - > isLocalDictionary ( ) )
2012-11-28 19:32:37 +00:00
{
2013-05-30 15:45:20 +00:00
if ( scanPopup )
scanPopup . get ( ) - > blockSignals ( true ) ;
2012-11-28 19:32:37 +00:00
showDictionaryInfo ( id ) ;
2013-05-30 15:45:20 +00:00
if ( scanPopup )
scanPopup . get ( ) - > blockSignals ( false ) ;
2012-11-28 19:32:37 +00:00
}
else
{
QMenu menu ( ui . dictsList ) ;
QAction * infoAction = menu . addAction ( tr ( " Dictionary info " ) ) ;
2013-06-09 13:31:57 +00:00
2014-03-01 13:11:14 +00:00
QAction * headwordsAction = NULL ;
if ( pDict - > getWordCount ( ) > 0 )
headwordsAction = menu . addAction ( tr ( " Dictionary headwords " ) ) ;
2013-06-09 13:31:57 +00:00
QAction * openDictFolderAction = menu . addAction ( tr ( " Open dictionary folder " ) ) ;
QAction * editAction = NULL ;
QString dictFilename = pDict - > getMainFilename ( ) ;
if ( ! cfg . editDictionaryCommandLine . isEmpty ( ) & & ! dictFilename . isEmpty ( ) )
editAction = menu . addAction ( tr ( " Edit dictionary " ) ) ;
2012-11-28 19:32:37 +00:00
QAction * result = menu . exec ( ui . dictsList - > mapToGlobal ( pos ) ) ;
if ( result & & result = = infoAction )
{
2013-05-30 15:45:20 +00:00
if ( scanPopup )
scanPopup . get ( ) - > blockSignals ( true ) ;
2012-11-28 19:32:37 +00:00
showDictionaryInfo ( id ) ;
2013-05-30 15:45:20 +00:00
if ( scanPopup )
scanPopup . get ( ) - > blockSignals ( false ) ;
2012-11-28 19:32:37 +00:00
}
else
2014-03-01 13:11:14 +00:00
if ( result & & result = = headwordsAction )
{
if ( scanPopup )
scanPopup . get ( ) - > blockSignals ( true ) ;
showDictionaryHeadwords ( pDict ) ;
if ( scanPopup )
scanPopup . get ( ) - > blockSignals ( false ) ;
}
else
2013-06-09 13:31:57 +00:00
if ( result & & result = = openDictFolderAction )
{
openDictionaryFolder ( id ) ;
}
else
2012-11-28 19:32:37 +00:00
if ( result & & result = = editAction )
{
2013-06-11 19:31:58 +00:00
editDictionary ( pDict ) ;
2012-11-28 19:32:37 +00:00
}
}
2012-09-24 12:51:51 +00:00
}
}
2012-11-26 13:13:13 +00:00
void MainWindow : : sendWordToInputLine ( const QString & word )
{
2012-12-25 10:12:13 +00:00
translateLine - > clear ( ) ;
translateLine - > setText ( word ) ;
2012-11-26 13:13:13 +00:00
}
2013-02-22 12:44:23 +00:00
void MainWindow : : storeResourceSavePath ( const QString & newPath )
{
cfg . resourceSavePath = newPath ;
}
2014-04-03 14:21:02 +00:00
void MainWindow : : proxyAuthentication ( const QNetworkProxy & ,
QAuthenticator * authenticator )
{
QNetworkProxy proxy = QNetworkProxy : : applicationProxy ( ) ;
QString * userStr , * passwordStr ;
if ( cfg . preferences . proxyServer . useSystemProxy )
{
userStr = & cfg . preferences . proxyServer . systemProxyUser ;
passwordStr = & cfg . preferences . proxyServer . systemProxyPassword ;
}
else
{
userStr = & cfg . preferences . proxyServer . user ;
passwordStr = & cfg . preferences . proxyServer . password ;
}
if ( proxy . user ( ) . isEmpty ( ) & & ! userStr - > isEmpty ( ) )
{
authenticator - > setUser ( * userStr ) ;
authenticator - > setPassword ( * passwordStr ) ;
proxy . setUser ( * userStr ) ;
proxy . setPassword ( * passwordStr ) ;
QNetworkProxy : : setApplicationProxy ( proxy ) ;
}
else
{
QDialog dlg ;
Ui : : Dialog ui ;
ui . setupUi ( & dlg ) ;
dlg . adjustSize ( ) ;
ui . userEdit - > setText ( * userStr ) ;
ui . passwordEdit - > setText ( * passwordStr ) ;
if ( dlg . exec ( ) = = QDialog : : Accepted )
{
* userStr = ui . userEdit - > text ( ) ;
* passwordStr = ui . passwordEdit - > text ( ) ;
authenticator - > setUser ( * userStr ) ;
authenticator - > setPassword ( * passwordStr ) ;
proxy . setUser ( * userStr ) ;
proxy . setPassword ( * passwordStr ) ;
QNetworkProxy : : setApplicationProxy ( proxy ) ;
}
}
}
2014-04-16 16:18:28 +00:00
void MainWindow : : showFullTextSearchDialog ( )
{
if ( ! ftsDlg )
{
2014-04-17 14:18:15 +00:00
ftsDlg = new FTS : : FullTextSearchDialog ( this , cfg , dictionaries , groupInstances , ftsIndexing ) ;
2014-04-16 16:18:28 +00:00
2014-04-22 13:47:02 +00:00
connect ( ftsDlg , SIGNAL ( showTranslationFor ( QString , QStringList , QRegExp ) ) ,
this , SLOT ( showTranslationFor ( QString , QStringList , QRegExp ) ) ) ;
2014-04-16 16:18:28 +00:00
connect ( ftsDlg , SIGNAL ( closeDialog ( ) ) ,
this , SLOT ( closeFullTextSearchDialog ( ) ) ) ;
connect ( & configEvents , SIGNAL ( mutedDictionariesChanged ( ) ) ,
ftsDlg , SLOT ( updateDictionaries ( ) ) ) ;
}
unsigned group = groupInstances . empty ( ) ? 0
: groupInstances [ groupList - > currentIndex ( ) ] . id ;
ftsDlg - > setCurrentGroup ( group ) ;
2014-04-23 13:47:56 +00:00
if ( ! ftsDlg - > isVisible ( ) )
ftsDlg - > show ( ) ;
else
ftsDlg - > activateWindow ( ) ;
2014-04-16 16:18:28 +00:00
}
void MainWindow : : closeFullTextSearchDialog ( )
{
if ( ftsDlg )
{
ftsDlg - > stopSearch ( ) ;
delete ftsDlg ;
ftsDlg = 0 ;
}
}
2012-09-18 23:01:31 +00:00
# ifdef Q_OS_WIN32
2014-03-17 14:53:47 +00:00
bool MainWindow : : handleGDMessage ( MSG * message , long * result )
2012-09-18 23:01:31 +00:00
{
if ( message - > message ! = gdAskMessage )
return false ;
* result = 0 ;
2014-03-17 14:53:47 +00:00
if ( ! isGoldenDictWindow ( message - > hwnd ) )
return true ;
2012-09-18 23:01:31 +00:00
ArticleView * view = getCurrentArticleView ( ) ;
if ( ! view )
return true ;
LPGDDataStruct lpdata = ( LPGDDataStruct ) message - > lParam ;
QString str = view - > wordAtPoint ( lpdata - > Pt . x , lpdata - > Pt . y ) ;
memset ( lpdata - > cwData , 0 , lpdata - > dwMaxLength * sizeof ( WCHAR ) ) ;
2013-01-26 14:49:02 +00:00
str . truncate ( lpdata - > dwMaxLength - 1 ) ;
2012-09-18 23:01:31 +00:00
str . toWCharArray ( lpdata - > cwData ) ;
* result = 1 ;
return true ;
}
2012-09-24 13:20:58 +00:00
bool MainWindow : : isGoldenDictWindow ( HWND hwnd )
{
2014-03-17 14:53:47 +00:00
return hwnd = = winId ( ) | | hwnd = = ui . centralWidget - > winId ( ) ;
2012-09-24 13:20:58 +00:00
}
2012-09-18 23:01:31 +00:00
# endif