meetingrequest/mrgui/src/cesmrlistquery.cpp
branchRCL_3
changeset 16 4ce476e64c59
parent 13 0396474f30f5
child 17 8592a65ad3fb
equal deleted inserted replaced
13:0396474f30f5 16:4ce476e64c59
     1 /*
       
     2 * Copyright (c) 2002-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:  Implementation for mrui list queries
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "emailtrace.h"
       
    21 #include "cesmrlistquery.h"
       
    22 
       
    23 #include <aknlists.h>
       
    24 //<cmail>
       
    25 #include "esmrdef.h"
       
    26 //</cmail>
       
    27 #include <aknPopup.h>
       
    28 #include <bautils.h>
       
    29 #include <esmrgui.rsg>
       
    30 #include <StringLoader.h>
       
    31 #include <data_caging_path_literals.hrh>
       
    32 
       
    33 #include "esmrgui.hrh"
       
    34 #include "cesmralarm.h"
       
    35 #include "cesmrrecurrence.h"
       
    36 #include "esmrhelper.h"//locateresourcefile
       
    37 
       
    38 // CONSTANTS
       
    39 // Unnamed namespace for local definitions
       
    40 namespace {
       
    41 
       
    42 // resource file:
       
    43 _LIT( KResourceFileName, "esmrgui.rsc");
       
    44 
       
    45 } // namespace
       
    46 
       
    47 // ======== MEMBER FUNCTIONS ========
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CESMRListQuery::CESMRListQuery
       
    51 // C++ default constructor can NOT contain any code, that
       
    52 // might leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 inline CESMRListQuery::CESMRListQuery( TESMRListQueryType aType ) : 
       
    56 	iType(aType)
       
    57     {
       
    58     FUNC_LOG;
       
    59     // Do nothing
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CESMRListQuery::~CESMRListQuery
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CESMRListQuery::~CESMRListQuery()
       
    67     {
       
    68     FUNC_LOG;
       
    69     iAlarmArray.ResetAndDestroy();
       
    70     iRecurrenceArray.ResetAndDestroy();
       
    71     iEnv->DeleteResourceFile(iResourceOffset);
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CESMRListQuery::NewL
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C CESMRListQuery*
       
    79     CESMRListQuery::NewL( TESMRListQueryType aType )
       
    80     {
       
    81     CESMRListQuery* self = new (ELeave) CESMRListQuery(aType);
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL( );
       
    84     CleanupStack::Pop( self );
       
    85     return self;
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CESMRListQuery::ConstructL
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CESMRListQuery::ConstructL()
       
    93     {
       
    94     FUNC_LOG;
       
    95     TFileName filename;
       
    96 
       
    97     iEnv = CEikonEnv::Static();  // codescanner::eikonenvstatic
       
    98 
       
    99     ESMRHelper::LocateResourceFile(
       
   100             KResourceFileName,
       
   101             KDC_RESOURCE_FILES_DIR,
       
   102             filename,
       
   103             &iEnv->FsSession() );
       
   104 
       
   105     //for localization
       
   106     BaflUtils::NearestLanguageFile(iEnv->FsSession(),filename); 
       
   107     iResourceOffset = iEnv->AddResourceFileL(filename);
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CESMRListQuery::SetAttendeeStatus
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CESMRListQuery::SetAttendeeStatus(TESMRAttendeeStatus aStatus)
       
   115     {
       
   116     FUNC_LOG;
       
   117     iStatus = aStatus;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CESMRListQuery::ExecuteL
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C TInt CESMRListQuery::ExecuteEditBeforeSendL(
       
   125 		TESMRAttendeeStatus aStatus)
       
   126     {
       
   127     FUNC_LOG;
       
   128     CESMRListQuery* query =
       
   129             CESMRListQuery::NewL( EESMREditBeforeSendQuery );
       
   130     CleanupStack::PushL(query);
       
   131     query->SetAttendeeStatus(aStatus);
       
   132     TInt ret = query->ExecuteLD();
       
   133     CleanupStack::Pop(query);
       
   134     return ret;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CESMRListQuery::ExecuteL
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 EXPORT_C TInt CESMRListQuery::ExecuteEditBeforeSendWithSendOptOnlyL(
       
   142                  TESMRAttendeeStatus aStatus )
       
   143     {
       
   144     FUNC_LOG;
       
   145     CESMRListQuery* query =
       
   146             CESMRListQuery::NewL( 
       
   147             		EESMREditBeforeSendQueryWithSendOptionsOnly );
       
   148     CleanupStack::PushL(query);
       
   149     query->SetAttendeeStatus(aStatus);
       
   150     TInt ret = query->ExecuteLD();
       
   151     CleanupStack::Pop(query);
       
   152     return ret;
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CESMRListQuery::ExecuteL
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 EXPORT_C TInt CESMRListQuery::ExecuteL( TESMRListQueryType aType )
       
   160     {
       
   161     FUNC_LOG;
       
   162     CESMRListQuery* query = CESMRListQuery::NewL(aType);
       
   163     CleanupStack::PushL(query);
       
   164     TInt ret = query->ExecuteLD();
       
   165     CleanupStack::Pop(query);
       
   166     return ret;
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CESMRListQuery::SetListQueryTextsL
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CESMRListQuery::SetListQueryTextsL(
       
   174         CDesCArrayFlat* aItemArray,
       
   175         CAknPopupList* aPopupList)
       
   176     {
       
   177     FUNC_LOG;
       
   178     if ( iType == EESMREditBeforeSendQuery ||
       
   179          iType == EESMREditBeforeSendQueryWithSendOptionsOnly)
       
   180         {
       
   181         // Set title:
       
   182         if (iStatus == EESMRAttendeeStatusAccept)
       
   183             {
       
   184             aPopupList->SetTitleL(*iEnv->AllocReadResourceAsDes16LC(
       
   185                     R_QTN_MEET_REQ_SEND_QUERY_ACCEPTED));
       
   186             CleanupStack::PopAndDestroy(); // Resource string
       
   187             }
       
   188         else if (iStatus == EESMRAttendeeStatusTentative)
       
   189             {
       
   190             aPopupList->SetTitleL(*iEnv->AllocReadResourceAsDes16LC(
       
   191                     R_QTN_MEET_REQ_SEND_QUERY_TENTATIVE));
       
   192             CleanupStack::PopAndDestroy(); // Resource string
       
   193             }
       
   194         else if (iStatus == EESMRAttendeeStatusDecline)
       
   195             {
       
   196             aPopupList->SetTitleL(*iEnv->AllocReadResourceAsDes16LC(
       
   197                     R_QTN_MEET_REQ_SEND_QUERY_DECLINED));
       
   198             CleanupStack::PopAndDestroy(); // Resource string
       
   199             }
       
   200 
       
   201         // Set list items:
       
   202         aItemArray->AppendL(*iEnv->AllocReadResourceAsDes16LC(
       
   203                 R_QTN_MEET_REQ_SEND_NOW));
       
   204         CleanupStack::PopAndDestroy(); // Resource string
       
   205         aItemArray->AppendL(*iEnv->AllocReadResourceAsDes16LC(
       
   206                 R_QTN_MEET_REQ_EDIT_BEFORE_SEND));
       
   207         CleanupStack::PopAndDestroy(); // Resource string
       
   208 
       
   209         if ( iType == EESMREditBeforeSendQuery )
       
   210             {
       
   211             aItemArray->AppendL(*iEnv->AllocReadResourceAsDes16LC(
       
   212                     R_QTN_MEET_REQ_DONT_SEND_RESPONSE));
       
   213             CleanupStack::PopAndDestroy(); // Resource string
       
   214             }
       
   215         }
       
   216 
       
   217     else if ( iType == EESMRSendUpdateToAllQuery )
       
   218         {
       
   219         // Set title:
       
   220         aPopupList->SetTitleL(*iEnv->AllocReadResourceAsDes16LC(
       
   221                 R_QTN_MEET_REQ_SEND_UPDATE_QUERY));
       
   222         CleanupStack::PopAndDestroy(); // Resource string
       
   223 
       
   224         // Set list items:
       
   225         aItemArray->AppendL(*iEnv->AllocReadResourceAsDes16LC(
       
   226                 R_QTN_MEET_REQ_SEND_UPDATE_ALL_QUERY));
       
   227         CleanupStack::PopAndDestroy(); // Resource string
       
   228         aItemArray->AppendL(*iEnv->AllocReadResourceAsDes16LC(
       
   229                 R_QTN_MEET_REQ_SEND_UPDATE_UPDATED_QUERY));
       
   230         CleanupStack::PopAndDestroy(); // Resource string
       
   231         }
       
   232     else if ( iType == EESMRRecurrenceQuery )
       
   233         {
       
   234         // Set title:
       
   235         aPopupList->SetTitleL(*iEnv->AllocReadResourceAsDes16LC(
       
   236                 R_QTN_MEET_REQ_SET_RECURRENCE_HEADER));
       
   237         CleanupStack::PopAndDestroy(); // Resource string
       
   238         const TInt count(iRecurrenceArray.Count());
       
   239         for ( TInt i=0; i<count; i++ )
       
   240             {
       
   241             
       
   242             aItemArray->AppendL(iRecurrenceArray[i]->RecurrenceText());
       
   243             }
       
   244         }
       
   245     else if ( iType == EESMRRelativeAlarmTimeQuery )
       
   246         {
       
   247         aPopupList->SetTitleL(*StringLoader::LoadLC(
       
   248                 R_QTN_MEET_REQ_SET_ALARM_HEADER));
       
   249         CleanupStack::PopAndDestroy(); // Resource string
       
   250 
       
   251         const TInt count(iAlarmArray.Count());
       
   252         for ( TInt i=0; i<count; i++ )
       
   253             {
       
   254             aItemArray->AppendL(*iAlarmArray[i]->Text());
       
   255             }
       
   256         }
       
   257     else if ( iType == EESMROpenThisOccurenceOrSeriesQuery )
       
   258         {
       
   259         // Set title:
       
   260         aPopupList->SetTitleL(*StringLoader::LoadLC(
       
   261                 R_QTN_MEET_REQ_RECURRENT_HEADING_OPEN));
       
   262         CleanupStack::PopAndDestroy(); // Resource string
       
   263         aItemArray->AppendL(*StringLoader::LoadLC(
       
   264                 R_QTN_MEET_REQ_RECURRENT_THIS_OCCURRENCE));
       
   265         CleanupStack::PopAndDestroy(); // Resource string
       
   266         aItemArray->AppendL(*StringLoader::LoadLC(
       
   267                 R_QTN_MEET_REQ_RECURRENT_SERIES));
       
   268         CleanupStack::PopAndDestroy(); // Resource string
       
   269         }
       
   270     else if (iType == EESMRDeleteThisOccurenceOrSeriesQuery )
       
   271         {
       
   272         // Deleting recurrent event
       
   273         aPopupList->SetTitleL(*StringLoader::LoadLC(
       
   274                 R_QTN_MEET_REQ_RECURRENT_HEADING_DELETE));
       
   275         CleanupStack::PopAndDestroy(); // Resource string
       
   276         aItemArray->AppendL(*StringLoader::LoadLC(
       
   277                 R_QTN_MEET_REQ_RECURRENT_THIS_OCCURRENCE_DELETE));
       
   278         CleanupStack::PopAndDestroy(); // Resource string
       
   279         aItemArray->AppendL(*StringLoader::LoadLC(
       
   280                 R_QTN_MEET_REQ_RECURRENT_SERIES_DELETE));
       
   281         CleanupStack::PopAndDestroy(); // Resource string
       
   282         }
       
   283     else if ( iType == EESMRPriorityPopup || iType == EESMRTodoPriorityPopup)
       
   284         {
       
   285         // Set title:
       
   286         aPopupList->SetTitleL(*StringLoader::LoadLC(
       
   287                 R_QTN_MEET_REQ_OPT_PRIORITY));
       
   288         CleanupStack::PopAndDestroy(); // Resource string
       
   289         aItemArray->AppendL(*StringLoader::LoadLC(
       
   290                 R_QTN_CALENDAR_TASK_PRIORITY_HIGH));
       
   291         CleanupStack::PopAndDestroy(); // Resource string
       
   292         aItemArray->AppendL(*StringLoader::LoadLC(
       
   293                 R_QTN_CALENDAR_TASK_PRIORITY_NORMAL));
       
   294         CleanupStack::PopAndDestroy(); // Resource string
       
   295         aItemArray->AppendL(*StringLoader::LoadLC(
       
   296                 R_QTN_CALENDAR_TASK_PRIORITY_LOW));
       
   297         CleanupStack::PopAndDestroy(); // Resource string
       
   298         }
       
   299     else if ( iType == EESMRSynchronizationPopup )
       
   300         {
       
   301         // Set title:
       
   302         aPopupList->SetTitleL(*StringLoader::LoadLC(
       
   303                 R_QTN_CALENDAR_TASK_SYNC_TITLE));
       
   304         CleanupStack::PopAndDestroy(); // Resource string
       
   305         aItemArray->AppendL(*StringLoader::LoadLC(
       
   306                 R_QTN_CALENDAR_TASK_SYNC_PRIVATE));
       
   307         CleanupStack::PopAndDestroy(); // Resource string
       
   308         aItemArray->AppendL(*StringLoader::LoadLC(
       
   309                 R_QTN_CALENDAR_TASK_SYNC_PUBLIC));
       
   310         CleanupStack::PopAndDestroy(); // Resource string
       
   311         aItemArray->AppendL(*StringLoader::LoadLC(
       
   312                 R_QTN_CALENDAR_TASK_SYNC_NONE));
       
   313         CleanupStack::PopAndDestroy(); // Resource string
       
   314         }    
       
   315     }
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // CESMRListQuery::MapSelectedIndexToReturnValue
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 TInt CESMRListQuery::MapSelectedIndexToReturnValue(TInt aIndex)
       
   322     {
       
   323     FUNC_LOG;
       
   324     TInt response (KErrCancel);
       
   325 
       
   326     if (iType == EESMREditBeforeSendQuery ||
       
   327         iType == EESMREditBeforeSendQueryWithSendOptionsOnly )
       
   328         {
       
   329         switch( aIndex )
       
   330             {
       
   331             case 0:
       
   332                 {
       
   333                 response = EESMRResponsePlain;
       
   334                 break;
       
   335                 }
       
   336             case 1:
       
   337                 {
       
   338                 response = EESMRResponseMessage;
       
   339                 break;
       
   340                 }
       
   341             case 2:
       
   342                 {
       
   343                 response = EESMRResponseDontSend;
       
   344                 break;
       
   345                 }
       
   346             default:
       
   347                 {
       
   348                 break;
       
   349                 }
       
   350             }
       
   351         }
       
   352     else if (iType == EESMRSendUpdateToAllQuery )
       
   353         {
       
   354         switch( aIndex )
       
   355             {
       
   356             case 0:
       
   357                 {
       
   358                 response = EESMRSendToAllParticipants;
       
   359                 break;
       
   360                 }
       
   361             case 1:
       
   362                 {
       
   363                 response = EESMRSendToAddedOrRemovedParticipants;
       
   364                 break;
       
   365                 }
       
   366             default:
       
   367                 {
       
   368                 break;
       
   369                 }
       
   370             }
       
   371         }
       
   372     else if ( iType == EESMRRecurrenceQuery )
       
   373         {
       
   374         return iRecurrenceArray[aIndex]->RecurrenceValue();
       
   375         }
       
   376     else if ( iType == EESMRRelativeAlarmTimeQuery )
       
   377         {
       
   378         return iAlarmArray[aIndex]->Id();
       
   379         }
       
   380     else if ( iType == EESMROpenThisOccurenceOrSeriesQuery ||
       
   381               iType == EESMRDeleteThisOccurenceOrSeriesQuery )
       
   382         {
       
   383         switch ( aIndex )
       
   384             {
       
   385             case 0:
       
   386                 {
       
   387                 response = EESMRThisOccurence;
       
   388                 break;
       
   389                 }
       
   390             case 1:
       
   391                 {
       
   392                 response = EESMRSeries;
       
   393                 break;
       
   394                 }
       
   395             default:
       
   396                 break;
       
   397             }
       
   398         }
       
   399     else if ( iType == EESMRPriorityPopup )
       
   400         {
       
   401         switch ( aIndex )
       
   402             {
       
   403             case 0:
       
   404                 {
       
   405                 response = EFSCalenMRPriorityHigh;
       
   406                 break;
       
   407                 }
       
   408             case 1:
       
   409                 {
       
   410                 response = EFSCalenMRPriorityNormal;
       
   411                 break;
       
   412                 }
       
   413             case 2:
       
   414                 {
       
   415                 response = EFSCalenMRPriorityLow;
       
   416                 break;
       
   417                 }
       
   418             default:
       
   419                 break;
       
   420             }
       
   421         }
       
   422     else if ( iType == EESMRTodoPriorityPopup )
       
   423         {
       
   424         switch ( aIndex )
       
   425             {
       
   426             case 0:
       
   427                 {
       
   428                 response = EFSCalenTodoPriorityHigh;
       
   429                 break;
       
   430                 }
       
   431             case 1:
       
   432                 {
       
   433                 response = EFSCalenTodoPriorityNormal;
       
   434                 break;
       
   435                 }
       
   436             case 2:
       
   437                 {
       
   438                 response = EFSCalenTodoPriorityLow;
       
   439                 break;
       
   440                 }
       
   441             default:
       
   442                 break;
       
   443             }
       
   444 
       
   445         }
       
   446     else if ( iType == EESMRSynchronizationPopup )
       
   447         {
       
   448         switch ( aIndex )
       
   449             {
       
   450             case 0:
       
   451                 {
       
   452                 response = ESyncPublic;
       
   453                 break;
       
   454                 }
       
   455             case 1:
       
   456                 {
       
   457                 response = ESyncPrivate;
       
   458                 break;
       
   459                 }
       
   460             case 2:
       
   461                 {
       
   462                 response = ESyncNone;
       
   463                 break;
       
   464                 }
       
   465             default:
       
   466                 break;
       
   467             }
       
   468         }
       
   469     
       
   470     return response;
       
   471     }
       
   472 
       
   473 // -----------------------------------------------------------------------------
       
   474 // CESMRListQuery::ExecuteLD
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 void CESMRListQuery::LoadTextsFromResourceL()
       
   478     {
       
   479     FUNC_LOG;
       
   480     if ( iType == EESMRRelativeAlarmTimeQuery )
       
   481         {
       
   482         TResourceReader reader;
       
   483         iEnv->CreateResourceReaderLC( reader, R_ESMREDITOR_ALARMS );
       
   484 
       
   485         // Read alarm items to array
       
   486         iAlarmArray.Reset();
       
   487         TInt count = reader.ReadInt16();
       
   488         for ( TInt i(0); i < count; i++ )
       
   489             {
       
   490             CESMRAlarm* alarm = new (ELeave) CESMRAlarm;
       
   491             CleanupStack::PushL( alarm );
       
   492             alarm->ConstructFromResourceL( reader );
       
   493             alarm->LoadTextL( iEnv );
       
   494             CleanupStack::Pop( alarm );
       
   495             iAlarmArray.Append( alarm );
       
   496             }
       
   497         CleanupStack::PopAndDestroy(); // resource reader
       
   498         }
       
   499     else if ( iType == EESMRRecurrenceQuery )
       
   500         {
       
   501         TResourceReader reader;
       
   502         iEnv->CreateResourceReaderLC( reader, R_ESMREDITOR_RECURRENCE );
       
   503 
       
   504         // Read alarm items to array
       
   505         iRecurrenceArray.Reset();
       
   506         TInt count = reader.ReadInt16();
       
   507         for ( TInt i(0); i < count; i++ )
       
   508             {
       
   509             CESMRRecurrence* recurrence = new (ELeave) CESMRRecurrence;
       
   510             CleanupStack::PushL( recurrence );
       
   511             recurrence->ConstructFromResourceL( iEnv, reader );
       
   512             CleanupStack::Pop( recurrence );
       
   513             iRecurrenceArray.Append( recurrence );
       
   514             }
       
   515         CleanupStack::PopAndDestroy(); // resource reader
       
   516         }
       
   517     }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CESMRListQuery::ExecuteLD
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 EXPORT_C TInt CESMRListQuery::ExecuteLD()
       
   524     {
       
   525     FUNC_LOG;
       
   526     TInt response(KErrCancel);
       
   527 
       
   528     CAknSinglePopupMenuStyleListBox* list =
       
   529         new(ELeave)CAknSinglePopupMenuStyleListBox;
       
   530     CleanupStack::PushL(list);
       
   531 
       
   532     CAknPopupList* popupList = CAknPopupList::NewL(list,
       
   533             R_AVKON_SOFTKEYS_OK_CANCEL,
       
   534             AknPopupLayouts::EMenuGraphicHeadingWindow);
       
   535     CleanupStack::PushL(popupList);
       
   536 
       
   537     list->ConstructL(popupList, 0);
       
   538     list->CreateScrollBarFrameL(ETrue);
       
   539     list->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,
       
   540                                                     CEikScrollBarFrame::EOn);
       
   541 
       
   542     CDesCArrayFlat* itemArray = new(ELeave)CDesCArrayFlat(2);
       
   543     CleanupStack::PushL(itemArray);
       
   544 
       
   545     LoadTextsFromResourceL();
       
   546 
       
   547     SetListQueryTextsL(itemArray, popupList);
       
   548 
       
   549     CleanupStack::Pop(itemArray);
       
   550     list->Model()->SetItemTextArray(itemArray);
       
   551     list->Model()->SetOwnershipType(ELbmOwnsItemArray);
       
   552 
       
   553     // Show popup list and then show return value.
       
   554     TInt popupOk = popupList->ExecuteLD();
       
   555 
       
   556     if (popupOk)
       
   557         {
       
   558         response = MapSelectedIndexToReturnValue( list->CurrentItemIndex() );
       
   559         }
       
   560 
       
   561     CleanupStack::Pop(popupList);
       
   562     CleanupStack::PopAndDestroy(list);
       
   563     delete this; // red key works correctly and no double destruction possible
       
   564 
       
   565     return response;
       
   566     }
       
   567 
       
   568 //  End of File
       
   569