2 * Copyright 2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
10 #include "PowerStatus.h"
11 #include "PowerStatusWindow.h"
14 #include <Application.h>
24 #undef B_TRANSLATION_CONTEXT
25 #define B_TRANSLATION_CONTEXT "PowerStatus"
28 class PowerStatus
: public BApplication
{
31 virtual ~PowerStatus();
33 virtual void ReadyToRun();
34 virtual void AboutRequested();
38 const char* kSignature
= "application/x-vnd.Haiku-PowerStatus";
39 const char* kDeskbarSignature
= "application/x-vnd.Be-TSKB";
40 const char* kDeskbarItemName
= "PowerStatus";
44 our_image(image_info
& image
)
47 while (get_next_image_info(B_CURRENT_TEAM
, &cookie
, &image
) == B_OK
) {
48 if ((char *)our_image
>= (char *)image
.text
49 && (char *)our_image
<= (char *)image
.text
+ image
.text_size
)
60 PowerStatus::PowerStatus()
61 : BApplication(kSignature
)
66 PowerStatus::~PowerStatus()
72 PowerStatus::ReadyToRun()
74 bool isInstalled
= false;
75 bool isDeskbarRunning
= true;
78 // if the Deskbar is not alive at this point, it might be after having
79 // acknowledged the requester below
81 #ifdef HAIKU_TARGET_PLATFORM_HAIKU
82 isDeskbarRunning
= deskbar
.IsRunning();
84 isInstalled
= deskbar
.HasItem(kDeskbarItemName
);
87 if (isDeskbarRunning
&& !isInstalled
) {
88 BAlert
* alert
= new BAlert("",
89 B_TRANSLATE("You can run PowerStatus in a window "
90 "or install it in the Deskbar."), B_TRANSLATE("Run in window"),
91 B_TRANSLATE("Install in Deskbar"), NULL
, B_WIDTH_AS_USUAL
,
98 if (our_image(info
) == B_OK
99 && get_ref_for_path(info
.name
, &ref
) == B_OK
) {
101 deskbar
.AddItem(&ref
);
109 BWindow
* window
= new PowerStatusWindow();
115 PowerStatus::AboutRequested()
117 BWindow
* window
= WindowAt(0);
121 BView
* view
= window
->FindView(kDeskbarItemName
);
125 BMessenger
target((BHandler
*)view
);
126 BMessage
about(B_ABOUT_REQUESTED
);
127 target
.SendMessage(&about
);