xref: /haiku/src/apps/codycam/CodyCam.h (revision 6a739773fceb43d72a2314eafb465d301ae36310)
1 /*
2  * Copyright 1998-1999 Be, Inc. All Rights Reserved.
3  * Copyright 2003-2019 Haiku, Inc. All rights reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef CODYCAM_H
7 #define CODYCAM_H
8 
9 
10 #include <string.h>
11 
12 #include <Application.h>
13 #include <Box.h>
14 #include <Catalog.h>
15 #include <CheckBox.h>
16 #include <Locale.h>
17 #include <Menu.h>
18 #include <MenuField.h>
19 #include <StringView.h>
20 #include <TextControl.h>
21 #include <Window.h>
22 
23 #include "Settings.h"
24 #include "VideoConsumer.h"
25 
26 
27 class BMediaRoster;
28 
29 
30 enum {
31 	msg_filename	= 'file',
32 
33 	msg_rate_changed = 'rate',
34 
35 	msg_translate	= 'tran',
36 
37 	msg_upl_client	= 'ucli',
38 	msg_server		= 'srvr',
39 	msg_login		= 'lgin',
40 	msg_password	= 'pswd',
41 	msg_directory	= 'drct',
42 	msg_passiveftp	= 'pasv',
43 	msg_pswrd_text	= 'pstx',
44 
45 	msg_start		= 'strt',
46 	msg_stop		= 'stop',
47 
48 	msg_setup		= 'setp',
49 	msg_video		= 'vdeo',
50 
51 	msg_control_win = 'ctlw'
52 };
53 
54 
55 struct capture_rate {
56 	const char* name;
57 	time_t		seconds;
58 };
59 
60 
61 // NOTE: These are translated once the app catalog is loaded.
62 capture_rate kCaptureRates[] = {
63 	{"Every 15 seconds", 15 },
64 	{"Every 30 seconds", 30 },
65 	{"Every minute", 60 },
66 	{"Every 5 minutes", 5 * 60 },
67 	{"Every 10 minutes", 10 * 60 },
68 	{"Every 15 minutes", 15 * 60 },
69 	{"Every 30 minutes", 30 * 60 },
70 	{"Every hour", 60 * 60 },
71 	{"Every 2 hours", 2 * 60 * 60 },
72 	{"Every 4 hours", 4 * 60 * 60 },
73 	{"Every 8 hours", 8 * 60 * 60 },
74 	{"Every 24 hours", 24 * 60 * 60 },
75 	{"Never", 0 }
76 };
77 
78 
79 const int32 kCaptureRatesCount = sizeof(kCaptureRates) / sizeof(capture_rate);
80 
81 
82 const char* kUploadClients[] = {
83 	// NOTE: These are translated once the app catalog is loaded.
84 	"FTP",
85 	"SFTP",
86 	"Local"
87 };
88 
89 
90 const int32 kUploadClientsCount = sizeof(kUploadClients) / sizeof(char*);
91 
92 class VideoWindow;
93 class ControlWindow;
94 
95 class CodyCam : public BApplication {
96 public:
97 							CodyCam();
98 	virtual					~CodyCam();
99 
100 			void			ReadyToRun();
101 	virtual	bool			QuitRequested();
102 	virtual	void			MessageReceived(BMessage* message);
103 
104 private:
105 			status_t		_SetUpNodes();
106 			void			_TearDownNodes();
107 
108 			BMediaRoster*	fMediaRoster;
109 			media_node		fTimeSourceNode;
110 			media_node		fProducerNode;
111 			VideoConsumer*	fVideoConsumer;
112 			media_output	fProducerOut;
113 			media_input		fConsumerIn;
114 			VideoWindow*	fWindow;
115 			port_id			fPort;
116 			ControlWindow*	fVideoControlWindow;
117 };
118 
119 
120 class VideoWindow : public BWindow {
121 public:
122 							VideoWindow(const char* title,
123 								window_type type, uint32 flags,
124 								port_id* consumerport);
125 							~VideoWindow();
126 
127 	virtual	bool			QuitRequested();
128 	virtual	void			MessageReceived(BMessage* message);
129 
130 			void			ApplyControls();
131 
132 			BView*			VideoView();
133 			BStringView*	StatusLine();
134 			void			ToggleMenuOnOff();
135 
136 			void			ErrorAlert(const char*, status_t);
137 
138 private:
139 			void			_BuildCaptureControls();
140 
141 			void			_SetUpSettings(const char* filename,
142 								const char* dirname);
143 			void			_UploadClientChanged();
144 			void			_QuitSettings();
145 
146 private:
147 			media_node*		fProducer;
148 			port_id*		fPortPtr;
149 
150 			BView*			fVideoView;
151 			BTextView*		fErrorView;
152 
153 			BTextControl*	fFileName;
154 			BBox*			fCaptureSetupBox;
155 			BMenu*			fCaptureRateMenu;
156 			BMenuField*		fCaptureRateSelector;
157 			BMenu*			fImageFormatMenu;
158 			BMenuField*		fImageFormatSelector;
159 			BMenu*			fUploadClientMenu;
160 			BMenuField*		fUploadClientSelector;
161 			BBox*			fFtpSetupBox;
162 			BTextControl*	fServerName;
163 			BTextControl*	fLoginId;
164 			BTextControl*	fPassword;
165 			BTextControl*	fDirectory;
166 			BCheckBox*		fPassiveFtp;
167 			BBox*			fStatusBox;
168 			BStringView*	fStatusLine;
169 
170 			ftp_msg_info	fFtpInfo;
171 
172 			Settings*		fSettings;
173 
174 			BMenu* 			fMenu;
175 
176 			StringValueSetting*		fServerSetting;
177 			StringValueSetting*		fLoginSetting;
178 			StringValueSetting*		fPasswordSetting;
179 			StringValueSetting*		fDirectorySetting;
180 			BooleanValueSetting*	fPassiveFtpSetting;
181 			StringValueSetting*		fFilenameSetting;
182 			StringValueSetting*		fImageFormatSettings;
183 
184 			EnumeratedStringValueSetting*	fUploadClientSetting;
185 			EnumeratedStringValueSetting*	fCaptureRateSetting;
186 };
187 
188 
189 class ControlWindow : public BWindow {
190 public:
191 							ControlWindow(BView* controls,
192 								media_node node);
193 			void			MessageReceived(BMessage* message);
194 			bool			QuitRequested();
195 
196 private:
197 			BView*			fView;
198 			media_node		fNode;
199 };
200 
201 #endif	// CODYCAM_H
202