omads/omadsextensions/adapters/agenda/src/nsmlagendadatastore.cpp
changeset 3 c2b8a5ae6ed5
parent 2 19dc812fb587
child 8 ad0f53516d84
equal deleted inserted replaced
2:19dc812fb587 3:c2b8a5ae6ed5
  2239         FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: ImportVCalendarL"));
  2239         FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: ImportVCalendarL"));
  2240         agendautil->iImporter->ImportVCalendarL( readStream, rdArray );
  2240         agendautil->iImporter->ImportVCalendarL( readStream, rdArray );
  2241         }
  2241         }
  2242     else
  2242     else
  2243         {
  2243         {
       
  2244         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
  2244         delete agendautil;
  2245         delete agendautil;
  2245         delete calfilename; 
  2246         delete calfilename; 
  2246         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
       
  2247         FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \
  2247         FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \
  2248                    KErrNotSupported: END"));
  2248                    KErrNotSupported: END"));
  2249         User::Leave( KErrNotSupported );
  2249         User::Leave( KErrNotSupported );
  2250         }
  2250         }
  2251     
  2251     
  2252     // If rdArray is empty or there is multiple items then return error
  2252     // If rdArray is empty or there is multiple items then return error
  2253     // Multiple items are not supported
  2253     // Multiple items are not supported
  2254     if ( rdArray.Count() != 1 )
  2254     if ( rdArray.Count() != 1 )
  2255         {
  2255         {
       
  2256         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
  2256         delete agendautil;
  2257         delete agendautil;
  2257         delete calfilename; 
  2258         delete calfilename; 
  2258         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
       
  2259         FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \
  2259         FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \
  2260                    Multiple items are not supported: END"));
  2260                    Multiple items are not supported: END"));
  2261         User::Leave( KErrNotSupported );
  2261         User::Leave( KErrNotSupported );
  2262         }           
  2262         }           
  2263         
  2263         
  2265     FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: before StoreL"));
  2265     FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: before StoreL"));
  2266     TRAP( err, iInterimUtils->StoreL( *agendautil->iEntryView, *rdArray[0], ETrue ) );
  2266     TRAP( err, iInterimUtils->StoreL( *agendautil->iEntryView, *rdArray[0], ETrue ) );
  2267     FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: after StoreL '%d'"), err );
  2267     FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: after StoreL '%d'"), err );
  2268     if ( err )
  2268     if ( err )
  2269         {
  2269         {
       
  2270         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
  2270         delete agendautil;
  2271         delete agendautil;
  2271         delete calfilename; 
  2272         delete calfilename; 
  2272         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
       
  2273         FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \
  2273         FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL - \
  2274                    Error at storing item to database: END"));
  2274                    Error at storing item to database: END"));
  2275         User::Leave( KErrGeneral );
  2275         User::Leave( KErrGeneral );
  2276         }
  2276         }
  2277 
  2277 
  2310                     }
  2310                     }
  2311                 }
  2311                 }
  2312             }
  2312             }
  2313         CleanupStack::PopAndDestroy();// newEntry,
  2313         CleanupStack::PopAndDestroy();// newEntry,
  2314         }
  2314         }
       
  2315 	CleanupStack::PopAndDestroy( 2 ); //  rdArray, readStream 
  2315     delete agendautil;
  2316     delete agendautil;
  2316     delete calfilename;     	
  2317 	delete calfilename;     	
  2317     CleanupStack::PopAndDestroy( 2 ); //  rdArray, readStream   
  2318       
  2318     FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: END"));
  2319     FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateCalItemL: END"));
  2319     }
  2320     }
  2320     
  2321     
  2321 // -----------------------------------------------------------------------------
  2322 // -----------------------------------------------------------------------------
  2322 // CNSmlAgendaDataStore::DoCommitReplaceCalItemL
  2323 // CNSmlAgendaDataStore::DoCommitReplaceCalItemL
  2363         }
  2364         }
  2364         
  2365         
  2365     if ( err || !agendautil )
  2366     if ( err || !agendautil )
  2366         {
  2367         {
  2367         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: entry is not valid"));
  2368         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: entry is not valid"));
       
  2369         CleanupStack::PopAndDestroy( 2 ); // olditem, writeStream
  2368         delete agendautil;
  2370         delete agendautil;
  2369         delete calfilename;
  2371         delete calfilename;
  2370         CleanupStack::PopAndDestroy( 2 ); // olditem, writeStream
       
  2371         User::Leave( KErrGeneral );
  2372         User::Leave( KErrGeneral );
  2372         }  
  2373         }  
  2373         
  2374         
  2374     // Export item from database depending on transmitted item entry type
  2375     // Export item from database depending on transmitted item entry type
  2375     if ( iTXEntryType == ENSmlVCal )
  2376     if ( iTXEntryType == ENSmlVCal )
  2384         agendautil->iExporter->ExportICalL( *agendautil->iEntry, writeStream );
  2385         agendautil->iExporter->ExportICalL( *agendautil->iEntry, writeStream );
  2385         }
  2386         }
  2386 #endif // __NSML_USE_ICAL_FEATURE
  2387 #endif // __NSML_USE_ICAL_FEATURE
  2387     else
  2388     else
  2388         {
  2389         {
       
  2390         CleanupStack::PopAndDestroy( 2 ); // olditem, writeStream
  2389         delete agendautil;
  2391         delete agendautil;
  2390         delete calfilename;
  2392         delete calfilename;
  2391         CleanupStack::PopAndDestroy( 2 ); // olditem, writeStream
       
  2392         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL - \
  2393         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL - \
  2393                    KErrNotSupported: END"));
  2394                    KErrNotSupported: END"));
  2394         User::Leave( KErrNotSupported );
  2395         User::Leave( KErrNotSupported );
  2395         }
  2396         }
  2396         
  2397         
  2427         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: SetPropertiesToDataL :uid"));
  2428         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: SetPropertiesToDataL :uid"));
  2428         SetPropertiesToDataL( uid, KVersitTokenUID() );    
  2429         SetPropertiesToDataL( uid, KVersitTokenUID() );    
  2429         }
  2430         }
  2430     else
  2431     else
  2431         {
  2432         {
       
  2433         CleanupStack::PopAndDestroy( 5 ); // xRecurrenceId, recurrenceId,
       
  2434                                               // uid, oldItem, geoId
  2432         delete agendautil;
  2435         delete agendautil;
  2433         delete calfilename;
  2436         delete calfilename;
  2434         CleanupStack::PopAndDestroy( 5 ); // xRecurrenceId, recurrenceId,
  2437         
  2435                                           // uid, oldItem, geoId
       
  2436         User::Leave( KErrNotSupported );
  2438         User::Leave( KErrNotSupported );
  2437         }
  2439         }
  2438     if ( recurrenceId )
  2440     if ( recurrenceId )
  2439         {
  2441         {
  2440         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: SetPropertiesToDataL :recurrenceId"));
  2442         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: SetPropertiesToDataL :recurrenceId"));
  2480         agendautil->iImporter->ImportICalendarL( readStream, rdArray );
  2482         agendautil->iImporter->ImportICalendarL( readStream, rdArray );
  2481         }
  2483         }
  2482 #endif // __NSML_USE_ICAL_FEATURE
  2484 #endif // __NSML_USE_ICAL_FEATURE
  2483     else
  2485     else
  2484         {
  2486         {
       
  2487         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
  2485         delete agendautil;
  2488         delete agendautil;
  2486         delete calfilename;
  2489         delete calfilename;
  2487         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
       
  2488         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceItemL - \
  2490         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceItemL - \
  2489                    KErrNotSupported: END"));
  2491                    KErrNotSupported: END"));
  2490         User::Leave( KErrNotSupported );
  2492         User::Leave( KErrNotSupported );
  2491         }
  2493         }
  2492 
  2494 
  2493     // If rdArray is empty or there is multiple items then return error
  2495     // If rdArray is empty or there is multiple items then return error
  2494     // Multiple items are not supported
  2496     // Multiple items are not supported
  2495     if ( rdArray.Count() != 1 )
  2497     if ( rdArray.Count() != 1 )
  2496         {
  2498         {
  2497         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: Multiple items are not supported "));
  2499         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: Multiple items are not supported "));
       
  2500         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
  2498         delete agendautil;
  2501         delete agendautil;
  2499         delete calfilename;
  2502         delete calfilename;
  2500         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
       
  2501         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceItemL - \
  2503         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceItemL - \
  2502                    Multiple items are not supported: END"));
  2504                    Multiple items are not supported: END"));
  2503         User::Leave( KErrNotSupported );
  2505         User::Leave( KErrNotSupported );
  2504         }
  2506         }
  2505         
  2507         
  2506     err = KErrNone;
  2508     err = KErrNone;
  2507 
  2509 
  2508     FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: before StoreL"));
  2510     FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: before StoreL"));
  2509     TRAP( err, iInterimUtils->StoreL( *agendautil->iEntryView, *rdArray[0], ETrue ) );
  2511     TRAP( err, iInterimUtils->StoreL( *agendautil->iEntryView, *rdArray[0], ETrue ) );
  2510     FLOG(_L("CNSmlAgendaDataStore::DoCommitCreateItemL: after StoreL '%d'"), err );
  2512     FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: after StoreL '%d'"), err );
       
  2513     
  2511     if ( err )
  2514     if ( err )
  2512         {
  2515         {
       
  2516         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
  2513         delete agendautil;
  2517         delete agendautil;
  2514         delete calfilename;
  2518         delete calfilename;
  2515         CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
       
  2516         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL - \
  2519         FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL - \
  2517                    Error at storing item to database: END"));
  2520                    Error at storing item to database: END"));
  2518         User::Leave( KErrGeneral );
  2521         User::Leave( KErrGeneral );
  2519         }
  2522         }
  2520 
  2523 
  2546             }
  2549             }
  2547         }
  2550         }
  2548     CleanupStack::PopAndDestroy(); // replacedEntry
  2551     CleanupStack::PopAndDestroy(); // replacedEntry
  2549     }
  2552     }
  2550     
  2553     
       
  2554 	CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
  2551     delete agendautil;
  2555     delete agendautil;
  2552     delete calfilename;
  2556 	delete calfilename;	
  2553 	
       
  2554     CleanupStack::PopAndDestroy( 2 ); // rdArray, readStream
       
  2555     
       
  2556 	FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: END"));
  2557 	FLOG(_L("CNSmlAgendaDataStore::DoCommitReplaceCalItemL: END"));
  2557     }
  2558     }
  2558 
  2559 
  2559 // -----------------------------------------------------------------------------
  2560 // -----------------------------------------------------------------------------
  2560 // CNSmlAgendaDataStore::DoCommitCreateFolderItemL
  2561 // CNSmlAgendaDataStore::DoCommitCreateFolderItemL
  3049 void CNSmlAgendaDataStore::OpenStoreL()
  3050 void CNSmlAgendaDataStore::OpenStoreL()
  3050     {
  3051     {
  3051     FLOG(_L("CNSmlAgendaDataStore::OpenStoreL BEGIN"));
  3052     FLOG(_L("CNSmlAgendaDataStore::OpenStoreL BEGIN"));
  3052 
  3053 
  3053     TInt profileid = NULL;
  3054     TInt profileid = NULL;
       
  3055     TBuf<KBuffLength> serverid;
  3054     TBuf<KBuffLength> profilename;
  3056     TBuf<KBuffLength> profilename;
  3055     
  3057 	TBool isHandlerAvailable( EFalse );
  3056     // Get the ProfileId and ProfileName from the cenrep
  3058     
       
  3059     // Get the ServerId, ProfileId and ProfileName from the cenrep
  3057     CRepository* rep = CRepository::NewLC( KNsmlDsSessionInfoKey );
  3060     CRepository* rep = CRepository::NewLC( KNsmlDsSessionInfoKey );
  3058     TInt err = rep->Get( EDSSessionProfileId, profileid );
  3061     TInt err = rep->Get( EDSSessionProfileId, profileid );
  3059     err = rep->Get( EDSSessionProfileName, profilename );
  3062     err = rep->Get( EDSSessionProfileName, profilename );
       
  3063     err = rep->Get(EDSSessionServerId, serverid );
  3060     User::LeaveIfError(err);
  3064     User::LeaveIfError(err);
  3061     CleanupStack::PopAndDestroy(rep);
  3065     CleanupStack::PopAndDestroy(rep);
       
  3066     
       
  3067     // Reintialize the StoreName
       
  3068     if ( iOpenedStoreName )
       
  3069         {
       
  3070         delete iOpenedStoreName;
       
  3071         iOpenedStoreName = NULL;
       
  3072         }
  3062     
  3073     
  3063     // Find the CalendarFile having the given ProfileID
  3074     // Find the CalendarFile having the given ProfileID
  3064     CDesCArray* calfilearr = new (ELeave) CDesCArrayFlat(1);
  3075     CDesCArray* calfilearr = new (ELeave) CDesCArrayFlat(1);
  3065     CleanupStack::PushL(calfilearr);
  3076     CleanupStack::PushL(calfilearr);
  3066     if ( IsCalFileAvailableL( profileid, calfilearr ) )
  3077     FLOG(_L("CNSmlAgendaDataStore:::OpenStoreL():Profilename '%S'"), &profilename );
       
  3078     FLOG(_L("CNSmlAgendaDataStore:::OpenStoreL():serverid '%S'"), &serverid );
       
  3079 	
       
  3080 	if( 0 != serverid.Length() )
       
  3081         {   
       
  3082 		HBufC8* opaquedata = HBufC8::NewL( serverid.Length() );
       
  3083         TPtr8 name( opaquedata->Des() );
       
  3084         CnvUtfConverter::ConvertFromUnicodeToUtf8(name , serverid );
       
  3085 		
       
  3086 		for( TInt adaptercount = 0; adaptercount < iAgendaPluginAdapters.Count(); adaptercount++ )
       
  3087 	        {
       
  3088 	        if( 0 == opaquedata->Compare(iAgendaPluginAdapters[adaptercount]->iOpaqueData->Des()) )
       
  3089 	            {
       
  3090 	            FLOG(_L("CNSmlAgendaDataStore::Handler available"));			
       
  3091 				isHandlerAvailable = ETrue;
       
  3092 	            break;
       
  3093 	            }        
       
  3094 	        }
       
  3095 			delete opaquedata;
       
  3096         }	
       
  3097     
       
  3098 	if( isHandlerAvailable )
       
  3099 		{
       
  3100 		iOpenedStoreName = iDefaultStoreFileName->AllocL();
       
  3101 		}	
       
  3102     else if( IsCalFileAvailableL( profileid, calfilearr ) )
  3067         {
  3103         {
  3068         FLOG(_L("CNSmlAgendaDataStore::OpenStoreL Found the assoicated calfile"));
  3104         FLOG(_L("CNSmlAgendaDataStore::OpenStoreL Found the assoicated calfile"));
  3069         
  3105         
  3070         // TODO: Yet to get clarification for enable/disable the notification
  3106         // TODO: Yet to get clarification for enable/disable the notification
  3071        
       
  3072         if ( iOpenedStoreName )
       
  3073             {
       
  3074             delete iOpenedStoreName;
       
  3075             iOpenedStoreName = NULL;
       
  3076             }
       
  3077         iOpenedStoreName = calfilearr->MdcaPoint(0).AllocL();
  3107         iOpenedStoreName = calfilearr->MdcaPoint(0).AllocL();
  3078         }
  3108         }
  3079     else
  3109     else
  3080         {
  3110         {
  3081         FLOG(_L("CNSmlAgendaDataStore::OpenStoreL CouldNot Find the Calfile"));
  3111         FLOG(_L("CNSmlAgendaDataStore::OpenStoreL CouldNot Find the Calfile"));
  3082         
  3112         
  3083         // No association found thus creating a CalendarFile
  3113         // No association found thus creating a CalendarFile
  3084         HBufC* name = profilename.AllocL();
  3114         HBufC* name = profilename.AllocL();
  3085         HBufC* calfilename = CreateCalFileL( name, profileid );
  3115         HBufC* calfilename = CreateCalFileL( name, profileid );
  3086         delete name;
  3116         delete name;
  3087         
       
  3088         if ( iOpenedStoreName )
       
  3089             {
       
  3090             delete iOpenedStoreName;
       
  3091             iOpenedStoreName = NULL;
       
  3092             }
       
  3093         iOpenedStoreName = calfilename;
  3117         iOpenedStoreName = calfilename;
  3094         }
  3118         }
  3095         
  3119         
  3096     CCalSession* calsession = CCalSession::NewL();
  3120     CCalSession* calsession = CCalSession::NewL();
  3097     CleanupStack::PushL(calsession);
  3121     CleanupStack::PushL(calsession);