iaupdate/IAD/bgcindicatorplugin/src/bgcindicator.cpp
changeset 25 98b66e4fb0be
child 29 26b6f0522fd8
equal deleted inserted replaced
24:84a16765cd86 25:98b66e4fb0be
       
     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:
       
    15  *
       
    16  */
       
    17 
       
    18 #include <w32std.h>
       
    19 #include <apgtask.h>
       
    20 #include <apacmdln.h>
       
    21 #include <xqservicerequest.h>
       
    22 
       
    23 // #include "debugtraces.h"
       
    24 #include "bgcindicator.h" 
       
    25 
       
    26 //----------------------------------------------------------------------
       
    27 
       
    28 
       
    29 // ----------------------------------------------------------------------------
       
    30 // BgcIndicator::BgcIndicator
       
    31 // @see bgcindicator.h
       
    32 // ----------------------------------------------------------------------------
       
    33 BgcIndicator::BgcIndicator(const QString &indicatorType) :
       
    34 HbIndicatorInterface(indicatorType,
       
    35         HbIndicatorInterface::GroupPriorityHigh,
       
    36         InteractionActivated),
       
    37         mNrOfUpdates(0)
       
    38     {
       
    39     }
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // BgcIndicator::~BgcIndicator
       
    43 // @see bgcindicator.h
       
    44 // ----------------------------------------------------------------------------
       
    45 BgcIndicator::~BgcIndicator()
       
    46     {
       
    47     }
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // BgcIndicator::handleInteraction
       
    51 // @see bgcindicator.h
       
    52 // ----------------------------------------------------------------------------
       
    53 bool BgcIndicator::handleInteraction(InteractionType type)
       
    54     {
       
    55     bool handled = false;
       
    56     
       
    57     if (type == InteractionActivated) 
       
    58         {
       
    59         StartIaupdateL();
       
    60         handled = true;   
       
    61         
       
    62         emit deactivate(); 
       
    63         }
       
    64     return handled;
       
    65     }
       
    66 
       
    67 // ----------------------------------------------------------------------------
       
    68 // BgcIndicator::indicatorData
       
    69 // @see bgcindicator.h
       
    70 // ----------------------------------------------------------------------------
       
    71 QVariant BgcIndicator::indicatorData(int role) const
       
    72 {
       
    73     
       
    74 switch(role)
       
    75     {
       
    76     case TextRole: 
       
    77         {
       
    78         QString text("");
       
    79         if ( mNrOfUpdates == 1 )
       
    80             text.append(QString("Updates available"));
       
    81         else
       
    82             text.append(QString("Check for updates?"));
       
    83         return text;        
       
    84         }
       
    85     case SecondaryTextRole:
       
    86         {
       
    87         QString text("Tap to view");
       
    88         return text; 
       
    89         }
       
    90     case IconNameRole:
       
    91         {
       
    92         // QString iconName("z:/resource/messaging/message.svg");
       
    93         QString iconName("c:/qgn_note_swupdate_notification.svg");
       
    94         return iconName;
       
    95         }
       
    96     default: 
       
    97         return QVariant();      
       
    98     }
       
    99 }
       
   100 
       
   101 // ----------------------------------------------------------------------------
       
   102 // BgcIndicator::prepareDisplayName
       
   103 // @see bgcindicator.h
       
   104 // ----------------------------------------------------------------------------
       
   105 bool BgcIndicator::handleClientRequest( RequestType type, 
       
   106         const QVariant &parameter)
       
   107     {
       
   108     bool handled(false);
       
   109     switch (type) {
       
   110         case RequestActivate:
       
   111             {
       
   112             mNrOfUpdates = parameter.toInt();
       
   113             handled =  true;
       
   114             }
       
   115             break;
       
   116         case RequestDeactivate:
       
   117             {
       
   118             emit deactivate();
       
   119             }
       
   120             break;
       
   121         default:
       
   122             break;
       
   123     }
       
   124 
       
   125     return handled;
       
   126     }
       
   127 
       
   128 // ----------------------------------------------------------
       
   129 // CIAUpdateBGTimer::StartIaupdateL()
       
   130 // ----------------------------------------------------------
       
   131 void BgcIndicator::StartIaupdateL() const
       
   132     {
       
   133     
       
   134     const TUint KIADUpdateLauncherUid( 0x2001FE2F );
       
   135     _LIT(KIAUpdateLauncherExe, "iaupdatelauncher.exe" );
       
   136     _LIT8( KRefreshFromNetworkDenied, "1" );
       
   137     
       
   138     //FLOG("[bgchecker] StartIaupdateL() begin");
       
   139     RWsSession ws;   
       
   140     User::LeaveIfError( ws.Connect() == KErrNone );
       
   141     TApaTaskList tasklist(ws);   
       
   142     TApaTask task = tasklist.FindApp( TUid::Uid( KIADUpdateLauncherUid ) );
       
   143     if ( task.Exists() )
       
   144         {
       
   145         //FLOG("[bgchecker] StartIaupdateL() IAD launcher process found");
       
   146         task.BringToForeground();
       
   147         //FLOG("[bgchecker] StartIaupdateL() after task.BringToForeground()");
       
   148         ws.Close();
       
   149         }
       
   150     else 
       
   151         {
       
   152         ws.Close();
       
   153         RProcess process;
       
   154         CleanupClosePushL( process );
       
   155         User::LeaveIfError( 
       
   156               process.Create( KIAUpdateLauncherExe, KNullDesC ) );
       
   157               
       
   158         CApaCommandLine* commandLine = CApaCommandLine::NewLC();
       
   159         commandLine->SetDocumentNameL( KNullDesC );
       
   160         commandLine->SetExecutableNameL( _L("iaupdatelauncher.exe") );
       
   161         commandLine->SetTailEndL( KRefreshFromNetworkDenied );
       
   162         commandLine->SetProcessEnvironmentL( process );
       
   163         CleanupStack::PopAndDestroy( commandLine );
       
   164        
       
   165         process.Resume();
       
   166         CleanupStack::PopAndDestroy( &process );    
       
   167         }
       
   168     //FLOG("[bgchecker] StartIaupdateL() end");
       
   169     }
       
   170