From 5fb214d470602f7e5cddea0675b36a0ecd5b97af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 17 Jul 2005 11:07:55 +0000 Subject: [PATCH] The Deskbar can now shutdown or reboot Haiku, but we should have a way to shutdown asynchronously, see TODO git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13712 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/deskbar/BarApp.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/apps/deskbar/BarApp.h | 10 +++++++++- src/apps/deskbar/BeMenu.cpp | 9 ++++----- src/apps/deskbar/Jamfile | 1 + 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 42177283d7..4482e7a21f 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -47,6 +47,10 @@ All rights reserved. #include #include +#if __HAIKU__ +# include +#endif + #include "FavoritesConfig.h" #include "icons.h" @@ -457,6 +461,26 @@ TBarApp::MessageReceived(BMessage *message) fSwitcherMess.SendMessage(message); break; +#if __HAIKU__ + case CMD_REBOOT_SYSTEM: + case CMD_SUSPEND_SYSTEM: + case CMD_SHUTDOWN_SYSTEM: { + // TODO: Deskbar cannot quit because BRoster::Private::Shutdown() is synchronous, + // so we launch a thread which does the shutdown, this should be reworked so + // that we can simply send a message to the roster and be done with it + void* cookie = message->what == CMD_SHUTDOWN_SYSTEM ? NULL : (void*)1; + thread_id thread = spawn_thread(_shutdown, "shutdown thread", B_NORMAL_PRIORITY, cookie); + if (thread >= B_OK) { + status_t ret = resume_thread(thread); + if (ret < B_OK) + fprintf(stderr, "error resuming shutdown thread: %s\n", strerror(ret)); + } else + fprintf(stderr, "error spawning shutdown thread: %s\n", strerror(thread)); + + break; + } +#endif // __HAIKU__ + default: BApplication::MessageReceived(message); break; @@ -643,6 +667,19 @@ TBarApp::ShowConfigWindow() } } +#if __HAIKU__ +// _shutdown +int32 +TBarApp::_shutdown(void* cookie) +{ + BRoster roster; + BRoster::Private rosterPrivate(roster); + status_t error = rosterPrivate.ShutDown(cookie != NULL, false); + fprintf(stderr, "Shutdown failed: %s\n", strerror(error)); + return 0; +} +#endif // __HAIKU__ + // #pragma mark - diff --git a/src/apps/deskbar/BarApp.h b/src/apps/deskbar/BarApp.h index 706aebd526..d0adcd68b1 100644 --- a/src/apps/deskbar/BarApp.h +++ b/src/apps/deskbar/BarApp.h @@ -46,7 +46,6 @@ All rights reserved. #define _FLOATER_W_TYPE_ 4 #define _STD_W_TYPE_ 0 - class BarTeamInfo { public: BarTeamInfo(BList *teams, uint32 flags, char *sig, BBitmap *icon, @@ -77,6 +76,11 @@ const uint32 msg_sortRunningApps = 'SAps'; const uint32 msg_superExpando = 'SprE'; const uint32 msg_expandNewTeams = 'ExTm'; +// from roster_private.h +const uint32 CMD_SHUTDOWN_SYSTEM = 301; +const uint32 CMD_REBOOT_SYSTEM = 302; +const uint32 CMD_SUSPEND_SYSTEM = 304; + /* --------------------------------------------- */ // if you want to extend this structure, maintain the @@ -154,6 +158,10 @@ private: void ShowConfigWindow(); +#if __HAIKU__ + static int32 _shutdown(void* cookie); +#endif + TBarWindow *fBarWindow; BMessenger fSwitcherMess; BMessenger fStatusViewMess; diff --git a/src/apps/deskbar/BeMenu.cpp b/src/apps/deskbar/BeMenu.cpp index 0eecd8d4e4..48a38164f5 100644 --- a/src/apps/deskbar/BeMenu.cpp +++ b/src/apps/deskbar/BeMenu.cpp @@ -48,11 +48,6 @@ All rights reserved. #include "StatusView.h" #include "IconMenuItem.h" -// from roster_private.h -const uint32 CMD_SHUTDOWN_SYSTEM = 301; -const uint32 CMD_REBOOT_SYSTEM = 302; -const uint32 CMD_SUSPEND_SYSTEM = 304; - #define ROSTER_SIG "application/x-vnd.Be-ROST" #ifdef B_BEOS_VERSION_5 @@ -455,7 +450,11 @@ TBeMenu::ResetTargets() case CMD_SUSPEND_SYSTEM: case CMD_SHUTDOWN_SYSTEM: // restart/shutdown +#if __HAIKU__ + item->SetTarget(be_app); +#else item->SetTarget(BMessenger(ROSTER_SIG)); +#endif break; } } diff --git a/src/apps/deskbar/Jamfile b/src/apps/deskbar/Jamfile index df87c8a259..6099b01c91 100644 --- a/src/apps/deskbar/Jamfile +++ b/src/apps/deskbar/Jamfile @@ -1,5 +1,6 @@ SubDir OBOS_TOP src apps deskbar ; +UsePrivateHeaders app ; UsePrivateHeaders shared ; UsePrivateHeaders tracker ; SubDirHdrs $(OBOS_TOP) src kits tracker ;