idlefw/plugins/shortcutplugin/src/caiscutsettingsitem.cpp
branchRCL_3
changeset 9 d0529222e3f0
parent 4 1a2a00e78665
child 10 5ef93ea513cb
child 18 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 9:d0529222e3f0
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Class for shortcut setting items
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <StringLoader.h>
       
    21 #include <centralrepository.h>
       
    22 #include <msvuids.h>        // For KMsvRootIndexEntryIdValue
       
    23 #include <SenduiMtmUids.h>
       
    24 #include <uri16.h>                  // For TUriParser16
       
    25 #include <aiscutsettingsres.rsg>
       
    26 #include <aiscuttexts.rsg>
       
    27 #include "caiscutsettingsitem.h"
       
    28 #include "caiscutsettingsmodel.h"
       
    29 #include "aiscutpluginprivatecrkeys.h"
       
    30 #include "taiscutparser.h"
       
    31 #include "aiscutdefs.h"
       
    32 #include "aiscutsettings.hrh"
       
    33 #include "aidefaultshortcut.h"
       
    34 #include "debug.h"
       
    35 
       
    36 const TInt KMaxBufSize = 250;
       
    37 // ======== MEMBER FUNCTIONS ========
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 
       
    43 CAiScutSettingsItem::CAiScutSettingsItem(
       
    44     CAiScutSettingsModel&   aModel,
       
    45     TInt                    aIndex,
       
    46     TUint32                 aKey)
       
    47     : iModel(aModel)
       
    48         , iIndex(aIndex)
       
    49         , iKey(aKey)
       
    50 {
       
    51 }
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CAiScutSettingsItem::ReadL(CRepository* aRepository)
       
    57 {
       
    58     if( !aRepository )
       
    59        {
       
    60           return;
       
    61        }
       
    62 
       
    63     HBufC* buffer = HBufC::NewLC(NCentralRepositoryConstants::KMaxUnicodeStringLength);
       
    64     TPtr bufferPtr = buffer->Des();
       
    65 
       
    66     // try user key first.
       
    67     TUint32 key = iKey & KScutBitMaskThemeDefault;
       
    68     TInt err = aRepository->Get(key, bufferPtr);
       
    69 
       
    70     if (err == KErrNone)
       
    71     {
       
    72         err = ParseValueL(bufferPtr);
       
    73     }
       
    74 
       
    75     if (err == KErrNone)
       
    76     {
       
    77         iKey = key;
       
    78     }
       
    79     else
       
    80     {
       
    81         // if no user key try default key then.
       
    82         key = iKey | KScutFlagBitThemeDefault;
       
    83         err = aRepository->Get(key, bufferPtr);
       
    84         if (err == KErrNone)
       
    85         {
       
    86             err = ParseValueL(bufferPtr);
       
    87         }
       
    88 
       
    89     }
       
    90 
       
    91     if (err != KErrNone ||
       
    92         (iType == EAiScutSettingTypeApplication && iModel.IsHidden(iUid)))
       
    93     {
       
    94         HBufC* buf = HBufC::NewLC(NCentralRepositoryConstants::KMaxUnicodeStringLength);        
       
    95         TPtr bufPtr = buf->Des();
       
    96         HBufC* caption = NULL;
       
    97 
       
    98         // Get the default shortcut uid for key 'key' 
       
    99         iType = EAiScutSettingTypeApplication;
       
   100         TAiDefaultShortcut::GetDefaultShortcut(key, iUid, bufPtr);
       
   101 
       
   102         err = iModel.GetAppCaption(iUid, bufPtr);
       
   103         if (err == KErrNone)
       
   104         {
       
   105             caption = bufPtr.AllocLC();
       
   106             CreateListBoxLineL(*caption);
       
   107             CleanupStack::PopAndDestroy(caption);
       
   108         }
       
   109 
       
   110         CleanupStack::PopAndDestroy(buf);
       
   111 
       
   112     }
       
   113 
       
   114     delete iValue;
       
   115     iValue = NULL;
       
   116     iValue = bufferPtr.AllocL();
       
   117 
       
   118     CleanupStack::PopAndDestroy(buffer);
       
   119 
       
   120  }
       
   121 
       
   122  // ---------------------------------------------------------------------------
       
   123  //
       
   124  // ---------------------------------------------------------------------------
       
   125  //
       
   126  TInt CAiScutSettingsItem::Save(CRepository* aRepository)
       
   127  {
       
   128 
       
   129     if( !aRepository )
       
   130     {
       
   131         return KErrGeneral;
       
   132     }
       
   133 
       
   134     iKey = iKey & KScutBitMaskThemeDefault;
       
   135 
       
   136     TInt err = aRepository->Set(iKey, Value());
       
   137 
       
   138     return err;
       
   139  }
       
   140 
       
   141 
       
   142  // ---------------------------------------------------------------------------
       
   143  // Constructs a new settings item leaving it on the cleanup stack.
       
   144  // ---------------------------------------------------------------------------
       
   145  //
       
   146  CAiScutSettingsItem* CAiScutSettingsItem::NewLC(
       
   147     CAiScutSettingsModel&   aModel,
       
   148     TInt                    aIndex,
       
   149     TUint32                 aKey)
       
   150  {
       
   151     CAiScutSettingsItem* self = new (ELeave) CAiScutSettingsItem(
       
   152         aModel, aIndex, aKey);
       
   153 
       
   154     CleanupStack::PushL(self);
       
   155     self->ConstructL();
       
   156     return self;
       
   157  }
       
   158 
       
   159  // ---------------------------------------------------------------------------
       
   160  //
       
   161  // ---------------------------------------------------------------------------
       
   162  //
       
   163  CAiScutSettingsItem* CAiScutSettingsItem::NewLC(
       
   164     CAiScutSettingsModel&   aModel,
       
   165     TInt                    aIndex,
       
   166     TUint32                 aKey,
       
   167     const TDesC&            aValue)
       
   168  {
       
   169     CAiScutSettingsItem* self = new (ELeave) CAiScutSettingsItem(
       
   170         aModel, aIndex, aKey);
       
   171 
       
   172     CleanupStack::PushL(self);
       
   173     self->ConstructL(aValue);
       
   174     return self;
       
   175  }
       
   176 
       
   177  // ---------------------------------------------------------------------------
       
   178  //
       
   179  // ---------------------------------------------------------------------------
       
   180  //
       
   181  void CAiScutSettingsItem::ConstructL()
       
   182  {
       
   183 
       
   184  }
       
   185 
       
   186  // ---------------------------------------------------------------------------
       
   187  //
       
   188  // ---------------------------------------------------------------------------
       
   189  //
       
   190  void CAiScutSettingsItem::ConstructL(const TDesC& aValue)
       
   191  {
       
   192      ParseValueL(aValue);
       
   193      iValue = aValue.AllocL();
       
   194  }
       
   195 
       
   196  // ---------------------------------------------------------------------------
       
   197  //
       
   198  // ---------------------------------------------------------------------------
       
   199  //
       
   200  CAiScutSettingsItem::~CAiScutSettingsItem()
       
   201  {
       
   202     delete iValue;
       
   203     delete iListBoxLine;
       
   204  }
       
   205 
       
   206  // ---------------------------------------------------------------------------
       
   207  //
       
   208  // ---------------------------------------------------------------------------
       
   209  //
       
   210  TInt CAiScutSettingsItem::ParseValueL(const TDesC& aValue)
       
   211  {
       
   212     HBufC* caption = NULL;
       
   213     TInt err = KErrNone;
       
   214     HBufC* buf = HBufC::NewLC(KMaxBufSize);
       
   215     TPtr bufPtr = buf->Des();
       
   216 
       
   217     TAiScutParser parser;
       
   218     parser.Parse(aValue);
       
   219 
       
   220     TShortcutType type = parser.Type();
       
   221 
       
   222     iUid = parser.Uid();
       
   223     iType = EAiScutSettingTypeApplication;
       
   224 
       
   225     switch (type)
       
   226     {
       
   227         case EScutApplication:
       
   228         case EScutApplicationWithParams:
       
   229         case EScutApplicationView:
       
   230         case EScutLogsMissedCallsView:
       
   231         case EScutLogsDialledCallsView:
       
   232         case EScutLogsReceivedCallsView:
       
   233         case EScutLogsMainView:
       
   234             err = iModel.GetAppCaption(iUid, bufPtr);
       
   235             if (err == KErrNone)
       
   236             {
       
   237                 caption = bufPtr.AllocLC();
       
   238             }
       
   239             break;
       
   240 
       
   241         case EScutNewMessage:
       
   242             caption = StringLoader::LoadLC(
       
   243                 R_SCUT_SETTINGS_NEW_MSG, iModel.Env());
       
   244             break;
       
   245 
       
   246         case EScutNewEmail:
       
   247             caption = StringLoader::LoadLC(
       
   248                 R_SCUT_SETTINGS_NEW_EMAIL, iModel.Env());
       
   249             break;
       
   250 
       
   251         #ifdef __SYNCML_DS_EMAIL
       
   252             case EScutNewSyncMLMail:
       
   253                 caption = StringLoader::LoadLC(
       
   254                     R_SCUT_SETTINGS_NEW_SYNCML_MAIL, iModel.Env());
       
   255                 break;
       
   256         #endif
       
   257 
       
   258         case EScutNewPostcard:
       
   259             caption = StringLoader::LoadLC(
       
   260                 R_SCUT_SETTINGS_NEW_POSTCARD, iModel.Env());
       
   261             break;
       
   262 
       
   263         case EScutNewAudioMsg:
       
   264             caption = StringLoader::LoadLC(
       
   265                 R_SCUT_SETTINGS_NEW_AUDIO_MSG, iModel.Env());
       
   266             break;
       
   267 
       
   268         case EScutNewMsgType:
       
   269             caption = StringLoader::LoadLC(
       
   270                 R_SCUT_SETTINGS_SELECT_MSG_TYPE, iModel.Env());
       
   271             break;
       
   272 
       
   273         case EScutChangeTheme:
       
   274             caption = StringLoader::LoadLC(
       
   275                 R_SCUT_SETTINGS_CHANGE_THEME, iModel.Env());
       
   276             break;
       
   277 
       
   278         case EScutMailbox:
       
   279             {
       
   280             err = KErrNotFound;
       
   281             // Parse the mailbox id from the definition
       
   282             TLex lex(parser.Get(EScutDefParamValue));
       
   283             TInt mailboxId = KErrNone;
       
   284             lex.Val(mailboxId);
       
   285 
       
   286             CMsvSession* msvSession = CMsvSession::OpenAsObserverL(*iModel.AppList());
       
   287             CleanupStack::PushL(msvSession);
       
   288 
       
   289             CMsvEntry* rootEntry = msvSession->GetEntryL(KMsvRootIndexEntryIdValue);
       
   290             CleanupStack::PushL(rootEntry);          
       
   291             
       
   292             // Searching the mailbox name
       
   293             for (TInt i = rootEntry->Count() - 1; i >= 0; --i)
       
   294             {
       
   295                 const TMsvEntry& tentry = (*rootEntry)[i];
       
   296 
       
   297                 if ((tentry.iMtm == KSenduiMtmImap4Uid || tentry.iMtm == KSenduiMtmPop3Uid) &&
       
   298                     tentry.Id() == mailboxId)
       
   299                 {
       
   300                     caption = tentry.iDetails.AllocL();
       
   301                     err = KErrNone;
       
   302                     break;
       
   303                 }
       
   304             }
       
   305             CleanupStack::PopAndDestroy(rootEntry);
       
   306             CleanupStack::PopAndDestroy(msvSession);
       
   307             if ( caption )
       
   308                 {
       
   309                 CleanupStack::PushL( caption );
       
   310                 }
       
   311             }
       
   312             break;
       
   313 
       
   314         case EScutNoEffect:
       
   315             caption = StringLoader::LoadLC(
       
   316                 R_SCUT_SETTINGS_NO_EFFECT, iModel.Env());
       
   317             break;
       
   318 
       
   319         case EScutConnectivityStatusView:
       
   320             caption = StringLoader::LoadLC(
       
   321                 R_SCUT_SETTINGS_CONNECTIVITY_STATUS, iModel.Env());
       
   322             break;
       
   323 
       
   324         case EScutApplicationManagerView:
       
   325             caption = StringLoader::LoadLC(
       
   326                 R_SCUT_SETTINGS_APPMNGR, iModel.Env());
       
   327             break;
       
   328 
       
   329         case EScutBookmark:
       
   330             {
       
   331             // aValue = "localapp:0x102750fb?bkm=0x12345678"
       
   332             iUid = KScutSettingsDllUid;
       
   333             iType = EAiScutSettingTypeBookmark;
       
   334             TUid uid = parser.ParseUid(parser.Get(EScutDefParamValue));
       
   335             TRAP(err, iModel.GetBkmCaptionL(uid, bufPtr));
       
   336             if (err == KErrNone)
       
   337             {
       
   338                 caption = bufPtr.AllocLC();
       
   339 
       
   340                 __PRINT( __DBG_FORMAT( "XAI: CAiScutSettingsItem bkm uid = 0x%x caption = '%S' "),
       
   341                 uid.iUid, caption);
       
   342             }
       
   343             }
       
   344             break;
       
   345 
       
   346         case EScutWebAddress:
       
   347         default:
       
   348             // treat unknown shortcuts as typed urls.
       
   349             iUid.iUid = 0;
       
   350             iType = EAiScutSettingTypeUrl;
       
   351         HBufC* tmp = HBufC::NewLC( aValue.Length() );
       
   352         TPtr tmpPtr = tmp->Des();
       
   353         TInt err = parser.CustomTitle( tmpPtr );
       
   354 
       
   355         if ( err != KErrNone || tmp->Length() <= 0 )
       
   356             {
       
   357             CleanupStack::PopAndDestroy( tmp );
       
   358             caption = aValue.AllocLC();
       
   359             }
       
   360         else
       
   361             {
       
   362             caption = tmp;
       
   363             }
       
   364             break;
       
   365         }
       
   366 
       
   367     if (caption)
       
   368     {
       
   369         CreateListBoxLineL(*caption);
       
   370         CleanupStack::PopAndDestroy(caption);
       
   371     }
       
   372 
       
   373     CleanupStack::PopAndDestroy(buf);
       
   374     return err;
       
   375  }
       
   376 
       
   377  // ---------------------------------------------------------------------------
       
   378  // Changes the setting item target application.
       
   379  // ---------------------------------------------------------------------------
       
   380  //
       
   381  void CAiScutSettingsItem::ChangeApplicationL(TUid aUid, const TDesC& aParams,
       
   382         const TDesC& aCaption)
       
   383  {
       
   384     iUid = aUid;
       
   385     iType = EAiScutSettingTypeApplication;
       
   386 
       
   387     HBufC* newValue = NULL;
       
   388     TAiScutParser parser;
       
   389     parser.ComposeL(newValue, iUid, aParams);
       
   390 
       
   391     delete iValue;
       
   392     iValue = NULL;
       
   393     iValue = newValue;
       
   394 
       
   395     CreateListBoxLineL(aCaption);
       
   396  }
       
   397 
       
   398  // -----------------------------------------------------------------------------
       
   399  // Changes the setting item target bookmark.
       
   400  // -----------------------------------------------------------------------------
       
   401  //
       
   402  void CAiScutSettingsItem::ChangeBookmarkL(const TDesC& aParams, const TDesC& aCaption)
       
   403  {
       
   404     iUid = KScutSettingsDllUid;
       
   405     iType = EAiScutSettingTypeBookmark;
       
   406 
       
   407     HBufC* newValue = NULL;
       
   408     TAiScutParser parser;
       
   409     parser.ComposeL(newValue, iUid, aParams);
       
   410 
       
   411     delete iValue;
       
   412     iValue = NULL;
       
   413     iValue = newValue;
       
   414 
       
   415     CreateListBoxLineL(aCaption);
       
   416  }
       
   417 
       
   418  // -----------------------------------------------------------------------------
       
   419  // Changes the setting item target url.
       
   420  // -----------------------------------------------------------------------------
       
   421  //
       
   422  void CAiScutSettingsItem::ChangeUrlL(const TDesC& aUrl)
       
   423  {
       
   424     iUid.iUid = 0;
       
   425     iType = EAiScutSettingTypeUrl;
       
   426 
       
   427     delete iValue;
       
   428     iValue = NULL;
       
   429     iValue = aUrl.AllocL();
       
   430 
       
   431     CreateListBoxLineL(*iValue);
       
   432  }
       
   433 
       
   434  // -----------------------------------------------------------------------------
       
   435  // Creates a formatted listbox line.
       
   436  // -----------------------------------------------------------------------------
       
   437  //
       
   438  void CAiScutSettingsItem::CreateListBoxLineL(const TDesC& aCaption)
       
   439  {
       
   440     HBufC* title = CreateItemTitleLC();
       
   441 
       
   442     TPtrC caption;
       
   443     caption.Set(aCaption);
       
   444 
       
   445     TUriParser parser;
       
   446     TInt err = parser.Parse(aCaption);
       
   447     if (err == KErrNone)
       
   448     {
       
   449         // Remove scheme from the url.
       
   450         const TDesC& host = parser.Extract(EUriHost);
       
   451         if (host.Length())
       
   452         {
       
   453             caption.Set(host);
       
   454         }
       
   455     }
       
   456 
       
   457     // Format (" \t%S\t\t%S") without %S characters.
       
   458     TInt formatLength = KSettingListboxLineFormat().Length();
       
   459 
       
   460     HBufC* listBoxLine =
       
   461         HBufC::NewLC(title->Length() + caption.Length() + formatLength);
       
   462 
       
   463     TPtr ptr = listBoxLine->Des();
       
   464     ptr.Format(KSettingListboxLineFormat, title, &caption);
       
   465 
       
   466     delete iListBoxLine;
       
   467     iListBoxLine = NULL;
       
   468     iListBoxLine = listBoxLine;
       
   469     CleanupStack::Pop(listBoxLine);
       
   470 
       
   471     TInt titlePos = ptr.Find(*title);
       
   472     if (titlePos < 0)
       
   473     {
       
   474         titlePos = 0;
       
   475     }
       
   476     iTitle.Set(ptr.Mid(titlePos, title->Length()));
       
   477 
       
   478     CleanupStack::PopAndDestroy(title);
       
   479  }
       
   480 
       
   481  // -----------------------------------------------------------------------------
       
   482  // Creates a setting item title.
       
   483  // -----------------------------------------------------------------------------
       
   484  //
       
   485  HBufC* CAiScutSettingsItem::CreateItemTitleLC()
       
   486  {
       
   487      HBufC* title = NULL;
       
   488      if (iKey & KScutFlagBitOptionallyVisible)
       
   489      {
       
   490         // Optionally visible shortcuts are either navigation keys or soft keys.
       
   491         title = CreateOptionallyVisibleKeyTitleLC();
       
   492      }
       
   493 
       
   494      // Make sure something gets loaded and put to cleanup stack.
       
   495      if (!title)
       
   496      {
       
   497         title = StringLoader::LoadLC(
       
   498             R_SCUT_SETTINGS_TXT_LINKN, iIndex+1, iModel.Env());
       
   499      }
       
   500 
       
   501      __PRINT( __DBG_FORMAT( "XAI: CreateItemTitleLC %d key = 0x%x (0x%x) title = '%S' "),
       
   502             iIndex+1, iKey, (iKey & 0xFFFF), title);
       
   503 
       
   504      return title;
       
   505  }
       
   506 
       
   507  // -----------------------------------------------------------------------------
       
   508  // Creates a key title for an optionally visible shortcut.
       
   509  // -----------------------------------------------------------------------------
       
   510  //
       
   511  HBufC* CAiScutSettingsItem::CreateOptionallyVisibleKeyTitleLC()
       
   512  {
       
   513     HBufC* title = NULL;
       
   514     TInt resourceId = 0;
       
   515 
       
   516     switch (iKey & 0xFFFF)
       
   517     {
       
   518         case EAiScutScrollKeyLeft:
       
   519             resourceId = R_SCUT_SETTINGS_SCROLL_LEFT;
       
   520             break;
       
   521 
       
   522         case EAiScutScrollKeyRight:
       
   523             resourceId = R_SCUT_SETTINGS_SCROLL_RIGHT;
       
   524             break;
       
   525 
       
   526         case EAiScutScrollKeyUp:
       
   527             resourceId = R_SCUT_SETTINGS_SCROLL_UP;
       
   528             break;
       
   529 
       
   530         case EAiScutScrollKeyDown:
       
   531             resourceId = R_SCUT_SETTINGS_SCROLL_DOWN;
       
   532             break;
       
   533 
       
   534         case EAiScutSelectionKey:
       
   535             resourceId = R_SCUT_SETTINGS_SELECTION_KEY;
       
   536             break;
       
   537 
       
   538         case EAiScutSoftKeyLeft:
       
   539             resourceId = R_SCUT_SETTINGS_SOFTKEY_LEFT;
       
   540             break;
       
   541 
       
   542         case EAiScutSoftKeyRight:
       
   543             resourceId = R_SCUT_SETTINGS_SOFTKEY_RIGHT;
       
   544             break;
       
   545 
       
   546         default:
       
   547             resourceId = 0;
       
   548             break;
       
   549         }
       
   550 
       
   551     if (resourceId)
       
   552     {
       
   553         title = StringLoader::LoadLC(resourceId, iModel.Env());
       
   554     }
       
   555     else
       
   556     {
       
   557         title = NULL;
       
   558     }
       
   559 
       
   560     return title;
       
   561  }
       
   562 
       
   563  // ---------------------------------------------------------------------------
       
   564  // Returns the setting item value.
       
   565  // ---------------------------------------------------------------------------
       
   566  //
       
   567  TPtrC CAiScutSettingsItem::Value() const
       
   568  {
       
   569      if(iValue)
       
   570          {
       
   571          return TPtrC( *iValue );
       
   572          }
       
   573      return TPtrC(KNullDesC);
       
   574  }
       
   575 
       
   576  // ---------------------------------------------------------------------------
       
   577  // Returns the formatted listbox line descriptor.
       
   578  // ---------------------------------------------------------------------------
       
   579  //
       
   580  TPtrC CAiScutSettingsItem::ListBoxLine() const
       
   581  {
       
   582      if(iListBoxLine)
       
   583          {
       
   584          return TPtrC( *iListBoxLine );
       
   585          }
       
   586      return TPtrC(KNullDesC);
       
   587  }
       
   588 // End of File.