messagingapp/msgsettings/msgsettingsmw/src/smssettingsprivate.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
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 sms 
       
    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 <csmsaccount.h>
       
    24 #include <smutset.h>
       
    25 #include "debugtraces.h"
       
    26 
       
    27 
       
    28 #include "smssettingsprivate.h"
       
    29 #include "msgsettingsutil.h"
       
    30 
       
    31 
       
    32 const TInt KUniSmsSCStringLength = 50;
       
    33 
       
    34 /**
       
    35  * Message Server session event handler 
       
    36  */
       
    37 class CObserver : public MMsvSessionObserver
       
    38 {
       
    39 public:
       
    40     void HandleSessionEvent(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/,
       
    41                             TAny* /*aArg2*/, TAny* /*aArg3*/)
       
    42     {
       
    43     }
       
    44 
       
    45     void HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/,
       
    46                              TAny* /*aArg2*/, TAny* /*aArg3*/)
       
    47     {
       
    48     }
       
    49 };
       
    50 
       
    51 //two phase constructor
       
    52 SmsSettingsPrivate* SmsSettingsPrivate::NewL()
       
    53 {
       
    54     SmsSettingsPrivate* self = new (ELeave) SmsSettingsPrivate();
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop();
       
    58     return self;
       
    59 }
       
    60 
       
    61 //2nd phase constructor
       
    62 void SmsSettingsPrivate::ConstructL()
       
    63 {
       
    64     createRepositoryL();
       
    65 }
       
    66 
       
    67 //---------------------------------------------------------------
       
    68 // SmsSettingsPrivate::SmsSettingsPrivate
       
    69 // @see header
       
    70 //---------------------------------------------------------------
       
    71 SmsSettingsPrivate::SmsSettingsPrivate()
       
    72 {
       
    73     //do nothing
       
    74 }
       
    75 
       
    76 //---------------------------------------------------------------
       
    77 // SmsSettingsPrivate::~SmsSettingsPrivate
       
    78 // @see header
       
    79 //---------------------------------------------------------------
       
    80 SmsSettingsPrivate::~SmsSettingsPrivate()
       
    81 {
       
    82     //do nothing
       
    83 }
       
    84 
       
    85 //---------------------------------------------------------------
       
    86 // SmsSettingsPrivate::createRepository
       
    87 // @see header
       
    88 //---------------------------------------------------------------
       
    89 void SmsSettingsPrivate::createRepositoryL()
       
    90 {
       
    91     CObserver* pObserver = new (ELeave) CObserver();
       
    92     CleanupStack::PushL(pObserver);
       
    93 
       
    94     TMsvSelectionOrdering ordering;
       
    95     CMsvSession* iMsvSession = CMsvSession::OpenSyncL(*pObserver);
       
    96     CleanupStack::PushL(iMsvSession);
       
    97     CMsvEntry* root = CMsvEntry::NewL(*iMsvSession,
       
    98                                       KMsvRootIndexEntryId,
       
    99                                       ordering);
       
   100     CleanupStack::PushL(root);
       
   101 
       
   102     //then do not create a new entry
       
   103     TMsvId firstId;
       
   104     TRAPD(err, TSmsUtilities::ServiceIdL(*root,firstId));
       
   105     if (err == KErrNotFound)
       
   106     {
       
   107         TMsvEntry entry;
       
   108         entry.iMtm = KUidMsgTypeSMS;
       
   109         entry.iType = KUidMsvServiceEntry;
       
   110         entry.SetReadOnly(EFalse);
       
   111         entry.SetVisible(EFalse);
       
   112         entry.iDate.UniversalTime();
       
   113         entry.iDetails.Set(_L("Nokiatest"));
       
   114 
       
   115         root->SetEntryL(KMsvRootIndexEntryId);
       
   116         root->CreateL(entry);
       
   117 		}
       
   118 		
       
   119         //create a dummy entry
       
   120     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   121 
       
   122     CSmsSettings* smsSettings = CSmsSettings::NewLC();
       
   123 
       
   124     smsAccount->LoadSettingsL(*smsSettings);
       
   125     smsSettings->SetValidityPeriod(ESmsVPMaximum);
       
   126     smsSettings->SetReplyQuoted(ETrue);
       
   127     smsSettings->SetRejectDuplicate(ETrue);
       
   128     smsSettings->SetDelivery(ESmsDeliveryImmediately);
       
   129     smsSettings->SetDeliveryReport(EFalse);
       
   130     smsSettings->SetReplyPath(EFalse);
       
   131     smsSettings->SetMessageConversion((TSmsPIDConversion) 0);
       
   132     smsSettings->SetCanConcatenate(ETrue);
       
   133     smsSettings->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet7Bit);
       
   134     smsSettings->SetValidityPeriodFormat(TSmsFirstOctet::ESmsVPFInteger);
       
   135     smsSettings->SetStatusReportHandling(CSmsSettings::EMoveReportToInboxVisible);
       
   136     smsSettings->SetSpecialMessageHandling(CSmsSettings::EMoveReportToInboxVisible);
       
   137     smsSettings->SetSmsBearer((CSmsSettings::TMobileSmsBearer) 3);
       
   138     smsSettings->SetCommDbAction(CSmsSettings::EStoreToCommDb);
       
   139     smsSettings->SetSmsBearerAction(CSmsSettings::EStoreToCommDb);
       
   140 
       
   141     smsAccount->SaveSettingsL(*smsSettings);
       
   142 
       
   143     CleanupStack::PopAndDestroy(2);
       
   144    	CleanupStack::PopAndDestroy(3);
       
   145 }
       
   146 
       
   147 void SmsSettingsPrivate::setDeliveryReport(TBool report)
       
   148 {
       
   149     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   150     CSmsSettings* smsSettings = CSmsSettings::NewLC();
       
   151 
       
   152     smsAccount->LoadSettingsL(*smsSettings);
       
   153 
       
   154     smsSettings->SetDeliveryReport(report);
       
   155 
       
   156     smsAccount->SaveSettingsL(*smsSettings);
       
   157 
       
   158     CleanupStack::PopAndDestroy(2);
       
   159 }
       
   160 
       
   161 void SmsSettingsPrivate::setCharacterEncoding(TBool status)
       
   162 {
       
   163     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   164     CSmsSettings* smsSettings = CSmsSettings::NewLC();
       
   165 
       
   166     smsAccount->LoadSettingsL(*smsSettings);
       
   167 
       
   168     if (status == EFalse)
       
   169     {
       
   170         smsSettings->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet7Bit);
       
   171     }
       
   172     else
       
   173     {
       
   174         smsSettings->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabetUCS2);
       
   175     }
       
   176 
       
   177     smsAccount->SaveSettingsL(*smsSettings);
       
   178 
       
   179     CleanupStack::PopAndDestroy(2);
       
   180 }
       
   181 
       
   182 void SmsSettingsPrivate::settingsDeliverReportAndCharEncoding(
       
   183                                                               TBool& report,
       
   184                                                               TBool& statusEncoding)
       
   185 {
       
   186     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   187     CSmsSettings* smsSettings = CSmsSettings::NewLC();
       
   188 
       
   189     smsAccount->LoadSettingsL(*smsSettings);
       
   190 
       
   191     report = smsSettings->DeliveryReport();
       
   192 
       
   193     TSmsDataCodingScheme::TSmsAlphabet charSet = smsSettings->CharacterSet();
       
   194 
       
   195     statusEncoding = ETrue;
       
   196     if (charSet == TSmsDataCodingScheme::ESmsAlphabet7Bit)
       
   197     {
       
   198         statusEncoding = EFalse;
       
   199     }
       
   200     CleanupStack::PopAndDestroy(2);
       
   201 }
       
   202 
       
   203 void SmsSettingsPrivate::getAllSMSMessageCenter(
       
   204                                                 RPointerArray<HBufC>& accessPoints,
       
   205                                                 TInt &defaultIndex)
       
   206 {
       
   207     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   208     CSmsSettings* settings = CSmsSettings::NewLC();
       
   209 
       
   210     smsAccount->LoadSettingsL(*settings);
       
   211 
       
   212     //save the default index
       
   213     defaultIndex = settings->DefaultServiceCenter();
       
   214 
       
   215     int totalSMSc = settings->ServiceCenterCount();
       
   216     for (int index = 0; index < totalSMSc; index++)
       
   217     {
       
   218         TPtrC16 name = settings->GetServiceCenter(index).Name();
       
   219         HBufC* accessName = name.AllocL();
       
   220         accessPoints.AppendL(accessName);
       
   221     }
       
   222 
       
   223     CleanupStack::PopAndDestroy(2);
       
   224 
       
   225     return;
       
   226 }
       
   227 
       
   228 void SmsSettingsPrivate::setSMSMessageCenter(int index)
       
   229 {
       
   230     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   231     CSmsSettings* smsSettings = CSmsSettings::NewLC();
       
   232 
       
   233     smsAccount->LoadSettingsL(*smsSettings);
       
   234     smsSettings->SetDefaultServiceCenter(index);
       
   235     smsAccount->SaveSettingsL(*smsSettings);
       
   236 
       
   237     CleanupStack::PopAndDestroy(2);
       
   238 }
       
   239 
       
   240 void SmsSettingsPrivate::editSMSServiceCentre(HBufC* address, HBufC* name,
       
   241                                               TInt index)
       
   242 {
       
   243     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   244     CSmsSettings* smsSettings = CSmsSettings::NewLC();
       
   245 
       
   246     smsAccount->LoadSettingsL(*smsSettings);
       
   247 
       
   248     TInt indexDefault = smsSettings->DefaultServiceCenter();
       
   249     bool flag = false;
       
   250     if (index == indexDefault)
       
   251     {
       
   252         flag = true;
       
   253     }
       
   254 
       
   255     //remove the service center
       
   256     smsSettings->RemoveServiceCenter(index);
       
   257     //add a new service center
       
   258     smsSettings->AddServiceCenterL(name->Des(), address->Des());
       
   259 
       
   260     if (flag == true)
       
   261     {
       
   262         smsSettings->SetDefaultServiceCenter(smsSettings->ServiceCenterCount()
       
   263                 - 1);
       
   264     }
       
   265     smsAccount->SaveSettingsL(*smsSettings);
       
   266 
       
   267     CleanupStack::PopAndDestroy(2);
       
   268 }
       
   269 
       
   270 void SmsSettingsPrivate::addSmsMessageCenter(HBufC* address, HBufC* name)
       
   271 {
       
   272     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   273     CSmsSettings* smsSettings = CSmsSettings::NewLC();
       
   274 
       
   275     smsAccount->LoadSettingsL(*smsSettings);
       
   276     smsSettings->AddServiceCenterL(name->Des(), address->Des());
       
   277     smsAccount->SaveSettingsL(*smsSettings);
       
   278 
       
   279     CleanupStack::PopAndDestroy(2);
       
   280 }
       
   281 
       
   282 void SmsSettingsPrivate::smsCenterNameAndNumber(int index,
       
   283                                                 HBufC** centerNumber,
       
   284                                                 HBufC** centerName)
       
   285 {
       
   286     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   287     CSmsSettings* smsSettings = CSmsSettings::NewLC();
       
   288 
       
   289     smsAccount->LoadSettingsL(*smsSettings);
       
   290 
       
   291     TPtrC16 addr = smsSettings->GetServiceCenter(index).Address();
       
   292     TPtrC16 name = smsSettings->GetServiceCenter(index).Name();
       
   293 
       
   294     (*centerNumber) = addr.AllocL();
       
   295     (*centerName) = name.AllocL();
       
   296 
       
   297     CleanupStack::PopAndDestroy(2);
       
   298 }
       
   299 
       
   300 void SmsSettingsPrivate::setEmailGateway(HBufC* emailGateway)
       
   301 {
       
   302 #ifdef _DEBUG_TRACES_
       
   303     qDebug() << "Enter SmsSettingsPrivate::setEmailGateway" << emailGateway;
       
   304 #endif
       
   305 
       
   306     
       
   307     TBuf<KUniSmsSCStringLength> emailGateWayNumber;
       
   308     
       
   309     MsgSettingsUtil::WriteEmailGatewayOverSmsSettingsL( 
       
   310                              emailGateway->Des(),
       
   311                              ETrue );
       
   312     
       
   313 #ifdef _DEBUG_TRACES_
       
   314     qDebug() << "Exit SmsSettingsPrivate::setEmailGateway";
       
   315 #endif
       
   316 
       
   317     return;
       
   318 }
       
   319 
       
   320 void SmsSettingsPrivate::setEmailSeriveCenterNumber(HBufC* emailNumber)
       
   321 {
       
   322 #ifdef _DEBUG_TRACES_
       
   323     qDebug() << "Enter SmsSettingsPrivate::setEmailSeriveCenterNumber"
       
   324             << emailNumber;
       
   325 #endif
       
   326 
       
   327     
       
   328     MsgSettingsUtil::WriteEmailServiceNumberOverSmsSettingsL(emailNumber->Des(),
       
   329                                                              ETrue );
       
   330     
       
   331 #ifdef _DEBUG_TRACES_
       
   332     qDebug() << "Enter SmsSettingsPrivate::setEmailSeriveCenterNumber";
       
   333 #endif
       
   334 
       
   335     return;
       
   336 }
       
   337 
       
   338 void SmsSettingsPrivate::emailEmailGatewayAndServiceCenterNumber(
       
   339                                                   HBufC** emailGateway,
       
   340                                                   HBufC** serviceNumber)
       
   341 {
       
   342 #ifdef _DEBUG_TRACES_
       
   343     qDebug()
       
   344             << "Enter SmsSettingsPrivate::emailEmailGatewayAndServiceCenterNumber";
       
   345 #endif
       
   346 
       
   347     CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   348     CSmsSettings* smsSettings = CSmsSettings::NewLC();
       
   349 
       
   350     smsAccount->LoadSettingsL(*smsSettings);
       
   351 
       
   352     TBuf<KUniSmsSCStringLength> emailSmscNumber;
       
   353     TBuf<KUniSmsSCStringLength> emailGateWayNumber;
       
   354 
       
   355     TInt readResult = MsgSettingsUtil::ReadEmailOverSmsSettingsL(emailSmscNumber,
       
   356                                                emailGateWayNumber);
       
   357     if (KErrNone == readResult)
       
   358     {
       
   359         // In any otther case we need to show the conf pop-up window
       
   360         if (emailSmscNumber == KNullDesC)
       
   361         {
       
   362             if (smsSettings->DefaultServiceCenter() > 0)
       
   363             {
       
   364                 emailSmscNumber = smsSettings->GetServiceCenter(
       
   365                              smsSettings->DefaultServiceCenter()).Address();
       
   366             }
       
   367             else
       
   368             {
       
   369                 int totalSMSc = smsSettings->ServiceCenterCount();
       
   370                 if (totalSMSc > 0)
       
   371                 {
       
   372                     emailSmscNumber
       
   373                         = smsSettings->GetServiceCenter(0).Address();
       
   374                 }
       
   375             }
       
   376         }
       
   377     }
       
   378     
       
   379     MsgSettingsUtil::WriteEmailServiceNumberOverSmsSettingsL(
       
   380                                                              emailSmscNumber,
       
   381                                                              ETrue);
       
   382     
       
   383     *emailGateway = emailGateWayNumber.AllocL();
       
   384     *serviceNumber = emailSmscNumber.AllocL();
       
   385     
       
   386     CleanupStack::PopAndDestroy(2); //smssetting and smsaccount
       
   387     
       
   388 #ifdef _DEBUG_TRACES_
       
   389     qDebug()
       
   390             << "Enter SmsSettingsPrivate::emailEmailGatewayAndServiceCenterNumber"
       
   391             << serviceNumber << " " << emailGateway;
       
   392 #endif
       
   393 
       
   394     
       
   395 }
       
   396 
       
   397 //eof