diff -r 238255e8b033 -r 84d9eb65b26f messagingapp/msgui/conversationview/src/msgeditorwidget.cpp --- a/messagingapp/msgui/conversationview/src/msgeditorwidget.cpp Fri Apr 16 14:56:15 2010 +0300 +++ b/messagingapp/msgui/conversationview/src/msgeditorwidget.cpp Mon May 03 12:29:07 2010 +0300 @@ -20,16 +20,36 @@ // SYSTEM INCLUDES #include #include +#include #include +#include +#include +#include +#include +#include +#include +#include "unieditorpluginloader.h" +#include "unieditorplugininterface.h" +#include "unisendingsettings.h" +#include "unieditorgenutils.h" #include "debugtraces.h" // LOCAL CONSTANTS const QString PLUGINPATH("conversationviewplugin.dll"); -const QString SMS_SERVICE("messaging.mserver.sms"); -const QString SEND_BUTTON(QObject::tr("Send")); +const QString SEND_ICON("qtg_mono_send"); +const QString BACKGROUND("qtg_fr_input_bg"); +const QString BACKGROUND_FRAME("qtg_fr_btn_normal"); -const QString SEND_ICON(":/icons/qtg_mono_send.png"); +const QString SEND_BUTTON_NORMAL("qtg_fr_input_btn_function_normal"); +const QString SEND_BUTTON_PRESSED("qtg_fr_input_btn_function_pressed"); +const QString SEND_BUTTON_DISABLED("qtg_fr_input_btn_function_disabled"); + +#define LOC_SMS_CHAR_LIMIT_REACHED hbTrId("txt_messaging_dialog_sms_character_count_exceeded") +#define LOC_DIALOG_OK hbTrId("txt_common_button_ok") +#define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel") + +const TInt KShowCounterLimit = 10; QGraphicsItem* FOCUSITEM = 0; @@ -38,8 +58,8 @@ // @see header //--------------------------------------------------------------- MsgEditorWidget::MsgEditorWidget(QGraphicsItem *parent) : - HbWidget(parent), mServiceId(SMS_SERVICE), mMsgEditor(NULL), - mSendButton(NULL) + HbWidget(parent), mMsgEditor(NULL), + mSendButton(NULL),mPluginLoader(NULL) { int baseId = style()->registerPlugin(PLUGINPATH); @@ -48,6 +68,13 @@ #endif setPluginBaseId(baseId); + + //setting background. + HbFrameItem* backGround = new HbFrameItem(this); + backGround->frameDrawer().setFrameGraphicsName(BACKGROUND); + backGround->frameDrawer().setFrameType(HbFrameDrawer::ThreePiecesVertical); + backGround->frameDrawer().setFillWholeRect(true); + this->setBackgroundItem(backGround); // Initialize the widget. init(); @@ -61,16 +88,40 @@ { // Create mandatory element of mesh layout. mMsgEditor = new MsgEditor(this); - mMsgEditor->setMaxRows(5); // NOTE: Don't remove this line. + mMsgEditor->setMaxRows(3); // NOTE: Don't remove this line. HbStyle::setItemName(mMsgEditor, "msgEditor"); mSendButton = new HbPushButton(this); HbStyle::setItemName(mSendButton, "sendButton"); mSendButton->setIcon(HbIcon(SEND_ICON)); mSendButton->setEnabled(false); + HbFrameDrawer* drawer = new HbFrameDrawer(this); + drawer->setFrameType(HbFrameDrawer::NinePieces); + mSendButton->setFrameBackground(drawer); + updateButtonBackground(SEND_BUTTON_DISABLED); + + mCharCounter = new HbTextItem(this); + HbStyle::setItemName(mCharCounter, "charCounter"); + mCharCounter->setZValue(1.5); + + mBackgroundItem = new HbFrameItem(this); + HbStyle::setItemName(mBackgroundItem, "charCounterFrame"); + + mBackgroundItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); + mBackgroundItem->frameDrawer().setFillWholeRect(true); + + mBackgroundItem->frameDrawer().setFrameGraphicsName( + BACKGROUND_FRAME); + + //Create editor utils object + mEditorUtils = new UniEditorGenUtils(); + FOCUSITEM = mSendButton; + connect(mSendButton, SIGNAL(clicked()),this, SLOT(onClicked())); + connect(mSendButton, SIGNAL(pressed()),this, SLOT(onPressed())); + connect(mSendButton, SIGNAL(released()),this, SLOT(onReleased())); connect(mMsgEditor, SIGNAL(replyStarted()),this, SIGNAL(replyStarted())); connect(mMsgEditor, SIGNAL(textChanged(QString)),this,SLOT(onTextChanged(QString))); @@ -83,15 +134,7 @@ MsgEditorWidget::~MsgEditorWidget() { style()->unregisterPlugin(PLUGINPATH); -} - -//--------------------------------------------------------------- -// MsgEditorWidget::serviceId -// @see header -//--------------------------------------------------------------- -const QString& MsgEditorWidget::serviceId() -{ - return mServiceId; + delete mEditorUtils; } //--------------------------------------------------------------- @@ -123,17 +166,24 @@ } //--------------------------------------------------------------- -// MsgEditorWidget::clear +// MsgEditorWidget::onTextChanged // @see header //--------------------------------------------------------------- void MsgEditorWidget::onTextChanged(const QString& str) { + //If char limit is already reached we are about to show the sms limit dialog + //So we need not process the additional character entered + if(mSmsCharLimitReached) + { + return; + } if(str.length() > 0 ) { if(!mSendButton->isEnabled()) { mSendButton->setFocusProxy(mMsgEditor); mSendButton->setEnabled(true); + updateButtonBackground(SEND_BUTTON_NORMAL); } } else @@ -142,8 +192,88 @@ { mSendButton->setFocusProxy(0); mSendButton->setEnabled(false); + updateButtonBackground(SEND_BUTTON_DISABLED); } } + + //Check done for optimization + //Only if content is deleted we need to call encodingsettings again + if(mPrevBuffer.isEmpty() || str.size() <= mPrevBuffer.size()) + { + mPluginInterface->setEncodingSettings(EFalse,ESmsEncodingNone,mCharSupportType); + } + + TInt numOfRemainingChars; + TInt numOfPDUs; + TBool unicodeMode; + TSmsEncoding alternativeEncodingType; + QString string = str; + mPluginInterface->getNumPDUs(string, numOfRemainingChars, numOfPDUs, + unicodeMode, alternativeEncodingType); + + //Set char counter value + QString display = QString("%1(%2)").arg(numOfRemainingChars).arg(numOfPDUs); + mCharCounter->setText(display); + + if(numOfPDUs > 1 || numOfRemainingChars <= KShowCounterLimit ) + { + mCharCounter->setVisible(true); + mBackgroundItem->setVisible(true); + } + else + { + mCharCounter->setVisible(false); + mBackgroundItem->setVisible(false); + } + + //Check if sms segment limit has been reached + bool unicode = (unicodeMode) ? true : false; + int contentSize = mEditorUtils->UTF8Size(string); + int maxSmsSize = mEditorUtils->MaxSmsMsgSizeL(unicode); + + if(contentSize > maxSmsSize) + { + //Give breathing time for ITUT to complete its processing + //without this there is a crash as ITUT cant complete its processing + mSmsCharLimitReached = true; + QTimer::singleShot(50, this, SLOT(handleSmsCharLimitReached())); + if(mPrevBuffer.isEmpty()) + { + //Chop the last char and set it to the editor + string.chop(1); + mPrevBuffer = string; + } + } + else + { + //Save the previous buffer + mPrevBuffer = string; + } +} + +//--------------------------------------------------------------- +// MsgEditorWidget::handleSmsCharLimitReached +// @see header +//--------------------------------------------------------------- +void MsgEditorWidget::handleSmsCharLimitReached() +{ + mSmsCharLimitReached = false; + + if(HbMessageBox::question(LOC_SMS_CHAR_LIMIT_REACHED, + LOC_DIALOG_OK, + LOC_BUTTON_CANCEL)) + { + //Launch UniEditor + emit smsCharLimitReached(); + return; + } + else + { + //Set the previous content + setContent(QString(mPrevBuffer)); + return; + } + } //--------------------------------------------------------------- @@ -165,6 +295,76 @@ emit sendMessage(); } +//--------------------------------------------------------------- +// MsgEditor::updateButtonBackground +// @see header +//--------------------------------------------------------------- +void MsgEditorWidget::updateButtonBackground(const QString& bg) + { + HbFrameDrawer* drawer = mSendButton->frameBackground(); + if(drawer) + { + drawer->setFrameGraphicsName(bg); + } + } + +//--------------------------------------------------------------- +// MsgEditor::onPressed +// @see header +//--------------------------------------------------------------- +void MsgEditorWidget::onPressed() + { + updateButtonBackground(SEND_BUTTON_PRESSED); + } + +//--------------------------------------------------------------- +// MsgEditor::onReleased +// @see header +//--------------------------------------------------------------- +void MsgEditorWidget::onReleased() + { + updateButtonBackground(SEND_BUTTON_NORMAL); + } + +//--------------------------------------------------------------- +// MsgEditor::setEncodingSettings +// @see header +//--------------------------------------------------------------- +void MsgEditorWidget::setEncodingSettings() +{ + if( mPluginLoader ) + { + delete mPluginLoader; + } + mPluginLoader = new UniEditorPluginLoader(this); + + mPluginInterface = + mPluginLoader->getUniEditorPlugin(ConvergedMessage::Sms); + + CSmsSettings* settings = CSmsSettings::NewLC(); + CSmsAccount* account = CSmsAccount::NewLC(); + account->LoadSettingsL( *settings ); + + if( settings->CharacterSet() == TSmsDataCodingScheme::ESmsAlphabetUCS2) + { + mCharSupportType = TUniSendingSettings::EUniCharSupportFull; + } + else + { + mCharSupportType = TUniSendingSettings::EUniCharSupportReduced; + } + + CleanupStack::PopAndDestroy( account ); + CleanupStack::PopAndDestroy( settings ); + + //Set the mPrevBuffer to NULL initially + mPrevBuffer = QString(); + + mSmsCharLimitReached = false; + + mCharCounter->setVisible(false); + mBackgroundItem->setVisible(false); +} //--------------------------------------------------------------- // MsgEditor::MsgEditor @@ -206,4 +406,5 @@ HbLineEdit::focusOutEvent(event); } + // EOF