ProjectsScreen.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <ProjectsScreen.h>
  9. #include <ProjectManagerDefs.h>
  10. #include <ProjectButtonWidget.h>
  11. #include <PythonBindingsInterface.h>
  12. #include <ProjectUtils.h>
  13. #include <ProjectBuilderController.h>
  14. #include <ScreensCtrl.h>
  15. #include <ProjectManagerSettings.h>
  16. #include <AzQtComponents/Components/FlowLayout.h>
  17. #include <AzCore/Platform.h>
  18. #include <AzCore/IO/SystemFile.h>
  19. #include <AzFramework/AzFramework_Traits_Platform.h>
  20. #include <AzFramework/Process/ProcessCommon.h>
  21. #include <AzFramework/Process/ProcessWatcher.h>
  22. #include <AzCore/Utils/Utils.h>
  23. #include <AzCore/Settings/SettingsRegistry.h>
  24. #include <QVBoxLayout>
  25. #include <QHBoxLayout>
  26. #include <QLabel>
  27. #include <QPushButton>
  28. #include <QMenu>
  29. #include <QListView>
  30. #include <QSpacerItem>
  31. #include <QListWidget>
  32. #include <QListWidgetItem>
  33. #include <QScrollArea>
  34. #include <QStackedWidget>
  35. #include <QFrame>
  36. #include <QIcon>
  37. #include <QPixmap>
  38. #include <QSettings>
  39. #include <QMessageBox>
  40. #include <QTimer>
  41. #include <QQueue>
  42. #include <QDir>
  43. #include <QGuiApplication>
  44. namespace O3DE::ProjectManager
  45. {
  46. ProjectsScreen::ProjectsScreen(QWidget* parent)
  47. : ScreenWidget(parent)
  48. {
  49. QVBoxLayout* vLayout = new QVBoxLayout();
  50. vLayout->setAlignment(Qt::AlignTop);
  51. vLayout->setContentsMargins(s_contentMargins, 0, s_contentMargins, 0);
  52. setLayout(vLayout);
  53. m_stack = new QStackedWidget(this);
  54. m_firstTimeContent = CreateFirstTimeContent();
  55. m_stack->addWidget(m_firstTimeContent);
  56. m_projectsContent = CreateProjectsContent();
  57. m_stack->addWidget(m_projectsContent);
  58. vLayout->addWidget(m_stack);
  59. connect(reinterpret_cast<ScreensCtrl*>(parent), &ScreensCtrl::NotifyBuildProject, this, &ProjectsScreen::SuggestBuildProject);
  60. // Will focus whatever button it finds so the Project tab is not focused on start-up
  61. QTimer::singleShot(0, this, [this]
  62. {
  63. QPushButton* foundButton = m_stack->currentWidget()->findChild<QPushButton*>();
  64. if (foundButton)
  65. {
  66. foundButton->setFocus();
  67. }
  68. });
  69. }
  70. ProjectsScreen::~ProjectsScreen()
  71. {
  72. }
  73. QFrame* ProjectsScreen::CreateFirstTimeContent()
  74. {
  75. QFrame* frame = new QFrame(this);
  76. frame->setObjectName("firstTimeContent");
  77. {
  78. QVBoxLayout* layout = new QVBoxLayout();
  79. layout->setContentsMargins(0, 0, 0, 0);
  80. layout->setAlignment(Qt::AlignTop);
  81. frame->setLayout(layout);
  82. QLabel* titleLabel = new QLabel(tr("Ready? Set. Create!"), this);
  83. titleLabel->setObjectName("titleLabel");
  84. layout->addWidget(titleLabel);
  85. QLabel* introLabel = new QLabel(this);
  86. introLabel->setObjectName("introLabel");
  87. introLabel->setText(tr("Welcome to O3DE! Start something new by creating a project."));
  88. layout->addWidget(introLabel);
  89. QHBoxLayout* buttonLayout = new QHBoxLayout();
  90. buttonLayout->setAlignment(Qt::AlignLeft);
  91. buttonLayout->setSpacing(s_spacerSize);
  92. // use a newline to force the text up
  93. QPushButton* createProjectButton = new QPushButton(tr("Create a Project\n"), this);
  94. createProjectButton->setObjectName("createProjectButton");
  95. buttonLayout->addWidget(createProjectButton);
  96. QPushButton* addProjectButton = new QPushButton(tr("Add a Project\n"), this);
  97. addProjectButton->setObjectName("addProjectButton");
  98. buttonLayout->addWidget(addProjectButton);
  99. connect(createProjectButton, &QPushButton::clicked, this, &ProjectsScreen::HandleNewProjectButton);
  100. connect(addProjectButton, &QPushButton::clicked, this, &ProjectsScreen::HandleAddProjectButton);
  101. layout->addLayout(buttonLayout);
  102. }
  103. return frame;
  104. }
  105. QFrame* ProjectsScreen::CreateProjectsContent()
  106. {
  107. QFrame* frame = new QFrame(this);
  108. frame->setObjectName("projectsContent");
  109. {
  110. QVBoxLayout* layout = new QVBoxLayout();
  111. layout->setAlignment(Qt::AlignTop);
  112. layout->setContentsMargins(0, 0, 0, 0);
  113. frame->setLayout(layout);
  114. QFrame* header = new QFrame(frame);
  115. QHBoxLayout* headerLayout = new QHBoxLayout();
  116. {
  117. QLabel* titleLabel = new QLabel(tr("My Projects"), this);
  118. titleLabel->setObjectName("titleLabel");
  119. headerLayout->addWidget(titleLabel);
  120. QMenu* newProjectMenu = new QMenu(this);
  121. m_createNewProjectAction = newProjectMenu->addAction("Create New Project");
  122. m_addExistingProjectAction = newProjectMenu->addAction("Add Existing Project");
  123. connect(m_createNewProjectAction, &QAction::triggered, this, &ProjectsScreen::HandleNewProjectButton);
  124. connect(m_addExistingProjectAction, &QAction::triggered, this, &ProjectsScreen::HandleAddProjectButton);
  125. QPushButton* newProjectMenuButton = new QPushButton(tr("New Project..."), this);
  126. newProjectMenuButton->setObjectName("newProjectButton");
  127. newProjectMenuButton->setMenu(newProjectMenu);
  128. newProjectMenuButton->setDefault(true);
  129. headerLayout->addWidget(newProjectMenuButton);
  130. }
  131. header->setLayout(headerLayout);
  132. layout->addWidget(header);
  133. QScrollArea* projectsScrollArea = new QScrollArea(this);
  134. QWidget* scrollWidget = new QWidget();
  135. m_projectsFlowLayout = new FlowLayout(0, s_spacerSize, s_spacerSize);
  136. scrollWidget->setLayout(m_projectsFlowLayout);
  137. projectsScrollArea->setWidget(scrollWidget);
  138. projectsScrollArea->setWidgetResizable(true);
  139. ResetProjectsContent();
  140. layout->addWidget(projectsScrollArea);
  141. }
  142. return frame;
  143. }
  144. ProjectButton* ProjectsScreen::CreateProjectButton(const ProjectInfo& project)
  145. {
  146. ProjectButton* projectButton = new ProjectButton(project, this);
  147. m_projectButtons.insert(QDir::toNativeSeparators(project.m_path), projectButton);
  148. m_projectsFlowLayout->addWidget(projectButton);
  149. connect(projectButton, &ProjectButton::OpenProject, this, &ProjectsScreen::HandleOpenProject);
  150. connect(projectButton, &ProjectButton::EditProject, this, &ProjectsScreen::HandleEditProject);
  151. connect(projectButton, &ProjectButton::EditProjectGems, this, &ProjectsScreen::HandleEditProjectGems);
  152. connect(projectButton, &ProjectButton::CopyProject, this, &ProjectsScreen::HandleCopyProject);
  153. connect(projectButton, &ProjectButton::RemoveProject, this, &ProjectsScreen::HandleRemoveProject);
  154. connect(projectButton, &ProjectButton::DeleteProject, this, &ProjectsScreen::HandleDeleteProject);
  155. connect(projectButton, &ProjectButton::BuildProject, this, &ProjectsScreen::QueueBuildProject);
  156. connect(projectButton, &ProjectButton::OpenCMakeGUI, this,
  157. [this](const ProjectInfo& projectInfo)
  158. {
  159. AZ::Outcome result = ProjectUtils::OpenCMakeGUI(projectInfo.m_path);
  160. if (!result)
  161. {
  162. QMessageBox::critical(this, tr("Failed to open CMake GUI"), result.GetError(), QMessageBox::Ok);
  163. }
  164. });
  165. return projectButton;
  166. }
  167. void ProjectsScreen::ResetProjectsContent()
  168. {
  169. RemoveInvalidProjects();
  170. // Get all projects and create a vertical scrolling list of them
  171. // Sort building and queued projects first
  172. auto projectsResult = PythonBindingsInterface::Get()->GetProjects();
  173. if (projectsResult.IsSuccess() && !projectsResult.GetValue().isEmpty())
  174. {
  175. QVector<ProjectInfo> projectsVector = projectsResult.GetValue();
  176. // If a project path is in this set then the button for it will be kept
  177. QSet<QString> keepProject;
  178. for (const ProjectInfo& project : projectsVector)
  179. {
  180. keepProject.insert(QDir::toNativeSeparators(project.m_path));
  181. }
  182. // Clear flow and delete buttons for removed projects
  183. auto projectButtonsIter = m_projectButtons.begin();
  184. while (projectButtonsIter != m_projectButtons.end())
  185. {
  186. m_projectsFlowLayout->removeWidget(projectButtonsIter.value());
  187. if (!keepProject.contains(projectButtonsIter.key()))
  188. {
  189. projectButtonsIter.value()->deleteLater();
  190. projectButtonsIter = m_projectButtons.erase(projectButtonsIter);
  191. }
  192. else
  193. {
  194. ++projectButtonsIter;
  195. }
  196. }
  197. QString buildProjectPath = "";
  198. if (m_currentBuilder)
  199. {
  200. buildProjectPath = QDir::toNativeSeparators(m_currentBuilder->GetProjectInfo().m_path);
  201. }
  202. // Put currently building project in front, then queued projects, then sorts alphabetically
  203. std::sort(projectsVector.begin(), projectsVector.end(), [buildProjectPath, this](const ProjectInfo& arg1, const ProjectInfo& arg2)
  204. {
  205. if (arg1.m_path == buildProjectPath)
  206. {
  207. return true;
  208. }
  209. else if (arg2.m_path == buildProjectPath)
  210. {
  211. return false;
  212. }
  213. bool arg1InBuildQueue = BuildQueueContainsProject(arg1.m_path);
  214. bool arg2InBuildQueue = BuildQueueContainsProject(arg2.m_path);
  215. if (arg1InBuildQueue && !arg2InBuildQueue)
  216. {
  217. return true;
  218. }
  219. else if (!arg1InBuildQueue && arg2InBuildQueue)
  220. {
  221. return false;
  222. }
  223. else
  224. {
  225. return arg1.m_displayName.toLower() < arg2.m_displayName.toLower();
  226. }
  227. });
  228. // Add any missing project buttons and restore buttons to default state
  229. for (const ProjectInfo& project : projectsVector)
  230. {
  231. ProjectButton* currentButton = nullptr;
  232. if (!m_projectButtons.contains(QDir::toNativeSeparators(project.m_path)))
  233. {
  234. currentButton = CreateProjectButton(project);
  235. m_projectButtons.insert(QDir::toNativeSeparators(project.m_path), currentButton);
  236. }
  237. else
  238. {
  239. auto projectButtonIter = m_projectButtons.find(QDir::toNativeSeparators(project.m_path));
  240. if (projectButtonIter != m_projectButtons.end())
  241. {
  242. currentButton = projectButtonIter.value();
  243. currentButton->RestoreDefaultState();
  244. m_projectsFlowLayout->addWidget(currentButton);
  245. }
  246. }
  247. // Check whether project manager has successfully built the project
  248. if (currentButton)
  249. {
  250. auto settingsRegistry = AZ::SettingsRegistry::Get();
  251. bool projectBuiltSuccessfully = false;
  252. if (settingsRegistry)
  253. {
  254. QString settingsKey = GetProjectBuiltSuccessfullyKey(project.m_projectName);
  255. settingsRegistry->Get(projectBuiltSuccessfully, settingsKey.toStdString().c_str());
  256. }
  257. if (!projectBuiltSuccessfully)
  258. {
  259. currentButton->ShowBuildRequired();
  260. }
  261. }
  262. }
  263. // Setup building button again
  264. auto buildProjectIter = m_projectButtons.find(buildProjectPath);
  265. if (buildProjectIter != m_projectButtons.end())
  266. {
  267. m_currentBuilder->SetProjectButton(buildProjectIter.value());
  268. }
  269. for (const ProjectInfo& project : m_buildQueue)
  270. {
  271. auto projectIter = m_projectButtons.find(QDir::toNativeSeparators(project.m_path));
  272. if (projectIter != m_projectButtons.end())
  273. {
  274. projectIter.value()->SetProjectButtonAction(
  275. tr("Cancel Queued Build"),
  276. [this, project]
  277. {
  278. UnqueueBuildProject(project);
  279. SuggestBuildProjectMsg(project, false);
  280. });
  281. }
  282. }
  283. for (const ProjectInfo& project : m_requiresBuild)
  284. {
  285. auto projectIter = m_projectButtons.find(QDir::toNativeSeparators(project.m_path));
  286. if (projectIter != m_projectButtons.end())
  287. {
  288. if (project.m_buildFailed)
  289. {
  290. projectIter.value()->ShowBuildFailed(true, project.m_logUrl);
  291. }
  292. else
  293. {
  294. projectIter.value()->ShowBuildRequired();
  295. }
  296. }
  297. }
  298. }
  299. m_stack->setCurrentWidget(m_projectsContent);
  300. }
  301. ProjectManagerScreen ProjectsScreen::GetScreenEnum()
  302. {
  303. return ProjectManagerScreen::Projects;
  304. }
  305. bool ProjectsScreen::IsTab()
  306. {
  307. return true;
  308. }
  309. QString ProjectsScreen::GetTabText()
  310. {
  311. return tr("Projects");
  312. }
  313. void ProjectsScreen::paintEvent([[maybe_unused]] QPaintEvent* event)
  314. {
  315. // we paint the background here because qss does not support background cover scaling
  316. QPainter painter(this);
  317. const QSize winSize = size();
  318. const float pixmapRatio = (float)m_background.width() / m_background.height();
  319. const float windowRatio = (float)winSize.width() / winSize.height();
  320. QRect backgroundRect;
  321. if (pixmapRatio > windowRatio)
  322. {
  323. const int newWidth = (int)(winSize.height() * pixmapRatio);
  324. const int offset = (newWidth - winSize.width()) / -2;
  325. backgroundRect = QRect(offset, 0, newWidth, winSize.height());
  326. }
  327. else
  328. {
  329. const int newHeight = (int)(winSize.width() / pixmapRatio);
  330. backgroundRect = QRect(0, 0, winSize.width(), newHeight);
  331. }
  332. // Draw the background image.
  333. painter.drawPixmap(backgroundRect, m_background);
  334. // Draw a semi-transparent overlay to darken down the colors.
  335. // Use SourceOver, DestinationIn will make background transparent on Mac
  336. painter.setCompositionMode (QPainter::CompositionMode_SourceOver);
  337. const float overlayTransparency = 0.3f;
  338. painter.fillRect(backgroundRect, QColor(0, 0, 0, static_cast<int>(255.0f * overlayTransparency)));
  339. }
  340. void ProjectsScreen::HandleNewProjectButton()
  341. {
  342. emit ResetScreenRequest(ProjectManagerScreen::CreateProject);
  343. emit ChangeScreenRequest(ProjectManagerScreen::CreateProject);
  344. }
  345. void ProjectsScreen::HandleAddProjectButton()
  346. {
  347. if (ProjectUtils::AddProjectDialog(this))
  348. {
  349. ResetProjectsContent();
  350. emit ChangeScreenRequest(ProjectManagerScreen::Projects);
  351. }
  352. }
  353. void ProjectsScreen::HandleOpenProject(const QString& projectPath)
  354. {
  355. if (!projectPath.isEmpty())
  356. {
  357. if (!WarnIfInBuildQueue(projectPath))
  358. {
  359. AZ::IO::FixedMaxPath executableDirectory = ProjectUtils::GetEditorDirectory();
  360. AZStd::string executableFilename = "Editor";
  361. AZ::IO::FixedMaxPath editorExecutablePath = executableDirectory / (executableFilename + AZ_TRAIT_OS_EXECUTABLE_EXTENSION);
  362. auto cmdPath = AZ::IO::FixedMaxPathString::format(
  363. "%s --regset=\"/Amazon/AzCore/Bootstrap/project_path=%s\"", editorExecutablePath.c_str(),
  364. projectPath.toStdString().c_str());
  365. AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
  366. processLaunchInfo.m_commandlineParameters = cmdPath;
  367. bool launchSucceeded = AzFramework::ProcessLauncher::LaunchUnwatchedProcess(processLaunchInfo);
  368. if (!launchSucceeded)
  369. {
  370. AZ_Error("ProjectManager", false, "Failed to launch editor");
  371. QMessageBox::critical(
  372. this, tr("Error"), tr("Failed to launch the Editor, please verify the project settings are valid."));
  373. }
  374. else
  375. {
  376. // prevent the user from accidentally pressing the button while the editor is launching
  377. // and let them know what's happening
  378. ProjectButton* button = qobject_cast<ProjectButton*>(sender());
  379. if (button)
  380. {
  381. button->SetLaunchButtonEnabled(false);
  382. button->SetButtonOverlayText(tr("Opening Editor..."));
  383. }
  384. // enable the button after 3 seconds
  385. constexpr int waitTimeInMs = 3000;
  386. QTimer::singleShot(
  387. waitTimeInMs, this,
  388. [button]
  389. {
  390. if (button)
  391. {
  392. button->SetLaunchButtonEnabled(true);
  393. }
  394. });
  395. }
  396. }
  397. }
  398. else
  399. {
  400. AZ_Error("ProjectManager", false, "Cannot open editor because an empty project path was provided");
  401. QMessageBox::critical( this, tr("Error"), tr("Failed to launch the Editor because the project path is invalid."));
  402. }
  403. }
  404. void ProjectsScreen::HandleEditProject(const QString& projectPath)
  405. {
  406. if (!WarnIfInBuildQueue(projectPath))
  407. {
  408. emit NotifyCurrentProject(projectPath);
  409. emit ChangeScreenRequest(ProjectManagerScreen::UpdateProject);
  410. }
  411. }
  412. void ProjectsScreen::HandleEditProjectGems(const QString& projectPath)
  413. {
  414. if (!WarnIfInBuildQueue(projectPath))
  415. {
  416. emit NotifyCurrentProject(projectPath);
  417. emit ChangeScreenRequest(ProjectManagerScreen::GemCatalog);
  418. }
  419. }
  420. void ProjectsScreen::HandleCopyProject(const ProjectInfo& projectInfo)
  421. {
  422. if (!WarnIfInBuildQueue(projectInfo.m_path))
  423. {
  424. ProjectInfo newProjectInfo(projectInfo);
  425. // Open file dialog and choose location for copied project then register copy with O3DE
  426. if (ProjectUtils::CopyProjectDialog(projectInfo.m_path, newProjectInfo, this))
  427. {
  428. ResetProjectsContent();
  429. emit NotifyBuildProject(newProjectInfo);
  430. emit ChangeScreenRequest(ProjectManagerScreen::Projects);
  431. }
  432. }
  433. }
  434. void ProjectsScreen::HandleRemoveProject(const QString& projectPath)
  435. {
  436. if (!WarnIfInBuildQueue(projectPath))
  437. {
  438. // Unregister Project from O3DE and reload projects
  439. if (ProjectUtils::UnregisterProject(projectPath))
  440. {
  441. ResetProjectsContent();
  442. emit ChangeScreenRequest(ProjectManagerScreen::Projects);
  443. }
  444. }
  445. }
  446. void ProjectsScreen::HandleDeleteProject(const QString& projectPath)
  447. {
  448. if (!WarnIfInBuildQueue(projectPath))
  449. {
  450. QMessageBox::StandardButton warningResult = QMessageBox::warning(this,
  451. tr("Delete Project"),
  452. tr("Are you sure?\nProject will be unregistered from O3DE and project directory will be deleted from your disk."),
  453. QMessageBox::No | QMessageBox::Yes);
  454. if (warningResult == QMessageBox::Yes)
  455. {
  456. QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  457. // Remove project from O3DE and delete from disk
  458. HandleRemoveProject(projectPath);
  459. ProjectUtils::DeleteProjectFiles(projectPath);
  460. QGuiApplication::restoreOverrideCursor();
  461. }
  462. }
  463. }
  464. void ProjectsScreen::SuggestBuildProjectMsg(const ProjectInfo& projectInfo, bool showMessage)
  465. {
  466. if (RequiresBuildProjectIterator(projectInfo.m_path) == m_requiresBuild.end() || projectInfo.m_buildFailed)
  467. {
  468. m_requiresBuild.append(projectInfo);
  469. }
  470. ResetProjectsContent();
  471. if (showMessage)
  472. {
  473. QMessageBox::information(this,
  474. tr("Project Should be rebuilt."),
  475. projectInfo.GetProjectDisplayName() + tr(" project likely needs to be rebuilt."));
  476. }
  477. }
  478. void ProjectsScreen::SuggestBuildProject(const ProjectInfo& projectInfo)
  479. {
  480. SuggestBuildProjectMsg(projectInfo, true);
  481. }
  482. void ProjectsScreen::QueueBuildProject(const ProjectInfo& projectInfo)
  483. {
  484. auto requiredIter = RequiresBuildProjectIterator(projectInfo.m_path);
  485. if (requiredIter != m_requiresBuild.end())
  486. {
  487. m_requiresBuild.erase(requiredIter);
  488. }
  489. if (!BuildQueueContainsProject(projectInfo.m_path))
  490. {
  491. if (m_buildQueue.empty() && !m_currentBuilder)
  492. {
  493. StartProjectBuild(projectInfo);
  494. // Projects Content is already reset in function
  495. }
  496. else
  497. {
  498. m_buildQueue.append(projectInfo);
  499. ResetProjectsContent();
  500. }
  501. }
  502. }
  503. void ProjectsScreen::UnqueueBuildProject(const ProjectInfo& projectInfo)
  504. {
  505. m_buildQueue.removeAll(projectInfo);
  506. ResetProjectsContent();
  507. }
  508. void ProjectsScreen::NotifyCurrentScreen()
  509. {
  510. if (ShouldDisplayFirstTimeContent())
  511. {
  512. m_background.load(":/Backgrounds/FtueBackground.jpg");
  513. m_stack->setCurrentWidget(m_firstTimeContent);
  514. }
  515. else
  516. {
  517. m_background.load(":/Backgrounds/DefaultBackground.jpg");
  518. ResetProjectsContent();
  519. }
  520. }
  521. bool ProjectsScreen::ShouldDisplayFirstTimeContent()
  522. {
  523. auto projectsResult = PythonBindingsInterface::Get()->GetProjects();
  524. if (!projectsResult.IsSuccess() || projectsResult.GetValue().isEmpty())
  525. {
  526. return true;
  527. }
  528. QSettings settings;
  529. bool displayFirstTimeContent = settings.value("displayFirstTimeContent", true).toBool();
  530. if (displayFirstTimeContent)
  531. {
  532. settings.setValue("displayFirstTimeContent", false);
  533. }
  534. return displayFirstTimeContent;
  535. }
  536. bool ProjectsScreen::RemoveInvalidProjects()
  537. {
  538. return PythonBindingsInterface::Get()->RemoveInvalidProjects();
  539. }
  540. bool ProjectsScreen::StartProjectBuild(const ProjectInfo& projectInfo)
  541. {
  542. if (ProjectUtils::FindSupportedCompiler(this))
  543. {
  544. QMessageBox::StandardButton buildProject = QMessageBox::information(
  545. this,
  546. tr("Building \"%1\"").arg(projectInfo.GetProjectDisplayName()),
  547. tr("Ready to build \"%1\"?").arg(projectInfo.GetProjectDisplayName()),
  548. QMessageBox::No | QMessageBox::Yes);
  549. if (buildProject == QMessageBox::Yes)
  550. {
  551. m_currentBuilder = new ProjectBuilderController(projectInfo, nullptr, this);
  552. ResetProjectsContent();
  553. connect(m_currentBuilder, &ProjectBuilderController::Done, this, &ProjectsScreen::ProjectBuildDone);
  554. connect(m_currentBuilder, &ProjectBuilderController::NotifyBuildProject, this, &ProjectsScreen::SuggestBuildProject);
  555. m_currentBuilder->Start();
  556. }
  557. else
  558. {
  559. SuggestBuildProjectMsg(projectInfo, false);
  560. return false;
  561. }
  562. return true;
  563. }
  564. return false;
  565. }
  566. void ProjectsScreen::ProjectBuildDone(bool success)
  567. {
  568. ProjectInfo currentBuilderProject;
  569. if (!success)
  570. {
  571. currentBuilderProject = m_currentBuilder->GetProjectInfo();
  572. }
  573. delete m_currentBuilder;
  574. m_currentBuilder = nullptr;
  575. if (!success)
  576. {
  577. SuggestBuildProjectMsg(currentBuilderProject, false);
  578. }
  579. if (!m_buildQueue.empty())
  580. {
  581. while (!StartProjectBuild(m_buildQueue.front()) && m_buildQueue.size() > 1)
  582. {
  583. m_buildQueue.pop_front();
  584. }
  585. m_buildQueue.pop_front();
  586. }
  587. ResetProjectsContent();
  588. }
  589. QList<ProjectInfo>::iterator ProjectsScreen::RequiresBuildProjectIterator(const QString& projectPath)
  590. {
  591. QString nativeProjPath(QDir::toNativeSeparators(projectPath));
  592. auto projectIter = m_requiresBuild.begin();
  593. for (; projectIter != m_requiresBuild.end(); ++projectIter)
  594. {
  595. if (QDir::toNativeSeparators(projectIter->m_path) == nativeProjPath)
  596. {
  597. break;
  598. }
  599. }
  600. return projectIter;
  601. }
  602. bool ProjectsScreen::BuildQueueContainsProject(const QString& projectPath)
  603. {
  604. QString nativeProjPath(QDir::toNativeSeparators(projectPath));
  605. for (const ProjectInfo& project : m_buildQueue)
  606. {
  607. if (QDir::toNativeSeparators(project.m_path) == nativeProjPath)
  608. {
  609. return true;
  610. }
  611. }
  612. return false;
  613. }
  614. bool ProjectsScreen::WarnIfInBuildQueue(const QString& projectPath)
  615. {
  616. if (BuildQueueContainsProject(projectPath))
  617. {
  618. QMessageBox::warning(
  619. this,
  620. tr("Action Temporarily Disabled!"),
  621. tr("Action not allowed on projects in build queue."));
  622. return true;
  623. }
  624. return false;
  625. }
  626. } // namespace O3DE::ProjectManager