1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "projectexplorer_export.h" 29 30 #include <utils/id.h> 31 #include <utils/persistentsettings.h> 32 33 #include <QDateTime> 34 #include <QString> 35 #include <QStringList> 36 37 namespace Core { class IEditor; } 38 39 namespace ProjectExplorer { 40 41 class Project; 42 class Target; 43 class BuildConfiguration; 44 class BuildSystem; 45 class DeployConfiguration; 46 class RunConfiguration; 47 48 enum class SetActive { Cascade, NoCascade }; 49 50 class PROJECTEXPLORER_EXPORT SessionManager : public QObject 51 { 52 Q_OBJECT 53 54 public: 55 explicit SessionManager(QObject *parent = nullptr); 56 ~SessionManager() override; 57 58 static SessionManager *instance(); 59 60 // higher level session management 61 static QString activeSession(); 62 static QString lastSession(); 63 static QString startupSession(); 64 static QStringList sessions(); 65 static QDateTime sessionDateTime(const QString &session); 66 67 static bool createSession(const QString &session); 68 69 static bool confirmSessionDelete(const QStringList &sessions); 70 static bool deleteSession(const QString &session); 71 static void deleteSessions(const QStringList &sessions); 72 73 static bool cloneSession(const QString &original, const QString &clone); 74 static bool renameSession(const QString &original, const QString &newName); 75 76 static bool loadSession(const QString &session, bool initial = false); 77 78 static bool save(); 79 static void closeAllProjects(); 80 81 static void addProject(Project *project); 82 static void removeProject(Project *project); 83 static void removeProjects(const QList<Project *> &remove); 84 85 static void setStartupProject(Project *startupProject); 86 87 static QList<Project *> dependencies(const Project *project); 88 static bool hasDependency(const Project *project, const Project *depProject); 89 static bool canAddDependency(const Project *project, const Project *depProject); 90 static bool addDependency(Project *project, Project *depProject); 91 static void removeDependency(Project *project, Project *depProject); 92 93 static bool isProjectConfigurationCascading(); 94 static void setProjectConfigurationCascading(bool b); 95 96 static void setActiveTarget(Project *p, Target *t, SetActive cascade); 97 static void setActiveBuildConfiguration(Target *t, BuildConfiguration *bc, SetActive cascade); 98 static void setActiveDeployConfiguration(Target *t, DeployConfiguration *dc, SetActive cascade); 99 100 static Utils::FilePath sessionNameToFileName(const QString &session); 101 static Project *startupProject(); 102 static Target *startupTarget(); 103 static BuildSystem *startupBuildSystem(); 104 static RunConfiguration *startupRunConfiguration(); 105 106 static const QList<Project *> projects(); 107 static bool hasProjects(); 108 static bool hasProject(Project *p); 109 110 static bool isDefaultVirgin(); 111 static bool isDefaultSession(const QString &session); 112 113 // Let other plugins store persistent values within the session file 114 static void setValue(const QString &name, const QVariant &value); 115 static QVariant value(const QString &name); 116 117 // NBS rewrite projectOrder (dependency management) 118 static QList<Project *> projectOrder(const Project *project = nullptr); 119 120 static Project *projectForFile(const Utils::FilePath &fileName); 121 122 static QStringList projectsForSessionName(const QString &session); 123 124 static void reportProjectLoadingProgress(); 125 static bool loadingSession(); 126 127 signals: 128 void targetAdded(ProjectExplorer::Target *target); 129 void targetRemoved(ProjectExplorer::Target *target); 130 void projectAdded(ProjectExplorer::Project *project); 131 void aboutToRemoveProject(ProjectExplorer::Project *project); 132 void projectDisplayNameChanged(ProjectExplorer::Project *project); 133 void projectRemoved(ProjectExplorer::Project *project); 134 135 void startupProjectChanged(ProjectExplorer::Project *project); 136 137 void aboutToUnloadSession(QString sessionName); 138 void aboutToLoadSession(QString sessionName); 139 void sessionLoaded(QString sessionName); 140 void aboutToSaveSession(); 141 void dependencyChanged(ProjectExplorer::Project *a, ProjectExplorer::Project *b); 142 143 signals: // for tests only 144 void projectFinishedParsing(ProjectExplorer::Project *project); 145 146 private: 147 static void saveActiveMode(Utils::Id mode); 148 static void configureEditor(Core::IEditor *editor, const QString &fileName); 149 static void markSessionFileDirty(); 150 static void configureEditors(Project *project); 151 }; 152 153 } // namespace ProjectExplorer 154