135 changes: 6 additions & 129 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,12 @@ using namespace std;
// libmythui headers
#include "myththemebase.h"
#include "screensaver.h"
#include "lirc.h"
#include "lircevent.h"
#include "mythudplistener.h"
#include "mythrender_base.h"
#include "mythuistatetracker.h"
#include "mythuiactions.h"
#include "mythrect.h"
#include "mythdisplay.h"

#ifdef USING_APPLEREMOTE
#include "AppleRemoteListener.h"
#endif

#include "mythscreentype.h"
#include "mythpainter.h"
#include "mythpainterwindow.h"
Expand Down Expand Up @@ -155,7 +148,6 @@ MythMainWindow::MythMainWindow(const bool useDB)

//Init();

d->m_ignoreLircKeys = false;
d->m_exitingtomain = false;
d->m_popwindows = true;
d->m_exitMenuCallback = nullptr;
Expand All @@ -166,29 +158,6 @@ MythMainWindow::MythMainWindow(const bool useDB)

installEventFilter(this);

d->m_lircThread = nullptr;
StartLIRC();

#ifdef USING_APPLEREMOTE
d->m_appleRemoteListener = new AppleRemoteListener(this);
d->m_appleRemote = AppleRemote::Get();

d->m_appleRemote->setListener(d->m_appleRemoteListener);
d->m_appleRemote->startListening();
if (d->m_appleRemote->isListeningToRemote())
{
d->m_appleRemote->start();
}
else
{
// start listening failed, no remote receiver present
delete d->m_appleRemote;
delete d->m_appleRemoteListener;
d->m_appleRemote = nullptr;
d->m_appleRemoteListener = nullptr;
}
#endif

d->m_udpListener = new MythUDPListener();

InitKeys();
Expand Down Expand Up @@ -261,19 +230,6 @@ MythMainWindow::~MythMainWindow()
delete context;
}

#ifdef USE_LIRC
if (d->m_lircThread)
{
d->m_lircThread->deleteLater();
d->m_lircThread = nullptr;
}
#endif

#ifdef USING_APPLEREMOTE
delete d->m_appleRemote;
delete d->m_appleRemoteListener;
#endif

m_deviceHandler.Stop();

delete d->m_nc;
Expand Down Expand Up @@ -657,16 +613,8 @@ bool MythMainWindow::event(QEvent *e)
return true;
}

#ifdef USING_APPLEREMOTE
if (d->m_appleRemote)
{
if (e->type() == QEvent::WindowActivate)
d->m_appleRemote->startListening();

if (e->type() == QEvent::WindowDeactivate)
d->m_appleRemote->stopListening();
}
#endif
if ((e->type() == QEvent::WindowActivate) || (e->type() == QEvent::WindowDeactivate))
m_deviceHandler.Event(e);

return QWidget::event(e);
}
Expand Down Expand Up @@ -2029,38 +1977,6 @@ void MythMainWindow::customEvent(QEvent *ce)
else
QCoreApplication::sendEvent(key_target, &key);
}
#if defined(USE_LIRC) || defined(USING_APPLEREMOTE)
else if (ce->type() == LircKeycodeEvent::kEventType &&
!d->m_ignoreLircKeys)
{
auto *lke = dynamic_cast<LircKeycodeEvent *>(ce);
if (lke == nullptr)
return;

if (LircKeycodeEvent::kLIRCInvalidKeyCombo == lke->modifiers())
{
LOG(VB_GENERAL, LOG_WARNING,
QString("Attempt to convert LIRC key sequence '%1' "
"to a Qt key sequence failed.")
.arg(lke->lirctext()));
}
else
{
MythUIHelper::ResetScreensaver();
if (GetMythUI()->GetScreenIsAsleep())
return;

QKeyEvent key(lke->keytype(), lke->key(),
lke->modifiers(), lke->text());

QObject *key_target = getTarget(key);
if (!key_target)
QCoreApplication::sendEvent(this, &key);
else
QCoreApplication::sendEvent(key_target, &key);
}
}
#endif
else if (ce->type() == MythMediaEvent::kEventType)
{
auto *me = dynamic_cast<MythMediaEvent*>(ce);
Expand Down Expand Up @@ -2139,12 +2055,12 @@ void MythMainWindow::customEvent(QEvent *ce)
}
else if (ce->type() == MythEvent::kLockInputDevicesEventType)
{
LockInputDevices(true);
m_deviceHandler.IgnoreKeys(true);
PauseIdleTimer(true);
}
else if (ce->type() == MythEvent::kUnlockInputDevicesEventType)
{
LockInputDevices(false);
m_deviceHandler.IgnoreKeys(false);
PauseIdleTimer(false);
}
else if (ce->type() == MythEvent::kDisableUDPListenerEventType)
Expand Down Expand Up @@ -2378,48 +2294,9 @@ int MythMainWindow::GetDrawInterval() const
return d->m_drawInterval;
}

