xref: /haiku/src/add-ons/network_settings/dialup/GeneralAddon.h (revision 0fb349bc5d470bc4c826cb401f7a5e296dcca110)
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 
21 class BBox;
22 class BMenuField;
23 class BMenuItem;
24 class GeneralView;
25 
26 
27 class GeneralAddon : public DialUpAddon {
28 	public:
29 		GeneralAddon(BMessage *addons);
30 		virtual ~GeneralAddon();
31 
IsNew()32 		bool IsNew() const
33 			{ return fIsNew; }
34 
DeviceName()35 		const char *DeviceName() const
36 			{ return fDeviceName.String(); }
Username()37 		const char *Username() const
38 			{ return fUsername.String(); }
Password()39 		const char *Password() const
40 			{ return fPassword.String(); }
HasPassword()41 		bool HasPassword() const
42 			{ return fHasPassword; }
43 
44 		bool NeedsAuthenticationRequest() const;
45 
46 		DialUpAddon *FindDevice(const BString& moduleName) const;
DeviceAddon()47 		DialUpAddon *DeviceAddon() const
48 			{ return fDeviceAddon; }
49 
CountAuthenticators()50 		int32 CountAuthenticators() const
51 			{ return fAuthenticatorsCount; }
52 
Settings()53 		BMessage *Settings() const
54 			{ return fSettings; }
Profile()55 		BMessage *Profile() const
56 			{ return fProfile; }
57 
Position()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 
89 class GeneralView : public BView {
90 	public:
91 		GeneralView(GeneralAddon *addon);
92 		virtual ~GeneralView();
93 
Addon()94 		GeneralAddon *Addon() const
95 			{ return fAddon; }
96 		void Reload();
97 
Username()98 		const char *Username() const
99 			{ return fUsername->Text(); }
Password()100 		const char *Password() const
101 			{ return fPassword->Text(); }
DoesSavePassword()102 		bool DoesSavePassword() const
103 			{ return fSavePassword->Value(); }
104 
HasTemporaryProfile()105 		bool HasTemporaryProfile() const
106 			{ return !DoesSavePassword() || (fDeviceAddon &&
107 				fDeviceAddon->HasTemporaryProfile()); }
108 
DeviceAddon()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