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 16class BButton; 17class BCheckBox; 18class BListView; 19class BTextControl; 20class BMessage; 21class BMessenger; 22class BPath; 23class Settings; 24 25 26static const uint32 kMsgNetworkTimeSettings = 'ntst'; 27static const uint32 kMsgSetDefaultServer = 'setd'; 28static const uint32 kMsgServerEdited = 'sved'; 29static const uint32 kMsgAddServer = 'asrv'; 30static const uint32 kMsgRemoveServer = 'rsrv'; 31static const uint32 kMsgResetServerList = 'rstl'; 32static const uint32 kMsgTryAllServers = 'tras'; 33static const uint32 kMsgSynchronizeAtBoot = 'synb'; 34static const uint32 kMsgSynchronize = 'sync'; 35static const uint32 kMsgStopSynchronization = 'stps'; 36static const uint32 kMsgSynchronizationResult = 'syrs'; 37static const uint32 kMsgNetworkTimeChange = 'ntch'; 38 39 40status_t 41update_time(const Settings& settings, BMessenger* messenger, 42 thread_id* thread); 43 44 45status_t 46update_time(const Settings& settings, const char** errorString, 47 int32* errorCode); 48 49 50class Settings { 51public: 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 73private: 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 84class NetworkTimeView : public BGroupView { 85public: 86 NetworkTimeView(const char* name); 87 88 virtual void MessageReceived(BMessage* message); 89 virtual void AttachedToWindow(); 90 91 bool CheckCanRevert(); 92private: 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