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

[Mac] Added support for global-menu.

-Added MacMenuReceiver class
-Added MENU_RECEIVER as receiver for action's signal
This commit is contained in:
S. Razi Alavizadeh 2013-02-07 16:31:01 +03:30
parent 67d6d380cd
commit 860b5b8440
8 changed files with 812 additions and 110 deletions

View File

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

View File

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

View File

@ -90,6 +90,13 @@
#include <X11/Xatom.h> #include <X11/Xatom.h>
#endif #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::VERSION = "1.3.5";
const QString QupZilla::BUILDTIME = __DATE__" "__TIME__; const QString QupZilla::BUILDTIME = __DATE__" "__TIME__;
const QString QupZilla::AUTHOR = "David Rosca"; const QString QupZilla::AUTHOR = "David Rosca";
@ -182,6 +189,7 @@ void QupZilla::postLaunch()
} }
break; break;
case Qz::BW_MacFirstWindow:
case Qz::BW_NewWindow: case Qz::BW_NewWindow:
addTab = true; addTab = true;
break; break;
@ -219,6 +227,16 @@ void QupZilla::postLaunch()
aboutToHideEditMenu(); 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); mApp->plugins()->emitMainWindowCreated(this);
emit startingCompleted(); emit startingCompleted();
@ -303,12 +321,12 @@ void QupZilla::setupMenu()
// Standard actions - needed on Mac to be placed correctly in "application" menu // 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 = new QAction(QIcon(":/icons/qupzilla.png"), tr("&About QupZilla"), 0);
m_actionAbout->setMenuRole(QAction::AboutRole); 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 = new QAction(QIcon(":/icons/faenza/settings.png"), tr("Pr&eferences"), 0);
m_actionPreferences->setMenuRole(QAction::PreferencesRole); m_actionPreferences->setMenuRole(QAction::PreferencesRole);
m_actionPreferences->setShortcut(QKeySequence(QKeySequence::Preferences)); 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 = new QAction(QIcon::fromTheme("application-exit"), tr("Quit"), 0);
m_actionQuit->setMenuRole(QAction::QuitRole); m_actionQuit->setMenuRole(QAction::QuitRole);
@ -320,92 +338,91 @@ void QupZilla::setupMenu()
} }
#endif #endif
m_actionQuit->setShortcut(quitSequence); m_actionQuit->setShortcut(quitSequence);
connect(m_actionQuit, SIGNAL(triggered()), this, SLOT(quitApp())); connect(m_actionQuit, SIGNAL(triggered()), MENU_RECEIVER, SLOT(quitApp()));
/************* /*************
* File Menu * * File Menu *
*************/ *************/
m_menuFile = new QMenu(tr("&File")); 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::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"), this, SLOT(addTab()))->setShortcut(QKeySequence("Ctrl+T")); 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"), this, SLOT(openLocation()))->setShortcut(QKeySequence("Ctrl+L")); 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"), this, SLOT(openFile()))->setShortcut(QKeySequence("Ctrl+O")); m_menuFile->addAction(QIcon::fromTheme("document-open"), tr("Open &File"), MENU_RECEIVER, SLOT(openFile()))->setShortcut(QKeySequence("Ctrl+O"));
m_menuFile->addAction(tr("Close Tab"), m_tabWidget, SLOT(closeTab()))->setShortcut(QKeySequence("Ctrl+W")); 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_actionCloseWindow = m_menuFile->addAction(QIcon::fromTheme("window-close"), tr("Close Window"), MENU_RECEIVER, SLOT(closeWindow()));
m_actionCloseWindow->setShortcut(QKeySequence("Ctrl+Shift+W")); m_actionCloseWindow->setShortcut(QKeySequence("Ctrl+Shift+W"));
m_menuFile->addSeparator(); m_menuFile->addSeparator();
m_menuFile->addAction(QIcon::fromTheme("document-save"), tr("&Save Page As..."), this, SLOT(savePage()))->setShortcut(QKeySequence("Ctrl+S")); 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"), this, SLOT(savePageScreen())); m_menuFile->addAction(tr("Save Page Screen"), MENU_RECEIVER, SLOT(savePageScreen()));
m_menuFile->addAction(QIcon::fromTheme("mail-message-new"), tr("Send Link..."), this, SLOT(sendLink())); m_menuFile->addAction(QIcon::fromTheme("mail-message-new"), tr("Send Link..."), MENU_RECEIVER, SLOT(sendLink()));
m_menuFile->addAction(QIcon::fromTheme("document-print"), tr("&Print..."), this, SLOT(printPage()))->setShortcut(QKeySequence("Ctrl+P")); 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->addSeparator(); m_menuFile->addAction(tr("Import bookmarks..."), MENU_RECEIVER, SLOT(showBookmarkImport()));
m_menuFile->addAction(tr("Import bookmarks..."), this, SLOT(showBookmarkImport()));
m_menuFile->addAction(m_actionQuit); 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 #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_actionAbout);
m_menuFile->addAction(m_actionPreferences); m_menuFile->addAction(m_actionPreferences);
#endif #endif
connect(m_menuFile, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFileMenu())); connect(m_menuFile, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowFileMenu()));
connect(m_menuFile, SIGNAL(aboutToHide()), this, SLOT(aboutToHideFileMenu())); connect(m_menuFile, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideFileMenu()));
/************* /*************
* Edit Menu * * Edit Menu *
*************/ *************/
m_menuEdit = new QMenu(tr("&Edit")); 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-undo"), tr("&Undo"), MENU_RECEIVER, 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-redo"), tr("&Redo"), MENU_RECEIVER, SLOT(editRedo()))->setShortcut(QKeySequence("Ctrl+Shift+Z"));
m_menuEdit->addSeparator(); 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-cut"), tr("&Cut"), MENU_RECEIVER, 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-copy"), tr("C&opy"), MENU_RECEIVER, 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-paste"), tr("&Paste"), MENU_RECEIVER, SLOT(editPaste()))->setShortcut(QKeySequence("Ctrl+V"));
m_menuEdit->addSeparator(); 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-select-all"), tr("Select &All"), MENU_RECEIVER, 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-find"), tr("&Find"), MENU_RECEIVER, SLOT(searchOnPage()))->setShortcut(QKeySequence("Ctrl+F"));
m_menuEdit->addSeparator(); m_menuEdit->addSeparator();
#ifdef QZ_WS_X11 #ifdef QZ_WS_X11
m_menuEdit->addAction(m_actionPreferences); m_menuEdit->addAction(m_actionPreferences);
#endif #endif
connect(m_menuEdit, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEditMenu())); connect(m_menuEdit, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowEditMenu()));
connect(m_menuEdit, SIGNAL(aboutToHide()), this, SLOT(aboutToHideEditMenu())); connect(m_menuEdit, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideEditMenu()));
/************* /*************
* View Menu * * View Menu *
*************/ *************/
m_menuView = new QMenu(tr("&View")); 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); m_actionShowToolbar->setCheckable(true);
connect(m_actionShowToolbar, SIGNAL(triggered(bool)), this, SLOT(showNavigationToolbar())); connect(m_actionShowToolbar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showNavigationToolbar()));
m_actionShowBookmarksToolbar = new QAction(tr("&Bookmarks Toolbar"), this); m_actionShowBookmarksToolbar = new QAction(tr("&Bookmarks Toolbar"), MENU_RECEIVER);
m_actionShowBookmarksToolbar->setCheckable(true); m_actionShowBookmarksToolbar->setCheckable(true);
connect(m_actionShowBookmarksToolbar, SIGNAL(triggered(bool)), this, SLOT(showBookmarksToolbar())); connect(m_actionShowBookmarksToolbar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showBookmarksToolbar()));
m_actionShowStatusbar = new QAction(tr("Sta&tus Bar"), this); m_actionShowStatusbar = new QAction(tr("Sta&tus Bar"), MENU_RECEIVER);
m_actionShowStatusbar->setCheckable(true); 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 #ifndef Q_OS_MAC
m_actionShowMenubar = new QAction(tr("&Menu Bar"), this); m_actionShowMenubar = new QAction(tr("&Menu Bar"), this);
m_actionShowMenubar->setCheckable(true); m_actionShowMenubar->setCheckable(true);
connect(m_actionShowMenubar, SIGNAL(triggered(bool)), this, SLOT(showMenubar())); connect(m_actionShowMenubar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showMenubar()));
#endif #endif
m_actionShowFullScreen = new QAction(tr("&Fullscreen"), this); m_actionShowFullScreen = new QAction(tr("&Fullscreen"), MENU_RECEIVER);
m_actionShowFullScreen->setCheckable(true); m_actionShowFullScreen->setCheckable(true);
m_actionShowFullScreen->setShortcut(QKeySequence("F11")); m_actionShowFullScreen->setShortcut(QKeySequence("F11"));
connect(m_actionShowFullScreen, SIGNAL(triggered(bool)), this, SLOT(fullScreen(bool))); connect(m_actionShowFullScreen, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(fullScreen(bool)));
m_actionStop = new QAction(qIconProvider->standardIcon(QStyle::SP_BrowserStop), tr("&Stop"), this); m_actionStop = new QAction(qIconProvider->standardIcon(QStyle::SP_BrowserStop), tr("&Stop"), MENU_RECEIVER);
connect(m_actionStop, SIGNAL(triggered()), this, SLOT(stop())); connect(m_actionStop, SIGNAL(triggered()), MENU_RECEIVER, SLOT(stop()));
m_actionStop->setShortcut(QKeySequence("Esc")); m_actionStop->setShortcut(QKeySequence("Esc"));
m_actionReload = new QAction(qIconProvider->standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), this); m_actionReload = new QAction(qIconProvider->standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), MENU_RECEIVER);
connect(m_actionReload, SIGNAL(triggered()), this, SLOT(reload())); connect(m_actionReload, SIGNAL(triggered()), MENU_RECEIVER, SLOT(reload()));
m_actionReload->setShortcut(QKeySequence("F5")); m_actionReload->setShortcut(QKeySequence("F5"));
QAction* actionEncoding = new QAction(tr("Character &Encoding"), this); QAction* actionEncoding = new QAction(tr("Character &Encoding"), MENU_RECEIVER);
m_menuEncoding = new QMenu(this); m_menuEncoding = new QMenu(this);
actionEncoding->setMenu(m_menuEncoding); actionEncoding->setMenu(m_menuEncoding);
connect(m_menuEncoding, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEncodingMenu())); connect(m_menuEncoding, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowEncodingMenu()));
m_actionCaretBrowsing = new QAction(tr("Enable &Caret Browsing"), this); m_actionCaretBrowsing = new QAction(tr("Enable &Caret Browsing"), MENU_RECEIVER);
m_actionCaretBrowsing->setVisible(false); m_actionCaretBrowsing->setVisible(false);
m_actionCaretBrowsing->setCheckable(true); m_actionCaretBrowsing->setCheckable(true);
m_actionCaretBrowsing->setShortcut(QKeySequence("F7")); 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 #if QTWEBKIT_FROM_2_3
m_actionCaretBrowsing->setVisible(true); m_actionCaretBrowsing->setVisible(true);
@ -427,40 +444,40 @@ void QupZilla::setupMenu()
m_menuView->addAction(m_actionStop); m_menuView->addAction(m_actionStop);
m_menuView->addAction(m_actionReload); m_menuView->addAction(m_actionReload);
m_menuView->addSeparator(); 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-in"), tr("Zoom &In"), MENU_RECEIVER, 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-out"), tr("Zoom &Out"), MENU_RECEIVER, 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-original"), tr("Reset"), MENU_RECEIVER, SLOT(zoomReset()))->setShortcut(QKeySequence("Ctrl+0"));
m_menuView->addSeparator(); m_menuView->addSeparator();
m_menuView->addAction(m_actionCaretBrowsing); m_menuView->addAction(m_actionCaretBrowsing);
m_menuView->addAction(actionEncoding); m_menuView->addAction(actionEncoding);
m_menuView->addSeparator(); 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->setShortcut(QKeySequence("Ctrl+U"));
m_actionPageSource->setEnabled(false); m_actionPageSource->setEnabled(false);
m_menuView->addAction(m_actionShowFullScreen); m_menuView->addAction(m_actionShowFullScreen);
connect(m_menuView, SIGNAL(aboutToShow()), this, SLOT(aboutToShowViewMenu())); connect(m_menuView, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowViewMenu()));
connect(m_menuView, SIGNAL(aboutToHide()), this, SLOT(aboutToHideViewMenu())); connect(m_menuView, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideViewMenu()));
/**************** /****************
* History Menu * * History Menu *
****************/ ****************/
m_menuHistory = new Menu(tr("Hi&story")); 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_ArrowBack), tr("&Back"), MENU_RECEIVER, 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->standardIcon(QStyle::SP_ArrowForward), tr("&Forward"), MENU_RECEIVER, 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(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"), this, SLOT(showHistoryManager()))->setShortcut(QKeySequence("Ctrl+Shift+H")); m_menuHistory->addAction(QIcon(":/icons/menu/history.png"), tr("Show &All History"), MENU_RECEIVER, SLOT(showHistoryManager()))->setShortcut(QKeySequence("Ctrl+Shift+H"));
m_menuHistory->addSeparator(); m_menuHistory->addSeparator();
connect(m_menuHistory, SIGNAL(aboutToShow()), this, SLOT(aboutToShowHistoryMenu())); connect(m_menuHistory, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowHistoryMenu()));
connect(m_menuHistory, SIGNAL(aboutToHide()), this, SLOT(aboutToHideHistoryMenu())); connect(m_menuHistory, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideHistoryMenu()));
m_menuClosedTabs = new QMenu(tr("Closed Tabs")); 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); 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); 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_menuHistoryRecent);
m_menuHistory->addMenu(m_menuHistoryMost); m_menuHistory->addMenu(m_menuHistoryMost);
@ -470,30 +487,30 @@ void QupZilla::setupMenu()
* Bookmarks Menu * * Bookmarks Menu *
******************/ ******************/
m_menuBookmarks = new Menu(tr("&Bookmarks")); 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 &This Page"), MENU_RECEIVER, SLOT(bookmarkPage()))->setShortcut(QKeySequence("Ctrl+D"));
m_menuBookmarks->addAction(tr("Bookmark &All Tabs"), this, SLOT(bookmarkAllTabs())); m_menuBookmarks->addAction(tr("Bookmark &All Tabs"), MENU_RECEIVER, SLOT(bookmarkAllTabs()));
m_menuBookmarks->addAction(qIconProvider->fromTheme("user-bookmarks"), tr("Organize &Bookmarks"), this, SLOT(showBookmarksManager()))->setShortcut(QKeySequence("Ctrl+Shift+O")); m_menuBookmarks->addAction(qIconProvider->fromTheme("user-bookmarks"), tr("Organize &Bookmarks"), MENU_RECEIVER, SLOT(showBookmarksManager()))->setShortcut(QKeySequence("Ctrl+Shift+O"));
m_menuBookmarks->addSeparator(); m_menuBookmarks->addSeparator();
connect(m_menuBookmarks, SIGNAL(aboutToShow()), this, SLOT(aboutToShowBookmarksMenu())); connect(m_menuBookmarks, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowBookmarksMenu()));
connect(m_menuBookmarks, SIGNAL(menuMiddleClicked(Menu*)), this, SLOT(loadFolderBookmarks(Menu*))); connect(m_menuBookmarks, SIGNAL(menuMiddleClicked(Menu*)), MENU_RECEIVER, SLOT(loadFolderBookmarks(Menu*)));
/************** /**************
* Tools Menu * * Tools Menu *
**************/ **************/
m_menuTools = new QMenu(tr("&Tools")); m_menuTools = new QMenu(tr("&Tools"));
m_menuTools->addAction(tr("&Web Search"), this, SLOT(webSearch()))->setShortcut(QKeySequence("Ctrl+K")); 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"), this, SLOT(showPageInfo())); m_actionPageInfo = m_menuTools->addAction(QIcon::fromTheme("dialog-information"), tr("Page &Info"), MENU_RECEIVER, SLOT(showPageInfo()));
m_actionPageInfo->setShortcut(QKeySequence("Ctrl+I")); m_actionPageInfo->setShortcut(QKeySequence("Ctrl+I"));
m_actionPageInfo->setEnabled(false); m_actionPageInfo->setEnabled(false);
m_menuTools->addSeparator(); m_menuTools->addSeparator();
m_menuTools->addAction(tr("&Download Manager"), this, SLOT(showDownloadManager()))->setShortcut(QKeySequence("Ctrl+Y")); m_menuTools->addAction(tr("&Download Manager"), MENU_RECEIVER, SLOT(showDownloadManager()))->setShortcut(QKeySequence("Ctrl+Y"));
m_menuTools->addAction(tr("&Cookies Manager"), this, SLOT(showCookieManager())); m_menuTools->addAction(tr("&Cookies Manager"), MENU_RECEIVER, SLOT(showCookieManager()));
m_menuTools->addAction(tr("&AdBlock"), AdBlockManager::instance(), SLOT(showDialog())); 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(QIcon(":/icons/menu/rss.png"), tr("RSS &Reader"), MENU_RECEIVER, SLOT(showRSSManager()));
m_menuTools->addAction(tr("Web In&spector"), this, SLOT(showWebInspector()))->setShortcut(QKeySequence("Ctrl+Shift+I")); 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"), this, SLOT(showClearPrivateData()))->setShortcut(QKeySequence("Ctrl+Shift+Del")); 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"), this); m_actionPrivateBrowsing = new QAction(tr("&Private Browsing"), MENU_RECEIVER);
m_actionPrivateBrowsing->setShortcut(QKeySequence("Ctrl+Shift+P")); m_actionPrivateBrowsing->setShortcut(QKeySequence("Ctrl+Shift+P"));
m_actionPrivateBrowsing->setVisible(!mApp->isPrivateSession()); m_actionPrivateBrowsing->setVisible(!mApp->isPrivateSession());
connect(m_actionPrivateBrowsing, SIGNAL(triggered(bool)), mApp, SLOT(startPrivateBrowsing())); connect(m_actionPrivateBrowsing, SIGNAL(triggered(bool)), mApp, SLOT(startPrivateBrowsing()));
@ -502,8 +519,8 @@ void QupZilla::setupMenu()
#if !defined(QZ_WS_X11) && !defined(Q_OS_MAC) #if !defined(QZ_WS_X11) && !defined(Q_OS_MAC)
m_menuTools->addAction(m_actionPreferences); m_menuTools->addAction(m_actionPreferences);
#endif #endif
connect(m_menuTools, SIGNAL(aboutToShow()), this, SLOT(aboutToShowToolsMenu())); connect(m_menuTools, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowToolsMenu()));
connect(m_menuTools, SIGNAL(aboutToHide()), this, SLOT(aboutToHideToolsMenu())); connect(m_menuTools, SIGNAL(aboutToHide()), MENU_RECEIVER, SLOT(aboutToHideToolsMenu()));
/************* /*************
* Help Menu * * Help Menu *
@ -517,10 +534,10 @@ void QupZilla::setupMenu()
QAction* infoAction = new QAction(tr("Information about application"), m_menuHelp); QAction* infoAction = new QAction(tr("Information about application"), m_menuHelp);
infoAction->setData(QUrl("qupzilla:about")); infoAction->setData(QUrl("qupzilla:about"));
infoAction->setShortcut(QKeySequence(QKeySequence::HelpContents)); 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(infoAction);
m_menuHelp->addAction(tr("Configuration Information"), this, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:config")); m_menuHelp->addAction(tr("Configuration Information"), MENU_RECEIVER, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:config"));
m_menuHelp->addAction(tr("Report &Issue"), this, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:reportbug")); m_menuHelp->addAction(tr("Report &Issue"), MENU_RECEIVER, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:reportbug"));
/************ /************
* Menu Bar * * Menu Bar *
@ -546,20 +563,20 @@ void QupZilla::setupMenu()
QShortcut* reloadByPassCacheAction = new QShortcut(QKeySequence("Ctrl+F5"), this); QShortcut* reloadByPassCacheAction = new QShortcut(QKeySequence("Ctrl+F5"), this);
QShortcut* reloadByPassCacheAction2 = new QShortcut(QKeySequence("Ctrl+Shift+R"), this); QShortcut* reloadByPassCacheAction2 = new QShortcut(QKeySequence("Ctrl+Shift+R"), this);
connect(reloadByPassCacheAction, SIGNAL(activated()), this, SLOT(reloadByPassCache())); connect(reloadByPassCacheAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(reloadByPassCache()));
connect(reloadByPassCacheAction2, SIGNAL(activated()), this, SLOT(reloadByPassCache())); connect(reloadByPassCacheAction2, SIGNAL(activated()), MENU_RECEIVER, SLOT(reloadByPassCache()));
QShortcut* reloadAction = new QShortcut(QKeySequence("Ctrl+R"), this); QShortcut* reloadAction = new QShortcut(QKeySequence("Ctrl+R"), this);
connect(reloadAction, SIGNAL(activated()), this, SLOT(reload())); connect(reloadAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(reload()));
QShortcut* backAction = new QShortcut(QKeySequence("Alt+Left"), this); QShortcut* backAction = new QShortcut(QKeySequence("Alt+Left"), this);
connect(backAction, SIGNAL(activated()), this, SLOT(goBack())); connect(backAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(goBack()));
QShortcut* forwardAction = new QShortcut(QKeySequence("Alt+Right"), this); QShortcut* forwardAction = new QShortcut(QKeySequence("Alt+Right"), this);
connect(forwardAction, SIGNAL(activated()), this, SLOT(goNext())); connect(forwardAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(goNext()));
QShortcut* openLocationAction = new QShortcut(QKeySequence("Alt+D"), this); QShortcut* openLocationAction = new QShortcut(QKeySequence("Alt+D"), this);
connect(openLocationAction, SIGNAL(activated()), this, SLOT(openLocation())); connect(openLocationAction, SIGNAL(activated()), MENU_RECEIVER, SLOT(openLocation()));
QShortcut* closeTabAction = new QShortcut(QKeySequence("Ctrl+F4"), this); QShortcut* closeTabAction = new QShortcut(QKeySequence("Ctrl+F4"), this);
connect(closeTabAction, SIGNAL(activated()), m_tabWidget, SLOT(closeTab())); connect(closeTabAction, SIGNAL(activated()), m_tabWidget, SLOT(closeTab()));
@ -584,6 +601,32 @@ void QupZilla::setupMenu()
#endif #endif
} }
void QupZilla::setEnabledSelectedMenuActions(QMenu* menu, const QList<int> indexList)
{
// we don't use this on other platforms
#ifdef Q_OS_MAC
if (!menu) {
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);
}
#else
Q_UNUSED(menu);
Q_UNUSED(indexList);
#endif
}
void QupZilla::loadSettings() void QupZilla::loadSettings()
{ {
Settings settings; Settings settings;
@ -771,7 +814,11 @@ void QupZilla::receiveMessage(Qz::AppMessageType mes, bool state)
void QupZilla::aboutToShowFileMenu() void QupZilla::aboutToShowFileMenu()
{ {
#ifndef Q_OS_MAC
m_actionCloseWindow->setEnabled(mApp->windowCount() > 1); m_actionCloseWindow->setEnabled(mApp->windowCount() > 1);
#else
setEnabledSelectedMenuActionsons(m_menuFile);
#endif
} }
void QupZilla::aboutToHideFileMenu() void QupZilla::aboutToHideFileMenu()
@ -781,6 +828,8 @@ void QupZilla::aboutToHideFileMenu()
void QupZilla::aboutToShowBookmarksMenu() void QupZilla::aboutToShowBookmarksMenu()
{ {
setEnabledSelectedMenuActions(m_menuBookmarks, QList<int>() << 0 << 1 << 2);
if (!m_bookmarksMenuChanged) { if (!m_bookmarksMenuChanged) {
if (m_menuBookmarksAction) { if (m_menuBookmarksAction) {
m_menuBookmarksAction->setVisible(m_bookmarksToolbar->isVisible()); m_menuBookmarksAction->setVisible(m_bookmarksToolbar->isVisible());
@ -811,8 +860,8 @@ void QupZilla::aboutToShowBookmarksMenu()
Action* act = new Action(icon, title); Action* act = new Action(icon, title);
act->setData(url); act->setData(url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl())); connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab())); connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
m_menuBookmarks->addAction(act); m_menuBookmarks->addAction(act);
} }
@ -831,8 +880,8 @@ void QupZilla::aboutToShowBookmarksMenu()
Action* act = new Action(icon, title); Action* act = new Action(icon, title);
act->setData(url); act->setData(url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl())); connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab())); connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
menuBookmarks->addAction(act); menuBookmarks->addAction(act);
} }
if (menuBookmarks->isEmpty()) { if (menuBookmarks->isEmpty()) {
@ -861,8 +910,8 @@ void QupZilla::aboutToShowBookmarksMenu()
Action* act = new Action(icon, title); Action* act = new Action(icon, title);
act->setData(url); act->setData(url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl())); connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab())); connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
tempFolder->addAction(act); tempFolder->addAction(act);
} }
if (tempFolder->isEmpty()) { if (tempFolder->isEmpty()) {
@ -885,8 +934,8 @@ void QupZilla::aboutToShowBookmarksMenu()
Action* act = new Action(icon, title); Action* act = new Action(icon, title);
act->setData(url); act->setData(url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl())); connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab())); connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
m_menuBookmarks->addAction(act); m_menuBookmarks->addAction(act);
} }
@ -895,6 +944,8 @@ void QupZilla::aboutToShowBookmarksMenu()
void QupZilla::aboutToShowHistoryMenu() void QupZilla::aboutToShowHistoryMenu()
{ {
// 2=Home, 3=Show all History, 7=Closed Tabs
setEnabledSelectedMenuActions(m_menuHistory, QList<int>() << 2 << 3 << 7);
TabbedWebView* view = weView(); TabbedWebView* view = weView();
if (!view) { if (!view) {
return; return;
@ -948,8 +999,8 @@ void QupZilla::aboutToShowHistoryRecentMenu()
Action* act = new Action(_iconForUrl(url), title); Action* act = new Action(_iconForUrl(url), title);
act->setData(url); act->setData(url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl())); connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab())); connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
m_menuHistoryRecent->addAction(act); m_menuHistoryRecent->addAction(act);
} }
@ -973,8 +1024,8 @@ void QupZilla::aboutToShowHistoryMostMenu()
Action* act = new Action(_iconForUrl(entry.url), title); Action* act = new Action(_iconForUrl(entry.url), title);
act->setData(entry.url); act->setData(entry.url);
connect(act, SIGNAL(triggered()), this, SLOT(loadActionUrl())); connect(act, SIGNAL(triggered()), MENU_RECEIVER, SLOT(loadActionUrl()));
connect(act, SIGNAL(middleClicked()), this, SLOT(loadActionUrlInNewNotSelectedTab())); connect(act, SIGNAL(middleClicked()), MENU_RECEIVER, SLOT(loadActionUrlInNewNotSelectedTab()));
m_menuHistoryMost->addAction(act); m_menuHistoryMost->addAction(act);
} }
@ -995,8 +1046,16 @@ void QupZilla::aboutToShowViewMenu()
m_actionPageSource->setEnabled(true); m_actionPageSource->setEnabled(true);
#if QTWEBKIT_FROM_2_3 #if QTWEBKIT_FROM_2_3
m_actionCaretBrowsing->setEnabled(true);
m_actionCaretBrowsing->setChecked(mApp->webSettings()->testAttribute(QWebSettings::CaretBrowsingEnabled)); m_actionCaretBrowsing->setChecked(mApp->webSettings()->testAttribute(QWebSettings::CaretBrowsingEnabled));
#endif #endif
#ifdef Q_OS_MAC
// 7,8,9=Zoom actions, 12=Character Encoding, 15=Fullscreen
setEnabledSelectedMenuActionsons(m_menuView, QList<int>()
<< 0 << 1 << 2 << 7 << 8 << 9 << 12 << 15);
// for updating reload and stop actions
updateLoadingActions();
#endif
} }
void QupZilla::aboutToHideViewMenu() void QupZilla::aboutToHideViewMenu()
@ -1016,6 +1075,9 @@ void QupZilla::aboutToShowEditMenu()
m_menuEdit->actions().at(5)->setEnabled(view->pageAction(QWebPage::Paste)->isEnabled()); m_menuEdit->actions().at(5)->setEnabled(view->pageAction(QWebPage::Paste)->isEnabled());
// Separator // Separator
m_menuEdit->actions().at(7)->setEnabled(view->pageAction(QWebPage::SelectAll)->isEnabled()); m_menuEdit->actions().at(7)->setEnabled(view->pageAction(QWebPage::SelectAll)->isEnabled());
// Find action
m_menuEdit->actions().at(8)->setEnabled(true);
} }
void QupZilla::aboutToHideEditMenu() void QupZilla::aboutToHideEditMenu()
@ -1031,6 +1093,9 @@ void QupZilla::aboutToHideEditMenu()
void QupZilla::aboutToShowToolsMenu() void QupZilla::aboutToShowToolsMenu()
{ {
m_actionPageInfo->setEnabled(true); m_actionPageInfo->setEnabled(true);
// enable all
setEnabledSelectedMenuActions(m_menuTools);
} }
void QupZilla::aboutToHideToolsMenu() void QupZilla::aboutToHideToolsMenu()
@ -1062,7 +1127,7 @@ void QupZilla::aboutToShowEncodingMenu()
QAction* action = new QAction(nameString, 0); QAction* action = new QAction(nameString, 0);
action->setData(nameString); action->setData(nameString);
action->setCheckable(true); 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) { if (activeCodec.compare(nameString, Qt::CaseInsensitive) == 0) {
action->setChecked(true); action->setChecked(true);
} }
@ -1105,9 +1170,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(); const QString &encoding = action->data().toString();
mApp->webSettings()->setDefaultTextEncoding(encoding); mApp->webSettings()->setDefaultTextEncoding(encoding);
@ -1222,23 +1291,35 @@ void QupZilla::reloadByPassCache()
weView()->triggerPageAction(QWebPage::ReloadAndBypassCache); 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()); 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); 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); m_tabWidget->addView(action->data().toUrl(), Qz::NT_NotSelectedTab);
} }
} }
@ -1939,9 +2020,13 @@ void QupZilla::disconnectObjects()
void QupZilla::closeWindow() void QupZilla::closeWindow()
{ {
#ifdef Q_OS_MAC
close();
#else
if (mApp->windowCount() > 1) { if (mApp->windowCount() > 1) {
close(); close();
} }
#endif
} }
bool QupZilla::quitApp() bool QupZilla::quitApp()

View File

@ -113,9 +113,9 @@ public slots:
void showWebInspector(bool toggle = true); void showWebInspector(bool toggle = true);
void showBookmarksToolbar(); void showBookmarksToolbar();
void loadActionUrl(); void loadActionUrl(QObject* obj = 0);
void loadActionUrlInNewTab(); void loadActionUrlInNewTab(QObject* obj = 0);
void loadActionUrlInNewNotSelectedTab(); void loadActionUrlInNewNotSelectedTab(QObject* obj = 0);
void loadFolderBookmarks(Menu* menu); void loadFolderBookmarks(Menu* menu);
void bookmarkPage(); void bookmarkPage();
@ -189,7 +189,7 @@ private slots:
void zoomOut(); void zoomOut();
void zoomReset(); void zoomReset();
void fullScreen(bool make); void fullScreen(bool make);
void changeEncoding(); void changeEncoding(QObject *obj = 0);
void triggerCaretBrowsing(); void triggerCaretBrowsing();
@ -209,6 +209,7 @@ private:
void setupUi(); void setupUi();
void setupMenu(); void setupMenu();
void setEnabledSelectedMenuActions(QMenu* menu, const QList<int> indexList = QList<int>());
void disconnectObjects(); void disconnectObjects();

View File

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

View File

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

View File

@ -0,0 +1,469 @@
/* ============================================================
* 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)
{
}
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::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()
{
if (!callSlot("aboutToShowFileMenu")) {
setDisabledSelectedMenuActions(qobject_cast<QMenu*>(sender()), QList<int>()
<< 4 << 5 << 7 << 8 << 9 << 10 << 12);
}
}
void MacMenuReceiver::aboutToHideFileMenu()
{
callSlot("aboutToHideFileMenu");
}
void MacMenuReceiver::aboutToShowHistoryMenu()
{
if (!callSlot("aboutToShowHistoryMenu")) {
setDisabledSelectedMenuActions(qobject_cast<QMenu*>(sender()), QList<int>()
<< 0 << 1 << 2 << 3 << 7);
}
}
void MacMenuReceiver::aboutToHideHistoryMenu()
{
callSlot("aboutToHideHistoryMenu");
}
void MacMenuReceiver::aboutToShowClosedTabsMenu()
{
callSlot("aboutToShowClosedTabsMenu");
}
void MacMenuReceiver::aboutToShowBookmarksMenu()
{
if (!callSlot("aboutToShowBookmarksMenu")) {
setDisabledSelectedMenuActions(qobject_cast<QMenu*>(sender()), QList<int>()
<< 0 << 1 << 2);
}
}
void MacMenuReceiver::aboutToShowViewMenu()
{
if (!callSlot("aboutToShowViewMenu")) {
setDisabledSelectedMenuActions(qobject_cast<QMenu*>(sender()));
}
}
void MacMenuReceiver::aboutToHideViewMenu()
{
callSlot("aboutToHideViewMenu");
}
void MacMenuReceiver::aboutToShowEditMenu()
{
if (!callSlot("aboutToShowEditMenu")) {
setDisabledSelectedMenuActions(qobject_cast<QMenu*>(sender()));
}
}
void MacMenuReceiver::aboutToHideEditMenu()
{
callSlot("aboutToHideEditMenu");
}
void MacMenuReceiver::aboutToShowToolsMenu()
{
if (!callSlot("aboutToShowToolsMenu")) {
setDisabledSelectedMenuActions(qobject_cast<QMenu*>(sender()), 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,123 @@
/* ============================================================
* 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 QT_QUPZILLA_EXPORT MacMenuReceiver : public QObject
{
Q_OBJECT
public:
MacMenuReceiver(QObject* parent = 0);
private:
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());
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);
};
#endif // MACMENURECEIVER_H