usbuis/usbsettingsapp/inc/usbuisettingmodel.h
branchRCL_3
changeset 80 e02eb84a14d2
parent 79 25fce757be94
child 83 60826dff342d
equal deleted inserted replaced
79:25fce757be94 80:e02eb84a14d2
     1 /*
       
     2 * Copyright (c) 2009-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 
       
    18 #ifndef USBUISETTINGMODEL_H
       
    19 #define USBUISETTINGMODEL_H
       
    20 
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32property.h>
       
    24 #include <QStringList>
       
    25 #include <QAbstractItemModel>
       
    26 #include <XQSettingsManager>
       
    27 
       
    28 typedef QList< QMap< int, QVariant > > UsbUiModelDataSource;
       
    29 
       
    30 class RUsb;
       
    31 class UsbUiModelActive;
       
    32 class QItemSelection;
       
    33 class QItemSelectionModel;
       
    34 
       
    35 class UsbUiSettingModel : public QAbstractItemModel
       
    36 {
       
    37     Q_OBJECT
       
    38     friend class TestUsbUiModelActive;
       
    39  
       
    40 public:
       
    41     UsbUiSettingModel( QObject *parent = 0);
       
    42     virtual ~UsbUiSettingModel();
       
    43 
       
    44     /*
       
    45      *  Returns the index of the item in the model specified by the given row, column and parent index.
       
    46      *  @param row is the row number of the specified item
       
    47      *  @param column is the column number of the specified item
       
    48      *  @param parent QModelIndex parent
       
    49      */   
       
    50     virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
       
    51     /*
       
    52      * Returns QModelIndex() because this model item has no parent
       
    53      * @param child is the index of item model, the parent of which is going to be returned
       
    54      * @param child is not used in here
       
    55      */
       
    56     virtual QModelIndex parent( const QModelIndex &child ) const;
       
    57     /*
       
    58      * Returns the number of rows under the given parent
       
    59      * @param parent QModelIndex parent
       
    60      */
       
    61     virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
       
    62     /*
       
    63      * Returns the number of columns for the children of the given parent.
       
    64      * @param parent QModelIndex parent
       
    65      */
       
    66     virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
       
    67     /*
       
    68      *Returns the data stored under the given role for the item referred to by the index. 
       
    69      */
       
    70     virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
       
    71 
       
    72     const QModelIndex* sourceData() const;
       
    73    
       
    74     /*
       
    75      * informs the model of the changes in selectionModel and the new mode 
       
    76      * will be Handeled by the Model
       
    77      */
       
    78     void  setSelectionModel(QItemSelectionModel *selectionModel);
       
    79 
       
    80 public slots:
       
    81     /*
       
    82      * Provides notification of changes in selected usb mode
       
    83      * @param key is not used 
       
    84      * @param value is the value read from cenrep key 
       
    85      */
       
    86     void cenrepChanged( const XQSettingsKey &key, const QVariant &value );
       
    87     
       
    88     /*
       
    89      * it checks the response from usbwatcher to see if the new mode change has been successful
       
    90      * it will go back to the previous personality if it has not been successful
       
    91      * @param status is the error code returned from usbwatcher
       
    92      */
       
    93     void personalitySetCompleted (int status );
       
    94     
       
    95     /**
       
    96      * This slot handles selection change from the selection model.
       
    97      * The personality is set according to the selection.
       
    98      * @param selected Item selection of selected items
       
    99      * @param deselected Item selection of deselected items
       
   100      */
       
   101     void handleSelectionChange(const QItemSelection &selected, 
       
   102             const QItemSelection &deselected );
       
   103     
       
   104 private:
       
   105 	/*
       
   106 	 * Get the translated mode name
       
   107 	 * @param friendlyName is the usb personality friendly name
       
   108 	 */   
       
   109     QString modeName( QString &friendlyName );
       
   110 
       
   111     /*
       
   112      * Get the current USB personality ID
       
   113      * Returns 0, if the key is missing or the value cannot be converted 
       
   114      * to integer.
       
   115      * @return The current personality id
       
   116      */
       
   117     int currentMode(); 
       
   118 
       
   119     /**
       
   120      * Initialize the model data
       
   121      * @param modeId The current mode ID
       
   122      */
       
   123     void initializeModelData( int modeId );
       
   124 
       
   125     /**
       
   126      * Update the selection model
       
   127      * @param newPersonality is the new personality id
       
   128      */
       
   129     void updateSelectionModel(int newPersonality);
       
   130 	
       
   131     /**
       
   132      * Check from the USB Manager if the USB personality is hidden.
       
   133      * @param usbman Already opened USB Manager session
       
   134      * @param personalityId The ID of the personality to be checked.
       
   135      * @return For hidden personality, true is returned.
       
   136      */
       
   137     bool isPersonalityHidden(RUsb &usbman, TInt personalityId);
       
   138     
       
   139     /**
       
   140      * Get the personality friendly name from USB Manager
       
   141      * The friendly name can be used in text IDs.
       
   142      * @param usbman The open USB Manager session
       
   143      * @param personalityId The ID of the personality
       
   144      * @return Friendly name for personality
       
   145      */
       
   146     QString getFriendlyName(RUsb &usbman, TInt personalityId);
       
   147     
       
   148 private:
       
   149        
       
   150     UsbUiModelDataSource mSettingsList;
       
   151  
       
   152     // current USB personality
       
   153     int mCurrentMode;
       
   154 
       
   155     //variable to access central repository
       
   156     XQSettingsManager mSettingsManager;
       
   157     
       
   158     QList<int> mPersonalityIds;
       
   159     //owned by the class
       
   160     // modelactive is used for the interaction with the usbwatcher
       
   161     UsbUiModelActive *mModelActive;
       
   162     
       
   163     QItemSelectionModel *mSelectionModel;
       
   164 };
       
   165 
       
   166 #endif // USBUISETTINGMODEL_H