Skip to content
Permalink
Browse files

Introduce Session class, for now serving as container for session rel…

…ated structures
  • Loading branch information...
Emdek committed Mar 26, 2019
1 parent 7de4098 commit 8f2162862a7270e2d941f3d26b79e3e9aa6e6ce9
@@ -632,11 +632,11 @@ void Application::triggerAction(int identifier, const QVariantMap &parameters, Q
case ActionsManager::NewWindowAction:
case ActionsManager::NewWindowPrivateAction:
{
SessionMainWindow session;
Session::MainWindow session;

if (m_activeWindow)
{
const SessionMainWindow activeSession(m_activeWindow->getSession());
const Session::MainWindow activeSession(m_activeWindow->getSession());

session.splitters = activeSession.splitters;
session.hasToolBarsState = true;
@@ -1246,7 +1246,7 @@ void Application::setLocale(const QString &locale)
QLocale::setDefault(Utils::createLocale(identifier));
}

MainWindow* Application::createWindow(const QVariantMap &parameters, const SessionMainWindow &session)
MainWindow* Application::createWindow(const QVariantMap &parameters, const Session::MainWindow &session)
{
MainWindow *mainWindow(new MainWindow(parameters, session));

@@ -66,7 +66,7 @@ class Application final : public QApplication, public ActionExecutor
static void showNotification(Notification *notification);
static void handlePositionalArguments(QCommandLineParser *parser, bool forceOpen = false);
static void setHidden(bool isHidden);
static MainWindow* createWindow(const QVariantMap &parameters = {}, const SessionMainWindow &session = {});
static MainWindow* createWindow(const QVariantMap &parameters = {}, const Session::MainWindow &session = {});
static Application* getInstance();
static MainWindow* getActiveWindow();
static QObject* getFocusObject(bool ignoreMenus);
@@ -406,7 +406,7 @@ class SessionsIniToJsonMigration final : public Migration
for (int j = 1; j <= windowsAmount; ++j)
{
const int tabs(sessionData.value(QStringLiteral("%1/Properties/windows").arg(j), 0).toInt());
SessionMainWindow sessionEntry;
Session::MainWindow sessionEntry;
sessionEntry.geometry = QByteArray::fromBase64(sessionData.value(QStringLiteral("%1/Properties/geometry").arg(j), {}).toString().toLatin1());
sessionEntry.index = (sessionData.value(QStringLiteral("%1/Properties/index").arg(j), 1).toInt() - 1);

@@ -418,11 +418,11 @@ class SessionsIniToJsonMigration final : public Migration
const QStringList geometry(sessionData.value(QStringLiteral("%1/%2/Properties/geometry").arg(j).arg(k), {}).toString().split(QLatin1Char(',')));
const int historyAmount(sessionData.value(QStringLiteral("%1/%2/Properties/history").arg(j).arg(k), 0).toInt());
const int reloadTime(sessionData.value(QStringLiteral("%1/%2/Properties/reloadTime").arg(j).arg(k), -1).toInt());
SessionWindow::State windowState;
Session::Window::State windowState;
windowState.geometry = ((geometry.count() == 4) ? QRect(geometry.at(0).simplified().toInt(), geometry.at(1).simplified().toInt(), geometry.at(2).simplified().toInt(), geometry.at(3).simplified().toInt()) : QRect());
windowState.state = ((state == QLatin1String("maximized")) ? Qt::WindowMaximized : ((state == QLatin1String("minimized")) ? Qt::WindowMinimized : Qt::WindowNoState));

SessionWindow sessionWindow;
Session::Window sessionWindow;
sessionWindow.state = windowState;
sessionWindow.parentGroup = sessionData.value(QStringLiteral("%1/%2/Properties/group").arg(j).arg(k), 0).toInt();
sessionWindow.isAlwaysOnTop = sessionData.value(QStringLiteral("%1/%2/Properties/alwaysOnTop").arg(j).arg(k), false).toBool();
@@ -443,13 +443,13 @@ class SessionsIniToJsonMigration final : public Migration
sessionWindow.options[SettingsManager::Content_PageReloadTimeOption] = reloadTime;
}

SessionWindow::History history;
Session::Window::History history;
history.index = (sessionData.value(QStringLiteral("%1/%2/Properties/index").arg(j).arg(k), 1).toInt() - 1);

for (int l = 1; l <= historyAmount; ++l)
{
const QStringList position(sessionData.value(QStringLiteral("%1/%2/History/%3/position").arg(j).arg(k).arg(l), 1).toStringList());
SessionWindow::History::Entry historyEntry;
Session::Window::History::Entry historyEntry;
historyEntry.url = sessionData.value(QStringLiteral("%1/%2/History/%3/url").arg(j).arg(k).arg(l), {}).toString();
historyEntry.title = sessionData.value(QStringLiteral("%1/%2/History/%3/title").arg(j).arg(k).arg(l), {}).toString();
historyEntry.position = ((position.count() == 2) ? QPoint(position.at(0).simplified().toInt(), position.at(1).simplified().toInt()) : QPoint(0, 0));
@@ -31,13 +31,17 @@
namespace Otter
{

Session::Session(QObject *parent) : QObject(parent)
{
}

SessionsManager* SessionsManager::m_instance(nullptr);
SessionModel* SessionsManager::m_model(nullptr);
QString SessionsManager::m_sessionPath;
QString SessionsManager::m_sessionTitle;
QString SessionsManager::m_cachePath;
QString SessionsManager::m_profilePath;
QVector<SessionMainWindow> SessionsManager::m_closedWindows;
QVector<Session::MainWindow> SessionsManager::m_closedWindows;
bool SessionsManager::m_isDirty(false);
bool SessionsManager::m_isPrivate(false);
bool SessionsManager::m_isReadOnly(false);
@@ -98,7 +102,7 @@ void SessionsManager::storeClosedWindow(MainWindow *mainWindow)
return;
}

SessionMainWindow session(mainWindow->getSession());
Session::MainWindow session(mainWindow->getSession());
session.geometry = mainWindow->saveGeometry();

if (!session.windows.isEmpty())
@@ -226,7 +230,7 @@ SessionInformation SessionsManager::getSession(const QString &path)
{
const QJsonObject mainWindowObject(mainWindowsArray.at(i).toObject());
const QJsonArray windowsArray(mainWindowObject.value(QLatin1String("windows")).toArray());
SessionMainWindow sessionMainWindow;
Session::MainWindow sessionMainWindow;
sessionMainWindow.geometry = QByteArray::fromBase64(mainWindowObject.value(QLatin1String("geometry")).toString().toLatin1());
sessionMainWindow.index = (mainWindowObject.value(QLatin1String("currentIndex")).toInt(1) - 1);

@@ -235,11 +239,11 @@ SessionInformation SessionsManager::getSession(const QString &path)
const QJsonObject windowObject(windowsArray.at(j).toObject());
const QJsonArray windowHistoryArray(windowObject.value(QLatin1String("history")).toArray());
const QString state(windowObject.value(QLatin1String("state")).toString());
SessionWindow::State windowState;
Session::Window::State windowState;
windowState.geometry = JsonSettings::readRectangle(windowObject.value(QLatin1String("geometry")).toVariant());
windowState.state = ((state == QLatin1String("maximized")) ? Qt::WindowMaximized : ((state == QLatin1String("minimized")) ? Qt::WindowMinimized : Qt::WindowNoState));

SessionWindow sessionWindow;
Session::Window sessionWindow;
sessionWindow.state = windowState;
sessionWindow.history.index = (windowObject.value(QLatin1String("currentIndex")).toInt(1) - 1);
sessionWindow.isAlwaysOnTop = windowObject.value(QLatin1String("isAlwaysOnTop")).toBool(false);
@@ -261,13 +265,13 @@ SessionInformation SessionsManager::getSession(const QString &path)
}
}

SessionWindow::History history;
Session::Window::History history;

for (int k = 0; k < windowHistoryArray.count(); ++k)
{
const QJsonObject historyEntryObject(windowHistoryArray.at(k).toObject());
const QStringList position(historyEntryObject.value(QLatin1String("position")).toString().split(QLatin1Char(',')));
SessionWindow::History::Entry historyEntry;
Session::Window::History::Entry historyEntry;
historyEntry.url = historyEntryObject.value(QLatin1String("url")).toString();
historyEntry.title = historyEntryObject.value(QLatin1String("title")).toString();
historyEntry.position = ((position.count() == 2) ? QPoint(position.at(0).simplified().toInt(), position.at(1).simplified().toInt()) : QPoint(0, 0));
@@ -384,8 +388,8 @@ QStringList SessionsManager::getClosedWindows()

for (int i = 0; i < m_closedWindows.count(); ++i)
{
const SessionMainWindow window(m_closedWindows.at(i));
const QString title(window.windows.value(window.index, SessionWindow()).getTitle());
const Session::MainWindow window(m_closedWindows.at(i));
const QString title(window.windows.value(window.index, Session::Window()).getTitle());

closedWindows.append(title.isEmpty() ? tr("(Untitled)") : title);
}
@@ -646,7 +650,7 @@ bool SessionsManager::saveSession(const SessionInformation &session)

for (int i = 0; i < session.windows.count(); ++i)
{
const SessionMainWindow sessionEntry(session.windows.at(i));
const Session::MainWindow sessionEntry(session.windows.at(i));
QJsonObject mainWindowObject({{QLatin1String("currentIndex"), (sessionEntry.index + 1)}, {QLatin1String("geometry"), QString(sessionEntry.geometry.toBase64())}});
QJsonArray windowsArray;

@@ -708,7 +712,7 @@ bool SessionsManager::saveSession(const SessionInformation &session)
windowObject.insert(QLatin1String("isPinned"), true);
}

const SessionWindow::History windowHistory(sessionEntry.windows.at(j).history);
const Session::Window::History windowHistory(sessionEntry.windows.at(j).history);
QJsonArray windowHistoryArray;

for (int k = 0; k < windowHistory.entries.count(); ++k)
@@ -85,103 +85,112 @@ struct ToolBarState final
}
};

struct SessionWindow final
class MainWindow;
class SessionModel;

class Session final : public QObject
{
struct History final
public:
struct Window final
{
struct Entry final
struct History final
{
QString url;
QString title;
QIcon icon;
QDateTime time;
QPoint position;
int zoom = SettingsManager::getOption(SettingsManager::Content_DefaultZoomOption).toInt();

QString getTitle() const
struct Entry final
{
if (title.isEmpty())
QString url;
QString title;
QIcon icon;
QDateTime time;
QPoint position;
int zoom = SettingsManager::getOption(SettingsManager::Content_DefaultZoomOption).toInt();

QString getTitle() const
{
if (url == QLatin1String("about:start") && SettingsManager::getOption(SettingsManager::StartPage_EnableStartPageOption).toBool())
if (title.isEmpty())
{
return QCoreApplication::translate("Otter::SessionsManager", "Start Page");
if (url == QLatin1String("about:start") && SettingsManager::getOption(SettingsManager::StartPage_EnableStartPageOption).toBool())
{
return QCoreApplication::translate("Otter::SessionsManager", "Start Page");
}

return QCoreApplication::translate("Otter::SessionsManager", "(Unknown)");
}

return QCoreApplication::translate("Otter::SessionsManager", "(Unknown)");
return title;
}
};

QVector<Entry> entries;
int index = -1;

return title;
bool isEmpty() const
{
return (entries.isEmpty() || (entries.count() == 1 && Utils::isUrlEmpty(QUrl(entries.first().url))));
}
};

QVector<Entry> entries;
int index = -1;

bool isEmpty() const
struct State final
{
return (entries.isEmpty() || (entries.count() == 1 && Utils::isUrlEmpty(QUrl(entries.first().url))));
}
};

struct State final
{
QRect geometry;
Qt::WindowState state = ((SettingsManager::getOption(SettingsManager::Interface_NewTabOpeningActionOption).toString() == QLatin1String("maximizeTab")) ? Qt::WindowMaximized : Qt::WindowNoState);
};
QRect geometry;
Qt::WindowState state = ((SettingsManager::getOption(SettingsManager::Interface_NewTabOpeningActionOption).toString() == QLatin1String("maximizeTab")) ? Qt::WindowMaximized : Qt::WindowNoState);
};

History history;
State state;
QHash<int, QVariant> options;
int parentGroup = 0;
bool isAlwaysOnTop = false;
bool isPinned = false;
History history;
State state;
QHash<int, QVariant> options;
int parentGroup = 0;
bool isAlwaysOnTop = false;
bool isPinned = false;

QString getUrl() const
{
if (history.index >= 0 && history.index < history.entries.count())
QString getUrl() const
{
return history.entries.at(history.index).url;
}
if (history.index >= 0 && history.index < history.entries.count())
{
return history.entries.at(history.index).url;
}

return {};
}
return {};
}

QString getTitle() const
{
if (history.index >= 0 && history.index < history.entries.count())
QString getTitle() const
{
return history.entries.at(history.index).getTitle();
}
if (history.index >= 0 && history.index < history.entries.count())
{
return history.entries.at(history.index).getTitle();
}

return QCoreApplication::translate("main", "(Untitled)");
}
return QCoreApplication::translate("main", "(Untitled)");
}

