24 |
24 |
25 #include "pplcontactitemmanager.h" |
25 #include "pplcontactitemmanager.h" |
26 #include "cntsqlprovider.h" |
26 #include "cntsqlprovider.h" |
27 #include "dbsqlconstants.h" |
27 #include "dbsqlconstants.h" |
28 #include "cntpersistenceutility.h" |
28 #include "cntpersistenceutility.h" |
|
29 #include "c12keypredictivesearchtable.h" |
|
30 #include "cqwertypredictivesearchtable.h" |
|
31 #include "cpredictivesearchsettingstable.h" |
|
32 #include "cpredictivesearchsynchronizer.h" |
|
33 #include "predictivesearchlog.h" |
29 //#include "cntmetadataoperation.h" |
34 //#include "cntmetadataoperation.h" |
30 #include <cntdef.h> |
35 #include <cntdef.h> |
31 #include <sqldb.h> |
36 #include <sqldb.h> |
32 #include <cntdb.h> |
37 #include <cntdb.h> |
33 |
38 |
34 // TODO: The code related to predictive search table is placed inside this |
39 // TODO: The code related to predictive search table is placed inside this |
35 // macro. Uncomment the below line to get the table into use. |
40 // macro. Uncomment the below line to get the table into use. |
36 #define USE_PRED_SEARCH_TABLE |
41 #define USE_PRED_SEARCH_TABLE |
|
42 |
|
43 // If this macro is defined, then pred.search qwerty tables are used |
|
44 #define USE_QWERTY_PRED_SEARCH_TABLE |
37 |
45 |
38 |
46 |
39 /** |
47 /** |
40 Creates a concrete CPplContactItemManager object |
48 Creates a concrete CPplContactItemManager object |
41 |
49 |
396 iDatabase.FreeReservedSpace(); |
418 iDatabase.FreeReservedSpace(); |
397 } |
419 } |
398 |
420 |
399 lowDisk = EFalse; |
421 lowDisk = EFalse; |
400 iGroupTable->DeleteL(*savedContactItem, lowDisk); |
422 iGroupTable->DeleteL(*savedContactItem, lowDisk); |
401 if(lowDisk) |
423 if (lowDisk) |
402 { |
424 { |
403 DeleteInLowDiskConditionL(iGroupTable, savedContactItem); |
425 DeleteInLowDiskConditionL(iGroupTable, savedContactItem); |
404 } |
426 } |
405 |
427 |
406 lowDisk = EFalse; |
428 lowDisk = EFalse; |
407 iCommAddrTable->DeleteL(*savedContactItem, lowDisk); |
429 iCommAddrTable->DeleteL(*savedContactItem, lowDisk); |
408 if(lowDisk) |
430 if (lowDisk) |
409 { |
431 { |
410 DeleteInLowDiskConditionL(iCommAddrTable, savedContactItem); |
432 DeleteInLowDiskConditionL(iCommAddrTable, savedContactItem); |
411 } |
433 } |
412 |
434 |
413 #if defined(USE_PRED_SEARCH_TABLE) |
435 #if defined(USE_PRED_SEARCH_TABLE) |
414 RDebug::Print(_L("delete contact from pred search table")); |
436 PRINT(_L("delete contact from pred search tables")); |
415 lowDisk = EFalse; |
437 lowDisk = EFalse; |
416 iPredSearchTable->DeleteL(*savedContactItem, lowDisk); |
438 iPredSearch12keyTable->DeleteL(*savedContactItem, lowDisk); |
417 if(lowDisk) |
439 if (lowDisk) |
418 { |
440 { |
419 DeleteInLowDiskConditionL(iPredSearchTable, savedContactItem); |
441 DeleteInLowDiskConditionL(iPredSearch12keyTable, savedContactItem); |
420 } |
442 } |
421 RDebug::Print(_L("delete contact from pred search table - done")); |
443 lowDisk = EFalse; |
|
444 #if defined(USE_QWERTY_PRED_SEARCH_TABLE) |
|
445 iPredSearchQwertyTable->DeleteL(*savedContactItem, lowDisk); |
|
446 if (lowDisk) |
|
447 { |
|
448 DeleteInLowDiskConditionL(iPredSearchQwertyTable, savedContactItem); |
|
449 } |
|
450 iPredSearchSettingsTable->DeleteL(*savedContactItem, lowDisk); |
|
451 if (lowDisk) |
|
452 { |
|
453 DeleteInLowDiskConditionL(iPredSearchSettingsTable, savedContactItem); |
|
454 } |
|
455 #endif |
|
456 PRINT(_L("delete contact from pred search tables - done")); |
422 #endif |
457 #endif |
423 |
458 |
424 //Fake checking read access to ICCEntry store to keep BC. |
459 //Fake checking read access to ICCEntry store to keep BC. |
425 iIccContactStore.ReadL(*savedContactItem, EPlGroupMembershipInfo, aSessionId, EFalse); |
460 iIccContactStore.ReadL(*savedContactItem, EPlGroupMembershipInfo, aSessionId, EFalse); |
426 |
461 |
531 // construct tables |
566 // construct tables |
532 iContactTable = CPplContactTable::NewL(iDatabase, iContactProperties); |
567 iContactTable = CPplContactTable::NewL(iDatabase, iContactProperties); |
533 iCommAddrTable = CPplCommAddrTable::NewL(iDatabase, iContactProperties); |
568 iCommAddrTable = CPplCommAddrTable::NewL(iDatabase, iContactProperties); |
534 iGroupTable = CPplGroupsTable::NewL(iDatabase); |
569 iGroupTable = CPplGroupsTable::NewL(iDatabase); |
535 iPreferencePersistor = CPplPreferencesPersistor::NewL(iDatabase); |
570 iPreferencePersistor = CPplPreferencesPersistor::NewL(iDatabase); |
|
571 |
536 #if defined(USE_PRED_SEARCH_TABLE) |
572 #if defined(USE_PRED_SEARCH_TABLE) |
537 RDebug::Print(_L("create CPplPredictiveSearchTable object")); |
573 PRINT(_L("create C12keyPredictiveSearchTable object")); |
538 iPredSearchTable = CPplPredictiveSearchTable::NewL(iDatabase); |
574 iPredSearch12keyTable = C12keyPredictiveSearchTable::NewL(iDatabase); |
539 RDebug::Print(_L("create CPplPredictiveSearchTable object - done")); |
575 #if defined(USE_QWERTY_PRED_SEARCH_TABLE) |
540 #endif |
576 PRINT(_L("create CQwertyPredictiveSearchTable object")); |
|
577 iPredSearchQwertyTable = CQwertyPredictiveSearchTable::NewL(iDatabase); |
|
578 PRINT(_L("create CPredictiveSearchSettingsTable object")); |
|
579 iPredSearchSettingsTable = CPredictiveSearchSettingsTable::NewL(iDatabase); |
|
580 |
|
581 iPredictiveSearchSynchronizer = |
|
582 CPredictiveSearchSynchronizer::NewL(iDatabase, |
|
583 *iPredSearch12keyTable, |
|
584 *iPredSearchQwertyTable, |
|
585 *iPredSearchSettingsTable); |
|
586 #endif // #if defined(USE_QWERTY_PRED_SEARCH_TABLE) |
|
587 #endif // #if defined(USE_PRED_SEARCH_TABLE) |
|
588 |
541 iPresenceTable = CPplPresenceTable::NewL(iDatabase); |
589 iPresenceTable = CPplPresenceTable::NewL(iDatabase); |
542 |
590 |
543 // Connect to metadata server |
591 // Connect to metadata server |
544 //User::LeaveIfError(iColSession.Connect()); |
592 //User::LeaveIfError(iColSession.Connect()); |
545 |
593 |
608 { |
656 { |
609 RDebug::Print(_L("CPplContactItemManager::CreateTablesL")); |
657 RDebug::Print(_L("CPplContactItemManager::CreateTablesL")); |
610 |
658 |
611 TBool controlTransaction = !(iTransactionManager.IsTransactionActive()); |
659 TBool controlTransaction = !(iTransactionManager.IsTransactionActive()); |
612 |
660 |
613 if(controlTransaction) |
661 if (controlTransaction) |
614 { |
662 { |
615 StartTransactionL(0); |
663 StartTransactionL(0); |
616 } |
664 } |
617 |
665 |
618 iContactTable->CreateTableL(); |
666 iContactTable->CreateTableL(); |
619 iGroupTable->CreateTableL(); |
667 iGroupTable->CreateTableL(); |
620 iCommAddrTable->CreateTableL(); |
668 iCommAddrTable->CreateTableL(); |
621 iPreferencePersistor->CreateTableL(); |
669 iPreferencePersistor->CreateTableL(); |
622 #if defined(USE_PRED_SEARCH_TABLE) |
670 #if defined(USE_PRED_SEARCH_TABLE) |
623 RDebug::Print(_L("create pred search table to DB")); |
671 PRINT(_L("create pred search tables to DB")); |
624 iPredSearchTable->CreateTableL(); |
672 iPredSearch12keyTable->CreateTableL(); |
625 RDebug::Print(_L("create pred search table to DB - done")); |
673 #if defined(USE_QWERTY_PRED_SEARCH_TABLE) |
|
674 iPredSearchQwertyTable->CreateTableL(); |
|
675 iPredSearchSettingsTable->CreateTableL(); |
|
676 #endif |
|
677 PRINT(_L("create pred search tables to DB - done")); |
626 #endif |
678 #endif |
627 iPresenceTable->CreateTableL(); |
679 iPresenceTable->CreateTableL(); |
628 |
680 |
629 if(controlTransaction) |
681 if (controlTransaction) |
630 { |
682 { |
631 CommitTransactionL(); |
683 CommitTransactionL(); |
632 } |
684 } |
633 |
685 |
634 RDebug::Print(_L("CPplContactItemManager::CreateTablesL ends")); |
686 RDebug::Print(_L("CPplContactItemManager::CreateTablesL ends")); |
790 void CPplContactItemManager::SetCardTemplatePrefIdL(TInt aCardTemplatePrefId) |
841 void CPplContactItemManager::SetCardTemplatePrefIdL(TInt aCardTemplatePrefId) |
791 { |
842 { |
792 iPreferencePersistor->SetPreferredCardTemplateIdL(aCardTemplatePrefId); |
843 iPreferencePersistor->SetPreferredCardTemplateIdL(aCardTemplatePrefId); |
793 } |
844 } |
794 |
845 |
795 // If predictive search tables do not exist, generate them using data from |
|
796 // contacts table. |
|
797 void CPplContactItemManager::SynchronizePredSearchTableL() |
846 void CPplContactItemManager::SynchronizePredSearchTableL() |
798 { |
847 { |
799 #if !defined(USE_PRED_SEARCH_TABLE) |
848 #if defined(USE_PRED_SEARCH_TABLE) |
800 return; |
849 iPredictiveSearchSynchronizer->SynchronizeTablesL(); |
801 #endif |
850 #endif |
802 RDebug::Print(_L("CPplContactItemManager::SynchronizePredSearchTableL")); |
|
803 |
|
804 if (!DoesPredSearchTableExistL()) |
|
805 { |
|
806 CreatePredSearchTablesL(); |
|
807 } |
|
808 } |
851 } |
809 |
852 |
810 void CPplContactItemManager::RecreatePredSearchTablesL() |
853 void CPplContactItemManager::RecreatePredSearchTablesL() |
811 { |
854 { |
812 DeletePredSearchTablesL(); |
855 #if defined(USE_PRED_SEARCH_TABLE) |
813 CreatePredSearchTablesL(); |
856 iPredictiveSearchSynchronizer->DeletePredSearchTablesL(); |
814 } |
857 iPredictiveSearchSynchronizer->CreatePredSearchTablesL(); |
815 |
858 #endif |
816 void CPplContactItemManager::CreatePredSearchTablesL() |
859 } |
817 { |
|
818 RDebug::Print(_L("CPplContactItemManager::CreatePredSearchTablesL")); |
|
819 |
|
820 iPredSearchTable->CreateTableL(); |
|
821 _LIT(KSelectAllContactsFormat, "SELECT %S,%S,%S FROM %S;"); |
|
822 TInt bufSize = KSelectAllContactsFormat().Length() + |
|
823 KContactId().Length() + |
|
824 KContactFirstName().Length() + |
|
825 KContactLastName().Length() + |
|
826 KSqlContactTableName().Length(); |
|
827 HBufC* sqlStatement = HBufC::NewLC(bufSize); |
|
828 sqlStatement->Des().AppendFormat(KSelectAllContactsFormat, |
|
829 &KContactId, |
|
830 &KContactFirstName, |
|
831 &KContactLastName, |
|
832 &KSqlContactTableName); |
|
833 |
|
834 RSqlStatement stmnt; |
|
835 CleanupClosePushL(stmnt); |
|
836 RDebug::Print(_L("CreatePredSearchTablesL prepare SQL statement")); |
|
837 stmnt.PrepareL(iDatabase, *sqlStatement); |
|
838 |
|
839 const TInt KContactIdIndex = 0; |
|
840 const TInt KFirstNameIndex = 1; |
|
841 const TInt KLastNameIndex = 2; |
|
842 TInt err(KErrNone); |
|
843 while ((err = stmnt.Next()) == KSqlAtRow) |
|
844 { |
|
845 RDebug::Print(_L("CreatePredSearchTablesL create CContactItem")); |
|
846 |
|
847 TInt id = KUidContactCardValue; |
|
848 TUid uid; |
|
849 uid.iUid = id; |
|
850 CContactItem* contact = CContactItem::NewLC(uid); |
|
851 contact->SetId(stmnt.ColumnInt(KContactIdIndex)); |
|
852 |
|
853 // If first name exists, write it to contact item |
|
854 TPtrC firstName; |
|
855 if (stmnt.ColumnText(KFirstNameIndex, firstName) == KErrNone) |
|
856 { |
|
857 CContactItemField* field = |
|
858 CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName); |
|
859 CContactTextField* textfield = field->TextStorage(); |
|
860 textfield->SetTextL(firstName); |
|
861 contact->AddFieldL(*field); // Takes ownership |
|
862 CleanupStack::Pop(field); |
|
863 } |
|
864 |
|
865 TPtrC lastName; |
|
866 if (stmnt.ColumnText(KLastNameIndex, lastName) == KErrNone) |
|
867 { |
|
868 CContactItemField* field = |
|
869 CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName); |
|
870 CContactTextField* textfield = field->TextStorage(); |
|
871 textfield->SetTextL(lastName); |
|
872 contact->AddFieldL(*field); // Takes ownership |
|
873 CleanupStack::Pop(field); |
|
874 } |
|
875 RDebug::Print(_L("CreatePredSearchTablesL create entry to tables")); |
|
876 iPredSearchTable->CreateInDbL(*contact); |
|
877 CleanupStack::PopAndDestroy(contact); |
|
878 } |
|
879 |
|
880 // Leave if we didn't complete going through the results properly |
|
881 if (err != KSqlAtEnd) |
|
882 { |
|
883 RDebug::Print(_L("CreatePredSearchTablesL SQL err=%d"), err); |
|
884 User::Leave(err); |
|
885 } |
|
886 CleanupStack::PopAndDestroy(&stmnt); |
|
887 CleanupStack::PopAndDestroy(sqlStatement); |
|
888 |
|
889 RDebug::Print(_L("CPplContactItemManager::CreatePredSearchTablesL ends")); |
|
890 } |
|
891 |
|
892 TBool CPplContactItemManager::DoesPredSearchTableExistL() const |
|
893 { |
|
894 RDebug::Print(_L("CPplContactItemManager::DoesPredSearchTableExistL")); |
|
895 |
|
896 _LIT(KSelectContactIdsFormat, "SELECT %S FROM %S;"); |
|
897 TInt bufSize = KSelectContactIdsFormat().Length() + |
|
898 KPredSearchContactId().Length() + |
|
899 KSqlContactPredSearchTable0().Length(); |
|
900 HBufC* sqlStatement = HBufC::NewLC(bufSize); |
|
901 sqlStatement->Des().AppendFormat(KSelectContactIdsFormat, |
|
902 &KPredSearchContactId, |
|
903 &KSqlContactPredSearchTable0); |
|
904 |
|
905 RSqlStatement stmnt; |
|
906 CleanupClosePushL(stmnt); |
|
907 // If predictive search table does not exist, leaves with -311. |
|
908 // If it exists, does not leave. |
|
909 TRAPD(err, stmnt.PrepareL(iDatabase, *sqlStatement)); |
|
910 RDebug::Print(_L("err=%d"), err ); |
|
911 |
|
912 CleanupStack::PopAndDestroy(&stmnt); |
|
913 CleanupStack::PopAndDestroy(sqlStatement); |
|
914 |
|
915 RDebug::Print(_L("CPplContactItemManager::DoesPredSearchTableExistL return %d"), |
|
916 err == KErrNone ); |
|
917 return err == KErrNone; |
|
918 } |
|
919 |
|
920 void CPplContactItemManager::DeletePredSearchTablesL() |
|
921 { |
|
922 RDebug::Print(_L("CPplContactItemManager::DeletePredSearchTablesL")); |
|
923 |
|
924 const TInt KTableCount = 10; |
|
925 const TDesC* KTableNames[KTableCount] = |
|
926 { |
|
927 &KSqlContactPredSearchTable0, |
|
928 &KSqlContactPredSearchTable1, |
|
929 &KSqlContactPredSearchTable2, |
|
930 &KSqlContactPredSearchTable3, |
|
931 &KSqlContactPredSearchTable4, |
|
932 &KSqlContactPredSearchTable5, |
|
933 &KSqlContactPredSearchTable6, |
|
934 &KSqlContactPredSearchTable7, |
|
935 &KSqlContactPredSearchTable8, |
|
936 &KSqlContactPredSearchTable9 |
|
937 }; |
|
938 |
|
939 // IF EXISTS suppresses error that would occur if table does not exist |
|
940 _LIT(KDropTable, "DROP TABLE IF EXISTS %S;"); |
|
941 for (TInt i = 0; i < KTableCount; ++i) |
|
942 { |
|
943 HBufC* dropTableCommand = HBufC::NewLC(KDropTable().Length() + |
|
944 // All table names are of same length |
|
945 KTableNames[i]->Length()); |
|
946 TPtr ptr = dropTableCommand->Des(); |
|
947 ptr.Format(KDropTable, KTableNames[i]); |
|
948 |
|
949 User::LeaveIfError(iDatabase.Exec(*dropTableCommand)); |
|
950 CleanupStack::PopAndDestroy(dropTableCommand); |
|
951 } |
|
952 RDebug::Print(_L("CPplContactItemManager::DeletePredSearchTablesL ends")); |
|
953 } |
|