File: chromecast.h

package info (click to toggle)
smplayer 18.10.0~ds0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 34,884 kB
  • sloc: cpp: 48,881; ansic: 16,654; makefile: 298; sh: 43
file content (143 lines) | stat: -rw-r--r-- 3,980 bytes parent folder | download
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*  smplayer, GUI front-end for mplayer.
    Copyright (C) 2006-2018 Ricardo Villalba <rvm@users.sourceforge.net>

    This program 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.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef CHROMECAST_H
#define CHROMECAST_H

#include <QString>
#include <QStringList>
#include <QProcess>

#define SERVE_FILE_DIR_ONLY
#define CONVERT_TO_VTT
#define CC_USE_TRAY_ICON

class QSettings;
class QSystemTrayIcon;
class QMenu;

class Chromecast : public QObject {
	Q_OBJECT

public:
	enum Device { DChromecast = 1, DMobile = 2 };

	Chromecast(QObject * parent = 0);
	~Chromecast();

	void setOutputDevice(Device d) { output_device = d; };
	Device outputDevice() { return output_device; };

	void openStream(const QString & url, const QString & title);
	void openLocal(const QString & file, const QString & title, const QString & subtitle = QString::null);

	static Chromecast * instance();
	static void deleteInstance();

	static QStringList localAddresses();
	static QString findLocalAddress();

	// Server settings
	void setServerPort(int port) {
		if (port != server_port) server_needs_restart = true;
		server_port = port;
	}
	int serverPort() { return server_port; };

	void setLocalAddress(const QString & address) {
		if (address != local_address) server_needs_restart = true;
		local_address = address;
	};
	QString localAddress() { return local_address; };

	void setDirectoryListing(bool enabled) {
		if (enabled != directory_listing) server_needs_restart = true;
		directory_listing = enabled;
	};
	bool directoryListing() { return directory_listing; };

	void setSettings(QSettings * set) { settings = set; loadSettings(); };

#ifdef CONVERT_TO_VTT
	void setAutoConvertToVTT(bool b) { autoconvert_to_vtt = b; };
	bool autoConvertToVTT() { return autoconvert_to_vtt; };

	void setSubtitleEncoding(const QString& encoding) { sub_encoding = encoding; };
	QString subtitleEncoding() { return sub_encoding; };

	void setSubtitlePosition(int position) { sub_position = position; };
	int subtitlePosition() { return sub_position; };

	void setSubtitleFilter(const QString & filter) { sub_filter = filter; };
	QString subtitleFilter() { return sub_filter; };

	void setOverwriteVTT(bool b) { overwrite_vtt = b; };
	bool overwriteVTT() { return overwrite_vtt; };

	void enableSubtitleFilter(bool b) { use_sub_filter = b; };
	bool isSubtitleFilterEnabled() { return use_sub_filter; };
#endif

protected:
	void startServer(QString doc_root);
	void loadSettings();
	void saveSettings();

#ifndef SERVE_FILE_DIR_ONLY
	QString filepathWithoutRoot(const QString & filepath);
#endif

	QString checkForVTT(const QString & video_path, const QString & subtitle_file);

protected slots:
	void stopServer();
	void readProcessOutput();
	void processFinished(int exit_code, QProcess::ExitStatus exit_status);
	void processError(QProcess::ProcessError error);

protected:
	QProcess * server_process;
	QSettings * settings;

	int server_port;
	QString local_address;
	bool directory_listing;

	bool server_needs_restart;

#ifdef CONVERT_TO_VTT
	bool autoconvert_to_vtt;
	QString sub_encoding;
	int sub_position;
	QString sub_filter;
	bool overwrite_vtt;
	bool use_sub_filter;
#endif

	Device output_device;

#ifdef CC_USE_TRAY_ICON
	QSystemTrayIcon * tray_icon;
	QMenu * tray_menu;
#endif

private:
	static Chromecast * instance_obj;
};

#endif