Commit 4b18da10 authored by Eike Hein's avatar Eike Hein
Browse files

Redo version checking approach for activity/silence monitoring.

Due to moc's limitations we end up having non-useful slots in the
D-Bus interface on <4.7.1. Unfortunately it's not possible to
toggle the scriptable flag on a QMetaMethod at runtime, and
QDBusConnection::registerObject() can't deal with an OR'd combo
of ExportScriptableSlots and ExportAdaptors, so it's not possible
to stuff the extra slots into a QDBusAbstractAdaptor subclass
either. I stopped short of duplicating the entire object inter-
face plus extra slots in an adaptor to toggle between the two at
runtime - as much as I hate sloppy D-Bus interfaces, that would
just be too ugly in terms of code. Maybe I'll find an acceptable
way later.
parent f8a2769e
......@@ -450,13 +450,11 @@ void MainWindow::handleContextDependentToggleAction(bool checked, QAction* actio
if (action == actionCollection()->action("toggle-session-keyboard-input"))
m_sessionStack->setSessionKeyboardInputEnabled(sessionId, !checked);
#if KDE_IS_VERSION(4, 7, 1)
if (action == actionCollection()->action("toggle-session-monitor-activity"))
m_sessionStack->setSessionMonitorActivityEnabled(sessionId, checked);
if (action == actionCollection()->action("toggle-session-monitor-silence"))
m_sessionStack->setSessionMonitorSilenceEnabled(sessionId, checked);
#endif
}
void MainWindow::setContextDependentActionsQuiet(bool quiet)
......@@ -479,7 +477,6 @@ void MainWindow::handleToggleTerminalKeyboardInput(bool checked)
m_sessionStack->setTerminalKeyboardInputEnabled(terminalId, !checked);
}
#if KDE_IS_VERSION(4, 7, 1)
void MainWindow::handleToggleTerminalMonitorActivity(bool checked)
{
QAction* action = qobject_cast<QAction*>(QObject::sender());
......@@ -535,7 +532,6 @@ void MainWindow::handleTerminalSilence(Terminal* terminal)
KNotification::CloseWhenWidgetActivated);
}
}
#endif
void MainWindow::handleSwitchToAction()
{
......
......@@ -74,14 +74,11 @@ class MainWindow : public KMainWindow
void handleContextDependentAction(QAction* action = 0, int sessionId = -1);
void handleContextDependentToggleAction(bool checked, QAction* action = 0, int sessionId = -1);
void handleToggleTerminalKeyboardInput(bool checked);
#if KDE_IS_VERSION(4, 7, 1)
void handleToggleTerminalMonitorActivity(bool checked);
void handleToggleTerminalMonitorSilence(bool checked);
void handleTerminalActivity(Terminal* terminal);
void handleTerminalSilence(Terminal* terminal);
#endif
signals:
void windowOpened();
......
......@@ -162,9 +162,7 @@ Terminal* Session::addTerminal(QWidget* parent)
connect(terminal, SIGNAL(manuallyActivated(Terminal*)), this, SIGNAL(terminalManuallyActivated(Terminal*)));
connect(terminal, SIGNAL(titleChanged(int,QString)), this, SLOT(setTitle(int,QString)));
connect(terminal, SIGNAL(keyboardInputBlocked(Terminal*)), this, SIGNAL(keyboardInputBlocked(Terminal*)));
#if KDE_IS_VERSION(4, 7, 1)
connect(terminal, SIGNAL(silenceDetected(Terminal*)), this, SIGNAL(silenceDetected(Terminal*)));
#endif
connect(terminal, SIGNAL(destroyed(int)), this, SLOT(cleanup(int)));
m_terminals.insert(terminal->id(), terminal);
......@@ -521,7 +519,6 @@ bool Session::hasTerminalsWithKeyboardInputDisabled()
return false;
}
#if KDE_IS_VERSION(4, 7, 1)
bool Session::monitorActivityEnabled()
{
int monitorActivityEnabledCount = 0;
......@@ -568,6 +565,7 @@ void Session::setMonitorActivityEnabled(int terminalId, bool enabled)
void Session::reconnectMonitorActivitySignals()
{
#if KDE_IS_VERSION(4, 7, 1)
QMapIterator<int, Terminal*> i(m_terminals);
while (i.hasNext())
......@@ -577,6 +575,7 @@ void Session::reconnectMonitorActivitySignals()
connect(i.value(), SIGNAL(activityDetected(Terminal*)), this, SIGNAL(activityDetected(Terminal*)),
Qt::UniqueConnection);
}
#endif
}
bool Session::monitorSilenceEnabled()
......@@ -617,4 +616,3 @@ void Session::setMonitorSilenceEnabled(int terminalId, bool enabled)
m_terminals.value(terminalId)->setMonitorSilenceEnabled(enabled);
}
#endif
......@@ -65,7 +65,6 @@ class Session : public QObject
void setKeyboardInputEnabled(int terminalId, bool enabled);
bool hasTerminalsWithKeyboardInputDisabled();
#if KDE_IS_VERSION(4, 7, 1)
bool monitorActivityEnabled();
void setMonitorActivityEnabled(bool enabled);
bool monitorActivityEnabled(int terminalId);
......@@ -75,7 +74,6 @@ class Session : public QObject
void setMonitorSilenceEnabled(bool enabled);
bool monitorSilenceEnabled(int terminalId);
void setMonitorSilenceEnabled(int terminalId, bool enabled);
#endif
public slots:
......@@ -94,9 +92,7 @@ class Session : public QObject
void manageProfiles();
void editProfile();
#if KDE_IS_VERSION(4, 7, 1)
void reconnectMonitorActivitySignals();
#endif
signals:
......
......@@ -32,7 +32,8 @@
SessionStack::SessionStack(QWidget* parent) : QStackedWidget(parent)
{
QDBusConnection::sessionBus().registerObject("/yakuake/sessions", this, QDBusConnection::ExportScriptableSlots);
QDBusConnection::sessionBus().registerObject("/yakuake/sessions", this,
QDBusConnection::ExportAdaptors | QDBusConnection::ExportScriptableSlots);
m_activeSessionId = -1;
......@@ -50,11 +51,9 @@ int SessionStack::addSession(Session::SessionType type)
connect(session, SIGNAL(titleChanged(int,QString)), this, SIGNAL(titleChanged(int,QString)));
connect(session, SIGNAL(terminalManuallyActivated(Terminal*)), this, SLOT(handleManualTerminalActivation(Terminal*)));
connect(session, SIGNAL(keyboardInputBlocked(Terminal*)), m_visualEventOverlay, SLOT(indicateKeyboardInputBlocked(Terminal*)));
#if KDE_IS_VERSION(4, 7, 1)
connect(session, SIGNAL(activityDetected(Terminal*)), parentWidget(), SLOT(handleTerminalActivity(Terminal*)));
connect(session, SIGNAL(silenceDetected(Terminal*)), parentWidget(), SLOT(handleTerminalSilence(Terminal*)));
connect(parentWidget(), SIGNAL(windowClosed()), session, SLOT(reconnectMonitorActivitySignals()));
#endif
connect(session, SIGNAL(destroyed(int)), this, SLOT(cleanup(int)));
addWidget(session->widget());
......@@ -103,9 +102,7 @@ void SessionStack::raiseSession(int sessionId)
disconnect(oldActiveSession, SIGNAL(titleChanged(QString)),
this, SIGNAL(activeTitleChanged(QString)));
#if KDE_IS_VERSION(4, 7, 1)
oldActiveSession->reconnectMonitorActivitySignals();
#endif
}
m_activeSessionId = sessionId;
......@@ -347,79 +344,121 @@ void SessionStack::setTerminalKeyboardInputEnabled(int terminalId, bool enabled)
}
}
#if KDE_IS_VERSION(4, 7, 1)
bool SessionStack::isSessionMonitorActivityEnabled(int sessionId)
{
#if KDE_IS_VERSION(4, 7, 1)
if (sessionId == -1) sessionId = m_activeSessionId;
if (sessionId == -1) return false;
if (!m_sessions.contains(sessionId)) return false;
return m_sessions.value(sessionId)->monitorActivityEnabled();
#else
Q_UNUSED(sessionId);
return false;
#endif
}
void SessionStack::setSessionMonitorActivityEnabled(int sessionId, bool enabled)
{
#if KDE_IS_VERSION(4, 7, 1)
if (sessionId == -1) sessionId = m_activeSessionId;
if (sessionId == -1) return;
if (!m_sessions.contains(sessionId)) return;
m_sessions.value(sessionId)->setMonitorActivityEnabled(enabled);
#else
Q_UNUSED(sessionId);
Q_UNUSED(enabled);
#endif
}
bool SessionStack::isTerminalMonitorActivityEnabled(int terminalId)
{
#if KDE_IS_VERSION(4, 7, 1)
int sessionId = sessionIdForTerminalId(terminalId);
if (sessionId == -1) return false;
if (!m_sessions.contains(sessionId)) return false;
return m_sessions.value(sessionId)->monitorActivityEnabled(terminalId);
#else
Q_UNUSED(terminalId);
return false;
#endif
}
void SessionStack::setTerminalMonitorActivityEnabled(int terminalId, bool enabled)
{
#if KDE_IS_VERSION(4, 7, 1)
int sessionId = sessionIdForTerminalId(terminalId);
if (sessionId == -1) return;
if (!m_sessions.contains(sessionId)) return;
m_sessions.value(sessionId)->setMonitorActivityEnabled(terminalId, enabled);
#else
Q_UNUSED(terminalId);
Q_UNUSED(enabled);
#endif
}
bool SessionStack::isSessionMonitorSilenceEnabled(int sessionId)
{
#if KDE_IS_VERSION(4, 7, 1)
if (sessionId == -1) sessionId = m_activeSessionId;
if (sessionId == -1) return false;
if (!m_sessions.contains(sessionId)) return false;
return m_sessions.value(sessionId)->monitorSilenceEnabled();
#else
Q_UNUSED(sessionId);
return false;
#endif
}
void SessionStack::setSessionMonitorSilenceEnabled(int sessionId, bool enabled)
{
#if KDE_IS_VERSION(4, 7, 1)
if (sessionId == -1) sessionId = m_activeSessionId;
if (sessionId == -1) return;
if (!m_sessions.contains(sessionId)) return;
m_sessions.value(sessionId)->setMonitorSilenceEnabled(enabled);
#else
Q_UNUSED(sessionId);
Q_UNUSED(enabled);
#endif
}
bool SessionStack::isTerminalMonitorSilenceEnabled(int terminalId)
{
#if KDE_IS_VERSION(4, 7, 1)
int sessionId = sessionIdForTerminalId(terminalId);
if (sessionId == -1) return false;
if (!m_sessions.contains(sessionId)) return false;
return m_sessions.value(sessionId)->monitorSilenceEnabled(terminalId);
#else
Q_UNUSED(terminalId);
return false;
#endif
}
void SessionStack::setTerminalMonitorSilenceEnabled(int terminalId, bool enabled)
{
#if KDE_IS_VERSION(4, 7, 1)
int sessionId = sessionIdForTerminalId(terminalId);
if (sessionId == -1) return;
if (!m_sessions.contains(sessionId)) return;
m_sessions.value(sessionId)->setMonitorSilenceEnabled(terminalId, enabled);
}
#else
Q_UNUSED(terminalId);
Q_UNUSED(enabled);
#endif
}
void SessionStack::editProfile(int sessionId)
{
......
......@@ -93,7 +93,6 @@ class SessionStack : public QStackedWidget
Q_SCRIPTABLE bool isTerminalKeyboardInputEnabled(int terminalId);
Q_SCRIPTABLE void setTerminalKeyboardInputEnabled(int terminalId, bool enabled);
#if KDE_IS_VERSION(4, 7, 1)
Q_SCRIPTABLE bool isSessionMonitorActivityEnabled(int sessionId);
Q_SCRIPTABLE void setSessionMonitorActivityEnabled(int sessionId, bool enabled);
Q_SCRIPTABLE bool isTerminalMonitorActivityEnabled(int terminalId);
......@@ -103,7 +102,6 @@ class SessionStack : public QStackedWidget
Q_SCRIPTABLE void setSessionMonitorSilenceEnabled(int sessionId, bool enabled);
Q_SCRIPTABLE bool isTerminalMonitorSilenceEnabled(int terminalId);
Q_SCRIPTABLE void setTerminalMonitorSilenceEnabled(int terminalId, bool enabled);
#endif
void handleTerminalHighlightRequest(int terminalId);
......
......@@ -66,10 +66,8 @@ TabBar::TabBar(MainWindow* mainWindow) : QWidget(mainWindow)
connect(m_tabContextMenu, SIGNAL(hovered(QAction*)), this, SLOT(contextMenuActionHovered(QAction*)));
m_toggleKeyboardInputMenu = new KMenu(i18nc("@title:menu", "Disable Keyboard Input"), this);
#if KDE_IS_VERSION(4, 7, 1)
m_toggleMonitorActivityMenu = new KMenu(i18nc("@title:menu", "Monitor for Activity"), this);
m_toggleMonitorSilenceMenu = new KMenu(i18nc("@title:menu", "Monitor for Silence"), this);
#endif
m_sessionMenu = new KMenu(this);
connect(m_sessionMenu, SIGNAL(aboutToShow()), this, SLOT(readySessionMenu()));
......@@ -237,7 +235,6 @@ void TabBar::updateToggleKeyboardInputMenu(int sessionId)
}
}
#if KDE_IS_VERSION(4, 7, 1)
void TabBar::updateToggleMonitorActivityMenu(int sessionId)
{
if (!m_tabs.contains(sessionId)) return;
......@@ -333,7 +330,6 @@ void TabBar::updateToggleMonitorSilenceMenu(int sessionId)
}
}
}
#endif
void TabBar::contextMenuActionHovered(QAction* action)
{
......
......@@ -120,10 +120,8 @@ class TabBar : public QWidget
void updateMoveActions(int index);
void updateToggleActions(int sessionId);
void updateToggleKeyboardInputMenu(int sessionId = -1);
#if KDE_IS_VERSION(4, 7, 1)
void updateToggleMonitorSilenceMenu(int sessionId = -1);
void updateToggleMonitorActivityMenu(int sessionId = -1);
#endif
int drawButton(int x, int y, int index, QPainter& painter);
......@@ -140,10 +138,8 @@ class TabBar : public QWidget
KMenu* m_tabContextMenu;
KMenu* m_toggleKeyboardInputMenu;
#if KDE_IS_VERSION(4, 7, 1)
KMenu* m_toggleMonitorActivityMenu;
KMenu* m_toggleMonitorSilenceMenu;
#endif
KMenu* m_sessionMenu;
KLineEdit* m_lineEdit;
......
......@@ -49,10 +49,8 @@ Terminal::Terminal(QWidget* parent) : QObject(parent)
m_keyboardInputEnabled = true;
#if KDE_IS_VERSION(4, 7, 1)
m_monitorActivityEnabled = false;
m_monitorSilenceEnabled = false;
#endif
m_part = NULL;
m_terminalInterface = NULL;
......@@ -249,7 +247,6 @@ void Terminal::overrideShortcut(QKeyEvent* /* event */, bool& override)
override = false;
}
#if KDE_IS_VERSION(4, 7, 1)
void Terminal::setMonitorActivityEnabled(bool enabled)
{
m_monitorActivityEnabled = enabled;
......@@ -301,4 +298,3 @@ void Terminal::silenceDetected()
{
emit silenceDetected(this);
}
#endif
......@@ -58,13 +58,11 @@ class Terminal : public QObject
bool keyboardInputEnabled() { return m_keyboardInputEnabled; }
void setKeyboardInputEnabled(bool enabled) { m_keyboardInputEnabled = enabled; }
#if KDE_IS_VERSION(4, 7, 1)
bool monitorActivityEnabled() { return m_monitorActivityEnabled; }
void setMonitorActivityEnabled(bool enabled);
bool monitorSilenceEnabled() { return m_monitorSilenceEnabled; }
void setMonitorSilenceEnabled(bool enabled);
#endif
void deletePart();
......@@ -82,10 +80,8 @@ class Terminal : public QObject
private slots:
void setTitle(const QString& title);
void overrideShortcut(QKeyEvent* event, bool& override);
#if KDE_IS_VERSION(4, 7, 1)
void silenceDetected();
void activityDetected();
#endif
private:
......@@ -106,10 +102,8 @@ class Terminal : public QObject
bool m_keyboardInputEnabled;
#if KDE_IS_VERSION(4, 7, 1)
bool m_monitorActivityEnabled;
bool m_monitorSilenceEnabled;
#endif
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment