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// GeneralAddon saves the loaded settings.
9// GeneralView saves the current settings.
10//-----------------------------------------------------------------------
11
12#ifndef _GENERAL_ADDON__H
13#define _GENERAL_ADDON__H
14
15#include "DialUpAddon.h"
16
17#include <CheckBox.h>
18#include <String.h>
19#include <TextControl.h>
20
21class BBox;
22class BMenuField;
23class BMenuItem;
24class GeneralView;
25
26
27class GeneralAddon : public DialUpAddon {
28	public:
29		GeneralAddon(BMessage *addons);
30		virtual ~GeneralAddon();
31
32		bool IsNew() const
33			{ return fIsNew; }
34
35		const char *DeviceName() const
36			{ return fDeviceName.String(); }
37		const char *Username() const
38			{ return fUsername.String(); }
39		const char *Password() const
40			{ return fPassword.String(); }
41		bool HasPassword() const
42			{ return fHasPassword; }
43
44		bool NeedsAuthenticationRequest() const;
45
46		DialUpAddon *FindDevice(const BString& moduleName) const;
47		DialUpAddon *DeviceAddon() const
48			{ return fDeviceAddon; }
49
50		int32 CountAuthenticators() const
51			{ return fAuthenticatorsCount; }
52
53		BMessage *Settings() const
54			{ return fSettings; }
55		BMessage *Profile() const
56			{ return fProfile; }
57
58		virtual int32 Position() const
59			{ return 0; }
60		virtual bool LoadSettings(BMessage *settings, BMessage *profile, bool isNew);
61		bool LoadDeviceSettings();
62		bool LoadAuthenticationSettings();
63
64		virtual bool HasTemporaryProfile() const;
65		virtual void IsModified(bool *settings, bool *profile) const;
66		void IsDeviceModified(bool *settings, bool *profile) const;
67		void IsAuthenticationModified(bool *settings, bool *profile) const;
68
69		virtual bool SaveSettings(BMessage *settings, BMessage *profile,
70			bool saveTemporary);
71		virtual bool GetPreferredSize(float *width, float *height) const;
72		virtual BView *CreateView();
73
74	private:
75		bool GetAuthenticator(const BString& moduleName, BMessage *entry) const;
76		bool MarkAuthenticatorAsValid(const BString& moduleName);
77
78	private:
79		bool fIsNew, fHasPassword;
80		BString fDeviceName, fUsername, fPassword;
81		DialUpAddon *fDeviceAddon;
82		int32 fAuthenticatorsCount;
83		BMessage *fSettings, *fProfile;
84			// saves last settings state
85		GeneralView *fGeneralView;
86};
87
88
89class GeneralView : public BView {
90	public:
91		GeneralView(GeneralAddon *addon);
92		virtual ~GeneralView();
93
94		GeneralAddon *Addon() const
95			{ return fAddon; }
96		void Reload();
97
98		const char *Username() const
99			{ return fUsername->Text(); }
100		const char *Password() const
101			{ return fPassword->Text(); }
102		bool DoesSavePassword() const
103			{ return fSavePassword->Value(); }
104
105		bool HasTemporaryProfile() const
106			{ return !DoesSavePassword() || (fDeviceAddon &&
107				fDeviceAddon->HasTemporaryProfile()); }
108
109		DialUpAddon *DeviceAddon() const
110			{ return fDeviceAddon; }
111		const char *DeviceName() const;
112		const char *AuthenticatorName() const;
113		void IsDeviceModified(bool *settings, bool *profile) const;
114
115		virtual void AttachedToWindow();
116		virtual void MessageReceived(BMessage *message);
117
118	private:
119		void ReloadDeviceView();
120		void UpdateControls();
121
122		void AddDevices();
123		void AddAuthenticators();
124
125	private:
126		GeneralAddon *fAddon;
127		DialUpAddon *fDeviceAddon;
128		BBox *fDeviceBox;
129		BMenuField *fDeviceField, *fAuthenticatorField;
130		BMenuItem *fAuthenticatorNone, *fAuthenticatorDefault;
131		BTextControl *fUsername, *fPassword;
132		BCheckBox *fSavePassword;
133};
134
135
136#endif
137