imstatuspaneindicatorplugin/src/imstatuspaneindicatorpluginimplementation.cpp
branchRCL_3
changeset 22 3104fc151679
parent 21 2b7283837edb
child 23 9a48e301e94b
equal deleted inserted replaced
21:2b7283837edb 22:3104fc151679
     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 class is the plugin implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <imstatuspaneindicatorpluginrss.rsg>
       
    21 #include <StringLoader.h>
       
    22 #include <bautils.h>
       
    23 #include <f32file.h>
       
    24 #include <e32base.h>
       
    25 #include <barsread.h>
       
    26 #include <coemain.h>
       
    27 #include <eikenv.h>
       
    28 #include <apgcli.h>
       
    29 #include <avkon.hrh>
       
    30 
       
    31 #include <xSPViewServices.h>
       
    32 // imlauncher
       
    33 #include <imcvlauncher.h>
       
    34 
       
    35 //sp settings
       
    36 #include <spsettings.h> 
       
    37 #include <spentry.h>
       
    38 #include <spproperty.h>
       
    39 
       
    40 #include "imstatuspaneindicator.h"
       
    41 #include "imstatuspaneindicatorpluginimplementation.h"
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CIMStatusPaneIndicatorPluginImplementation::CIMStatusPaneIndicatorPluginImplementation
       
    47 // C++ default constructor can NOT contain any code, that
       
    48 // might leave.
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CIMStatusPaneIndicatorPluginImplementation::CIMStatusPaneIndicatorPluginImplementation()
       
    52 : iCoeEnv( *CCoeEnv::Static() )
       
    53     {
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CIMStatusPaneIndicatorPluginImplementation::ConstructL
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 void CIMStatusPaneIndicatorPluginImplementation::ConstructL()
       
    62     {
       
    63     TFileName resPathWithoutDrive;
       
    64     resPathWithoutDrive.Zero();
       
    65     resPathWithoutDrive.Append( KResourceDir() );
       
    66     resPathWithoutDrive.Append( KIndicatorResourceFile() );
       
    67     
       
    68     TFileName path;    
       
    69     Dll::FileName(path); //get the location of the dll
       
    70     
       
    71     TDriveName drive( TParsePtrC( path ).Drive( ) ); // solve drive
       
    72 
       
    73     // leave to stack, LC method
       
    74     HBufC* resourceFilePath = HBufC::NewLC( KMaxResourcePathLength );
       
    75     TPtr ptr( resourceFilePath->Des() );
       
    76     ptr.Append( resPathWithoutDrive ); // without drive
       
    77     ptr.Insert( 0, drive ); // insert drive
       
    78 
       
    79     // NearestLanguageFile takes only TFileName
       
    80     path.Zero();
       
    81     path.Append( *resourceFilePath );
       
    82 
       
    83     if ( path.Length() != 0 )
       
    84         {
       
    85         BaflUtils::NearestLanguageFile( iCoeEnv.FsSession(), path );
       
    86         }
       
    87     
       
    88     CleanupStack::PopAndDestroy(resourceFilePath);
       
    89 
       
    90     iResourceOffset = iCoeEnv.AddResourceFileL(path);
       
    91      
       
    92     iPopupTextOne =  StringLoader::LoadLC( R_QTN_SERVTAB_UNIPANE_ONENEWMSG );
       
    93     CleanupStack::Pop();
       
    94     iPopupTextMultiple = StringLoader::LoadLC( R_QTN_SERVTAB_UNIPANE_NEWMSGS );
       
    95     CleanupStack::Pop();
       
    96     iIMStatusPaneIndicator = CIMStatusPaneIndicator::NewL();
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CIMStatusPaneIndicatorPluginImplementation::NewL
       
   101 // Two-phased constructor.
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 CIMStatusPaneIndicatorPluginImplementation* CIMStatusPaneIndicatorPluginImplementation::NewL()
       
   105     {
       
   106     CIMStatusPaneIndicatorPluginImplementation* self = 
       
   107         new( ELeave ) CIMStatusPaneIndicatorPluginImplementation();
       
   108     CleanupStack::PushL( self );
       
   109     self->ConstructL();
       
   110     CleanupStack::Pop( self );
       
   111     return self;
       
   112     }
       
   113 
       
   114 
       
   115 // Destructor
       
   116 CIMStatusPaneIndicatorPluginImplementation::~CIMStatusPaneIndicatorPluginImplementation()
       
   117     {
       
   118     delete iIMStatusPaneIndicator;
       
   119     iCoeEnv.DeleteResourceFile( iResourceOffset );
       
   120     delete iPopupTextMultiple;
       
   121     delete iPopupTextOne;  
       
   122     iViewServices.Close();
       
   123     }
       
   124 
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CIMStatusPaneIndicatorPluginImplementation::HandleIndicatorTapL
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CIMStatusPaneIndicatorPluginImplementation::HandleIndicatorTapL( const TInt aUid)
       
   131     {
       
   132    if(EAknIndicatorMecoServiceTab == aUid)
       
   133        {
       
   134        ShowMessageL();
       
   135        }
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CIMStatusPaneIndicatorPluginImplementation::CreatePopupContentMessageL()
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 HBufC* CIMStatusPaneIndicatorPluginImplementation::CreatePopupContentMessageL()
       
   143     {
       
   144     if( !iPopupTextMultiple || !iPopupTextOne )
       
   145        {
       
   146        // do not allocate KNullDesC>AllocL() memory here, as the avakon component
       
   147        // donot test for the lenght of the text, instead it tests if
       
   148        // the text is valid or not.
       
   149        // Load resource strings before calling this method!
       
   150        return NULL;
       
   151        }
       
   152     
       
   153     HBufC* dynStringBuf = NULL;
       
   154     if(iIMStatusPaneIndicator)
       
   155         {
       
   156         TInt Count = iIMStatusPaneIndicator->MsgCount();
       
   157         if( 1 == Count )
       
   158            {
       
   159            dynStringBuf =  iPopupTextOne->AllocL();
       
   160            }
       
   161        else if(Count > 1)
       
   162            {
       
   163            TInt reqDynLen = iPopupTextMultiple->Length() + 
       
   164                                     KMaxMessageNumberLength;
       
   165            dynStringBuf = HBufC::NewL( reqDynLen );
       
   166            TPtr dynString = dynStringBuf->Des();
       
   167            StringLoader::Format( dynString,
       
   168                                 iPopupTextMultiple->Des(),
       
   169                                 -1,             //No index code in source string
       
   170                                 Count );
       
   171            }
       
   172         }
       
   173    
       
   174       return dynStringBuf;
       
   175     }
       
   176  
       
   177 // ---------------------------------------------------------------------------
       
   178 // CIMStatusPaneIndicatorPluginImplementation::TextL()
       
   179 // ---------------------------------------------------------------------------
       
   180 //    
       
   181 HBufC* CIMStatusPaneIndicatorPluginImplementation::TextL( const TInt aUid, TInt& aTextType )
       
   182 	{
       
   183 	if(EAknIndicatorMecoServiceTab == aUid)
       
   184 	    {
       
   185 	    // check the uid, if its only my uid then call the functionality below.
       
   186         aTextType = CAknIndicatorPlugin::EAknIndicatorPluginLinkText;
       
   187         return CreatePopupContentMessageL();
       
   188 	    }
       
   189 	return NULL;
       
   190 	}
       
   191 // ---------------------------------------------------------------------------
       
   192 // CIMStatusPaneIndicatorPluginImplementation::ShowMessageL()
       
   193 // ---------------------------------------------------------------------------
       
   194 // 
       
   195 void CIMStatusPaneIndicatorPluginImplementation::ShowMessageL()
       
   196 	{
       
   197     if(iIMStatusPaneIndicator)
       
   198         {
       
   199         // conversation view should be launched if is 1 message or if more than
       
   200         // one message, but the sender is same of all the messages.
       
   201         if(iIMStatusPaneIndicator->MsgCount() >= 1 && iIMStatusPaneIndicator->IsMultipleSenders() == 1 )
       
   202             {
       
   203             TVwsViewId activeViewId;
       
   204             CCoeEnv::Static()->AppUi()->GetActiveViewId( activeViewId );
       
   205             // launch the conversation view
       
   206             // imlauncher call for luanching the conversationview with seletced user id
       
   207             IMCVLauncher::LaunchImConversationViewL(activeViewId, iIMStatusPaneIndicator->ServiceId(), iIMStatusPaneIndicator->SenderId());  
       
   208             }
       
   209         // servie tab is launched when there are more than one messages received from different
       
   210         // senders.
       
   211         else if(iIMStatusPaneIndicator->MsgCount() > 1 )
       
   212             {
       
   213             //launch service tab based on the service id.
       
   214             TInt serviceviewId = 0 ;
       
   215             TInt seriveId = iIMStatusPaneIndicator->ServiceId();
       
   216             if(  seriveId != KErrNotFound)
       
   217                 {
       
   218                 CSPSettings* spSettings = CSPSettings::NewL();
       
   219                 CleanupStack::PushL(spSettings);
       
   220                 //get the tabview id from settings
       
   221                 CSPProperty* property = CSPProperty::NewLC();
       
   222                 spSettings->FindPropertyL( seriveId,
       
   223                         EPropertyContactViewId,
       
   224                         *property );    
       
   225                 property->GetValue(serviceviewId);
       
   226                 CleanupStack::PopAndDestroy( property );  
       
   227                 CleanupStack::PopAndDestroy( spSettings );
       
   228                 }
       
   229             // Launched from service tab, go back there
       
   230             TInt err = iViewServices.Open();
       
   231             if ( KErrServerTerminated == err || KErrNotFound == err )
       
   232                 {
       
   233                 iViewServices.Close();
       
   234                 err = iViewServices.Open();
       
   235                 }
       
   236             // this error comes when the phonebook is already open, hence we should directly launch the 
       
   237             // service tab.
       
   238             if(KErrAlreadyExists != err)
       
   239                 {
       
   240                 User::LeaveIfError( err );
       
   241                 }
       
   242             // Activate the service tab in phonebook.
       
   243             User::LeaveIfError( iViewServices.Activate( 
       
   244                     KMECOIMPLEMENTATIONUID,
       
   245                     serviceviewId ) );
       
   246             
       
   247             }
       
   248         }
       
   249 	}
       
   250 
       
   251 
       
   252 
       
   253 //  End of File