Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
project_manager.h
1// SPDX-FileCopyrightText: © 2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "gui/backend/project_ui_state.h"
7#include "gui/backend/recent_projects_model.h"
8
9#include <QFutureWatcher>
10#include <QtQmlIntegration/qqmlintegration.h>
11
12// DEPRECATED - do not use in new code
13#define PROJECT \
14 (zrythm::gui::ProjectManager::get_instance ()->activeProject ()->project ())
15
16namespace zrythm::gui
17{
18
19class ProjectManager : public QObject
20{
21 Q_OBJECT
22 QML_ELEMENT
23 Q_PROPERTY (
24 zrythm::gui::RecentProjectsModel * recentProjects READ getRecentProjects
25 CONSTANT)
26 Q_PROPERTY (
27 zrythm::gui::ProjectUiState * activeProject READ activeProject WRITE
28 setActiveProject NOTIFY activeProjectChanged)
29 QML_UNCREATABLE ("")
30
31public:
32 ProjectManager (utils::AppSettings &app_settings, QObject * parent = nullptr);
33
34 using Template = fs::path;
35 using TemplateList = std::vector<Template>;
36 using ProjectLoadResult =
37 std::variant<utils::QObjectUniquePtr<ProjectUiState>, QString>;
38
39 static ProjectManager * get_instance ();
40
44 TemplateList get_templates () const;
45
51 Q_INVOKABLE static QString
52 getNextAvailableProjectName (const QUrl &directory, const QString &name);
53
54 Q_INVOKABLE void createNewProject (
55 const QUrl &directory,
56 const QString &name,
57 const QUrl &templateUrl = QUrl{});
58 Q_INVOKABLE void loadProject (const QString &filepath);
59
60 void add_to_recent_projects (const QString &path);
61
62 RecentProjectsModel * getRecentProjects () const;
63
64 ProjectUiState * activeProject () const;
65 void setActiveProject (ProjectUiState * project);
66
67Q_SIGNALS:
68 void projectLoaded (ProjectUiState * project);
69 void projectLoadingFailed (const QString &errorMessage);
70 void activeProjectChanged (ProjectUiState * project);
71
72private:
76 void init_templates ();
77
78 // void create_or_load_project (const QString &filepath, bool is_template);
79
84 void load_from_file ();
85
98 const fs::path &prj_dir,
99 const utils::Utf8String &name,
100 bool with_engine);
101
107 std::unique_ptr<plugins::IPluginHostWindow>
108 create_window_for_plugin (plugins::Plugin &plugin) const;
109
110private:
111 utils::AppSettings &app_settings_;
112
114 TemplateList templates_;
115
121 Template demo_template_;
122
123 RecentProjectsModel * recent_projects_model_ = nullptr;
124
129
135 QFutureWatcher<ProjectLoadResult> project_watcher_;
136};
137
138}
TemplateList get_templates() const
Gets a copy of the list of project templates.
static Q_INVOKABLE QString getNextAvailableProjectName(const QUrl &directory, const QString &name)
Get the next available untitled project name for the given directory.
UI-related state of a project.
DSP processing plugin.
Definition plugin.h:30
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:38