1 /* 2 * Copyright 2011, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Hamish Morrison <hamish@lavabit.com> 7 * Axel Dörfler <axeld@pinc-software.de> 8 */ 9 #ifndef NETWORK_TIME_VIEW_H 10 #define NETWORK_TIME_VIEW_H 11 12 13 #include <LayoutBuilder.h> 14 15 16 class BButton; 17 class BCheckBox; 18 class BListView; 19 class BTextControl; 20 class BMessage; 21 class BMessenger; 22 class BPath; 23 class Settings; 24 25 26 static const uint32 kMsgNetworkTimeSettings = 'ntst'; 27 static const uint32 kMsgSetDefaultServer = 'setd'; 28 static const uint32 kMsgServerEdited = 'sved'; 29 static const uint32 kMsgAddServer = 'asrv'; 30 static const uint32 kMsgRemoveServer = 'rsrv'; 31 static const uint32 kMsgResetServerList = 'rstl'; 32 static const uint32 kMsgTryAllServers = 'tras'; 33 static const uint32 kMsgSynchronizeAtBoot = 'synb'; 34 static const uint32 kMsgSynchronize = 'sync'; 35 static const uint32 kMsgStopSynchronization = 'stps'; 36 static const uint32 kMsgSynchronizationResult = 'syrs'; 37 static const uint32 kMsgNetworkTimeChange = 'ntch'; 38 39 40 status_t 41 update_time(const Settings& settings, BMessenger* messenger, 42 thread_id* thread); 43 44 45 status_t 46 update_time(const Settings& settings, const char** errorString, 47 int32* errorCode); 48 49 50 class Settings { 51 public: 52 Settings(); 53 ~Settings(); 54 55 void AddServer(const char* server); 56 const char* GetServer(int32 index) const; 57 void RemoveServer(const char* server); 58 void SetDefaultServer(int32 index); 59 int32 GetDefaultServer() const; 60 void SetTryAllServers(bool boolean); 61 bool GetTryAllServers() const; 62 void SetSynchronizeAtBoot(bool boolean); 63 bool GetSynchronizeAtBoot() const; 64 65 void ResetServersToDefaults(); 66 void ResetToDefaults(); 67 void Revert(); 68 bool SettingsChanged(); 69 70 status_t Load(); 71 status_t Save(); 72 73 private: 74 int32 _GetStringByValue(const char* name, 75 const char* value); 76 status_t _GetPath(BPath& path); 77 78 BMessage fMessage; 79 BMessage fOldMessage; 80 bool fWasUpdated; 81 }; 82 83 84 class NetworkTimeView : public BGroupView { 85 public: 86 NetworkTimeView(const char* name); 87 88 virtual void MessageReceived(BMessage* message); 89 virtual void AttachedToWindow(); 90 91 bool CheckCanRevert(); 92 private: 93 void _InitView(); 94 void _UpdateServerList(); 95 void _DoneSynchronizing(); 96 bool _IsValidServerName(const char * serverName); 97 98 Settings fSettings; 99 100 BTextControl* fServerTextControl; 101 BButton* fAddButton; 102 BButton* fRemoveButton; 103 BButton* fResetButton; 104 105 BListView* fServerListView; 106 BCheckBox* fTryAllServersCheckBox; 107 BCheckBox* fSynchronizeAtBootCheckBox; 108 BButton* fSynchronizeButton; 109 110 thread_id fUpdateThread; 111 }; 112 113 #endif 114 115