TDE network applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
6.9KB

  1. // -*- Mode: c++-mode; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 2; -*-
  2. //
  3. // Copyright (C) 2003 Grzegorz Jaskiewicz <gj at pointblue.com.pl>
  4. //
  5. // gaduregisteraccount.cpp
  6. //
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU General Public License
  9. // as published by the Free Software Foundation; either version 2
  10. // of the License, or (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program; if not, write to the Free Software
  19. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. // 02110-1301, USA.
  21. #include <tqstring.h>
  22. #include <tqregexp.h>
  23. #include <tqpushbutton.h>
  24. #include <tqlabel.h>
  25. #include <klineedit.h>
  26. #include <tdemessagebox.h>
  27. #include <kdebug.h>
  28. #include <tdelocale.h>
  29. #include <kiconloader.h>
  30. #include <tdeglobal.h>
  31. #include "gaduregisteraccountui.h"
  32. #include "gaduregisteraccount.h"
  33. #include "gaducommands.h"
  34. GaduRegisterAccount::GaduRegisterAccount( TQWidget* parent, const char* name )
  35. : KDialogBase( parent, name, true, i18n( "Register New Account" ), KDialogBase::User1 | KDialogBase::Ok, KDialogBase::User1, true )
  36. {
  37. ui = new GaduRegisterAccountUI( this );
  38. setMainWidget( ui );
  39. ui->valueVerificationSequence->setDisabled( true );
  40. setButtonText( User1, i18n( "&Register" ) );
  41. setButtonText( Ok, i18n( "&Cancel" ) );
  42. enableButton( User1, false );
  43. cRegister = new RegisterCommand( TQT_TQOBJECT(this) );
  44. emailRegexp = new TQRegExp( "[\\w\\d.+_-]{1,}@[\\w\\d.-]{1,}" );
  45. hintPixmap = TDEGlobal::iconLoader()->loadIcon ( "gadu_protocol", TDEIcon::Small );
  46. connect( this, TQT_SIGNAL( user1Clicked() ), TQT_SLOT( doRegister() ) );
  47. connect( this, TQT_SIGNAL( okClicked() ), TQT_SLOT( slotClose() ) );
  48. connect( ui->valueEmailAddress, TQT_SIGNAL( textChanged( const TQString &) ), TQT_SLOT( inputChanged( const TQString & ) ) );
  49. connect( ui->valuePassword, TQT_SIGNAL( textChanged( const TQString & ) ), TQT_SLOT( inputChanged( const TQString & ) ) );
  50. connect( ui->valuePasswordVerify, TQT_SIGNAL( textChanged( const TQString & ) ), TQT_SLOT( inputChanged( const TQString & ) ) );
  51. connect( ui->valueVerificationSequence, TQT_SIGNAL( textChanged( const TQString & ) ), TQT_SLOT( inputChanged( const TQString & ) ) );
  52. connect( cRegister, TQT_SIGNAL( tokenRecieved( TQPixmap, TQString ) ), TQT_SLOT( displayToken( TQPixmap, TQString ) ) );
  53. connect( cRegister, TQT_SIGNAL( done( const TQString&, const TQString& ) ), TQT_SLOT( registrationDone( const TQString&, const TQString& ) ) );
  54. connect( cRegister, TQT_SIGNAL( error( const TQString&, const TQString& ) ), TQT_SLOT( registrationError( const TQString&, const TQString& ) ) );
  55. connect( cRegister, TQT_SIGNAL( operationStatus( const TQString ) ), TQT_SLOT( updateStatus( const TQString ) ) );
  56. updateStatus( i18n( "Retrieving token" ) );
  57. cRegister->requestToken();
  58. show();
  59. }
  60. void
  61. GaduRegisterAccount::doRegister( )
  62. {
  63. cRegister->setUserinfo( ui->valueEmailAddress->text(), ui->valuePassword->text(), ui->valueVerificationSequence->text() );
  64. cRegister->execute();
  65. enableButton( User1, false );
  66. }
  67. void
  68. GaduRegisterAccount::validateInput()
  69. {
  70. int valid = true;
  71. int passwordHighlight = false;
  72. if ( !emailRegexp->exactMatch( ui->valueEmailAddress->text() ) )
  73. {
  74. updateStatus( i18n( "Please enter a valid E-Mail Address." ) );
  75. ui->pixmapEmailAddress->setPixmap ( hintPixmap );
  76. valid = false;
  77. }
  78. else {
  79. ui->pixmapEmailAddress->setText ( "" );
  80. }
  81. if ( valid && ( ( ui->valuePassword->text().isEmpty() ) || ( ui->valuePasswordVerify->text().isEmpty() ) ) )
  82. {
  83. updateStatus( i18n( "Please enter the same password twice." ) );
  84. valid = false;
  85. passwordHighlight = true;
  86. }
  87. if ( valid && ( ui->valuePassword->text() != ui->valuePasswordVerify->text() ) )
  88. {
  89. updateStatus( i18n( "Password entries do not match." ) );
  90. valid = false;
  91. passwordHighlight = true;
  92. }
  93. if ( valid && ( ui->valueVerificationSequence->text().isEmpty() ) )
  94. {
  95. updateStatus( i18n( "Please enter the verification sequence." ) );
  96. ui->pixmapVerificationSequence->setPixmap ( hintPixmap );
  97. valid = false;
  98. }
  99. else {
  100. ui->pixmapVerificationSequence->setText ( "" );
  101. }
  102. if ( passwordHighlight == true )
  103. {
  104. ui->pixmapPassword->setPixmap ( hintPixmap );
  105. ui->pixmapPasswordVerify->setPixmap ( hintPixmap );
  106. }
  107. else {
  108. ui->pixmapPassword->setText ( "" );
  109. ui->pixmapPasswordVerify->setText ( "" );
  110. }
  111. if ( valid )
  112. {
  113. // clear status message if we have valid data
  114. updateStatus( "" );
  115. }
  116. enableButton( User1, valid );
  117. }
  118. void
  119. GaduRegisterAccount::inputChanged( const TQString & )
  120. {
  121. validateInput();
  122. }
  123. void
  124. GaduRegisterAccount::registrationDone( const TQString& /*title*/, const TQString& /*what */ )
  125. {
  126. ui->valueEmailAddress->setDisabled( true );
  127. ui->valuePassword->setDisabled( true );
  128. ui->valuePasswordVerify->setDisabled( true );
  129. ui->valueVerificationSequence->setDisabled( true );
  130. ui->labelEmailAddress->setDisabled( true );
  131. ui->labelPassword->setDisabled( true );
  132. ui->labelPasswordVerify->setDisabled( true );
  133. ui->labelVerificationSequence->setDisabled( true );
  134. ui->labelInstructions->setDisabled( true );
  135. emit registeredNumber( cRegister->newUin(), ui->valuePassword->text() );
  136. updateStatus( i18n( "Account created; your new UIN is %1." ).arg(TQString::number( cRegister->newUin() ) ) );
  137. enableButton( User1, false );
  138. setButtonText( Ok, i18n( "&Close" ) );
  139. }
  140. void
  141. GaduRegisterAccount::registrationError( const TQString& title, const TQString& what )
  142. {
  143. updateStatus( i18n( "Registration failed: %1" ).arg( what ) );
  144. KMessageBox::sorry( this, "Registration was unsucessful, please try again.", title );
  145. disconnect( this, TQT_SLOT( displayToken( TQPixmap, TQString ) ) );
  146. disconnect( this, TQT_SLOT( registrationDone( const TQString&, const TQString& ) ) );
  147. disconnect( this, TQT_SLOT( registrationError( const TQString&, const TQString& ) ) );
  148. disconnect( this, TQT_SLOT( updateStatus( const TQString ) ) );
  149. ui->valueVerificationSequence->setDisabled( true );
  150. ui->valueVerificationSequence->setText( "" );
  151. enableButton( User1, false );
  152. updateStatus( "" );
  153. // emit UIN 0, to enable 'register new account' button again in dialog below
  154. emit registeredNumber( 0, TQString( "" ) );
  155. deleteLater();
  156. }
  157. void
  158. GaduRegisterAccount::displayToken( TQPixmap image, TQString /*tokenId */ )
  159. {
  160. ui->valueVerificationSequence->setDisabled( false );
  161. ui->pixmapToken->setPixmap( image );
  162. validateInput();
  163. }
  164. void
  165. GaduRegisterAccount::updateStatus( const TQString status )
  166. {
  167. ui->labelStatusMessage->setAlignment( AlignCenter );
  168. ui->labelStatusMessage->setText( status );
  169. }
  170. void
  171. GaduRegisterAccount::slotClose()
  172. {
  173. deleteLater();
  174. }
  175. GaduRegisterAccount::~GaduRegisterAccount( )
  176. {
  177. kdDebug( 14100 ) << " register Cancel " << endl;
  178. }
  179. #include "gaduregisteraccount.moc"