summaryrefslogtreecommitdiff
path: root/src/plugins/projectexplorer/session.h
blob: b40e687d648293a565e4f9432ae4376fabdde4a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include "projectexplorer_export.h"

#include <utils/id.h>
#include <utils/persistentsettings.h>

#include <QDateTime>
#include <QString>
#include <QStringList>

namespace ProjectExplorer {

class PROJECTEXPLORER_EXPORT SessionManager : public QObject
{
    Q_OBJECT

public:
    SessionManager();
    ~SessionManager() override;

    static SessionManager *instance();

    // higher level session management
    static QString activeSession();
    static QString lastSession();
    static QString startupSession();
    static QStringList sessions();
    static QDateTime sessionDateTime(const QString &session);
    static QDateTime lastActiveTime(const QString &session);

    static bool createSession(const QString &session);

    static bool confirmSessionDelete(const QStringList &sessions);
    static bool deleteSession(const QString &session);
    static void deleteSessions(const QStringList &sessions);

    static bool cloneSession(const QString &original, const QString &clone);
    static bool renameSession(const QString &original, const QString &newName);

    static Utils::FilePath sessionNameToFileName(const QString &session);

    static bool isDefaultVirgin();
    static bool isDefaultSession(const QString &session);

    // Let other plugins store persistent values within the session file
    // These are settings that are also saved and loaded at startup, and are taken over
    // to the default session when switching from implicit to explicit default session
    static void setValue(const QString &name, const QVariant &value);
    static QVariant value(const QString &name);

    // These are settings that are specific to a session and are not loaded
    // at startup and also not taken over to the default session when switching from implicit
    static void setSessionValue(const QString &name, const QVariant &value);
    static QVariant sessionValue(const QString &name, const QVariant &defaultValue = {});

    static bool loadingSession();
    static void markSessionFileDirty();

    static void sessionLoadingProgress();
    static void addSessionLoadingSteps(int steps);

    static bool loadSession(const QString &session, bool initial = false);

signals:
    void startupSessionRestored();
    void aboutToUnloadSession(QString sessionName);
    // Sent during session loading, after the values of the session are available via value() and
    // sessionValue. Use to restore values from the new session
    void aboutToLoadSession(QString sessionName);
    void sessionLoaded(QString sessionName);
    void aboutToSaveSession();

    void sessionRenamed(const QString &oldName, const QString &newName);
    void sessionRemoved(const QString &name);

private:
    static void saveActiveMode(Utils::Id mode);
};

} // namespace ProjectExplorer