Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
system.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Authors: see git history
6 *
7 * Copyright (C) 2017 Authors
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
10#ifndef SEEN_COLORS_CMS_SYSTEM_H
11#define SEEN_COLORS_CMS_SYSTEM_H
12
13#include <cassert>
14#include <map>
15#include <memory>
16#include <string>
17#include <vector>
18
19#include "preferences.h"
20
21using DirPaths = std::vector<std::pair<std::string, bool>>;
22
23namespace Inkscape::Colors::CMS {
24
25class Profile;
26class Transform;
27class System
28{
29private:
30 System(System const &) = delete;
31 void operator=(System const &) = delete;
32
33public:
34 // Access the singleton CMS::System object.
35 static System &get()
36 {
37 static System instance;
38 return instance;
39 }
40
42 void addDirectoryPath(std::string path, bool is_user);
44
45 std::vector<std::shared_ptr<Profile>> getProfiles() const;
46 const std::shared_ptr<Profile> &getProfile(std::string const &name) const;
47
48 std::vector<std::shared_ptr<Profile>> getDisplayProfiles() const;
49 const std::shared_ptr<Profile> &getDisplayProfile(bool &updated);
50 const std::shared_ptr<Transform> &getDisplayTransform();
51
52 std::vector<std::shared_ptr<Profile>> getOutputProfiles() const;
53
54 void refreshProfiles();
55
56 System();
57 ~System() = default;
58
59 // Used by testing to add profiles when needed
60 void addProfile(std::shared_ptr<Profile> profile) { _profiles.emplace_back(profile); }
61
62private:
63 // List of ICC profiles found on system
64 std::vector<std::shared_ptr<Profile>> _profiles;
65
66 // Paths to search for icc profiles
68
69 // We track last display transform settings. If there is a change, we delete create new transform.
70 std::shared_ptr<Profile> _display_profile;
71 std::shared_ptr<Transform> _display_transform;
72 bool _display = false;
74
76};
77
78class CmsError : public std::exception
79{
80public:
81 CmsError(std::string &&msg)
82 : _msg(msg)
83 {}
84 char const *what() const noexcept override { return _msg.c_str(); }
85
86private:
87 std::string _msg;
88};
89
90} // namespace Inkscape::Colors::CMS
91
92#endif // SEEN_COLORS_CMS_SYSTEM_H
93
94/*
95 Local Variables:
96 mode:c++
97 c-file-style:"stroustrup"
98 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
99 indent-tabs-mode:nil
100 fill-column:99
101 End:
102*/
103// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
char const * what() const noexcept override
Definition system.h:84
CmsError(std::string &&msg)
Definition system.h:81
Inkscape::PrefObserver _prefs_observer
Definition system.h:75
void addDirectoryPath(std::string path, bool is_user)
Replace all generated profile paths with this single path, useful for testing.
Definition system.cpp:144
void operator=(System const &)=delete
const std::shared_ptr< Profile > & getProfile(std::string const &name) const
Return the profile object which is matched by the given name, id or path.
Definition system.cpp:221
void clearDirectoryPaths()
Remove all directory paths that might have been generated (useful for refreshing)
Definition system.cpp:136
System(System const &)=delete
static System & get()
Definition system.h:35
std::vector< std::shared_ptr< Profile > > getDisplayProfiles() const
Returns a list of profiles that can apply to the display (display), sorted by their internal names.
Definition system.cpp:182
std::vector< std::shared_ptr< Profile > > getOutputProfiles() const
Return vector of profiles which can be used for cms output.
Definition system.cpp:199
std::vector< std::shared_ptr< Profile > > getProfiles() const
Returns a list of profiles sorted by their internal names.
Definition system.cpp:152
void addProfile(std::shared_ptr< Profile > profile)
Definition system.h:60
const std::shared_ptr< Profile > & getDisplayProfile(bool &updated)
Get the user set display profile, if set.
Definition system.cpp:162
std::shared_ptr< Profile > _display_profile
Definition system.h:70
DirPaths const & getDirectoryPaths()
Create list of all directories where ICC profiles are expected to be found.
Definition system.cpp:125
const std::shared_ptr< Transform > & getDisplayTransform()
Get the color managed trasform for the screen.
Definition system.cpp:240
std::vector< std::shared_ptr< Profile > > _profiles
Definition system.h:64
std::shared_ptr< Transform > _display_transform
Definition system.h:71
void refreshProfiles()
Search for system ICC profile files and add them to list.
Definition system.cpp:42
std::vector< std::pair< std::string, bool > > DirPaths
Definition system.h:21
Glib::ustring msg
std::unique_ptr< Preferences::PreferencesObserver > PrefObserver
Singleton class to access the preferences file in a convenient way.
Glib::ustring name
Definition toolbars.cpp:55