16 */ |
16 */ |
17 |
17 |
18 #include <glxcommondialogs.h> |
18 #include <glxcommondialogs.h> |
19 |
19 |
20 #include <hbaction.h> |
20 #include <hbaction.h> |
|
21 #include <QEventLoop> |
21 |
22 |
22 GlxTextInputDialog::GlxTextInputDialog() |
23 GlxTextInputDialog::GlxTextInputDialog() |
23 { |
24 : mDialog ( NULL ), |
24 } |
25 mEventLoop ( 0 ), |
|
26 mResult ( false ) |
|
27 { |
|
28 } |
25 |
29 |
26 GlxTextInputDialog::~GlxTextInputDialog() |
30 GlxTextInputDialog::~GlxTextInputDialog() |
27 { |
31 { |
28 } |
32 } |
29 |
33 |
30 QString GlxTextInputDialog::getText(const QString &label, |
34 QString GlxTextInputDialog::getText(const QString &label, |
31 const QString &text, bool *ok) |
35 const QString &text, bool *ok) |
32 { |
36 { |
|
37 QEventLoop eventLoop; |
|
38 mEventLoop = &eventLoop; |
|
39 |
33 mDialog = new HbInputDialog(); |
40 mDialog = new HbInputDialog(); |
34 mDialog->setPromptText(label); |
41 mDialog->setPromptText(label); |
35 mDialog->setInputMode(HbInputDialog::TextInput); |
42 mDialog->setInputMode(HbInputDialog::TextInput); |
36 mDialog->setValue(text); |
43 mDialog->setValue(text); |
37 connect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ), |
44 connect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ), |
38 this, SLOT( textChanged (const QString &))); |
45 this, SLOT( textChanged (const QString &))); |
39 HbAction* action = mDialog->exec(); |
46 |
|
47 mDialog->open( this, SLOT( dialogClosed( HbAction* ) ) ); |
|
48 eventLoop.exec( ); |
|
49 mEventLoop = 0 ; |
|
50 |
|
51 if ( ok ) { |
|
52 *ok = mResult ; |
|
53 } |
40 QString retText = NULL; |
54 QString retText = NULL; |
41 if (action == mDialog->secondaryAction()) |
55 if ( mResult ) { |
42 { //Cancel was pressed |
|
43 if (ok) |
|
44 { |
|
45 *ok = false; |
|
46 } |
|
47 } |
|
48 else |
|
49 { //OK was pressed |
|
50 if (ok) |
|
51 { |
|
52 *ok = true; |
|
53 } |
|
54 retText = mDialog->value().toString().trimmed(); |
56 retText = mDialog->value().toString().trimmed(); |
55 } |
57 } |
|
58 |
56 disconnect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ), |
59 disconnect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ), |
57 this, SLOT( textChanged (const QString &))); |
60 this, SLOT( textChanged (const QString &))); |
58 delete mDialog; |
61 delete mDialog; |
59 mDialog = NULL; |
62 mDialog = NULL; |
60 return retText; |
63 return retText; |
61 } |
64 } |
62 |
65 |
63 void GlxTextInputDialog::textChanged(const QString &text) |
66 void GlxTextInputDialog::textChanged(const QString &text) |
64 { |
67 { |
65 if (text.trimmed().isEmpty()) |
68 if (text.trimmed().isEmpty()) { |
66 { |
69 mDialog->actions().first()->setEnabled(false); |
67 mDialog->primaryAction()->setEnabled(false); |
|
68 } |
|
69 else |
|
70 { |
|
71 mDialog->primaryAction()->setEnabled(true); |
|
72 } |
|
73 } |
70 } |
|
71 else { |
|
72 mDialog->actions().first()->setEnabled(true); |
|
73 } |
|
74 } |
|
75 |
|
76 void GlxTextInputDialog::dialogClosed(HbAction *action) |
|
77 { |
|
78 HbInputDialog *dlg = static_cast<HbInputDialog*>(sender()); |
|
79 if( action == dlg->actions().first() ) { |
|
80 mResult = true ; |
|
81 } |
|
82 else { |
|
83 mResult = false ; |
|
84 } |
|
85 if ( mEventLoop && mEventLoop->isRunning( ) ) { |
|
86 mEventLoop->exit( 0 ); |
|
87 } |
|
88 } |