calendarui/globaldata/src/calenglobaldata.cpp
branchRCL_3
changeset 14 21239b3bcd78
parent 13 1984aceb8774
child 15 9711e452b5e9
equal deleted inserted replaced
13:1984aceb8774 14:21239b3bcd78
    85 // which should be handled by the controller.
    85 // which should be handled by the controller.
    86 // (other items were commented in a header).
    86 // (other items were commented in a header).
    87 // ----------------------------------------------------------------------------
    87 // ----------------------------------------------------------------------------
    88 //
    88 //
    89 EXPORT_C CCalenGlobalData* CCalenGlobalData::NewL( MCalProgressCallBack& aCalCallBack,
    89 EXPORT_C CCalenGlobalData* CCalenGlobalData::NewL( MCalProgressCallBack& aCalCallBack,
    90                                                    MCalenContextChangeObserver* aNotifier )
    90                                                    MCalenContextChangeObserver* aNotifier,
       
    91                                                    MCalenDBChangeObserver* aDBNotifier)
    91     {
    92     {
    92     TRACE_ENTRY_POINT;
    93     TRACE_ENTRY_POINT;
    93 
    94 
    94     CCalenGlobalData* self = NULL;
    95     CCalenGlobalData* self = NULL;
    95     TAny* tlsPtr = Dll::Tls();
    96     TAny* tlsPtr = Dll::Tls();
   104         User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( self ) ) );
   105         User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( self ) ) );
   105         // Increment ref count right away. If we don't do it here, and someone
   106         // Increment ref count right away. If we don't do it here, and someone
   106         // calls CCalenGlobalData::InstanceL in ConstructL and then ConstructL
   107         // calls CCalenGlobalData::InstanceL in ConstructL and then ConstructL
   107         // leaves, we will double delete the global data.
   108         // leaves, we will double delete the global data.
   108         ++self->iRefCount;
   109         ++self->iRefCount;
   109         self->ConstructL( aNotifier );
   110         self->ConstructL( aNotifier, aDBNotifier );
   110         CleanupStack::Pop( self );
   111         CleanupStack::Pop( self );
   111         }
   112         }
   112     else
   113     else
   113         {
   114         {
   114         // An instance of the global data exists already.
   115         // An instance of the global data exists already.
   204 // -----------------------------------------------------------------------------
   205 // -----------------------------------------------------------------------------
   205 // CCalenGlobalData::ConstructL
   206 // CCalenGlobalData::ConstructL
   206 // Symbian 2nd phase constructor can leave.
   207 // Symbian 2nd phase constructor can leave.
   207 // (other items were commented in a header).
   208 // (other items were commented in a header).
   208 // -----------------------------------------------------------------------------
   209 // -----------------------------------------------------------------------------
   209 void CCalenGlobalData::ConstructL( MCalenContextChangeObserver* aNotifier )
   210 void CCalenGlobalData::ConstructL( MCalenContextChangeObserver* aNotifier,
       
   211                                     MCalenDBChangeObserver* aDBNotifier)
   210     {
   212     {
   211     TRACE_ENTRY_POINT;
   213     TRACE_ENTRY_POINT;
   212 
   214 
   213     iContext = new (ELeave ) CCalenContextImpl( aNotifier );  
   215     iContext = new (ELeave ) CCalenContextImpl( aNotifier );  
   214     
   216     
   215     iNewInstanceViewCreation = NULL;
   217     iNewInstanceViewCreation = NULL;
       
   218     
       
   219     iDBChangeNotifier = aDBNotifier;
   216     
   220     
   217     TRACE_EXIT_POINT;
   221     TRACE_EXIT_POINT;
   218     }
   222     }
   219 
   223 
   220 // -----------------------------------------------------------------------------
   224 // -----------------------------------------------------------------------------
   827         CCalenFileMapping* filemap = CCalenFileMapping::NewL(); 
   831         CCalenFileMapping* filemap = CCalenFileMapping::NewL(); 
   828         CleanupStack::PushL(filemap);
   832         CleanupStack::PushL(filemap);
   829         filemap->SetCalendarFileNameL(calendarFileName);
   833         filemap->SetCalendarFileNameL(calendarFileName);
   830         
   834         
   831         iNewEntryView  = NULL;
   835         iNewEntryView  = NULL;
   832         iNewEntryViewCreation  = NULL;  
   836         iNewEntryViewCreation  = NULL;
       
   837         CCalenDbChangeNotifier* dbChangeNotifier = NULL;
   833         if(iCalSession)
   838         if(iCalSession)
   834             {
   839             {
   835             iNewCalSession = NULL;
   840             iNewCalSession = NULL;
   836             CCalCalendarInfo* calendarInfo = iCalendarInfoList[index];
   841             CCalCalendarInfo* calendarInfo = iCalendarInfoList[index];
   837             
   842             
   839                                     *calendarInfo );
   844                                     *calendarInfo );
   840             filemap->SetSessionPtr(&tempSession);
   845             filemap->SetSessionPtr(&tempSession);
   841             filemap->SetCollectionId(tempSession.CollectionIdL());
   846             filemap->SetCollectionId(tempSession.CollectionIdL());
   842             CreateEntryViewL(tempSession);
   847             CreateEntryViewL(tempSession);
   843             filemap->SetEntryView( iNewEntryView );
   848             filemap->SetEntryView( iNewEntryView );
       
   849             dbChangeNotifier = CCalenDbChangeNotifier::NewL( tempSession );
       
   850             dbChangeNotifier->RegisterObserverL(*iDBChangeNotifier);
       
   851             filemap->SetDBChangeNotifier(dbChangeNotifier);
   844             }            
   852             }            
   845          else
   853          else
   846             {
   854             {
   847             CCalSession& tempSession = CalSessionL();
   855             CCalSession& tempSession = CalSessionL();
   848             filemap->SetSessionPtr(&tempSession);
   856             filemap->SetSessionPtr(&tempSession);
   849             filemap->SetCollectionId(tempSession.CollectionIdL());
   857             filemap->SetCollectionId(tempSession.CollectionIdL());
   850             CreateEntryViewL(tempSession);
   858             CreateEntryViewL(tempSession);
   851             filemap->SetEntryView( iNewEntryView );
   859             filemap->SetEntryView( iNewEntryView );
   852             iGlobalDataOwnsEntryView = EFalse;
   860             iGlobalDataOwnsEntryView = EFalse;
   853             iGlobalDataOwnsCalSession = EFalse;
   861             iGlobalDataOwnsCalSession = EFalse;
       
   862             dbChangeNotifier = CCalenDbChangeNotifier::NewL( tempSession );
       
   863             dbChangeNotifier->RegisterObserverL(*iDBChangeNotifier);
       
   864             filemap->SetDBChangeNotifier(dbChangeNotifier);
   854             }
   865             }
   855         iFileMappingArray.Append(filemap);        
   866         iFileMappingArray.Append(filemap);        
   856         CleanupStack::Pop(filemap);
   867         CleanupStack::Pop(filemap);
   857         }   
   868         }   
   858     
   869     
  1276 		if(!iCalendarForcedExit)
  1287 		if(!iCalendarForcedExit)
  1277 			{
  1288 			{
  1278 			CreateEntryViewL(tempSession);
  1289 			CreateEntryViewL(tempSession);
  1279 			}
  1290 			}
  1280 		fileMapping->SetEntryView( iNewEntryView );
  1291 		fileMapping->SetEntryView( iNewEntryView );
       
  1292 		CCalenDbChangeNotifier* dbChangeNotifier = CCalenDbChangeNotifier::NewL( tempSession );
       
  1293 		dbChangeNotifier->RegisterObserverL(*iDBChangeNotifier);
       
  1294 		fileMapping->SetDBChangeNotifier(dbChangeNotifier);
  1281 		CleanupStack::PopAndDestroy(aCalendarInfo);
  1295 		CleanupStack::PopAndDestroy(aCalendarInfo);
  1282 		iCalendarInfoList.Append(tempSession.CalendarInfoL());
  1296 		iCalendarInfoList.Append(tempSession.CalendarInfoL());
  1283 		}
  1297 		}
  1284 
  1298 
  1285 	CleanupStack::Pop(fileMapping);
  1299 	CleanupStack::Pop(fileMapping);
  1658 				CreateEntryViewL(*newSession);
  1672 				CreateEntryViewL(*newSession);
  1659 				}
  1673 				}
  1660 			fileMapper->SetEntryView( iNewEntryView );
  1674 			fileMapper->SetEntryView( iNewEntryView );
  1661 			
  1675 			
  1662 			iCalendarInfoList.AppendL(newSession->CalendarInfoL());
  1676 			iCalendarInfoList.AppendL(newSession->CalendarInfoL());
       
  1677 		    CCalenDbChangeNotifier* dbChangeNotifier = CCalenDbChangeNotifier::NewL( *newSession );
       
  1678 		    dbChangeNotifier->RegisterObserverL(*iDBChangeNotifier);
       
  1679 		    fileMapper->SetDBChangeNotifier(dbChangeNotifier);
  1663 			}
  1680 			}
  1664 		else
  1681 		else
  1665 			{
  1682 			{
  1666 			// create the first session
  1683 			// create the first session
  1667 			iCalSession = CCalSession::NewL();
  1684 			iCalSession = CCalSession::NewL();
  1676 				{
  1693 				{
  1677 				CreateEntryViewL(*iCalSession);
  1694 				CreateEntryViewL(*iCalSession);
  1678 				}
  1695 				}
  1679 			
  1696 			
  1680 			fileMapper->SetEntryView(iNewEntryView);
  1697 			fileMapper->SetEntryView(iNewEntryView);
       
  1698 	        CCalenDbChangeNotifier* dbChangeNotifier = CCalenDbChangeNotifier::NewL( *iCalSession );
       
  1699 	        fileMapper->SetDBChangeNotifier(dbChangeNotifier);
       
  1700 	        dbChangeNotifier->RegisterObserverL(*iDBChangeNotifier);
  1681 			iGlobalDataOwnsEntryView = EFalse;
  1701 			iGlobalDataOwnsEntryView = EFalse;
  1682 			iGlobalDataOwnsCalSession = EFalse;
  1702 			iGlobalDataOwnsCalSession = EFalse;
  1683 			iCalendarInfoList.AppendL(iCalSession->CalendarInfoL());
  1703 			iCalendarInfoList.AppendL(iCalSession->CalendarInfoL());
  1684 			}
  1704 			}
  1685 		// append to filemapper list
  1705 		// append to filemapper list