commsfwtools/preparedefaultcommsdatabase/Tools/ced/src/preference.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include "database.h"
       
    22 #include "dbdef.h"
       
    23 #include "filedump.h"
       
    24 
       
    25 /**
       
    26 makes logging accessible to all files
       
    27 
       
    28 */
       
    29 extern FileDump* oMsg;
       
    30 
       
    31 //
       
    32 //
       
    33 // PRIVATE PREFERENCE METHODS
       
    34 //
       
    35 //
       
    36 
       
    37 
       
    38 TInt DBAccess::OpenPreferenceTable(TDesC &table)
       
    39 /**
       
    40 Opens the preference table
       
    41 
       
    42   @param table A reference to a descriptor containing the name of a table
       
    43   @return ETrue if Successful else EFalse 
       
    44   */
       
    45 	{
       
    46 	TInt valid = EFalse;
       
    47 	
       
    48 	if (table.Compare(TPtrC(CONNECTION_PREFERENCES)) == 0)
       
    49 		{
       
    50 		IAPpreference.iDirection = ECommDbConnectionDirectionOutgoing;
       
    51 		
       
    52 		oMsg->Dbg(_L("  Opening preference table for outgoing"));
       
    53 		
       
    54 		TRAPD(ret, _OpenPrefTableL());
       
    55 		if (Evaluate(ret))
       
    56 			{
       
    57 			if (dbPrefView)
       
    58 				{
       
    59 				access |= DBPrefOut;
       
    60 				valid = ETrue;
       
    61 				}
       
    62 			}
       
    63 		}
       
    64 	
       
    65 	if (valid)
       
    66 		if (access & DBUpdate)
       
    67 			if (!Evaluate(dbPrefView->GotoFirstRecord()))
       
    68 				valid = EFalse;
       
    69 			
       
    70 			return valid;
       
    71 	}
       
    72 
       
    73 
       
    74 TInt DBAccess::OpenPreferenceTableOnRank(TDesC &table)
       
    75 /**
       
    76 Open the preference table according to supplied rank and direction
       
    77 
       
    78   @param table A reference to a descriptor containing the name of a table
       
    79   @return ETrue if Successful else EFalse 
       
    80   */
       
    81 	{
       
    82 	TInt valid = EFalse;
       
    83 	
       
    84 	if (table.Compare(TPtrC(CONNECTION_PREFERENCES)) == 0)
       
    85 		{
       
    86 		IAPpreference.iDirection = ECommDbConnectionDirectionOutgoing;
       
    87 		
       
    88 		oMsg->Dbg(_L("  Opening preference table using rank [%d] direction [%d]"), IAPpreference.iRanking, IAPpreference.iDirection);
       
    89 		
       
    90 		TRAPD(ret, _OpenPrefTableOnRankL());
       
    91 		if (Evaluate(ret))
       
    92 			{
       
    93 			if (dbPrefView)
       
    94 				{
       
    95 				access |= DBPrefOut;
       
    96 				valid = ETrue;
       
    97 				}
       
    98 			}
       
    99 		}
       
   100 	
       
   101 	if (valid)
       
   102 		if (access & DBUpdate)
       
   103 			if (!Evaluate(dbPrefView->GotoFirstRecord()))
       
   104 				valid = EFalse;
       
   105 			
       
   106 			return valid;
       
   107 	}
       
   108 
       
   109 
       
   110 void DBAccess::_OpenPrefTableL()
       
   111 /**
       
   112 Opens specific tables.  This is done in it's own functions because
       
   113 they put stuff on the stack that has to be popped off before a
       
   114 TRAP can be called on it.
       
   115 
       
   116   */
       
   117 	{
       
   118 	dbPrefView = db->OpenConnectionPrefTableLC(IAPpreference.iDirection);
       
   119 	
       
   120 	CleanupStack::Pop(); // view
       
   121 	}
       
   122 
       
   123 void DBAccess::_OpenPrefTableOnRankL()
       
   124 	{
       
   125 	dbPrefView = db->OpenConnectionPrefTableViewOnRankLC(IAPpreference.iDirection, IAPpreference.iRanking);
       
   126 	
       
   127 	CleanupStack::Pop(); // view
       
   128 	}
       
   129 
       
   130 
       
   131 void DBAccess::ResetPreferenceFields()
       
   132 /**
       
   133 Set Preference Table structure to known values
       
   134 
       
   135   */
       
   136 	{
       
   137 	IAPpreference.iRanking = BADNUMVAL;
       
   138 	IAPpreference.iDirection = ECommDbConnectionDirectionUnknown;
       
   139 	IAPpreference.iDialogPref = ECommDbDialogPrefUnknown;
       
   140 	IAPpreference.iBearer.iBearerSet = BADNUMVAL;
       
   141 	IAPpreference.iBearer.iIapId = BADNUMVAL;
       
   142 #ifdef __COMMDB_ROHID_SUPPORT__	
       
   143 	isReadOnly = EFalse;
       
   144 #endif
       
   145 	}
       
   146 
       
   147 
       
   148 TInt DBAccess::CheckPreferenceFieldsL()
       
   149 /**
       
   150 Makes sure we have all preference fields set
       
   151 
       
   152   @return ETrue if successful or EFalse
       
   153   */
       
   154 	{
       
   155 	oMsg->Dbg(_L("  Checking preference fields..."));
       
   156 	
       
   157 	if (IAPpreference.iRanking == BADNUMVAL || 
       
   158 		IAPpreference.iDirection == ECommDbConnectionDirectionUnknown ||
       
   159 		IAPpreference.iDialogPref == ECommDbDialogPrefUnknown ||
       
   160 		IAPpreference.iBearer.iBearerSet == BADNUMVAL )
       
   161 		{
       
   162 		iLastError = E_NOTENOUGHDATA;
       
   163 		LastErrorMessage.Set(errorCode[E_NOTENOUGHDATA]);
       
   164 		return EFalse;
       
   165 		}
       
   166 	// now check if the optional field was supplied - if not, zero it
       
   167 	if (IAPpreference.iBearer.iIapId == BADNUMVAL)
       
   168 		IAPpreference.iBearer.iIapId = 0;
       
   169 	
       
   170 	oMsg->Msg(_L("All preference fields valid"));
       
   171 	return ETrue;
       
   172 	}
       
   173 
       
   174 
       
   175 TInt DBAccess::SetPrefValue(TInt index)
       
   176 /**
       
   177 Attempts to open the preference table, or set a particular field
       
   178 
       
   179   @param index Index in the Table
       
   180   @return ETrue if successful or EFalse
       
   181   */
       
   182 	{
       
   183 	TInt valid = EFalse;
       
   184 	TLex temp = TargetCols[ColCount].Value;
       
   185 	TInt tempInt = 0;
       
   186 	
       
   187 	// once we have the ranking value, we can open the database
       
   188 	if (TargetCols[ColCount].Name.Compare(TPtrC(CONNECT_PREF_RANKING)) == 0)
       
   189 		{
       
   190 		if (Evaluate(temp.Val(tempInt)))
       
   191 			{
       
   192 			TPtrC table = tableArray[index];
       
   193 			
       
   194 			ResetPreferenceFields();
       
   195 			IAPpreference.iRanking = tempInt;
       
   196 			
       
   197 			if (access & DBInsert)
       
   198 				{
       
   199 				if (OpenPreferenceTable(table))
       
   200 					valid = ETrue;
       
   201 				}
       
   202 			else if (access & DBUpdate)
       
   203 				{
       
   204 				// open record we want to edit
       
   205 				if (OpenPreferenceTableOnRank(table))
       
   206 					valid = ETrue;
       
   207 				}
       
   208 			}
       
   209 		}
       
   210 	else
       
   211 		{
       
   212 		// set IAP value
       
   213 		if(Evaluate(temp.Val(tempInt)))
       
   214 			{
       
   215 			if (TargetCols[ColCount].Name.Compare(TPtrC(CONNECT_PREF_DIALOG_PREF)) == 0)
       
   216 				{
       
   217 				IAPpreference.iDialogPref = (TCommDbDialogPref)tempInt;
       
   218 				oMsg->Dbg(_L("  Dialog preference set to %d"), IAPpreference.iDialogPref);
       
   219 				valid = ETrue;
       
   220 				}
       
   221 			else if (TargetCols[ColCount].Name.Compare(TPtrC(CONNECT_PREF_IAP)) == 0)
       
   222 				{
       
   223 				IAPpreference.iBearer.iIapId = tempInt;
       
   224 				oMsg->Dbg(_L("  Bearer ID set to %d"), IAPpreference.iBearer.iIapId);
       
   225 				valid = ETrue;
       
   226 				}
       
   227 			else if (TargetCols[ColCount].Name.Compare(TPtrC(CONNECT_PREF_DIRECTION)) == 0)
       
   228 				{
       
   229 				IAPpreference.iDirection = (TCommDbConnectionDirection)tempInt;
       
   230 				oMsg->Dbg(_L("  Bearer Direction set to %d"), IAPpreference.iDirection);
       
   231 				valid = ETrue;
       
   232 				}
       
   233 			else if (TargetCols[ColCount].Name.Compare(TPtrC(CONNECT_PREF_BEARER_SET)) == 0)
       
   234 				{
       
   235 				IAPpreference.iBearer.iBearerSet = tempInt;
       
   236 				oMsg->Dbg(_L("  Bearer Set set to %d"), IAPpreference.iBearer.iBearerSet);
       
   237 				valid = ETrue;
       
   238 				}
       
   239 #ifdef __COMMDB_ROHID_SUPPORT__
       
   240 			else if (TargetCols[ColCount].Name.Compare(TPtrC(COMMDB_READ_ONLY)) == 0)
       
   241 				{
       
   242 				oMsg->Dbg(_L("  ReadOnly set to %d"), tempInt);
       
   243 				valid = ETrue;
       
   244 				}
       
   245 #endif
       
   246 			else
       
   247 				{
       
   248 				iLastError = E_INCORRECTCOLNAME;
       
   249 				LastErrorMessage.Set(errorCode[E_INCORRECTCOLNAME]);
       
   250 				}
       
   251 			}
       
   252 		else
       
   253 			{
       
   254 			iLastError = E_INCORRECTTYPE;
       
   255 			LastErrorMessage.Set(errorCode[E_INCORRECTTYPE]);
       
   256 			}
       
   257 		}
       
   258 	
       
   259 	return valid;
       
   260 	}
       
   261 
       
   262 TInt DBAccess::ConnectionPreferencesTable(TDesC &table)
       
   263 	{
       
   264 	
       
   265 	if (table.Compare(TPtrC(CONNECTION_PREFERENCES)) == 0)
       
   266 		{
       
   267 		return ETrue;
       
   268 		}
       
   269 	
       
   270 	return EFalse;
       
   271 	}