summaryrefslogtreecommitdiff
path: root/src/lib/show_playlist_list.h
blob: 0da94ba9930cd3e5cee93f3e1de658a34fed5a86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
    Copyright (C) 2025 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_SHOW_PLAYLIST_LIST_H
#define DCPOMATIC_SHOW_PLAYLIST_LIST_H


#include "show_playlist_entry.h"
#include "show_playlist_id.h"
#include "sqlite_database.h"
#include "sqlite_table.h"


class ShowPlaylist;
class SQLiteStatement;


/** @class ShowPlaylistList
 *
 *  @brief A list of SPLs (show playlists) stored in a SQLite database.
 *
 *  A SPL (show playlist) is a list of content (and maybe later automation cues)
 *  that make up a "show" in a cinema/theater.  For example, a SPL might contain
 *  some adverts, some trailers and a feature.
 *
 *  There are two tables: show_playlists and entries.  show_playlists contains
 *  just playlist UUIDs with their names.
 */
class ShowPlaylistList
{
public:
	ShowPlaylistList();
	explicit ShowPlaylistList(boost::filesystem::path db_file);

	/** Write a ShowPlaylist to the database, returning its new SQLite ID */
	ShowPlaylistID add_show_playlist(ShowPlaylist const& show_playlist);
	void update_show_playlist(ShowPlaylistID id, ShowPlaylist const& show_playlist);
	void remove_show_playlist(ShowPlaylistID id);

	std::vector<std::pair<ShowPlaylistID, ShowPlaylist>> show_playlists() const;
	boost::optional<ShowPlaylist> show_playlist(ShowPlaylistID id) const;

	boost::optional<ShowPlaylistID> get_show_playlist_id(std::string const& show_playlist_uuid) const;

	/** @return The entries on a given show playlist, given the playlist's SQLite ID */
	std::vector<ShowPlaylistEntry> entries(ShowPlaylistID show_playlist_id) const;
	/** @return The entries on a given show playlist, given the playlist's UUID */
	std::vector<ShowPlaylistEntry> entries(std::string const& show_playlist_uuid) const;

	bool missing(std::string const& show_playlist_uuid) const;
	bool missing(ShowPlaylistID id) const;

	/** Add a playlist entry to the end of a playlist in the database */
	void add_entry(ShowPlaylistID playlist_id, ShowPlaylistEntry const& entry);
	/** Insert the given playlist entry at the given index */
	void insert_entry(ShowPlaylistID playlist_id, ShowPlaylistEntry const& entry, int index);
	/** Set the values in the database from entry */
	void update_entry(ShowPlaylistID, int index, ShowPlaylistEntry const& entry);
	/** Remove a playlist entry from the database */
	void remove_entry(ShowPlaylistID, int index);
	/** Move the given playlist entry one place higher (earlier) */
	void move_entry_up(ShowPlaylistID, int index);
	/** Move the given playlist entry one place lower (later) */
	void move_entry_down(ShowPlaylistID, int index);
	/** Move the given playlist entry to the given index */
	void move_entry(ShowPlaylistID playlist_id, int old_index, int new_index);

	void read_legacy(boost::filesystem::path dir);

private:
	void setup_tables();
	void setup();
	std::vector<ShowPlaylistEntry> entries(std::string const& where, std::function<void (SQLiteStatement&)> bind) const;
	void swap_entries(ShowPlaylistID playlist_id, int index);

	SQLiteTable _show_playlists;
	SQLiteTable _entries;
	mutable SQLiteDatabase _db;
};



#endif