Falkon Develop
Cross-platform Qt-based web browser
mainmenu.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2014-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "mainmenu.h"
19#include "siteinfo.h"
20#include "tabwidget.h"
21#include "historymenu.h"
22#include "aboutdialog.h"
23#include "preferences.h"
24#include "iconprovider.h"
25#include "cookiemanager.h"
26#include "bookmarksmenu.h"
27#include "tabbedwebview.h"
28#include "browserwindow.h"
29#include "downloadmanager.h"
30#include "mainapplication.h"
31#include "clearprivatedata.h"
32#include "qzsettings.h"
33#include "pluginproxy.h"
34#include "webinspector.h"
35#include "sessionmanager.h"
36#include "statusbar.h"
37
38#include <QApplication>
39#include <QMetaObject>
40#include <QWebEnginePage>
41#include <QMenuBar>
42#include <QDesktopServices>
43
44#ifdef Q_OS_MACOS
45extern void qt_mac_set_dock_menu(QMenu* menu);
46#endif
47
48MainMenu::MainMenu(BrowserWindow* window, QWidget* parent)
49 : QMenu(parent)
50 , m_window(window)
51{
52 Q_ASSERT(m_window);
53
54 init();
55}
56
58{
59 Q_ASSERT(window);
60
61 m_window = window;
62 addActionsToWindow();
63}
64
65void MainMenu::initMenuBar(QMenuBar* menuBar) const
66{
67 menuBar->addMenu(m_menuFile);
68 menuBar->addMenu(m_menuEdit);
69 menuBar->addMenu(m_menuView);
70 menuBar->addMenu(m_menuHistory);
71 menuBar->addMenu(m_menuBookmarks);
72 menuBar->addMenu(m_menuTools);
73 menuBar->addMenu(m_menuHelp);
74}
75
76void MainMenu::initSuperMenu(QMenu* superMenu) const
77{
78 superMenu->addAction(m_actions[QSL("File/NewTab")]);
79 superMenu->addAction(m_actions[QSL("File/NewWindow")]);
80 superMenu->addAction(m_actions[QSL("File/NewPrivateWindow")]);
81 superMenu->addAction(m_actions[QSL("File/OpenFile")]);
82 if (mApp->sessionManager()) {
83 superMenu->addSeparator();
84 auto* sessionsSubmenu = new QMenu(tr("Sessions"));
85 connect(sessionsSubmenu, SIGNAL(aboutToShow()), mApp->sessionManager(), SLOT(aboutToShowSessionsMenu()));
86 superMenu->addMenu(sessionsSubmenu);
87 superMenu->addAction(m_actions[QSL("File/SessionManager")]);
88 }
89 superMenu->addSeparator();
90 superMenu->addAction(m_actions[QSL("File/SendLink")]);
91 superMenu->addAction(m_actions[QSL("File/Print")]);
92 superMenu->addSeparator();
93 superMenu->addAction(m_actions[QSL("Edit/SelectAll")]);
94 superMenu->addAction(m_actions[QSL("Edit/Find")]);
95 superMenu->addSeparator();
96 superMenu->addAction(m_menuHistory->actions().at(3));
97 superMenu->addAction(m_menuBookmarks->actions().at(2));
98 superMenu->addSeparator();
99 superMenu->addMenu(m_menuView);
100 superMenu->addMenu(m_menuHistory);
101 superMenu->addMenu(m_menuBookmarks);
102 superMenu->addMenu(m_menuTools);
103 superMenu->addMenu(m_menuHelp);
104 superMenu->addSeparator();
105 superMenu->addAction(m_actions[QSL("Standard/Preferences")]);
106 superMenu->addAction(m_actions[QSL("Standard/About")]);
107 superMenu->addSeparator();
108 superMenu->addAction(m_actions[QSL("Standard/Quit")]);
109
110 connect(superMenu, &QMenu::aboutToShow, this, &MainMenu::aboutToShowSuperMenu);
111}
112
113QAction* MainMenu::action(const QString &name) const
114{
115 Q_ASSERT(m_actions.value(name));
116
117 return m_actions.value(name);
118}
119
120void MainMenu::showAboutDialog()
121{
122 auto* dialog = new AboutDialog(m_window);
123 dialog->open();
124}
125
126void MainMenu::showPreferences()
127{
128 if (!m_preferences)
129 m_preferences = new Preferences(m_window);
130
131 m_preferences->show();
132 m_preferences->raise();
133 m_preferences->activateWindow();
134}
135
136void MainMenu::quitApplication()
137{
138 mApp->quitApplication();
139}
140
141void MainMenu::newTab()
142{
143 callSlot("addTab");
144}
145
146void MainMenu::newWindow()
147{
148 mApp->createWindow(Qz::BW_NewWindow);
149}
150
151void MainMenu::newPrivateWindow()
152{
153 mApp->startPrivateBrowsing();
154}
155
156void MainMenu::openLocation()
157{
158 callSlot("openLocation");
159}
160
161void MainMenu::openFile()
162{
163 callSlot("openFile");
164}
165
166void MainMenu::closeWindow()
167{
168 callSlot("closeWindow");
169}
170
171void MainMenu::savePageAs()
172{
173 if (m_window) {
174 QMetaObject::invokeMethod(m_window->weView(), "savePageAs");
175 }
176}
177
178void MainMenu::sendLink()
179{
180 const QUrl mailUrl = QUrl::fromEncoded(QByteArray(
181 "mailto:%20?body=" +
182 QUrl::toPercentEncoding(
183 QString::fromUtf8(m_window->weView()->url().toEncoded())) +
184 "&subject=" + QUrl::toPercentEncoding(m_window->weView()->title())));
185 QDesktopServices::openUrl(mailUrl);
186}
187
188void MainMenu::printPage()
189{
190 callSlot("printPage");
191}
192
193void MainMenu::editUndo()
194{
195 if (m_window) {
196 m_window->weView()->editUndo();
197 }
198}
199
200void MainMenu::editRedo()
201{
202 if (m_window) {
203 m_window->weView()->editRedo();
204 }
205}
206
207void MainMenu::editCut()
208{
209 if (m_window) {
210 m_window->weView()->editCut();
211 }
212}
213
214void MainMenu::editCopy()
215{
216 if (m_window) {
217 m_window->weView()->editCopy();
218 }
219}
220
221void MainMenu::editPaste()
222{
223 if (m_window) {
224 m_window->weView()->editPaste();
225 }
226}
227
228void MainMenu::editSelectAll()
229{
230 if (m_window) {
231 m_window->weView()->editSelectAll();
232 }
233}
234
235void MainMenu::editFind()
236{
237 callSlot("searchOnPage");
238}
239
240void MainMenu::showStatusBar()
241{
242 if (m_window) {
243 m_window->toggleShowStatusBar();
244 }
245}
246
247void MainMenu::stop()
248{
249 if (m_window) {
250 m_window->weView()->stop();
251 }
252}
253
254void MainMenu::reload()
255{
256 if (m_window) {
257 m_window->weView()->reload();
258 }
259}
260
261void MainMenu::zoomIn()
262{
263 if (m_window) {
264 m_window->weView()->zoomIn();
265 }
266}
267
268void MainMenu::zoomOut()
269{
270 if (m_window) {
271 m_window->weView()->zoomOut();
272 }
273}
274
275void MainMenu::zoomReset()
276{
277 if (m_window) {
278 m_window->weView()->zoomReset();
279 }
280}
281
282void MainMenu::showPageSource()
283{
284 callSlot("showSource");
285}
286
287void MainMenu::showFullScreen()
288{
289 if (m_window) {
290 m_window->toggleFullScreen();
291 }
292}
293
294void MainMenu::webSearch()
295{
296 callSlot("webSearch");
297}
298
299void MainMenu::showSiteInfo()
300{
301 if (m_window && SiteInfo::canShowSiteInfo(m_window->weView()->url())) {
302 auto* info = new SiteInfo(m_window->weView());
303 info->show();
304 }
305}
306
307void MainMenu::showDownloadManager()
308{
309 DownloadManager* m = mApp->downloadManager();
310 m->show();
311 m->raise();
312}
313
314void MainMenu::showCookieManager()
315{
316 auto* m = new CookieManager(m_window);
317 m->show();
318 m->raise();
319}
320
321void MainMenu::toggleWebInspector()
322{
323 callSlot("toggleWebInspector");
324}
325
326void MainMenu::showClearRecentHistoryDialog()
327{
328 auto* dialog = new ClearPrivateData(m_window);
329 dialog->open();
330}
331
332void MainMenu::aboutQt()
333{
334 QApplication::aboutQt();
335}
336
337void MainMenu::showInfoAboutApp()
338{
339 if (m_window) {
340 m_window->tabWidget()->addView(QUrl(QSL("falkon:about")), Qz::NT_CleanSelectedTab);
341 }
342}
343
344void MainMenu::showConfigInfo()
345{
346 if (m_window) {
347 m_window->tabWidget()->addView(QUrl(QSL("falkon:config")), Qz::NT_CleanSelectedTab);
348 }
349}
350
351void MainMenu::reportIssue()
352{
353 if (m_window) {
354 m_window->tabWidget()->addView(QUrl(QSL("falkon:reportbug")), Qz::NT_CleanSelectedTab);
355 }
356}
357
358void MainMenu::restoreClosedTab()
359{
360 if (m_window) {
361 m_window->tabWidget()->restoreClosedTab();
362 }
363}
364
365void MainMenu::aboutToShowFileMenu()
366{
367#ifndef Q_OS_MACOS
368 m_actions[QSL("File/CloseWindow")]->setEnabled(mApp->windowCount() > 1);
369#endif
370}
371
372void MainMenu::aboutToShowViewMenu()
373{
374 if (!m_window) {
375 return;
376 }
377
378 m_actions[QSL("View/ShowStatusBar")]->setChecked(m_window->statusBar()->isVisible());
379 m_actions[QSL("View/FullScreen")]->setChecked(m_window->isFullScreen());
380}
381
382void MainMenu::aboutToShowEditMenu()
383{
384 if (!m_window) {
385 return;
386 }
387
388 WebView* view = m_window->weView();
389
390 m_actions[QSL("Edit/Undo")]->setEnabled(view->pageAction(QWebEnginePage::Undo)->isEnabled());
391 m_actions[QSL("Edit/Redo")]->setEnabled(view->pageAction(QWebEnginePage::Redo)->isEnabled());
392 m_actions[QSL("Edit/Cut")]->setEnabled(view->pageAction(QWebEnginePage::Cut)->isEnabled());
393 m_actions[QSL("Edit/Copy")]->setEnabled(view->pageAction(QWebEnginePage::Copy)->isEnabled());
394 m_actions[QSL("Edit/Paste")]->setEnabled(view->pageAction(QWebEnginePage::Paste)->isEnabled());
395 m_actions[QSL("Edit/SelectAll")]->setEnabled(view->pageAction(QWebEnginePage::SelectAll)->isEnabled());
396}
397
398void MainMenu::aboutToShowToolsMenu()
399{
400 if (!m_window)
401 return;
402
403 m_actions[QSL("Tools/SiteInfo")]->setEnabled(SiteInfo::canShowSiteInfo(m_window->weView()->url()));
404
405 m_submenuExtensions->clear();
406 mApp->plugins()->populateExtensionsMenu(m_submenuExtensions);
407
408 m_submenuExtensions->menuAction()->setVisible(!m_submenuExtensions->actions().isEmpty());
409}
410
411void MainMenu::aboutToShowSuperMenu()
412{
413 if (!m_window) {
414 return;
415 }
416
417 WebView* view = m_window->weView();
418
419 m_actions[QSL("Edit/Find")]->setEnabled(true);
420 m_actions[QSL("Edit/SelectAll")]->setEnabled(view->pageAction(QWebEnginePage::SelectAll)->isEnabled());
421}
422
423void MainMenu::aboutToShowToolbarsMenu()
424{
425 auto* menu = qobject_cast<QMenu*>(sender());
426 Q_ASSERT(menu);
427
428 if (m_window) {
429 menu->clear();
430 m_window->createToolbarsMenu(menu);
431 }
432}
433
434void MainMenu::aboutToShowSidebarsMenu()
435{
436 auto* menu = qobject_cast<QMenu*>(sender());
437 Q_ASSERT(menu);
438
439 if (m_window) {
440 m_window->createSidebarsMenu(menu);
441 }
442}
443
444void MainMenu::aboutToShowEncodingMenu()
445{
446 auto* menu = qobject_cast<QMenu*>(sender());
447 Q_ASSERT(menu);
448
449 if (m_window) {
450 menu->clear();
451 m_window->createEncodingMenu(menu);
452 }
453}
454
455void MainMenu::init()
456{
457#define ADD_ACTION(name, menu, icon, trName, slot, shortcut) \
458 action = menu->addAction(icon, trName); \
459 action->setShortcut(QKeySequence(QSL(shortcut))); \
460 connect(action, SIGNAL(triggered()), this, slot); \
461 m_actions[QSL(name)] = action
462
463#define ADD_CHECKABLE_ACTION(name, menu, icon, trName, slot, shortcut) \
464 action = menu->addAction(icon, trName); \
465 action->setShortcut(QKeySequence(QSL(shortcut))); \
466 action->setCheckable(true); \
467 connect(action, SIGNAL(triggered(bool)), this, slot); \
468 m_actions[QSL(name)] = action
469
470 // Standard actions - needed on Mac to be placed correctly in "application" menu
471 auto* action = new QAction(QIcon::fromTheme(QSL("help-about")), tr("&About Falkon"), this);
472 action->setMenuRole(QAction::AboutRole);
473 connect(action, &QAction::triggered, this, &MainMenu::showAboutDialog);
474 m_actions[QSL("Standard/About")] = action;
475
476 action = new QAction(IconProvider::settingsIcon(), tr("Pr&eferences"), this);
477 action->setMenuRole(QAction::PreferencesRole);
478 action->setShortcut(QKeySequence(QKeySequence::Preferences));
479 connect(action, &QAction::triggered, this, &MainMenu::showPreferences);
480 m_actions[QSL("Standard/Preferences")] = action;
481
482 action = new QAction(QIcon::fromTheme(QSL("application-exit")), tr("Quit"), this);
483 action->setMenuRole(QAction::QuitRole);
484 // shortcut set from browserwindow
485 connect(action, &QAction::triggered, this, &MainMenu::quitApplication);
486 m_actions[QSL("Standard/Quit")] = action;
487
488 // File menu
489 m_menuFile = new QMenu(tr("&File"));
490 connect(m_menuFile, &QMenu::aboutToShow, this, &MainMenu::aboutToShowFileMenu);
491
492 ADD_ACTION("File/NewTab", m_menuFile, IconProvider::newTabIcon(), tr("New Tab"), SLOT(newTab()), "Ctrl+T");
493 ADD_ACTION("File/NewWindow", m_menuFile, IconProvider::newWindowIcon(), tr("&New Window"), SLOT(newWindow()), "Ctrl+N");
494 ADD_ACTION("File/NewPrivateWindow", m_menuFile, IconProvider::privateBrowsingIcon(), tr("New &Private Window"), SLOT(newPrivateWindow()), "Ctrl+Shift+P");
495 ADD_ACTION("File/OpenLocation", m_menuFile, QIcon::fromTheme(QSL("document-open-remote")), tr("Open Location"), SLOT(openLocation()), "Ctrl+L");
496 ADD_ACTION("File/OpenFile", m_menuFile, QIcon::fromTheme(QSL("document-open")), tr("Open &File..."), SLOT(openFile()), "Ctrl+O");
497 ADD_ACTION("File/CloseWindow", m_menuFile, QIcon::fromTheme(QSL("window-close")), tr("Close Window"), SLOT(closeWindow()), "Ctrl+Shift+W");
498 m_menuFile->addSeparator();
499
500 if (mApp->sessionManager()) {
501 auto* sessionsSubmenu = new QMenu(tr("Sessions"));
502 connect(sessionsSubmenu, SIGNAL(aboutToShow()), mApp->sessionManager(), SLOT(aboutToShowSessionsMenu()));
503 m_menuFile->addMenu(sessionsSubmenu);
504 action = new QAction(tr("Session Manager"), this);
505 connect(action, &QAction::triggered, mApp->sessionManager(), &SessionManager::openSessionManagerDialog);
506 m_actions[QSL("File/SessionManager")] = action;
507 m_menuFile->addAction(action);
508 m_menuFile->addSeparator();
509 }
510
511 ADD_ACTION("File/SavePageAs", m_menuFile, QIcon::fromTheme(QSL("document-save")), tr("&Save Page As..."), SLOT(savePageAs()), "Ctrl+S");
512 ADD_ACTION("File/SendLink", m_menuFile, QIcon::fromTheme(QSL("mail-message-new")), tr("Send Link..."), SLOT(sendLink()), "");
513 ADD_ACTION("File/Print", m_menuFile, QIcon::fromTheme(QSL("document-print")), tr("&Print..."), SLOT(printPage()), "Ctrl+P");
514 m_menuFile->addSeparator();
515 m_menuFile->addAction(m_actions[QSL("Standard/Quit")]);
516
517 // Edit menu
518 m_menuEdit = new QMenu(tr("&Edit"));
519 connect(m_menuEdit, &QMenu::aboutToShow, this, &MainMenu::aboutToShowEditMenu);
520
521 ADD_ACTION("Edit/Undo", m_menuEdit, QIcon::fromTheme(QSL("edit-undo")), tr("&Undo"), SLOT(editUndo()), "Ctrl+Z");
522 action->setShortcutContext(Qt::WidgetShortcut);
523 ADD_ACTION("Edit/Redo", m_menuEdit, QIcon::fromTheme(QSL("edit-redo")), tr("&Redo"), SLOT(editRedo()), "Ctrl+Shift+Z");
524 action->setShortcutContext(Qt::WidgetShortcut);
525 m_menuEdit->addSeparator();
526 ADD_ACTION("Edit/Cut", m_menuEdit, QIcon::fromTheme(QSL("edit-cut")), tr("&Cut"), SLOT(editCut()), "Ctrl+X");
527 action->setShortcutContext(Qt::WidgetShortcut);
528 ADD_ACTION("Edit/Copy", m_menuEdit, QIcon::fromTheme(QSL("edit-copy")), tr("C&opy"), SLOT(editCopy()), "Ctrl+C");
529 action->setShortcutContext(Qt::WidgetShortcut);
530 ADD_ACTION("Edit/Paste", m_menuEdit, QIcon::fromTheme(QSL("edit-paste")), tr("&Paste"), SLOT(editPaste()), "Ctrl+V");
531 action->setShortcutContext(Qt::WidgetShortcut);
532 m_menuEdit->addSeparator();
533 ADD_ACTION("Edit/SelectAll", m_menuEdit, QIcon::fromTheme(QSL("edit-select-all")), tr("Select &All"), SLOT(editSelectAll()), "Ctrl+A");
534 action->setShortcutContext(Qt::WidgetShortcut);
535 ADD_ACTION("Edit/Find", m_menuEdit, QIcon::fromTheme(QSL("edit-find")), tr("&Find"), SLOT(editFind()), "Ctrl+F");
536 action->setShortcutContext(Qt::WidgetShortcut);
537 m_menuEdit->addSeparator();
538
539 // View menu
540 m_menuView = new QMenu(tr("&View"));
541 connect(m_menuView, &QMenu::aboutToShow, this, &MainMenu::aboutToShowViewMenu);
542
543 auto* toolbarsMenu = new QMenu(tr("Toolbars"));
544 connect(toolbarsMenu, &QMenu::aboutToShow, this, &MainMenu::aboutToShowToolbarsMenu);
545 auto* sidebarMenu = new QMenu(tr("Sidebar"));
546 connect(sidebarMenu, &QMenu::aboutToShow, this, &MainMenu::aboutToShowSidebarsMenu);
547 auto* encodingMenu = new QMenu(tr("Character &Encoding"));
548 connect(encodingMenu, &QMenu::aboutToShow, this, &MainMenu::aboutToShowEncodingMenu);
549
550 // Create menus to make shortcuts available even before first showing the menu
551 m_window->createToolbarsMenu(toolbarsMenu);
552 m_window->createSidebarsMenu(sidebarMenu);
553
554 m_menuView->addMenu(toolbarsMenu);
555 m_menuView->addMenu(sidebarMenu);
556 ADD_CHECKABLE_ACTION("View/ShowStatusBar", m_menuView, QIcon(), tr("Sta&tus Bar"), SLOT(showStatusBar()), "");
557 m_menuView->addSeparator();
558 ADD_ACTION("View/Stop", m_menuView, QIcon::fromTheme(QSL("process-stop")), tr("&Stop"), SLOT(stop()), "Esc");
559 ADD_ACTION("View/Reload", m_menuView, QIcon::fromTheme(QSL("view-refresh")), tr("&Reload"), SLOT(reload()), "F5");
560 m_menuView->addSeparator();
561 ADD_ACTION("View/ZoomIn", m_menuView, QIcon::fromTheme(QSL("zoom-in")), tr("Zoom &In"), SLOT(zoomIn()), "Ctrl++");
562 ADD_ACTION("View/ZoomOut", m_menuView, QIcon::fromTheme(QSL("zoom-out")), tr("Zoom &Out"), SLOT(zoomOut()), "Ctrl+-");
563 ADD_ACTION("View/ZoomReset", m_menuView, QIcon::fromTheme(QSL("zoom-original")), tr("Reset"), SLOT(zoomReset()), "Ctrl+0");
564 m_menuView->addSeparator();
565 m_menuView->addMenu(encodingMenu);
566 m_menuView->addSeparator();
567 ADD_ACTION("View/PageSource", m_menuView, QIcon::fromTheme(QSL("text-html")), tr("&Page Source"), SLOT(showPageSource()), "Ctrl+U");
568 action->setShortcutContext(Qt::WidgetShortcut);
569 ADD_CHECKABLE_ACTION("View/FullScreen", m_menuView, QIcon::fromTheme(QSL("view-fullscreen")), tr("&FullScreen"), SLOT(showFullScreen()), "F11");
570
571 // Tools menu
572 m_menuTools = new QMenu(tr("&Tools"));
573 connect(m_menuTools, &QMenu::aboutToShow, this, &MainMenu::aboutToShowToolsMenu);
574
575 ADD_ACTION("Tools/WebSearch", m_menuTools, QIcon::fromTheme(QSL("edit-find")), tr("&Web Search"), SLOT(webSearch()), "Ctrl+K");
576 ADD_ACTION("Tools/SiteInfo", m_menuTools, QIcon::fromTheme(QSL("dialog-information")), tr("Site &Info"), SLOT(showSiteInfo()), "Ctrl+I");
577 action->setShortcutContext(Qt::WidgetShortcut);
578 m_menuTools->addSeparator();
579 ADD_ACTION("Tools/DownloadManager", m_menuTools, QIcon::fromTheme(QSL("download")), tr("&Download Manager"), SLOT(showDownloadManager()), "Ctrl+Y");
580 ADD_ACTION("Tools/CookiesManager", m_menuTools, QIcon(), tr("&Cookies Manager"), SLOT(showCookieManager()), "");
581 ADD_ACTION("Tools/WebInspector", m_menuTools, QIcon(), tr("Web In&spector"), SLOT(toggleWebInspector()), "Ctrl+Shift+I");
582 ADD_ACTION("Tools/ClearRecentHistory", m_menuTools, QIcon::fromTheme(QSL("edit-clear")), tr("Clear Recent &History"), SLOT(showClearRecentHistoryDialog()), "Ctrl+Shift+Del");
583
585 m_actions.value(QSL("Tools/WebInspector"))->setVisible(false);
586
587 m_submenuExtensions = new QMenu(tr("&Extensions"));
588 m_submenuExtensions->menuAction()->setVisible(false);
589 m_menuTools->addMenu(m_submenuExtensions);
590 m_menuTools->addSeparator();
591
592 // Help menu
593 m_menuHelp = new QMenu(tr("&Help"));
594
595#ifndef Q_OS_MACOS
596 ADD_ACTION("Help/AboutQt", m_menuHelp, QIcon(), tr("About &Qt"), SLOT(aboutQt()), "");
597 m_menuHelp->addAction(m_actions[QSL("Standard/About")]);
598 m_menuHelp->addSeparator();
599#endif
600
601 ADD_ACTION("Help/InfoAboutApp", m_menuHelp, QIcon::fromTheme(QSL("help-contents")), tr("Information about application"), SLOT(showInfoAboutApp()), "");
602 ADD_ACTION("Help/ConfigInfo", m_menuHelp, QIcon(), tr("Configuration Information"), SLOT(showConfigInfo()), "");
603 ADD_ACTION("Help/ReportIssue", m_menuHelp, QIcon(), tr("Report &Issue"), SLOT(reportIssue()), "");
604
605 m_actions[QSL("Help/InfoAboutApp")]->setShortcut(QKeySequence(QKeySequence::HelpContents));
606
607 // History menu
608 m_menuHistory = new HistoryMenu();
609 m_menuHistory->setMainWindow(m_window);
610
611 // Bookmarks menu
612 m_menuBookmarks = new BookmarksMenu();
613 m_menuBookmarks->setMainWindow(m_window);
614
615 // Other actions
616 action = new QAction(QIcon::fromTheme(QSL("user-trash")), tr("Restore &Closed Tab"), this);
617 action->setShortcut(QKeySequence(QSL("Ctrl+Shift+T")));
618 connect(action, &QAction::triggered, this, &MainMenu::restoreClosedTab);
619 m_actions[QSL("Other/RestoreClosedTab")] = action;
620
621#ifdef Q_OS_MACOS
622 m_actions[QSL("View/FullScreen")]->setShortcut(QKeySequence(QSL("Ctrl+Meta+F")));
623
624 // Add standard actions to File Menu (as it won't be ever cleared) and Mac menubar should move them to "Application" menu
625 m_menuFile->addAction(m_actions[QSL("Standard/About")]);
626 m_menuFile->addAction(m_actions[QSL("Standard/Preferences")]);
627
628 // Prevent ConfigInfo action to be detected as "Preferences..." action in Mac menubar
629 m_actions[QSL("Help/ConfigInfo")]->setMenuRole(QAction::NoRole);
630
631 // Create Dock menu
632 QMenu* dockMenu = new QMenu(0);
633 dockMenu->addAction(m_actions[QSL("File/NewTab")]);
634 dockMenu->addAction(m_actions[QSL("File/NewWindow")]);
635 dockMenu->addAction(m_actions[QSL("File/NewPrivateWindow")]);
636 qt_mac_set_dock_menu(dockMenu);
637#endif
638
639#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
640 m_menuEdit->addAction(m_actions[QSL("Standard/Preferences")]);
641#elif !defined(Q_OS_MACOS)
642 m_menuTools->addAction(m_actions[QSL("Standard/Preferences")]);
643#endif
644
645 addActionsToWindow();
646}
647
648void MainMenu::addActionsToWindow()
649{
650 // Make shortcuts available even in fullscreen (hidden menu)
651
652 QList<QAction*> actions;
653 actions << m_menuFile->actions();
654 actions << m_menuEdit->actions();
655 actions << m_menuView->actions();
656 actions << m_menuTools->actions();
657 actions << m_menuHelp->actions();
658 actions << m_menuHistory->actions();
659 actions << m_menuBookmarks->actions();
660 actions << m_actions[QSL("Other/RestoreClosedTab")];
661
662 for (int i = 0; i < actions.size(); ++i) {
663 QAction* action = actions.at(i);
664 if (action->menu()) {
665 actions += action->menu()->actions();
666 }
667 m_window->addAction(action);
668 }
669}
670
671void MainMenu::callSlot(const char* slot)
672{
673 if (m_window) {
674 QMetaObject::invokeMethod(m_window, slot);
675 }
676}
void setMainWindow(BrowserWindow *window)
void setMainWindow(BrowserWindow *window)
Definition: historymenu.cpp:40
static QIcon settingsIcon()
static QIcon privateBrowsingIcon()
static QIcon newWindowIcon()
static QIcon newTabIcon()
MainMenu(BrowserWindow *window, QWidget *parent=nullptr)
Definition: mainmenu.cpp:48
QAction * action(const QString &name) const
Definition: mainmenu.cpp:113
void initSuperMenu(QMenu *superMenu) const
Definition: mainmenu.cpp:76
void setWindow(BrowserWindow *window)
Definition: mainmenu.cpp:57
void initMenuBar(QMenuBar *menuBar) const
Definition: mainmenu.cpp:65
void openSessionManagerDialog()
static bool canShowSiteInfo(const QUrl &url)
Definition: siteinfo.cpp:162
static bool isEnabled()
#define mApp
#define ADD_ACTION(name, menu, icon, trName, slot, shortcut)
#define ADD_CHECKABLE_ACTION(name, menu, icon, trName, slot, shortcut)
@ BW_NewWindow
Definition: qzcommon.h:67
@ NT_CleanSelectedTab
Definition: qzcommon.h:107
i
Definition: i18n.py:23
#define QSL(x)
Definition: qzcommon.h:40