summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
Diffstat (limited to 'vcl')
-rw-r--r--vcl/unx/generic/window/screensaverinhibitor.cxx159
1 files changed, 62 insertions, 97 deletions
diff --git a/vcl/unx/generic/window/screensaverinhibitor.cxx b/vcl/unx/generic/window/screensaverinhibitor.cxx
index 4ac63fe5750e..b352c1d2e862 100644
--- a/vcl/unx/generic/window/screensaverinhibitor.cxx
+++ b/vcl/unx/generic/window/screensaverinhibitor.cxx
@@ -37,11 +37,15 @@ void ScreenSaverInhibitor::inhibit( bool bInhibit, const OUString& sReason, bool
}
}
-void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason )
+void dbusInhibit( bool bInhibit,
+ const gchar* service, const gchar* path, const gchar* interface,
+ std::function<bool( DBusGProxy*, guint&, GError*& )> fInhibit,
+ std::function<bool( DBusGProxy*, const guint, GError*& )> fUnInhibit,
+ boost::optional<guint>& rCookie )
{
#ifdef ENABLE_DBUS
- if ( ( !bInhibit && ( mnFDOCookie == boost::none ) ) ||
- ( bInhibit && ( mnFDOCookie != boost::none ) ) )
+ if ( ( !bInhibit && ( rCookie == boost::none ) ) ||
+ ( bInhibit && ( rCookie != boost::none ) ) )
{
return;
}
@@ -58,46 +62,36 @@ void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, cons
}
proxy = dbus_g_proxy_new_for_name( session_connection,
- FDO_DBUS_SERVICE,
- FDO_DBUS_PATH,
- FDO_DBUS_INTERFACE );
+ service,
+ path,
+ interface );
if (proxy == NULL) {
- SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " FDO_DBUS_SERVICE );
+ SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " << service );
return;
}
if ( bInhibit )
{
guint nCookie;
- res = dbus_g_proxy_call( proxy,
- "Inhibit", &error,
- G_TYPE_STRING, appname,
- G_TYPE_STRING, reason,
- G_TYPE_INVALID,
- G_TYPE_UINT, &nCookie,
- G_TYPE_INVALID);
+ res = fInhibit( proxy, nCookie, error );
+
if (res)
{
- mnFDOCookie = nCookie;
+ rCookie = nCookie;
}
else
{
- SAL_INFO( "vcl.screensaverinhibitor", FDO_DBUS_SERVICE ".Inhibit failed");
+ SAL_INFO( "vcl.screensaverinhibitor", service << ".Inhibit failed");
}
}
else
{
- res = dbus_g_proxy_call (proxy,
- "UnInhibit",
- &error,
- G_TYPE_UINT, mnFDOCookie.get(),
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- mnFDOCookie = boost::none;
+ res = fUnInhibit( proxy, rCookie.get(), error );
+ rCookie = boost::none;
if (!res)
{
- SAL_INFO( "vcl.screensaverinhibitor", FDO_DBUS_SERVICE ".UnInhibit failed" );
+ SAL_INFO( "vcl.screensaverinhibitor", service << ".UnInhibit failed" );
}
}
@@ -112,81 +106,52 @@ void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, cons
#endif // ENABLE_DBUS
}
-void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, const guint xid )
+void ScreenSaverInhibitor::inhibitFDO( bool bInhibit, const gchar* appname, const gchar* reason )
{
-#ifdef ENABLE_DBUS
- if ( ( !bInhibit && ( mnGSMCookie == boost::none ) ) ||
- ( bInhibit && ( mnGSMCookie != boost::none ) ) )
- {
- return;
- }
-
- gboolean res;
- GError *error = NULL;
- DBusGProxy *proxy = NULL;
-
- DBusGConnection *session_connection = dbus_g_bus_get( DBUS_BUS_SESSION, &error );
- if (error != NULL) {
- SAL_WARN( "vcl.screensaverinhibitor", "failed to connect to dbus session bus: " << error->message );
- g_error_free( error );
- return;
- }
-
- proxy = dbus_g_proxy_new_for_name( session_connection,
- GSM_DBUS_SERVICE,
- GSM_DBUS_PATH,
- GSM_DBUS_INTERFACE );
- if (proxy == NULL) {
- SAL_INFO( "vcl.screensaverinhibitor", "could not get dbus proxy: " GSM_DBUS_SERVICE );
- return;
- }
-
- if ( bInhibit )
- {
- guint nCookie;
- res = dbus_g_proxy_call (proxy,
- "Inhibit", &error,
- G_TYPE_STRING, appname,
- G_TYPE_UINT, xid,
- G_TYPE_STRING, reason,
- G_TYPE_UINT, 8, //Inhibit the session being marked as idle
- G_TYPE_INVALID,
- G_TYPE_UINT, &nCookie,
- G_TYPE_INVALID);
- if ( res )
- {
- mnGSMCookie = nCookie;
- }
- else
- {
- SAL_INFO( "vcl.screensaverinhibitor", GSM_DBUS_SERVICE ".Inhibit failed" );
- }
- }
- else
- {
- res = dbus_g_proxy_call (proxy,
- "Uninhibit",
- &error,
- G_TYPE_UINT, mnGSMCookie.get(),
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- mnGSMCookie = boost::none;
-
- if ( !res )
- {
- SAL_INFO( "vcl.screensaverinhibitor", GSM_DBUS_SERVICE ".Uninhibit failed" );
- }
- }
-
- if (error != NULL)
- {
- SAL_INFO( "vcl.screensaverinhibitor", "Error: " << error->message );
- g_error_free( error );
- }
-
- g_object_unref( G_OBJECT( proxy ) );
+ dbusInhibit( bInhibit,
+ FDO_DBUS_SERVICE, FDO_DBUS_PATH, FDO_DBUS_INTERFACE,
+ [appname, reason] ( DBusGProxy *proxy, guint& nCookie, GError*& error ) -> bool {
+ return dbus_g_proxy_call( proxy,
+ "Inhibit", &error,
+ G_TYPE_STRING, appname,
+ G_TYPE_STRING, reason,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &nCookie,
+ G_TYPE_INVALID );
+ },
+ [] ( DBusGProxy *proxy, const guint nCookie, GError*& error ) -> bool {
+ return dbus_g_proxy_call( proxy,
+ "UnInhibit", &error,
+ G_TYPE_UINT, nCookie,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID );
+ },
+ mnFDOCookie );
+}
-#endif // ENABLE_DBUS
+void ScreenSaverInhibitor::inhibitGSM( bool bInhibit, const gchar* appname, const gchar* reason, const guint xid )
+{
+ dbusInhibit( bInhibit,
+ GSM_DBUS_SERVICE, GSM_DBUS_PATH, GSM_DBUS_INTERFACE,
+ [appname, reason, xid] ( DBusGProxy *proxy, guint& nCookie, GError*& error ) -> bool {
+ return dbus_g_proxy_call( proxy,
+ "Inhibit", &error,
+ G_TYPE_STRING, appname,
+ G_TYPE_UINT, xid,
+ G_TYPE_STRING, reason,
+ G_TYPE_UINT, 8, //Inhibit the session being marked as idle
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &nCookie,
+ G_TYPE_INVALID );
+ },
+ [] ( DBusGProxy *proxy, const guint nCookie, GError*& error ) -> bool {
+ return dbus_g_proxy_call( proxy,
+ "Uninhibit", &error,
+ G_TYPE_UINT, nCookie,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID );
+ },
+ mnGSMCookie );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */