LibrePCB Developers Documentation
workspace.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_WORKSPACE_H
21#define LIBREPCB_CORE_WORKSPACE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../fileio/directorylock.h"
27#include "../types/version.h"
28
29#include <QtCore>
30
31#include <memory>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37
38class Library;
39class Project;
40class TransactionalFileSystem;
41class WorkspaceLibraryDb;
42class WorkspaceSettings;
43
44/*******************************************************************************
45 * Class Workspace
46 ******************************************************************************/
47
54class Workspace final : public QObject {
55 Q_OBJECT
56
57public:
58 // Constructors / Destructor
59 Workspace() = delete;
60 Workspace(const Workspace& other) = delete;
61
75 explicit Workspace(const FilePath& wsPath, const QString& dataDirName,
76 DirectoryLock::LockHandlerCallback lockCallback = nullptr);
77
81 ~Workspace() noexcept;
82
83 // Getters
84
88 const FilePath& getPath() const { return mPath; }
89
93 const FilePath& getProjectsPath() const { return mProjectsPath; }
94
98 const FilePath& getDataPath() const { return mDataPath; }
99
103 const FilePath& getLibrariesPath() const { return mLibrariesPath; }
104
109 return mLibrariesPath.getPathTo("local");
110 }
111
116 return mLibrariesPath.getPathTo("remote");
117 }
118
123
128
133
134 // General Methods
135
139 void saveSettings();
140
141 // Operator Overloadings
142 Workspace& operator=(const Workspace& rhs) = delete;
143
144 // Static Methods
145
156 static bool checkCompatibility(const FilePath& wsRoot,
157 QString* errorMsg = nullptr);
158
168 static QMap<QString, Version> findDataDirectories(const FilePath& wsRoot);
169
184 static QString determineDataDirectory(const QMap<QString, Version>& dataDirs,
185 QString& copyFromDir,
186 QString& copyToDir) noexcept;
187
195 static void createNewWorkspace(const FilePath& path);
196
203
209 static void setMostRecentlyUsedWorkspacePath(const FilePath& path) noexcept;
210
218 static Version FILE_FORMAT_VERSION() noexcept {
219 return Version::fromString("0.1");
220 }
221
222private: // Methods
227
228private: // Data
231
234
237
240
242 std::shared_ptr<TransactionalFileSystem> mFileSystem;
243
245 QScopedPointer<WorkspaceSettings> mWorkspaceSettings;
246
248 QScopedPointer<WorkspaceLibraryDb> mLibraryDb;
249};
250
251/*******************************************************************************
252 * End of File
253 ******************************************************************************/
254
255} // namespace librepcb
256
257#endif
std::function< bool(const FilePath &dir, LockStatus status, const QString &user)> LockHandlerCallback
Callback type used to determine whether a lock should be overridden or not.
Definition: directorylock.h:193
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
FilePath getPathTo(const QString &filename) const noexcept
Get the filepath to a file or directory which is relative to this filepath.
Definition: filepath.cpp:176
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
static Version fromString(const QString &str)
Create a Version object from a string.
Definition: version.cpp:91
The Workspace class represents a workspace with all its data (library, projects, settings,...
Definition: workspace.h:54
void saveSettingsToTransactionalFileSystem()
Save the workspace settings to the transactional file system.
Definition: workspace.cpp:278
QScopedPointer< WorkspaceSettings > mWorkspaceSettings
the WorkspaceSettings object
Definition: workspace.h:245
FilePath getLocalLibrariesPath() const
Get the filepath to the "data/libraries/local" directory.
Definition: workspace.h:108
WorkspaceSettings & getSettings()
Get the workspace settings.
Definition: workspace.h:122
Workspace & operator=(const Workspace &rhs)=delete
static void createNewWorkspace(const FilePath &path)
Create a new workspace.
Definition: workspace.cpp:256
static bool checkCompatibility(const FilePath &wsRoot, QString *errorMsg=nullptr)
Check the existence & compatibility of a workspace directory.
Definition: workspace.cpp:149
const FilePath & getProjectsPath() const
Get the filepath to the "projects" directory in the workspace.
Definition: workspace.h:93
static void setMostRecentlyUsedWorkspacePath(const FilePath &path) noexcept
Set the most recently used workspace path.
Definition: workspace.cpp:268
QScopedPointer< WorkspaceLibraryDb > mLibraryDb
the library database
Definition: workspace.h:248
FilePath mDataPath
the subdirectory of the current file format version
Definition: workspace.h:236
FilePath mProjectsPath
the directory "projects"
Definition: workspace.h:233
FilePath mPath
a FilePath object which represents the workspace directory
Definition: workspace.h:230
const FilePath & getLibrariesPath() const
Get the filepath to the "data/libraries" directory in the workspace.
Definition: workspace.h:103
static QMap< QString, Version > findDataDirectories(const FilePath &wsRoot)
Find all data directories of a workspace.
Definition: workspace.cpp:175
FilePath mLibrariesPath
the directory "data/libraries"
Definition: workspace.h:239
static FilePath getMostRecentlyUsedWorkspacePath() noexcept
Get the most recently used workspace path.
Definition: workspace.cpp:262
std::shared_ptr< TransactionalFileSystem > mFileSystem
to lock the version directory (mDataPath)
Definition: workspace.h:242
WorkspaceLibraryDb & getLibraryDb() const
Get the workspace library database.
Definition: workspace.h:132
const FilePath & getDataPath() const
Get the filepath to the data directory in the workspace.
Definition: workspace.h:98
void saveSettings()
Save all (modified) settings to disk.
Definition: workspace.cpp:139
static Version FILE_FORMAT_VERSION() noexcept
Current workspace file format version (constant)
Definition: workspace.h:218
static QString determineDataDirectory(const QMap< QString, Version > &dataDirs, QString &copyFromDir, QString &copyToDir) noexcept
Decide which data directory to open, and how to do it.
Definition: workspace.cpp:208
Workspace(const Workspace &other)=delete
const WorkspaceSettings & getSettings() const
Get the workspace settings.
Definition: workspace.h:127
~Workspace() noexcept
Definition: workspace.cpp:132
FilePath getRemoteLibrariesPath() const
Get the filepath to the "data/libraries/remote" directory.
Definition: workspace.h:115
const FilePath & getPath() const
Get the filepath to the workspace directory.
Definition: workspace.h:88
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:58
Container for all workspace related settings.
Definition: workspacesettings.h:60
Definition: occmodel.cpp:77