Example #1
0
bool SessionsManager::deleteSession(const QString &path)
{
	const QString cleanPath = getSessionPath(path, true);

	if (QFile::exists(cleanPath))
	{
		return QFile::remove(cleanPath);
	}

	return false;
}
Example #2
0
SessionInformation SessionsManager::getSession(const QString &path)
{
	const QString sessionPath = getSessionPath(path);
	QSettings sessionData(sessionPath, QSettings::IniFormat);
	sessionData.setIniCodec("UTF-8");

	const int windows = sessionData.value(QLatin1String("Session/windows"), 0).toInt();
	SessionInformation session;
	session.path = path;
	session.title = sessionData.value(QLatin1String("Session/title"), ((path == QLatin1String("default")) ? tr("Default") : tr("(Untitled)"))).toString();
	session.index = (sessionData.value(QLatin1String("Session/index"), 1).toInt() - 1);
	session.clean = sessionData.value(QLatin1String("Session/clean"), true).toBool();

	for (int i = 1; i <= windows; ++i)
	{
		const int tabs = sessionData.value(QStringLiteral("%1/Properties/windows").arg(i), 0).toInt();
		SessionMainWindow sessionEntry;
		sessionEntry.index = (sessionData.value(QStringLiteral("%1/Properties/index").arg(i), 1).toInt() - 1);

		for (int j = 1; j <= tabs; ++j)
		{
			const int history = sessionData.value(QStringLiteral("%1/%2/Properties/history").arg(i).arg(j), 0).toInt();
			SessionWindow sessionWindow;
			sessionWindow.searchEngine = sessionData.value(QStringLiteral("%1/%2/Properties/searchEngine").arg(i).arg(j), QString()).toString();
			sessionWindow.userAgent = sessionData.value(QStringLiteral("%1/%2/Properties/userAgent").arg(i).arg(j), QString()).toString();
			sessionWindow.group = sessionData.value(QStringLiteral("%1/%2/Properties/group").arg(i).arg(j), 0).toInt();
			sessionWindow.index = (sessionData.value(QStringLiteral("%1/%2/Properties/index").arg(i).arg(j), 1).toInt() - 1);
			sessionWindow.pinned = sessionData.value(QStringLiteral("%1/%2/Properties/pinned").arg(i).arg(j), false).toBool();

			for (int k = 1; k <= history; ++k)
			{
				const QStringList position = sessionData.value(QStringLiteral("%1/%2/History/%3/position").arg(i).arg(j).arg(k), 1).toStringList();
				WindowHistoryEntry historyEntry;
				historyEntry.url = sessionData.value(QStringLiteral("%1/%2/History/%3/url").arg(i).arg(j).arg(k), 0).toString();
				historyEntry.title = sessionData.value(QStringLiteral("%1/%2/History/%3/title").arg(i).arg(j).arg(k), 1).toString();
				historyEntry.position = QPoint(position.value(0, QString::number(0)).toInt(), position.value(1, QString::number(0)).toInt());
				historyEntry.zoom = sessionData.value(QStringLiteral("%1/%2/History/%3/zoom").arg(i).arg(j).arg(k), 100).toInt();

				sessionWindow.history.append(historyEntry);
			}

			sessionEntry.windows.append(sessionWindow);
		}

		session.windows.append(sessionEntry);
	}

	return session;
}
Example #3
0
bool SessionsManager::moveSession(const QString &from, const QString &to)
{
	return QFile::rename(getSessionPath(from), getSessionPath(to));
}
Example #4
0
bool SessionsManager::saveSession(const QString &path, const QString &title, MainWindow *window, bool clean)
{
	QList<MainWindow*> windows;

	if (window)
	{
		windows.append(window);
	}
	else
	{
		windows = Application::getInstance()->getWindows();
	}

	if (windows.isEmpty())
	{
		return false;
	}

	QDir().mkpath(m_profilePath + QLatin1String("/sessions/"));

	const QString sessionPath = getSessionPath(path);
	QString sessionTitle = title;

	if (title.isEmpty())
	{
		QSettings sessionData(sessionPath, QSettings::IniFormat);
		sessionData.setIniCodec("UTF-8");

		sessionTitle = sessionData.value(QLatin1String("Session/title")).toString();;
	}

	QSaveFile file(sessionPath);

	if (!file.open(QIODevice::WriteOnly))
	{
		return false;
	}

	int tabs = 0;
	const QString defaultSearchEngine = SettingsManager::getValue(QLatin1String("Search/DefaultSearchEngine")).toString();
	const QString defaultUserAgent = SettingsManager::getValue(QLatin1String("Network/UserAgent")).toString();
	QTextStream stream(&file);
	stream.setCodec("UTF-8");
	stream << QLatin1String("[Session]\n");
	stream << Utils::formatConfigurationEntry(QLatin1String("title"), sessionTitle, true);

	if (!clean)
	{
		stream << QLatin1String("clean=false\n");
	}

	stream << QLatin1String("windows=") << windows.count() << QLatin1Char('\n');
	stream << QLatin1String("index=1\n\n");

	for (int i = 0; i < windows.count(); ++i)
	{
		const SessionMainWindow sessionEntry = windows.at(i)->getWindowsManager()->getSession();

		tabs += sessionEntry.windows.count();

		stream << QStringLiteral("[%1/Properties]\n").arg(i + 1);
		stream << QLatin1String("groups=0\n");
		stream << QLatin1String("windows=") << sessionEntry.windows.count() << QLatin1Char('\n');
		stream << QLatin1String("index=") << (sessionEntry.index + 1) << QLatin1String("\n\n");

		for (int j = 0; j < sessionEntry.windows.count(); ++j)
		{
			stream << QStringLiteral("[%1/%2/Properties]\n").arg(i + 1).arg(j + 1);

			if (sessionEntry.windows.at(j).searchEngine != defaultSearchEngine)
			{
				stream << Utils::formatConfigurationEntry(QLatin1String("searchEngine"), sessionEntry.windows.at(j).searchEngine);
			}

			if (sessionEntry.windows.at(j).userAgent != defaultUserAgent)
			{
				stream << Utils::formatConfigurationEntry(QLatin1String("userAgent"), sessionEntry.windows.at(j).userAgent);
			}

			if (sessionEntry.windows.at(j).pinned)
			{
				stream << QLatin1String("pinned=true\n");
			}

			stream << QLatin1String("history=") << sessionEntry.windows.at(j).history.count() << QLatin1Char('\n');
			stream << QLatin1String("index=") << (sessionEntry.windows.at(j).index + 1) << QLatin1String("\n\n");

			for (int k = 0; k < sessionEntry.windows.at(j).history.count(); ++k)
			{
				stream << QStringLiteral("[%1/%2/History/%3]\n").arg(i + 1).arg(j + 1).arg(k + 1);
				stream << Utils::formatConfigurationEntry(QLatin1String("url"), sessionEntry.windows.at(j).history.at(k).url, true);
				stream << Utils::formatConfigurationEntry(QLatin1String("title"), sessionEntry.windows.at(j).history.at(k).title, true);
				stream << QLatin1String("position=") << sessionEntry.windows.at(j).history.at(k).position.x() << ',' << sessionEntry.windows.at(j).history.at(k).position.y() << QLatin1Char('\n');
				stream << QLatin1String("zoom=") << sessionEntry.windows.at(j).history.at(k).zoom << QLatin1String("\n\n");
			}
		}
	}

	if (tabs == 0)
	{
		file.cancelWriting();

		return false;
	}

	return file.commit();
}
Example #5
0
bool SessionsManager::saveSession(const QString &path, const QString &title, MainWindow *window, bool isClean)
{
	if (m_isPrivate && path.isEmpty())
	{
		return false;
	}

	QList<MainWindow*> windows;

	if (window)
	{
		windows.append(window);
	}
	else
	{
		windows = Application::getInstance()->getWindows();
	}

	if (windows.isEmpty())
	{
		return false;
	}

	QDir().mkpath(m_profilePath + QLatin1String("/sessions/"));

	QSaveFile file(getSessionPath(path));

	if (!file.open(QIODevice::WriteOnly))
	{
		return false;
	}

	const QString defaultSearchEngine = SettingsManager::getValue(QLatin1String("Search/DefaultSearchEngine")).toString();
	const QString defaultUserAgent = SettingsManager::getValue(QLatin1String("Network/UserAgent")).toString();
	QTextStream stream(&file);
	stream.setCodec("UTF-8");
	stream << QLatin1String("[Session]\n");
	stream << Utils::formatConfigurationEntry(QLatin1String("title"), (title.isEmpty() ? m_sessionTitle : title), true);

	if (!isClean)
	{
		stream << QLatin1String("clean=false\n");
	}

	stream << QLatin1String("windows=") << windows.count() << QLatin1Char('\n');
	stream << QLatin1String("index=1\n\n");

	for (int i = 0; i < windows.count(); ++i)
	{
		const SessionMainWindow sessionEntry = windows.at(i)->getWindowsManager()->getSession();

		stream << QStringLiteral("[%1/Properties]\n").arg(i + 1);
		stream << Utils::formatConfigurationEntry(QLatin1String("geometry"), windows.at(i)->saveGeometry().toBase64(), true);
		stream << QLatin1String("groups=0\n");
		stream << QLatin1String("windows=") << sessionEntry.windows.count() << QLatin1Char('\n');
		stream << QLatin1String("index=") << (sessionEntry.index + 1) << QLatin1String("\n\n");

		for (int j = 0; j < sessionEntry.windows.count(); ++j)
		{
			stream << QStringLiteral("[%1/%2/Properties]\n").arg(i + 1).arg(j + 1);

			if (sessionEntry.windows.at(j).state == NormalWindowState)
			{
				stream << Utils::formatConfigurationEntry(QLatin1String("geometry"), QStringLiteral("%1,%2,%3,%4").arg(sessionEntry.windows.at(j).geometry.x()).arg(sessionEntry.windows.at(j).geometry.y()).arg(sessionEntry.windows.at(j).geometry.width()).arg(sessionEntry.windows.at(j).geometry.height()), true);
			}
			else
			{
				stream << Utils::formatConfigurationEntry(QLatin1String("state"), ((sessionEntry.windows.at(j).state == MaximizedWindowState) ? QLatin1String("maximized") : QLatin1String("minimized")));
			}

			if (sessionEntry.windows.at(j).overrides.value(QLatin1String("Search/DefaultSearchEngine"), QString()).toString() != defaultSearchEngine)
			{
				stream << Utils::formatConfigurationEntry(QLatin1String("searchEngine"), sessionEntry.windows.at(j).overrides[QLatin1String("Search/DefaultSearchEngine")].toString());
			}

			if (sessionEntry.windows.at(j).overrides.value(QLatin1String("Network/UserAgent"), QString()).toString() != defaultUserAgent)
			{
				stream << Utils::formatConfigurationEntry(QLatin1String("userAgent"), sessionEntry.windows.at(j).overrides[QLatin1String("Network/UserAgent")].toString(), true);
			}

			if (sessionEntry.windows.at(j).overrides.value(QLatin1String("Content/PageReloadTime"), -1).toInt() != -1)
			{
				stream << Utils::formatConfigurationEntry(QLatin1String("reloadTime"), QString::number(sessionEntry.windows.at(j).overrides[QLatin1String("Content/PageReloadTime")].toInt()));
			}

			if (sessionEntry.windows.at(j).isAlwaysOnTop)
			{
				stream << QLatin1String("alwaysOnTop=true\n");
			}

			if (sessionEntry.windows.at(j).isPinned)
			{
				stream << QLatin1String("pinned=true\n");
			}

			stream << QLatin1String("history=") << sessionEntry.windows.at(j).history.count() << QLatin1Char('\n');
			stream << QLatin1String("index=") << (sessionEntry.windows.at(j).historyIndex + 1) << QLatin1String("\n\n");

			for (int k = 0; k < sessionEntry.windows.at(j).history.count(); ++k)
			{
				stream << QStringLiteral("[%1/%2/History/%3]\n").arg(i + 1).arg(j + 1).arg(k + 1);
				stream << Utils::formatConfigurationEntry(QLatin1String("url"), sessionEntry.windows.at(j).history.at(k).url, true);
				stream << Utils::formatConfigurationEntry(QLatin1String("title"), sessionEntry.windows.at(j).history.at(k).title, true);
				stream << QLatin1String("position=") << sessionEntry.windows.at(j).history.at(k).position.x() << ',' << sessionEntry.windows.at(j).history.at(k).position.y() << QLatin1Char('\n');
				stream << QLatin1String("zoom=") << sessionEntry.windows.at(j).history.at(k).zoom << QLatin1String("\n\n");
			}
		}
	}

	return file.commit();
}
Example #6
0
SessionInformation SessionsManager::getSession(const QString &path)
{
	const QString sessionPath = getSessionPath(path);
	QSettings sessionData(sessionPath, QSettings::IniFormat);
	sessionData.setIniCodec("UTF-8");

	SessionInformation session;
	session.path = path;
	session.title = sessionData.value(QLatin1String("Session/title"), ((path == QLatin1String("default")) ? tr("Default") : tr("(Untitled)"))).toString();
	session.index = (sessionData.value(QLatin1String("Session/index"), 1).toInt() - 1);
	session.isClean = sessionData.value(QLatin1String("Session/clean"), true).toBool();

	const int windows = sessionData.value(QLatin1String("Session/windows"), 0).toInt();
	const int defaultZoom = SettingsManager::getValue(QLatin1String("Content/DefaultZoom")).toInt();

	for (int i = 1; i <= windows; ++i)
	{
		const int tabs = sessionData.value(QStringLiteral("%1/Properties/windows").arg(i), 0).toInt();
		SessionMainWindow sessionEntry;
		sessionEntry.geometry = QByteArray::fromBase64(sessionData.value(QStringLiteral("%1/Properties/geometry").arg(i), 1).toString().toLatin1());
		sessionEntry.index = (sessionData.value(QStringLiteral("%1/Properties/index").arg(i), 1).toInt() - 1);

		for (int j = 1; j <= tabs; ++j)
		{
			const QString state = sessionData.value(QStringLiteral("%1/%2/Properties/state").arg(i).arg(j), QString()).toString();
			const QString searchEngine = sessionData.value(QStringLiteral("%1/%2/Properties/searchEngine").arg(i).arg(j), QString()).toString();
			const QString userAgent = sessionData.value(QStringLiteral("%1/%2/Properties/userAgent").arg(i).arg(j), QString()).toString();
			const QStringList geometry = sessionData.value(QStringLiteral("%1/%2/Properties/geometry").arg(i).arg(j), QString()).toString().split(QLatin1Char(','));
			const int history = sessionData.value(QStringLiteral("%1/%2/Properties/history").arg(i).arg(j), 0).toInt();
			const int reloadTime = (sessionData.value(QStringLiteral("%1/%2/Properties/reloadTime").arg(i).arg(j), -1).toInt());
			SessionWindow sessionWindow;
			sessionWindow.geometry = ((geometry.count() == 4) ? QRect(geometry.at(0).toInt(), geometry.at(1).toInt(), geometry.at(2).toInt(), geometry.at(3).toInt()) : QRect());
			sessionWindow.state = ((state == QLatin1String("maximized")) ? MaximizedWindowState : ((state == QLatin1String("minimized")) ? MinimizedWindowState : NormalWindowState));
			sessionWindow.parentGroup = sessionData.value(QStringLiteral("%1/%2/Properties/group").arg(i).arg(j), 0).toInt();
			sessionWindow.historyIndex = (sessionData.value(QStringLiteral("%1/%2/Properties/index").arg(i).arg(j), 1).toInt() - 1);
			sessionWindow.isAlwaysOnTop = sessionData.value(QStringLiteral("%1/%2/Properties/alwaysOnTop").arg(i).arg(j), false).toBool();
			sessionWindow.isPinned = sessionData.value(QStringLiteral("%1/%2/Properties/pinned").arg(i).arg(j), false).toBool();

			if (!searchEngine.isEmpty())
			{
				sessionWindow.overrides[QLatin1String("Search/DefaultSearchEngine")] = searchEngine;
			}

			if (!userAgent.isEmpty())
			{
				sessionWindow.overrides[QLatin1String("Network/UserAgent")] = userAgent;
			}

			if (reloadTime >= 0)
			{
				sessionWindow.overrides[QLatin1String("Content/PageReloadTime")] = reloadTime;
			}

			for (int k = 1; k <= history; ++k)
			{
				const QStringList position = sessionData.value(QStringLiteral("%1/%2/History/%3/position").arg(i).arg(j).arg(k), 1).toStringList();
				WindowHistoryEntry historyEntry;
				historyEntry.url = sessionData.value(QStringLiteral("%1/%2/History/%3/url").arg(i).arg(j).arg(k), 0).toString();
				historyEntry.title = sessionData.value(QStringLiteral("%1/%2/History/%3/title").arg(i).arg(j).arg(k), 1).toString();
				historyEntry.position = QPoint(position.value(0, QString::number(0)).toInt(), position.value(1, QString::number(0)).toInt());
				historyEntry.zoom = sessionData.value(QStringLiteral("%1/%2/History/%3/zoom").arg(i).arg(j).arg(k), defaultZoom).toInt();

				sessionWindow.history.append(historyEntry);
			}

			sessionEntry.windows.append(sessionWindow);
		}

		session.windows.append(sessionEntry);
	}

	return session;
}