Use sqlite for cinema and DKDM recipient lists.
[dcpomatic.git] / src / lib / dkdm_recipient_list.h
1 /*
2     Copyright (C) 2024 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #ifndef DCPOMATIC_DKDM_RECIPIENT_LIST_H
23 #define DCPOMATIC_DKDM_RECIPIENT_LIST_H
24
25
26 #include "id.h"
27 #include "sqlite_table.h"
28 #include <libcxml/cxml.h>
29 #include <boost/filesystem.hpp>
30 #include <boost/optional.hpp>
31
32
33 class DKDMRecipient;
34
35
36 class DKDMRecipientID : public ID
37 {
38 public:
39         DKDMRecipientID(sqlite3_int64 id)
40                 : ID(id) {}
41
42         bool operator==(DKDMRecipientID const& other) const {
43                 return get() == other.get();
44         }
45
46         bool operator!=(DKDMRecipientID const& other) const {
47                 return get() != other.get();
48         }
49
50         bool operator<(DKDMRecipientID const& other) const {
51                 return get() < other.get();
52         }
53 };
54
55
56 class DKDMRecipientList
57 {
58 public:
59         DKDMRecipientList();
60         DKDMRecipientList(boost::filesystem::path db_file);
61         ~DKDMRecipientList();
62
63         DKDMRecipientList(DKDMRecipientList const&) = delete;
64         DKDMRecipientList& operator=(DKDMRecipientList const&) = delete;
65
66         DKDMRecipientList(DKDMRecipientList&& other);
67         DKDMRecipientList& operator=(DKDMRecipientList&& other);
68
69         void read_legacy_file(boost::filesystem::path xml_file);
70         void read_legacy_string(std::string const& xml);
71
72         void clear();
73
74         DKDMRecipientID add_dkdm_recipient(DKDMRecipient const& dkdm_recipient);
75         void update_dkdm_recipient(DKDMRecipientID id, DKDMRecipient const& dkdm_recipient);
76         void remove_dkdm_recipient(DKDMRecipientID id);
77         std::vector<std::pair<DKDMRecipientID, DKDMRecipient>> dkdm_recipients() const;
78         boost::optional<DKDMRecipient> dkdm_recipient(DKDMRecipientID id) const;
79
80 private:
81         void setup(boost::filesystem::path db_file);
82         void read_legacy_document(cxml::Document const& doc);
83
84         sqlite3* _db = nullptr;
85         SQLiteTable _dkdm_recipients;
86 };
87
88
89 #endif
90