usbuis/usbindicatorplugin/src/usbindicator.cpp
changeset 38 218231f2b3b3
child 56 f45583a69686
equal deleted inserted replaced
35:9d8b04ca6939 38:218231f2b3b3
       
     1 /*
       
     2 * Copyright (c) 2010 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 #include "usbindicator.h" 
       
    18 #include <QVariant.h>
       
    19 #include <e32uid.h>
       
    20 #include <apadef.h>
       
    21 
       
    22 
       
    23 const QString TextIdPrefix = ("txt_usb_dblist_usb_connected_val_");
       
    24 /*!
       
    25    USBIndicator::USBIndicator
       
    26 */ 
       
    27 USBIndicator::USBIndicator(const QString &indicatorType) :
       
    28 HbIndicatorInterface(indicatorType,
       
    29         HbIndicatorInterface::SettingCategory,
       
    30         InteractionActivated)
       
    31 {
       
    32 }
       
    33 
       
    34 /*!
       
    35    USBIndicator::~USBIndicator
       
    36 */
       
    37 USBIndicator::~USBIndicator()
       
    38 {
       
    39 }
       
    40 
       
    41 
       
    42 /*!
       
    43    USBIndicator::handleInteraction
       
    44 */
       
    45 bool USBIndicator::handleInteraction(InteractionType type)
       
    46 {
       
    47     bool handled = false;
       
    48     TUidType uidtype(KExecutableImageUid, TUid::Uid(0x00),
       
    49                             TUid::Uid(KUSBUIUid));    
       
    50     if (type == InteractionActivated) {
       
    51         RProcess usbUiProcess;                
       
    52         TInt result = usbUiProcess.Create(KUSBExe(), KNullDesC, uidtype);
       
    53         if (result == KErrNone) {
       
    54             usbUiProcess.Resume();
       
    55         }
       
    56         usbUiProcess.Close();         
       
    57         handled = true;                
       
    58     }
       
    59     return handled;
       
    60 }
       
    61 
       
    62 /*!
       
    63    USBIndicator::indicatorData
       
    64    returns the data and icon that needs to be displayed in the universal pop up and indicator menu 
       
    65 */
       
    66 QVariant USBIndicator::indicatorData(int role) const
       
    67 {
       
    68     switch(role) {
       
    69     case PrimaryTextRole: 
       
    70         {
       
    71         QString text = QString(hbTrId("txt_usb_dblist_usb_connected"));
       
    72         return text;
       
    73         }
       
    74     case SecondaryTextRole:
       
    75         {
       
    76         return mSecDisplayName;
       
    77         }
       
    78     case DecorationNameRole:
       
    79         {
       
    80         QString iconName(KUsbIconFile);
       
    81         return iconName;
       
    82         }
       
    83     default: 
       
    84         return QVariant();      
       
    85     }
       
    86 }
       
    87 
       
    88 /*!
       
    89    USBIndicator::handleClientRequest
       
    90    handles client's activate and deactivate request
       
    91 */
       
    92 bool USBIndicator::handleClientRequest( RequestType type, 
       
    93         const QVariant &parameter)
       
    94 { 
       
    95     switch (type) {
       
    96         case RequestActivate:
       
    97             {
       
    98             QString friendlyName = parameter.toString();
       
    99             friendlyName.replace( QChar(' '), QChar('_') );
       
   100             QString textId = TextIdPrefix + friendlyName;
       
   101             mSecDisplayName = hbTrId(textId.toAscii());  
       
   102             emit dataChanged();
       
   103             }
       
   104             break;
       
   105         default:
       
   106             mSecDisplayName.clear();
       
   107             emit deactivate();
       
   108             break;
       
   109     }
       
   110     //request always handled
       
   111     return true;
       
   112 }