1 /*
2     SPDX-FileCopyrightText: 2020 Roman Gilg <subdiff@gmail.com>
3 
4     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only
5 */
6 #ifndef BACKEND_IMPL_H
7 #define BACKEND_IMPL_H
8 
9 #include "backend.h"
10 
11 #include <memory>
12 
13 namespace Disman
14 {
15 class Device;
16 class Filer_controller;
17 
18 class BackendImpl : public Backend
19 {
20     Q_OBJECT
21 
22 public:
23     explicit BackendImpl();
24     ~BackendImpl();
25 
26     void init(const QVariantMap& arguments) override;
27 
28     ConfigPtr config() const override;
29     void set_config(ConfigPtr const& config) override;
30 
31 protected:
32     virtual void update_config(ConfigPtr& config) const = 0;
33     virtual bool set_config_system(ConfigPtr const& config) = 0;
34 
35     /**
36      * Handles a change in the window system. Sets a stored or generated config if needed and
37      * returns false in this case. If the state correspondes to the stored state or is already
38      * optimal returns true.
39      */
40     bool handle_config_change();
41 
42 private:
43     ConfigPtr config_impl() const;
44     bool set_config_impl(ConfigPtr const& config);
45 
46     void load_lid_config();
47 
48     std::unique_ptr<Device> m_device;
49     std::unique_ptr<Filer_controller> m_filer_controller;
50 
51     mutable bool m_config_initialized{false};
52 
53     ConfigPtr m_config;
54 };
55 
56 }
57 
58 #endif
59