int getZoom() const
{
if (history.index >= 0 && history.index < history.entries.count())
int getZoom() const
{
return history.entries.at(history.index).zoom;
if (history.index >= 0 && history.index < history.entries.count())
{
return history.entries.at(history.index).zoom;
}

return SettingsManager::getOption(SettingsManager::Content_DefaultZoomOption).toInt();
}
};

return SettingsManager::getOption(SettingsManager::Content_DefaultZoomOption).toInt();
}
};
struct MainWindow final
{
QMap<QString, QVector<int> > splitters;
QVector<Window> windows;
QVector<ToolBarState> toolBars;
QByteArray geometry;
int index = -1;
bool hasToolBarsState = false;
};

struct SessionMainWindow final
{
QMap<QString, QVector<int> > splitters;
QVector<SessionWindow> windows;
QVector<ToolBarState> toolBars;
QByteArray geometry;
int index = -1;
bool hasToolBarsState = false;
explicit Session(QObject *parent = nullptr);
};

struct SessionInformation final
{
QString path;
QString title;
QVector<SessionMainWindow> windows;
QVector<Session::MainWindow> windows;
int index = -1;
bool isClean = true;

@@ -193,16 +202,13 @@ struct SessionInformation final

struct ClosedWindow final
{
SessionWindow window;
Session::Window window;
QIcon icon;
quint64 nextWindow = 0;
quint64 previousWindow = 0;
bool isPrivate = false;
};

class MainWindow;
class SessionModel;

class SessionsManager final : public QObject
{
Q_OBJECT
@@ -264,7 +270,7 @@ class SessionsManager final : public QObject
static QString m_sessionTitle;
static QString m_cachePath;
static QString m_profilePath;
static QVector<SessionMainWindow> m_closedWindows;
static QVector<Session::MainWindow> m_closedWindows;
static bool m_isDirty;
static bool m_isPrivate;
static bool m_isReadOnly;

0 comments on commit 8f21628

Please sign in to comment.
You can’t perform that action at this time.