Skip to content

Commit bcdfca8

Browse files
committed
Add FilePaths class
1 parent 61b4b3e commit bcdfca8

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

src/global/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ set(MODULE_SRC
44
globalmodule.cpp
55
globalmodule.h
66
iappinfo.h
7+
ifilepaths.h
78
modularity/ioc.h
89
modularity/modulesioc.h
910
modularity/imoduleexportinterface.h
1011
modularity/imodulesetup.h
1112
internal/appinfo.cpp
1213
internal/appinfo.h
14+
internal/filepaths.cpp
15+
internal/filepaths.h
1316
)
1417

1518
include(${PROJECT_SOURCE_DIR}/build/module.cmake)

src/global/globalmodule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "globalmodule.h"
66
#include "internal/appinfo.h"
7+
#include "internal/filepaths.h"
78

89
using namespace scratchcpp;
910

@@ -19,4 +20,6 @@ void GlobalModule::registerExports()
1920
QQmlEngine::setObjectOwnership(m_appInfo.get(), QQmlEngine::CppOwnership);
2021
qmlRegisterSingletonInstance<AppInfo>("ScratchCPP.Ui", 1, 0, "AppInfo", m_appInfo.get());
2122
modularity::ioc()->registerExport<IAppInfo>(m_appInfo);
23+
24+
modularity::ioc()->registerExport<FilePaths>(FilePaths::instance());
2225
}

src/global/ifilepaths.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
#pragma once
4+
5+
#include <QString>
6+
7+
#include "modularity/ioc.h"
8+
9+
namespace scratchcpp
10+
{
11+
12+
class IFilePaths : MODULE_EXPORT_INTERFACE
13+
{
14+
public:
15+
virtual ~IFilePaths() { }
16+
17+
virtual QString configLocation() const = 0;
18+
};
19+
20+
} // namespace scratchcpp

src/global/internal/filepaths.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
#include <QStandardPaths>
4+
#include <QCoreApplication>
5+
6+
#include "filepaths.h"
7+
8+
using namespace scratchcpp;
9+
10+
std::shared_ptr<FilePaths> FilePaths::m_instance = std::make_shared<FilePaths>();
11+
12+
std::shared_ptr<FilePaths> FilePaths::instance()
13+
{
14+
return m_instance;
15+
}
16+
17+
QString scratchcpp::FilePaths::configLocation() const
18+
{
19+
return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/" + qApp->applicationName() + "/config.ini";
20+
}

src/global/internal/filepaths.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
#pragma once
4+
5+
#include <QObject>
6+
7+
#include "ifilepaths.h"
8+
9+
namespace scratchcpp
10+
{
11+
12+
class FilePaths : public IFilePaths
13+
{
14+
public:
15+
static std::shared_ptr<FilePaths> instance();
16+
17+
QString configLocation() const override;
18+
19+
private:
20+
static std::shared_ptr<FilePaths> m_instance;
21+
};
22+
23+
} // namespace scratchcpp

0 commit comments

Comments
 (0)