1 /* 2 * Copyright 2006-2017, 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 void DrawTo(BView* view, BRect rect); 38 39 40 protected: 41 PowerStatusView(BMessage* archive); 42 43 virtual void Update(bool force = false, bool notify = true); 44 45 void FromMessage(const BMessage* message); 46 status_t ToMessage(BMessage* message) const; 47 48 private: 49 void _GetBatteryInfo(int batteryID, battery_info* info); 50 void _Init(); 51 void _SetLabel(char* buffer, size_t bufferLength); 52 void _DrawBattery(BView* view, BRect rect); 53 void _NotifyLowBattery(); 54 55 protected: 56 PowerStatusDriverInterface* fDriverInterface; 57 58 bool fShowLabel; 59 bool fShowTime; 60 bool fShowStatusIcon; 61 62 int fBatteryID; 63 bool fInDeskbar; 64 65 battery_info fBatteryInfo; 66 67 double fPercent; 68 time_t fTimeLeft; 69 bool fOnline; 70 bool fHasBattery; 71 72 bool fHasNotifiedLowBattery; 73 }; 74 75 76 class PowerStatusReplicant : public PowerStatusView { 77 public: 78 PowerStatusReplicant(BRect frame, 79 int32 resizingMode, bool inDeskbar = false); 80 PowerStatusReplicant(BMessage* archive); 81 virtual ~PowerStatusReplicant(); 82 83 static PowerStatusReplicant* Instantiate(BMessage* archive); 84 virtual status_t Archive(BMessage* archive, bool deep = true) const; 85 86 virtual void MessageReceived(BMessage* message); 87 virtual void MouseDown(BPoint where); 88 89 private: 90 void _AboutRequested(); 91 void _Init(); 92 void _Quit(); 93 94 status_t _GetSettings(BFile& file, int mode); 95 void _LoadSettings(); 96 void _SaveSettings(); 97 98 void _OpenExtendedWindow(); 99 100 private: 101 BWindow* fExtendedWindow; 102 bool fMessengerExist; 103 BMessenger* fExtWindowMessenger; 104 bool fReplicated; 105 }; 106 107 108 #endif // POWER_STATUS_VIEW_H 109