summaryrefslogtreecommitdiff
path: root/src/lib/cinema_list.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-05-20 22:51:49 +0200
committerCarl Hetherington <cth@carlh.net>2024-05-06 20:42:50 +0200
commita3fcbb3a76e079a5485a0552ea5d35b8d6739116 (patch)
tree58f6476b7197c0e32b5aa3d52d0859a9b04db268 /src/lib/cinema_list.h
parenta4105c6e8dc83407abc9b12e80c958673c942888 (diff)
Use sqlite for cinema and DKDM recipient lists.
Diffstat (limited to 'src/lib/cinema_list.h')
-rw-r--r--src/lib/cinema_list.h126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/lib/cinema_list.h b/src/lib/cinema_list.h
new file mode 100644
index 000000000..c91f29476
--- /dev/null
+++ b/src/lib/cinema_list.h
@@ -0,0 +1,126 @@
+/*
+ Copyright (C) 2023 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#ifndef DCPOMATIC_CINEMA_LIST_H
+#define DCPOMATIC_CINEMA_LIST_H
+
+
+#include "id.h"
+#include "sqlite_table.h"
+#include <libcxml/cxml.h>
+#include <dcp/utc_offset.h>
+#include <boost/filesystem.hpp>
+#include <boost/optional.hpp>
+#include <sqlite3.h>
+#include <set>
+
+
+class Cinema;
+namespace dcpomatic {
+ class Screen;
+}
+class SQLiteStatement;
+
+
+class CinemaID : public ID
+{
+public:
+ CinemaID(sqlite3_int64 id)
+ : ID(id) {}
+
+ bool operator<(CinemaID const& other) const {
+ return get() < other.get();
+ }
+};
+
+
+class ScreenID : public ID
+{
+public:
+ ScreenID(sqlite3_int64 id)
+ : ID(id) {}
+
+ bool operator==(ScreenID const& other) const {
+ return get() == other.get();
+ }
+
+ bool operator!=(ScreenID const& other) const {
+ return get() != other.get();
+ }
+
+ bool operator<(ScreenID const& other) const {
+ return get() < other.get();
+ }
+};
+
+
+class CinemaList
+{
+public:
+ CinemaList();
+ CinemaList(boost::filesystem::path db_file);
+ ~CinemaList();
+
+ CinemaList(CinemaList const&) = delete;
+ CinemaList& operator=(CinemaList const&) = delete;
+
+ CinemaList(CinemaList&& other);
+ CinemaList& operator=(CinemaList&& other);
+
+ void read_legacy_file(boost::filesystem::path xml_file);
+ void read_legacy_string(std::string const& xml);
+
+ void clear();
+
+ CinemaID add_cinema(Cinema const& cinema);
+ void update_cinema(CinemaID id, Cinema const& cinema);
+ void remove_cinema(CinemaID id);
+ std::vector<std::pair<CinemaID, Cinema>> cinemas() const;
+ boost::optional<Cinema> cinema(CinemaID id) const;
+ boost::optional<std::pair<CinemaID, Cinema>> cinema_by_partial_name(std::string const& text) const;
+ boost::optional<std::pair<CinemaID, Cinema>> cinema_by_name_or_email(std::string const& text) const;
+
+ ScreenID add_screen(CinemaID cinema_id, dcpomatic::Screen const& screen);
+ void update_screen(ScreenID id, dcpomatic::Screen const& screen);
+ void remove_screen(ScreenID id);
+ boost::optional<dcpomatic::Screen> screen(ScreenID screen_id) const;
+ std::vector<std::pair<ScreenID, dcpomatic::Screen>> screens(CinemaID cinema_id) const;
+ std::vector<std::pair<ScreenID, dcpomatic::Screen>> screens_by_cinema_and_name(CinemaID id, std::string const& name) const;
+
+ boost::optional<dcp::UTCOffset> unique_utc_offset(std::set<CinemaID> const& cinemas);
+
+private:
+ dcpomatic::Screen screen_from_result(SQLiteStatement& statement, ScreenID screen_id) const;
+ std::vector<std::pair<ScreenID, dcpomatic::Screen>> screens_from_result(SQLiteStatement& statement) const;
+ void setup_tables();
+ void setup(boost::filesystem::path db_file);
+ void read_legacy_document(cxml::Document const& doc);
+
+ sqlite3* _db = nullptr;
+ SQLiteTable _cinemas;
+ SQLiteTable _screens;
+ SQLiteTable _trusted_devices;
+};
+
+
+
+#endif
+