2011-03-03 18:29:20 +01:00
/* ============================================================
2017-01-20 09:37:00 +01:00
* QupZilla - Qt web browser
* Copyright ( C ) 2010 - 2017 David Rosca < nowrep @ gmail . com >
2011-03-03 18:29:20 +01:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
2014-02-19 22:07:21 +01:00
# include "browserwindow.h"
2011-03-02 16:57:41 +01:00
# include "tabwidget.h"
# include "tabbar.h"
# include "webpage.h"
2012-01-21 20:27:45 +01:00
# include "tabbedwebview.h"
2011-03-02 16:57:41 +01:00
# include "lineedit.h"
2012-04-30 16:33:14 +02:00
# include "history.h"
2011-03-02 16:57:41 +01:00
# include "locationbar.h"
# include "websearchbar.h"
2013-01-17 15:24:30 +01:00
# include "pluginproxy.h"
# include "sidebar.h"
2011-03-02 16:57:41 +01:00
# include "downloadmanager.h"
# include "cookiejar.h"
# include "cookiemanager.h"
# include "bookmarkstoolbar.h"
# include "clearprivatedata.h"
2013-01-24 17:47:50 +01:00
# include "autofill.h"
2011-03-02 16:57:41 +01:00
# include "mainapplication.h"
2012-03-15 19:35:37 +01:00
# include "checkboxdialog.h"
2011-03-27 21:59:40 +02:00
# include "adblockmanager.h"
# include "clickablelabel.h"
2011-04-15 20:45:22 +02:00
# include "docktitlebarwidget.h"
2011-04-25 20:56:45 +02:00
# include "iconprovider.h"
2011-04-25 15:06:59 +02:00
# include "progressbar.h"
2011-05-07 12:59:53 +02:00
# include "adblockicon.h"
# include "closedtabsmanager.h"
2011-05-09 17:58:19 +02:00
# include "statusbarmessage.h"
2011-07-29 15:39:43 +02:00
# include "browsinglibrary.h"
2011-09-11 19:15:06 +02:00
# include "navigationbar.h"
2014-02-15 01:49:12 +01:00
# include "bookmarksimport/bookmarksimportdialog.h"
2013-01-22 19:04:22 +01:00
# include "qztools.h"
2012-10-20 11:31:45 +02:00
# include "reloadstopbutton.h"
2011-12-14 22:30:05 +01:00
# include "enhancedmenu.h"
2013-02-11 13:08:11 +01:00
# include "navigationcontainer.h"
2012-01-11 21:58:25 +01:00
# include "settings.h"
2013-02-09 13:00:45 +01:00
# include "qzsettings.h"
2012-01-21 23:19:38 +01:00
# include "webtab.h"
2012-02-05 17:13:08 +01:00
# include "speeddial.h"
2013-02-09 14:08:12 +01:00
# include "menubar.h"
2014-02-08 23:01:01 +01:00
# include "bookmarkstools.h"
2014-02-09 01:09:08 +01:00
# include "bookmarksmenu.h"
2014-02-27 22:53:56 +01:00
# include "historymenu.h"
2014-03-10 16:55:11 +01:00
# include "mainmenu.h"
2011-03-02 16:57:41 +01:00
2014-09-26 19:28:24 +02:00
# include <algorithm>
2012-08-31 15:19:07 +02:00
# include <QKeyEvent>
2012-02-29 18:33:50 +01:00
# include <QSplitter>
# include <QStatusBar>
# include <QMenuBar>
# include <QTimer>
# include <QShortcut>
# include <QStackedWidget>
# include <QSqlQuery>
# include <QTextCodec>
# include <QFileDialog>
# include <QDesktopServices>
2015-01-27 11:01:52 +01:00
# include <QWebEngineHistory>
2015-02-08 11:42:01 +01:00
# include <QWebEngineSettings>
2012-02-29 18:33:50 +01:00
# include <QMessageBox>
2013-03-23 17:37:58 +01:00
# include <QDesktopWidget>
2013-05-12 10:59:33 +02:00
# include <QToolTip>
2013-11-26 14:14:36 +01:00
# include <QScrollArea>
2015-09-29 11:14:20 +02:00
# include <QCollator>
Add initial printing support with QtWebEngine >= 5.7.0 (#2068)
* Add initial printing support with QtWebEngine >= 5.7.0
This works by printing to PDF first, then sending the PDF to a printer
if printing to a physical printer was requested.
On *nix (including Mac OS X), we use the lpr command, which is typically
provided by CUPS nowadays. Currently, no options beyond the printer name
are passed, there is room for improvement there. (Okular has a
FilePrinter class that handles this in a more sophisticated way.)
On Windows, we use ShellExecuteW with the "printto" verb. In that case,
the printer name is unfortunately the only thing that can be passed. The
user experience may also be suboptimal depending on the PDF viewer
installed on the system. (E.g., Adobe Reader is reported to ignore
SW_HIDE.) And if there is no PDF viewer installed at all, it will of
course not work at all. But it is the best we can do without bundling
something like GhostScript (or requiring the user to install it).
* Printing: Let lpr autoremove the temporary file instead of QTemporaryFile
Only lpr knows for sure when it is safe to delete the temporary file.
* Printing: Use the callback version of printToPdf instead of the file one
The file version is also asynchronous and does not report when it is
done.
* Printing: Use async QProcess API instead of QProcess::execute to run lpr
This also required making tempFile a QTemporaryFile * instead of a
QTemporaryFile on the stack, because QTemporaryFile is a QObject and
cannot be copied.
* Printing: Adapt the FilePrinter from Okular to pass correct lpr args
The license of those files is GPLv2+, which is compatible with
QupZilla's GPLv3+ licensing.
2016-09-14 14:07:07 +02:00
# include <QTemporaryFile>
2014-03-03 14:47:47 +01:00
# ifdef QZ_WS_X11
2015-09-25 22:04:05 +02:00
# include <QX11Info>
# include <xcb/xcb.h>
# include <xcb/xcb_atom.h>
2012-12-22 15:01:55 +01:00
# endif
2012-12-20 14:45:35 +01:00
2014-03-10 16:55:11 +01:00
BrowserWindow : : BrowserWindow ( Qz : : BrowserWindowType type , const QUrl & startUrl )
2012-04-17 14:00:32 +02:00
: QMainWindow ( 0 )
2014-03-10 16:55:11 +01:00
, m_startUrl ( startUrl )
2013-02-15 22:18:46 +01:00
, m_windowType ( type )
2013-05-13 22:01:36 +02:00
, m_startTab ( 0 )
2016-03-30 09:10:57 +02:00
, m_startPage ( 0 )
2012-04-01 16:36:38 +02:00
, m_sideBarManager ( new SideBarManager ( this ) )
2011-10-15 16:37:32 +02:00
, m_statusBarMessage ( new StatusBarMessage ( this ) )
2015-10-05 17:39:52 +02:00
, m_isHtmlFullScreen ( false )
2014-03-31 10:01:04 +02:00
, m_hideNavigationTimer ( 0 )
2011-03-02 16:57:41 +01:00
{
2011-03-05 10:57:36 +01:00
setAttribute ( Qt : : WA_DeleteOnClose ) ;
2015-11-12 16:38:39 +01:00
setAttribute ( Qt : : WA_DontCreateNativeAncestors ) ;
setObjectName ( " mainwindow " ) ;
2012-01-16 18:28:56 +01:00
setWindowTitle ( tr ( " QupZilla " ) ) ;
2014-09-17 16:19:27 +02:00
setProperty ( " private " , mApp - > isPrivate ( ) ) ;
2012-06-26 11:49:39 +02:00
2011-03-02 16:57:41 +01:00
setupUi ( ) ;
setupMenu ( ) ;
2012-01-08 11:38:15 +01:00
2013-02-09 15:44:17 +01:00
m_hideNavigationTimer = new QTimer ( this ) ;
m_hideNavigationTimer - > setInterval ( 1000 ) ;
m_hideNavigationTimer - > setSingleShot ( true ) ;
connect ( m_hideNavigationTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( hideNavigationSlot ( ) ) ) ;
2014-03-10 00:47:07 +01:00
connect ( mApp , SIGNAL ( settingsReloaded ( ) ) , this , SLOT ( loadSettings ( ) ) ) ;
2013-02-09 15:44:17 +01:00
QTimer : : singleShot ( 0 , this , SLOT ( postLaunch ( ) ) ) ;
2013-07-07 12:32:55 +02:00
2014-03-10 00:47:07 +01:00
if ( mApp - > isPrivate ( ) ) {
2013-10-21 15:59:25 +02:00
QzTools : : setWmClass ( " QupZilla Browser (Private Window) " , this ) ;
}
else {
QzTools : : setWmClass ( " QupZilla Browser " , this ) ;
}
2011-03-02 16:57:41 +01:00
}
2014-03-10 19:41:44 +01:00
BrowserWindow : : ~ BrowserWindow ( )
{
2014-03-13 11:24:19 +01:00
mApp - > plugins ( ) - > emitMainWindowDeleted ( this ) ;
foreach ( const QPointer < QWidget > & pointer , m_deleteOnCloseWidgets ) {
if ( pointer ) {
pointer - > deleteLater ( ) ;
}
}
2014-03-10 19:41:44 +01:00
}
2014-03-10 16:55:11 +01:00
void BrowserWindow : : setStartTab ( WebTab * tab )
2013-05-13 22:01:36 +02:00
{
m_startTab = tab ;
}
2016-03-30 09:10:57 +02:00
void BrowserWindow : : setStartPage ( WebPage * page )
{
m_startPage = page ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : postLaunch ( )
2011-05-07 12:59:53 +02:00
{
loadSettings ( ) ;
2012-01-18 18:36:10 +01:00
2012-03-10 13:57:50 +01:00
bool addTab = true ;
2011-05-07 12:59:53 +02:00
QUrl startUrl ;
2012-03-14 14:04:20 +01:00
2015-09-28 14:51:38 +02:00
switch ( mApp - > afterLaunch ( ) ) {
case MainApplication : : OpenBlankPage :
2012-09-02 11:42:41 +02:00
startUrl = QUrl ( ) ;
2011-12-04 20:35:49 +01:00
break ;
2015-09-28 14:51:38 +02:00
case MainApplication : : OpenSpeedDial :
2011-12-04 20:35:49 +01:00
startUrl = QUrl ( " qupzilla:speeddial " ) ;
break ;
2015-09-28 14:51:38 +02:00
case MainApplication : : OpenHomePage :
case MainApplication : : RestoreSession :
2011-12-04 20:35:49 +01:00
startUrl = m_homepage ;
break ;
default :
break ;
}
2013-02-15 22:18:46 +01:00
switch ( m_windowType ) {
2012-01-21 23:19:38 +01:00
case Qz : : BW_FirstAppWindow :
2012-08-21 20:28:38 +02:00
if ( mApp - > isStartingAfterCrash ( ) ) {
2015-09-24 19:36:20 +02:00
addTab = false ;
startUrl . clear ( ) ;
m_tabWidget - > addView ( QUrl ( " qupzilla:restore " ) , Qz : : NT_CleanSelectedTabAtTheEnd ) ;
2011-11-06 17:01:23 +01:00
}
2015-09-28 14:51:38 +02:00
else if ( mApp - > afterLaunch ( ) = = MainApplication : : RestoreSession & & mApp - > restoreManager ( ) ) {
2014-03-10 00:47:07 +01:00
addTab = ! mApp - > restoreSession ( this , mApp - > restoreManager ( ) - > restoreData ( ) ) ;
2012-03-14 14:04:20 +01:00
}
2011-11-03 18:51:46 +01:00
break ;
2012-01-21 23:19:38 +01:00
case Qz : : BW_NewWindow :
2016-12-27 18:40:16 +01:00
case Qz : : BW_MacFirstWindow :
2011-11-03 18:51:46 +01:00
addTab = true ;
break ;
2012-01-21 23:19:38 +01:00
case Qz : : BW_OtherRestoredWindow :
2011-11-03 18:51:46 +01:00
addTab = false ;
break ;
}
2011-05-07 12:59:53 +02:00
2012-09-06 11:39:42 +02:00
show ( ) ;
2014-03-10 16:55:11 +01:00
if ( ! m_startUrl . isEmpty ( ) ) {
startUrl = m_startUrl ;
2011-05-07 12:59:53 +02:00
addTab = true ;
}
2013-05-13 22:01:36 +02:00
if ( m_startTab ) {
addTab = false ;
m_tabWidget - > addView ( m_startTab ) ;
}
2016-03-30 09:10:57 +02:00
if ( m_startPage ) {
addTab = false ;
m_tabWidget - > addView ( QUrl ( ) ) ;
weView ( ) - > setPage ( m_startPage ) ;
}
2011-12-05 19:54:17 +01:00
if ( addTab ) {
2015-10-06 09:46:23 +02:00
m_tabWidget - > addView ( startUrl , Qz : : NT_CleanSelectedTabAtTheEnd ) ;
2011-12-05 19:54:17 +01:00
2012-09-04 12:42:45 +02:00
if ( startUrl . isEmpty ( ) | | startUrl . toString ( ) = = QLatin1String ( " qupzilla:speeddial " ) ) {
2011-12-05 19:54:17 +01:00
locationBar ( ) - > setFocus ( ) ;
}
}
2014-04-01 16:34:08 +02:00
// Something went really wrong .. add one tab
2014-04-04 17:14:31 +02:00
if ( m_tabWidget - > tabBar ( ) - > normalTabsCount ( ) < = 0 ) {
2015-10-06 09:46:23 +02:00
m_tabWidget - > addView ( m_homepage , Qz : : NT_SelectedTabAtTheEnd ) ;
2011-11-06 17:01:23 +01:00
}
2011-05-07 12:59:53 +02:00
2012-03-05 13:16:34 +01:00
mApp - > plugins ( ) - > emitMainWindowCreated ( this ) ;
2011-05-07 12:59:53 +02:00
emit startingCompleted ( ) ;
2012-03-13 17:51:37 +01:00
2013-03-16 10:36:29 +01:00
raise ( ) ;
activateWindow ( ) ;
2013-11-26 14:14:36 +01:00
2016-01-27 13:23:28 +01:00
QTimer : : singleShot ( 0 , this , [ this ] ( ) {
// Scroll to current tab
tabWidget ( ) - > tabBar ( ) - > ensureVisible ( ) ;
// Update focus
2016-12-26 14:35:08 +01:00
if ( ! m_startPage & & LocationBar : : convertUrlToText ( weView ( ) - > page ( ) - > requestedUrl ( ) ) . isEmpty ( ) )
2016-01-27 13:23:28 +01:00
locationBar ( ) - > setFocus ( ) ;
else
weView ( ) - > setFocus ( ) ;
} ) ;
2011-05-07 12:59:53 +02:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : setupUi ( )
2011-05-07 12:59:53 +02:00
{
2011-10-17 09:59:09 +02:00
int locationBarWidth ;
int websearchBarWidth ;
2014-11-10 11:50:53 +01:00
QDesktopWidget * desktop = mApp - > desktop ( ) ;
2014-11-10 12:15:23 +01:00
int windowWidth = desktop - > availableGeometry ( ) . width ( ) / 1.3 ;
int windowHeight = desktop - > availableGeometry ( ) . height ( ) / 1.3 ;
2014-11-10 11:50:53 +01:00
2012-01-11 21:58:25 +01:00
Settings settings ;
2011-09-21 12:43:27 +02:00
settings . beginGroup ( " Browser-View-Settings " ) ;
if ( settings . value ( " WindowMaximised " , false ) . toBool ( ) ) {
2014-11-10 11:50:53 +01:00
resize ( windowWidth , windowHeight ) ;
2011-10-01 20:06:38 +02:00
setWindowState ( Qt : : WindowMaximized ) ;
2011-11-06 17:01:23 +01:00
}
else {
2013-03-23 17:37:58 +01:00
// Let the WM decides where to put new browser window
2013-08-03 22:17:15 +02:00
if ( ( m_windowType ! = Qz : : BW_FirstAppWindow & & m_windowType ! = Qz : : BW_MacFirstWindow ) & & mApp - > getWindow ( ) ) {
2013-03-23 17:37:58 +01:00
# ifdef Q_WS_WIN
// Windows WM places every new window in the middle of screen .. for some reason
QPoint p = mApp - > getWindow ( ) - > geometry ( ) . topLeft ( ) ;
p . setX ( p . x ( ) + 30 ) ;
p . setY ( p . y ( ) + 30 ) ;
2014-11-10 11:50:53 +01:00
if ( ! desktop - > availableGeometry ( mApp - > getWindow ( ) ) . contains ( p ) ) {
p . setX ( desktop - > availableGeometry ( mApp - > getWindow ( ) ) . x ( ) + 30 ) ;
p . setY ( desktop - > availableGeometry ( mApp - > getWindow ( ) ) . y ( ) + 30 ) ;
2013-03-23 17:37:58 +01:00
}
2014-11-10 11:50:53 +01:00
2013-03-23 17:37:58 +01:00
setGeometry ( QRect ( p , mApp - > getWindow ( ) - > size ( ) ) ) ;
# else
resize ( mApp - > getWindow ( ) - > size ( ) ) ;
# endif
2012-02-01 20:31:51 +01:00
}
2013-03-23 17:37:58 +01:00
else if ( ! restoreGeometry ( settings . value ( " WindowGeometry " ) . toByteArray ( ) ) ) {
# ifdef Q_WS_WIN
2014-11-10 11:50:53 +01:00
setGeometry ( QRect ( desktop - > availableGeometry ( mApp - > getWindow ( ) ) . x ( ) + 30 ,
desktop - > availableGeometry ( mApp - > getWindow ( ) ) . y ( ) + 30 , windowWidth , windowHeight ) ) ;
2013-03-23 17:37:58 +01:00
# else
2014-11-10 11:50:53 +01:00
resize ( windowWidth , windowHeight ) ;
2013-03-23 17:37:58 +01:00
# endif
2011-11-09 16:58:25 +01:00
}
2011-09-21 12:43:27 +02:00
}
2011-12-03 11:27:53 +01:00
locationBarWidth = settings . value ( " LocationBarWidth " , 480 ) . toInt ( ) ;
websearchBarWidth = settings . value ( " WebSearchBarWidth " , 140 ) . toInt ( ) ;
2012-04-04 18:48:54 +02:00
settings . endGroup ( ) ;
2011-10-17 09:59:09 +02:00
2011-08-02 16:19:20 +02:00
QWidget * widget = new QWidget ( this ) ;
2011-12-03 12:07:10 +01:00
widget - > setCursor ( Qt : : ArrowCursor ) ;
2011-09-11 19:15:06 +02:00
setCentralWidget ( widget ) ;
2011-08-02 16:19:20 +02:00
m_mainLayout = new QVBoxLayout ( widget ) ;
2011-11-06 17:01:23 +01:00
m_mainLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2011-08-02 16:19:20 +02:00
m_mainLayout - > setSpacing ( 0 ) ;
2011-09-11 19:15:06 +02:00
m_mainSplitter = new QSplitter ( this ) ;
2011-10-28 23:17:38 +02:00
m_mainSplitter - > setObjectName ( " sidebar-splitter " ) ;
2011-07-11 20:30:49 +02:00
m_tabWidget = new TabWidget ( this ) ;
2011-05-07 12:59:53 +02:00
m_superMenu = new QMenu ( this ) ;
2014-03-10 16:55:11 +01:00
m_navigationToolbar = new NavigationBar ( this ) ;
m_navigationToolbar - > setSplitterSizes ( locationBarWidth , websearchBarWidth ) ;
2011-09-11 19:15:06 +02:00
m_bookmarksToolbar = new BookmarksToolbar ( this ) ;
2012-08-30 10:46:58 +02:00
2013-02-11 13:08:11 +01:00
m_navigationContainer = new NavigationContainer ( this ) ;
2014-03-30 16:38:34 +02:00
m_navigationContainer - > addWidget ( m_navigationToolbar ) ;
m_navigationContainer - > addWidget ( m_bookmarksToolbar ) ;
2014-04-04 17:14:31 +02:00
m_navigationContainer - > setTabBar ( m_tabWidget - > tabBar ( ) ) ;
2013-02-09 13:00:45 +01:00
2011-09-11 19:15:06 +02:00
m_mainSplitter - > addWidget ( m_tabWidget ) ;
m_mainSplitter - > setCollapsible ( 0 , false ) ;
2011-05-07 12:59:53 +02:00
2014-03-30 16:38:34 +02:00
m_mainLayout - > addWidget ( m_navigationContainer ) ;
m_mainLayout - > addWidget ( m_mainSplitter ) ;
2011-09-11 19:15:06 +02:00
statusBar ( ) - > setObjectName ( " mainwindow-statusbar " ) ;
2011-12-03 12:07:10 +01:00
statusBar ( ) - > setCursor ( Qt : : ArrowCursor ) ;
2011-05-07 12:59:53 +02:00
m_progressBar = new ProgressBar ( statusBar ( ) ) ;
m_adblockIcon = new AdBlockIcon ( this ) ;
m_ipLabel = new QLabel ( this ) ;
2011-09-11 19:15:06 +02:00
m_ipLabel - > setObjectName ( " statusbar-ip-label " ) ;
2011-05-07 12:59:53 +02:00
m_ipLabel - > setToolTip ( tr ( " IP Address of current page " ) ) ;
2013-05-26 15:46:21 +02:00
statusBar ( ) - > addPermanentWidget ( m_progressBar ) ;
statusBar ( ) - > addPermanentWidget ( m_ipLabel ) ;
statusBar ( ) - > addPermanentWidget ( m_adblockIcon ) ;
2013-05-12 10:59:33 +02:00
// Workaround for Oxygen tooltips not having transparent background
QPalette pal = QToolTip : : palette ( ) ;
QColor col = pal . window ( ) . color ( ) ;
col . setAlpha ( 0 ) ;
pal . setColor ( QPalette : : Window , col ) ;
QToolTip : : setPalette ( pal ) ;
2014-03-17 15:01:28 +01:00
// Set some sane minimum width
setMinimumWidth ( 300 ) ;
2011-05-07 12:59:53 +02:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : setupMenu ( )
2011-05-07 12:59:53 +02:00
{
2017-02-10 19:00:58 +01:00
# ifdef Q_OS_MACOS
2014-09-25 14:27:25 +02:00
static MainMenu * macMainMenu = 0 ;
if ( ! macMainMenu ) {
macMainMenu = new MainMenu ( this , 0 ) ;
macMainMenu - > initMenuBar ( new QMenuBar ( 0 ) ) ;
}
else {
macMainMenu - > setWindow ( this ) ;
}
2014-10-07 11:04:31 +02:00
m_mainMenu = macMainMenu ;
2016-03-19 14:04:25 +01:00
m_mainMenu - > initSuperMenu ( m_superMenu ) ;
2014-09-25 14:27:25 +02:00
# else
2014-03-10 16:55:11 +01:00
setMenuBar ( new MenuBar ( this ) ) ;
2013-03-23 00:47:55 +01:00
2014-03-10 16:55:11 +01:00
m_mainMenu = new MainMenu ( this , this ) ;
m_mainMenu - > initMenuBar ( menuBar ( ) ) ;
m_mainMenu - > initSuperMenu ( m_superMenu ) ;
2014-09-25 14:27:25 +02:00
# endif
2014-03-15 19:58:19 +01:00
// Setup other shortcuts
QShortcut * reloadBypassCacheAction = new QShortcut ( QKeySequence ( QSL ( " Ctrl+F5 " ) ) , this ) ;
QShortcut * reloadBypassCacheAction2 = new QShortcut ( QKeySequence ( QSL ( " Ctrl+Shift+R " ) ) , this ) ;
connect ( reloadBypassCacheAction , SIGNAL ( activated ( ) ) , this , SLOT ( reloadBypassCache ( ) ) ) ;
connect ( reloadBypassCacheAction2 , SIGNAL ( activated ( ) ) , this , SLOT ( reloadBypassCache ( ) ) ) ;
2014-05-11 14:25:57 +02:00
QShortcut * closeTabAction = new QShortcut ( QKeySequence ( QSL ( " Ctrl+W " ) ) , this ) ;
QShortcut * closeTabAction2 = new QShortcut ( QKeySequence ( QSL ( " Ctrl+F4 " ) ) , this ) ;
connect ( closeTabAction , SIGNAL ( activated ( ) ) , this , SLOT ( closeTab ( ) ) ) ;
connect ( closeTabAction2 , SIGNAL ( activated ( ) ) , this , SLOT ( closeTab ( ) ) ) ;
2014-03-15 19:58:19 +01:00
QShortcut * reloadAction = new QShortcut ( QKeySequence ( " Ctrl+R " ) , this ) ;
connect ( reloadAction , SIGNAL ( activated ( ) ) , this , SLOT ( reload ( ) ) ) ;
QShortcut * openLocationAction = new QShortcut ( QKeySequence ( " Alt+D " ) , this ) ;
connect ( openLocationAction , SIGNAL ( activated ( ) ) , this , SLOT ( openLocation ( ) ) ) ;
2014-05-11 14:25:57 +02:00
QShortcut * inspectorAction = new QShortcut ( QKeySequence ( QSL ( " F12 " ) ) , this ) ;
2015-09-29 23:35:16 +02:00
connect ( inspectorAction , SIGNAL ( activated ( ) ) , this , SLOT ( toggleWebInspector ( ) ) ) ;
2014-03-10 16:55:11 +01:00
}
2011-05-07 12:59:53 +02:00
2014-10-07 16:15:23 +02:00
QAction * BrowserWindow : : createEncodingAction ( const QString & codecName ,
const QString & activeCodecName , QMenu * menu )
2014-07-22 10:02:08 +02:00
{
QAction * action = new QAction ( codecName , menu ) ;
action - > setData ( codecName ) ;
action - > setCheckable ( true ) ;
connect ( action , SIGNAL ( triggered ( ) ) , this , SLOT ( changeEncoding ( ) ) ) ;
if ( activeCodecName . compare ( codecName , Qt : : CaseInsensitive ) = = 0 ) {
action - > setChecked ( true ) ;
}
return action ;
}
2014-10-07 16:15:23 +02:00
void BrowserWindow : : createEncodingSubMenu ( const QString & name , QStringList & codecNames , QMenu * menu )
2014-07-22 10:02:08 +02:00
{
if ( codecNames . isEmpty ( ) ) {
return ;
}
2015-09-29 11:14:20 +02:00
QCollator collator ;
collator . setNumericMode ( true ) ;
std : : sort ( codecNames . begin ( ) , codecNames . end ( ) , [ collator ] ( const QString & a , const QString & b ) {
return collator . compare ( a , b ) < 0 ;
} ) ;
2014-07-22 10:02:08 +02:00
QMenu * subMenu = new QMenu ( name , menu ) ;
2015-10-01 18:02:36 +02:00
const QString activeCodecName = QWebEngineSettings : : defaultSettings ( ) - > defaultTextEncoding ( ) ;
2014-07-22 10:02:08 +02:00
foreach ( const QString & codecName , codecNames ) {
subMenu - > addAction ( createEncodingAction ( codecName , activeCodecName , subMenu ) ) ;
}
menu - > addMenu ( subMenu ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : loadSettings ( )
2011-03-02 16:57:41 +01:00
{
2012-01-11 21:58:25 +01:00
Settings settings ;
2011-03-02 16:57:41 +01:00
//Url settings
settings . beginGroup ( " Web-URL-Settings " ) ;
2011-11-06 17:01:23 +01:00
m_homepage = settings . value ( " homepage " , " qupzilla:start " ) . toUrl ( ) ;
2011-03-02 16:57:41 +01:00
settings . endGroup ( ) ;
//Browser Window settings
settings . beginGroup ( " Browser-View-Settings " ) ;
2016-01-24 16:29:46 +01:00
bool showStatusBar = settings . value ( " showStatusBar " , false ) . toBool ( ) ;
2012-10-20 11:31:45 +02:00
bool showReloadButton = settings . value ( " showReloadButton " , true ) . toBool ( ) ;
bool showHomeButton = settings . value ( " showHomeButton " , true ) . toBool ( ) ;
bool showBackForwardButtons = settings . value ( " showBackForwardButtons " , true ) . toBool ( ) ;
bool showAddTabButton = settings . value ( " showAddTabButton " , false ) . toBool ( ) ;
2012-07-19 19:56:58 +02:00
bool showWebSearchBar = settings . value ( " showWebSearchBar " , true ) . toBool ( ) ;
2011-11-06 17:01:23 +01:00
bool showBookmarksToolbar = settings . value ( " showBookmarksToolbar " , true ) . toBool ( ) ;
bool showNavigationToolbar = settings . value ( " showNavigationToolbar " , true ) . toBool ( ) ;
2016-01-24 16:29:46 +01:00
bool showMenuBar = settings . value ( " showMenubar " , false ) . toBool ( ) ;
2012-01-14 11:46:06 +01:00
m_sideBarWidth = settings . value ( " SideBarWidth " , 250 ) . toInt ( ) ;
2012-02-02 15:54:38 +01:00
m_webViewWidth = settings . value ( " WebViewWidth " , 2000 ) . toInt ( ) ;
2013-12-30 13:43:48 +01:00
const QString activeSideBar = settings . value ( " SideBar " , " None " ) . toString ( ) ;
2013-03-01 22:53:50 +01:00
// Make sure both menubar and navigationbar are not hidden
// Fixes #781
if ( ! showNavigationToolbar ) {
showMenuBar = true ;
settings . setValue ( " showMenubar " , true ) ;
}
2011-03-02 16:57:41 +01:00
settings . endGroup ( ) ;
2012-11-28 11:27:30 +01:00
settings . beginGroup ( " Shortcuts " ) ;
m_useTabNumberShortcuts = settings . value ( " useTabNumberShortcuts " , true ) . toBool ( ) ;
m_useSpeedDialNumberShortcuts = settings . value ( " useSpeedDialNumberShortcuts " , true ) . toBool ( ) ;
2014-04-05 03:00:06 +02:00
m_useSingleKeyShortcuts = settings . value ( " useSingleKeyShortcuts " , false ) . toBool ( ) ;
2012-11-28 11:27:30 +01:00
settings . endGroup ( ) ;
2011-03-29 20:30:05 +02:00
2014-07-17 23:05:38 +02:00
settings . beginGroup ( " Web-Browser-Settings " ) ;
QAction * quitAction = m_mainMenu - > action ( QSL ( " Standard/Quit " ) ) ;
if ( settings . value ( " closeAppWithCtrlQ " , true ) . toBool ( ) ) {
2015-11-12 16:53:09 +01:00
quitAction - > setShortcut ( QzTools : : actionShortcut ( QKeySequence : : Quit , QKeySequence ( QSL ( " Ctrl+Q " ) ) ) ) ;
2014-07-17 23:05:38 +02:00
} else {
quitAction - > setShortcut ( QKeySequence ( ) ) ;
}
settings . endGroup ( ) ;
2012-12-02 00:59:17 +01:00
m_adblockIcon - > setEnabled ( settings . value ( " AdBlock/enabled " , true ) . toBool ( ) ) ;
2011-03-02 16:57:41 +01:00
2014-01-02 13:10:23 +01:00
statusBar ( ) - > setVisible ( ! isFullScreen ( ) & & showStatusBar ) ;
2011-03-02 16:57:41 +01:00
m_bookmarksToolbar - > setVisible ( showBookmarksToolbar ) ;
2014-03-10 16:55:11 +01:00
m_navigationToolbar - > setVisible ( showNavigationToolbar ) ;
2014-09-25 14:42:36 +02:00
2017-02-10 19:00:58 +01:00
# ifndef Q_OS_MACOS
2014-01-02 13:10:23 +01:00
menuBar ( ) - > setVisible ( ! isFullScreen ( ) & & showMenuBar ) ;
2014-09-25 14:42:36 +02:00
# endif
2011-03-02 16:57:41 +01:00
2014-03-10 16:55:11 +01:00
m_navigationToolbar - > setSuperMenuVisible ( ! showMenuBar ) ;
m_navigationToolbar - > buttonReloadStop ( ) - > setVisible ( showReloadButton ) ;
m_navigationToolbar - > buttonHome ( ) - > setVisible ( showHomeButton ) ;
m_navigationToolbar - > buttonBack ( ) - > setVisible ( showBackForwardButtons ) ;
2014-04-19 13:10:20 +02:00
m_navigationToolbar - > buttonForward ( ) - > setVisible ( showBackForwardButtons ) ;
2014-03-10 16:55:11 +01:00
m_navigationToolbar - > webSearchBar ( ) - > setVisible ( showWebSearchBar ) ;
m_navigationToolbar - > buttonAddTab ( ) - > setVisible ( showAddTabButton ) ;
2011-03-02 16:57:41 +01:00
2012-04-30 16:33:14 +02:00
m_sideBarManager - > showSideBar ( activeSideBar , false ) ;
2011-03-02 16:57:41 +01:00
}
2014-02-27 22:53:56 +01:00
void BrowserWindow : : goForward ( )
2012-02-01 17:01:08 +01:00
{
weView ( ) - > forward ( ) ;
}
2014-03-15 19:58:19 +01:00
void BrowserWindow : : reload ( )
{
weView ( ) - > reload ( ) ;
}
void BrowserWindow : : reloadBypassCache ( )
{
weView ( ) - > reloadBypassCache ( ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : goBack ( )
2012-02-01 17:01:08 +01:00
{
weView ( ) - > back ( ) ;
}
2014-02-19 22:07:21 +01:00
TabbedWebView * BrowserWindow : : weView ( ) const
2012-02-01 17:01:08 +01:00
{
return weView ( m_tabWidget - > currentIndex ( ) ) ;
}
2014-02-19 22:07:21 +01:00
TabbedWebView * BrowserWindow : : weView ( int index ) const
2012-02-01 17:01:08 +01:00
{
WebTab * webTab = qobject_cast < WebTab * > ( m_tabWidget - > widget ( index ) ) ;
if ( ! webTab ) {
return 0 ;
}
2014-03-18 20:00:34 +01:00
return webTab - > webView ( ) ;
2012-02-01 17:01:08 +01:00
}
2014-02-19 22:07:21 +01:00
LocationBar * BrowserWindow : : locationBar ( ) const
2012-02-01 17:01:08 +01:00
{
return qobject_cast < LocationBar * > ( m_tabWidget - > locationBars ( ) - > currentWidget ( ) ) ;
}
2014-03-10 16:55:11 +01:00
TabWidget * BrowserWindow : : tabWidget ( ) const
2013-02-15 22:18:46 +01:00
{
2014-03-10 16:55:11 +01:00
return m_tabWidget ;
2013-02-15 22:18:46 +01:00
}
2014-03-10 16:55:11 +01:00
BookmarksToolbar * BrowserWindow : : bookmarksToolbar ( ) const
2013-02-09 14:08:12 +01:00
{
2014-03-10 16:55:11 +01:00
return m_bookmarksToolbar ;
2013-02-09 14:08:12 +01:00
}
2014-03-10 16:55:11 +01:00
StatusBarMessage * BrowserWindow : : statusBarMessage ( ) const
2013-03-23 20:39:55 +01:00
{
2014-03-10 16:55:11 +01:00
return m_statusBarMessage ;
2013-03-23 20:39:55 +01:00
}
2014-03-10 16:55:11 +01:00
NavigationBar * BrowserWindow : : navigationBar ( ) const
2013-08-03 22:09:54 +02:00
{
2014-03-10 16:55:11 +01:00
return m_navigationToolbar ;
2013-08-03 22:09:54 +02:00
}
2014-03-10 16:55:11 +01:00
SideBarManager * BrowserWindow : : sideBarManager ( ) const
2011-09-17 11:13:38 +02:00
{
2014-03-10 16:55:11 +01:00
return m_sideBarManager ;
2011-09-17 11:13:38 +02:00
}
2014-03-10 16:55:11 +01:00
QLabel * BrowserWindow : : ipLabel ( ) const
2011-12-17 15:09:17 +01:00
{
2014-03-10 16:55:11 +01:00
return m_ipLabel ;
2011-12-17 15:09:17 +01:00
}
2014-03-10 16:55:11 +01:00
AdBlockIcon * BrowserWindow : : adBlockIcon ( ) const
2011-12-17 15:09:17 +01:00
{
2014-03-10 16:55:11 +01:00
return m_adblockIcon ;
2011-12-17 15:09:17 +01:00
}
2014-03-10 16:55:11 +01:00
QMenu * BrowserWindow : : superMenu ( ) const
2011-03-02 16:57:41 +01:00
{
2014-03-10 16:55:11 +01:00
return m_superMenu ;
2011-03-02 16:57:41 +01:00
}
2014-03-10 16:55:11 +01:00
QUrl BrowserWindow : : homepageUrl ( ) const
2011-11-27 15:43:54 +01:00
{
2014-03-10 16:55:11 +01:00
return m_homepage ;
2011-11-27 15:43:54 +01:00
}
2014-03-10 16:55:11 +01:00
Qz : : BrowserWindowType BrowserWindow : : windowType ( ) const
2011-11-27 15:43:54 +01:00
{
2014-03-10 16:55:11 +01:00
return m_windowType ;
2011-11-27 15:43:54 +01:00
}
2014-03-10 16:55:11 +01:00
QAction * BrowserWindow : : action ( const QString & name ) const
2013-01-26 21:58:09 +01:00
{
2014-03-10 16:55:11 +01:00
return m_mainMenu - > action ( name ) ;
2013-01-26 21:58:09 +01:00
}
2014-03-10 16:55:11 +01:00
void BrowserWindow : : setWindowTitle ( const QString & t )
2011-03-17 20:46:53 +01:00
{
2014-03-10 16:55:11 +01:00
QString title = t ;
2011-03-17 20:46:53 +01:00
2014-03-10 16:55:11 +01:00
if ( mApp - > isPrivate ( ) ) {
title . append ( tr ( " (Private Browsing) " ) ) ;
2011-03-17 20:46:53 +01:00
}
2014-03-10 16:55:11 +01:00
QMainWindow : : setWindowTitle ( title ) ;
2011-03-17 20:46:53 +01:00
}
2014-03-10 16:55:11 +01:00
void BrowserWindow : : changeEncoding ( )
2011-03-17 20:46:53 +01:00
{
2014-03-10 16:55:11 +01:00
if ( QAction * action = qobject_cast < QAction * > ( sender ( ) ) ) {
2013-12-30 13:43:48 +01:00
const QString encoding = action - > data ( ) . toString ( ) ;
2015-10-01 18:02:36 +02:00
QWebEngineSettings : : defaultSettings ( ) - > setDefaultTextEncoding ( encoding ) ;
2012-03-30 12:02:49 +02:00
Settings settings ;
settings . setValue ( " Web-Browser-Settings/DefaultEncoding " , encoding ) ;
2014-03-10 16:55:11 +01:00
weView ( ) - > reload ( ) ;
2011-03-17 20:46:53 +01:00
}
}
Add initial printing support with QtWebEngine >= 5.7.0 (#2068)
* Add initial printing support with QtWebEngine >= 5.7.0
This works by printing to PDF first, then sending the PDF to a printer
if printing to a physical printer was requested.
On *nix (including Mac OS X), we use the lpr command, which is typically
provided by CUPS nowadays. Currently, no options beyond the printer name
are passed, there is room for improvement there. (Okular has a
FilePrinter class that handles this in a more sophisticated way.)
On Windows, we use ShellExecuteW with the "printto" verb. In that case,
the printer name is unfortunately the only thing that can be passed. The
user experience may also be suboptimal depending on the PDF viewer
installed on the system. (E.g., Adobe Reader is reported to ignore
SW_HIDE.) And if there is no PDF viewer installed at all, it will of
course not work at all. But it is the best we can do without bundling
something like GhostScript (or requiring the user to install it).
* Printing: Let lpr autoremove the temporary file instead of QTemporaryFile
Only lpr knows for sure when it is safe to delete the temporary file.
* Printing: Use the callback version of printToPdf instead of the file one
The file version is also asynchronous and does not report when it is
done.
* Printing: Use async QProcess API instead of QProcess::execute to run lpr
This also required making tempFile a QTemporaryFile * instead of a
QTemporaryFile on the stack, because QTemporaryFile is a QObject and
cannot be copied.
* Printing: Adapt the FilePrinter from Okular to pass correct lpr args
The license of those files is GPLv2+, which is compatible with
QupZilla's GPLv3+ licensing.
2016-09-14 14:07:07 +02:00
void BrowserWindow : : printPage ( )
{
2017-02-06 20:39:57 +01:00
weView ( ) - > printPage ( ) ;
Add initial printing support with QtWebEngine >= 5.7.0 (#2068)
* Add initial printing support with QtWebEngine >= 5.7.0
This works by printing to PDF first, then sending the PDF to a printer
if printing to a physical printer was requested.
On *nix (including Mac OS X), we use the lpr command, which is typically
provided by CUPS nowadays. Currently, no options beyond the printer name
are passed, there is room for improvement there. (Okular has a
FilePrinter class that handles this in a more sophisticated way.)
On Windows, we use ShellExecuteW with the "printto" verb. In that case,
the printer name is unfortunately the only thing that can be passed. The
user experience may also be suboptimal depending on the PDF viewer
installed on the system. (E.g., Adobe Reader is reported to ignore
SW_HIDE.) And if there is no PDF viewer installed at all, it will of
course not work at all. But it is the best we can do without bundling
something like GhostScript (or requiring the user to install it).
* Printing: Let lpr autoremove the temporary file instead of QTemporaryFile
Only lpr knows for sure when it is safe to delete the temporary file.
* Printing: Use the callback version of printToPdf instead of the file one
The file version is also asynchronous and does not report when it is
done.
* Printing: Use async QProcess API instead of QProcess::execute to run lpr
This also required making tempFile a QTemporaryFile * instead of a
QTemporaryFile on the stack, because QTemporaryFile is a QObject and
cannot be copied.
* Printing: Adapt the FilePrinter from Okular to pass correct lpr args
The license of those files is GPLv2+, which is compatible with
QupZilla's GPLv3+ licensing.
2016-09-14 14:07:07 +02:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : bookmarkPage ( )
2011-03-02 16:57:41 +01:00
{
2014-02-08 23:01:01 +01:00
TabbedWebView * view = weView ( ) ;
BookmarksTools : : addBookmarkDialog ( this , view - > url ( ) , view - > title ( ) ) ;
2011-03-02 16:57:41 +01:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : bookmarkAllTabs ( )
2014-02-09 11:02:51 +01:00
{
BookmarksTools : : bookmarkAllTabsDialog ( this , m_tabWidget ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : addBookmark ( const QUrl & url , const QString & title )
2011-03-02 16:57:41 +01:00
{
2014-02-08 23:01:01 +01:00
BookmarksTools : : addBookmarkDialog ( this , url , title ) ;
2011-03-02 16:57:41 +01:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : goHome ( )
2011-10-26 19:23:50 +02:00
{
loadAddress ( m_homepage ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : goHomeInNewTab ( )
2011-10-26 19:23:50 +02:00
{
2012-01-21 23:19:38 +01:00
m_tabWidget - > addView ( m_homepage , Qz : : NT_SelectedTab ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : loadActionUrl ( QObject * obj )
2011-03-02 16:57:41 +01:00
{
2013-02-07 14:01:01 +01:00
if ( ! obj ) {
obj = sender ( ) ;
}
if ( QAction * action = qobject_cast < QAction * > ( obj ) ) {
2011-03-02 16:57:41 +01:00
loadAddress ( action - > data ( ) . toUrl ( ) ) ;
}
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : loadActionUrlInNewTab ( QObject * obj )
2011-09-19 20:49:39 +02:00
{
2013-02-07 14:01:01 +01:00
if ( ! obj ) {
obj = sender ( ) ;
}
if ( QAction * action = qobject_cast < QAction * > ( obj ) ) {
2012-02-07 18:37:44 +01:00
m_tabWidget - > addView ( action - > data ( ) . toUrl ( ) , Qz : : NT_SelectedTabAtTheEnd ) ;
2011-09-19 20:49:39 +02:00
}
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : loadAddress ( const QUrl & url )
2011-07-31 00:50:40 +02:00
{
2014-02-09 15:07:19 +01:00
if ( weView ( ) - > webTab ( ) - > isPinned ( ) ) {
int index = m_tabWidget - > addView ( url , qzSettings - > newTabPosition ) ;
weView ( index ) - > setFocus ( ) ;
}
else {
weView ( ) - > setFocus ( ) ;
weView ( ) - > load ( url ) ;
}
2011-07-31 00:50:40 +02:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : showHistoryManager ( )
2011-03-02 16:57:41 +01:00
{
2011-07-29 15:39:43 +02:00
mApp - > browsingLibrary ( ) - > showHistory ( this ) ;
2011-03-02 16:57:41 +01:00
}
2015-05-24 21:26:17 +02:00
void BrowserWindow : : showSource ( WebView * view )
2011-03-02 16:57:41 +01:00
{
2015-05-24 21:26:17 +02:00
if ( ! view )
view = weView ( ) ;
view - > showSource ( ) ;
2011-03-02 16:57:41 +01:00
}
2014-02-19 22:07:21 +01:00
SideBar * BrowserWindow : : addSideBar ( )
2011-09-11 19:15:06 +02:00
{
2012-01-18 18:36:10 +01:00
if ( m_sideBar ) {
2012-04-01 16:36:38 +02:00
return m_sideBar . data ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-09-11 19:15:06 +02:00
2012-04-01 16:36:38 +02:00
m_sideBar = new SideBar ( m_sideBarManager , this ) ;
2011-09-11 19:15:06 +02:00
2011-12-09 21:56:01 +01:00
m_mainSplitter - > insertWidget ( 0 , m_sideBar . data ( ) ) ;
2011-09-11 19:15:06 +02:00
m_mainSplitter - > setCollapsible ( 0 , false ) ;
2011-10-17 09:59:09 +02:00
2012-01-14 11:46:06 +01:00
m_mainSplitter - > setSizes ( QList < int > ( ) < < m_sideBarWidth < < m_webViewWidth ) ;
2012-04-01 16:36:38 +02:00
return m_sideBar . data ( ) ;
2011-10-17 09:59:09 +02:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : saveSideBarWidth ( )
2011-10-17 09:59:09 +02:00
{
// That +1 is important here, without it, the sidebar width would
// decrease by 1 pixel every close
2012-01-13 16:51:58 +01:00
2012-01-14 11:46:06 +01:00
m_sideBarWidth = m_mainSplitter - > sizes ( ) . at ( 0 ) + 1 ;
m_webViewWidth = width ( ) - m_sideBarWidth ;
2011-04-15 20:45:22 +02:00
}
2014-03-13 12:31:08 +01:00
void BrowserWindow : : toggleShowMenubar ( )
2011-03-02 16:57:41 +01:00
{
2017-02-10 19:00:58 +01:00
# ifdef Q_OS_MACOS
2014-03-13 15:58:39 +01:00
// We use one shared global menubar on Mac that can't be hidden
2014-03-13 12:31:08 +01:00
return ;
# endif
2011-03-02 16:57:41 +01:00
2014-02-12 14:23:23 +01:00
setUpdatesEnabled ( false ) ;
2014-03-13 12:31:08 +01:00
menuBar ( ) - > setVisible ( ! menuBar ( ) - > isVisible ( ) ) ;
m_navigationToolbar - > setSuperMenuVisible ( ! menuBar ( ) - > isVisible ( ) ) ;
2014-02-12 14:23:23 +01:00
setUpdatesEnabled ( true ) ;
2011-03-02 16:57:41 +01:00
2014-03-13 12:31:08 +01:00
Settings ( ) . setValue ( " Browser-View-Settings/showMenubar " , menuBar ( ) - > isVisible ( ) ) ;
// Make sure we show Navigation Toolbar when Menu Bar is hidden
2014-03-10 16:55:11 +01:00
if ( ! m_navigationToolbar - > isVisible ( ) & & ! menuBar ( ) - > isVisible ( ) ) {
2014-03-13 12:31:08 +01:00
toggleShowNavigationToolbar ( ) ;
2011-11-06 17:01:23 +01:00
}
2014-03-13 12:31:08 +01:00
}
2011-03-02 16:57:41 +01:00
2014-03-13 13:38:14 +01:00
void BrowserWindow : : toggleShowStatusBar ( )
{
setUpdatesEnabled ( false ) ;
statusBar ( ) - > setVisible ( ! statusBar ( ) - > isVisible ( ) ) ;
setUpdatesEnabled ( true ) ;
2014-03-14 13:33:33 +01:00
Settings ( ) . setValue ( " Browser-View-Settings/showStatusBar " , statusBar ( ) - > isVisible ( ) ) ;
2014-03-13 13:38:14 +01:00
}
2014-03-13 12:31:08 +01:00
void BrowserWindow : : toggleShowBookmarksToolbar ( )
{
2014-02-12 14:23:23 +01:00
setUpdatesEnabled ( false ) ;
2014-03-13 12:31:08 +01:00
m_bookmarksToolbar - > setVisible ( ! m_bookmarksToolbar - > isVisible ( ) ) ;
2011-04-04 20:04:29 +02:00
2014-03-13 12:31:08 +01:00
setUpdatesEnabled ( true ) ;
Settings ( ) . setValue ( " Browser-View-Settings/showBookmarksToolbar " , m_bookmarksToolbar - > isVisible ( ) ) ;
2016-08-23 08:57:11 +02:00
Settings ( ) . setValue ( " Browser-View-Settings/instantBookmarksToolbar " , false ) ;
2014-03-13 12:31:08 +01:00
}
void BrowserWindow : : toggleShowNavigationToolbar ( )
{
setUpdatesEnabled ( false ) ;
m_navigationToolbar - > setVisible ( ! m_navigationToolbar - > isVisible ( ) ) ;
2014-02-12 14:23:23 +01:00
setUpdatesEnabled ( true ) ;
2014-03-13 12:31:08 +01:00
Settings ( ) . setValue ( " Browser-View-Settings/showNavigationToolbar " , m_navigationToolbar - > isVisible ( ) ) ;
2017-02-10 19:00:58 +01:00
# ifndef Q_OS_MACOS
2014-03-13 12:31:08 +01:00
// Make sure we show Menu Bar when Navigation Toolbar is hidden
if ( ! m_navigationToolbar - > isVisible ( ) & & ! menuBar ( ) - > isVisible ( ) ) {
toggleShowMenubar ( ) ;
}
2014-09-25 14:42:36 +02:00
# endif
2014-03-13 12:31:08 +01:00
}
void BrowserWindow : : toggleTabsOnTop ( bool enable )
{
qzSettings - > tabsOnTop = enable ;
2014-03-30 16:38:34 +02:00
m_navigationContainer - > toggleTabsOnTop ( enable ) ;
2011-03-02 16:57:41 +01:00
}
2014-03-13 13:38:14 +01:00
void BrowserWindow : : toggleFullScreen ( )
{
2015-11-06 17:55:57 +01:00
if ( m_isHtmlFullScreen ) {
weView ( ) - > triggerPageAction ( QWebEnginePage : : ExitFullScreen ) ;
return ;
2014-03-13 13:38:14 +01:00
}
2015-11-06 17:55:57 +01:00
if ( isFullScreen ( ) )
2016-07-10 17:26:07 +02:00
setWindowState ( windowState ( ) & ~ Qt : : WindowFullScreen ) ;
2015-11-06 17:55:57 +01:00
else
2016-07-10 17:26:07 +02:00
setWindowState ( windowState ( ) | Qt : : WindowFullScreen ) ;
2011-03-02 16:57:41 +01:00
}
2015-10-05 17:39:52 +02:00
void BrowserWindow : : enterHtmlFullScreen ( )
{
showFullScreen ( ) ;
m_isHtmlFullScreen = true ;
}
2014-03-31 17:46:59 +02:00
void BrowserWindow : : showWebInspector ( )
2011-03-02 16:57:41 +01:00
{
2014-03-31 17:46:59 +02:00
if ( weView ( ) & & weView ( ) - > webTab ( ) ) {
weView ( ) - > webTab ( ) - > showWebInspector ( ) ;
2012-08-30 10:46:58 +02:00
}
2011-03-02 16:57:41 +01:00
}
2015-09-29 23:35:16 +02:00
void BrowserWindow : : toggleWebInspector ( )
{
if ( weView ( ) & & weView ( ) - > webTab ( ) ) {
weView ( ) - > webTab ( ) - > toggleWebInspector ( ) ;
}
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : refreshHistory ( )
2011-09-11 19:15:06 +02:00
{
2014-03-10 16:55:11 +01:00
m_navigationToolbar - > refreshHistory ( ) ;
2011-09-11 19:15:06 +02:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : currentTabChanged ( )
2012-01-14 09:54:51 +01:00
{
2012-01-21 20:27:45 +01:00
TabbedWebView * view = weView ( ) ;
2012-01-14 09:54:51 +01:00
if ( ! view ) {
return ;
}
2014-04-01 18:47:19 +02:00
setWindowTitle ( tr ( " %1 - QupZilla " ) . arg ( view - > webTab ( ) - > title ( ) ) ) ;
2012-01-14 09:54:51 +01:00
m_ipLabel - > setText ( view - > getIp ( ) ) ;
view - > setFocus ( ) ;
updateLoadingActions ( ) ;
// Setting correct tab order (LocationBar -> WebSearchBar -> WebView)
2014-03-10 16:55:11 +01:00
setTabOrder ( locationBar ( ) , m_navigationToolbar - > webSearchBar ( ) ) ;
setTabOrder ( m_navigationToolbar - > webSearchBar ( ) , view ) ;
2012-01-14 09:54:51 +01:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : updateLoadingActions ( )
2012-01-14 09:54:51 +01:00
{
2012-01-21 20:27:45 +01:00
TabbedWebView * view = weView ( ) ;
2012-01-14 09:54:51 +01:00
if ( ! view ) {
return ;
}
bool isLoading = view - > isLoading ( ) ;
m_ipLabel - > setVisible ( ! isLoading ) ;
m_progressBar - > setVisible ( isLoading ) ;
2014-03-10 16:55:11 +01:00
action ( QSL ( " View/Stop " ) ) - > setEnabled ( isLoading ) ;
action ( QSL ( " View/Reload " ) ) - > setEnabled ( ! isLoading ) ;
2012-01-14 09:54:51 +01:00
if ( isLoading ) {
2012-06-27 18:29:00 +02:00
m_progressBar - > setValue ( view - > loadingProgress ( ) ) ;
2014-03-10 16:55:11 +01:00
m_navigationToolbar - > showStopButton ( ) ;
2012-01-14 09:54:51 +01:00
}
else {
2014-03-10 16:55:11 +01:00
m_navigationToolbar - > showReloadButton ( ) ;
2012-01-14 09:54:51 +01:00
}
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : addDeleteOnCloseWidget ( QWidget * widget )
2012-01-21 20:27:45 +01:00
{
if ( ! m_deleteOnCloseWidgets . contains ( widget ) ) {
m_deleteOnCloseWidgets . append ( widget ) ;
}
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : restoreWindowState ( const RestoreManager : : WindowData & d )
2012-03-13 17:51:37 +01:00
{
2012-09-06 11:39:42 +02:00
restoreState ( d . windowState ) ;
2012-08-21 20:28:38 +02:00
m_tabWidget - > restoreState ( d . tabsState , d . currentTab ) ;
2012-03-13 17:51:37 +01:00
}
2014-03-10 16:55:11 +01:00
void BrowserWindow : : createToolbarsMenu ( QMenu * menu )
{
2014-09-25 17:36:51 +02:00
removeActions ( menu - > actions ( ) ) ;
menu - > clear ( ) ;
2014-09-25 14:42:36 +02:00
QAction * action ;
2017-02-10 19:00:58 +01:00
# ifndef Q_OS_MACOS
2014-09-25 14:42:36 +02:00
action = menu - > addAction ( tr ( " &Menu Bar " ) , this , SLOT ( toggleShowMenubar ( ) ) ) ;
2014-03-10 16:55:11 +01:00
action - > setCheckable ( true ) ;
action - > setChecked ( menuBar ( ) - > isVisible ( ) ) ;
2014-09-25 14:42:36 +02:00
# endif
2014-03-10 16:55:11 +01:00
2014-03-13 12:31:08 +01:00
action = menu - > addAction ( tr ( " &Navigation Toolbar " ) , this , SLOT ( toggleShowNavigationToolbar ( ) ) ) ;
2014-03-10 16:55:11 +01:00
action - > setCheckable ( true ) ;
action - > setChecked ( m_navigationToolbar - > isVisible ( ) ) ;
2014-03-13 12:31:08 +01:00
action = menu - > addAction ( tr ( " &Bookmarks Toolbar " ) , this , SLOT ( toggleShowBookmarksToolbar ( ) ) ) ;
2014-03-10 16:55:11 +01:00
action - > setCheckable ( true ) ;
2016-08-23 08:57:11 +02:00
action - > setChecked ( Settings ( ) . value ( " Browser-View-Settings/showBookmarksToolbar " ) . toBool ( ) ) ;
2014-03-10 16:55:11 +01:00
menu - > addSeparator ( ) ;
action = menu - > addAction ( tr ( " &Tabs on Top " ) , this , SLOT ( toggleTabsOnTop ( bool ) ) ) ;
action - > setCheckable ( true ) ;
action - > setChecked ( qzSettings - > tabsOnTop ) ;
2014-09-25 17:36:51 +02:00
addActions ( menu - > actions ( ) ) ;
2014-03-10 16:55:11 +01:00
}
void BrowserWindow : : createSidebarsMenu ( QMenu * menu )
2011-03-02 16:57:41 +01:00
{
2014-03-10 16:55:11 +01:00
m_sideBarManager - > createMenu ( menu ) ;
}
void BrowserWindow : : createEncodingMenu ( QMenu * menu )
{
2015-10-01 18:02:36 +02:00
const QString activeCodecName = QWebEngineSettings : : defaultSettings ( ) - > defaultTextEncoding ( ) ;
2014-03-10 16:55:11 +01:00
2015-09-29 11:14:20 +02:00
QStringList isoCodecs ;
QStringList utfCodecs ;
QStringList windowsCodecs ;
QStringList isciiCodecs ;
QStringList ibmCodecs ;
QStringList otherCodecs ;
QStringList allCodecs ;
2014-03-10 16:55:11 +01:00
2014-07-22 10:02:08 +02:00
foreach ( const int mib , QTextCodec : : availableMibs ( ) ) {
const QString codecName = QString : : fromUtf8 ( QTextCodec : : codecForMib ( mib ) - > name ( ) ) ;
2014-03-10 16:55:11 +01:00
2015-09-29 11:14:20 +02:00
if ( ! allCodecs . contains ( codecName ) )
allCodecs . append ( codecName ) ;
else
continue ;
if ( codecName . startsWith ( QLatin1String ( " ISO " ) ) )
isoCodecs . append ( codecName ) ;
else if ( codecName . startsWith ( QLatin1String ( " UTF " ) ) )
utfCodecs . append ( codecName ) ;
else if ( codecName . startsWith ( QLatin1String ( " windows " ) ) )
windowsCodecs . append ( codecName ) ;
else if ( codecName . startsWith ( QLatin1String ( " Iscii " ) ) )
isciiCodecs . append ( codecName ) ;
else if ( codecName . startsWith ( QLatin1String ( " IBM " ) ) )
ibmCodecs . append ( codecName ) ;
else if ( codecName = = QLatin1String ( " System " ) )
2014-07-22 10:02:08 +02:00
menu - > addAction ( createEncodingAction ( codecName , activeCodecName , menu ) ) ;
2015-09-29 11:14:20 +02:00
else
otherCodecs . append ( codecName ) ;
2014-03-10 16:55:11 +01:00
}
2015-09-29 11:14:20 +02:00
if ( ! menu - > isEmpty ( ) )
2014-07-22 10:02:08 +02:00
menu - > addSeparator ( ) ;
2015-09-29 11:14:20 +02:00
2014-07-22 10:02:08 +02:00
createEncodingSubMenu ( " ISO " , isoCodecs , menu ) ;
createEncodingSubMenu ( " UTF " , utfCodecs , menu ) ;
createEncodingSubMenu ( " Windows " , windowsCodecs , menu ) ;
createEncodingSubMenu ( " Iscii " , isciiCodecs , menu ) ;
2015-09-29 11:14:20 +02:00
createEncodingSubMenu ( " IBM " , ibmCodecs , menu ) ;
2014-07-22 10:02:08 +02:00
createEncodingSubMenu ( tr ( " Other " ) , otherCodecs , menu ) ;
2011-03-02 16:57:41 +01:00
}
2014-09-25 17:36:51 +02:00
void BrowserWindow : : removeActions ( const QList < QAction * > & actions )
{
foreach ( QAction * action , actions ) {
removeAction ( action ) ;
}
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : addTab ( )
2012-01-21 23:19:38 +01:00
{
2013-01-25 23:49:46 +01:00
m_tabWidget - > addView ( QUrl ( ) , Qz : : NT_SelectedNewEmptyTab , true ) ;
2016-08-15 13:54:54 +02:00
m_tabWidget - > setCurrentTabFresh ( true ) ;
if ( isFullScreen ( ) )
showNavigationWithFullScreen ( ) ;
2012-01-21 23:19:38 +01:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : webSearch ( )
2011-09-11 19:15:06 +02:00
{
2014-03-10 16:55:11 +01:00
m_navigationToolbar - > webSearchBar ( ) - > setFocus ( ) ;
m_navigationToolbar - > webSearchBar ( ) - > selectAll ( ) ;
2011-09-11 19:15:06 +02:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : searchOnPage ( )
2011-03-02 16:57:41 +01:00
{
2017-01-21 17:42:14 +01:00
if ( weView ( ) & & weView ( ) - > webTab ( ) ) {
weView ( ) - > webTab ( ) - > showSearchToolBar ( ) ;
2011-03-02 16:57:41 +01:00
}
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : openFile ( )
2011-03-02 16:57:41 +01:00
{
2013-12-30 13:43:48 +01:00
const QString fileTypes = QString ( " %1(*.html *.htm *.shtml *.shtm *.xhtml);; "
" %2(*.png *.jpg *.jpeg *.bmp *.gif *.svg *.tiff);; "
" %3(*.txt);; "
" %4(*.*) " ) . arg ( tr ( " HTML files " ) , tr ( " Image files " ) , tr ( " Text files " ) , tr ( " All files " ) ) ;
2012-03-04 18:30:34 +01:00
2013-12-30 13:43:48 +01:00
const QString filePath = QzTools : : getOpenFileName ( " MainWindow-openFile " , this , tr ( " Open file... " ) , QDir : : homePath ( ) , fileTypes ) ;
2012-03-04 18:30:34 +01:00
2011-11-06 17:01:23 +01:00
if ( ! filePath . isEmpty ( ) ) {
2011-12-17 14:30:54 +01:00
loadAddress ( QUrl : : fromLocalFile ( filePath ) ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : openLocation ( )
2011-12-16 19:07:36 +01:00
{
2014-12-24 21:40:30 +01:00
if ( isFullScreen ( ) ) {
showNavigationWithFullScreen ( ) ;
}
2011-12-16 19:07:36 +01:00
locationBar ( ) - > setFocus ( ) ;
locationBar ( ) - > selectAll ( ) ;
}
2014-02-19 22:07:21 +01:00
bool BrowserWindow : : fullScreenNavigationVisible ( ) const
2011-04-22 07:45:15 +02:00
{
2013-02-09 15:44:17 +01:00
return m_navigationContainer - > isVisible ( ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : showNavigationWithFullScreen ( )
2013-02-09 15:44:17 +01:00
{
2015-10-05 17:39:52 +02:00
if ( m_isHtmlFullScreen )
return ;
2013-02-09 15:44:17 +01:00
if ( m_hideNavigationTimer - > isActive ( ) ) {
m_hideNavigationTimer - > stop ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-10-24 17:46:45 +02:00
2013-02-09 15:44:17 +01:00
m_navigationContainer - > show ( ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : hideNavigationWithFullScreen ( )
2013-02-09 15:44:17 +01:00
{
2016-08-15 13:54:54 +02:00
if ( m_tabWidget - > isCurrentTabFresh ( ) )
return ;
2013-02-09 15:44:17 +01:00
if ( ! m_hideNavigationTimer - > isActive ( ) ) {
m_hideNavigationTimer - > start ( ) ;
2011-11-06 17:01:23 +01:00
}
2013-02-09 15:44:17 +01:00
}
2011-10-24 17:46:45 +02:00
2014-02-19 22:07:21 +01:00
void BrowserWindow : : hideNavigationSlot ( )
2013-02-09 15:44:17 +01:00
{
TabbedWebView * view = weView ( ) ;
2013-02-24 10:57:58 +01:00
bool mouseInView = view & & view - > underMouse ( ) ;
2011-10-24 17:46:45 +02:00
2013-02-09 15:44:17 +01:00
if ( isFullScreen ( ) & & mouseInView ) {
m_navigationContainer - > hide ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-04-22 07:45:15 +02:00
}
2014-02-19 22:07:21 +01:00
bool BrowserWindow : : event ( QEvent * event )
2011-03-02 16:57:41 +01:00
{
2013-02-17 11:05:35 +01:00
switch ( event - > type ( ) ) {
case QEvent : : WindowStateChange : {
QWindowStateChangeEvent * ev = static_cast < QWindowStateChangeEvent * > ( event ) ;
2011-10-24 17:46:45 +02:00
2013-02-17 11:05:35 +01:00
if ( ! ( ev - > oldState ( ) & Qt : : WindowFullScreen ) & & windowState ( ) & Qt : : WindowFullScreen ) {
// Enter fullscreen
m_windowStates = ev - > oldState ( ) ;
2011-10-24 17:46:45 +02:00
2013-02-17 11:05:35 +01:00
m_statusBarVisible = statusBar ( ) - > isVisible ( ) ;
2017-02-10 19:00:58 +01:00
# ifndef Q_OS_MACOS
2014-09-25 14:42:36 +02:00
m_menuBarVisible = menuBar ( ) - > isVisible ( ) ;
2013-02-17 11:05:35 +01:00
menuBar ( ) - > hide ( ) ;
2014-09-25 14:42:36 +02:00
# endif
2013-02-17 11:05:35 +01:00
statusBar ( ) - > hide ( ) ;
2014-03-30 16:38:34 +02:00
2013-02-17 11:05:35 +01:00
m_navigationContainer - > hide ( ) ;
2017-01-20 09:37:00 +01:00
m_navigationToolbar - > buttonExitFullscreen ( ) - > show ( ) ;
2013-02-17 11:05:35 +01:00
}
else if ( ev - > oldState ( ) & Qt : : WindowFullScreen & & ! ( windowState ( ) & Qt : : WindowFullScreen ) ) {
// Leave fullscreen
statusBar ( ) - > setVisible ( m_statusBarVisible ) ;
2017-02-10 19:00:58 +01:00
# ifndef Q_OS_MACOS
2014-09-25 14:42:36 +02:00
menuBar ( ) - > setVisible ( m_menuBarVisible ) ;
# endif
2014-03-30 16:38:34 +02:00
2013-02-17 11:05:35 +01:00
m_navigationContainer - > show ( ) ;
2014-03-10 16:55:11 +01:00
m_navigationToolbar - > setSuperMenuVisible ( ! m_menuBarVisible ) ;
2017-01-20 09:37:00 +01:00
m_navigationToolbar - > buttonExitFullscreen ( ) - > hide ( ) ;
2015-10-05 17:39:52 +02:00
m_isHtmlFullScreen = false ;
2017-01-20 09:37:00 +01:00
setWindowState ( m_windowStates ) ;
2013-02-17 11:05:35 +01:00
}
2014-03-31 10:01:04 +02:00
if ( m_hideNavigationTimer ) {
m_hideNavigationTimer - > stop ( ) ;
}
2014-03-30 16:38:34 +02:00
break ;
2011-03-02 16:57:41 +01:00
}
2011-10-24 17:46:45 +02:00
2013-02-17 11:05:35 +01:00
default :
break ;
}
2011-10-24 17:46:45 +02:00
2013-02-17 11:05:35 +01:00
return QMainWindow : : event ( event ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : resizeEvent ( QResizeEvent * event )
2011-12-29 15:21:26 +01:00
{
m_bookmarksToolbar - > setMaximumWidth ( width ( ) ) ;
QMainWindow : : resizeEvent ( event ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : keyPressEvent ( QKeyEvent * event )
2011-11-06 12:05:16 +01:00
{
2014-02-26 19:55:49 +01:00
if ( mApp - > plugins ( ) - > processKeyPress ( Qz : : ON_BrowserWindow , this , event ) ) {
2012-03-05 13:16:34 +01:00
return ;
}
2012-02-05 17:13:08 +01:00
int number = - 1 ;
2013-02-17 11:05:35 +01:00
TabbedWebView * view = weView ( ) ;
2012-02-05 17:13:08 +01:00
2011-11-06 12:05:16 +01:00
switch ( event - > key ( ) ) {
case Qt : : Key_Back :
2013-02-17 11:05:35 +01:00
if ( view ) {
2014-03-10 16:55:11 +01:00
view - > back ( ) ;
2013-02-17 11:05:35 +01:00
event - > accept ( ) ;
}
2011-11-06 12:05:16 +01:00
break ;
2012-02-05 16:00:23 +01:00
2011-11-06 12:05:16 +01:00
case Qt : : Key_Forward :
2013-02-17 11:05:35 +01:00
if ( view ) {
2014-03-10 16:55:11 +01:00
view - > forward ( ) ;
2013-02-17 11:05:35 +01:00
event - > accept ( ) ;
}
2011-11-06 12:05:16 +01:00
break ;
2012-02-05 16:00:23 +01:00
2011-11-06 12:05:16 +01:00
case Qt : : Key_Stop :
2013-02-17 11:05:35 +01:00
if ( view ) {
2014-03-10 16:55:11 +01:00
view - > stop ( ) ;
2013-02-17 11:05:35 +01:00
event - > accept ( ) ;
}
2011-11-06 12:05:16 +01:00
break ;
2012-02-05 16:00:23 +01:00
2011-11-06 12:05:16 +01:00
case Qt : : Key_Refresh :
2013-02-17 11:05:35 +01:00
if ( view ) {
2014-03-10 16:55:11 +01:00
view - > reload ( ) ;
event - > accept ( ) ;
}
break ;
2011-11-06 12:05:16 +01:00
case Qt : : Key_HomePage :
goHome ( ) ;
event - > accept ( ) ;
break ;
2012-02-05 16:00:23 +01:00
2011-11-06 12:05:16 +01:00
case Qt : : Key_Favorites :
2014-03-10 16:55:11 +01:00
mApp - > browsingLibrary ( ) - > showBookmarks ( this ) ;
2011-11-06 12:05:16 +01:00
event - > accept ( ) ;
break ;
2012-02-05 16:00:23 +01:00
2011-11-06 12:05:16 +01:00
case Qt : : Key_Search :
searchOnPage ( ) ;
event - > accept ( ) ;
break ;
2012-02-05 16:00:23 +01:00
2011-12-16 19:07:36 +01:00
case Qt : : Key_F6 :
2011-11-06 12:05:16 +01:00
case Qt : : Key_OpenUrl :
openLocation ( ) ;
event - > accept ( ) ;
break ;
2012-02-05 16:00:23 +01:00
2011-11-06 12:05:16 +01:00
case Qt : : Key_History :
showHistoryManager ( ) ;
event - > accept ( ) ;
break ;
2012-02-05 16:00:23 +01:00
2011-11-06 12:05:16 +01:00
case Qt : : Key_AddFavorite :
bookmarkPage ( ) ;
event - > accept ( ) ;
break ;
2012-02-05 16:00:23 +01:00
2011-11-06 12:05:16 +01:00
case Qt : : Key_News :
2014-03-10 16:55:11 +01:00
action ( QSL ( " Tools/RssReader " ) ) - > trigger ( ) ;
2011-11-06 12:05:16 +01:00
event - > accept ( ) ;
break ;
2012-02-05 16:00:23 +01:00
2011-11-06 12:05:16 +01:00
case Qt : : Key_Tools :
2014-03-10 16:55:11 +01:00
action ( QSL ( " Standard/Preferences " ) ) - > trigger ( ) ;
2011-11-06 12:05:16 +01:00
event - > accept ( ) ;
break ;
2012-02-05 16:00:23 +01:00
2011-11-07 19:56:53 +01:00
case Qt : : Key_Tab :
if ( event - > modifiers ( ) = = Qt : : ControlModifier ) {
2012-03-22 17:19:10 +01:00
m_tabWidget - > nextTab ( ) ;
event - > accept ( ) ;
2011-11-07 19:56:53 +01:00
}
break ;
2012-02-05 16:00:23 +01:00
2011-11-07 19:56:53 +01:00
case Qt : : Key_Backtab :
if ( event - > modifiers ( ) = = ( Qt : : ControlModifier + Qt : : ShiftModifier ) ) {
2012-03-22 17:19:10 +01:00
m_tabWidget - > previousTab ( ) ;
event - > accept ( ) ;
}
break ;
case Qt : : Key_PageDown :
if ( event - > modifiers ( ) = = Qt : : ControlModifier ) {
m_tabWidget - > nextTab ( ) ;
event - > accept ( ) ;
}
break ;
case Qt : : Key_PageUp :
if ( event - > modifiers ( ) = = Qt : : ControlModifier ) {
m_tabWidget - > previousTab ( ) ;
event - > accept ( ) ;
2011-11-07 19:56:53 +01:00
}
break ;
2011-11-06 12:05:16 +01:00
2012-07-14 11:46:53 +02:00
case Qt : : Key_Equal :
2013-02-17 11:05:35 +01:00
if ( view & & event - > modifiers ( ) = = Qt : : ControlModifier ) {
2014-03-10 16:55:11 +01:00
view - > zoomIn ( ) ;
2012-07-14 11:46:53 +02:00
event - > accept ( ) ;
}
break ;
2013-01-26 21:58:09 +01:00
case Qt : : Key_I :
if ( event - > modifiers ( ) = = Qt : : ControlModifier ) {
2014-03-10 16:55:11 +01:00
action ( QSL ( " Tools/SiteInfo " ) ) - > trigger ( ) ;
2013-01-26 21:58:09 +01:00
event - > accept ( ) ;
}
break ;
case Qt : : Key_U :
if ( event - > modifiers ( ) = = Qt : : ControlModifier ) {
2014-03-10 16:55:11 +01:00
action ( QSL ( " View/PageSource " ) ) - > trigger ( ) ;
event - > accept ( ) ;
}
break ;
2014-03-31 17:58:56 +02:00
case Qt : : Key_F :
if ( event - > modifiers ( ) = = Qt : : ControlModifier ) {
action ( QSL ( " Edit/Find " ) ) - > trigger ( ) ;
event - > accept ( ) ;
}
break ;
2014-04-10 01:19:45 +02:00
case Qt : : Key_Slash :
if ( m_useSingleKeyShortcuts ) {
action ( QSL ( " Edit/Find " ) ) - > trigger ( ) ;
event - > accept ( ) ;
}
break ;
2012-02-05 16:00:23 +01:00
case Qt : : Key_1 :
2012-02-05 17:13:08 +01:00
number = 1 ;
break ;
2012-02-05 16:00:23 +01:00
case Qt : : Key_2 :
2012-02-05 17:13:08 +01:00
number = 2 ;
break ;
2012-02-05 16:00:23 +01:00
case Qt : : Key_3 :
2012-02-05 17:13:08 +01:00
number = 3 ;
break ;
2012-02-05 16:00:23 +01:00
case Qt : : Key_4 :
2012-02-05 17:13:08 +01:00
number = 4 ;
break ;
2012-02-05 16:00:23 +01:00
case Qt : : Key_5 :
2012-02-05 17:13:08 +01:00
number = 5 ;
break ;
2012-02-05 16:00:23 +01:00
case Qt : : Key_6 :
2012-02-05 17:13:08 +01:00
number = 6 ;
break ;
2012-02-05 16:00:23 +01:00
case Qt : : Key_7 :
2012-02-05 17:13:08 +01:00
number = 7 ;
break ;
2012-02-05 16:00:23 +01:00
case Qt : : Key_8 :
2012-02-05 17:13:08 +01:00
number = 8 ;
2012-02-05 16:00:23 +01:00
break ;
case Qt : : Key_9 :
2012-02-05 17:13:08 +01:00
number = 9 ;
break ;
2012-02-05 16:00:23 +01:00
2011-11-06 12:05:16 +01:00
default :
2012-02-05 17:13:08 +01:00
break ;
2011-11-06 12:05:16 +01:00
}
2012-02-05 16:00:23 +01:00
2012-02-05 17:13:08 +01:00
if ( number ! = - 1 ) {
2012-11-28 11:27:30 +01:00
if ( event - > modifiers ( ) & Qt : : AltModifier & & m_useTabNumberShortcuts ) {
2012-02-05 17:13:08 +01:00
if ( number = = 9 ) {
number = m_tabWidget - > count ( ) ;
}
m_tabWidget - > setCurrentIndex ( number - 1 ) ;
return ;
}
2012-11-28 11:27:30 +01:00
if ( event - > modifiers ( ) & Qt : : ControlModifier & & m_useSpeedDialNumberShortcuts ) {
2013-12-30 13:43:48 +01:00
const QUrl url = mApp - > plugins ( ) - > speedDial ( ) - > urlForShortcut ( number - 1 ) ;
2012-02-05 17:13:08 +01:00
if ( url . isValid ( ) ) {
loadAddress ( url ) ;
return ;
}
}
2014-04-05 03:00:06 +02:00
if ( event - > modifiers ( ) = = Qt : : NoModifier & & m_useSingleKeyShortcuts ) {
if ( number = = 1 )
m_tabWidget - > previousTab ( ) ;
if ( number = = 2 )
m_tabWidget - > nextTab ( ) ;
}
2012-02-05 17:13:08 +01:00
}
2012-02-05 16:00:23 +01:00
QMainWindow : : keyPressEvent ( event ) ;
2011-11-06 12:05:16 +01:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : keyReleaseEvent ( QKeyEvent * event )
2012-03-05 13:16:34 +01:00
{
2014-02-26 19:55:49 +01:00
if ( mApp - > plugins ( ) - > processKeyRelease ( Qz : : ON_BrowserWindow , this , event ) ) {
2012-03-05 13:16:34 +01:00
return ;
}
QMainWindow : : keyReleaseEvent ( event ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : closeEvent ( QCloseEvent * event )
2011-03-02 16:57:41 +01:00
{
2011-11-06 17:01:23 +01:00
if ( mApp - > isClosing ( ) ) {
2011-03-02 16:57:41 +01:00
return ;
2011-11-06 17:01:23 +01:00
}
2011-03-29 19:55:21 +02:00
2012-08-14 12:35:24 +02:00
Settings settings ;
bool askOnClose = settings . value ( " Browser-Tabs-Settings/AskOnClosing " , true ) . toBool ( ) ;
2015-09-28 14:51:38 +02:00
if ( mApp - > afterLaunch ( ) = = MainApplication : : RestoreSession & & mApp - > windowCount ( ) = = 1 ) {
2012-08-14 12:35:24 +02:00
askOnClose = false ;
}
2012-09-08 19:28:47 +02:00
if ( askOnClose & & m_tabWidget - > normalTabsCount ( ) > 1 ) {
2012-08-14 12:35:24 +02:00
CheckBoxDialog dialog ( QDialogButtonBox : : Yes | QDialogButtonBox : : No , this ) ;
2016-02-15 09:58:14 +01:00
dialog . setText ( tr ( " There are still %n open tabs and your session won't be stored. \n Are you sure you want to close this window? " , " " , m_tabWidget - > count ( ) ) ) ;
2012-08-14 12:35:24 +02:00
dialog . setCheckBoxText ( tr ( " Don't ask again " ) ) ;
dialog . setWindowTitle ( tr ( " There are still open tabs " ) ) ;
2014-03-07 18:03:42 +01:00
dialog . setIcon ( IconProvider : : standardIcon ( QStyle : : SP_MessageBoxWarning ) ) ;
2012-08-14 12:35:24 +02:00
if ( dialog . exec ( ) ! = QDialog : : Accepted ) {
event - > ignore ( ) ;
return ;
}
if ( dialog . isChecked ( ) ) {
settings . setValue ( " Browser-Tabs-Settings/AskOnClosing " , false ) ;
}
}
2016-04-05 09:07:40 +02:00
saveSettings ( ) ;
2012-01-10 19:10:16 +01:00
2017-02-10 19:00:58 +01:00
# ifndef Q_OS_MACOS
2016-04-05 09:07:40 +02:00
if ( mApp - > windowCount ( ) = = 1 )
mApp - > quitApplication ( ) ;
# endif
2011-03-02 16:57:41 +01:00
event - > accept ( ) ;
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : closeWindow ( )
2012-02-01 17:01:08 +01:00
{
2017-02-10 19:00:58 +01:00
# ifdef Q_OS_MACOS
2014-03-13 15:58:39 +01:00
close ( ) ;
return ;
2014-03-10 16:55:11 +01:00
# endif
2014-03-13 15:58:39 +01:00
if ( mApp - > windowCount ( ) > 1 ) {
2012-02-01 17:01:08 +01:00
close ( ) ;
}
}
2016-04-05 09:07:40 +02:00
void BrowserWindow : : saveSettings ( )
2011-03-02 16:57:41 +01:00
{
2012-01-18 18:36:10 +01:00
if ( m_sideBar ) {
2011-10-17 09:59:09 +02:00
saveSideBarWidth ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-10-17 09:59:09 +02:00
2014-03-10 00:47:07 +01:00
if ( ! mApp - > isPrivate ( ) ) {
2012-07-04 19:13:44 +02:00
Settings settings ;
settings . beginGroup ( " Browser-View-Settings " ) ;
settings . setValue ( " WindowMaximised " , windowState ( ) . testFlag ( Qt : : WindowMaximized ) ) ;
2014-03-10 16:55:11 +01:00
settings . setValue ( " LocationBarWidth " , m_navigationToolbar - > splitter ( ) - > sizes ( ) . at ( 0 ) ) ;
settings . setValue ( " WebSearchBarWidth " , m_navigationToolbar - > splitter ( ) - > sizes ( ) . at ( 1 ) ) ;
2012-07-04 19:13:44 +02:00
settings . setValue ( " SideBarWidth " , m_sideBarWidth ) ;
settings . setValue ( " WebViewWidth " , m_webViewWidth ) ;
2016-04-05 09:07:40 +02:00
if ( ! isFullScreen ( ) )
2013-02-09 15:47:06 +01:00
settings . setValue ( " WindowGeometry " , saveGeometry ( ) ) ;
2012-07-04 19:13:44 +02:00
settings . endGroup ( ) ;
2011-03-02 16:57:41 +01:00
}
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : closeTab ( )
2013-02-07 15:01:25 +01:00
{
2014-02-12 11:16:57 +01:00
// Don't close pinned tabs with keyboard shortcuts (Ctrl+W, Ctrl+F4)
if ( weView ( ) & & ! weView ( ) - > webTab ( ) - > isPinned ( ) ) {
2015-10-12 12:04:48 +02:00
m_tabWidget - > requestCloseTab ( ) ;
2014-02-12 11:16:57 +01:00
}
2013-02-07 15:01:25 +01:00
}
2014-02-19 22:07:21 +01:00
QByteArray BrowserWindow : : saveState ( int version ) const
2012-09-06 11:39:42 +02:00
{
2014-03-03 14:47:47 +01:00
# ifdef QZ_WS_X11
2012-09-06 11:39:42 +02:00
QByteArray data ;
QDataStream stream ( & data , QIODevice : : WriteOnly ) ;
stream < < QMainWindow : : saveState ( version ) ;
stream < < getCurrentVirtualDesktop ( ) ;
return data ;
# else
return QMainWindow : : saveState ( version ) ;
# endif
}
2014-02-19 22:07:21 +01:00
bool BrowserWindow : : restoreState ( const QByteArray & state , int version )
2012-09-06 11:39:42 +02:00
{
2014-03-03 14:47:47 +01:00
# ifdef QZ_WS_X11
2012-09-06 11:39:42 +02:00
QByteArray windowState ;
int desktopId = - 1 ;
QDataStream stream ( state ) ;
stream > > windowState ;
stream > > desktopId ;
moveToVirtualDesktop ( desktopId ) ;
return QMainWindow : : restoreState ( windowState , version ) ;
# else
2012-09-07 20:31:55 +02:00
return QMainWindow : : restoreState ( state , version ) ;
2012-09-06 11:39:42 +02:00
# endif
}
2014-03-03 14:47:47 +01:00
# ifdef QZ_WS_X11
2014-02-19 22:07:21 +01:00
int BrowserWindow : : getCurrentVirtualDesktop ( ) const
2012-09-06 11:39:42 +02:00
{
2016-06-14 11:53:20 +02:00
if ( QGuiApplication : : platformName ( ) ! = QL1S ( " xcb " ) )
2015-09-25 22:04:05 +02:00
return 0 ;
2012-09-06 11:39:42 +02:00
2015-09-25 22:04:05 +02:00
xcb_intern_atom_cookie_t intern_atom ;
xcb_intern_atom_reply_t * atom_reply = 0 ;
xcb_atom_t atom ;
xcb_get_property_cookie_t cookie ;
xcb_get_property_reply_t * reply = 0 ;
uint32_t value ;
2012-09-06 11:39:42 +02:00
2015-09-25 22:04:05 +02:00
intern_atom = xcb_intern_atom ( QX11Info : : connection ( ) , false , qstrlen ( " _NET_WM_DESKTOP " ) , " _NET_WM_DESKTOP " ) ;
atom_reply = xcb_intern_atom_reply ( QX11Info : : connection ( ) , intern_atom , 0 ) ;
2012-09-06 11:39:42 +02:00
2015-09-25 22:04:05 +02:00
if ( ! atom_reply )
goto error ;
atom = atom_reply - > atom ;
2012-09-06 11:39:42 +02:00
2015-09-25 22:04:05 +02:00
cookie = xcb_get_property ( QX11Info : : connection ( ) , false , winId ( ) , atom , XCB_ATOM_CARDINAL , 0 , 1 ) ;
reply = xcb_get_property_reply ( QX11Info : : connection ( ) , cookie , 0 ) ;
2012-09-06 11:39:42 +02:00
2015-09-25 22:04:05 +02:00
if ( ! reply | | reply - > type ! = XCB_ATOM_CARDINAL | | reply - > value_len ! = 1 | | reply - > format ! = sizeof ( uint32_t ) * 8 )
goto error ;
value = * reinterpret_cast < uint32_t * > ( xcb_get_property_value ( reply ) ) ;
free ( reply ) ;
free ( atom_reply ) ;
return value ;
error :
free ( reply ) ;
free ( atom_reply ) ;
return 0 ;
2012-09-06 11:39:42 +02:00
}
2014-02-19 22:07:21 +01:00
void BrowserWindow : : moveToVirtualDesktop ( int desktopId )
2012-09-06 11:39:42 +02:00
{
2016-06-14 11:53:20 +02:00
if ( QGuiApplication : : platformName ( ) ! = QL1S ( " xcb " ) )
2015-09-25 22:04:05 +02:00
return ;
2012-09-06 11:39:42 +02:00
// Don't move when window is already visible or it is first app window
2015-09-25 22:04:05 +02:00
if ( desktopId < 0 | | isVisible ( ) | | m_windowType = = Qz : : BW_FirstAppWindow )
2012-09-06 11:39:42 +02:00
return ;
2015-09-25 22:04:05 +02:00
xcb_intern_atom_cookie_t intern_atom ;
xcb_intern_atom_reply_t * atom_reply = 0 ;
xcb_atom_t atom ;
2012-09-06 11:39:42 +02:00
2015-09-25 22:04:05 +02:00
intern_atom = xcb_intern_atom ( QX11Info : : connection ( ) , false , qstrlen ( " _NET_WM_DESKTOP " ) , " _NET_WM_DESKTOP " ) ;
atom_reply = xcb_intern_atom_reply ( QX11Info : : connection ( ) , intern_atom , 0 ) ;
if ( ! atom_reply )
goto error ;
atom = atom_reply - > atom ;
xcb_change_property ( QX11Info : : connection ( ) , XCB_PROP_MODE_REPLACE , winId ( ) , atom ,
XCB_ATOM_CARDINAL , 32 , 1 , ( const void * ) & desktopId ) ;
2012-09-06 11:39:42 +02:00
2015-09-25 22:04:05 +02:00
error :
free ( atom_reply ) ;
2012-09-06 11:39:42 +02:00
}
# endif