1 /*************************************************************************
2 Copyright © 2020   Roman Gilg <subdiff@gmail.com>
3 
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8 
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 **************************************************************************/
18 #pragma once
19 
20 #include "types.h"
21 
22 #include "disman_export.h"
23 
24 #include <QObject>
25 
26 #include <memory>
27 
28 namespace Disman
29 {
30 class Device;
31 class Filer;
32 
33 /**
34  * Side-channel controller for writing additional data to control files through the @ref Filer and
35  * Output_filer class.
36  */
37 class Filer_controller : public QObject
38 {
39     Q_OBJECT
40 public:
41     explicit Filer_controller(Device* device, QObject* parent = nullptr);
42     ~Filer_controller() override;
43 
44     /**
45      * Read in currently stored configuration in file on disk. If no configuration control file was
46      * found false is returned but the outputs might still be adapted to global output presets.
47      *
48      * @param config the object to save the configuration in
49      * @return true when a configuration file was found, otherwise false
50      */
51     bool read(ConfigPtr& config);
52 
53     /**
54      * Write @param config to file on disk.
55      *
56      * @param config provides configuration data to write
57      * @return true if write successful, otherwise false
58      */
59     bool write(ConfigPtr const& config);
60 
61     bool load_lid_file(ConfigPtr& config);
62     bool save_lid_file(ConfigPtr const& config);
63 
64 private:
65     bool lid_file_exists(ConfigPtr const& config);
66     bool move_lid_file(ConfigPtr const& config);
67 
68     void reset_filer(ConfigPtr const& config);
69 
70     std::unique_ptr<Filer> m_filer;
71     Device* m_device;
72 };
73 
74 }
75