@@ -87,22 +87,30 @@ void Utils::OS::shutdownComputer([[maybe_unused]] const ShutdownDialogAction &ac
8787 {
8888 ::SetSuspendState (TRUE , FALSE , FALSE );
8989 }
90- else
90+ else if (action == ShutdownDialogAction::Shutdown)
9191 {
9292 std::wstring msg = QCoreApplication::translate (" misc"
9393 , " qBittorrent will shutdown the computer now because all downloads are complete." ).toStdWString ();
9494 ::InitiateSystemShutdownW (nullptr , msg.data(), 10, TRUE, FALSE);
9595 }
96+ else if (action == ShutdownDialogAction::Reboot)
97+ {
98+ std::wstring msg = QCoreApplication::translate (" misc"
99+ , " qBittorrent will reboot the computer now because all downloads are complete." ).toStdWString ();
100+ ::InitiateSystemShutdownW (nullptr , msg.data(), 10, TRUE, TRUE);
101+ }
96102
97103 // Disable shutdown privilege.
98104 tkp.Privileges [0 ].Attributes = 0 ;
99105 ::AdjustTokenPrivileges (hToken, FALSE , &tkp, 0 , NULL , 0 );
100106
101107#elif defined(Q_OS_MACOS)
102- AEEventID EventToSend;
103- if (action != ShutdownDialogAction::Shutdown )
108+ AEEventID EventToSend {} ;
109+ if (action == ShutdownDialogAction::Suspend )
104110 EventToSend = kAESleep ;
105- else
111+ else if (action == ShutdownDialogAction::Reboot)
112+ EventToSend = kAERestart ;
113+ else if (action == ShutdownDialogAction::Shutdown)
106114 EventToSend = kAEShutDown ;
107115 AEAddressDesc targetDesc;
108116 const ProcessSerialNumber kPSNOfSystemProcess = {0 , kSystemProcess };
@@ -133,7 +141,7 @@ void Utils::OS::shutdownComputer([[maybe_unused]] const ShutdownDialogAction &ac
133141
134142#elif defined(QBT_USES_DBUS)
135143 // Use dbus to power off / suspend the system
136- if (action != ShutdownDialogAction::Shutdown )
144+ if (( action == ShutdownDialogAction::Suspend) || (action == ShutdownDialogAction::Hibernate) )
137145 {
138146 // Some recent systems use systemd's logind
139147 QDBusInterface login1Iface (u" org.freedesktop.login1" _s, u" /org/freedesktop/login1" _s,
@@ -166,7 +174,7 @@ void Utils::OS::shutdownComputer([[maybe_unused]] const ShutdownDialogAction &ac
166174 else
167175 halIface.call (u" Hibernate" _s);
168176 }
169- else
177+ else if (action == ShutdownDialogAction::Shutdown)
170178 {
171179 // Some recent systems use systemd's logind
172180 QDBusInterface login1Iface (u" org.freedesktop.login1" _s, u" /org/freedesktop/login1" _s,
@@ -190,6 +198,30 @@ void Utils::OS::shutdownComputer([[maybe_unused]] const ShutdownDialogAction &ac
190198 QDBusConnection::systemBus ());
191199 halIface.call (u" Shutdown" _s);
192200 }
201+ else if (action == ShutdownDialogAction::Reboot)
202+ {
203+ // Some recent systems use systemd's logind
204+ QDBusInterface login1Iface (u" org.freedesktop.login1" _s, u" /org/freedesktop/login1" _s,
205+ u" org.freedesktop.login1.Manager" _s, QDBusConnection::systemBus ());
206+ if (login1Iface.isValid ())
207+ {
208+ login1Iface.call (u" Reboot" _s, false );
209+ return ;
210+ }
211+ // Else, other recent systems use ConsoleKit
212+ QDBusInterface consolekitIface (u" org.freedesktop.ConsoleKit" _s, u" /org/freedesktop/ConsoleKit/Manager" _s,
213+ u" org.freedesktop.ConsoleKit.Manager" _s, QDBusConnection::systemBus ());
214+ if (consolekitIface.isValid ())
215+ {
216+ consolekitIface.call (u" Restart" _s);
217+ return ;
218+ }
219+ // HAL (older systems)
220+ QDBusInterface halIface (u" org.freedesktop.Hal" _s, u" /org/freedesktop/Hal/devices/computer" _s,
221+ u" org.freedesktop.Hal.Device.SystemPowerManagement" _s,
222+ QDBusConnection::systemBus ());
223+ halIface.call (u" Reboot" _s);
224+ }
193225#endif
194226}
195227
0 commit comments