summaryrefslogtreecommitdiffstats
path: root/korn/account_input.h
blob: 548db498b223b9a83987a42ca1bf665aa344a689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
* Copyright (C) 2005, Mart Kelder ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/


#ifndef MK_ACCOUNT_INPUT
#define MK_ACCOUNT_INPUT

class TQWidget;
class TQString;
class TQStringList;

class TQLabel;
class KLineEdit;
class KURLRequester;
class TQComboBox;
class TQCheckBox;

#include <tqmap.h>

/**
 * This classe contains methods to use in the creation of the protocol configuration box.
 * The subclasses of this classes define the methods.
 */
class AccountInput
{
public:
	/**
	 * Constructor.
	 *
	 * @param configName The name as the information is stored in the configuration-file.
	 */
	AccountInput( const TQString& configName );
	/**
	 * Destructor
	 */
	virtual ~AccountInput();

	/**
	 * Implementations should return the left widget. In the configuration, it is
	 * possible to make a left label and a right input box.
	 * @return The pointer to the widget.
	 */
	virtual TQWidget* leftWidget() = 0;
	/**
	 * Implementations should return the right widget. In the configuration, it is
	 * possible to make a left label and a right input box.
	 * @return The pointer to the widget.
	 */
	virtual TQWidget* rightWidget() = 0;

	/**
	 * This function return the config name. This is used for stored an retrieving information.
	 *
	 * @return The configName as used for this config field.
	 */
	TQString configName() const;
	
	/**
	 * Return the value of the configuration object. In most cases, this is the value the user typed in.
	 * This information will be stored in the configuration file.
	 *
	 * @return The value of the object
	 */
	virtual TQString value() const = 0;
	
	/**
	 * Implementation should edit there widget such that value() would return the parameter.
	 *
	 * @param value The value that the object must get.
	 */
	virtual void setValue( const TQString& value ) = 0;
protected:
	TQString *_configName;
};

/**
 * This class implement a simple text input.
 * The left widget is a label, the right widget is a KLineEdit.
 * The value of this object is determined by the value of the KLineEdit.
 */
class TextInput : public AccountInput
{
public:
	/** 
	 * Enum for specifing the type.
	 * text means a normal LineEdit,
	 * password means that *-sings are used instead of characters.
	 */
	enum Type { text, password };
	
	/**
	 * Constructor
	 *
	 * @param parent The parent widget
	 * @param title The title that appears on the screen
	 * @param type The type of TextEdit which is used
	 * @param defaul The default value of this object
	 * @param configName The name it has in the configuration box.
	 */
	TextInput( TQWidget *parent, const TQString& title, Type type, const TQString& defaul, const TQString& configName );
	/**
	 * Constructor. Use this one if you want to ensure a number is inserted.
	 *
	 * @param parent The parent widget
	 * @param title The title that appears on the screen
	 * @param min The minimum value that can be inserted
	 * @param max The maximum value that can be inserted
	 * @param defaul The default value of this object
	 * @param configName The name it has in the configuration box.
	 */
	TextInput( TQWidget *parent, const TQString& title, int min, int max, const TQString& defaul, const TQString& configName );
	/**
	 * Destructor
	 */
	virtual ~TextInput();

	/**
	 * Returns a pointer to the label.
	 * @return A pointer to the label
	 */
	virtual TQWidget* leftWidget() { return (TQWidget*)_left; }
	/**
	 * Returns a pointer to the KLineEdit.
	 * @return A pointer to the KLineEdit
	 */
	virtual TQWidget* rightWidget() { return (TQWidget*)_right; }

	/**
	 * The value of the lineedit.
	 * @return The value of the lineedit.
	 */
	virtual TQString value() const;
	/**
	 * This function sets the text of the edit box.
	 * @param value The value to appear in the lineedit box.
	 */
	virtual void setValue( const TQString& value );
private:
	TQLabel *_left;
	KLineEdit *_right;
};

/**
 * This class implements a URL AccountInput. It can be used to request a file.
 */
