1/*
2 * Copyright 2003-2004 Waldemar Kornewald. All rights reserved.
3 * Copyright 2017 Haiku, Inc. All rights reserved.
4 * Distributed under the terms of the MIT License.
5 */
6
7//-----------------------------------------------------------------------
8// IPCPAddon saves the loaded settings.
9// IPCPView saves the current settings.
10//-----------------------------------------------------------------------
11
12#ifndef _IPCP_ADDON__H
13#define _IPCP_ADDON__H
14
15#include "DialUpAddon.h"
16
17#include <CheckBox.h>
18#include <String.h>
19#include <TextControl.h>
20
21class BButton;
22class IPCPView;
23
24
25class IPCPAddon : public DialUpAddon {
26	public:
27		IPCPAddon(BMessage *addons);
28		virtual ~IPCPAddon();
29
30		bool IsNew() const
31			{ return fIsNew; }
32
33		bool IsEnabled() const
34			{ return fIsEnabled; }
35		const char *IPAddress() const
36			{ return fIPAddress.String(); }
37		const char *PrimaryDNS() const
38			{ return fPrimaryDNS.String(); }
39		const char *SecondaryDNS() const
40			{ return fSecondaryDNS.String(); }
41
42		BMessage *Settings() const
43			{ return fSettings; }
44		BMessage *Profile() const
45			{ return fProfile; }
46
47		virtual int32 Position() const
48			{ return 10; }
49
50		virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew);
51		virtual void IsModified(bool *settings, bool *profile) const;
52		virtual bool SaveSettings(BMessage *settings, BMessage *profile,
53			bool saveTemporary);
54		virtual bool GetPreferredSize(float *width, float *height) const;
55		virtual BView *CreateView();
56
57	private:
58		int32 FindIPCPProtocol(const BMessage& message, BMessage *protocol) const;
59
60	private:
61		bool fIsNew, fIsEnabled;
62		BString fIPAddress, fPrimaryDNS, fSecondaryDNS;
63		BMessage *fSettings, *fProfile;
64			// saves last settings state
65		IPCPView *fIPCPView;
66};
67
68
69class IPCPView : public BView {
70	public:
71		IPCPView(IPCPAddon *addon);
72
73		IPCPAddon *Addon() const
74			{ return fAddon; }
75		void Reload();
76
77		bool IsEnabled() const
78			{ return fIsEnabled->Value(); }
79		const char *IPAddress() const
80			{ return fIPAddress->Text(); }
81		const char *PrimaryDNS() const
82			{ return fPrimaryDNS->Text(); }
83		const char *SecondaryDNS() const
84			{ return fSecondaryDNS->Text(); }
85
86		virtual void AttachedToWindow();
87		virtual void MessageReceived(BMessage *message);
88
89	private:
90		void UpdateControls();
91
92	private:
93		IPCPAddon *fAddon;
94		BCheckBox *fIsEnabled;
95		BButton *fCancelButton, *fOKButton;
96		BTextControl *fIPAddress, *fPrimaryDNS, *fSecondaryDNS;
97};
98
99
100#endif
101