examples/SFExamples/symbian_os_communications_programming_book_v2/chapter8/receivingmessages/CSummaryScreenUI.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 #include "CSummaryScreenUI.h"
00018 #include "CWeatherReportWatcher.h"
00019 #include "SummaryScreenLog.h"
00020 
00021 _LIT(KNewLine, "\n");
00022 
00023 CSummaryScreenUI* CSummaryScreenUI::NewLC(CConsoleBase& aConsole)
00024         {
00025         CSummaryScreenUI* self = new (ELeave) CSummaryScreenUI(aConsole);
00026         CleanupStack::PushL(self);
00027         self->ConstructL();
00028         CActiveScheduler::Add(self);
00029         return self;
00030         }
00031 
00032 void CSummaryScreenUI::ConstructL()
00033         {
00034         iFs.Connect();
00035         
00036         // Create the message summary engine
00037         // This object passes itself in to the CMessageSummaryEngine as an observer.
00038         // When the contents of the message summary engine changes then the Refresh()
00039         // function is called.
00040         iMessageSummaryEngine = CMessageSummaryEngine::NewL(*this);
00041         }
00042 
00043 void CSummaryScreenUI::StartL()
00044         {
00045         LOG(">> CSummaryScreenUI::StartL()");
00046 
00047         iStatus = KRequestPending;
00048         
00049         iMessageSummaryEngine->StartL();
00050         
00051         SetActive();
00052         
00053         CActiveScheduler::Start();
00054 
00055         LOG("<< CSummaryScreenUI::StartL()");
00056         }
00057 
00058 
00059 CSummaryScreenUI::~CSummaryScreenUI()
00060         {
00061         delete iMessageSummaryEngine;
00062         delete iWeatherReportWatcher;
00063         iFs.Close();
00064         }
00065 
00066 CSummaryScreenUI::CSummaryScreenUI(CConsoleBase& aConsole) : CActive(EPriorityStandard), iConsole(aConsole)
00067         {
00068         }
00069         
00070 void CSummaryScreenUI::WriteSummaries(const CMessageSummaryGenerator& aSummaryGenerator)
00071         {
00072         // List the message summaries
00073         const RArray<TMessageSummary>& messageSummaries = aSummaryGenerator.MessageSummaries();
00074 
00075         TInt index;
00076         TInt messageCount = messageSummaries.Count();
00077         
00078         // Display each message summary
00079         for (index = 0; index < messageCount; index++)
00080                 {
00081                 iConsole.Printf(messageSummaries[index].iFrom);
00082                 iConsole.SetPos(KSubjectIndent);
00083                 iConsole.Printf(messageSummaries[index].iSummaryText);
00084                 iConsole.Printf(KNewLine);
00085                 }       
00086         }
00087 
00088 void CSummaryScreenUI::Refresh()
00089         {
00090         _LIT(KSmsMessageTitle, "SMS Messages:\n\n");
00091         _LIT(KEmailMessageTitle, "Email Messages:\n\n");
00092         _LIT(KWeatherReportTitle, "Weather Report:\n\n");
00093         
00094         _LIT(KNoWeatherReport, "None\n");
00095         _LIT(KSunnyWeatherReport, "Sun\n");
00096         _LIT(KCloudyWeatherReport, "Cloud\n");
00097         _LIT(KRainyWeatherReport, "Rain\n");
00098 
00099         iConsole.ClearScreen();
00100         
00101         // If this is the first time that refresh is called then create the weather report watcher
00102         if (iWeatherReportWatcher == NULL)
00103                 iWeatherReportWatcher = CWeatherReportWatcher::NewL(*this, iFs);
00104 
00105         // List the SMS message summaries
00106         iConsole.Printf(KSmsMessageTitle);
00107         WriteSummaries(iMessageSummaryEngine->SmsSummary());
00108         
00109         // List the Email message summaries
00110         const CMessageSummaryGenerator* emailSummaries = iMessageSummaryEngine->EmailSummary();
00111         if (emailSummaries != NULL)
00112                 {
00113                 iConsole.Printf(KNewLine);
00114                 iConsole.Printf(KEmailMessageTitle);
00115                 WriteSummaries(*emailSummaries);        
00116                 }
00117                 
00118         iConsole.Printf(KNewLine);
00119         iConsole.Printf(KWeatherReportTitle);
00120 
00121         switch (iWeatherReport)
00122                 {
00123                 case ENone:
00124                         iConsole.Printf(KNoWeatherReport);
00125                         break;
00126                         
00127                 case ESunny:
00128                         iConsole.Printf(KSunnyWeatherReport);
00129                         break;
00130                         
00131                 case ECloudy:
00132                         iConsole.Printf(KCloudyWeatherReport);
00133                         break;
00134                         
00135                 case ERainy:
00136                         iConsole.Printf(KRainyWeatherReport);
00137                         break;
00138                                                 
00139                 default:
00140                         break;
00141                 }
00142         }
00143 
00144 void CSummaryScreenUI::DoCancel()
00145         {
00146         }
00147 
00148 void CSummaryScreenUI::RunL()
00149         {               
00150         // A more sophisticated UI would probably queue some other initialisation task here.
00151         }
00152 
00153 // From MWeatherReportObserver
00154 void CSummaryScreenUI::NewWeatherReport(MWeatherReportObserver::TWeatherReport aWeatherReport)
00155         {
00156         iWeatherReport = aWeatherReport;
00157         Refresh();
00158         }
00159 

Generated by  doxygen 1.6.2