class URLInput : public AccountInput
{
public:
	/**
	 * Constructor
	 * @param parent The parent of this object
	 * @param title The title of the label next to the URL.
	 * @param defaul The default value
	 * @param configName The name of the configuration entry
	 */
	URLInput( TQWidget *parent, const TQString& title, const TQString& defaul, const TQString& configName );
	/**
	 * Destructor
	 */
	virtual ~URLInput();

	/**
	 * This return a pointer to the label of this object
	 * @return A pointer to the label of this object
	 */
	virtual TQWidget* leftWidget() { return (TQWidget*)_left; }
	/**
	* This return a pointer to the KURLRequestor of this object
	* @return A pointer to the KURLRequestor of this object
	 */
	virtual TQWidget* rightWidget() { return (TQWidget*)_right; }

	/**
	 * This function returns the url as given in the KURLRequestor
	 * @return The currently selected url
	 */
	virtual TQString value() const;
	/**
	 * Sets the currently selected url
	 * @param value The url to be set.
	 */
	virtual void setValue( const TQString& );

private:
	TQLabel *_left;
	KURLRequester *_right;
};

/**
 * This is an imput for a combobox.
 */
class ComboInput : public AccountInput
{
public:
	/** 
	 * Constructor
	 *
	 * @param parent The parent of the widgets which are created
	 * @param title The title next to the combo box
	 * @param list A mapping which maps a value in the configuration to a (translated) entry in the
	 *             combo box.
	 * @param default The default value of the combo box.
	 * @param configName The name in which the option is saved.
	 */
	ComboInput( TQWidget *parent, const TQString& title, const TQMap<TQString,TQString>& list,
	            const TQString& defaul, const TQString& configName );
	/**
	 * Destructor
	 */
	virtual ~ComboInput();

	/**
	 * The left widget (a label with the title on it)
	 * @return A pointer to the label of this object.
	 */
	virtual TQWidget* leftWidget() { return (TQWidget*)_left; }
	/**
	 * The right widget (the combo box itselfs)
	 * @return A pointer to the combo box of this object
	 */
	virtual TQWidget* rightWidget() { return (TQWidget*)_right; }

	/**
	 * Return the value of the currently selected item
	 * @return The value of the currently selected item
	 */
	virtual TQString value() const;
	
	/**
	 * This function sets the combo box to an item which has @p value as value.
	 *
	 * @param value The value to be searched
	 */
	virtual void setValue( const TQString& value );
private:
	TQLabel *_left;
	TQComboBox *_right;
	TQMap< TQString, TQString > *_list;

};

/**
 * This is an object for creating a text-box.
 * If has no left widget, as the title is stored in the checkbox itselfs.
 */
class CheckboxInput : public AccountInput
{
public:
	/**
	 * Constructor
	 *
	 * @param parent The parent for the objects which are created
	 * @param title The title of the checkbox
	 * @param defaul The default value ("true" for checked, "false" otherwise")
	 * @param configName The name of the configuration entry of this object
	 */
	CheckboxInput( TQWidget *parent, const TQString& title, const TQString& defaul, const TQString& configName );
	/**
	 * Destructor
	 */
	virtual ~CheckboxInput();

	/**
	 * Return a 0-pointer as this object doesn't have a left widget.
	 *
	 * @return 0
	 */
	virtual TQWidget* leftWidget() { return 0; }
	/**
	 * This function returns the checkbox.
	 * @return A pointer to the checkbox.
	 */
	virtual TQWidget* rightWidget() { return (TQWidget*)_right; }

	/**
	 * This gives the value of the checkbox: "true" if checked, "false" otherwise.
	 *
	 * @return "true" if the checkbox is checked, "false" otherwise.
	 */
	virtual TQString value() const;
	/**
	 * This function can change the state of the checkbox.
	 * It can check or uncheck it.
	 * 
	 * @param value If this parameter is "true", the checkbox gets checked,
	 *              if it is "false", the checkbox get unchecked.
	 */
	virtual void setValue( const TQString& value );

private:
	TQCheckBox *_right;
};

#endif