javauis/nokiauiapi_qt/softnoteplugin/src/javasoftnotehandler.cpp
changeset 78 71ad690e91f5
child 87 1627c337e51e
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2009, 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - initial implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 #include <memory>
       
    13 #include <badesca.h>
       
    14 #include <hbsymbianvariant.h>
       
    15 #include <HbIndicatorsymbian.h>
       
    16 
       
    17 #include <javastorageentry.h>
       
    18 #include <javastorage.h>
       
    19 #include <javastoragenames.h>
       
    20 #include <JavaCommonUtils.h>
       
    21 #include <JavaUid.h>
       
    22 #include <javasymbianoslayer.h>
       
    23 #include <booteventprovidermessages.h>
       
    24 #include <logger.h>
       
    25 
       
    26 #include "javasoftnotehandler.h"
       
    27 
       
    28 using namespace std;
       
    29 using namespace java::storage;
       
    30 using namespace java::util;
       
    31 _LIT(KIndicatorTypeJavaSoftNote,"com.nokia.javasoftnotification.indicatorplugin/1.0_%u_%i");
       
    32 const TInt KIndicatorTypeStringLength = 250;
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // javasoftnotehandler::getExtensionPlugin
       
    36 // ----------------------------------------------------------------------------
       
    37 #ifdef __SYMBIAN32__
       
    38 ExtensionPluginInterface* getExtensionPlugin()
       
    39     {
       
    40 #else
       
    41     extern "C" ExtensionPluginInterface* getExtensionPlugin()
       
    42         {
       
    43 #endif
       
    44     return new javasoftnotehandler();
       
    45     }
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // javasoftnotehandler::javasoftnotehandler
       
    49 // ----------------------------------------------------------------------------
       
    50 OS_EXPORT javasoftnotehandler::javasoftnotehandler() 
       
    51     {
       
    52     JELOG2(EJavaCaptain);
       
    53     }
       
    54 
       
    55 // ----------------------------------------------------------------------------
       
    56 // javasoftnotehandler::~javasoftnotehandler
       
    57 // ----------------------------------------------------------------------------
       
    58 OS_EXPORT javasoftnotehandler::~javasoftnotehandler()
       
    59     {
       
    60     JELOG2(EJavaCaptain);
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // javasoftnotehandler::startPlugin
       
    65 // ----------------------------------------------------------------------------
       
    66 void javasoftnotehandler::startPlugin(CoreInterface* /*core*/)
       
    67     {
       
    68     JELOG2(EJavaCaptain);
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // javasoftnotehandler::stopPlugin
       
    73 // ----------------------------------------------------------------------------
       
    74  void javasoftnotehandler::stopPlugin()
       
    75     {
       
    76     JELOG2(EJavaCaptain);
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------------------------------
       
    80 // javasoftnotehandler::getEventConsumer
       
    81 // ----------------------------------------------------------------------------
       
    82 EventConsumerInterface* javasoftnotehandler::getEventConsumer()
       
    83     {
       
    84     JELOG2(EJavaCaptain);
       
    85     return this;
       
    86     }
       
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // javasoftnotehandler::getApplicationManagementListener
       
    90 // ----------------------------------------------------------------------------
       
    91 ApplicationManagementEventsInterface* javasoftnotehandler::getApplicationManagementListener()
       
    92     {
       
    93     JELOG2(EJavaCaptain);
       
    94     return this;
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // javasoftnotehandler::event
       
    99 // ----------------------------------------------------------------------------
       
   100 void javasoftnotehandler::event(const std::string& eventProvider,
       
   101         java::comms::CommsMessage& /*aMsg*/)
       
   102     {
       
   103     LOG1(EJavaCaptain, EInfo, "javasoftnotehandler::event(), aEvent.event = %s", eventProvider.c_str());
       
   104     if (eventProvider == BOOT_EVENT_PROVIDER)
       
   105         {
       
   106         TRAP_IGNORE(createIndicatorsL());
       
   107         }
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------------------------------
       
   111 // javasoftnotehandler::amAdded
       
   112 // ----------------------------------------------------------------------------
       
   113 void javasoftnotehandler::amAdded(const uids_t& aUids)
       
   114     {
       
   115     JELOG2(EJavaCaptain);
       
   116     LOG1(EJavaCaptain, EInfo, "javasoftnotehandler::amAdded, %d uids", aUids.size());
       
   117     }
       
   118 
       
   119 // ----------------------------------------------------------------------------
       
   120 // javasoftnotehandler::amUpdated
       
   121 // ----------------------------------------------------------------------------
       
   122 void javasoftnotehandler::amUpdated(const uids_t& aUids)
       
   123     {
       
   124     JELOG2(EJavaCaptain);
       
   125     LOG1(EJavaCaptain, EInfo, "javasoftnotehandler::amUpdated, %d uids", aUids.size());
       
   126     TRAP_IGNORE(deleteIndicatorsL(aUids));
       
   127     }
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 // javasoftnotehandler::amDeleted
       
   131 // ----------------------------------------------------------------------------
       
   132 void javasoftnotehandler::amDeleted(const uids_t& aUids)
       
   133     {
       
   134     JELOG2(EJavaCaptain);
       
   135     LOG1(EJavaCaptain, EInfo, "javasoftnotehandler::amDeleted, %d uids", aUids.size());
       
   136     TRAP_IGNORE(deleteIndicatorsL(aUids));
       
   137     }
       
   138 
       
   139 // ----------------------------------------------------------------------------
       
   140 // javasoftnotehandler::createIndicatorsL
       
   141 // ----------------------------------------------------------------------------
       
   142 void javasoftnotehandler::createIndicatorsL()
       
   143     {
       
   144     std::auto_ptr<JavaStorage> js(JavaStorage::createInstance());
       
   145     try
       
   146         {
       
   147         js->open(JAVA_DATABASE_NAME);
       
   148         JavaStorageApplicationEntry_t findPattern;
       
   149         JavaStorageApplicationList_t foundEntries;
       
   150         // Reading all java based softnotes from database 
       
   151         js->search(JAVA_SOFTNOTE_TABLE, findPattern, foundEntries);
       
   152         js->close();
       
   153 
       
   154         if (foundEntries.size() > 0)
       
   155             {
       
   156             JavaStorageApplicationList_t::const_iterator applications;
       
   157             JavaStorageApplicationEntry_t::const_iterator findIterator;
       
   158             JavaStorageEntry attribute;
       
   159             CDesC16ArrayFlat* array = NULL;
       
   160             // Reading all sfotNotes data  from database and 
       
   161             // adding to status menu.
       
   162             for (applications = foundEntries.begin(); applications
       
   163                     != foundEntries.end(); applications++)
       
   164                 {
       
   165                 // Only 5 columns in the softNote table. So, create array with size 5.
       
   166                 array = new CDesC16ArrayFlat(5);
       
   167                 CleanupStack::PushL(array);
       
   168                 TUid midletId;
       
   169                 TInt notificationId;
       
   170                 attribute.setEntry(SOFTNOTE_MIDLET_ID, L"");
       
   171                 findIterator = (*applications).find(attribute);
       
   172                 // no need to check null midlet id, as it is a primary key in the table.
       
   173                         midletId = TUid::Uid(JavaCommonUtils::wstringToInt(
       
   174                                         (*findIterator).entryValue()));
       
   175                 array->AppendL(wstringToBuf((*findIterator).entryValue())->Des());
       
   176 
       
   177                 attribute.setEntry(SOFTNOTE_ID, L"");
       
   178                 findIterator = (*applications).find(attribute);
       
   179                 // no ned to check for null notification id, as it is a primary key in the table.
       
   180                 notificationId = JavaCommonUtils::wstringToInt(
       
   181                         (*findIterator).entryValue());
       
   182                 array->AppendL(wstringToBuf((*findIterator).entryValue())->Des());
       
   183 
       
   184                 // if no entry is found for primary text, appends Null desc to array 
       
   185                 // to keep all variable positions correctly.
       
   186                 attribute.setEntry(SOFTNOTE_PRIMARY_TEXT, L"");
       
   187                 findIterator = (*applications).find(attribute);
       
   188                 if (findIterator != (*applications).end())
       
   189                     {
       
   190                     array->AppendL(wstringToBuf((*findIterator).entryValue())->Des());
       
   191                     }
       
   192                 else
       
   193                     {
       
   194                     array->AppendL(KNullDesC);
       
   195                     }
       
   196 
       
   197                 attribute.setEntry(SOFTNOTE_SECONDARY_TEXT, L"");
       
   198                 findIterator = (*applications).find(attribute);
       
   199                 if (findIterator != (*applications).end())
       
   200                     {
       
   201                     array->AppendL(wstringToBuf((*findIterator).entryValue())->Des());
       
   202                     }
       
   203                 else
       
   204                     {
       
   205                     array->AppendL(KNullDesC);
       
   206                     }
       
   207 
       
   208                 attribute.setEntry(SOFTNOTE_IMAGE_PATH, L"");
       
   209                 findIterator = (*applications).find(attribute);
       
   210                 if (findIterator != (*applications).end())
       
   211                     {
       
   212                     array->AppendL(wstringToBuf((*findIterator).entryValue())->Des());
       
   213                     }
       
   214                 else
       
   215                     {
       
   216                     array->AppendL(KNullDesC);
       
   217                     }
       
   218 
       
   219                 MDesCArray* marray = static_cast<MDesCArray*>(array);
       
   220                 CHbSymbianVariant* varValues = CHbSymbianVariant::NewL( marray, CHbSymbianVariant::EDesArray);
       
   221                 CleanupStack::PushL(varValues);
       
   222 
       
   223                 TBuf<KIndicatorTypeStringLength> indicatorType;
       
   224                 indicatorType.Format(KIndicatorTypeJavaSoftNote, midletId, notificationId);
       
   225                 // creating indicator and adding to status menu
       
   226                 CHbIndicatorSymbian* indicator = CHbIndicatorSymbian::NewL();
       
   227                 CleanupStack::PushL(indicator);
       
   228                 indicator->Activate(indicatorType, varValues);
       
   229                 CleanupStack::PopAndDestroy(indicator);
       
   230 
       
   231                 CleanupStack::PopAndDestroy(varValues);
       
   232                 CleanupStack::PopAndDestroy(array);
       
   233                 array = NULL;
       
   234                 }
       
   235             }
       
   236         }
       
   237     catch(JavaStorageException& ex)
       
   238         {
       
   239         LOG1(EJavaStorage, EInfo," JavaSoftNote Exception %s", ex.toString());
       
   240         }   
       
   241     }
       
   242 
       
   243 // ----------------------------------------------------------------------------
       
   244 // javasoftnotehandler::deleteIndicatorsL
       
   245 // ----------------------------------------------------------------------------
       
   246 void javasoftnotehandler::deleteIndicatorsL(const uids_t& aUids)
       
   247     {
       
   248 
       
   249     std::auto_ptr<JavaStorage> js(JavaStorage::createInstance());
       
   250     try        
       
   251         {
       
   252         js->open(JAVA_DATABASE_NAME);
       
   253         JavaStorageEntry attribute;
       
   254         JavaStorageApplicationEntry_t findPattern;
       
   255         JavaStorageApplicationList_t foundEntries;
       
   256         // Search all softnotes for each given midlet UID in the softNote table 
       
   257         // and notify to the indicator in status mentu to delete/clear them.
       
   258         for (uids_t::const_iterator iter = aUids.begin(); iter != aUids.end(); ++iter)
       
   259             {
       
   260             TUid aMidletId;
       
   261             uidToTUid(*iter, aMidletId);
       
   262             attribute.setEntry(SOFTNOTE_MIDLET_ID, JavaCommonUtils::intToWstring(aMidletId.iUid));
       
   263             findPattern.insert(attribute);
       
   264             // search for all softnotes for single midlet UID 
       
   265             js->search(JAVA_SOFTNOTE_TABLE, findPattern, foundEntries);
       
   266             findPattern.clear();
       
   267 
       
   268             if (foundEntries.size() > 0)
       
   269                 {
       
   270                 attribute.setEntry(SOFTNOTE_ID, L"");
       
   271                 JavaStorageApplicationList_t::const_iterator applications;
       
   272                 // Deletes all softnotes for single midlet UID
       
   273                 for(applications = foundEntries.begin(); applications !=foundEntries.end(); applications++)
       
   274                     {
       
   275                     // Get softnote ID.
       
   276                     JavaStorageApplicationEntry_t::const_iterator findIterator = (*applications).find(attribute);
       
   277                     if (findIterator != (*applications).end())
       
   278                         {
       
   279                         TBuf<KIndicatorTypeStringLength> type;
       
   280                         type.Format(KIndicatorTypeJavaSoftNote, aMidletId,
       
   281                                 JavaCommonUtils::wstringToInt((*findIterator).entryValue()));
       
   282                         // create reference to Indicator
       
   283                         CHbIndicatorSymbian* indicator = CHbIndicatorSymbian::NewL();
       
   284                         CleanupStack::PushL(indicator);
       
   285                         //Inform to clear from status menu and database.
       
   286                         indicator->Deactivate(type);
       
   287                         CleanupStack::PopAndDestroy(indicator);
       
   288                         }
       
   289                     }
       
   290                 }
       
   291             foundEntries.clear();
       
   292             }
       
   293         js->close();
       
   294         }
       
   295     catch(JavaStorageException& ex)
       
   296         {
       
   297         LOG1(EJavaStorage, EInfo," JavaSoftNote Exception %s", ex.toString());
       
   298         }
       
   299     }
       
   300