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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
|
/*
* File name: kfeedback.cpp
* Summary: User feedback form
* License: LGPL - See file COPYING.LIB for details.
* Author: Stefan Hundhammer <sh@suse.de>
*
* Updated: 2004-11-23
*/
#include <tqheader.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqglobal.h>
#include <tqmultilineedit.h>
#include <tqhbox.h>
#include <kglobal.h>
#include <kapp.h>
#include <klocale.h>
#include <kdebug.h>
#include <kaboutdata.h>
#include <kiconloader.h>
#include <kurl.h>
#include "kfeedback.h"
KFeedbackDialog::KFeedbackDialog( const TQString & feedbackMailAddress,
const TQString & helpTopic )
: KDialogBase( Plain, // dialogFace
i18n( "Feedback" ), // caption
Apply | Cancel
| ( helpTopic.isEmpty() ? 0 : (int) Help ), // buttonMask
Apply ) // defaultButton
{
TQVBoxLayout * layout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
setButtonApply( KGuiItem( i18n( "&Mail this..." ) ) );
if ( ! helpTopic.isEmpty() )
setHelp( helpTopic );
_form = new KFeedbackForm( feedbackMailAddress, plainPage() );
TQ_CHECK_PTR( _form );
layout->addWidget( _form );
checkSendButton();
connect( this, TQT_SIGNAL( applyClicked() ),
_form, TQT_SLOT ( sendMail() ) );
connect( _form, TQT_SIGNAL( mailSent() ),
this, TQT_SLOT ( hide() ) );
connect( _form, TQT_SIGNAL( mailSent() ),
this, TQT_SIGNAL( mailSent() ) );
connect( _form, TQT_SIGNAL( checkComplete() ),
this, TQT_SLOT ( checkSendButton() ) );
}
KFeedbackDialog::~KFeedbackDialog()
{
// NOP
}
void
KFeedbackDialog::checkSendButton()
{
enableButtonApply( _form->readyToSend() );
}
KFeedbackForm::KFeedbackForm( const TQString & feedbackMailAddress,
TQWidget * parent )
: TQVBox( parent )
, _feedbackMailAddress( feedbackMailAddress )
{
//
// Explanation above the question list
//
TQLabel * label = new TQLabel( i18n( "<p><b>Please tell us your opinion about this program.</b></p>"
"<p>You will be able to review everything in your mailer "
"before any mail is sent.<br>"
"Nothing will be sent behind your back.</p>"
), this );
//
// Question list
//
_questionList = new KFeedbackQuestionList( this );
TQ_CHECK_PTR( _questionList );
connect( _questionList, TQT_SIGNAL( checkComplete() ),
this, TQT_SLOT ( slotCheckComplete() ) );
//
// Explanation below the question list
//
TQHBox * hbox = new TQHBox( this );
TQ_CHECK_PTR( hbox );
TQSizePolicy pol( TQSizePolicy::Fixed, TQSizePolicy::Fixed ); // hor / vert
label = new TQLabel( i18n( "Questions marked with " ), hbox );
TQ_CHECK_PTR( label );
label->setSizePolicy( pol );
label = new TQLabel( hbox );
TQ_CHECK_PTR( label );
label->setPixmap( KGlobal::iconLoader()->loadIcon( "edit", KIcon::Small ) );
label->setSizePolicy( pol );
label = new TQLabel( i18n( " must be answered before a mail can be sent.") , hbox );
TQ_CHECK_PTR( label );
label->setSizePolicy( pol );
new TQWidget( hbox ); // Fill any leftover space to the right.
//
// Free-text comment field
//
label = new TQLabel( "\n" + i18n( "&Additional Comments:" ), this ); TQ_CHECK_PTR( label );
_comment = new TQMultiLineEdit( this ); TQ_CHECK_PTR( _comment );
label->setBuddy( _comment );
_comment->setWordWrap( TQMultiLineEdit::FixedColumnWidth );
_comment->setWrapColumnOrWidth( 70 );
}
KFeedbackForm::~KFeedbackForm()
{
// NOP
}
void
KFeedbackForm::sendMail()
{
//
// Build mail subject
//
TQString subject;
const KAboutData * aboutData = KGlobal::instance()->aboutData();
if ( aboutData )
subject = aboutData->programName() + "-" + aboutData->version();
else
subject = kapp->name();
subject = "[kde-feedback] " + subject + " user feedback";
//
// Build mail body
//
TQString body = subject + "\n\n"
+ formatComment()
+ _questionList->result();
//
// Build "mailto:" URL from all this
//
KURL mail;
mail.setProtocol( "mailto" );
mail.setPath( _feedbackMailAddress );
mail.setQuery( "?subject=" + KURL::encode_string( subject ) +
"&body=" + KURL::encode_string( body ) );
// TODO: Check for maximum command line length.
//
// The hard part with this is how to get this from all that 'autoconf'
// stuff into 'config.h' or some other include file without hardcoding
// anything - this is too system dependent.
//
// Actually send mail
//
kapp->invokeMailer( mail );
emit mailSent();
}
void
KFeedbackForm::slotCheckComplete()
{
emit checkComplete();
}
TQString
KFeedbackForm::formatComment()
{
TQString result = _comment->text();
if ( ! result.isEmpty() )
{
result = "<comment>\n" + result + "\n</comment>\n\n";
}
return result;
}
bool
KFeedbackForm::readyToSend()
{
return _questionList->isComplete();
}
KFeedbackQuestionList::KFeedbackQuestionList( TQWidget *parent )
: TQListView( parent )
{
addColumn( "" );
header()->hide();
}
KFeedbackQuestionList::~KFeedbackQuestionList()
{
// NOP
}
bool
KFeedbackQuestionList::isComplete()
{
KFeedbackQuestion * question = firstQuestion();
while ( question )
{
if ( question->isRequired() && ! question->isAnswered() )
return false;
question = question->nextQuestion();
}
return true;
}
TQString
KFeedbackQuestionList::result()
{
TQString res;
KFeedbackQuestion * question = firstQuestion();
while ( question )
{
res += question->result();
question = question->nextQuestion();
}
return res;
}
KFeedbackQuestion *
KFeedbackQuestionList::addQuestion( const TQString & text,
const TQString & id,
bool exclusiveAnswer,
bool required )
{
KFeedbackQuestion * question = new KFeedbackQuestion( this, text, id,
exclusiveAnswer,
required );
TQ_CHECK_PTR( question );
return question;
}
void
KFeedbackQuestionList::addYesNoQuestion( const TQString & text,
const TQString & id,
bool required )
{
KFeedbackQuestion * question = new KFeedbackQuestion( this, text, id,
true, // exclusive
required );
TQ_CHECK_PTR( question );
question->addAnswer( i18n( "yes" ), "yes" );
question->addAnswer( i18n( "no" ), "no" );
}
void
KFeedbackQuestionList::questionAnswered()
{
emit checkComplete();
}
void
KFeedbackQuestionList::questionAdded( KFeedbackQuestion * question)
{
if ( question->isRequired() )
emit checkComplete();
}
static int nextNo = 0;
KFeedbackQuestion::KFeedbackQuestion( KFeedbackQuestionList * parent,
const TQString & text,
const TQString & id,
bool exclusiveAnswer,
bool required,
bool open )
: TQCheckListItem( parent, text )
, _id( id )
, _exclusiveAnswer( exclusiveAnswer )
, _required( required )
{
if ( required )
{
setPixmap( 0, KGlobal::iconLoader()->loadIcon( "edit", KIcon::Small ) );
}
setOpen( open );
_no = nextNo++;
parent->questionAdded( this );
}
void
KFeedbackQuestion::addAnswer( const TQString & text,
const TQString & id )
{
new KFeedbackAnswer( this, text, id, _exclusiveAnswer );
}
bool
KFeedbackQuestion::isAnswered()
{
if ( ! _exclusiveAnswer )
{
/**
* If any number of answers is permitted for this question, this
* question is always considered to be answered.
**/
return true;
}
/**
* If this question requires an exclusive answer, exactly one of them
* should be checked. We don't need to bother about more than one being
* checked here - TQListView does that for us.
**/
KFeedbackAnswer *answer = firstAnswer();
while ( answer )
{
if ( answer->isChecked() )
return true;
answer = answer->nextAnswer();
}
return false;
}
TQString
KFeedbackQuestion::result()
{
TQString res;
int answers = 0;
KFeedbackAnswer *answer = firstAnswer();
while ( answer )
{
if ( answer->isChecked() )
{
res += _id + "=\"" + answer->id() + "\"\n";
answers++;
}
answer = answer->nextAnswer();
}
if ( answers > 1 )
{
res = "\n" + res + "\n";
}
return res;
}
TQString
KFeedbackQuestion::text()
{
return TQCheckListItem::text(0);
}
TQString
KFeedbackQuestion::key( int, bool ) const
{
TQString no;
no.sprintf( "%08d", _no );
return no;
}
KFeedbackQuestionList *
KFeedbackQuestion::questionList() const
{
return dynamic_cast<KFeedbackQuestionList *>( listView() );
}
KFeedbackAnswer::KFeedbackAnswer( KFeedbackQuestion * parent,
const TQString & text,
const TQString & id,
bool exclusive )
: TQCheckListItem( parent,
text,
exclusive
? TQCheckListItem::RadioButton
: TQCheckListItem::CheckBox )
, _id( id )
{
_no = nextNo++;
}
TQString
KFeedbackAnswer::text()
{
return TQCheckListItem::text(0);
}
TQString
KFeedbackAnswer::key( int, bool ) const
{
TQString no;
no.sprintf( "%08d", _no );
return no;
}
void
KFeedbackAnswer::stateChange( bool newState )
{
if ( newState && question()->isRequired() )
{
KFeedbackQuestionList * list = question()->questionList();
if ( list )
list->questionAnswered();
}
}
// EOF
|