summaryrefslogtreecommitdiffstats
path: root/korn/account_input.h
blob: 80f9890349622d67717f2c3ddf0f5f1c58b5427a (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 (mart.kde@hccnet.nl)
*
* 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 QWidget;
class QString;
class QStringList;

class QLabel;
class KLineEdit;
class KURLRequester;
class QComboBox;
class QCheckBox;

#include <qmap.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 QString& 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 QWidget* 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 QWidget* 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.
	 */
	QString 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 QString 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 QString& value ) = 0;
protected:
	QString *_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( QWidget *parent, const QString& title, Type type, const QString& defaul, const QString& 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( QWidget *parent, const QString& title, int min, int max, const QString& defaul, const QString& configName );
	/**
	 * Destructor
	 */
	virtual ~TextInput();

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

	/**
	 * The value of the lineedit.
	 * @return The value of the lineedit.
	 */
	virtual QString 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 QString& value );
private:
	QLabel *_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( QWidget *parent, const QString& title, const QString& defaul, const QString& configName );
	/**
	 * Destructor
	 */
	virtual ~URLInput();

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

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

private:
	QLabel *_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( QWidget *parent, const QString& title, const QMap<QString,QString>& list,
	            const QString& defaul, const QString& configName );
	/**
	 * Destructor
	 */
	virtual ~ComboInput();

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

	/**
	 * Return the value of the currently selected item
	 * @return The value of the currently selected item
	 */
	virtual QString 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 QString& value );
private:
	QLabel *_left;
	QComboBox *_right;
	QMap< QString, QString > *_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( QWidget *parent, const QString& title, const QString& defaul, const QString& configName );
	/**
	 * Destructor
	 */
	virtual ~CheckboxInput();

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

	/**
	 * This gives the value of the checkbox: "true" if checked, "false" otherwise.
	 *
	 * @return "true" if the checkbox is checked, "false" otherwise.
	 */
	virtual QString 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 QString& value );

private:
	QCheckBox *_right;
};

#endif