omads/omadsappui/AspSyncUtil/inc/AspUtil.h
branchRCL_3
changeset 25 4f0867e42d62
equal deleted inserted replaced
24:8e7494275d3a 25:4f0867e42d62
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: General utilities 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef ASPUTIL_H
       
    21 #define ASPUTIL_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <ecom.h>
       
    26 #include <eikenv.h> 
       
    27 
       
    28 
       
    29 #include <ApSettingsHandlerUI.h>
       
    30 
       
    31 #include <SyncMLClient.h>    // for RSyncMLSession
       
    32 #include <SyncMLClientDS.h>  // for RSyncMLDataSyncProfile
       
    33 
       
    34 #include <csch_cli.h> // RScheduler
       
    35 
       
    36 
       
    37 #include "AspDefines.h"
       
    38 
       
    39 
       
    40 // CONSTANTS
       
    41 
       
    42 
       
    43 
       
    44 // FORWARD DECLARATIONS
       
    45 class CAspProfile;
       
    46 class CAspProfileList;
       
    47 class CAspContentList;
       
    48 class CAspTask;
       
    49 class CAspFilter;
       
    50 class CAspSchedule;
       
    51 
       
    52 // CLASS DECLARATION
       
    53 
       
    54 
       
    55 /**
       
    56 * TAspParam
       
    57 *
       
    58 * This class is used as general parameter type.
       
    59 */
       
    60 NONSHARABLE_CLASS (TAspParam)
       
    61 	{
       
    62     public:
       
    63 		// calling application id
       
    64 		TInt iApplicationId;
       
    65 
       
    66 		// profile id
       
    67 		TInt iProfileId;
       
    68 
       
    69 		// dialog mode
       
    70 		TInt iMode;
       
    71 
       
    72 		// general id number
       
    73 		TInt iId;
       
    74 
       
    75 		// return value to caller.
       
    76 		TInt iReturnValue;
       
    77 		
       
    78 		// data provider id
       
    79 		TInt  iDataProviderId;
       
    80 		
       
    81 		// sync task id
       
    82 		TInt  iSyncTaskId;
       
    83 		
       
    84 		// sync profile
       
    85 		CAspProfile* iProfile;
       
    86 		
       
    87 		// sync task
       
    88 		CAspTask* iSyncTask;
       
    89 		
       
    90 		// sync filter
       
    91 		CAspFilter* iSyncFilter;
       
    92 		
       
    93 		// session with sync server
       
    94 		RSyncMLSession* iSyncSession;
       
    95 		
       
    96 		// profile list
       
    97 		CAspProfileList* iProfileList;
       
    98 		
       
    99 		// content list
       
   100 		CAspContentList* iContentList;
       
   101 
       
   102 		//auto sync schedule setting
       
   103 		CAspSchedule* iSchedule;
       
   104 		
       
   105 
       
   106     public:
       
   107     	TAspParam(TInt aApplicationId);
       
   108 		TAspParam(TInt aApplicationId, RSyncMLSession* aSyncSession);
       
   109 	};
       
   110 
       
   111 
       
   112 
       
   113 
       
   114 
       
   115 /**
       
   116 * TAspUtil
       
   117 * 
       
   118 * This class contains general utility functions. 
       
   119 */
       
   120 NONSHARABLE_CLASS (TUtil)
       
   121 	{
       
   122     public:
       
   123         static void Panic(TInt aReason);
       
   124 		static void StrCopy(TDes& aTarget, const TDesC& aSource);
       
   125 		static void StrCopy(TDes& aTarget, const TDesC8& aSource);
       
   126 		static void StrCopy(TDes8& aTarget, const TDesC& aSource);
       
   127 		static HBufC* StrConversion(const TDesC& aText);
       
   128 		
       
   129 		static void StrAppend(TDes& aTarget, const TDesC& aSource);
       
   130 		static void StrInsert(TDes& aTarget, const TDesC& aSource);
       
   131 		static void Fill(TDes& aTarget, const TDesC& aOneCharStr, TInt aLength);
       
   132 		static TInt StrToInt(const TDesC& aText, TInt& aNum);
       
   133 		static TInt AddResFileL(const TDesC& aFile);
       
   134 		static TBool IsEmpty(const TDesC& aText);
       
   135 		
       
   136 		static TInt ProviderIdFromAppId(TInt aApplicationId);
       
   137 		static TInt ProviderIdFromAppId(TInt aApplicationId, TBool aOperatorProfile);
       
   138 		static TInt OperatorProviderIdFromAppId(TInt aApplicationId);
       
   139 		static TInt AppIdFromProviderId(TInt aAdapterId);
       
   140 		static TInt AppIdFromOperatorSpecificProviderId(TInt aAdapterId);
       
   141 		static TBool IsValidAppId(TInt aApplicationId);
       
   142 		static TBool IsValidSID(TInt aApplicationId);
       
   143 		
       
   144 		static void GetDateTextL(TDes& aText, TTime aDateTime);
       
   145 		static void GetTimeTextL(TDes& aText, TTime aDateTime);
       
   146 		static HBufC* SyncTimeLC(TTime aLastSync);
       
   147 		static void GetDateTimeTextL(TDes& aText, TTime aDateTime);
       
   148 		static TBool IsToday(TTime aTime);
       
   149 		static TTime ConvertUniversalToHomeTime(const TTime& aUniversalTime);
       
   150 		static void LaunchHelpAppL();
       
   151 		static void LaunchHelpAppL(CEikonEnv* aEikonkEnv);
       
   152 		static TBool SettingEnforcementStateL();
       
   153 		static TBool SettingEnforcementState();
       
   154 		static CDesCArray* NumberConversionLC(CDesCArray* aList);
       
   155 		
       
   156 		
       
   157 
       
   158 
       
   159 #ifdef _DEBUG		
       
   160     public:		
       
   161 		static void GetMandatoryFieldText(TDes& aText, TInt aStatus);
       
   162 		static void Print(const TDesC& aText);
       
   163 		static void Print(const TDesC& aText, TInt aNum);
       
   164 		
       
   165 		static TTime TimeBefore();
       
   166 		static TInt TimeAfter(TTime aBefore);
       
   167 		static void TimeAfter(TTime aBefore, const TDesC& aText);
       
   168 		static void GetApplicationName(TDes& aText, TInt aApplicationId);
       
   169 #endif		
       
   170 	};
       
   171 
       
   172 
       
   173 
       
   174 /**
       
   175 *  TStr contains descriptor operations with range checking.
       
   176 */
       
   177 NONSHARABLE_CLASS (TStr)
       
   178     {
       
   179     public:
       
   180         TStr(const TDesC& aStr);
       
   181        
       
   182     public:
       
   183         TPtrC Mid(TInt aPos, TInt aLen);
       
   184         TPtrC Mid(TInt aPos);
       
   185         TPtrC Left(TInt aPos);
       
   186         TPtrC Right(TInt aPos);
       
   187         TPtrC Trim();
       
   188         TPtrC SubStr(TInt aStartPos, TInt aEndPos);
       
   189         TPtrC SubStrEx(TInt aStartPos, TInt aEndPos);
       
   190         TInt LastPos();
       
   191         TInt Len();
       
   192         TBool Compare(TInt aPos, TChar aChar);
       
   193         TInt Find(TInt aPos, TChar aChar);
       
   194         
       
   195     public:	
       
   196         TInt FirstNonSpace();
       
   197         TInt LastNonSpace();
       
   198         
       
   199     private:
       
   200         // reference to descriptor
       
   201 		const TDesC& iStr;
       
   202     };
       
   203 
       
   204 
       
   205 /**
       
   206 *  TURIParser is used for parsing URI.
       
   207 */
       
   208 NONSHARABLE_CLASS (TURIParser)
       
   209     {
       
   210     public:
       
   211     enum TDefaultPortNumber
       
   212 	    {
       
   213 	    EDefaultHttpPort = 80,
       
   214         EDefaultHttpsPort = 443
       
   215     	};
       
   216 
       
   217     enum TPortNumberRange
       
   218 	    {
       
   219         EMinURIPortNumber = 1,
       
   220         EMaxURIPortNumber = 65535
       
   221     	};
       
   222 
       
   223     public:
       
   224         TURIParser(const TDesC& aStr);
       
   225        
       
   226     public:
       
   227         void GetUriWithoutPort(TDes& aText);
       
   228         void GetUriWithPort(TDes& aText, const TInt aPort);
       
   229         TInt Port();
       
   230         TInt DefaultPort();
       
   231         static TBool IsValidUri(const TDesC& aText);
       
   232         static TBool IsValidBluetoothHostAddress(const TDesC& aText);
       
   233         static TBool IsValidPort(const TInt aPort);
       
   234         
       
   235     private:
       
   236         TPtrC ParseHttp();
       
   237         TPtrC ParseAddress();
       
   238         TPtrC ParseDocument();
       
   239         TInt ParsePort(TInt& aPortNumber);
       
   240         TPtrC ParsePort();
       
   241         
       
   242      private:
       
   243         void GetHttpPos(TInt& aStartPos, TInt& aEndPos);
       
   244         void SkipHttp();
       
   245   
       
   246     private:
       
   247         // reference to original URI text
       
   248 		const TDesC& iOriginalStr;
       
   249 		
       
   250 		// pointer to original URI text
       
   251 		TPtrC iPtr;
       
   252 		
       
   253     };
       
   254 
       
   255 
       
   256 /**
       
   257 *  TFlag contains integer flag operations.
       
   258 */
       
   259 class TFlag
       
   260     {
       
   261     public:
       
   262         /**
       
   263         * C++ default constructor.
       
   264         */
       
   265         TFlag(TUint32& aFlag);
       
   266     public:
       
   267         /**
       
   268         * Turns given bit(s) on.
       
   269         * @since 2.5
       
   270         * @param aValue Bits to be turned on.
       
   271         * @return None.
       
   272         */
       
   273         void SetOn(const TUint32 aValue);
       
   274 
       
   275         /**
       
   276         * Turns given bit(s) off.
       
   277         * @since 2.5
       
   278         * @param aValue Bits to be turned off.
       
   279         * @return None.
       
   280         */
       
   281         void SetOff(const TUint32 aValue);
       
   282 
       
   283         /**
       
   284         * Checks if given bit(s) is/are set.
       
   285         * @since 2.5
       
   286         * @param aValue Bitmap to be checked.
       
   287         * @return None.
       
   288         */
       
   289         TBool IsOn(const TUint32 aValue) const;
       
   290         
       
   291     private:
       
   292 		// reference to flag (integer)
       
   293         TUint32& iFlag;
       
   294     };
       
   295 
       
   296 
       
   297 /**
       
   298 * CAspIdleWait
       
   299 * 
       
   300 * This class is used for waiting synchronously until
       
   301 * active scheduler has completed all pending events.
       
   302 */
       
   303 NONSHARABLE_CLASS (CAspIdleWait) : public CBase
       
   304 	{
       
   305     public:
       
   306         /**
       
   307         * Two-phased constructor.
       
   308         */
       
   309 		static CAspIdleWait* NewL();
       
   310 
       
   311         /**
       
   312         * Destructor.
       
   313         */
       
   314 		virtual ~CAspIdleWait();
       
   315 
       
   316     private:
       
   317 
       
   318         /**
       
   319         * C++ default constructor.
       
   320         */
       
   321 		CAspIdleWait();
       
   322 
       
   323 	public:
       
   324 		/**
       
   325 		* Waits until active schedure has nothing to do.
       
   326 		* @param  None.
       
   327 		* @return None.
       
   328 		*/
       
   329 		static void CAspIdleWait::WaitL();
       
   330 		
       
   331     private:
       
   332         static TInt IdleCallback(TAny* aThisPtr);        
       
   333 
       
   334 	private:
       
   335 		CActiveSchedulerWait iWait;
       
   336 	};
       
   337 
       
   338 
       
   339 
       
   340 
       
   341 /**
       
   342 * MAspActiveCallerObserver
       
   343 *
       
   344 * MAspActiveCallerObserver is for observing CAspActiveCaller.
       
   345 */
       
   346 class MAspActiveCallerObserver
       
   347     {
       
   348     public:
       
   349 	    virtual void HandleActiveCallL(TInt aCallId) = 0;
       
   350     };
       
   351 
       
   352 
       
   353 /**
       
   354 * CAspActiveCaller
       
   355 *
       
   356 * CAspActiveCaller is used for generating a call from active scheduler.
       
   357 */
       
   358 NONSHARABLE_CLASS (CAspActiveCaller) : public CActive
       
   359     {
       
   360     public:
       
   361         /**
       
   362         * Two-phased constructor.
       
   363         */
       
   364         static CAspActiveCaller* NewL(MAspActiveCallerObserver* aObserver);
       
   365 
       
   366 	    /**
       
   367         * Destructor.
       
   368         */
       
   369         virtual ~CAspActiveCaller();
       
   370 
       
   371     private:
       
   372         /**
       
   373         * C++ default constructor.
       
   374         */
       
   375 	    CAspActiveCaller(MAspActiveCallerObserver* aObserver);
       
   376 
       
   377         /**
       
   378         * By default Symbian 2nd phase constructor is private.
       
   379         */
       
   380 	    void ConstructL();
       
   381 
       
   382 	public:
       
   383         /**
       
   384         * Calls observer using active object framework.
       
   385         * @param aCallId.
       
   386 		* @param aMilliseconds Delay before observer is called.
       
   387         * @return None
       
   388         */
       
   389 		void Start(TInt aCallId, TInt aMilliseconds);
       
   390 
       
   391         /**
       
   392         * Make active scheduler call RunL.
       
   393         * @param None
       
   394         * @return None
       
   395         */
       
   396 		void Request();
       
   397 
       
   398     private:
       
   399         /**
       
   400         * From CActive. Called when asynchronous request completes.
       
   401         * @param None
       
   402         * @return None
       
   403         */
       
   404 	    void RunL();
       
   405 
       
   406         /**
       
   407         * From CActive. Cancels asynchronous request.
       
   408         * @param None
       
   409         * @return None
       
   410         */
       
   411 	    void DoCancel();
       
   412         
       
   413     private:
       
   414 		// call that is passed to observer
       
   415 		TInt iCallId;
       
   416 
       
   417 		// timer
       
   418 		RTimer iTimer;
       
   419 
       
   420 		// observer that gets called
       
   421 		MAspActiveCallerObserver* iObserver;
       
   422     };
       
   423 
       
   424 
       
   425 
       
   426 
       
   427 
       
   428 /**
       
   429 * TAspBearerItem 
       
   430 *
       
   431 */
       
   432 NONSHARABLE_CLASS (TAspBearerItem)
       
   433 	{
       
   434 	public:
       
   435 		TInt iBearerType;
       
   436     	TBuf<KBufSize> iBearerName;
       
   437 	};
       
   438 
       
   439 
       
   440 
       
   441 /**
       
   442 * CAspBearerHandler 
       
   443 *
       
   444 * CAspBearerHandler is for constructing list control for selecting
       
   445 * bearer type (internet, bluetooth etc.)
       
   446 */
       
   447 NONSHARABLE_CLASS (CAspBearerHandler) : public CBase
       
   448     {
       
   449     public:
       
   450         /**
       
   451         * Two-phased constructor.
       
   452         */
       
   453         static CAspBearerHandler* NewL(const TAspParam& aParam);
       
   454 
       
   455 	    /**
       
   456         * Destructor.
       
   457         */
       
   458         virtual ~CAspBearerHandler();
       
   459 
       
   460     private:
       
   461         /**
       
   462         * C++ default constructor.
       
   463         */
       
   464 	    CAspBearerHandler(const TAspParam& aParam);
       
   465 
       
   466         /**
       
   467         * By default Symbian 2nd phase constructor is private.
       
   468         */
       
   469 	    void ConstructL();
       
   470 
       
   471 	public:
       
   472 	    /**
       
   473         * Finds out whether bearer type is supported.
       
   474 		* @param aBearer Bearer type.
       
   475         * @return ETrue if supported, EFalse otherwise.
       
   476         */
       
   477 		TBool IsSupported(TInt aBearer);
       
   478 
       
   479 	    /**
       
   480         * Finds out bearer type for list item.
       
   481 		* @param aIndex List index.
       
   482         * @return Bearer type.
       
   483         */
       
   484 		TInt BearerForListIndex(TInt aIndex);
       
   485 
       
   486 		/**
       
   487         * Finds out list position for aBearer.
       
   488 		* @param aBearer.
       
   489         * @return List array index.
       
   490         */
       
   491 		TInt ListIndexForBearer(TInt aBearer);
       
   492 
       
   493 		/**
       
   494         * Creates supported bearer list.
       
   495 		* @param None.
       
   496         * @return None.
       
   497         */
       
   498 		void CreateSupportedBearerListL();
       
   499 
       
   500 	    /**
       
   501         * Finds out default bearer for a device.
       
   502 		* @param None.
       
   503         * @return Bearer type.
       
   504         */
       
   505 		TInt DefaultBearer();
       
   506 
       
   507 	    /**
       
   508         * Gets bearer name string.
       
   509 		* @param aText.
       
   510 		* @param aBearer.
       
   511         * @return None.
       
   512         */
       
   513 		void GetBearerName(TDes& aText, TInt aBearerType);
       
   514 
       
   515 	    /**
       
   516         * Builds array of bearer names for ui list control.
       
   517 		* @param None.
       
   518         * @return Bearer name array.
       
   519         */
       
   520 		CDesCArray* BuildBearerListLC();
       
   521 
       
   522 	    /**
       
   523         * Finds out how many bearer types are supported.
       
   524 		* @param None.
       
   525         * @return Bearer count.
       
   526         */
       
   527 		TInt SupportedBearerCount();
       
   528 		
       
   529 	    /**
       
   530         * Convert asp bearer id to sml beareer id.
       
   531 		* @param aId.
       
   532         * @return Bearer id.
       
   533         */
       
   534 		static TInt SmlBearerId(const TInt aId);
       
   535 
       
   536 	    /**
       
   537         * Convert sml bearer id to asp beareer id.
       
   538 		* @param aId.
       
   539         * @return Bearer id.
       
   540         */
       
   541 		static TInt AspBearerId(const TInt aId);
       
   542 
       
   543     private:
       
   544    		// sync session
       
   545 		RSyncMLSession* iSyncSession;
       
   546 
       
   547 		// list of bearers that can shown in ui list
       
   548 		RArray<TAspBearerItem> iList;
       
   549     };
       
   550 
       
   551 
       
   552 /**
       
   553 * TAspAccessPointItem 
       
   554 *
       
   555 */
       
   556 NONSHARABLE_CLASS (TAspAccessPointItem)
       
   557 	{
       
   558 	public:
       
   559 		TInt  iUid;
       
   560     	TBuf<KBufSize> iName;
       
   561     	
       
   562     	TInt  iUid2;
       
   563 	};
       
   564 
       
   565 
       
   566 
       
   567 /**
       
   568 * CAspAccessPointHandler 
       
   569 *
       
   570 * CAspAccessPointHandler is for setting internet access points.
       
   571 */
       
   572 NONSHARABLE_CLASS (CAspAccessPointHandler) : public CBase
       
   573     {
       
   574     public:
       
   575 	enum TExitMode
       
   576 		{
       
   577 	    EAspDialogSelect,
       
   578 	    EAspDialogCancel,
       
   579 	    EAspDialogExit
       
   580 		};
       
   581 		
       
   582 	// when ap is set to -1, ap is always asked before sync
       
   583     static const TInt KAskAlways = -1;
       
   584 
       
   585 	static const TInt KDefaultConnection = -2;
       
   586     
       
   587     public:
       
   588         /**
       
   589         * Two-phased constructor.
       
   590         */
       
   591         static CAspAccessPointHandler* NewL(const TAspParam& aParam);
       
   592 
       
   593 	    /**
       
   594         * Destructor.
       
   595         */
       
   596         virtual ~CAspAccessPointHandler();
       
   597 
       
   598     private:
       
   599         /**
       
   600         * C++ default constructor.
       
   601         */
       
   602 	    CAspAccessPointHandler(const TAspParam& aParam);
       
   603 
       
   604         /**
       
   605         * By default Symbian 2nd phase constructor is private.
       
   606         */
       
   607 	    void ConstructL();
       
   608 
       
   609     public:
       
   610 	    /**
       
   611         * Displays dialog for selecting one access point.
       
   612 		* @param aItem.
       
   613         * @return ETrue if user selected access point, EFalse otherwise.
       
   614         */
       
   615         TInt ShowApSelectDialogL(TAspAccessPointItem& aItem);
       
   616         
       
   617 	    /**
       
   618         * Gets access point info.
       
   619 		* @param aItem.
       
   620         * @return Error value.
       
   621         */
       
   622 		TInt GetInternetApInfo(TAspAccessPointItem& aItem);
       
   623 
       
   624 	private:
       
   625 	    /**
       
   626         * Gets access point info.
       
   627 		* @param aItem.
       
   628         * @return Error value.
       
   629         */
       
   630 		TInt GetApInfo(TAspAccessPointItem& aItem);
       
   631 
       
   632 	    /**
       
   633         * Gets access point info.
       
   634 		* @param aItem.
       
   635         * @return Error value.
       
   636         */
       
   637 		TInt GetApInfoL(TAspAccessPointItem& aItem);
       
   638 
       
   639         /**
       
   640         * Utility function.
       
   641 		* @param None.
       
   642         * @return Bearer flags.
       
   643         */
       
   644 		TInt BearerFlags();
       
   645 
       
   646 
       
   647     private:
       
   648     
       
   649    		// communications database
       
   650 		CCommsDatabase* iCommDb;
       
   651 
       
   652     	//access point utilities
       
   653     	CApUtils* iApUtil;
       
   654     	
       
   655     	// access point selection utility
       
   656     	CApSelect* iApSelect;
       
   657     	
       
   658     	// dialog parameters
       
   659     	TAspParam* iParam;
       
   660     	
       
   661     };
       
   662 
       
   663 
       
   664 
       
   665 /**
       
   666 * TAspSyncError 
       
   667 *
       
   668 * TAspSyncError is used for error code handling.
       
   669 */
       
   670 NONSHARABLE_CLASS (TAspSyncError)
       
   671     {
       
   672     
       
   673     public:
       
   674         static HBufC* GetSmlErrorTextL(TInt aErrorCode, TInt aTransport);
       
   675         static HBufC* GetSmlErrorText(TInt aErrorCode, TInt aTransport);
       
   676       	static TInt GetSmlErrorValue(TInt aErrorCode);
       
   677         
       
   678 #ifdef _DEBUG        
       
   679     public:
       
   680         static void GetSyncMLErrorText(TDes& aText, TInt aError);
       
   681 #endif
       
   682      
       
   683     };
       
   684 
       
   685 
       
   686 
       
   687 
       
   688 #endif  // ASPUTIL_H
       
   689 
       
   690 
       
   691 // End of file