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