libtdepim

sendsmsdialog.cpp
1 /*
2  This file is part of libtdepim.
3 
4  Copyright (C) 2005 Con Hennessy <cp.hennessy@iname.com>
5  Tobias Koenig <tokoe@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library 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 GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21  */
22 #include <tqlabel.h>
23 #include <tqlayout.h>
24 #include <tqtextedit.h>
25 
26 #include <tdelocale.h>
27 
28 #include "sendsmsdialog.h"
29 
30 SendSMSDialog::SendSMSDialog( const TQString &recipientName, TQWidget *parent, const char *name )
31  : KDialogBase( Plain, i18n( "Send SMS" ), Ok | Cancel, Ok, parent, name, true, true )
32 {
33  TQWidget *page = plainPage();
34 
35  TQGridLayout *layout = new TQGridLayout( page, 3, 3, marginHint(), spacingHint() );
36 
37  layout->addWidget( new TQLabel( i18n( "Message" ), page ), 0, 0 );
38 
39  mMessageLength = new TQLabel( "0/160", page );
40  mMessageLength->setAlignment( TQt::AlignRight );
41  layout->addWidget( mMessageLength, 0, 2 );
42 
43  mText = new TQTextEdit( page );
44  layout->addMultiCellWidget( mText, 1, 1, 0, 2 );
45 
46  layout->addWidget( new TQLabel( i18n( "Recipient:" ), page ), 2, 0 );
47  layout->addWidget( new TQLabel( recipientName, page ), 2, 2 );
48 
49  setButtonText( Ok, i18n( "Send" ) );
50 
51  connect( mText, TQ_SIGNAL( textChanged() ),
52  this, TQ_SLOT( updateMessageLength() ) );
53  connect( mText, TQ_SIGNAL( textChanged() ),
54  this, TQ_SLOT( updateButtons() ) );
55 
56  updateButtons();
57 
58  mText->setFocus();
59 }
60 
61 TQString SendSMSDialog::text() const
62 {
63  return mText->text();
64 }
65 
66 void SendSMSDialog::updateMessageLength()
67 {
68  int length = mText->length();
69 
70  if( length > 480 )
71  mMessageLength->setText( TQString( "%1/%2 (%3)" ).arg( length ).arg( 500 ).arg( 4 ) );
72  else if( length > 320 )
73  mMessageLength->setText( TQString( "%1/%2 (%3)" ).arg( length ).arg( 480 ).arg( 3 ) );
74  else if( length > 160 )
75  mMessageLength->setText( TQString( "%1/%2 (%3)" ).arg( length ).arg( 320 ).arg( 2 ) );
76  else
77  mMessageLength->setText( TQString( "%1/%2" ).arg( length ).arg( 160 ) );
78 }
79 
80 void SendSMSDialog::updateButtons()
81 {
82  enableButton( Ok, mText->length() > 0 );
83 }
84 
85 #include "sendsmsdialog.moc"