Changeset 89815 in vbox
- Timestamp:
- Jun 21, 2021 12:06:22 PM (3 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r89717 r89815 1557 1557 UICommon_QT_MODULES.linux += X11Extras 1558 1558 UICommon_QT_MODULES.linux += DBus 1559 UICommon_QT_MODULES.linux += Xml 1559 1560 UICommon_QT_MODULES.solaris += X11Extras 1560 1561 UICommon_QT_MODULES.solaris += DBus 1562 UICommon_QT_MODULES.solaris += Xml 1561 1563 UICommon_QT_MODULES.freebsd += X11Extras 1562 1564 UICommon_QT_MODULES.freebsd += DBus 1565 UICommon_QT_MODULES.freebsd += Xml 1563 1566 UICommon_QT_MODULES.darwin += MacExtras 1564 1567 UICommon_QT_MODULES.win += WinExtras -
trunk/src/VBox/Frontends/VirtualBox/src/platform/x11/VBoxX11Helper.cpp
r89767 r89815 17 17 18 18 /* Qt includes: */ 19 #include <QString>20 19 #include <QX11Info> 21 20 #include <QtDBus/QDBusConnection> … … 23 22 #include <QtDBus/QDBusInterface> 24 23 #include <QtDBus/QDBusConnectionInterface> 24 #include <QtXml/QDomDocument> 25 #include <QtXml/QDomElement> 25 26 26 27 /* GUI includes: */ … … 162 163 } 163 164 164 QStringList X11ScrenSaverServices()165 static QStringList X11FindDBusScreenSaverServices(const QDBusConnection &connection) 165 166 { 166 167 QStringList serviceNames; 167 QDBusConnection bus = QDBusConnection::sessionBus(); 168 QDBusReply<QStringList> replyr = bus.interface()->registeredServiceNames();168 169 QDBusReply<QStringList> replyr = connection.interface()->registeredServiceNames(); 169 170 if (!replyr.isValid()) 171 { 172 const QDBusError replyError = replyr.error(); 173 LogRel(("QDBus error. Could not query registered service names %s %s", 174 replyError.name().toUtf8().constData(), replyError.message().toUtf8().constData())); 170 175 return serviceNames; 176 } 177 171 178 for (int i = 0; i < replyr.value().size(); ++i) 172 179 { … … 176 183 } 177 184 if (serviceNames.isEmpty()) 178 LogRel((" No screen saver service found among registered DBus services."));185 LogRel(("QDBus error. No screen saver service found among registered DBus services.")); 179 186 180 187 return serviceNames; 181 188 } 182 189 183 void X11InhibitScrenSaver(const QStringList &serviceNameList, QMap<QString, uint> &outCookies) 184 { 185 outCookies.clear(); 186 QDBusConnection bus = QDBusConnection::sessionBus(); 187 188 foreach(QString service, serviceNameList) 189 { 190 QDBusInterface screenSaverInterface(service, "/ScreenSaver", 191 service, bus); 190 static void X11IntrorespectInterfaceNode(const QDomElement &interface, 191 const QString &strServiceName, QVector<X11ScreenSaverInhibitMethod*> &methods) 192 { 193 QDomElement child = interface.firstChildElement(); 194 while (!child.isNull()) { 195 196 if (child.tagName() == "method" && child.attribute("name") == "Inhibit") 197 { 198 X11ScreenSaverInhibitMethod *newMethod = new X11ScreenSaverInhibitMethod; 199 newMethod->m_iCookie = 0; 200 newMethod->m_strServiceName = strServiceName; 201 newMethod->m_strInterface = interface.attribute("name"); 202 newMethod->m_strPath = "/"; 203 newMethod->m_strPath.append(interface.attribute("name")); 204 newMethod->m_strPath.replace(".", "/"); 205 methods << newMethod; 206 } 207 child = child.nextSiblingElement(); 208 } 209 } 210 211 static void X11IntrorespectServices(const QDBusConnection &connection, 212 const QString &strService, const QString &path, QVector<X11ScreenSaverInhibitMethod*> &methods) 213 { 214 QDBusMessage call = QDBusMessage::createMethodCall(strService, path.isEmpty() ? QLatin1String("/") : path, 215 QLatin1String("org.freedesktop.DBus.Introspectable"), 216 QLatin1String("Introspect")); 217 QDBusReply<QString> xmlReply = connection.call(call); 218 219 if (!xmlReply.isValid()) 220 return; 221 222 QDomDocument doc; 223 doc.setContent(xmlReply); 224 QDomElement node = doc.documentElement(); 225 QDomElement child = node.firstChildElement(); 226 while (!child.isNull()) 227 { 228 if (child.tagName() == QLatin1String("node")) 229 { 230 QString subPath = path + QLatin1Char('/') + child.attribute(QLatin1String("name")); 231 X11IntrorespectServices(connection, strService, subPath, methods); 232 } 233 else if (child.tagName() == QLatin1String("interface")) 234 X11IntrorespectInterfaceNode(child, strService, methods); 235 child = child.nextSiblingElement(); 236 } 237 } 238 239 static bool X11CheckDBusConnection(const QDBusConnection &connection) 240 { 241 if (!connection.isConnected()) { 242 const QDBusError lastError = connection.lastError(); 243 if (lastError.isValid()) 244 { 245 LogRel(("QDBus error. Could not connect to D-Bus server: %s: %s\n", 246 lastError.name().toUtf8().constData(), 247 lastError.message().toUtf8().constData())); 248 } 249 else 250 LogRel(("QDBus error. Could not connect to D-Bus server: Unable to load dbus libraries\n")); 251 return false; 252 } 253 return true; 254 } 255 256 QVector<X11ScreenSaverInhibitMethod*> X11FindDBusScrenSaverInhibitMethods() 257 { 258 QVector<X11ScreenSaverInhibitMethod*> methods; 259 260 QDBusConnection connection = QDBusConnection::sessionBus(); 261 if (!X11CheckDBusConnection(connection)) 262 return methods; 263 264 foreach(const QString &strServiceName, X11FindDBusScreenSaverServices(connection)) 265 X11IntrorespectServices(connection, strServiceName, "", methods); 266 267 return methods; 268 } 269 270 void X11InhibitUninhibitScrenSaver(bool fInhibit, QVector<X11ScreenSaverInhibitMethod*> &inOutIhibitMethods) 271 { 272 QDBusConnection connection = QDBusConnection::sessionBus(); 273 if (!X11CheckDBusConnection(connection)) 274 return; 275 for (int i = 0; i < inOutIhibitMethods.size(); ++i) 276 { 277 QDBusInterface screenSaverInterface(inOutIhibitMethods[i]->m_strServiceName, inOutIhibitMethods[i]->m_strPath, 278 inOutIhibitMethods[i]->m_strInterface, connection); 192 279 if (!screenSaverInterface.isValid()) 193 280 { 194 281 QDBusError error = screenSaverInterface.lastError(); 195 LogRel(("QDBus error for service %s: %s\n", 196 service.toUtf8().constData(), error.message().toUtf8().constData())); 282 LogRel(("QDBus error for service %s: %s. %s\n", 283 inOutIhibitMethods[i]->m_strServiceName.toUtf8().constData(), 284 error.name().toUtf8().constData(), 285 error.message().toUtf8().constData())); 197 286 continue; 198 287 } 199 QDBusReply<uint> reply = screenSaverInterface.call("Inhibit", "Oracle VirtualBox", ""); 200 if (reply.isValid()) 201 outCookies[service] = reply.value(); 288 QDBusReply<uint> reply; 289 if (fInhibit) 290 { 291 reply = screenSaverInterface.call("Inhibit", "Oracle VirtualBox", "ScreenSaverInhibit"); 292 if (reply.isValid()) 293 inOutIhibitMethods[i]->m_iCookie = reply.value(); 294 } 202 295 else 203 296 { 204 QDBusError error = screenSaverInterface.lastError(); 205 LogRel(("QDBus inhibition call error for service %s: %s\n", 206 service.toUtf8().constData(), error.message().toUtf8().constData())); 207 } 208 } 209 } 210 211 void X11UninhibitScrenSaver(const QMap<QString, uint> &cookies) 212 { 213 214 QDBusConnection bus = QDBusConnection::sessionBus(); 215 216 for (QMap<QString, uint>::const_iterator iterator = cookies.begin(); iterator != cookies.end(); ++iterator) 217 { 218 219 QDBusInterface screenSaverInterface(iterator.key(), "/ScreenSaver", 220 iterator.key(), bus); 221 if (!screenSaverInterface.isValid()) 222 { 223 QDBusError error = screenSaverInterface.lastError(); 224 LogRel(("QDBus error for service %s: %s\n", 225 iterator.key().toUtf8().constData(), error.message().toUtf8().constData())); 226 continue; 227 } 228 QDBusReply<uint> reply = screenSaverInterface.call("UnInhibit", iterator.value()); 297 reply = screenSaverInterface.call("UnInhibit", inOutIhibitMethods[i]->m_iCookie); 298 } 229 299 if (!reply.isValid()) 230 300 { 231 QDBusError error = screenSaverInterface.lastError(); 232 LogRel(("QDBus uninhibition call error for service %s: %s\n", 233 iterator.key().toUtf8().constData(), error.message().toUtf8().constData())); 234 } 235 } 236 } 237 301 QDBusError error = reply.error(); 302 LogRel(("QDBus inhibition call error for service %s: %s. %s\n", 303 inOutIhibitMethods[i]->m_strServiceName.toUtf8().constData(), 304 error.name().toUtf8().constData(), 305 error.message().toUtf8().constData())); 306 } 307 } 308 } 238 309 239 310 #ifdef VBOX_WS_X11 -
trunk/src/VBox/Frontends/VirtualBox/src/platform/x11/VBoxX11Helper.h
r89708 r89815 22 22 #endif 23 23 24 /* Qt includes: */ 25 #include <QString> 26 24 27 /* GUI includes: */ 25 28 #include "UILibraryDefs.h" … … 38 41 }; 39 42 43 struct X11ScreenSaverInhibitMethod 44 { 45 QString m_strServiceName; 46 QString m_strInterface; 47 QString m_strPath; 48 uint m_iCookie; 49 }; 40 50 41 51 /** X11: Determines and returns whether the compositing manager is running. */ … … 54 64 SHARED_LIBRARY_STUFF bool X11CheckExtension(const char *extensionName); 55 65 56 /* Returns the list of DBus screensaver services.*/57 SHARED_LIBRARY_STUFF Q StringList X11ScrenSaverServices();66 /** Returns the list of Inhibit methods found by introrespecting DBus services. */ 67 SHARED_LIBRARY_STUFF QVector<X11ScreenSaverInhibitMethod*> X11FindDBusScrenSaverInhibitMethods(); 58 68 59 /* Disables Screen Saver through QDBus. */ 60 SHARED_LIBRARY_STUFF void X11InhibitScrenSaver(const QStringList &serviceNameList, QMap<QString, uint> &outCookies); 61 62 /* Enables Screen Saver through QDBus. */ 63 SHARED_LIBRARY_STUFF void X11UninhibitScrenSaver(const QMap<QString, uint> &cookies); 69 /** Disables/enables Screen Saver through QDBus. */ 70 SHARED_LIBRARY_STUFF void X11InhibitUninhibitScrenSaver(bool fInhibit, QVector<X11ScreenSaverInhibitMethod*> &inOutIhibitMethods); 64 71 65 72 #endif /* !FEQT_INCLUDED_SRC_platform_x11_VBoxX11Helper_h */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
r89744 r89815 714 714 { 715 715 #if defined(VBOX_WS_X11) 716 QStringList services = X11ScrenSaverServices(); 717 if (services.isEmpty()) 718 return; 719 720 if (fDisabled) 721 X11InhibitScrenSaver(services, m_screenSaverInhibitionCookies); 722 else 723 X11UninhibitScrenSaver(m_screenSaverInhibitionCookies); 716 if (m_methods.isEmpty()) 717 m_methods = X11FindDBusScrenSaverInhibitMethods(); 718 X11InhibitUninhibitScrenSaver(fDisabled, m_methods); 724 719 #elif defined(VBOX_WS_WIN) 725 720 NativeWindowSubsystem::setScreenSaverActive(fDisabled); … … 887 882 , m_pVMInformationDialog(0) 888 883 { 884 } 885 886 UIMachineLogic::~UIMachineLogic() 887 { 888 qDeleteAll(m_methods.begin(), m_methods.end()); 889 m_methods.clear(); 889 890 } 890 891 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h
r89745 r89815 53 53 class CUSBDevice; 54 54 class CVirtualBoxErrorInfo; 55 struct X11ScreenSaverInhibitMethod; 55 56 56 57 #ifdef VBOX_WITH_DEBUGGER_GUI … … 207 208 /* Constructor: */ 208 209 UIMachineLogic(QObject *pParent, UISession *pSession, UIVisualStateType visualStateType); 210 /* Destructor: */ 211 ~UIMachineLogic(); 209 212 210 213 /* Protected getters/setters: */ … … 463 466 /* Holds the cookies returnd by QDBus inhibition calls. Map keys are service name. These are required during uninhibition.*/ 464 467 QMap<QString, uint> m_screenSaverInhibitionCookies; 465 468 QVector<X11ScreenSaverInhibitMethod*> m_methods; 466 469 /* Friend classes: */ 467 470 friend class UIMachineWindow;
Note:
See TracChangeset
for help on using the changeset viewer.