1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Merge pull request #749 from srazi/mac_global_menu

Added support for Mac global menu
This commit is contained in:
David Rosca 2013-02-09 03:38:16 -08:00
commit 484c76eae2
12 changed files with 1043 additions and 161 deletions

3
.gitignore vendored
View File

@ -33,3 +33,6 @@ tests/modeltest
bin/autotests
.clang_complete
.tx/
bin/qupzilla.app
.DS_Store
*.dylib

View File

@ -59,6 +59,7 @@
#endif
#ifdef Q_OS_MAC
#include "macmenureceiver.h"
#include <QFileOpenEvent>
#endif
#include <QNetworkDiskCache>
@ -110,6 +111,9 @@ MainApplication::MainApplication(int &argc, char** argv)
#ifdef Q_OS_WIN
, m_registerQAppAssociation(0)
#endif
#ifdef Q_OS_MAC
, m_macMenuReceiver(0)
#endif
{
#if defined(QZ_WS_X11) && !defined(NO_SYSTEM_DATAPATH)
DATADIR = USE_DATADIR;
@ -608,7 +612,7 @@ void MainApplication::addNewTab(const QUrl &url)
QupZilla* MainApplication::makeNewWindow(Qz::BrowserWindow type, const QUrl &startUrl)
{
if (m_mainWindows.count() == 0) {
if (m_mainWindows.count() == 0 && type != Qz::BW_MacFirstWindow) {
type = Qz::BW_FirstAppWindow;
}
@ -619,6 +623,14 @@ QupZilla* MainApplication::makeNewWindow(Qz::BrowserWindow type, const QUrl &sta
}
#ifdef Q_OS_MAC
MacMenuReceiver* MainApplication::macMenuReceiver()
{
if (!m_macMenuReceiver) {
m_macMenuReceiver = new MacMenuReceiver(this);
}
return m_macMenuReceiver;
}
bool MainApplication::event(QEvent* e)
{
switch (e->type()) {

View File

@ -52,6 +52,9 @@ class ProxyStyle;
class RegisterQAppAssociation;
class HTML5PermissionsManager;
class Speller;
#ifdef Q_OS_MAC
class MacMenuReceiver;
#endif
class QT_QUPZILLA_EXPORT MainApplication : public QtSingleApplication
{
@ -123,6 +126,7 @@ public:
#endif
#ifdef Q_OS_MAC
MacMenuReceiver* macMenuReceiver();
bool event(QEvent* e);
#endif
@ -178,7 +182,6 @@ private:
#endif
DatabaseWriter* m_dbWriter;
UserAgentManager* m_uaManager;
QList<QPointer<QupZilla> > m_mainWindows;
QString m_activeProfil;
@ -197,6 +200,9 @@ private:
#ifdef Q_OS_WIN
RegisterQAppAssociation* m_registerQAppAssociation;
#endif
#ifdef Q_OS_MAC
MacMenuReceiver* m_macMenuReceiver;
#endif
};
#endif // MAINAPPLICATION_H

View File

@ -90,6 +90,13 @@
#include <X11/Xatom.h>
#endif
#ifndef Q_OS_MAC
#define MENU_RECEIVER this
#else
#include "macmenureceiver.h"
#define MENU_RECEIVER mApp->macMenuReceiver()
#endif
const QString QupZilla::VERSION = "1.3.5";
const QString QupZilla::BUILDTIME = __DATE__" "__TIME__;
const QString QupZilla::AUTHOR = "David Rosca";
@ -107,9 +114,6 @@ QupZilla::QupZilla(Qz::BrowserWindow type, QUrl startUrl)
, m_startingUrl(startUrl)
, m_startBehaviour(type)
, m_menuBookmarksAction(0)
#ifdef Q_OS_MAC
, m_macMenuBar(new QMenuBar())
#endif
, m_actionPrivateBrowsing(0)
, m_sideBarManager(new SideBarManager(this))
, m_statusBarMessage(new StatusBarMessage(this))
@ -182,6 +186,7 @@ void QupZilla::postLaunch()
}
break;
case Qz::BW_MacFirstWindow:
case Qz::BW_NewWindow:
addTab = true;
break;
@ -219,6 +224,16 @@ void QupZilla::postLaunch()
aboutToHideEditMenu();
#ifdef Q_OS_MAC
// fill menus even if user don't call them
if (m_startBehaviour == Qz::BW_FirstAppWindow) {
aboutToShowBookmarksMenu();
aboutToShowHistoryMostMenu();
aboutToShowHistoryRecentMenu();
aboutToShowEncodingMenu();
}
#endif
mApp->plugins()->emitMainWindowCreated(this);
emit startingCompleted();
@ -300,15 +315,26 @@ void QupZilla::setupUi()
void QupZilla::setupMenu()
{
#ifdef Q_OS_MAC
if (menuBar()) {
setupMacMenu();
setupOtherActions();
return;
}
else {
mApp->macMenuReceiver()->setMenuBar(new QMenuBar(0));
}
#endif
// Standard actions - needed on Mac to be placed correctly in "application" menu
m_actionAbout = new QAction(QIcon(":/icons/qupzilla.png"), tr("&About QupZilla"), 0);
m_actionAbout->setMenuRole(QAction::AboutRole);
connect(m_actionAbout, SIGNAL(triggered()), this, SLOT(aboutQupZilla()));
connect(m_actionAbout, SIGNAL(triggered()), MENU_RECEIVER, SLOT(aboutQupZilla()));
m_actionPreferences = new QAction(QIcon(":/icons/faenza/settings.png"), tr("Pr&eferences"), 0);
m_actionPreferences->setMenuRole(QAction::PreferencesRole);
m_actionPreferences->setShortcut(QKeySequence(QKeySequence::Preferences));
connect(m_actionPreferences, SIGNAL(triggered()), this, SLOT(showPreferences()));
connect(m_actionPreferences, SIGNAL(triggered()), MENU_RECEIVER, SLOT(showPreferences()));
m_actionQuit = new QAction(QIcon::fromTheme("application-exit"), tr("Quit"), 0);
m_actionQuit->setMenuRole(QAction::QuitRole);
@ -320,92 +346,93 @@ void QupZilla::setupMenu()
}
#endif
m_actionQuit->setShortcut(quitSequence);
connect(m_actionQuit, SIGNAL(triggered()), this, SLOT(quitApp()));
connect(m_actionQuit, SIGNAL(triggered()), MENU_RECEIVER, SLOT(quitApp()));
/*************
* File Menu *
*************/
m_menuFile = new QMenu(tr("&File"));
m_menuFile->addAction(QIcon::fromTheme("window-new"), tr("&New Window"), this, SLOT(newWindow()))->setShortcut(QKeySequence("Ctrl+N"));
m_menuFile->addAction(QIcon(":/icons/menu/new-tab.png"), tr("New Tab"), this, SLOT(addTab()))->setShortcut(QKeySequence("Ctrl+T"));
m_menuFile->addAction(QIcon::fromTheme("document-open-remote"), tr("Open Location"), this, SLOT(openLocation()))->setShortcut(QKeySequence("Ctrl+L"));
m_menuFile->addAction(QIcon::fromTheme("document-open"), tr("Open &File"), this, SLOT(openFile()))->setShortcut(QKeySequence("Ctrl+O"));
m_menuFile->addAction(tr("Close Tab"), m_tabWidget, SLOT(closeTab()))->setShortcut(QKeySequence("Ctrl+W"));
m_actionCloseWindow = m_menuFile->addAction(QIcon::fromTheme("window-close"), tr("Close Window"), this, SLOT(closeWindow()));
m_menuFile->addAction(QIcon::fromTheme("window-new"), tr("&New Window"), MENU_RECEIVER, SLOT(newWindow()))->setShortcut(QKeySequence("Ctrl+N"));
m_menuFile->addAction(QIcon(":/icons/menu/new-tab.png"), tr("New Tab"), MENU_RECEIVER, SLOT(addTab()))->setShortcut(QKeySequence("Ctrl+T"));
m_menuFile->addAction(QIcon::fromTheme("document-open-remote"), tr("Open Location"), MENU_RECEIVER, SLOT(openLocation()))->setShortcut(QKeySequence("Ctrl+L"));
m_menuFile->addAction(QIcon::fromTheme("document-open"), tr("Open &File"), MENU_RECEIVER, SLOT(openFile()))->setShortcut(QKeySequence("Ctrl+O"));
m_menuFile->addAction(tr("Close Tab"), MENU_RECEIVER, SLOT(closeTab()))->setShortcut(QKeySequence("Ctrl+W"));
m_actionCloseWindow = m_menuFile->addAction(QIcon::fromTheme("window-close"), tr("Close Window"), MENU_RECEIVER, SLOT(closeWindow()));
m_actionCloseWindow->setShortcut(QKeySequence("Ctrl+Shift+W"));
m_menuFile->addSeparator();
m_menuFile->addAction(QIcon::fromTheme("document-save"), tr("&Save Page As..."), this, SLOT(savePage()))->setShortcut(QKeySequence("Ctrl+S"));
m_menuFile->addAction(tr("Save Page Screen"), this, SLOT(savePageScreen()));
m_menuFile->addAction(QIcon::fromTheme("mail-message-new"), tr("Send Link..."), this, SLOT(sendLink()));
m_menuFile->addAction(QIcon::fromTheme("document-print"), tr("&Print..."), this, SLOT(printPage()))->setShortcut(QKeySequence("Ctrl+P"));
m_menuFile->addAction(QIcon::fromTheme("document-save"), tr("&Save Page As..."), MENU_RECEIVER, SLOT(savePage()))->setShortcut(QKeySequence("Ctrl+S"));
m_menuFile->addAction(tr("Save Page Screen"), MENU_RECEIVER, SLOT(savePageScreen()));
m_menuFile->addAction(QIcon::fromTheme("mail-message-new"), tr("Send Link..."), MENU_RECEIVER, SLOT(sendLink()));
m_menuFile->addAction(QIcon::fromTheme("document-print"), tr("&Print..."), MENU_RECEIVER, SLOT(printPage()))->setShortcut(QKeySequence("Ctrl+P"));
m_menuFile->addSeparator();
m_menuFile->addSeparator();
m_menuFile->addAction(tr("Import bookmarks..."), this, SLOT(showBookmarkImport()));
m_menuFile->addAction(tr("Import bookmarks..."), MENU_RECEIVER, SLOT(showBookmarkImport()));
m_menuFile->addAction(m_actionQuit);
#ifdef Q_OS_MAC // Add standard actions to File Menu (as it won't be ever cleared) and Mac menubar should move them to "application" menu
m_menuFile->addAction(m_actionAbout);
m_menuFile->addAction(m_actionPreferences);
#endif
connect(m_menuFile, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFileMenu()));
connect(m_menuFile, SIGNAL(aboutToHide()), this, SLOT(aboutToHideFileMenu()));
connect(m_menuFile, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowFileMenu()));
connect(m_menuFile, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideFileMenu()));
/*************
* Edit Menu *
*************/
m_menuEdit = new QMenu(tr("&Edit"));
m_menuEdit->addAction(QIcon::fromTheme("edit-undo"), tr("&Undo"), this, SLOT(editUndo()))->setShortcut(QKeySequence("Ctrl+Z"));
m_menuEdit->addAction(QIcon::fromTheme("edit-redo"), tr("&Redo"), this, SLOT(editRedo()))->setShortcut(QKeySequence("Ctrl+Shift+Z"));
m_menuEdit->addAction(QIcon::fromTheme("edit-undo"), tr("&Undo"), MENU_RECEIVER, SLOT(editUndo()))->setShortcut(QKeySequence("Ctrl+Z"));
m_menuEdit->addAction(QIcon::fromTheme("edit-redo"), tr("&Redo"), MENU_RECEIVER, SLOT(editRedo()))->setShortcut(QKeySequence("Ctrl+Shift+Z"));
m_menuEdit->addSeparator();
m_menuEdit->addAction(QIcon::fromTheme("edit-cut"), tr("&Cut"), this, SLOT(editCut()))->setShortcut(QKeySequence("Ctrl+X"));
m_menuEdit->addAction(QIcon::fromTheme("edit-copy"), tr("C&opy"), this, SLOT(editCopy()))->setShortcut(QKeySequence("Ctrl+C"));
m_menuEdit->addAction(QIcon::fromTheme("edit-paste"), tr("&Paste"), this, SLOT(editPaste()))->setShortcut(QKeySequence("Ctrl+V"));
m_menuEdit->addAction(QIcon::fromTheme("edit-cut"), tr("&Cut"), MENU_RECEIVER, SLOT(editCut()))->setShortcut(QKeySequence("Ctrl+X"));
m_menuEdit->addAction(QIcon::fromTheme("edit-copy"), tr("C&opy"), MENU_RECEIVER, SLOT(editCopy()))->setShortcut(QKeySequence("Ctrl+C"));
m_menuEdit->addAction(QIcon::fromTheme("edit-paste"), tr("&Paste"), MENU_RECEIVER, SLOT(editPaste()))->setShortcut(QKeySequence("Ctrl+V"));
m_menuEdit->addSeparator();
m_menuEdit->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &All"), this, SLOT(editSelectAll()))->setShortcut(QKeySequence("Ctrl+A"));
m_menuEdit->addAction(QIcon::fromTheme("edit-find"), tr("&Find"), this, SLOT(searchOnPage()))->setShortcut(QKeySequence("Ctrl+F"));
m_menuEdit->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &All"), MENU_RECEIVER, SLOT(editSelectAll()))->setShortcut(QKeySequence("Ctrl+A"));
m_menuEdit->addAction(QIcon::fromTheme("edit-find"), tr("&Find"), MENU_RECEIVER, SLOT(searchOnPage()))->setShortcut(QKeySequence("Ctrl+F"));
m_menuEdit->addSeparator();
#ifdef QZ_WS_X11
m_menuEdit->addAction(m_actionPreferences);
#endif
connect(m_menuEdit, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEditMenu()));
connect(m_menuEdit, SIGNAL(aboutToHide()), this, SLOT(aboutToHideEditMenu()));
connect(m_menuEdit, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowEditMenu()));
connect(m_menuEdit, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideEditMenu()));
/*************
* View Menu *
*************/
m_menuView = new QMenu(tr("&View"));
m_actionShowToolbar = new QAction(tr("&Navigation Toolbar"), this);
m_actionShowToolbar = new QAction(tr("&Navigation Toolbar"), MENU_RECEIVER);
m_actionShowToolbar->setCheckable(true);
connect(m_actionShowToolbar, SIGNAL(triggered(bool)), this, SLOT(showNavigationToolbar()));
m_actionShowBookmarksToolbar = new QAction(tr("&Bookmarks Toolbar"), this);
connect(m_actionShowToolbar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showNavigationToolbar()));
m_actionShowBookmarksToolbar = new QAction(tr("&Bookmarks Toolbar"), MENU_RECEIVER);
m_actionShowBookmarksToolbar->setCheckable(true);
connect(m_actionShowBookmarksToolbar, SIGNAL(triggered(bool)), this, SLOT(showBookmarksToolbar()));
m_actionShowStatusbar = new QAction(tr("Sta&tus Bar"), this);
connect(m_actionShowBookmarksToolbar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showBookmarksToolbar()));
m_actionShowStatusbar = new QAction(tr("Sta&tus Bar"), MENU_RECEIVER);
m_actionShowStatusbar->setCheckable(true);
connect(m_actionShowStatusbar, SIGNAL(triggered(bool)), this, SLOT(showStatusbar()));
connect(m_actionShowStatusbar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showStatusbar()));
#ifndef Q_OS_MAC
m_actionShowMenubar = new QAction(tr("&Menu Bar"), this);
m_actionShowMenubar->setCheckable(true);
connect(m_actionShowMenubar, SIGNAL(triggered(bool)), this, SLOT(showMenubar()));
connect(m_actionShowMenubar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showMenubar()));
m_menuEncoding = new QMenu(this);
#else
m_menuEncoding = new QMenu(0);
#endif
m_actionShowFullScreen = new QAction(tr("&Fullscreen"), this);
m_actionShowFullScreen = new QAction(tr("&Fullscreen"), MENU_RECEIVER);
m_actionShowFullScreen->setCheckable(true);
m_actionShowFullScreen->setShortcut(QKeySequence("F11"));
connect(m_actionShowFullScreen, SIGNAL(triggered(bool)), this, SLOT(fullScreen(bool)));
m_actionStop = new QAction(qIconProvider->standardIcon(QStyle::SP_BrowserStop), tr("&Stop"), this);
connect(m_actionStop, SIGNAL(triggered()), this, SLOT(stop()));
connect(m_actionShowFullScreen, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(fullScreen(bool)));
m_actionStop = new QAction(qIconProvider->standardIcon(QStyle::SP_BrowserStop), tr("&Stop"), MENU_RECEIVER);
connect(m_actionStop, SIGNAL(triggered()), MENU_RECEIVER, SLOT(stop()));
m_actionStop->setShortcut(QKeySequence("Esc"));
m_actionReload = new QAction(qIconProvider->standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), this);
connect(m_actionReload, SIGNAL(triggered()), this, SLOT(reload()));
m_actionReload = new QAction(qIconProvider->standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), MENU_RECEIVER);
connect(m_actionReload, SIGNAL(triggered()), MENU_RECEIVER, SLOT(reload()));
m_actionReload->setShortcut(QKeySequence("F5"));
QAction* actionEncoding = new QAction(tr("Character &Encoding"), this);
m_menuEncoding = new QMenu(this);
QAction* actionEncoding = new QAction(tr("Character &Encoding"), MENU_RECEIVER);
actionEncoding->setMenu(m_menuEncoding);
connect(m_menuEncoding, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEncodingMenu()));
m_actionCaretBrowsing = new QAction(tr("Enable &Caret Browsing"), this);
connect(m_menuEncoding, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowEncodingMenu()));
m_actionCaretBrowsing = new QAction(tr("Enable &Caret Browsing"), MENU_RECEIVER);
m_actionCaretBrowsing->setVisible(false);
m_actionCaretBrowsing->setCheckable(true);
m_actionCaretBrowsing->setShortcut(QKeySequence("F7"));
connect(m_actionCaretBrowsing, SIGNAL(triggered()), this, SLOT(triggerCaretBrowsing()));
connect(m_actionCaretBrowsing, SIGNAL(triggered()), MENU_RECEIVER, SLOT(triggerCaretBrowsing()));
#if QTWEBKIT_FROM_2_3
m_actionCaretBrowsing->setVisible(true);
@ -427,40 +454,40 @@ void QupZilla::setupMenu()
m_menuView->addAction(m_actionStop);
m_menuView->addAction(m_actionReload);
m_menuView->addSeparator();
m_menuView->addAction(QIcon::fromTheme("zoom-in"), tr("Zoom &In"), this, SLOT(zoomIn()))->setShortcut(QKeySequence("Ctrl++"));
m_menuView->addAction(QIcon::fromTheme("zoom-out"), tr("Zoom &Out"), this, SLOT(zoomOut()))->setShortcut(QKeySequence("Ctrl+-"));
m_menuView->addAction(QIcon::fromTheme("zoom-original"), tr("Reset"), this, SLOT(zoomReset()))->setShortcut(QKeySequence("Ctrl+0"));
m_menuView->addAction(QIcon::fromTheme("zoom-in"), tr("Zoom &In"), MENU_RECEIVER, SLOT(zoomIn()))->setShortcut(QKeySequence("Ctrl++"));
m_menuView->addAction(QIcon::fromTheme("zoom-out"), tr("Zoom &Out"), MENU_RECEIVER, SLOT(zoomOut()))->setShortcut(QKeySequence("Ctrl+-"));
m_menuView->addAction(QIcon::fromTheme("zoom-original"), tr("Reset"), MENU_RECEIVER, SLOT(zoomReset()))->setShortcut(QKeySequence("Ctrl+0"));
m_menuView->addSeparator();
m_menuView->addAction(m_actionCaretBrowsing);
m_menuView->addAction(actionEncoding);
m_menuView->addSeparator();
m_actionPageSource = m_menuView->addAction(QIcon::fromTheme("text-html"), tr("&Page Source"), this, SLOT(showSource()));
m_actionPageSource = m_menuView->addAction(QIcon::fromTheme("text-html"), tr("&Page Source"), MENU_RECEIVER, SLOT(showSource()));
m_actionPageSource->setShortcut(QKeySequence("Ctrl+U"));
m_actionPageSource->setEnabled(false);
m_menuView->addAction(m_actionShowFullScreen);
connect(m_menuView, SIGNAL(aboutToShow()), this, SLOT(aboutToShowViewMenu()));
connect(m_menuView, SIGNAL(aboutToHide()), this, SLOT(aboutToHideViewMenu()));
connect(m_menuView, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowViewMenu()));
connect(m_menuView, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideViewMenu()));
/****************
* History Menu *
****************/
m_menuHistory = new Menu(tr("Hi&story"));
m_menuHistory->addAction(qIconProvider->standardIcon(QStyle::SP_ArrowBack), tr("&Back"), this, SLOT(goBack()))->setShortcut(QKeySequence("Ctrl+Left"));
m_menuHistory->addAction(qIconProvider->standardIcon(QStyle::SP_ArrowForward), tr("&Forward"), this, SLOT(goNext()))->setShortcut(QKeySequence("Ctrl+Right"));
m_menuHistory->addAction(qIconProvider->fromTheme("go-home"), tr("&Home"), this, SLOT(goHome()))->setShortcut(QKeySequence("Alt+Home"));
m_menuHistory->addAction(QIcon(":/icons/menu/history.png"), tr("Show &All History"), this, SLOT(showHistoryManager()))->setShortcut(QKeySequence("Ctrl+Shift+H"));
m_menuHistory->addAction(qIconProvider->standardIcon(QStyle::SP_ArrowBack), tr("&Back"), MENU_RECEIVER, SLOT(goBack()))->setShortcut(QKeySequence("Ctrl+Left"));
m_menuHistory->addAction(qIconProvider->standardIcon(QStyle::SP_ArrowForward), tr("&Forward"), MENU_RECEIVER, SLOT(goNext()))->setShortcut(QKeySequence("Ctrl+Right"));
m_menuHistory->addAction(qIconProvider->fromTheme("go-home"), tr("&Home"), MENU_RECEIVER, SLOT(goHome()))->setShortcut(QKeySequence("Alt+Home"));
m_menuHistory->addAction(QIcon(":/icons/menu/history.png"), tr("Show &All History"), MENU_RECEIVER, SLOT(showHistoryManager()))->setShortcut(QKeySequence("Ctrl+Shift+H"));
m_menuHistory->addSeparator();
connect(m_menuHistory, SIGNAL(aboutToShow()), this, SLOT(aboutToShowHistoryMenu()));
connect(m_menuHistory, SIGNAL(aboutToHide()), this, SLOT(aboutToHideHistoryMenu()));
connect(m_menuHistory, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowHistoryMenu()));
connect(m_menuHistory, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideHistoryMenu()));
m_menuClosedTabs = new QMenu(tr("Closed Tabs"));
connect(m_menuClosedTabs, SIGNAL(aboutToShow()), this, SLOT(aboutToShowClosedTabsMenu()));
connect(m_menuClosedTabs, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowClosedTabsMenu()));
m_menuHistoryRecent = new Menu(tr("Recently Visited"), m_menuHistory);
connect(m_menuHistoryRecent, SIGNAL(aboutToShow()), this, SLOT(aboutToShowHistoryRecentMenu()));
connect(m_menuHistoryRecent, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowHistoryRecentMenu()));
m_menuHistoryMost = new Menu(tr("Most Visited"), m_menuHistory);
connect(m_menuHistoryMost, SIGNAL(aboutToShow()), this, SLOT(aboutToShowHistoryMostMenu()));
connect(m_menuHistoryMost, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowHistoryMostMenu()));
m_menuHistory->addMenu(m_menuHistoryRecent);
m_menuHistory->addMenu(m_menuHistoryMost);
@ -470,30 +497,30 @@ void QupZilla::setupMenu()
* Bookmarks Menu *
******************/
m_menuBookmarks = new Menu(tr("&Bookmarks"));
m_menuBookmarks->addAction(tr("Bookmark &This Page"), this, SLOT(bookmarkPage()))->setShortcut(QKeySequence("Ctrl+D"));
m_menuBookmarks->addAction(tr("Bookmark &All Tabs"), this, SLOT(bookmarkAllTabs()));
m_menuBookmarks->addAction(qIconProvider->fromTheme("user-bookmarks"), tr("Organize &Bookmarks"), this, SLOT(showBookmarksManager()))->setShortcut(QKeySequence("Ctrl+Shift+O"));
m_menuBookmarks->addAction(tr("Bookmark &This Page"), MENU_RECEIVER, SLOT(bookmarkPage()))->setShortcut(QKeySequence("Ctrl+D"));
m_menuBookmarks->addAction(tr("Bookmark &All Tabs"), MENU_RECEIVER, SLOT(bookmarkAllTabs()));
m_menuBookmarks->addAction(qIconProvider->fromTheme("user-bookmarks"), tr("Organize &Bookmarks"), MENU_RECEIVER, SLOT(showBookmarksManager()))->setShortcut(QKeySequence("Ctrl+Shift+O"));
m_menuBookmarks->addSeparator();
connect(m_menuBookmarks, SIGNAL(aboutToShow()), this, SLOT(aboutToShowBookmarksMenu()));
connect(m_menuBookmarks, SIGNAL(menuMiddleClicked(Menu*)), this, SLOT(loadFolderBookmarks(Menu*)));
connect(m_menuBookmarks, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowBookmarksMenu()));
connect(m_menuBookmarks, SIGNAL(menuMiddleClicked(Menu*)), MENU_RECEIVER, SLOT(loadFolderBookmarks(Menu*)));
/**************
* Tools Menu *
**************/
m_menuTools = new QMenu(tr("&Tools"));
m_menuTools->addAction(tr("&Web Search"), this, SLOT(webSearch()))->setShortcut(QKeySequence("Ctrl+K"));
m_actionPageInfo = m_menuTools->addAction(QIcon::fromTheme("dialog-information"), tr("Page &Info"), this, SLOT(showPageInfo()));
m_menuTools->addAction(tr("&Web Search"), MENU_RECEIVER, SLOT(webSearch()))->setShortcut(QKeySequence("Ctrl+K"));
m_actionPageInfo = m_menuTools->addAction(QIcon::fromTheme("dialog-information"), tr("Page &Info"), MENU_RECEIVER, SLOT(showPageInfo()));
m_actionPageInfo->setShortcut(QKeySequence("Ctrl+I"));
m_actionPageInfo->setEnabled(false);
m_menuTools->addSeparator();
m_menuTools->addAction(tr("&Download Manager"), this, SLOT(showDownloadManager()))->setShortcut(QKeySequence("Ctrl+Y"));
m_menuTools->addAction(tr("&Cookies Manager"), this, SLOT(showCookieManager()));
m_menuTools->addAction(tr("&Download Manager"), MENU_RECEIVER, SLOT(showDownloadManager()))->setShortcut(QKeySequence("Ctrl+Y"));
m_menuTools->addAction(tr("&Cookies Manager"), MENU_RECEIVER, SLOT(showCookieManager()));
m_menuTools->addAction(tr("&AdBlock"), AdBlockManager::instance(), SLOT(showDialog()));
m_menuTools->addAction(QIcon(":/icons/menu/rss.png"), tr("RSS &Reader"), this, SLOT(showRSSManager()));
m_menuTools->addAction(tr("Web In&spector"), this, SLOT(showWebInspector()))->setShortcut(QKeySequence("Ctrl+Shift+I"));
m_menuTools->addAction(QIcon::fromTheme("edit-clear"), tr("Clear Recent &History"), this, SLOT(showClearPrivateData()))->setShortcut(QKeySequence("Ctrl+Shift+Del"));
m_actionPrivateBrowsing = new QAction(tr("&Private Browsing"), this);
m_menuTools->addAction(QIcon(":/icons/menu/rss.png"), tr("RSS &Reader"), MENU_RECEIVER, SLOT(showRSSManager()));
m_menuTools->addAction(tr("Web In&spector"), MENU_RECEIVER, SLOT(showWebInspector()))->setShortcut(QKeySequence("Ctrl+Shift+I"));
m_menuTools->addAction(QIcon::fromTheme("edit-clear"), tr("Clear Recent &History"), MENU_RECEIVER, SLOT(showClearPrivateData()))->setShortcut(QKeySequence("Ctrl+Shift+Del"));
m_actionPrivateBrowsing = new QAction(tr("&Private Browsing"), MENU_RECEIVER);
m_actionPrivateBrowsing->setShortcut(QKeySequence("Ctrl+Shift+P"));
m_actionPrivateBrowsing->setVisible(!mApp->isPrivateSession());
connect(m_actionPrivateBrowsing, SIGNAL(triggered(bool)), mApp, SLOT(startPrivateBrowsing()));
@ -502,8 +529,8 @@ void QupZilla::setupMenu()
#if !defined(QZ_WS_X11) && !defined(Q_OS_MAC)
m_menuTools->addAction(m_actionPreferences);
#endif
connect(m_menuTools, SIGNAL(aboutToShow()), this, SLOT(aboutToShowToolsMenu()));
connect(m_menuTools, SIGNAL(aboutToHide()), this, SLOT(aboutToHideToolsMenu()));
connect(m_menuTools, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowToolsMenu()));
connect(m_menuTools, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideToolsMenu()));
/*************
* Help Menu *
@ -517,10 +544,10 @@ void QupZilla::setupMenu()
QAction* infoAction = new QAction(tr("Information about application"), m_menuHelp);
infoAction->setData(QUrl("qupzilla:about"));
infoAction->setShortcut(QKeySequence(QKeySequence::HelpContents));
connect(infoAction, SIGNAL(triggered()), this, SLOT(loadActionUrlInNewTab()));
connect(infoAction, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrlInNewTab()));
m_menuHelp->addAction(infoAction);
m_menuHelp->addAction(tr("Configuration Information"), this, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:config"));
m_menuHelp->addAction(tr("Report &Issue"), this, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:reportbug"));
m_menuHelp->addAction(tr("Configuration Information"), MENU_RECEIVER, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:config"));
m_menuHelp->addAction(tr("Report &Issue"), MENU_RECEIVER, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:reportbug"));
/************
* Menu Bar *
@ -539,39 +566,7 @@ void QupZilla::setupMenu()
/*****************
* Other Actions *
*****************/
m_actionRestoreTab = new QAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), this);
m_actionRestoreTab->setShortcut(QKeySequence("Ctrl+Shift+T"));
connect(m_actionRestoreTab, SIGNAL(triggered()), m_tabWidget, SLOT(restoreClosedTab()));
addAction(m_actionRestoreTab);
QShortcut* reloadByPassCacheAction = new QShortcut(QKeySequence("Ctrl+F5"), this);
QShortcut* reloadByPassCacheAction2 = new QShortcut(QKeySequence("Ctrl+Shift+R"), this);
connect(reloadByPassCacheAction, SIGNAL(activated()), this, SLOT(reloadByPassCache()));
connect(reloadByPassCacheAction2, SIGNAL(activated()), this, SLOT(reloadByPassCache()));
QShortcut* reloadAction = new QShortcut(QKeySequence("Ctrl+R"), this);
connect(reloadAction, SIGNAL(activated()), this, SLOT(reload()));
QShortcut* backAction = new QShortcut(QKeySequence("Alt+Left"), this);
connect(backAction, SIGNAL(activated()), this, SLOT(goBack()));
QShortcut* forwardAction = new QShortcut(QKeySequence("Alt+Right"), this);
connect(forwardAction, SIGNAL(activated()), this, SLOT(goNext()));
QShortcut* openLocationAction = new QShortcut(QKeySequence("Alt+D"), this);
connect(openLocationAction, SIGNAL(activated()), this, SLOT(openLocation()));
QShortcut* closeTabAction = new QShortcut(QKeySequence("Ctrl+F4"), this);
connect(closeTabAction, SIGNAL(activated()), m_tabWidget, SLOT(closeTab()));
// Make shortcuts available even in fullscreen (menu hidden)
QList<QAction*> actions = menuBar()->actions();
foreach(QAction * action, actions) {
if (action->menu()) {
actions += action->menu()->actions();
}
addAction(action);
}
setupOtherActions();
#ifndef Q_OS_MAC
m_superMenu->addMenu(m_menuFile);
@ -584,6 +579,81 @@ void QupZilla::setupMenu()
#endif
}
void QupZilla::setupOtherActions()
{
m_actionRestoreTab = new QAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), this);
m_actionRestoreTab->setShortcut(QKeySequence("Ctrl+Shift+T"));
connect(m_actionRestoreTab, SIGNAL(triggered()), MENU_RECEIVER, SLOT(restoreClosedTab()));
addAction(m_actionRestoreTab);
QShortcut* reloadByPassCacheAction = new QShortcut(QKeySequence("Ctrl+F5"), this);
QShortcut* reloadByPassCacheAction2 = new QShortcut(QKeySequence("Ctrl+Shift+R"), this);
connect(reloadByPassCacheAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(reloadByPassCache()));
connect(reloadByPassCacheAction2, SIGNAL(activated()), MENU_RECEIVER, SLOT(reloadByPassCache()));
QShortcut* reloadAction = new QShortcut(QKeySequence("Ctrl+R"), this);
connect(reloadAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(reload()));
QShortcut* backAction = new QShortcut(QKeySequence("Alt+Left"), this);
connect(backAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(goBack()));
QShortcut* forwardAction = new QShortcut(QKeySequence("Alt+Right"), this);
connect(forwardAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(goNext()));
QShortcut* openLocationAction = new QShortcut(QKeySequence("Alt+D"), this);
connect(openLocationAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(openLocation()));
QShortcut* closeTabAction = new QShortcut(QKeySequence("Ctrl+F4"), this);
connect(closeTabAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(closeTab()));
// Make shortcuts available even in fullscreen (menu hidden)
QList<QAction*> actions = menuBar()->actions();
foreach(QAction * action, actions) {
if (action->menu()) {
actions += action->menu()->actions();
}
addAction(action);
}
}
#ifdef Q_OS_MAC
void QupZilla::setupMacMenu()
{
// menus
m_menuFile = menuBar()->actions().at(0)->menu();
m_menuEdit = menuBar()->actions().at(1)->menu();
m_menuView = menuBar()->actions().at(2)->menu();
m_menuHistory = qobject_cast<Menu*>(menuBar()->actions().at(3)->menu());
m_menuBookmarks = qobject_cast<Menu*>(menuBar()->actions().at(4)->menu());
m_menuTools = menuBar()->actions().at(5)->menu();
m_menuHelp = menuBar()->actions().at(6)->menu();
m_menuEncoding = m_menuView->actions().at(12)->menu();
m_menuHistoryRecent = qobject_cast<Menu*>(m_menuHistory->actions().at(5)->menu());
m_menuHistoryMost = qobject_cast<Menu*>(m_menuHistory->actions().at(6)->menu());
m_menuClosedTabs = m_menuHistory->actions().at(7)->menu();
// actions
m_actionCloseWindow = m_menuFile->actions().at(5);
m_actionQuit = m_menuFile->actions().at(13);
m_actionAbout = m_menuFile->actions().at(14);
m_actionPreferences = m_menuFile->actions().at(15);
m_actionShowToolbar = m_menuView->actions().at(0)->menu()->actions().at(0);
m_actionShowBookmarksToolbar = m_menuView->actions().at(0)->menu()->actions().at(1);
m_actionShowStatusbar = m_menuView->actions().at(2);
m_actionStop = m_menuView->actions().at(4);
m_actionReload = m_menuView->actions().at(5);
m_actionCaretBrowsing = m_menuView->actions().at(11);
m_actionPageSource = m_menuView->actions().at(14);
m_actionShowFullScreen = m_menuView->actions().at(15);
m_actionPageInfo = m_menuTools->actions().at(1);
m_actionPrivateBrowsing = m_menuTools->actions().at(9);
}
#endif
void QupZilla::loadSettings()
{
Settings settings;
@ -695,7 +765,7 @@ void QupZilla::goBack()
QMenuBar* QupZilla::menuBar() const
{
#ifdef Q_OS_MAC
return m_macMenuBar;
return mApp->macMenuReceiver()->menuBar();
#else
return QMainWindow::menuBar();
#endif
@ -760,7 +830,7 @@ void QupZilla::receiveMessage(Qz::AppMessageType mes, bool state)
break;
case Qz::AM_BookmarksChanged:
m_bookmarksMenuChanged = true;
setBookmarksMenuChanged(true);
break;
default:
@ -771,7 +841,9 @@ void QupZilla::receiveMessage(Qz::AppMessageType mes, bool state)
void QupZilla::aboutToShowFileMenu()
{
#ifndef Q_OS_MAC
m_actionCloseWindow->setEnabled(mApp->windowCount() > 1);
#endif
}
void QupZilla::aboutToHideFileMenu()
@ -781,13 +853,13 @@ void QupZilla::aboutToHideFileMenu()
void QupZilla::aboutToShowBookmarksMenu()
{
if (!m_bookmarksMenuChanged) {
if (m_menuBookmarksAction) {
m_menuBookmarksAction->setVisible(m_bookmarksToolbar->isVisible());
if (!bookmarksMenuChanged()) {
if (menuBookmarksAction()) {
menuBookmarksAction()->setVisible(m_bookmarksToolbar->isVisible());
}
return;
}
m_bookmarksMenuChanged = false;
setBookmarksMenuChanged(false);
while (m_menuBookmarks->actions().count() != 4) {
QAction* act = m_menuBookmarks->actions().at(4);
@ -811,8 +883,8 @@ void QupZilla::aboutToShowBookmarksMenu()
Action* act = new Action(icon, title);
act->setData(url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab()));
connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
m_menuBookmarks->addAction(act);
}
@ -831,14 +903,14 @@ void QupZilla::aboutToShowBookmarksMenu()
Action* act = new Action(icon, title);
act->setData(url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab()));
connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
menuBookmarks->addAction(act);
}
if (menuBookmarks->isEmpty()) {
menuBookmarks->addAction(tr("Empty"))->setEnabled(false);
}
m_menuBookmarksAction = m_menuBookmarks->addMenu(menuBookmarks);
setMenuBookmarksAction(m_menuBookmarks->addMenu(menuBookmarks));
query.exec("SELECT name FROM folders");
while (query.next()) {
@ -861,8 +933,8 @@ void QupZilla::aboutToShowBookmarksMenu()
Action* act = new Action(icon, title);
act->setData(url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab()));
connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
tempFolder->addAction(act);
}
if (tempFolder->isEmpty()) {
@ -885,12 +957,12 @@ void QupZilla::aboutToShowBookmarksMenu()
Action* act = new Action(icon, title);
act->setData(url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab()));
connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
m_menuBookmarks->addAction(act);
}
m_menuBookmarksAction->setVisible(m_bookmarksToolbar->isVisible());
menuBookmarksAction()->setVisible(m_bookmarksToolbar->isVisible());
}
void QupZilla::aboutToShowHistoryMenu()
@ -920,7 +992,7 @@ void QupZilla::aboutToShowClosedTabsMenu()
title.truncate(40);
title += "..";
}
m_menuClosedTabs->addAction(_iconForUrl(tab.url), title, m_tabWidget, SLOT(restoreClosedTab()))->setData(i);
m_menuClosedTabs->addAction(_iconForUrl(tab.url), title, MENU_RECEIVER, SLOT(restoreClosedTab()))->setData(i);
i++;
}
m_menuClosedTabs->addSeparator();
@ -928,8 +1000,8 @@ void QupZilla::aboutToShowClosedTabsMenu()
m_menuClosedTabs->addAction(tr("Empty"))->setEnabled(false);
}
else {
m_menuClosedTabs->addAction(tr("Restore All Closed Tabs"), m_tabWidget, SLOT(restoreAllClosedTabs()));
m_menuClosedTabs->addAction(tr("Clear list"), m_tabWidget, SLOT(clearClosedTabsList()));
m_menuClosedTabs->addAction(tr("Restore All Closed Tabs"), MENU_RECEIVER, SLOT(restoreAllClosedTabs()));
m_menuClosedTabs->addAction(tr("Clear list"), MENU_RECEIVER, SLOT(clearClosedTabsList()));
}
}
@ -948,8 +1020,8 @@ void QupZilla::aboutToShowHistoryRecentMenu()
Action* act = new Action(_iconForUrl(url), title);
act->setData(url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab()));
connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
m_menuHistoryRecent->addAction(act);
}
@ -973,8 +1045,8 @@ void QupZilla::aboutToShowHistoryMostMenu()
Action* act = new Action(_iconForUrl(entry.url), title);
act->setData(entry.url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab()));
connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
m_menuHistoryMost->addAction(act);
}
@ -988,7 +1060,10 @@ void QupZilla::aboutToShowViewMenu()
m_actionShowToolbar->setChecked(m_navigationBar->isVisible());
#ifndef Q_OS_MAC
m_actionShowMenubar->setChecked(menuBar()->isVisible());
#else
m_sideBarManager->setSideBarMenu(m_menuView->actions().at(1)->menu());
#endif
m_actionShowStatusbar->setChecked(statusBar()->isVisible());
m_actionShowBookmarksToolbar->setChecked(m_bookmarksToolbar->isVisible());
@ -1001,7 +1076,9 @@ void QupZilla::aboutToShowViewMenu()
void QupZilla::aboutToHideViewMenu()
{
#ifndef Q_OS_MAC
m_actionPageSource->setEnabled(false);
#endif
}
void QupZilla::aboutToShowEditMenu()
@ -1020,9 +1097,11 @@ void QupZilla::aboutToShowEditMenu()
void QupZilla::aboutToHideEditMenu()
{
#ifndef Q_OS_MAC
foreach(QAction * act, m_menuEdit->actions()) {
act->setEnabled(false);
}
#endif
m_menuEdit->actions().at(8)->setEnabled(true);
m_actionPreferences->setEnabled(true);
@ -1035,7 +1114,9 @@ void QupZilla::aboutToShowToolsMenu()
void QupZilla::aboutToHideToolsMenu()
{
#ifndef Q_OS_MAC
m_actionPageInfo->setEnabled(false);
#endif
}
void QupZilla::aboutToShowEncodingMenu()
@ -1062,7 +1143,7 @@ void QupZilla::aboutToShowEncodingMenu()
QAction* action = new QAction(nameString, 0);
action->setData(nameString);
action->setCheckable(true);
connect(action, SIGNAL(triggered()), this, SLOT(changeEncoding()));
connect(action, SIGNAL(triggered()), MENU_RECEIVER, SLOT(changeEncoding()));
if (activeCodec.compare(nameString, Qt::CaseInsensitive) == 0) {
action->setChecked(true);
}
@ -1105,9 +1186,13 @@ void QupZilla::aboutToShowEncodingMenu()
}
}
void QupZilla::changeEncoding()
void QupZilla::changeEncoding(QObject* obj)
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
if (!obj) {
obj = sender();
}
if (QAction* action = qobject_cast<QAction*>(obj)) {
const QString &encoding = action->data().toString();
mApp->webSettings()->setDefaultTextEncoding(encoding);
@ -1222,23 +1307,35 @@ void QupZilla::reloadByPassCache()
weView()->triggerPageAction(QWebPage::ReloadAndBypassCache);
}
void QupZilla::loadActionUrl()
void QupZilla::loadActionUrl(QObject *obj)
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
if (!obj) {
obj = sender();
}
if (QAction* action = qobject_cast<QAction*>(obj)) {
loadAddress(action->data().toUrl());
}
}
void QupZilla::loadActionUrlInNewTab()
void QupZilla::loadActionUrlInNewTab(QObject* obj)
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
if (!obj) {
obj = sender();
}
if (QAction* action = qobject_cast<QAction*>(obj)) {
m_tabWidget->addView(action->data().toUrl(), Qz::NT_SelectedTabAtTheEnd);
}
}
void QupZilla::loadActionUrlInNewNotSelectedTab()
void QupZilla::loadActionUrlInNewNotSelectedTab(QObject* obj)
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
if (!obj) {
obj = sender();
}
if (QAction* action = qobject_cast<QAction*>(obj)) {
m_tabWidget->addView(action->data().toUrl(), Qz::NT_NotSelectedTab);
}
}
@ -1939,9 +2036,13 @@ void QupZilla::disconnectObjects()
void QupZilla::closeWindow()
{
#ifdef Q_OS_MAC
close();
#else
if (mApp->windowCount() > 1) {
close();
}
#endif
}
bool QupZilla::quitApp()
@ -1966,6 +2067,65 @@ bool QupZilla::quitApp()
return true;
}
void QupZilla::closeTab()
{
m_tabWidget->closeTab();
}
void QupZilla::restoreClosedTab(QObject* obj)
{
if (!obj) {
obj = sender();
}
m_tabWidget->restoreClosedTab(obj);
}
void QupZilla::restoreAllClosedTabs()
{
m_tabWidget->restoreAllClosedTabs();
}
void QupZilla::clearClosedTabsList()
{
m_tabWidget->clearClosedTabsList();
}
bool QupZilla::bookmarksMenuChanged()
{
#ifdef Q_OS_MAC
return mApp->macMenuReceiver()->bookmarksMenuChanged();
#else
return m_bookmarksMenuChanged;
#endif
}
void QupZilla::setBookmarksMenuChanged(bool changed)
{
#ifdef Q_OS_MAC
mApp->macMenuReceiver()->setBookmarksMenuChanged(changed);
#else
m_bookmarksMenuChanged = changed;
#endif
}
QAction* QupZilla::menuBookmarksAction()
{
#ifdef Q_OS_MAC
return mApp->macMenuReceiver()->menuBookmarksAction();
#else
return m_menuBookmarksAction;
#endif
}
void QupZilla::setMenuBookmarksAction(QAction* action)
{
#ifdef Q_OS_MAC
mApp->macMenuReceiver()->setMenuBookmarksAction(action);
#else
m_menuBookmarksAction = action;
#endif
}
QByteArray QupZilla::saveState(int version) const
{
#ifdef QZ_WS_X11

View File

@ -113,9 +113,9 @@ public slots:
void showWebInspector(bool toggle = true);
void showBookmarksToolbar();
void loadActionUrl();
void loadActionUrlInNewTab();
void loadActionUrlInNewNotSelectedTab();
void loadActionUrl(QObject* obj = 0);
void loadActionUrlInNewTab(QObject* obj = 0);
void loadActionUrlInNewNotSelectedTab(QObject* obj = 0);
void loadFolderBookmarks(Menu* menu);
void bookmarkPage();
@ -189,12 +189,16 @@ private slots:
void zoomOut();
void zoomReset();
void fullScreen(bool make);
void changeEncoding();
void changeEncoding(QObject *obj = 0);
void triggerCaretBrowsing();
void closeWindow();
bool quitApp();
void closeTab();
void restoreClosedTab(QObject* obj = 0);
void restoreAllClosedTabs();
void clearClosedTabsList();
#ifdef Q_OS_WIN
void applyBlurToMainWindow(bool force = false);
#endif
@ -209,6 +213,10 @@ private:
void setupUi();
void setupMenu();
void setupOtherActions();
#ifdef Q_OS_MAC
void setupMacMenu();
#endif
void disconnectObjects();
@ -226,6 +234,12 @@ private:
void moveToVirtualDesktop(int desktopId);
#endif
bool bookmarksMenuChanged();
void setBookmarksMenuChanged(bool changed);
QAction* menuBookmarksAction();
void setMenuBookmarksAction(QAction* action);
bool m_historyMenuChanged;
bool m_bookmarksMenuChanged;
bool m_isClosing;
@ -249,9 +263,6 @@ private:
Menu* m_menuHistoryMost;
QMenu* m_menuEncoding;
QAction* m_menuBookmarksAction;
#ifdef Q_OS_MAC
QMenuBar* m_macMenuBar;
#endif
QAction* m_actionAbout;
QAction* m_actionPreferences;

View File

@ -46,7 +46,8 @@ enum AppMessageType {
enum BrowserWindow {
BW_FirstAppWindow,
BW_OtherRestoredWindow,
BW_NewWindow
BW_NewWindow,
BW_MacFirstWindow
};
enum CommandLineAction {

View File

@ -441,11 +441,16 @@ RESOURCES += \
LIBS += -lX11
}
win {
win32 {
HEADERS += other/registerqappassociation.h
SOURCES += other/registerqappassociation.cpp
}
macx {
HEADERS += other/macmenureceiver.h
SOURCES += other/macmenureceiver.cpp
}
message(===========================================)
message( Using following defines:)
message( $$DEFINES)

View File

@ -0,0 +1,537 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
* Copyright (C) 2013 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
*
* 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/>.
* ============================================================ */
#include "macmenureceiver.h"
#include "mainapplication.h"
#include "qupzilla.h"
#include "settings.h"
#include <QAction>
#include <QMenu>
#include <QDebug>
MacMenuReceiver::MacMenuReceiver(QObject* parent)
: QObject(parent)
, m_macMenuBar(0)
, m_bookmarksMenuChanged(true)
, m_menuBookmarksAction(0)
{
}
void MacMenuReceiver::setEnabledSelectedMenuActions(QMenu* menu, const QList<int> indexList)
{
if (!menu || mApp->windowCount() == 0) {
return;
}
// we mean all actions by empty list
if (indexList.isEmpty()) {
foreach (QAction * act, menu->actions()) {
act->setEnabled(true);
}
return;
}
foreach (int index, indexList) {
Q_ASSERT(index >= 0 && index < menu->actions().size());
menu->actions().at(index)->setEnabled(true);
}
}
void MacMenuReceiver::setDisabledSelectedMenuActions(QMenu* menu, const QList<int> indexList)
{
if (!menu) {
return;
}
// we mean all actions by empty list
if (indexList.isEmpty()) {
foreach (QAction * act, menu->actions()) {
act->setDisabled(true);
}
return;
}
foreach (int index, indexList) {
Q_ASSERT(index >= 0 && index < menu->actions().size());
menu->actions().at(index)->setDisabled(true);
}
}
bool MacMenuReceiver::callSlot(const char *member, bool makeIfNoWindow, QGenericArgument val0, QGenericArgument val1)
{
//qDebug("MacMenuReceiver::callSlot: \'QupZilla::%s()\'", member);
QupZilla* qzWindow = mApp->getWindow();
if (!qzWindow) {
if (!makeIfNoWindow) {
return false;
}
else {
qzWindow = mApp->makeNewWindow(Qz::BW_MacFirstWindow);
mApp->processEvents();
}
}
bool success = QMetaObject::invokeMethod(qzWindow, member, val0, val1);
if (!success) {
qCritical("Warning: try to invoke \'QupZilla::%s()\' with incorrect parameter(s) or no such slot.", member);
// this should never happen, for now:
// we just ignore it!
}
return true;
}
void MacMenuReceiver::goNext()
{
callSlot("goNext");
}
void MacMenuReceiver::goBack()
{
callSlot("goBack");
}
void MacMenuReceiver::goHome()
{
callSlot("goHome", true);
}
void MacMenuReceiver::stop()
{
callSlot("stop");
}
void MacMenuReceiver::reload()
{
callSlot("reload");
}
void MacMenuReceiver::reloadByPassCache()
{
callSlot("reloadByPassCache");
}
void MacMenuReceiver::aboutQupZilla()
{
callSlot("aboutQupZilla", true);
}
void MacMenuReceiver::addTab()
{
if (!callSlot("addTab")) {
mApp->makeNewWindow(Qz::BW_MacFirstWindow);
}
}
void MacMenuReceiver::savePageScreen()
{
callSlot("savePageScreen");
}
void MacMenuReceiver::searchOnPage()
{
callSlot("searchOnPage");
}
void MacMenuReceiver::showCookieManager()
{
callSlot("showCookieManager");
}
void MacMenuReceiver::showHistoryManager()
{
callSlot("showHistoryManager");
}
void MacMenuReceiver::showBookmarksManager()
{
callSlot("showBookmarksManager");
}
void MacMenuReceiver::showRSSManager()
{
callSlot("showRSSManager");
}
void MacMenuReceiver::showDownloadManager()
{
callSlot("showDownloadManager");
}
void MacMenuReceiver::showMenubar()
{
callSlot("showMenubar");
}
void MacMenuReceiver::showNavigationToolbar()
{
callSlot("showNavigationToolbar");
}
void MacMenuReceiver::showStatusbar()
{
callSlot("showStatusbar");
}
void MacMenuReceiver::showClearPrivateData()
{
callSlot("showClearPrivateData");
}
void MacMenuReceiver::showPreferences()
{
callSlot("showPreferences", true);
}
void MacMenuReceiver::showBookmarkImport()
{
callSlot("showBookmarkImport");
}
void MacMenuReceiver::refreshHistory()
{
callSlot("refreshHistory");
}
void MacMenuReceiver::bookmarkAllTabs()
{
callSlot("bookmarkAllTabs");
}
void MacMenuReceiver::newWindow()
{
if (!callSlot("newWindow")) {
mApp->makeNewWindow(Qz::BW_MacFirstWindow);
}
}
void MacMenuReceiver::openLocation()
{
callSlot("openLocation", true);
}
void MacMenuReceiver::openFile()
{
callSlot("openFile", true);
}
void MacMenuReceiver::savePage()
{
callSlot("savePage");
}
void MacMenuReceiver::sendLink()
{
callSlot("sendLink");
}
void MacMenuReceiver::webSearch()
{
callSlot("webSearch");
}
void MacMenuReceiver::editUndo()
{
callSlot("editUndo");
}
void MacMenuReceiver::editRedo()
{
callSlot("editRedo");
}
void MacMenuReceiver::editCut()
{
callSlot("editCut");
}
void MacMenuReceiver::editCopy()
{
callSlot("editCopy");
}
void MacMenuReceiver::editPaste()
{
callSlot("editPaste");
}
void MacMenuReceiver::editSelectAll()
{
callSlot("editSelectAll");
}
void MacMenuReceiver::zoomIn()
{
callSlot("zoomIn");
}
void MacMenuReceiver::zoomOut()
{
callSlot("zoomOut");
}
void MacMenuReceiver::zoomReset()
{
callSlot("zoomReset");
}
void MacMenuReceiver::fullScreen(bool make)
{
callSlot("fullScreen", false, Q_ARG(bool, make));
}
void MacMenuReceiver::changeEncoding(QObject* obj)
{
if (!obj) {
obj = sender();
}
callSlot("changeEncoding", false, Q_ARG(QObject*, obj));
}
void MacMenuReceiver::triggerCaretBrowsing()
{
callSlot("triggerCaretBrowsing");
}
void MacMenuReceiver::closeWindow()
{
callSlot("closeWindow");
}
void MacMenuReceiver::quitApp()
{
if (!callSlot("quitApp")) {
mApp->quitApplication();
}
}
void MacMenuReceiver::printPage(QWebFrame* frame)
{
callSlot("printPage", false, Q_ARG(QWebFrame*, frame));
}
void MacMenuReceiver::showBookmarksToolbar()
{
callSlot("showBookmarksToolbar");
}
void MacMenuReceiver::showSource(QWebFrame* frame, const QString &selectedHtml)
{
callSlot("showSource", false, Q_ARG(QWebFrame*, frame), Q_ARG(const QString &, selectedHtml));
}
void MacMenuReceiver::bookmarkPage()
{
callSlot("bookmarkPage");
}
void MacMenuReceiver::loadFolderBookmarks(Menu* menu)
{
callSlot("loadFolderBookmarks", false, Q_ARG(Menu*, menu));
}
void MacMenuReceiver::closeTab()
{
callSlot("closeTab");
}
void MacMenuReceiver::restoreClosedTab(QObject* obj)
{
if (!obj) {
obj = sender();
}
callSlot("restoreClosedTab", false, Q_ARG(QObject*, obj));
}
void MacMenuReceiver::restoreAllClosedTabs()
{
callSlot("restoreAllClosedTabs");
}
void MacMenuReceiver::clearClosedTabsList()
{
callSlot("clearClosedTabsList");
}
void MacMenuReceiver::showPageInfo()
{
callSlot("showPageInfo");
}
void MacMenuReceiver::showWebInspector(bool toggle)
{
callSlot("showWebInspector", false, Q_ARG(bool, toggle));
}
void MacMenuReceiver::loadActionUrl(QObject* obj)
{
if (!obj) {
obj = sender();
}
callSlot("loadActionUrl", true, Q_ARG(QObject*, obj));
}
void MacMenuReceiver::loadActionUrlInNewTab(QObject* obj)
{
if (!obj) {
obj = sender();
}
if (!callSlot("loadActionUrlInNewTab", false, Q_ARG(QObject*, obj))) {
callSlot("loadActionUrl", true, Q_ARG(QObject*, obj));
}
}
void MacMenuReceiver::loadActionUrlInNewNotSelectedTab(QObject* obj)
{
if (!obj) {
obj = sender();
}
if (!callSlot("loadActionUrlInNewNotSelectedTab", false, Q_ARG(QObject*, obj))) {
callSlot("loadActionUrl", true, Q_ARG(QObject*, obj));
}
}
// about to show/hide slots
void MacMenuReceiver::aboutToShowFileMenu()
{
QMenu* menu = qobject_cast<QMenu*>(sender());
setEnabledSelectedMenuActions(menu);
if (!callSlot("aboutToShowFileMenu")) {
setDisabledSelectedMenuActions(menu, QList<int>()
<< 4 << 5 << 7 << 8 << 9 << 10 << 12);
}
}
void MacMenuReceiver::aboutToHideFileMenu()
{
callSlot("aboutToHideFileMenu");
}
void MacMenuReceiver::aboutToShowHistoryMenu()
{
QMenu* menu = qobject_cast<QMenu*>(sender());
// 2=Home, 3=Show all History, 7=Closed Tabs
setEnabledSelectedMenuActions(menu, QList<int>() << 2 << 3 << 7);
if (!callSlot("aboutToShowHistoryMenu")) {
setDisabledSelectedMenuActions(menu, QList<int>()
<< 0 << 1 << 2 << 3 << 7);
}
}
void MacMenuReceiver::aboutToHideHistoryMenu()
{
callSlot("aboutToHideHistoryMenu");
}
void MacMenuReceiver::aboutToShowClosedTabsMenu()
{
callSlot("aboutToShowClosedTabsMenu");
}
void MacMenuReceiver::aboutToShowBookmarksMenu()
{
QMenu* menu = qobject_cast<QMenu*>(sender());
setEnabledSelectedMenuActions(menu, QList<int>() << 0 << 1 << 2);
if (!callSlot("aboutToShowBookmarksMenu")) {
setDisabledSelectedMenuActions(menu, QList<int>() << 0 << 1 << 2);
}
}
void MacMenuReceiver::aboutToShowViewMenu()
{
QMenu* menu = qobject_cast<QMenu*>(sender());
// 7,8,9=Zoom actions, 12=Character Encoding, 15=Fullscreen
setEnabledSelectedMenuActions(menu, QList<int>()
<< 0 << 1 << 2 << 7 << 8 << 9 << 11 << 12 << 15);
// for updating reload and stop actions
if (mApp->getWindow()) {
mApp->getWindow()->updateLoadingActions();
}
if (!callSlot("aboutToShowViewMenu")) {
setDisabledSelectedMenuActions(menu);
}
}
void MacMenuReceiver::aboutToHideViewMenu()
{
callSlot("aboutToHideViewMenu");
}
void MacMenuReceiver::aboutToShowEditMenu()
{
QMenu* menu = qobject_cast<QMenu*>(sender());
// 8=Find
setEnabledSelectedMenuActions(menu, QList<int>() << 8);
if (!callSlot("aboutToShowEditMenu")) {
setDisabledSelectedMenuActions(menu);
}
}
void MacMenuReceiver::aboutToHideEditMenu()
{
callSlot("aboutToHideEditMenu");
}
void MacMenuReceiver::aboutToShowToolsMenu()
{
QMenu* menu = qobject_cast<QMenu*>(sender());
// enable all
setEnabledSelectedMenuActions(menu);
if (!callSlot("aboutToShowToolsMenu")) {
setDisabledSelectedMenuActions(menu, QList<int>()
<< 0 << 1 << 3 << 4 << 6 << 7 << 8);
}
}
void MacMenuReceiver::aboutToHideToolsMenu()
{
callSlot("aboutToHideToolsMenu");
}
void MacMenuReceiver::aboutToShowEncodingMenu()
{
callSlot("aboutToShowEncodingMenu");
}
void MacMenuReceiver::aboutToShowHistoryRecentMenu()
{
callSlot("aboutToShowHistoryRecentMenu");
}
void MacMenuReceiver::aboutToShowHistoryMostMenu()
{
callSlot("aboutToShowHistoryMostMenu");
}

View File

@ -0,0 +1,144 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
* Copyright (C) 2013 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
*
* 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/>.
* ============================================================ */
#ifndef MACMENURECEIVER_H
#define MACMENURECEIVER_H
#include <QObject>
#include "qz_namespace.h"
class QWebFrame;
class Menu;
class QMenu;
class QAction;
class QMenuBar;
class QT_QUPZILLA_EXPORT MacMenuReceiver : public QObject
{
Q_OBJECT
public:
MacMenuReceiver(QObject* parent = 0);
inline QMenuBar* menuBar() { return m_macMenuBar; }
inline void setMenuBar(QMenuBar* menuBar) { m_macMenuBar = menuBar; }
inline bool bookmarksMenuChanged() { return m_bookmarksMenuChanged; }
inline void setBookmarksMenuChanged(bool changed) { m_bookmarksMenuChanged = changed; }
inline QAction* menuBookmarksAction() { return m_menuBookmarksAction; }
inline void setMenuBookmarksAction(QAction* action) { m_menuBookmarksAction = action; }
private:
void setEnabledSelectedMenuActions(QMenu* menu, const QList<int> indexList = QList<int>());
void setDisabledSelectedMenuActions(QMenu* menu, const QList<int> indexList = QList<int>());
bool callSlot(const char *member, bool makeIfNoWindow = false,
QGenericArgument val0 = QGenericArgument(0),
QGenericArgument val1 = QGenericArgument());
QMenuBar* m_macMenuBar;
bool m_bookmarksMenuChanged;
QAction* m_menuBookmarksAction;
private slots:
void goNext();
void goBack();
void goHome();
void stop();
void reload();
void reloadByPassCache();
void aboutQupZilla();
void addTab();
void savePageScreen();
void aboutToShowFileMenu();
void aboutToHideFileMenu();
void aboutToShowHistoryMenu();
void aboutToHideHistoryMenu();
void aboutToShowClosedTabsMenu();
void aboutToShowBookmarksMenu();
void aboutToShowViewMenu();
void aboutToHideViewMenu();
void aboutToShowEditMenu();
void aboutToHideEditMenu();
void aboutToShowToolsMenu();
void aboutToHideToolsMenu();
void aboutToShowEncodingMenu();
void searchOnPage();
void showCookieManager();
void showHistoryManager();
void showBookmarksManager();
void showRSSManager();
void showDownloadManager();
void showMenubar();
void showNavigationToolbar();
void showStatusbar();
void showClearPrivateData();
void aboutToShowHistoryRecentMenu();
void aboutToShowHistoryMostMenu();
void showPreferences();
void showBookmarkImport();
void refreshHistory();
void bookmarkAllTabs();
void newWindow();
void openLocation();
void openFile();
void savePage();
void sendLink();
void webSearch();
// Edit menu actions
void editUndo();
void editRedo();
void editCut();
void editCopy();
void editPaste();
void editSelectAll();
void zoomIn();
void zoomOut();
void zoomReset();
void fullScreen(bool make);
void changeEncoding(QObject *obj = 0);
void triggerCaretBrowsing();
void closeWindow();
void quitApp();
void printPage(QWebFrame* frame = 0);
void showBookmarksToolbar();
void showSource(QWebFrame* frame = 0, const QString &selectedHtml = QString());
void bookmarkPage();
void showPageInfo();
void showWebInspector(bool toggle = true);
void loadActionUrl(QObject* obj = 0);
void loadActionUrlInNewTab(QObject* obj = 0);
void loadActionUrlInNewNotSelectedTab(QObject* obj = 0);
void loadFolderBookmarks(Menu* menu);
void closeTab();
void restoreClosedTab(QObject* obj = 0);
void restoreAllClosedTabs();
void clearClosedTabsList();
};
#endif // MACMENURECEIVER_H

View File

@ -14,10 +14,10 @@ unix:contains(DEFINES, USE_QTWEBKIT_2_3):system(pkg-config --exists hunspell) {
LIBS += $$system(pkg-config --libs hunspell)
}
win {
win32 {
# QtWebKit 2.3 and Hunspell is now needed to build on Windows
buildSpellcheck = true
LIBS += $PWD/../../../../bin/libhunspell.dll
LIBS += $$PWD/../../../../bin/libhunspell.lib
}
equals(buildSpellcheck, true) {

View File

@ -641,15 +641,18 @@ int TabWidget::duplicateTab(int index)
return id;
}
void TabWidget::restoreClosedTab()
void TabWidget::restoreClosedTab(QObject* obj)
{
if (!obj) {
obj = sender();
}
if (!m_closedTabsManager->isClosedTabAvailable()) {
return;
}
ClosedTabsManager::Tab tab;
QAction* action = qobject_cast<QAction*>(sender());
QAction* action = qobject_cast<QAction*>(obj);
if (action && action->data().toInt() != 0) {
tab = m_closedTabsManager->getTabAt(action->data().toInt());
}

View File

@ -110,7 +110,7 @@ public slots:
void reloadAllTabs();
void stopTab(int index);
void closeAllButCurrent(int index);
void restoreClosedTab();
void restoreClosedTab(QObject* obj = 0);
void restoreAllClosedTabs();
void clearClosedTabsList();
void aboutToShowClosedTabsMenu();