void Window::setSession(SessionWindow session) { m_session = session; setSearchEngine(session.searchEngine); setPinned(session.pinned); if (!SettingsManager::getValue(QLatin1String("Browser/DelayRestoringOfBackgroundTabs")).toBool()) { setUrl(session.getUrl(), false); } }
void Window::triggerAction(int identifier, const QVariantMap ¶meters) { switch (identifier) { case ActionsManager::CloneTabAction: if (canClone()) { m_mainWindow->addWindow(clone(true, m_mainWindow)); } break; case ActionsManager::PinTabAction: setPinned(!isPinned()); break; case ActionsManager::DetachTabAction: if (m_mainWindow->getWindowCount() > 1) { m_mainWindow->moveWindow(this); } break; case ActionsManager::SuspendTabAction: if (!m_contentsWidget || m_contentsWidget->close()) { m_session = getSession(); setContentsWidget(nullptr); } break; case ActionsManager::CloseTabAction: if (!isPinned()) { requestClose(); } break; case ActionsManager::GoAction: case ActionsManager::ActivateAddressFieldAction: case ActionsManager::ActivateSearchFieldAction: { AddressWidget *addressWidget(findAddressWidget()); SearchWidget *searchWidget(nullptr); for (int i = 0; i < m_searchWidgets.count(); ++i) { if (m_searchWidgets.at(i) && m_searchWidgets.at(i)->isVisible()) { searchWidget = m_searchWidgets.at(i); break; } } if (identifier == ActionsManager::ActivateSearchFieldAction && searchWidget) { searchWidget->activate(Qt::ShortcutFocusReason); } else if (addressWidget) { if (identifier == ActionsManager::ActivateAddressFieldAction) { addressWidget->activate(Qt::ShortcutFocusReason); } else if (identifier == ActionsManager::ActivateSearchFieldAction) { addressWidget->setText(QLatin1String("? ")); addressWidget->activate(Qt::OtherFocusReason); } else if (identifier == ActionsManager::GoAction) { addressWidget->handleUserInput(addressWidget->text(), SessionsManager::CurrentTabOpen); return; } } else if (identifier == ActionsManager::ActivateAddressFieldAction || identifier == ActionsManager::ActivateSearchFieldAction) { OpenAddressDialog dialog(this); if (identifier == ActionsManager::ActivateSearchFieldAction) { dialog.setText(QLatin1String("? ")); } connect(&dialog, SIGNAL(requestedLoadUrl(QUrl,SessionsManager::OpenHints)), this, SLOT(handleOpenUrlRequest(QUrl,SessionsManager::OpenHints))); connect(&dialog, SIGNAL(requestedOpenBookmark(BookmarksItem*,SessionsManager::OpenHints)), this, SIGNAL(requestedOpenBookmark(BookmarksItem*,SessionsManager::OpenHints))); connect(&dialog, SIGNAL(requestedSearch(QString,QString,SessionsManager::OpenHints)), this, SLOT(handleSearchRequest(QString,QString,SessionsManager::OpenHints))); dialog.exec(); } } break; case ActionsManager::PrintAction: { QPrinter printer; printer.setCreator(QStringLiteral("Otter Browser %1").arg(Application::getFullVersion())); QPrintDialog printDialog(&printer, this); printDialog.setWindowTitle(tr("Print Page")); if (printDialog.exec() != QDialog::Accepted) { break; } getContentsWidget()->print(&printer); } break; case ActionsManager::PrintPreviewAction: { QPrintPreviewDialog printPreviewDialog(this); printPreviewDialog.printer()->setCreator(QStringLiteral("Otter Browser %1").arg(Application::getFullVersion())); printPreviewDialog.setWindowFlags(printPreviewDialog.windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint); printPreviewDialog.setWindowTitle(tr("Print Preview")); if (QApplication::activeWindow()) { printPreviewDialog.resize(QApplication::activeWindow()->size()); } connect(&printPreviewDialog, SIGNAL(paintRequested(QPrinter*)), getContentsWidget(), SLOT(print(QPrinter*))); printPreviewDialog.exec(); } break; case ActionsManager::BookmarkPageAction: { const QUrl url((parameters.contains(QLatin1String("url")) ? parameters[QLatin1String("url")].toUrl() : getUrl()).adjusted(QUrl::RemovePassword)); if (url.isEmpty()) { break; } const QVector<BookmarksItem*> bookmarks(BookmarksManager::getModel()->getBookmarks(url)); if (bookmarks.isEmpty()) { BookmarkPropertiesDialog dialog(url, (parameters.contains(QLatin1String("title")) ? parameters[QLatin1String("title")].toString() : getTitle()), parameters[QLatin1String("description")].toString(), nullptr, -1, true, this); dialog.exec(); } else { BookmarkPropertiesDialog dialog(bookmarks.at(0), this); dialog.exec(); } } break; case ActionsManager::FullScreenAction: if (m_addressBar) { m_addressBar->setVisible(m_addressBar->shouldBeVisible(m_mainWindow->isFullScreen())); } if (m_contentsWidget) { m_contentsWidget->triggerAction(identifier, parameters); } break; default: getContentsWidget()->triggerAction(identifier, parameters); break; }