diff options
author | Ilya Sinitsyn <ilya.sinitsyn@nokia.com> | 2011-01-24 09:03:17 +0200 |
---|---|---|
committer | Ilya Sinitsyn <ilya.sinitsyn@nokia.com> | 2011-01-24 09:03:17 +0200 |
commit | bb2542ec97f1c9ebb0b0db88fd2cfda1033075af (patch) | |
tree | e59242a42ed2fbb9b5c0a1f9f10deff83ece7d75 | |
parent | ba72d5319e1bd2052996341e316cfd38e0b0fdac (diff) |
Taking S4 features into symbian contacts model
12 files changed, 1237 insertions, 0 deletions
diff --git a/plugins/contacts/symbian/contactsmodel/cntmodel/inc/cntimagerescaleutility.h b/plugins/contacts/symbian/contactsmodel/cntmodel/inc/cntimagerescaleutility.h new file mode 100644 index 0000000000..a575ec0df2 --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/cntmodel/inc/cntimagerescaleutility.h @@ -0,0 +1,81 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef CNTIMAGERESCALEUTILITY_H_ +#define CNTIMAGERESCALEUTILITY_H_ + +#include <f32file.h> + +class CContactItem; +/** + * This is a utility class used with CntImageRescale class. This class holds the information + * about phonbooks private image folder and is able to update the contact fields. + * + * When user assigns a image to contact, CntImageRescaler copies and rescales the image + * and asks this class to store it to contact item. + */ +NONSHARABLE_CLASS(TCntImageRescaleUtility) +{ +public: + /** + * Returns the private image directory. + * + * @return TPath Valid path to image directory + * @leave If any error occures + */ + IMPORT_C static TPath ImageDirectoryL(); + /** + * Create a private image folder if it does not exists already. + * + * @return TPath Full path to created image directory. + * @leave If any error occures + */ + IMPORT_C static TPath CreateImageDirectoryL(); + /** + * Delete the private image directory if it exists. + * + * @leave If any error occures + */ + IMPORT_C static void DeleteImageDirectoryL(); + /** + * Delete the private image from file system, if one exists. + */ + IMPORT_C static void DeleteImageL( const CContactItem& aItem ); + /** + * Checks that if the private image filename does not contain an unique + * identifier (GUID), adds it and renames the image. Updates also the contact + * item to contain the renamed image path. + * + * @param aItem Contact item which has a private image stored + * @leave If any error occures + */ + IMPORT_C static void UpdateImageNameL( const CContactItem& aItem ); + /** + * Stores the private image to given contacts field. + * + * @param aItem CContactItem where the private image path should be stored + * @param aPath New private image path + */ + IMPORT_C static void StoreImageFieldL( const CContactItem& aItem, const TPath aPath ); + +private: + /** + * Creates a backup and restore file + */ + static void CreateBackupAndRestoreFileL( RFs& aFs, const TPath& aDir ); +}; +#endif /* CNTIMAGERESCALEUTILITY_H_ */ diff --git a/plugins/contacts/symbian/contactsmodel/cntmodel/src/cntimagerescaleutility.cpp b/plugins/contacts/symbian/contactsmodel/cntmodel/src/cntimagerescaleutility.cpp new file mode 100644 index 0000000000..8940ebe9a5 --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/cntmodel/src/cntimagerescaleutility.cpp @@ -0,0 +1,224 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "cntimagerescaleutility.h" +#include "cntdbconsts_internal.h" + +#include "cntitem.h" +#include "cntfldst.h" + +#include <pathinfo.h> +#include <driveinfo.h> +#include <bautils.h> +#include <utf.h> + +_LIT(KImagesBackupFolderName, "backup_registration_images.xml"); +_LIT8(KXmlFilePart1, + "<?xml version=\"1.0\" standalone=\"yes\"?>\r\n" + "<backup_registration>\r\n" + " <public_backup delete_before_restore=\"yes\">\r\n" + " <include_directory name=\""); +_LIT8(KXmlFilePart2, + "\"/>\r\n" + " </public_backup>\r\n" + "</backup_registration>\r\n"); + +EXPORT_C TPath TCntImageRescaleUtility::ImageDirectoryL() +{ + TInt drive; + #ifdef __WINS__ + User::LeaveIfError(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive)); + #else + User::LeaveIfError(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, drive)); + #endif + + RFs fs; + CleanupClosePushL( fs ); + User::LeaveIfError( fs.Connect() ); + + // Get the root path in this drive to create the images directory + TPath imagesDirPath; + imagesDirPath.Zero(); + + User::LeaveIfError(PathInfo::GetRootPath(imagesDirPath, drive)); + imagesDirPath.Append(KImagesFolder); + + CleanupStack::PopAndDestroy(); // RFs + return imagesDirPath; +} + +EXPORT_C TPath TCntImageRescaleUtility::CreateImageDirectoryL() +{ + TPath imagePath; + TRAPD( err, imagePath = TCntImageRescaleUtility::ImageDirectoryL() ); + if ( err == KErrNone ) + { + RFs fs; + CleanupClosePushL( fs ); + User::LeaveIfError( fs.Connect() ); + + BaflUtils::EnsurePathExistsL( fs, imagePath ); + User::LeaveIfError(fs.SetAtt(imagePath, KEntryAttHidden, KEntryAttNormal)); + TCntImageRescaleUtility::CreateBackupAndRestoreFileL( fs, imagePath ); + + CleanupStack::PopAndDestroy(); // close RFs + } + return imagePath; +} + +EXPORT_C void TCntImageRescaleUtility::DeleteImageDirectoryL() +{ + TPath dir = TCntImageRescaleUtility::ImageDirectoryL(); + + RFs fs; + CleanupClosePushL( fs ); + User::LeaveIfError( fs.Connect() ); + + CFileMan* fileMan = CFileMan::NewL( fs ); + fileMan->RmDir(dir); // err not used + delete fileMan; + + CleanupStack::PopAndDestroy(); // close RFs +} + +EXPORT_C void TCntImageRescaleUtility::DeleteImageL( const CContactItem& aItem ) +{ + CContactItemFieldSet& fieldSet = aItem.CardFields(); + RFs fs; + CleanupClosePushL( fs ); + User::LeaveIfError( fs.Connect() ); + + // Find the image field + TInt index = fieldSet.Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown); + if (index != KErrNotFound) + { + // Image path field from list of contact fields + CContactItemField& field = fieldSet[index]; + TPtrC imagePath = field.TextStorage()->Text(); + + // Remove image file if it is stored in private folder + BaflUtils::DeleteFile(fs, imagePath); // Error value not necessary + } + + CleanupStack::PopAndDestroy(); // RFs +} + +EXPORT_C void TCntImageRescaleUtility::StoreImageFieldL( const CContactItem& aItem, const TPath aPath ) +{ + CContactItemFieldSet& fieldSet = aItem.CardFields(); + if ( aPath.Length() > 0 ) + { + CContactItemField* field = NULL; + + TInt privateImageIndex = fieldSet.Find( KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown ); + if ( privateImageIndex != KErrNotFound ) + { + field = &fieldSet[privateImageIndex]; + field->TextStorage()->SetTextL( aPath ); + } + } +} + +EXPORT_C void TCntImageRescaleUtility::UpdateImageNameL( const CContactItem& aItem ) +{ + CContactItemFieldSet& fieldSet = aItem.CardFields(); + + // Find the image field + TInt index = fieldSet.Find( KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown ); + if (index != KErrNotFound) + { + // Image path field from list of contact fields + CContactItemField& field = fieldSet[index]; + TPtrC privateImagePath = field.TextStorage()->Text(); + // unfortunately the Guid method is not const (?) and this ugly cast is needed + TPtrC guid = const_cast<CContactItem&>(aItem).Guid(); + + // Append the guid in the filename if it doesn't already exists + if (privateImagePath.Length() && privateImagePath.Find(guid) == KErrNotFound) + { + // Image file type + TParse p; + p.Set(privateImagePath, NULL, NULL); + + // Generate the image path + // Format <path>guid_timestamp_filename.ext + TPath newImagePath; + newImagePath.Append(TCntImageRescaleUtility::ImageDirectoryL()); + newImagePath.Append(guid); + newImagePath.Append(p.NameAndExt()); + + RFs fs; + CleanupClosePushL( fs ); + User::LeaveIfError( fs.Connect() ); + User::LeaveIfError(BaflUtils::RenameFile(fs, privateImagePath, newImagePath)); // Rename the file + CleanupStack::PopAndDestroy(); // RFs + + field.TextStorage()->SetTextL(newImagePath); + } + } +} + +void TCntImageRescaleUtility::CreateBackupAndRestoreFileL( RFs& aFs, const TPath& aDir ) +{ + TPath privatePath; + User::LeaveIfError( aFs.PrivatePath(privatePath)); + User::LeaveIfError( aFs.SetSessionPath(privatePath)); + + // If the path does not exist create it. + TInt err = aFs.MkDirAll(privatePath); + if (err != KErrAlreadyExists ) + { + User::LeaveIfError(err); + } + + // Remove previous backup registration file. The drive path may have + // changed so this file needs to be regenerated all the time + BaflUtils::DeleteFile( aFs, KImagesBackupFolderName()); // Error value not necessary + + const TInt newFileNameLength = KImagesBackupFolderName().Length(); + HBufC* newFileName = HBufC::NewLC(newFileNameLength); + TPtr newFileNamePtr(newFileName->Des()); + newFileNamePtr.Append(KImagesBackupFolderName); + + // Create registration file. + RFile file; + CleanupClosePushL(file); + + // File should not exist since it was deleted + User::LeaveIfError( file.Create(aFs, *newFileName, EFileWrite) ); + + HBufC* nameAndExt = NULL; + nameAndExt = HBufC::NewLC(aDir.Length()); + nameAndExt->Des().Append(aDir); + + // Convert foldername and extension to UTF8 before writing to file. + HBufC8* folderName = HBufC8::NewLC(aDir.Length()); + TPtr8 pFolderName(folderName->Des()); + + User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(pFolderName,*nameAndExt)); + + // Write data into file. + User::LeaveIfError(file.Write(KXmlFilePart1())); + User::LeaveIfError(file.Write(pFolderName)); + User::LeaveIfError(file.Write(KXmlFilePart2())); + User::LeaveIfError(file.Flush()); + + User::LeaveIfError( aFs.SetSessionPath(aDir) ); + CleanupStack::PopAndDestroy(4, newFileName); // folderName, nameAndExt, file, newFileName +} + +// End of File diff --git a/plugins/contacts/symbian/contactsmodel/cntplsql/group/cntplsql.iby b/plugins/contacts/symbian/contactsmodel/cntplsql/group/cntplsql.iby new file mode 100644 index 0000000000..7c92570795 --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/cntplsql/group/cntplsql.iby @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef __CNTPLSQL_IBY__ +#define __CNTPLSQL_IBY__ + +#include <sql.iby> + +file=ABI_DIR\BUILD_DIR\cntplsql.dll System\Libs\cntplsql.dll + +#endif diff --git a/plugins/contacts/symbian/contactsmodel/cntplsql/inc/cntsqldbstructure.h b/plugins/contacts/symbian/contactsmodel/cntplsql/inc/cntsqldbstructure.h new file mode 100644 index 0000000000..ce0cace021 --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/cntplsql/inc/cntsqldbstructure.h @@ -0,0 +1,184 @@ +/* +* Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: An object representing a sql database table information. +* All the tables and their column information is stored in the source code. +* While checking compatibility, this information is compared with the tables and columns in the database. +* This class is used for checking if the database contains all the columns. If not, then +* it may be needed to add those columns (To maintain compatibility accross releases) +* +*/ + + + +/** +@internalComponent +@released +*/ + +#ifndef __CNTSQLDBSTRUCTURE_H__ +#define __CNTSQLDBSTRUCTURE_H__ + +#include <e32base.h> +#include <sqldb.h> + +/* +* Class provide information about columns in a table +*/ +class CCntSqlDbTableColumn:public CBase + { + public: + + /* + * Creates a new CCntSqlDbTableColumn obj + * @param aColumnName - Mandatory + * @param aColType - Mandatory + * @param aNotNullValue + * @param aAdditionalInfo + * @return - obj of CCntSqlDbTableColumn + */ + static CCntSqlDbTableColumn* NewLC( + const TDesC& aColumnName, + const TDesC& aColType, + TBool aNotNullValue = EFalse, + const TDesC& aAdditionalInfo = KNullDesC() ); + + /* + * Returns the column Name + */ + const TDesC& ColumnName() const; + + /* + * Returns the column type i.e INTEGER, VARCHAR etc + */ + const TDesC& ColumnType() const; + + /* + * Returns true if NOTNULL constrain set + */ + TBool NotNullValue() const ; + + /* + * Any addition infomation such as default value etc + */ + const TDesC& AdditionalInfo() const; + + /* + * Returns NOTNULL string if NOTNULL constrain set + * else returns KNullDesC() + */ + const TDesC& NotNullString() const; + + /* + * Destructor + */ + ~CCntSqlDbTableColumn(); + +private: + + CCntSqlDbTableColumn(TBool aNotNullValue); + void ConstructL(const TDesC& aColumnName, const TDesC& aColType,const TDesC& aAdditionalInfo); + +private: + + HBufC* iColumnName; //own, column name + HBufC* iColumnType; //own, column type + TBool iNotNullValue; //own , notnull value + HBufC* iAdditionalInfo; //own, additional information + HBufC* iNotNullStr; //Own, Not NULL String + }; + + +/* +* Class provide information about the table +*/ +NONSHARABLE_CLASS(CCntSqlDbTable) : public CBase + { +public: + static CCntSqlDbTable* NewLC (const TDesC& aTableName, RSqlDatabase& aDbInstance); +public: + /* + * Returns the table name + */ + const TDesC& TableName() const; + /* + * Checks the database table and verifies if all columns are present. If not, + * then the missing columns are added in the database table + */ + void MakeTableStructureCompatibleL(); + /* + * Add a column to this table + * @param aColumnName - Mandatory + * @param aColType - Mandatory + * @param aNotNullValue + * @param aAdditionalInfo + */ + void AddColumnToColumnInfoL( const TDesC& aColumnName, + const TDesC& aColType, + TBool aNotNullValue = EFalse, + const TDesC& aAdditionalInfo = KNullDesC() ); + + /* + * destructor + */ + ~CCntSqlDbTable(); + +protected: + void ConstructL(const TDesC& aTableName); + +private: + CCntSqlDbTable(RSqlDatabase& aDbInstance); + void GetMissingColumns(RPointerArray<CCntSqlDbTableColumn>& aColumnsToAdd); + void GetExistingColumnsFromDatabaseL(RPointerArray<CCntSqlDbTableColumn>& aExistingColumnsFromOldDb); + void AlterTableToAddColumnL( CCntSqlDbTableColumn* aColInfo); + +protected: + HBufC* iTableName; // holds the table name, own + RPointerArray<CCntSqlDbTableColumn> iColumnInfo; // own,List of columns this table should have + RSqlDatabase& iDatabase; // not own + + }; + +/* + * This class holds the actual table structure that should be. If the databsse does not have + * this structure then it needs to be modified to make it compatible + */ +NONSHARABLE_CLASS(CCntSqlDbStructure) : public CBase + { +public: + static CCntSqlDbStructure* NewL( RSqlDatabase& aDbInstance); + ~CCntSqlDbStructure(); + /* + * Checks the database and verifies if all tables and columns are present. If not, + * then the missing columns are added in the database + */ + void MakeDatabaseCompatibleL(); + + /* + * Returns the List of Tables present in this DB + */ + const RPointerArray<CCntSqlDbTable>& Tables(); + +private: + CCntSqlDbStructure( RSqlDatabase& aDbInstance); + void InitializeL(); + void InitializeContactsTableInfoL(); + void InitializeGroupsTableInfoL(); + void InitializeCommAddrTableInfoL(); + +private: + RPointerArray<CCntSqlDbTable> iTables; //own, list of tables + RSqlDatabase& iDatabase; // not own, handle to the database + + }; +#endif //__CNTSQLDBSTRUCTURE_H__ diff --git a/plugins/contacts/symbian/contactsmodel/cntplsql/src/cntsqldbstructure.cpp b/plugins/contacts/symbian/contactsmodel/cntplsql/src/cntsqldbstructure.cpp new file mode 100644 index 0000000000..fa945f01ce --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/cntplsql/src/cntsqldbstructure.cpp @@ -0,0 +1,440 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#include "cntsqldbstructure.h" +#include "dbsqlconstants.h" +#include <sqldb.h> + +const TInt KSqlStatementSize = 1024; +// Destroy the RPointerArray +void DestroyRPointerArray(TAny* aPtr) + { + RPointerArray<CCntSqlDbTableColumn>* self = static_cast<RPointerArray<CCntSqlDbTableColumn>*> (aPtr); + self->ResetAndDestroy(); + self->Close(); + } + +/* + * Factory method to get instance of CCntSqlDbTableColumn + */ +CCntSqlDbTableColumn* CCntSqlDbTableColumn::NewLC( const TDesC& aColumnName, + const TDesC& aColType, + TBool aNotNullValue /*= EFalse*/, + const TDesC& aAdditionalInfo /*= KNullDesC()*/ ) + { + CCntSqlDbTableColumn* self = new (ELeave) CCntSqlDbTableColumn( aNotNullValue ); + CleanupStack::PushL( self ); + self->ConstructL( aColumnName, aColType, aAdditionalInfo ); + return self; + } + +void CCntSqlDbTableColumn::ConstructL( const TDesC& aColumnName, + const TDesC& aColType, + const TDesC& aAdditionalInfo ) + { + iColumnName = aColumnName.AllocL(); + iColumnType = aColType.AllocL(); + iAdditionalInfo = aAdditionalInfo.AllocL(); + if ( iNotNullValue ) + { + iNotNullStr = KNotNull().AllocL(); + } + else + { + iNotNullStr = KNullDesC().AllocL(); + } + } + +/* + * constructor + */ +CCntSqlDbTableColumn::CCntSqlDbTableColumn( TBool aNotNullValue ) + : iNotNullValue( aNotNullValue ) + { + } + +/* + * returns the column name + */ +const TDesC& CCntSqlDbTableColumn::ColumnName() const + { + return *iColumnName; + } +/* + * Returns the column type + */ +const TDesC& CCntSqlDbTableColumn::ColumnType() const + { + return *iColumnType; + } + +/* + * Returns the non null value + */ +TBool CCntSqlDbTableColumn::NotNullValue() const + { + return iNotNullValue; + } + +/* + * Returns the non null value + */ +const TDesC& CCntSqlDbTableColumn::NotNullString() const + { + return *iNotNullStr; + } + +/* + * Additional info such as default value, constrain etc + */ +const TDesC& CCntSqlDbTableColumn::AdditionalInfo() const + { + return *iAdditionalInfo; + } +/* + * Destructor + */ +CCntSqlDbTableColumn::~CCntSqlDbTableColumn() + { + delete iColumnName; + delete iColumnType; + delete iAdditionalInfo; + delete iNotNullStr; + } + +/* +Factory method to create an instance of the class +*/ + +CCntSqlDbTable* CCntSqlDbTable::NewLC( const TDesC& aTableName, RSqlDatabase& aDbInstance ) + { + CCntSqlDbTable* self = new (ELeave) CCntSqlDbTable( aDbInstance ); + CleanupStack::PushL( self ); + self->ConstructL( aTableName ); + return self; + } + +/* +Private Constructor +*/ + +CCntSqlDbTable::CCntSqlDbTable( RSqlDatabase& aDbInstance ) +: iDatabase( aDbInstance ) + { + } + +/* +Returns the table name +*/ + +const TDesC& CCntSqlDbTable::TableName() const + { + return *iTableName; + } + +/* +Reads the database and gets the existing columns information for this table +*/ + +void CCntSqlDbTable::GetExistingColumnsFromDatabaseL( + RPointerArray<CCntSqlDbTableColumn>& aExistingColumnsInDb ) + { + //Get the table information using the PRAGMA Statement + RSqlStatement columnInfoStatement; + CleanupClosePushL( columnInfoStatement ); + + HBufC* sqlstmt = HBufC::NewLC( KPragmaStmnt().Length() + + iTableName->Length() ); + sqlstmt->Des().Format( KPragmaStmnt, &*iTableName ); + + //Get the name and type + User::LeaveIfError( columnInfoStatement.Prepare( iDatabase, *sqlstmt ) ); + TInt KNameIndex = columnInfoStatement.ColumnIndex( KPragmaName ); + TInt KTypeIndex = columnInfoStatement.ColumnIndex( KPragmaType ); + + TInt err = KErrNotFound; + + //Go through each one and add the column details + while( ( err = columnInfoStatement.Next() ) == KSqlAtRow ) + { + TPtrC nameCol = ( columnInfoStatement.ColumnTextL( KNameIndex ) ); + TPtrC typeCol = ( columnInfoStatement.ColumnTextL( KTypeIndex ) ); + CCntSqlDbTableColumn* columnInOldTable = + CCntSqlDbTableColumn::NewLC( nameCol, typeCol ); + aExistingColumnsInDb.AppendL(columnInOldTable); + CleanupStack::Pop(); //columnInOldTable + } + + if ( KSqlAtEnd != err ) + { + User::Leave( err ); + } + + //clean up + CleanupStack::PopAndDestroy() ; //sqlstmt + CleanupStack::PopAndDestroy( &columnInfoStatement ); + } + +/* + * Gets the columns that are missing from the database file for this table + * */ +void CCntSqlDbTable::GetMissingColumns( RPointerArray<CCntSqlDbTableColumn>& aColumnsToAdd ) + { + RPointerArray<CCntSqlDbTableColumn> existingColumnsFromDb; + CleanupStack::PushL( TCleanupItem( DestroyRPointerArray, &existingColumnsFromDb ) ); + GetExistingColumnsFromDatabaseL( existingColumnsFromDb ); + + TInt existingColumnCount = existingColumnsFromDb.Count(); + if( existingColumnCount ) + { + //Check if any new columns exist + for( TInt i = 0; i < iColumnInfo.Count(); i++ ) + { + CCntSqlDbTableColumn* col = iColumnInfo[i]; + TInt j = 0; + for( ; j < existingColumnCount; j++ ) + { + + if( col->ColumnName().CompareC( existingColumnsFromDb[j]->ColumnName() ) == 0 ) + { + break; + } + } + if( existingColumnCount == j ) + { + aColumnsToAdd.Append( iColumnInfo[i] ); + } + + } + } + CleanupStack::PopAndDestroy( &existingColumnsFromDb ); //existingColumnsFromDb + } +/* + * Checks the table structure and adds new columns if needed for this table + * + */ +void CCntSqlDbTable::MakeTableStructureCompatibleL() + + { + RPointerArray<CCntSqlDbTableColumn> columnsToAdd; + //Contents are not owned by ColumnsToAdd. So its enough if we call close at the end + CleanupClosePushL( columnsToAdd ); + + GetMissingColumns(columnsToAdd); + + // Create the sql string for altering the table + // We cannot add all columns in one statement, so need to process + // one by one + TInt cnt = columnsToAdd.Count(); + + for( TInt i = 0; i< cnt ; i++ ) + { + AlterTableToAddColumnL(columnsToAdd[i]); + } + + CleanupStack::PopAndDestroy(); //ColumnsToAdd.Close() + } +/* + * Alters this table and adds the column specified by aColInfo. + */ +void CCntSqlDbTable::AlterTableToAddColumnL( CCntSqlDbTableColumn* aColInfo) + { + HBufC* sqlstmt = HBufC::NewLC( KSqlStatementSize ); + if(aColInfo) + { + sqlstmt->Des().Format( KContactTableAddColumn, + &*iTableName, + &( aColInfo->ColumnName() ), + &( aColInfo->ColumnType() ), + &( aColInfo->NotNullString() ), + &( aColInfo->AdditionalInfo() ) + ); + + RSqlStatement addColStmt; + CleanupClosePushL(addColStmt); + addColStmt.Prepare( iDatabase, *sqlstmt ); + TInt err = addColStmt.Exec(); + CleanupStack::PopAndDestroy( &addColStmt ); + } + CleanupStack::PopAndDestroy(); //sqlstmt + } +/* + * Adds a column to the table info. + */ +void CCntSqlDbTable::AddColumnToColumnInfoL( const TDesC& aColName, + const TDesC& aColType, + TBool aNotNullValue /*= EFalse*/, + const TDesC& aAdditionalInfo /*= KNullDesC()*/ ) + { + + CCntSqlDbTableColumn* col = CCntSqlDbTableColumn::NewLC( aColName, aColType, + aNotNullValue, aAdditionalInfo ); + iColumnInfo.AppendL(col); + CleanupStack::Pop(); //col + } + +/* + * Destructor + */ +CCntSqlDbTable::~CCntSqlDbTable() + { + delete iTableName; + iColumnInfo.ResetAndDestroy(); + iColumnInfo.Close(); + } + +void CCntSqlDbTable::ConstructL(const TDesC& aTableName) + { + iTableName = aTableName.Alloc(); + } + + +/* + * Factory method to return instance of CCntSqlDbStructure. + */ +CCntSqlDbStructure* CCntSqlDbStructure::NewL( RSqlDatabase& aDbInstance) + { + return new ( ELeave ) CCntSqlDbStructure( aDbInstance ); + } +/* + * Initilizes the table with table and columns + */ +void CCntSqlDbStructure::InitializeL() + { + // Contacts table + InitializeContactsTableInfoL(); + + //Groups table + InitializeGroupsTableInfoL(); + + // Comm addr table + InitializeCommAddrTableInfoL(); + } + + +/* + * Initilizes the contacts table column information. + */ +void CCntSqlDbStructure::InitializeContactsTableInfoL() + { + CCntSqlDbTable * contactTable = CCntSqlDbTable::NewLC( KSqlContactTableName(), iDatabase ); + + contactTable->AddColumnToColumnInfoL(KContactId(), KInteger(),ETrue, KAutoIncrement); + contactTable->AddColumnToColumnInfoL(KContactTemplateId(), KInteger(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactTypeFlags(), KInteger(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactAccessCount(), KInteger(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactCreationDate(), KInteger(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactLastModified(), KInteger(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactGuidString(), KVarchar255(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactFirstName(), KVarchar255(),ETrue, KDefault()); + contactTable->AddColumnToColumnInfoL(KContactLastName(), KVarchar255(),ETrue, KDefault()); + contactTable->AddColumnToColumnInfoL(KContactCompanyName(), KVarchar255(),ETrue, KDefault()); + + contactTable->AddColumnToColumnInfoL(KContactFirstNamePrn(), KVarchar255(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactLastNamePrn(), KVarchar255(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactCompanyNamePrn(), KVarchar255(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactTextFieldHeader(), KBlob(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactBinaryFieldHeader(), KBlob(),EFalse, KNullDesC()); + + contactTable->AddColumnToColumnInfoL(KContactTextFields(), KText(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactBinaryFields(), KBlob(),EFalse, KNullDesC()); + contactTable->AddColumnToColumnInfoL(KContactFavoriteIndex(), KInteger(),EFalse, KNullDesC()); + + iTables.AppendL( contactTable ); + CleanupStack::Pop(); //contactTable + } + +/* + * Initilizes the Groups table column information. + */ +void CCntSqlDbStructure::InitializeGroupsTableInfoL() + { + CCntSqlDbTable * groupTable = CCntSqlDbTable::NewLC( KSqlContactGroupTableName(), iDatabase ); + + groupTable->AddColumnToColumnInfoL(KGroupId(), KInteger(),ETrue, KAutoIncrement()); + groupTable->AddColumnToColumnInfoL(KGroupContactGroupId(), KInteger(),ETrue, KNullDesC()); + groupTable->AddColumnToColumnInfoL(KGroupContactGroupMemberId(), KInteger(),ETrue, KNullDesC()); + + iTables.AppendL( groupTable ); + CleanupStack::Pop(); //groupTable + } + +/* + * Initilizes the comm_addr table column information. + */ +void CCntSqlDbStructure::InitializeCommAddrTableInfoL() + { + CCntSqlDbTable * commAddrTable = CCntSqlDbTable::NewLC( KSqlContactCommAddrTableName(), iDatabase ); + + commAddrTable->AddColumnToColumnInfoL(KCommAddrId(), KInteger(),ETrue, KAutoIncrement()); + commAddrTable->AddColumnToColumnInfoL(KCommAddrType(), KInteger(),ETrue, KNullDesC()); + commAddrTable->AddColumnToColumnInfoL(KCommAddrValue(), KChar255(),ETrue, KNullDesC()); + commAddrTable->AddColumnToColumnInfoL(KCommAddrExtraValue(), KChar255(),EFalse, KNullDesC()); + commAddrTable->AddColumnToColumnInfoL(KCommAddrContactId(), KInteger(),ETrue, KNullDesC()); + commAddrTable->AddColumnToColumnInfoL(KCommAddrExtraTypeInfo(), KInteger(),EFalse, KNullDesC()); + + iTables.AppendL( commAddrTable ); + CleanupStack::Pop(); //commAddrTable + } + +/* + * Destructor + */ +CCntSqlDbStructure::~CCntSqlDbStructure() + { + iTables.ResetAndDestroy(); + iTables.Close(); + } + +/* + * Makes the database compatible with respect to the structure defined + * For each of the tables, it calls the corresponding function to make + * it compatible + */ +void CCntSqlDbStructure::MakeDatabaseCompatibleL() + { + // Initilize the table and column info + InitializeL(); + TInt count = iTables.Count(); + for( TInt i = 0; i < count; i++ ) + { + iTables[i]->MakeTableStructureCompatibleL(); + } + } + +/* + * Returns the list of tables + */ +const RPointerArray<CCntSqlDbTable>& CCntSqlDbStructure::Tables() + { + return iTables; + } + +/* + * Constructor + */ +CCntSqlDbStructure::CCntSqlDbStructure( RSqlDatabase& aDbInstance) + : iDatabase( aDbInstance ) + { + } diff --git a/plugins/contacts/symbian/contactsmodel/conf/contactsmodel.confml b/plugins/contacts/symbian/contactsmodel/conf/contactsmodel.confml Binary files differnew file mode 100644 index 0000000000..b6a546beba --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/conf/contactsmodel.confml diff --git a/plugins/contacts/symbian/contactsmodel/conf/contactsmodel_10003a73.crml b/plugins/contacts/symbian/contactsmodel/conf/contactsmodel_10003a73.crml Binary files differnew file mode 100644 index 0000000000..0ccab7ccb8 --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/conf/contactsmodel_10003a73.crml diff --git a/plugins/contacts/symbian/contactsmodel/groupsql/cntmodelteftest.iby b/plugins/contacts/symbian/contactsmodel/groupsql/cntmodelteftest.iby new file mode 100644 index 0000000000..835c0b1888 --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/groupsql/cntmodelteftest.iby @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef __CNTMODELTEFTEST_IBY__ +#define __CNTMODELTEFTEST_IBY__ + +#include <testexecute.iby> + +#include <CntPerfTestServer.iby> +#include <te_PerformanceFunctionalitySuite.iby> +#include <TE_Cntsrv_API_Policing.IBY> +#include <TestContactSuite.iby> +#include <TEF_CntModelCIT.iby> + + +#endif diff --git a/plugins/contacts/symbian/contactsmodel/tsrc/cm_all_tests.bat b/plugins/contacts/symbian/contactsmodel/tsrc/cm_all_tests.bat new file mode 100644 index 0000000000..e979a73428 --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/tsrc/cm_all_tests.bat @@ -0,0 +1,109 @@ +T_AGENT +T_DBASE2 +T_DBNAMETEST +T_EXPDEL +T_FIELD +T_FILTERFINDCONTACTS +t_geo +T_ITEM +T_TEMPL +T_VERS +T_VIEW +t_vtel_email +T_TTVERS +T_NOMACH +T_CNTMATCH +T_CARDTM +T_OWNCAR +T_OWNCARDDELETE +T_GROUPS +T_CONNEC +T_CURRENTDB +T_VIEW2 +T_FILTERVIEW +T_CUSTFILTER +T_GROUPVIEW +T_SERVERSTART +T_LOCALVIEWDUPLICATES +T_FILTEREDVIEWUPDATE +T_GROUPVIEWUPDATE +T_VIEWSOOM +T_REFINEFINDVIEWL +T_VIEWOBSERVERSBUG +T_GROUPVIEWPANIC +T_ICCENTRY +T_ICCVIEW +T_ICCMULTIPLEPHONEBOOK +T_ICCSTARTUP +T_CASESENSITIVEDB +T_CONTACTAT +t_requeststoretest +T_FILTEREDVIEWEVENTS +T_GROUPDELETEBUG +T_VIEWCONTACTID +T_VIEWSORT +T_VIEWSORTPLUGIN +T_PREFIXFULLSEARCH +T_DATABASE_KILLER +T_WRONGFIELDMATCH +T_UPDATEFORSYNC +T_FILTERVIEW_MATCHING_PROFILE +T_GROUPVIEW_UNFILED_PROFILE +T_GROUPVIEWMODIFIEDCONTACT +T_SPEEDDIALTEST +T_GENERALADDRESS +T_APAC +T_VIEWEVENTS +T_OWNCARD +T_ICCIMPORTLOCK +T_FILTEREDVIEWSORT +T_LOCALVIEWREMOVE +T_TIMEIS +T_CVIEWCONTACT +T_FILTERBROADCAST +T_SECONDNAME +T_REMOTEVIEW +T_FILTERVIEWSPEED +T_VIEWNOTIFICATIONERROR +T_VEXPORTBIRTHDAY +T_VEXPORTTYPE +T_CONTACTVIEWEVENTS +T_LONGSQL +T_VEXPORTORG +T_SEC_CNTDBASE +T_SEC_ASYNCOPEN +T_PERFORMANCE +T_PLATSEC +T_CNTFINDALL +T_ASYNCOPEN +T_PLPERFORMANCE +T_CONCURRENT +T_DBFill +t_contactsramtest +T_CntPBAPSupport +asynaccess +T_CntDelete +T_CntIdTest +T_DB_SORTL_TEST +t_contactdbevent +t_subview +T_GROUPVIEWEVENTS +TESTEXECUTE C:\CITExImvCard\scripts\TestImpExvCard.script +TESTEXECUTE C:\ContactTestCases.script +TESTEXECUTE c:\CntPerfTest\scripts\cntperftest.script +TESTEXECUTE C:\testdata\scripts\TE_Cntsrv_API_Policing.script +TESTEXECUTE C:\CITExImvCard\scripts\TestImpExvCardPBAP.script +TVERSIT +TVGEN +TCHARSETVCARD +TBUGFIX +TOOM +TPERFORMANCE +TDEFAULTCHARSET +TEST_SAVELOADBIN +TEST_SAVELOADBINOOM +TJAPANESESOUNDPROPERTY +TEST_RECOGNIZER +TestExternalize +T_DataCompatibility + diff --git a/plugins/contacts/symbian/contactsmodel/tsrc/cm_all_tests_unicode.bat b/plugins/contacts/symbian/contactsmodel/tsrc/cm_all_tests_unicode.bat Binary files differnew file mode 100644 index 0000000000..ca5e082af6 --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/tsrc/cm_all_tests_unicode.bat diff --git a/plugins/contacts/symbian/contactsmodel/tsrc/t_launchTest.cpp b/plugins/contacts/symbian/contactsmodel/tsrc/t_launchTest.cpp new file mode 100644 index 0000000000..7e83c3ed0c --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/tsrc/t_launchTest.cpp @@ -0,0 +1,115 @@ +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +// INCLUDE FILES +#include <t_launchTest.h> + +void DoTestsL() + { + CLog* loger; + RTest test(_L("T_LaunchTest")); + TInt blankLoc; + TBuf<100> appName( 0 ); + TBuf<200> parameters( 0 ); + TBuf<200> tempStr( 0 ); + RFile fileread; + TFileText tf; + RFs fsSession; + TUidType uidtype( KNullUid ); + _LIT(KFileNameRead, "C:\\data\\cm_all_tests.bat"); + _LIT(KLogFileName,"t_launchTest.log"); + + // New loger + loger = CLog::NewL( test, KLogFileName ); + CleanupStack::PushL( loger ); + + // New process control + RProcess* process = new RProcess(); + CleanupStack::PushL( process ); + loger->LogLine( + _L("Run auto testing for contacts model.[cm_all_tests.bat]") ); + + // Open cm_all_tests.bat + User::LeaveIfError( fsSession.Connect() ); + CleanupClosePushL( fsSession ); + User::LeaveIfError( fileread.Open( fsSession, KFileNameRead, EFileStream + | EFileRead ) ); + CleanupClosePushL( fileread ); + tf.Set( fileread ); + loger->LogLine( _L("Runing:") ); + + // Read the testing cases from cm_all_tests.bat and run it. + for (; KErrNone == tf.Read( tempStr ); ) + { + if ( tempStr.Length() <= 0 ) + { + loger->LogLine( _L("Blank line: No Program ") ); + continue; + } + // Analyze the command format + appName.Copy( _L("z:\\sys\\bin\\") ); + tempStr.TrimAll(); + blankLoc = tempStr.Locate( ' ' ); + if ( 0 > blankLoc ) + { + // No parameters. + appName.Append( tempStr ); + parameters = _L( "" ); + } + else + { + // Store parameters. + appName.Append( tempStr.Left( blankLoc ) ); + parameters = tempStr.Mid( blankLoc + 1 ); + } + appName.Append( _L(".exe") ); + loger->LogLine( tempStr ); + + // Run the command. + TInt err = process->Create( appName, parameters, uidtype ); + if ( KErrNone != err ) + { + tempStr.Format( _L("Not Found %S "), &appName ); + loger->LogLine( tempStr ); + continue; + } + TRequestStatus status( KRequestPending ); + process->Rendezvous( status ); + process->Resume(); + User::WaitForRequest( status ); + TExitType type = process->ExitType(); + TBuf<200> buf = process->ExitCategory(); + buf.AppendFormat( _L(": process->ExitType %d "), type ); + loger->LogLine( buf ); + process->Close(); + User::After( 1000000 ); + } + fileread.Close(); + fsSession.Close(); + loger->LogLine( _L("Print any key to exit:")); + test.Close(); + CleanupStack::PopAndDestroy( 4 ); // fileread, process, fsSession, loger + } + + + +int main( void ) + { + __UHEAP_MARK; + TRAPD(err,DoTestsL()); + __UHEAP_MARKEND; + return KErrNone; + } + diff --git a/plugins/contacts/symbian/contactsmodel/tsrc/t_launchTest.h b/plugins/contacts/symbian/contactsmodel/tsrc/t_launchTest.h new file mode 100644 index 0000000000..0770138be1 --- /dev/null +++ b/plugins/contacts/symbian/contactsmodel/tsrc/t_launchTest.h @@ -0,0 +1,29 @@ +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +#include <stdio.h> +#include <e32std.h> +#include <f32file.h> +#include <s32file.h> +#include <e32cons.h> +#include <t_utils2.h> +#include <e32test.h> +#include <cntdb.h> +#include <cntitem.h> +#include <cntfldst.h> + +#define __TB92_PROTO_TESTING__ // Enable the code for testing on proto + + |