1 /* 2 * Copyright 2011-2014 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 * Hamish Morrison, hamish@lavabit.com 8 * John Scipione, jscipione@gmail.com 9 */ 10 #ifndef NETWORK_TIME_VIEW_H 11 #define NETWORK_TIME_VIEW_H 12 13 14 #include <LayoutBuilder.h> 15 16 17 class BButton; 18 class BCheckBox; 19 class BListView; 20 class BMessage; 21 class BMessenger; 22 class BPath; 23 class BTextControl; 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 class Settings { 41 public: 42 Settings(); 43 ~Settings(); 44 45 void AddServer(const char* server); 46 const char* GetServer(int32 index) const; 47 void RemoveServer(const char* server); 48 void SetDefaultServer(int32 index); 49 int32 GetDefaultServer() const; 50 void SetTryAllServers(bool boolean); 51 bool GetTryAllServers() const; 52 void SetSynchronizeAtBoot(bool boolean); 53 bool GetSynchronizeAtBoot() const; 54 55 void ResetServersToDefaults(); 56 void ResetToDefaults(); 57 void Revert(); 58 bool SettingsChanged(); 59 60 status_t Load(); 61 status_t Save(); 62 63 private: 64 int32 _GetStringByValue(const char* name, 65 const char* value); 66 status_t _GetPath(BPath& path); 67 68 BMessage fMessage; 69 BMessage fOldMessage; 70 bool fWasUpdated; 71 }; 72 73 74 class NetworkTimeView : public BGroupView { 75 public: 76 NetworkTimeView(const char* name); 77 virtual ~NetworkTimeView(); 78 79 virtual void MessageReceived(BMessage* message); 80 virtual void AttachedToWindow(); 81 82 bool CheckCanRevert(); 83 private: 84 void _InitView(); 85 void _UpdateServerList(); 86 void _DoneSynchronizing(); 87 bool _IsValidServerName(const char* serverName); 88 89 Settings fSettings; 90 91 BTextControl* fServerTextControl; 92 BButton* fAddButton; 93 BButton* fRemoveButton; 94 BButton* fResetButton; 95 96 BListView* fServerListView; 97 BCheckBox* fTryAllServersCheckBox; 98 BCheckBox* fSynchronizeAtBootCheckBox; 99 BButton* fSynchronizeButton; 100 101 rgb_color fTextColor; 102 rgb_color fInvalidColor; 103 104 thread_id fUpdateThread; 105 }; 106 107 108 int32 109 update_thread(void* params); 110 111 status_t 112 update_time(const Settings& settings, BMessenger* messenger, 113 thread_id* thread); 114 115 status_t 116 update_time(const Settings& settings, const char** errorString, 117 int32* errorCode); 118 119 120 #endif // NETWORK_TIME_VIEW_H 121