|
2 | 2 | // SPDX-License-Identifier: MIT |
3 | 3 | #include "profileManager.h" |
4 | 4 |
|
5 | | -// Project headers |
6 | | -#include <misc/pathHelpers.h> |
7 | | -#include <model/profile.h> |
8 | | -#include <storage/profileStore.h> |
9 | | - |
10 | 5 | namespace kemai |
11 | 6 | { |
12 | 7 | ProfileManager::ProfileManager(QObject *parent): |
13 | | - QObject(parent), |
14 | | - m_profileModel(std::make_unique<ProfileModel>()), |
15 | | - m_profileStore(std::make_unique<ProfileStore>()) |
| 8 | + ProfileController(parent) |
16 | 9 | { |
17 | | - auto profilesPath = PathHelpers::getFilePath(PathHelpers::FilePathType::Profiles); |
18 | | - m_profileStore->setStorePath(profilesPath); |
19 | | - |
20 | | - connect(m_profileStore.get(), &ProfileStore::profilesLoaded, this, &ProfileManager::onProfilesLoaded); |
21 | | - connect(m_profileStore.get(), &ProfileStore::profileSaved, this, &ProfileManager::onProfileSaved); |
22 | | - connect(m_profileStore.get(), &ProfileStore::profileRemoved, this, &ProfileManager::onProfileRemoved); |
23 | | - |
24 | | - m_profileStore->loadAll(); |
25 | | - } |
26 | | - |
27 | | - ProfileManager::~ProfileManager() = default; |
28 | | - |
29 | | - ProfileModel *ProfileManager::profileModel() const |
30 | | - { |
31 | | - return m_profileModel.get(); |
32 | 10 | } |
33 | 11 |
|
34 | 12 | void ProfileManager::upsert(const ProfileId &profileId, const QString &name, const QString &host, const QString &token) |
35 | 13 | { |
36 | | - Profile profile; |
37 | | - profile.id = profileId.isNull() ? ProfileId::createUuid() : profileId; |
38 | | - profile.name = name; |
39 | | - profile.host = host; |
40 | | - profile.token = token; |
41 | | - |
42 | | - m_profileStore->save(profile); |
| 14 | + ProfileController::upsert(profileId, name, host, token); |
43 | 15 | } |
44 | 16 |
|
45 | 17 | void ProfileManager::remove(const ProfileId &profileId) |
46 | 18 | { |
47 | | - m_profileStore->remove(profileId); |
48 | | - } |
49 | | - |
50 | | - void ProfileManager::onProfilesLoaded(const std::vector<Profile> &profiles) |
51 | | - { |
52 | | - m_profileModel->setProfiles(profiles); |
53 | | - } |
54 | | - |
55 | | - void ProfileManager::onProfileSaved(ProfileId /*profileId*/) |
56 | | - { |
57 | | - m_profileStore->loadAll(); |
58 | | - } |
59 | | - |
60 | | - void ProfileManager::onProfileRemoved(ProfileId /*profileId*/) |
61 | | - { |
62 | | - m_profileStore->loadAll(); |
| 19 | + ProfileController::remove(profileId); |
63 | 20 | } |
64 | 21 |
|
65 | 22 | } // namespace kemai |
0 commit comments