コード例 #1
0
ファイル: MainWindow.cpp プロジェクト: mboevink/otter
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());
}
コード例 #2
0
ファイル: Window.cpp プロジェクト: GioMac/otter
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);
	}
}
コード例 #3
0
ファイル: MainWindow.cpp プロジェクト: mboevink/otter
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();
			}
		}
	}
}