void MythMainWindow::StartLIRC(void)
{
#ifdef USE_LIRC
if (d->m_lircThread)
{
d->m_lircThread->deleteLater();
d->m_lircThread = nullptr;
}

QString config_file = GetConfDir() + "/lircrc";
if (!QFile::exists(config_file))
config_file = QDir::homePath() + "/.lircrc";

/* lircd socket moved from /dev/ to /var/run/lirc/ in lirc 0.8.6 */
QString lirc_socket = "/dev/lircd";
if (!QFile::exists(lirc_socket))
lirc_socket = "/var/run/lirc/lircd";

d->m_lircThread = new LIRC(
this,
GetMythDB()->GetSetting("LircSocket", lirc_socket),
"mythtv", config_file);

if (d->m_lircThread->Init())
{
d->m_lircThread->start();
}
else
{
d->m_lircThread->deleteLater();
d->m_lircThread = nullptr;
}
#endif
}

void MythMainWindow::LockInputDevices( bool locked )
void MythMainWindow::RestartInputHandlers(void)
{
#ifdef USE_LIRC
d->m_ignoreLircKeys = locked;
#endif

m_deviceHandler.IgnoreKeys(locked);
m_deviceHandler.Reset();
}

void MythMainWindow::ShowMouseCursor(bool show)
Expand Down
8 changes: 1 addition & 7 deletions mythtv/libs/libmythui/mythmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class MUI_PUBLIC MythMainWindow : public QWidget
int NormX(int x);
int NormY(int y);
void SetScalingFactors(float wmult, float hmult);
void StartLIRC(void);
void RestartInputHandlers(void);
uint PushDrawDisabled(void);
uint PopDrawDisabled(void);
void SetEffectsEnabled(bool enable);
Expand Down Expand Up @@ -158,15 +158,9 @@ class MUI_PUBLIC MythMainWindow : public QWidget
bool eventFilter(QObject *o, QEvent *e) override; // QWidget
void customEvent(QEvent *ce) override; // QWidget
void closeEvent(QCloseEvent *e) override; // QWidget

void drawScreen(QPaintEvent* Event = nullptr);

bool event(QEvent* e) override; // QWidget

void ExitToMainMenu();

void LockInputDevices(bool locked);

void ShowMouseCursor(bool show);

MythMainWindowPrivate *d {nullptr}; // NOLINT(readability-identifier-naming)
Expand Down
15 changes: 0 additions & 15 deletions mythtv/libs/libmythui/mythmainwindowprivate.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
#ifndef MYTHMAINWINDOWPRIVATE_H
#define MYTHMAINWINDOWPRIVATE_H

// Qt
#include <QKeyEvent>

// MythTV
#include "mythconfig.h"
#include "mythmainwindow.h"
#include "mythgesture.h"

#ifdef USING_APPLEREMOTE
#include "AppleRemoteListener.h"
#endif

class MythScreenStack;
class MythSignalingTimer;
class MythThemeBase;
class MythUDPListener;
class LIRC;
class MythMediaDevice;

class KeyContext
Expand Down Expand Up @@ -69,13 +61,6 @@ class MythMainWindowPrivate
QRect m_screenRect;
QRect m_uiScreenRect;
bool m_doesFillScreen { false };
bool m_ignoreLircKeys { false };
LIRC *m_lircThread { nullptr };
#ifdef USING_APPLEREMOTE
AppleRemoteListener *m_appleRemoteListener { nullptr };
AppleRemote *m_appleRemote { nullptr };
#endif

bool m_exitingtomain { false };
bool m_popwindows { false };
/// To allow or prevent database access
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythfrontend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ void handleSIGUSR1(void)
void handleSIGUSR2(void)
{
LOG(VB_GENERAL, LOG_INFO, "Restarting LIRC handler");
GetMythMainWindow()->StartLIRC();
GetMythMainWindow()->RestartInputHandlers();
}

#include "main.moc"
Expand Down