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
17class BButton;
18class BCheckBox;
19class BListView;
20class BMessage;
21class BMessenger;
22class BPath;
23class BTextControl;
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
40class Settings {
41public:
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
63private:
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
74class NetworkTimeView : public BGroupView {
75public:
76							NetworkTimeView(const char* name);
77	virtual					~NetworkTimeView();
78
79	virtual	void			MessageReceived(BMessage* message);
80	virtual	void			AttachedToWindow();
81
82			bool			CheckCanRevert();
83private:
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
108int32
109update_thread(void* params);
110
111status_t
112update_time(const Settings& settings, BMessenger* messenger,
113	thread_id* thread);
114
115status_t
116update_time(const Settings& settings, const char** errorString,
117	int32* errorCode);
118
119
120#endif	// NETWORK_TIME_VIEW_H
121