akonadi
smsdialog.cpp
00001 /* 00002 This file is part of Akonadi Contact. 00003 00004 Copyright (c) 2010 Felix Mauch (felix_mauch@web.de) 00005 00006 This library is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU Library General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or (at your 00009 option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, but WITHOUT 00012 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to the 00018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 02110-1301, USA. 00020 */ 00021 00022 #include "smsdialog.h" 00023 00024 #include <kabc/phonenumber.h> 00025 #include <klocale.h> 00026 #include <kmessagebox.h> 00027 #include <ktextedit.h> 00028 00029 #include <QtGui/QLabel> 00030 #include <QtGui/QPushButton> 00031 #include <QtGui/QVBoxLayout> 00032 00033 SmsDialog::SmsDialog( const KABC::PhoneNumber &number ) 00034 : mNumber( number.number() ) 00035 { 00036 initUI(); 00037 } 00038 00039 SmsDialog::~SmsDialog() 00040 { 00041 } 00042 00043 QString SmsDialog::message() const 00044 { 00045 return mText; 00046 } 00047 00048 void SmsDialog::initUI() 00049 { 00050 setCaption( i18n( "SMS text" ) ); 00051 setButtons( Ok | Cancel ); 00052 setDefaultButton( Ok ); 00053 showButtonSeparator( true ); 00054 00055 QWidget *page = new QWidget( this ); 00056 setMainWidget( page ); 00057 page->setFixedWidth( 300 ); 00058 00059 QVBoxLayout *topLayout = new QVBoxLayout( page ); 00060 topLayout->setSpacing( spacingHint() ); 00061 topLayout->setMargin( 0 ); 00062 00063 00064 QLabel *label = new QLabel( i18n( "Please insert SMS text for an SMS to the following number: %1", mNumber ), page ); 00065 topLayout->addWidget( label ); 00066 label->setWordWrap( true ); 00067 00068 mSmsTextEdit = new KTextEdit( page ); 00069 mSmsTextEdit->setAcceptRichText( false ); 00070 label->setBuddy( mSmsTextEdit ); 00071 topLayout->addWidget( mSmsTextEdit ); 00072 00073 connect( mSmsTextEdit, SIGNAL(textChanged()), SLOT(updateCounter()) ); 00074 00075 mLengthLabel = new QLabel( QLatin1String("-") , page ); 00076 topLayout->addWidget( mLengthLabel ); 00077 00078 mSmsTextEdit->setFocus(); 00079 updateCounter(); 00080 } 00081 00082 void SmsDialog::updateCounter() 00083 { 00084 mText = mSmsTextEdit->toPlainText(); 00085 unsigned int messageSize = 160; 00086 00087 bool noLatin1Char = false; 00088 const int size = mText.length(); 00089 for ( int i = 0; i <size; ++i ) 00090 { 00091 if ( mText[i].row() > 0 ) { 00092 noLatin1Char = true; 00093 messageSize = 70; 00094 break; 00095 } 00096 } 00097 const int numberSms = ( size - ( size % messageSize ) ) / messageSize + 1; 00098 const int numberChars = messageSize * numberSms; 00099 00100 mLengthLabel->setText( i18n( "%1/%2 (%3 SMS)", size, numberChars, numberSms ) ); 00101 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:09:24 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:09:24 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.