3 * Copyright (C) 2016-2020 William Morrow
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 #include "mainsession.h"
24 #include "mwindowgui.h"
26 #include "remotecontrol.h"
29 RemoteWindow::RemoteWindow(RemoteControl *remote_control)
30 : BC_Window(_(PROGRAM_NAME ": RemoteWindow"),
31 0, 0, xS(16), yS(16), -1, -1, 1, 0, 1)
33 this->remote_control = remote_control;
34 // *** CONTEXT_HELP ***
35 context_help_set_keyword("Remote Control for DVB");
38 RemoteWindow::~RemoteWindow()
43 RemoteControl::RemoteControl(MWindowGUI *mwindow_gui)
46 this->mwindow_gui = mwindow_gui;
48 active_lock = new Mutex("RemoteControl::active_lock");
50 remote_window = new RemoteWindow(this);
52 remote_window->init_wait();
53 gui = new RemoteGUI(remote_window, this);
56 void RemoteControl::run()
58 remote_window->run_window();
61 RemoteControl::~RemoteControl()
63 if( Thread::running() ) {
64 remote_window->close(1);
74 int RemoteControl::activate(RemoteHandler *handler)
79 handler = !mwindow_gui->record->running() ?
80 (RemoteHandler *)mwindow_gui->cwindow_remote_handler :
81 (RemoteHandler *)mwindow_gui->record_remote_handler ;
82 active_lock->lock("RemoteControl::activate");
84 gui->lock_window("RemoteControl::activate");
85 gui->set_active(handler);
86 gui->set_color(handler->color);
87 gui->fill_color(handler->color);
91 active_lock->unlock();
95 int RemoteControl::deactivate()
99 active_lock->lock("RemoteControl::deactivate");
104 active_lock->unlock();
109 int RemoteControl::remote_key(int key)
111 if( !is_active() ) return 0;
112 return handler->remote_key(key);
115 void RemoteControl::set_color(int color)
117 gui->lock_window("RemoteControl::fill_color");
118 gui->set_color(color);
119 gui->unlock_window();
122 void RemoteControl::fill_color(int color)
124 gui->lock_window("RemoteControl::fill_color");
125 gui->fill_color(color);
126 gui->unlock_window();
129 RemoteGUI::RemoteGUI(BC_WindowBase *wdw, RemoteControl *remote_control)
130 : BC_Popup(wdw, remote_control->mwindow_gui->mwindow->session->mwindow_x,0,
131 xS(16),yS(16), -1, 1)
133 this->remote_control = remote_control;
136 RemoteGUI::~RemoteGUI()
140 void RemoteGUI::set_active(RemoteHandler *handler)
142 remote_control->handler = handler;
147 void RemoteGUI::set_inactive()
149 remote_control->handler = 0;
155 fill_color(int color)
158 draw_box(0, 0, get_w(), get_h());
162 void RemoteGUI::tile_windows(int config)
164 MWindow *mwindow = remote_control->mwindow_gui->mwindow;
165 if( config == mwindow->session->window_config ) return;
166 lock_window("RemoteGUI::tile_windows");
167 ungrab_keyboard(); hide_window();
168 mwindow->gui->lock_window("RemoteGUI::tile_windows 1");
169 int need_reload = mwindow->tile_windows(config);
170 mwindow->gui->unlock_window();
172 show_window(); raise_window(); grab_keyboard();
173 reposition_window(mwindow->session->mwindow_x,0);
178 mwindow->restart_status = 1;
183 int RemoteGUI::button_press_event()
185 remote_control->deactivate();
189 int RemoteGUI::keypress_event()
191 int key = get_keypress();
192 int result = remote_control->remote_key(key);
194 remote_control->deactivate();
200 RemoteHandler::RemoteHandler(RemoteGUI *gui, int color)
206 RemoteHandler::~RemoteHandler()
210 int RemoteHandler::remote_key(int key)
216 int RemoteHandler::process_key(int key)