BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / powerstatus / PowerStatus.cpp
blobbf342b031433ea0c4503f3ed94731b0bb0b978c6
1 /*
2 * Copyright 2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 */
10 #include "PowerStatus.h"
11 #include "PowerStatusWindow.h"
13 #include <Alert.h>
14 #include <Application.h>
15 #include <Catalog.h>
16 #include <Deskbar.h>
17 #include <Entry.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
24 #undef B_TRANSLATION_CONTEXT
25 #define B_TRANSLATION_CONTEXT "PowerStatus"
28 class PowerStatus : public BApplication {
29 public:
30 PowerStatus();
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";
43 status_t
44 our_image(image_info& image)
46 int32 cookie = 0;
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)
50 return B_OK;
53 return B_ERROR;
57 // #pragma mark -
60 PowerStatus::PowerStatus()
61 : BApplication(kSignature)
66 PowerStatus::~PowerStatus()
71 void
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
80 BDeskbar deskbar;
81 #ifdef HAIKU_TARGET_PLATFORM_HAIKU
82 isDeskbarRunning = deskbar.IsRunning();
83 #endif
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,
92 B_WARNING_ALERT);
94 if (alert->Go()) {
95 image_info info;
96 entry_ref ref;
98 if (our_image(info) == B_OK
99 && get_ref_for_path(info.name, &ref) == B_OK) {
100 BDeskbar deskbar;
101 deskbar.AddItem(&ref);
104 Quit();
105 return;
109 BWindow* window = new PowerStatusWindow();
110 window->Show();
114 void
115 PowerStatus::AboutRequested()
117 BWindow* window = WindowAt(0);
118 if (window == NULL)
119 return;
121 BView* view = window->FindView(kDeskbarItemName);
122 if (view == NULL)
123 return;
125 BMessenger target((BHandler*)view);
126 BMessage about(B_ABOUT_REQUESTED);
127 target.SendMessage(&about);
131 // #pragma mark -
135 main(int, char**)
137 PowerStatus app;
138 app.Run();
140 return 0;