void MainWindow::menuClosedWindowsAboutToShow() { m_closedWindowsMenu->clear(); m_ui->menuClosedWindows->clear(); m_ui->menuClosedWindows->addAction(Utils::getIcon(QLatin1String("edit-clear")), tr("Clear"), this, SLOT(actionClearClosedWindows()))->setData(0); m_ui->menuClosedWindows->addSeparator(); const QStringList windows = SessionsManager::getClosedWindows(); if (!windows.isEmpty()) { for (int i = 0; i < windows.count(); ++i) { m_ui->menuClosedWindows->addAction(Utils::elideText(tr("Window - %1").arg(windows.at(i)), m_ui->menuClosedWindows), this, SLOT(actionRestoreClosedWindow()))->setData(-(i + 1)); } m_ui->menuClosedWindows->addSeparator(); } WebBackend *backend = WebBackendsManager::getBackend(); const QList<SessionWindow> tabs = m_windowsManager->getClosedWindows(); for (int i = 0; i < tabs.count(); ++i) { m_ui->menuClosedWindows->addAction(backend->getIconForUrl(QUrl(tabs.at(i).getUrl())), Utils::elideText(tabs.at(i).getTitle(), m_ui->menuClosedWindows), this, SLOT(actionRestoreClosedWindow()))->setData(i + 1); } m_closedWindowsMenu->addActions(m_ui->menuClosedWindows->actions()); }
void MainWindow::actionAboutApplication() { WebBackend *backend = WebBackendsManager::getBackend(); QString about = tr("<b>Otter %1</b><br>Web browser controlled by the user, not vice-versa.").arg(QApplication::applicationVersion()); about.append(QLatin1String("<br><br>") + tr("Web backend: %1 %2.").arg(backend->getTitle()).arg(backend->getEngineVersion()) + QLatin1String("<br><br>")); if (QSslSocket::supportsSsl()) { about.append(tr("SSL library version: %1.").arg(QSslSocket::sslLibraryVersionString())); } else { about.append(tr("SSL library not available.")); } QMessageBox::about(this, QLatin1String("Otter"), about); }
void Window::updateGoForwardMenu() { if (!m_ui->forwardButton->menu() || !m_contentsWidget) { return; } m_ui->forwardButton->menu()->clear(); WebBackend *backend = WebBackendsManager::getBackend(); const WindowHistoryInformation history = m_contentsWidget->getHistory(); for (int i = (history.index + 1); i < history.entries.count(); ++i) { QString title = history.entries.at(i).title; m_ui->forwardButton->menu()->addAction(backend->getIconForUrl(QUrl(history.entries.at(i).url)), (title.isEmpty() ? tr("(Untitled)") : title.replace(QLatin1Char('&'), QLatin1String("&&"))))->setData(i); } }
void MainWindow::menuBookmarksAboutToShow() { QMenu *menu = qobject_cast<QMenu*>(sender()); if (!menu || !menu->menuAction()) { return; } menu->setObjectName(QLatin1String("bookmarks")); menu->installEventFilter(this); const int folder = menu->menuAction()->data().toInt(); if ((folder == 0 && menu->actions().count() == 3) || (folder != 0 && menu->actions().isEmpty())) { WebBackend *backend = WebBackendsManager::getBackend(); const QList<BookmarkInformation*> bookmarks = BookmarksManager::getFolder(folder); if (folder != 0 && bookmarks.count() > 1) { QAction *openAllAction = menu->addAction(Utils::getIcon(QLatin1String("document-open-folder")), tr("Open All")); openAllAction->setData(folder); connect(openAllAction, SIGNAL(triggered()), this, SLOT(actionOpenBookmarkFolder())); menu->addSeparator(); } for (int i = 0; i < bookmarks.count(); ++i) { if (bookmarks.at(i)->type == FolderBookmark || bookmarks.at(i)->type == UrlBookmark) { QAction *action = menu->addAction(((bookmarks.at(i)->type == FolderBookmark) ? Utils::getIcon(QLatin1String("inode-directory")) : backend->getIconForUrl(QUrl(bookmarks.at(i)->url))), (bookmarks.at(i)->title.isEmpty() ? tr("(Untitled)") : Utils::elideText(QString(bookmarks.at(i)->title).replace(QLatin1Char('&'), QLatin1String("&&")), menu))); action->setToolTip(bookmarks.at(i)->description); if (bookmarks.at(i)->type == FolderBookmark) { action->setData(bookmarks.at(i)->identifier); if (!bookmarks.at(i)->children.isEmpty()) { action->setMenu(new QMenu()); connect(action->menu(), SIGNAL(aboutToShow()), this, SLOT(menuBookmarksAboutToShow())); } } else { action->setData(bookmarks.at(i)->url); connect(action, SIGNAL(triggered()), this, SLOT(actionOpenBookmark())); } } else { menu->addSeparator(); } } } }
void MainWindow::triggerAction(int identifier, const QVariantMap ¶meters) { switch (identifier) { case ActionsManager::NewWindowAction: emit requestedNewWindow(false, false, QUrl()); break; case ActionsManager::NewWindowPrivateAction: emit requestedNewWindow(true, false, QUrl()); break; case ActionsManager::OpenAction: { const QUrl url = QFileDialog::getOpenFileUrl(this, tr("Open File")); if (url.isValid()) { m_windowsManager->open(url); } } break; case ActionsManager::ClosePrivateTabsPanicAction: if (SessionsManager::isPrivate()) { Application::getInstance()->close(); } else { const QList<MainWindow*> windows = SessionsManager::getWindows(); for (int i = 0; i < windows.count(); ++i) { if (windows[i]->getWindowsManager()->isPrivate()) { windows[i]->close(); } else { windows[i]->getWindowsManager()->triggerAction(ActionsManager::ClosePrivateTabsAction); } } } break; case ActionsManager::MaximizeTabAction: case ActionsManager::MinimizeTabAction: case ActionsManager::RestoreTabAction: case ActionsManager::AlwaysOnTopTabAction: case ActionsManager::MaximizeAllAction: case ActionsManager::MinimizeAllAction: case ActionsManager::RestoreAllAction: case ActionsManager::CascadeAllAction: case ActionsManager::TileAllAction: m_workspace->triggerAction(identifier, parameters); break; case ActionsManager::CloseWindowAction: close(); break; case ActionsManager::SessionsAction: { SessionsManagerDialog dialog(this); dialog.exec(); } break; case ActionsManager::SaveSessionAction: { SaveSessionDialog dialog(this); dialog.exec(); } break; case ActionsManager::GoToPageAction: { OpenAddressDialog dialog(this); connect(&dialog, SIGNAL(requestedLoadUrl(QUrl,WindowsManager::OpenHints)), m_windowsManager, SLOT(open(QUrl,WindowsManager::OpenHints))); connect(&dialog, SIGNAL(requestedOpenBookmark(BookmarksItem*,WindowsManager::OpenHints)), m_windowsManager, SLOT(open(BookmarksItem*,WindowsManager::OpenHints))); connect(&dialog, SIGNAL(requestedSearch(QString,QString,WindowsManager::OpenHints)), m_windowsManager, SLOT(search(QString,QString,WindowsManager::OpenHints))); dialog.exec(); } break; case ActionsManager::GoToHomePageAction: { const QString homePage = SettingsManager::getValue(QLatin1String("Browser/HomePage")).toString(); if (!homePage.isEmpty()) { m_windowsManager->open(QUrl(homePage), WindowsManager::CurrentTabOpen); } } break; case ActionsManager::BookmarksAction: { const QUrl url(QLatin1String("about:bookmarks")); if (!SessionsManager::hasUrl(url, true)) { m_windowsManager->open(url); } } break; case ActionsManager::AddBookmarkAction: addBookmark(QUrl(), QString(), QString(), true); break; case ActionsManager::QuickBookmarkAccessAction: { OpenBookmarkDialog dialog(this); connect(&dialog, SIGNAL(requestedOpenBookmark(BookmarksItem*)), m_windowsManager, SLOT(open(BookmarksItem*))); dialog.exec(); } break; case ActionsManager::WorkOfflineAction: SettingsManager::setValue(QLatin1String("Network/WorkOffline"), parameters); break; case ActionsManager::FullScreenAction: if (isFullScreen()) { restoreWindowState(); } else { storeWindowState(); showFullScreen(); } break; case ActionsManager::ShowTabSwitcherAction: if (!m_tabSwitcher) { m_tabSwitcher = new TabSwitcherWidget(m_windowsManager, this); } m_tabSwitcher->raise(); m_tabSwitcher->resize(size()); m_tabSwitcher->show(TabSwitcherWidget::ActionReason); break; case ActionsManager::ShowMenuBarAction: { ToolBarDefinition definition = ToolBarsManager::getToolBarDefinition(ToolBarsManager::MenuBar); definition.visibility = (parameters.value(QLatin1String("isChecked")).toBool() ? AlwaysVisibleToolBar : AlwaysHiddenToolBar); ToolBarsManager::setToolBar(definition); } break; case ActionsManager::ShowTabBarAction: { ToolBarDefinition definition = ToolBarsManager::getToolBarDefinition(ToolBarsManager::TabBar); definition.visibility = (parameters.value(QLatin1String("isChecked")).toBool() ? AlwaysVisibleToolBar : AlwaysHiddenToolBar); ToolBarsManager::setToolBar(definition); } break; case ActionsManager::ShowSidebarAction: SettingsManager::setValue(QLatin1String("Sidebar/Visible"), parameters.value(QLatin1String("isChecked")).toBool()); break; case ActionsManager::OpenPanelAction: if (m_sidebar && m_sidebar->getCurrentPanel()) { m_windowsManager->open(m_sidebar->getCurrentPanel()->getUrl(), WindowsManager::NewTabOpen); } break; case ActionsManager::ClosePanelAction: SettingsManager::setValue(QLatin1String("Sidebar/CurrentPanel"), QString()); break; case ActionsManager::ShowErrorConsoleAction: m_ui->consoleDockWidget->setVisible(parameters.value(QLatin1String("isChecked")).toBool()); break; case ActionsManager::LockToolBarsAction: ToolBarsManager::setToolBarsLocked(parameters.value(QLatin1String("isChecked")).toBool()); break; case ActionsManager::ContentBlockingAction: { ContentBlockingDialog dialog(this); dialog.exec(); } break; case ActionsManager::HistoryAction: { const QUrl url(QLatin1String("about:history")); if (!SessionsManager::hasUrl(url, true)) { m_windowsManager->open(url); } } break; case ActionsManager::ClearHistoryAction: { ClearHistoryDialog dialog(SettingsManager::getValue(QLatin1String("History/ManualClearOptions")).toStringList(), false, this); dialog.exec(); } break; case ActionsManager::NotesAction: { const QUrl url(QLatin1String("about:notes")); if (!SessionsManager::hasUrl(url, true)) { m_windowsManager->open(url); } } break; case ActionsManager::TransfersAction: { const QUrl url(QLatin1String("about:transfers")); if (!SessionsManager::hasUrl(url, true)) { m_windowsManager->open(url); } } break; case ActionsManager::CookiesAction: { const QUrl url(QLatin1String("about:cookies")); if (!SessionsManager::hasUrl(url, true)) { m_windowsManager->open(url); } } break; case ActionsManager::PreferencesAction: { PreferencesDialog dialog(QLatin1String("general"), this); dialog.exec(); } break; case ActionsManager::SwitchApplicationLanguageAction: { LocaleDialog dialog(this); dialog.exec(); } break; case ActionsManager::CheckForUpdatesAction: { UpdateCheckerDialog *dialog = new UpdateCheckerDialog(this); dialog->show(); } break; case ActionsManager::DiagnosticReportAction: { ReportDialog *dialog = new ReportDialog(this); dialog->show(); } break; case ActionsManager::AboutApplicationAction: { WebBackend *backend = AddonsManager::getWebBackend(); QString about = tr("<b>Otter %1</b><br>Web browser controlled by the user, not vice-versa.").arg(Application::getInstance()->getFullVersion()); about.append(QLatin1String("<br><br>") + tr("Web backend: %1 %2.").arg(backend->getTitle()).arg(backend->getEngineVersion()) + QLatin1String("<br><br>")); if (QSslSocket::supportsSsl()) { about.append(tr("SSL library version: %1.").arg(QSslSocket::sslLibraryVersionString())); } else { about.append(tr("SSL library not available.")); } QMessageBox::about(this, QLatin1String("Otter"), about); } break; case ActionsManager::AboutQtAction: Application::getInstance()->aboutQt(); break; case ActionsManager::ExitAction: Application::getInstance()->close(); break; default: m_windowsManager->triggerAction(identifier, parameters); break; } }