messagingapp/msgsettings/settingsview/src/mmssettingsprivate.cpp
changeset 25 84d9eb65b26f
child 37 518b245aa84c
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     1 /*
       
     2  * Copyright (c) 2009 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:  This provides the messaging mw interface for MMS
       
    15  *
       
    16  */
       
    17 
       
    18 #include <commdb.h>
       
    19 #include <commdbconnpref.h>
       
    20 #include <msvapi.h>
       
    21 #include <msvstd.h>
       
    22 #include <msvuids.h>
       
    23 #include <mmsaccount.h>
       
    24 #include <mmssettings.h>
       
    25 #include <mtclreg.h> //For client reg
       
    26 #include <mmsclient.h> //For MMS client
       
    27 #include <mmsconst.h>
       
    28 
       
    29 #include "debugtraces.h"
       
    30 
       
    31 
       
    32 #include "mmssettingprivate.h"
       
    33 
       
    34 /**
       
    35  * Message Server session event handler 
       
    36  */
       
    37 class CEventHandler : public MMsvSessionObserver
       
    38 {
       
    39 public:
       
    40     void HandleSessionEvent(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2,
       
    41                             TAny* aArg3);
       
    42     void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2,
       
    43                              TAny* aArg3);
       
    44 };
       
    45 void CEventHandler::HandleSessionEvent(TMsvSessionEvent /*aEvent*/,
       
    46                                        TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
    47 {
       
    48 }
       
    49 void CEventHandler::HandleSessionEventL(TMsvSessionEvent /*aEvent*/,
       
    50                                         TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
    51 {
       
    52 }
       
    53 
       
    54 //two phase constructor
       
    55 MmsSettingsPrivate* MmsSettingsPrivate::NewL()
       
    56 {
       
    57     MmsSettingsPrivate* self = new (ELeave) MmsSettingsPrivate();
       
    58     CleanupStack::PushL(self);
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop();
       
    61     return self;
       
    62 }
       
    63 
       
    64 //---------------------------------------------------------------
       
    65 // MmsSettingsPrivate::MmsSettingsPrivate
       
    66 // @see header
       
    67 //---------------------------------------------------------------
       
    68 MmsSettingsPrivate::MmsSettingsPrivate()
       
    69 {
       
    70     //do nothing
       
    71 }
       
    72 
       
    73 //2nd phase constructor
       
    74 void MmsSettingsPrivate::ConstructL()
       
    75 {
       
    76     //for debug only
       
    77     //createRepositoryL();    
       
    78 }
       
    79 
       
    80 //---------------------------------------------------------------
       
    81 // MmsSettingsPrivate::~MmsSettingsPrivate
       
    82 // @see header
       
    83 //---------------------------------------------------------------
       
    84 MmsSettingsPrivate::~MmsSettingsPrivate()
       
    85 {
       
    86     // do nothing
       
    87 }
       
    88 
       
    89 //---------------------------------------------------------------
       
    90 // MmsSettingsPrivate::createRepository
       
    91 // @see header
       
    92 //---------------------------------------------------------------
       
    93 void MmsSettingsPrivate::createRepositoryL()
       
    94 {
       
    95     CEventHandler* pObserver = new (ELeave) CEventHandler();
       
    96     CleanupStack::PushL(pObserver);
       
    97 
       
    98     CMsvSession* iMsvSession = CMsvSession::OpenSyncL(*pObserver);
       
    99     CleanupStack::PushL(iMsvSession);
       
   100 
       
   101     CMmsSettings* mmsSetting = CMmsSettings::NewL();
       
   102     CleanupStack::PushL(mmsSetting);
       
   103 
       
   104     mmsSetting->LoadSettingsL();
       
   105 
       
   106     TMsvId entryToBeKilled = KMsvNullIndexEntryId;
       
   107     // Get access to root index
       
   108     CMsvEntry* cEntry = iMsvSession->GetEntryL(KMsvRootIndexEntryId);
       
   109     CleanupStack::PushL(cEntry);
       
   110 
       
   111     entryToBeKilled = mmsSetting->Service();
       
   112     cEntry->SetSortTypeL(TMsvSelectionOrdering(KMsvNoGrouping,
       
   113                                                EMsvSortByNone,
       
   114                                                ETrue));
       
   115     if (entryToBeKilled == KMsvNullIndexEntryId)
       
   116     {
       
   117         mmsSetting->CreateNewServiceL(*iMsvSession);
       
   118     }
       
   119 
       
   120     CleanupStack::PopAndDestroy(); // cEntry          
       
   121 
       
   122     mmsSetting->SetReceivingModeHome(EMmsReceivingAutomatic);
       
   123     mmsSetting->SetReceivingModeForeign(EMmsReceivingAutomatic);
       
   124 
       
   125     mmsSetting->SaveSettingsL();
       
   126 
       
   127     CleanupStack::PopAndDestroy(3); // settings    
       
   128 }
       
   129 
       
   130 void MmsSettingsPrivate::setMMSRetrieval(MsgSettingEngine::MmsRetrieval aRetrieval)
       
   131 {
       
   132     CEventHandler* pObserver = new (ELeave) CEventHandler();
       
   133     CleanupStack::PushL(pObserver);
       
   134 
       
   135     CMsvSession* mMsvSession = CMsvSession::OpenSyncL(*pObserver);
       
   136     CleanupStack::PushL(mMsvSession);
       
   137 
       
   138     CClientMtmRegistry* mMtmReg = CClientMtmRegistry::NewL(*mMsvSession);
       
   139     CleanupStack::PushL(mMtmReg);
       
   140     
       
   141     CMmsClientMtm* mMmsClient = static_cast<CMmsClientMtm*> 
       
   142                                       (mMtmReg->NewMtmL(KUidMsgTypeMultimedia));
       
   143     CleanupStack::PushL(mMmsClient);
       
   144     
       
   145     CMmsSettings* mMmsSetting = CMmsSettings::NewL();
       
   146     CleanupStack::PushL(mMmsSetting);
       
   147 
       
   148     //Load settings
       
   149     mMmsClient->RestoreSettingsL();
       
   150     mMmsSetting->CopyL( mMmsClient->MmsSettings() );
       
   151 
       
   152     //do your operation
       
   153     TMmsReceivingMode receveMode = EMmsReceivingAutomatic;
       
   154 
       
   155     if (aRetrieval == MsgSettingEngine::Maual)
       
   156         receveMode = EMmsReceivingManual;
       
   157     else if (aRetrieval == MsgSettingEngine::Off)
       
   158         receveMode = EMmsReceivingPostpone;
       
   159     else if (aRetrieval == MsgSettingEngine::No)
       
   160         receveMode = EMmsReceivingReject;
       
   161 
       
   162     if (aRetrieval == MsgSettingEngine::AlwaysAutomatic)
       
   163         {
       
   164         mMmsSetting->SetReceivingModeForeign(receveMode);
       
   165         }
       
   166     else
       
   167         {
       
   168         mMmsSetting->SetReceivingModeForeign(EMmsReceivingManual);
       
   169         }
       
   170 
       
   171     mMmsSetting->SetReceivingModeHome(receveMode);
       
   172     
       
   173     //save the settings
       
   174     mMmsClient->SetSettingsL( *mMmsSetting );
       
   175     //TODO:User Input should be blocked when save is being done
       
   176     //This should be called as this takes care of automatic 
       
   177     //downloading of messages upon change of retrieval mode
       
   178     mMmsClient->StoreSettingsL();
       
   179 
       
   180     CleanupStack::PopAndDestroy(5);
       
   181 }
       
   182 
       
   183 void MmsSettingsPrivate::setAnonymousMessages(TBool aAnonymous)
       
   184 {
       
   185     CMmsAccount* mMmsAccount = CMmsAccount::NewL();
       
   186     CleanupStack::PushL(mMmsAccount);
       
   187 
       
   188     CMmsSettings* mMmsSetting = CMmsSettings::NewL();
       
   189     CleanupStack::PushL(mMmsSetting);
       
   190 
       
   191     mMmsAccount->LoadSettingsL(*mMmsSetting);
       
   192 
       
   193     //do your operation
       
   194     mMmsSetting->SetAcceptAnonymousMessages(aAnonymous);
       
   195 
       
   196     //save the settings
       
   197     mMmsAccount->SaveSettingsL(*mMmsSetting);
       
   198     CleanupStack::PopAndDestroy(2);
       
   199 }
       
   200 
       
   201 void MmsSettingsPrivate::setReceiveMMSAdverts(TBool aReceiveAdvert)
       
   202 {
       
   203     CMmsAccount* mMmsAccount = CMmsAccount::NewL();
       
   204     CleanupStack::PushL(mMmsAccount);
       
   205 
       
   206     CMmsSettings* mMmsSetting = CMmsSettings::NewL();
       
   207     CleanupStack::PushL(mMmsSetting);
       
   208 
       
   209     mMmsAccount->LoadSettingsL(*mMmsSetting);
       
   210 
       
   211     //do your operation
       
   212     mMmsSetting->SetAcceptAdvertisementMessages(aReceiveAdvert);
       
   213 
       
   214     //save the settings
       
   215     mMmsAccount->SaveSettingsL(*mMmsSetting);
       
   216     CleanupStack::PopAndDestroy(2);
       
   217 }
       
   218 
       
   219 void MmsSettingsPrivate::advanceMmsSettings(
       
   220                                             MsgSettingEngine::MmsRetrieval& aRetrieval,
       
   221                                             TBool& aAnonymousStatus,
       
   222                                             TBool& aMmsAdvertsStatus)
       
   223 {
       
   224     CMmsAccount* mMmsAccount = CMmsAccount::NewL();
       
   225     CleanupStack::PushL(mMmsAccount);
       
   226 
       
   227     CMmsSettings* mMmsSetting = CMmsSettings::NewL();
       
   228     CleanupStack::PushL(mMmsSetting);
       
   229 
       
   230     mMmsAccount->LoadSettingsL(*mMmsSetting);
       
   231 
       
   232     TMmsReceivingMode receveMode = mMmsSetting->ReceivingModeHome();
       
   233     
       
   234     if (receveMode == EMmsReceivingManual)
       
   235         aRetrieval = MsgSettingEngine::Maual;
       
   236     else if (receveMode == EMmsReceivingPostpone)
       
   237         aRetrieval = MsgSettingEngine::Off;
       
   238     else if (receveMode == EMmsReceivingReject)
       
   239         aRetrieval = MsgSettingEngine::No;
       
   240 
       
   241     receveMode = mMmsSetting->ReceivingModeForeign();
       
   242     if (receveMode == EMmsReceivingAutomatic)
       
   243         {
       
   244         aRetrieval = MsgSettingEngine::AlwaysAutomatic;
       
   245         }
       
   246 
       
   247     aAnonymousStatus = mMmsSetting->AcceptAnonymousMessages();
       
   248 
       
   249     aMmsAdvertsStatus = mMmsSetting->AcceptAdvertisementMessages();
       
   250 
       
   251     CleanupStack::PopAndDestroy(2);
       
   252 }
       
   253 
       
   254 //---------------------------------------------------------------
       
   255 // SmsSettings::iAPSelector
       
   256 // @see header
       
   257 //---------------------------------------------------------------
       
   258 void MmsSettingsPrivate::getAllAccessPoints(
       
   259                                             RPointerArray<HBufC>& aAccessPoints,
       
   260                                             TInt& aDefaultIndex)
       
   261 {
       
   262 #ifdef _DEBUG_TRACES_
       
   263 		qDebug() << "Enter MmsSettingsPrivate::getAllAccessPoints: Index= " << aDefaultIndex;
       
   264 #endif
       
   265 
       
   266     CCommsDatabase *db;
       
   267     CCommsDbTableView *view;
       
   268     TInt result, err;
       
   269 
       
   270     //select the access point and store it in cenrep
       
   271     CMmsAccount* mmsAccount = CMmsAccount::NewL();
       
   272     CleanupStack::PushL(mmsAccount);
       
   273 
       
   274     CMmsSettings* mMmsSetting = CMmsSettings::NewL();
       
   275     CleanupStack::PushL(mMmsSetting);
       
   276 
       
   277     mmsAccount->LoadSettingsL(*mMmsSetting);
       
   278 
       
   279     //select the default access point
       
   280     TInt32 defaultId = mMmsSetting->AccessPoint(0);
       
   281 
       
   282     TBuf<KCommsDbSvrMaxColumnNameLength> iapName;
       
   283     TBuf<KCommsDbSvrMaxFieldLength> serviceType;
       
   284     TUint32 iapId = 0;
       
   285     db = CCommsDatabase::NewL(EDatabaseTypeIAP);
       
   286     CleanupStack::PushL(db);
       
   287     view = db->OpenTableLC(TPtrC(IAP));
       
   288 
       
   289     // Walk through records
       
   290     result = view->GotoFirstRecord();
       
   291     TInt recordIndex = 0;
       
   292     while (result == KErrNone)
       
   293     {
       
   294         TRAP(err, view->ReadTextL(TPtrC(COMMDB_NAME), iapName));
       
   295         TRAP(err, view->ReadTextL(TPtrC(IAP_SERVICE_TYPE), serviceType));
       
   296 #ifdef __WINSCW__
       
   297         if (serviceType.CompareF(TPtrC(LAN_SERVICE)) == 0)
       
   298         {
       
   299             HBufC* accessPointName = iapName.Alloc();
       
   300             aAccessPoints.AppendL(accessPointName);
       
   301             TRAP(err, view->ReadUintL(TPtrC(COMMDB_ID), iapId));
       
   302             
       
   303             // check to see if this is default set for MMsAccesspoint
       
   304             if (defaultId == iapId)
       
   305             {
       
   306                aDefaultIndex = recordIndex;
       
   307             }
       
   308             recordIndex++;
       
   309         }
       
   310 #else
       
   311         if(serviceType.CompareF(TPtrC(OUTGOING_GPRS)) == 0)
       
   312         {
       
   313             HBufC* accessPointName = iapName.Alloc();
       
   314             aAccessPoints.AppendL(accessPointName);
       
   315             TRAP(err, view->ReadUintL(TPtrC(COMMDB_ID), iapId));
       
   316             
       
   317             // check to see if this is default set for MMsAccesspoint
       
   318             if (defaultId == iapId)
       
   319             {
       
   320                 aDefaultIndex = recordIndex;
       
   321             }
       
   322         recordIndex++;
       
   323         }
       
   324 #endif           
       
   325         TRAP(err, result = view->GotoNextRecord());
       
   326     }
       
   327     CleanupStack::PopAndDestroy(4); // nMmsSettings, db,view
       
   328 #ifdef _DEBUG_TRACES_
       
   329 		qDebug() << "Exit MmsSettingsPrivate::getAllAccessPoints: Index=" 
       
   330 	          << aDefaultIndex
       
   331 	          << "\n";
       
   332 #endif
       
   333 
       
   334 }
       
   335 
       
   336 //---------------------------------------------------------------
       
   337 // MmsSettingsPrivate::setMMSAccesspoint
       
   338 // @see header
       
   339 //---------------------------------------------------------------
       
   340 void MmsSettingsPrivate::setMMSAccesspoint(TInt& aDefaultIndex)
       
   341 {
       
   342 #ifdef _DEBUG_TRACES_
       
   343 		qDebug() << "Enter MmsSettingsPrivate::setMMSAccesspoint: Index=" 
       
   344 	          << aDefaultIndex
       
   345 	          << "\n";
       
   346 #endif
       
   347 
       
   348 	          
       
   349     //select the access point and store it in cenrep
       
   350     CMmsAccount* mmsAccount = CMmsAccount::NewL();
       
   351     CleanupStack::PushL(mmsAccount);
       
   352 
       
   353     CMmsSettings* mMmsSetting = CMmsSettings::NewL();
       
   354     CleanupStack::PushL(mMmsSetting);
       
   355 
       
   356     mmsAccount->LoadSettingsL(*mMmsSetting);
       
   357 
       
   358     CCommsDatabase *db;
       
   359     CCommsDbTableView *view;
       
   360     TInt result, err;
       
   361 
       
   362     TCommDbConnPref prefs;
       
   363 
       
   364     TBuf<KCommsDbSvrMaxColumnNameLength> iapName;
       
   365     TBuf<KCommsDbSvrMaxFieldLength> serviceType;
       
   366     TUint32 iapId = 0;
       
   367     db = CCommsDatabase::NewL(EDatabaseTypeIAP);
       
   368     CleanupStack::PushL(db);
       
   369     view = db->OpenTableLC(TPtrC(IAP));
       
   370 
       
   371     // Walk through records
       
   372     result = view->GotoFirstRecord();
       
   373     TInt serviceCounter = 0;
       
   374     while (result == KErrNone)
       
   375     {
       
   376         TRAP(err, view->ReadTextL(TPtrC(COMMDB_NAME), iapName));
       
   377         TRAP(err, view->ReadTextL(TPtrC(IAP_SERVICE_TYPE), serviceType));
       
   378 
       
   379 #ifdef __WINSCW__
       
   380         if (serviceType.CompareF(TPtrC(LAN_SERVICE)) == 0 && serviceCounter
       
   381                 == aDefaultIndex)
       
   382         {
       
   383             TRAP(err, view->ReadUintL(TPtrC(COMMDB_ID), iapId));
       
   384             prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   385             prefs.SetDirection(ECommDbConnectionDirectionOutgoing);
       
   386             prefs.SetIapId(iapId);
       
   387 
       
   388             while (mMmsSetting->AccessPointCount())
       
   389             {
       
   390                 mMmsSetting->DeleteAccessPointL(0);
       
   391             }
       
   392             if (iapId != 0)
       
   393             {
       
   394 #ifdef _DEBUG_TRACES_
       
   395 		        qDebug() << "Set MMs Accesspoint IAP ID:"
       
   396             	         << iapId;
       
   397 #endif
       
   398 
       
   399 
       
   400                 mMmsSetting->AddAccessPointL(iapId, 0);
       
   401             }
       
   402             mmsAccount->SaveSettingsL(*mMmsSetting);
       
   403             serviceCounter++;
       
   404         }
       
   405         else if (serviceType.CompareF(TPtrC(LAN_SERVICE)) == 0)
       
   406         	{
       
   407         		serviceCounter++;
       
   408         	}
       
   409 #else
       
   410         if(serviceType.CompareF(TPtrC(OUTGOING_GPRS)) == 0 &&
       
   411                 serviceCounter == aDefaultIndex)
       
   412         {
       
   413             TRAP(err, view->ReadUintL(TPtrC(COMMDB_ID), iapId));
       
   414             prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   415             prefs.SetDirection(ECommDbConnectionDirectionOutgoing);
       
   416             prefs.SetIapId(iapId);
       
   417 
       
   418             while ( mMmsSetting->AccessPointCount() )
       
   419             {
       
   420 #ifdef _DEBUG_TRACES_
       
   421                 qDebug() << "Set MMs Accesspoint IAP ID:"
       
   422             	         << iapId;
       
   423 #endif
       
   424 
       
   425                 mMmsSetting->DeleteAccessPointL( 0 );
       
   426             }
       
   427             if ( iapId != 0 )
       
   428             {
       
   429                 mMmsSetting->AddAccessPointL(iapId, 0);
       
   430             }
       
   431             mmsAccount->SaveSettingsL(*mMmsSetting);
       
   432             serviceCounter++;
       
   433         }
       
   434         else if(serviceType.CompareF(TPtrC(OUTGOING_GPRS)) == 0)
       
   435         {
       
   436         		serviceCounter++;
       
   437         }        	
       
   438 #endif          
       
   439         TRAP(err, result = view->GotoNextRecord());
       
   440     }
       
   441 
       
   442     CleanupStack::PopAndDestroy(4); // mMmsSetting, db,view
       
   443 #ifdef _DEBUG_TRACES_
       
   444 		qDebug() << "Exit MmsSettingsPrivate::setMMSAccesspoint: Index=" 
       
   445 	          << aDefaultIndex
       
   446 	          << "\n";
       
   447 #endif
       
   448 
       
   449 }
       
   450 
       
   451 //eof
       
   452