diff -r 238255e8b033 -r 84d9eb65b26f messagingapp/msgnotifications/msgindicatorplugin/src/msgindicator.cpp --- a/messagingapp/msgnotifications/msgindicatorplugin/src/msgindicator.cpp Fri Apr 16 14:56:15 2010 +0300 +++ b/messagingapp/msgnotifications/msgindicatorplugin/src/msgindicator.cpp Mon May 03 12:29:07 2010 +0300 @@ -14,83 +14,139 @@ * Description: * */ + #include "msgindicator.h" #include "msgindicator_p.h" +#include "msginfodefs.h" +#include "debugtraces.h" #include #include #include #include -#include "debugtraces.h" +#include +#include +#include +#include +#include -#include //Localized Constants #define LOC_UNREAD_MESSAGES hbTrId("txt_messaging_list_ln") #define LOC_NEW_MESSAGES hbTrId("txt_common_opt_ln_new_messages") +#define LOC_RECEIVED_FILES hbTrId("Received files") +#define LOC_UNREAD_SINGLE_MESSAGE hbTrId("Unread Message") +#define LOC_UNREAD_MULTIPLE_MESSAGES hbTrId("Unread Messages") +#define LOC_FAILED_SINGLE_MESSAGE hbTrId("Failed Message") +#define LOC_FAILED_MULTIPLE_MESSAGES hbTrId("Failed Messages") +#define LOC_OUTGOING_SINGLE_MESSAGE hbTrId("Outgoing Message") +#define LOC_OUTGOING_MULTIPLE_MESSAGES hbTrId("Outgoing Messages") -//---------------------------------------------------------------------- -class ServiceRequestSenderTask : public QRunnable - { -public: - ServiceRequestSenderTask(qint64 conversationId):mConvId(conversationId) {} - - void run() - { - XQServiceRequest snd( - "com.nokia.services.hbserviceprovider.conversationview", - "open(qint64)",false); - snd << mConvId; - bool res=snd.send(); - } - - ~ServiceRequestSenderTask() +/** + * The number of indicators. + */ +static const int MsgIndicatorCount = 4; + +/** + * The attibutes of an indicator. + */ +struct MsgIndicatorInfo +{ + QString icon; + QString primaryText; + QString secondaryText; +}; + +/** + * Array of Indicator information elements + */ + +//TODO: Localize + + +// TODO: get regular icons, thes are placeholders.hanlde later +static const MsgIndicatorInfo IndicatorInfo[MsgIndicatorCount] = { + { "", "", "" }, + { "qtg_large_new_message", "newindicatorplugin", "%1 unread messages" }, + { "qtg_small_fail", "failedindicatorplugin", "%1 Failed message%2" }, + { "qtg_small_outbox","pendingindicatorplugin", "%1 Outgoing message%2" } +}; + +// ---------------------------------------------------------------------------- +// ServiceRequestSenderTask::ServiceRequestSenderTask +// @see msgindicator.h +// ---------------------------------------------------------------------------- +ServiceRequestSenderTask::ServiceRequestSenderTask(qint64 conversationId): +mConvId(conversationId) { } - - private: - qint64 mConvId; - }; - -//---------------------------------------------------------------------- + +// ---------------------------------------------------------------------------- +// ServiceRequestSenderTask::~ServiceRequestSenderTask +// @see msgindicator.h +// ---------------------------------------------------------------------------- +ServiceRequestSenderTask::~ServiceRequestSenderTask() + { + } +// ---------------------------------------------------------------------------- +// ServiceRequestSenderTask::run +// @see msgindicator.h +// ---------------------------------------------------------------------------- +void ServiceRequestSenderTask::run() + { + QList args; + QString serviceName("com.nokia.services.hbserviceprovider"); + QString operation("open(qint64)"); + XQAiwRequest* request; + XQApplicationManager appManager; + request = appManager.create(serviceName, "conversationview", operation, false); // embedded + if ( request == NULL ) + { + return; + } + args << QVariant(mConvId); + request->setArguments(args); + request->send(); + delete request; + } // ---------------------------------------------------------------------------- // MsgIndicator::MsgIndicator // @see msgindicator.h // ---------------------------------------------------------------------------- MsgIndicator::MsgIndicator(const QString &indicatorType) : -HbIndicatorInterface(indicatorType, - HbIndicatorInterface::GroupPriorityHigh, - InteractionActivated) - { + HbIndicatorInterface(indicatorType, HbIndicatorInterface::GroupPriorityHigh, + InteractionActivated), + mIndicatorType(NULL) +{ d_ptr = new MsgIndicatorPrivate(this); - } +} // ---------------------------------------------------------------------------- // MsgIndicator::~MsgIndicator // @see msgindicator.h // ---------------------------------------------------------------------------- MsgIndicator::~MsgIndicator() - { +{ delete d_ptr; - } +} // ---------------------------------------------------------------------------- // MsgIndicator::handleInteraction // @see msgindicator.h // ---------------------------------------------------------------------------- bool MsgIndicator::handleInteraction(InteractionType type) + { + bool handled = false; + if (type == InteractionActivated) { - bool handled = false; - if (type == InteractionActivated) - { - QThreadPool::globalInstance()->start( - new ServiceRequestSenderTask(mConversationId)); - handled = true; - } + QThreadPool::globalInstance()->start(new ServiceRequestSenderTask( + mConversationId)); + handled = true; + } return handled; - } +} // ---------------------------------------------------------------------------- // MsgIndicator::indicatorData @@ -98,49 +154,22 @@ // ---------------------------------------------------------------------------- QVariant MsgIndicator::indicatorData(int role) const { -switch(role) + switch (role) { + case PrimaryTextRole: + { + return mPrimaryText; + } + case SecondaryTextRole: { - case TextRole: - { - mConversationId = -100; - - IndicatorData data; - d_ptr->getIndicatorInfo(data); - - mConversationFromSingleContact = data.mFromSingle; - mBodyText = data.mDescription; - - if (mConversationFromSingleContact) - { - mConversationId = (int)data.mConversationId; - QString name = prepareDisplayName(data); - name.append(QString(" (%1)").arg(data.mUnreadMsgCount)); - return name; - } - else - { - QString text = QString("%1 new messages").arg(data.mUnreadMsgCount); - return text; - } - } - case SecondaryTextRole: - { - if (mConversationFromSingleContact) - { - return mBodyText; - } - else - { - return QString(); - } - } - case IconNameRole: - { - QString iconName("z:/resource/messaging/message.svg"); - return iconName; - } - default: - return QVariant(); + return mSecondaryText; + } + case DecorationNameRole: + { + return IndicatorInfo[mIndicatorType].icon; + + } + default: + return QVariant(); } } @@ -148,71 +177,156 @@ // MsgIndicator::handleClientRequest // @see msgindicator.h // ---------------------------------------------------------------------------- -bool MsgIndicator::handleClientRequest( RequestType type, - const QVariant ¶meter) - { - Q_UNUSED(parameter); +bool MsgIndicator::handleClientRequest(RequestType type, const QVariant ¶meter) +{ + bool handled(false); switch (type) { - case RequestActivate: - { - emit dataChanged(); - handled = true; - } + case RequestActivate: + { + QByteArray dataArray = parameter.toByteArray(); + QDataStream messageStream(&dataArray, QIODevice::ReadOnly); + MsgInfo info; + info.deserialize(messageStream); - break; - case RequestDeactivate: - { - // reset data - mConversationId = -100; - mBodyText = QString(); - emit deactivate(); - } - break; - default: - break; + mCount = info.mMsgCount; + mIndicatorType = info.mIndicatorType; + mPrimaryText = getPrimaryText(info); + mSecondaryText = getSecondaryText(info); + mConversationId = info.mConversationId; + emit + dataChanged(); + handled = true; + } + break; + + case RequestDeactivate: + { + // reset data + mConversationId = -100; + mBodyText = QString(); + emit deactivate(); + } + break; + default: + break; } return handled; - } +} // ---------------------------------------------------------------------------- // MsgIndicator::prepareDisplayName // @see msgindicator.h // ---------------------------------------------------------------------------- -QString MsgIndicator::prepareDisplayName(IndicatorData& indicatorData) const - - { +QString MsgIndicator::prepareDisplayName(MsgInfo& indicatorData) const +{ //Set the Contact Name/Number - QString firstName(indicatorData.mFirstName); - QString lastName(indicatorData.mLastName); - QString contactAddress(indicatorData.mContactNum); - QString nickName(indicatorData.mNickName); QString displayName; - if (!nickName.isEmpty()) - { - displayName.append(nickName); + if (ECsBlueTooth == indicatorData.mMessageType) { + displayName = LOC_RECEIVED_FILES; + } + else { + indicatorData.mDisplayName.removeDuplicates(); + indicatorData.mDisplayName.sort(); + displayName = indicatorData.mDisplayName.at(0); + + for (int i = 1; i < indicatorData.mDisplayName.count(); ++i) { + displayName += QString(", ") + indicatorData.mDisplayName.at(i); } - else if ( firstName.isEmpty() && lastName.isEmpty()) - { - displayName.append(contactAddress); - } - else if (lastName.isEmpty() && !firstName.isEmpty()) - { - displayName.append(firstName); + } + return displayName; +} + +// ---------------------------------------------------------------------------- +// MsgIndicator::getPrimaryText +// @see msgindicator.h +// ---------------------------------------------------------------------------- +QString MsgIndicator::getPrimaryText(MsgInfo& data) +{ + if (data.mIndicatorType == NewIndicatorPlugin) { + return getUnreadPrimaryText(data); + } + else { + QString primaryText; + if (mCount >= 1) { + if (data.mIndicatorType == FailedIndicatorPlugin) { + primaryText += QString("%1 ").arg(mCount); + primaryText += (mCount > 1)? + LOC_FAILED_MULTIPLE_MESSAGES : LOC_FAILED_SINGLE_MESSAGE; + } + else { + primaryText += QString("%1 ").arg(mCount); + primaryText += (mCount > 1)? + LOC_OUTGOING_MULTIPLE_MESSAGES : LOC_OUTGOING_SINGLE_MESSAGE; + } } - else if (firstName.isEmpty() && !lastName.isEmpty()) - { - displayName.append(lastName); + return primaryText; + } +} + +// ---------------------------------------------------------------------------- +// MsgIndicator::getUnreadPrimaryText +// @see msgindicator.h +// ---------------------------------------------------------------------------- +QString MsgIndicator::getUnreadPrimaryText(MsgInfo& data) +{ + mConversationId = -100; + + d_ptr->getIndicatorInfo(data); + + mConversationFromSingleContact = data.mFromSingle; + mBodyText = data.mDescription; + + if (mConversationFromSingleContact) { + mConversationId = (int) data.mConversationId; + QString name = data.mDisplayName.at(0); + name.append(QString(" (%1)").arg(data.mMsgCount)); + return name; + } + else { + QString text = QString("%1 ").arg(mCount) + LOC_UNREAD_MULTIPLE_MESSAGES; + return text; + } + +} + +// ---------------------------------------------------------------------------- +// MsgIndicator::getSecondaryText +// @see msgindicator.h +// ---------------------------------------------------------------------------- +QString MsgIndicator::getSecondaryText(MsgInfo& info) +{ + QString secondaryText(""); + + if (info.mIndicatorType == NewIndicatorPlugin) { + secondaryText = info.mDescription; + + if (info.mFromSingle) { + if (ECsBlueTooth == info.mMessageType) { + QFileInfo fname(secondaryText); + secondaryText = fname.fileName(); + } } - else - { - // If both first Name and last name are present - displayName.append(firstName); - displayName.append(" "); - displayName.append(lastName); + else { + info.mConversationId = -100; } - return displayName; } + else { + info.mDisplayName.removeDuplicates(); + info.mDisplayName.sort(); + int count = info.mDisplayName.count(); + if (count > 1) { + info.mConversationId = -100; + } + + secondaryText.append(info.mDisplayName.at(0)); + for (int i = 1; i < info.mDisplayName.count(); ++i) { + secondaryText.append(", "); + secondaryText.append(info.mDisplayName.at(i)); + } + } + return secondaryText; +}