Example #1
0
void WindowsManager::clearClosedWindows()
{
	m_closedWindows.clear();

	if (SessionsManager::getClosedWindows().isEmpty())
	{
		emit closedWindowsAvailableChanged(false);
	}
}
Example #2
0
void WindowsManager::closeWindow(Window *window)
{
	const int index = getWindowIndex(window);

	if (index < 0)
	{
		return;
	}

	if (window && !window->isPrivate())
	{
		const WindowHistoryInformation history = window->getContentsWidget()->getHistory();

		if (!window->isUrlEmpty() || history.entries.count() > 1)
		{
			const SessionWindow information = window->getSession();

			if (window->getType() != QLatin1String("web"))
			{
				removeStoredUrl(information.getUrl());
			}

			m_closedWindows.prepend(information);

			emit closedWindowsAvailableChanged(true);
		}
	}

	if (m_tabBar->count() == 1)
	{
		window = getWindow(0);

		if (window)
		{
			window->clear();

			return;
		}
	}

	m_tabBar->removeTab(index);

	emit windowRemoved(index);

	if (m_tabBar->count() < 1)
	{
		open();
	}
}
void WindowsManager::restore(int index)
{
	if (index < 0 || index >= m_closedWindows.count())
	{
		return;
	}

	const ClosedWindow closedWindow = m_closedWindows.at(index);
	int windowIndex = -1;

	if (closedWindow.previousWindow == 0)
	{
		windowIndex = 0;
	}
	else if (closedWindow.nextWindow == 0)
	{
		windowIndex = m_mainWindow->getTabBar()->count();
	}
	else
	{
		const int previousIndex = getWindowIndex(closedWindow.previousWindow);

		if (previousIndex >= 0)
		{
			windowIndex = (previousIndex + 1);
		}
		else
		{
			const int nextIndex = getWindowIndex(closedWindow.nextWindow);

			if (nextIndex >= 0)
			{
				windowIndex = qMax(0, (nextIndex - 1));
			}
		}
	}

	Window *window = new Window(m_isPrivate);
	window->setSession(closedWindow.window);

	m_closedWindows.removeAt(index);

	if (m_closedWindows.isEmpty() && SessionsManager::getClosedWindows().isEmpty())
	{
		emit closedWindowsAvailableChanged(false);
	}

	addWindow(window, DefaultOpen, windowIndex);
}
Example #4
0
void WindowsManager::removeStoredUrl(const QString &url)
{
	for (int i = (m_closedWindows.count() - 1); i >= 0; --i)
	{
		if (url == m_closedWindows.at(i).getUrl())
		{
			m_closedWindows.removeAt(i);

			break;
		}
	}

	if (m_closedWindows.isEmpty())
	{
		emit closedWindowsAvailableChanged(false);
	}
}
Example #5
0
void WindowsManager::restore(int index)
{
	if (index < 0 || index >= m_closedWindows.count())
	{
		return;
	}

	Window *window = new Window(m_isPrivate, NULL, m_mdi);
	window->setSession(m_closedWindows.at(index));

	m_closedWindows.removeAt(index);

	if (m_closedWindows.isEmpty() && SessionsManager::getClosedWindows().isEmpty())
	{
		emit closedWindowsAvailableChanged(false);
	}

	addWindow(window);
}
Example #6
0
void WindowsManager::closeWindow(Window *window)
{
	const int index = getWindowIndex(window);

	if (index < 0)
	{
		return;
	}

	if (window && !window->isPrivate())
	{
		const WindowHistoryInformation history = window->getContentsWidget()->getHistory();

		if (!window->isUrlEmpty() || history.entries.count() > 1)
		{
			const SessionWindow information = window->getSession();

			if (window->getType() != QLatin1String("web"))
			{
				removeStoredUrl(information.getUrl());
			}

			m_closedWindows.prepend(information);

			emit closedWindowsAvailableChanged(true);
		}
	}

	const QString lastTabClosingAction = SettingsManager::getValue(QLatin1String("TabBar/LastTabClosingAction")).toString();

	if (m_tabBar->count() == 1)
	{
		if (lastTabClosingAction == QLatin1String("closeWindow"))
		{
			ActionsManager::triggerAction(QLatin1String("CloseWindow"), m_mdi);

			return;
		}

		if (lastTabClosingAction == QLatin1String("openTab"))
		{
			window = getWindow(0);

			if (window)
			{
				window->clear();

				return;
			}
		}
		else
		{
			ActionsManager::getAction(QLatin1String("CloneTab"), m_mdi)->setEnabled(false);

			emit windowTitleChanged(QString());
		}
	}

	m_tabBar->removeTab(index);

	emit windowRemoved(index);

	if (m_tabBar->count() < 1 && lastTabClosingAction != QLatin1String("doNothing"))
	{
		open();
	}
}
void WindowsManager::handleWindowClose(Window *window)
{
	const int index = (window ? getWindowIndex(window->getIdentifier()) : -1);

	if (index < 0)
	{
		return;
	}

	if (window && !window->isPrivate())
	{
		const WindowHistoryInformation history = window->getContentsWidget()->getHistory();

		if (!Utils::isUrlEmpty(window->getUrl()) || history.entries.count() > 1)
		{
			Window *nextWindow = getWindowByIndex(index + 1);
			Window *previousWindow = ((index > 0) ? getWindowByIndex(index - 1) : NULL);

			ClosedWindow closedWindow;
			closedWindow.window = window->getSession();
			closedWindow.nextWindow = (nextWindow ? nextWindow->getIdentifier() : 0);
			closedWindow.previousWindow = (previousWindow ? previousWindow->getIdentifier() : 0);

			if (window->getType() != QLatin1String("web"))
			{
				removeStoredUrl(closedWindow.window.getUrl());
			}

			m_closedWindows.prepend(closedWindow);

			emit closedWindowsAvailableChanged(true);
		}
	}

	const QString lastTabClosingAction = SettingsManager::getValue(QLatin1String("Interface/LastTabClosingAction")).toString();

	if (m_mainWindow->getTabBar()->count() == 1)
	{
		if (lastTabClosingAction == QLatin1String("closeWindow") || (lastTabClosingAction == QLatin1String("closeWindowIfNotLast") && SessionsManager::getWindows().count() > 1))
		{
			m_mainWindow->triggerAction(ActionsManager::CloseWindowAction);

			return;
		}

		if (lastTabClosingAction == QLatin1String("openTab"))
		{
			window = getWindowByIndex(0);

			if (window)
			{
				window->clear();

				return;
			}
		}
		else
		{
			m_mainWindow->getAction(ActionsManager::CloseTabAction)->setEnabled(false);
			m_mainWindow->setCurrentWindow(NULL);

			emit windowTitleChanged(QString());
		}
	}

	m_mainWindow->getTabBar()->removeTab(index);

	Action *closePrivateTabsAction = m_mainWindow->getAction(ActionsManager::ClosePrivateTabsAction);

	if (closePrivateTabsAction->isEnabled() && getWindowCount(true) == 0)
	{
		closePrivateTabsAction->setEnabled(false);
	}

	emit windowRemoved(window->getIdentifier());

	m_windows.remove(window->getIdentifier());

	if (m_mainWindow->getTabBar()->count() < 1 && lastTabClosingAction == QLatin1String("openTab"))
	{
		open();
	}
}