diff -r 1f0034e370aa -r 71ad690e91f5 javauis/nokiauiapi_qt/src/CSoftNotification.cpp --- a/javauis/nokiauiapi_qt/src/CSoftNotification.cpp Fri Sep 17 16:44:34 2010 +0300 +++ b/javauis/nokiauiapi_qt/src/CSoftNotification.cpp Mon Oct 04 11:29:25 2010 +0300 @@ -9,11 +9,17 @@ * Nokia Corporation - initial implementation *******************************************************************************/ - -#include #include #include #include + +#include +#include +#include +#include +#include +#include + #include "CSoftNotification.h" _LIT(KMidletId, "MidletId"); @@ -25,6 +31,10 @@ // Event id when user accepted notification const TInt KEventNoteAccepted = 1; +using namespace std; +using namespace java::storage; +using namespace java::util; + // ============================ MEMBER FUNCTIONS =============================== // ----------------------------------------------------------------------------- // CSoftNotification::NewLC @@ -48,7 +58,7 @@ // ----------------------------------------------------------------------------- // CSoftNotification::CSoftNotification(TInt aAppId, TInt aNotificationId) : - iNotificationId(aNotificationId) + iNotificationId(aNotificationId),iIsNoteExist(EFalse) { iMidletId = TUid::Uid(aAppId); } @@ -60,8 +70,60 @@ // void CSoftNotification::ConstructL() { - iIndicator = CHbIndicatorSymbian::NewL(); - iIndicator->SetObserver(this); + std::auto_ptr js(JavaStorage::createInstance()); + TInt maxValue = 0; + try + { + js->open(JAVA_DATABASE_NAME); + JavaStorageEntry attribute; + JavaStorageApplicationEntry_t findPattern; + JavaStorageApplicationList_t foundEntries; + + std::wstring midletId = JavaCommonUtils::intToWstring(iMidletId.iUid); + attribute.setEntry(SOFTNOTE_MIDLET_ID, midletId); + findPattern.insert(attribute); + + js->search(JAVA_SOFTNOTE_TABLE, findPattern, foundEntries); + js->close(); + findPattern.clear(); + + // like to know softnote id. + attribute.setEntry(SOFTNOTE_ID, L""); + // Iterate through all rows matched with search patterns. + JavaStorageApplicationList_t::const_iterator applications; + for(applications = foundEntries.begin(); applications !=foundEntries.end(); applications++) + { + // Get softnote ID from its parameters. + JavaStorageApplicationEntry_t::const_iterator findIterator = (*applications).find(attribute); + if (findIterator != (*applications).end()) + { + TInt id = JavaCommonUtils::wstringToInt((*findIterator).entryValue()); + if(iNotificationId == id) + { + iIsNoteExist = true; + } + if(maxValueSetObserver(this); + } } // ----------------------------------------------------------------------------- @@ -90,6 +152,11 @@ delete iIndicator; } + if(iNotificationDialog) + { + delete iNotificationDialog; + } + if (iPeer) { iJniEnv->DeleteWeakGlobalRef((jweak)iPeer); @@ -99,6 +166,7 @@ iSecondaryText = NULL; iImagePath = NULL; iIndicator = NULL; + iNotificationDialog = NULL; iPeer = NULL; iMethodId = NULL; } @@ -110,36 +178,40 @@ // bool CSoftNotification::ShowSoftNotificationL() { - CHbDeviceNotificationDialogSymbian* dialog = - CHbDeviceNotificationDialogSymbian::NewL(); - CleanupStack::PushL(dialog); + AddorUpdateSoftNotificationToStorage(); + + if(iNotificationDialog == NULL) + { + iNotificationDialog = CHbDeviceNotificationDialogSymbian::NewL(this); + } if(iPrimaryText != NULL) { - dialog->SetTitleL(iPrimaryText->Des()); + iNotificationDialog->SetTitleL(iPrimaryText->Des()); } if(iSecondaryText != NULL) { - dialog->SetTextL(iSecondaryText->Des()); + iNotificationDialog->SetTextL(iSecondaryText->Des()); } if (iImagePath != NULL) { - dialog->SetIconNameL(iImagePath->Des()); + iNotificationDialog->SetIconNameL(iImagePath->Des()); } - - dialog->ShowL(); + iNotificationDialog->EnableTouchActivation(ETrue); + iNotificationDialog->ShowL(); + // reading Softnote data CHbSymbianVariant* varValues = NotificationParamsL(); CleanupStack::PushL(varValues); + // creating indicator in status menu TBuf indicatorType; indicatorType.Format(KIndicatorTypeJavaSoftNote, iMidletId, iNotificationId); bool indStatus = iIndicator->Activate(indicatorType, varValues); CleanupStack::PopAndDestroy(varValues); - CleanupStack::PopAndDestroy(dialog); return indStatus; } @@ -232,20 +304,53 @@ } // ----------------------------------------------------------------------------- +// CSoftNotification::NotificationDialogActivated +// Dynamic soft notification was accepted by user. +// ----------------------------------------------------------------------------- +// +void CSoftNotification::NotificationDialogActivated(const CHbDeviceNotificationDialogSymbian* /*aDialog*/) + { + RWsSession ws; + User::LeaveIfError(ws.Connect() == KErrNone); + TApaTaskList tasklist(ws); + TApaTask task = tasklist.FindApp(iMidletId); + if (task.Exists()) + { + task.BringToForeground(); + ws.Close(); + } + } + +// ----------------------------------------------------------------------------- +// CSoftNotification::NotificationDialogClosed +// Dynamic soft notification was closed. +// ----------------------------------------------------------------------------- +// +void CSoftNotification::NotificationDialogClosed(const CHbDeviceNotificationDialogSymbian* /*aDialog*/, + TInt /*aCompletionCode*/) + { + + } + +// ----------------------------------------------------------------------------- // CSoftNotification::FillNotificationParams // ----------------------------------------------------------------------------- // CHbSymbianVariant* CSoftNotification::NotificationParamsL() { - //only five parameter, so creat the array - //for five parameters to fit and append them + //only five parameter, so creat the array with size 5. CDesC16ArrayFlat* array = new CDesC16ArrayFlat(5); CleanupStack::PushL(array); TBuf midletId; _LIT(MidletId,"%u"); midletId.Format(MidletId,iMidletId); array->AppendL(midletId); - array->AppendL(reinterpret_cast(iNotificationId)); + + TBuf<10> noteId; + _LIT(NoteId,"%d"); + noteId.Format(NoteId,iNotificationId); + array->AppendL(noteId); + if(iPrimaryText != NULL) { array->AppendL(iPrimaryText->Des()); @@ -277,3 +382,93 @@ CleanupStack::PopAndDestroy(array); return varValues; } + +// ----------------------------------------------------------------------------- +// CSoftNotification::AddSoftNotificationToStorage +// ----------------------------------------------------------------------------- +// +void CSoftNotification::AddorUpdateSoftNotificationToStorage() + { + std::auto_ptr js(JavaStorage::createInstance()); + try + { + js->open(JAVA_DATABASE_NAME); + JavaStorageApplicationEntry_t newEntries; + JavaStorageApplicationEntry_t matchEntries; + JavaStorageEntry attribute; + + if (!iIsNoteExist) + { + // if Softnote is not created, add midletId and notificationId to storage + std::wstring midletId = JavaCommonUtils::intToWstring( + iMidletId.iUid); + attribute.setEntry(SOFTNOTE_MIDLET_ID, midletId, + JavaStorageEntry::STRING); + newEntries.insert(attribute); + + std::wstring notificationId = JavaCommonUtils::intToWstring( + iNotificationId); + attribute.setEntry(SOFTNOTE_ID, notificationId, + JavaStorageEntry::INT); + newEntries.insert(attribute); + } + else + { + // if Softnote is already in the storage, just aupdate the data. + std::wstring midletId = JavaCommonUtils::intToWstring( + iMidletId.iUid); + attribute.setEntry(SOFTNOTE_MIDLET_ID, midletId, + JavaStorageEntry::STRING); + matchEntries.insert(attribute); + + std::wstring notificationId = JavaCommonUtils::intToWstring( + iNotificationId); + attribute.setEntry(SOFTNOTE_ID, notificationId, + JavaStorageEntry::INT); + matchEntries.insert(attribute); + } + + if (iPrimaryText) + { + std::wstring primaryText((wchar_t*) iPrimaryText->Ptr(), + iPrimaryText->Length()); + attribute.setEntry(SOFTNOTE_PRIMARY_TEXT, primaryText, + JavaStorageEntry::STRING); + newEntries.insert(attribute); + } + if (iSecondaryText) + { + std::wstring secondaryText((wchar_t*) iSecondaryText->Ptr(), + iSecondaryText->Length()); + attribute.setEntry(SOFTNOTE_SECONDARY_TEXT, secondaryText, + JavaStorageEntry::STRING); + newEntries.insert(attribute); + } + if (iImagePath) + { + std::wstring imagePath((wchar_t*) iImagePath->Ptr(), + iImagePath->Length()); + attribute.setEntry(SOFTNOTE_IMAGE_PATH, imagePath, + JavaStorageEntry::STRING); + newEntries.insert(attribute); + } + + if (!iIsNoteExist) + { + // create new entry in storage if softnote is not created earlier + js->write(JAVA_SOFTNOTE_TABLE, newEntries); + } + else + { + // update data for softNote. + js->update(JAVA_SOFTNOTE_TABLE, newEntries, matchEntries); + } + js->close(); + newEntries.clear(); + matchEntries.clear(); + } + catch (JavaStorageException& ex) + { + LOG1(EJavaStorage, EInfo," JavaSoftNote Exception %s", ex.toString()); + } + }