xref: /haiku/src/apps/powerstatus/PowerStatusView.h (revision a3e794ae459fec76826407f8ba8c94cd3535f128)
1 /*
2  * Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Axel Dörfler, axeld@pinc-software.de
7  *		Clemens Zeidler, haiku@Clemens-Zeidler.de
8  */
9 #ifndef POWER_STATUS_VIEW_H
10 #define POWER_STATUS_VIEW_H
11 
12 
13 #include <View.h>
14 
15 #include "DriverInterface.h"
16 
17 
18 class BFile;
19 
20 
21 class PowerStatusView : public BView {
22 public:
23 							PowerStatusView(
24 								PowerStatusDriverInterface* interface,
25 								BRect frame, int32 resizingMode,
26 								int batteryID = -1, bool inDeskbar = false);
27 
28 	virtual					~PowerStatusView();
29 
30 	virtual	status_t		Archive(BMessage* archive, bool deep = true) const;
31 
32 	virtual	void			AttachedToWindow();
33 	virtual	void			DetachedFromWindow();
34 
35 	virtual	void			MessageReceived(BMessage* message);
36 	virtual	void			Draw(BRect updateRect);
37 
38 
39 protected:
40 							PowerStatusView(BMessage* archive);
41 
42 	virtual void			Update(bool force = false);
43 
44 			void			FromMessage(const BMessage* message);
45 			status_t		ToMessage(BMessage* message) const;
46 
47 private:
48 			void			_GetBatteryInfo(int batteryID, battery_info* info);
49 			void			_Init();
50 			void			_SetLabel(char* buffer, size_t bufferLength);
51 			void			_DrawBattery(BRect rect);
52 			void			_NotifyLowBattery();
53 
54 protected:
55 			PowerStatusDriverInterface*	fDriverInterface;
56 
57 			bool			fShowLabel;
58 			bool			fShowTime;
59 			bool			fShowStatusIcon;
60 
61 			int				fBatteryID;
62 			bool			fInDeskbar;
63 
64 			battery_info	fBatteryInfo;
65 
66 			int32			fPercent;
67 			time_t			fTimeLeft;
68 			bool			fOnline;
69 			bool			fHasBattery;
70 };
71 
72 
73 class PowerStatusReplicant : public PowerStatusView {
74 public:
75 							PowerStatusReplicant(BRect frame,
76 								int32 resizingMode, bool inDeskbar = false);
77 							PowerStatusReplicant(BMessage* archive);
78 	virtual					~PowerStatusReplicant();
79 
80 	static	PowerStatusReplicant* Instantiate(BMessage* archive);
81 	virtual	status_t		Archive(BMessage* archive, bool deep = true) const;
82 
83 	virtual	void			MessageReceived(BMessage* message);
84 	virtual	void			MouseDown(BPoint where);
85 
86 private:
87 			void			_AboutRequested();
88 			void			_Init();
89 			void			_Quit();
90 
91 			status_t		_GetSettings(BFile& file, int mode);
92 			void			_LoadSettings();
93 			void			_SaveSettings();
94 
95 			void			_OpenExtendedWindow();
96 
97 private:
98 			BWindow*		fExtendedWindow;
99 			bool			fMessengerExist;
100 			BMessenger*		fExtWindowMessenger;
101 };
102 
103 
104 #endif	// POWER_STATUS_VIEW_H
105