usbuis/usbindicatorplugin/src/usbmassstorageindicator.cpp
branchRCL_3
changeset 80 e02eb84a14d2
parent 79 25fce757be94
child 83 60826dff342d
equal deleted inserted replaced
79:25fce757be94 80:e02eb84a14d2
     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: USB Mass Storage indicator implementation 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "usbmassstorageindicator.h" 
       
    19 #include <QVariant>
       
    20 #include <e32uid.h>
       
    21 #include <apadef.h>
       
    22 #include <usb/hostms/msmmindicatorclient.h>
       
    23 #include "usbdebug.h"
       
    24 
       
    25 // icon name for mass storage
       
    26 const QString KUsbIconFile("qtg_large_usb_memory");
       
    27 
       
    28 /*!
       
    29    Constructor
       
    30    @param indicatorType The indicator type name
       
    31 */ 
       
    32 UsbMassStorageIndicator::UsbMassStorageIndicator(const QString &indicatorType) :
       
    33 HbIndicatorInterface(indicatorType,
       
    34         HbIndicatorInterface::SettingCategory,
       
    35         InteractionActivated),
       
    36         mEjectStarted(false)
       
    37 {
       
    38 }
       
    39 
       
    40 /*!
       
    41    Destructor
       
    42 */
       
    43 UsbMassStorageIndicator::~UsbMassStorageIndicator()
       
    44 {
       
    45     myDebug() << ">>> UsbMassStorageIndicator::~UsbMassStorageIndicator";
       
    46 }
       
    47 
       
    48 
       
    49 /*!
       
    50    Handle user interaction
       
    51    Request eject for all USB drives.
       
    52 */
       
    53 bool UsbMassStorageIndicator::handleInteraction(InteractionType type)
       
    54 {
       
    55     myDebug() << ">>> UsbMassStorageIndicator::handleInteraction";
       
    56     bool handled = false;
       
    57     if (type == InteractionActivated) {
       
    58         if (!mEjectStarted) {
       
    59             mEjectStarted = true;
       
    60             // dismount all drives without waiting for result
       
    61             RHostMassStorage hostMassStorage;
       
    62             myDebug() << "    UsbMassStorageIndicator::handleInteraction hostMassStorage connecting";
       
    63             TInt err = hostMassStorage.Connect();
       
    64             myDebug() << "    UsbMassStorageIndicator::handleInteraction hostMassStorage connected";
       
    65             if (err == KErrNone) {
       
    66                 hostMassStorage.EjectUsbDrives();
       
    67                 myDebug() << "UsbMassStorageIndicator::handleInteraction EjectUsbDrives called";
       
    68             }
       
    69             else {
       
    70                 myDebug() << "    UsbMassStorageIndicator::handleInteraction "
       
    71                         <<"RHostMassStorage Connect fail " << err;
       
    72             }
       
    73             hostMassStorage.Disconnect();
       
    74             myDebug() << ">>> UsbMassStorageIndicator::handleInteraction disconnected";
       
    75             hostMassStorage.Close();
       
    76             myDebug() << ">>> UsbMassStorageIndicator::handleInteraction closed";
       
    77         }
       
    78         handled = true;                
       
    79     }
       
    80     myDebug() << "<<< UsbMassStorageIndicator::handleInteraction";
       
    81     return handled;
       
    82 }
       
    83 
       
    84 /*!
       
    85    Return the data and icon that needs to be displayed in the universal indicator menu 
       
    86 */
       
    87 QVariant UsbMassStorageIndicator::indicatorData(int role) const
       
    88 {
       
    89     myDebug() << ">>> UsbMassStorageIndicator::indicatorData";
       
    90     switch (role) {
       
    91         case PrimaryTextRole: 
       
    92             return QString(hbTrId("txt_usb_dblist_usb_connected"));
       
    93         case SecondaryTextRole:
       
    94             return QString(hbTrId("txt_usb_dpinfo_click_to_eject"));;
       
    95         case DecorationNameRole:
       
    96             return KUsbIconFile;
       
    97         default: 
       
    98             return QVariant(); //empty variant      
       
    99     }
       
   100 }
       
   101 
       
   102 /*!
       
   103    USBIndicator::handleClientRequest
       
   104    handles client's activate and deactivate request
       
   105 */
       
   106 bool UsbMassStorageIndicator::handleClientRequest( RequestType type, 
       
   107         const QVariant &parameter)
       
   108 { 
       
   109     myDebug() << ">>> UsbMassStorageIndicator::handleClientRequest";
       
   110     Q_UNUSED(parameter);
       
   111     if (type == RequestDeactivate) {
       
   112         myDebug() << "    UsbMassStorageIndicator::handleClientRequest deactivate";
       
   113         mEjectStarted = false;
       
   114         emit deactivate();        
       
   115     }
       
   116     myDebug() << "<<< UsbMassStorageIndicator::handleClientRequest";
       
   117     return true;
       
   118 }