usbuis/usbuiqt/inc/usbuisettingmodel.h
changeset 35 9d8b04ca6939
parent 25 8c311f9acc5e
equal deleted inserted replaced
34:7858bc6ead78 35:9d8b04ca6939
       
     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 #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 const int KDefaultColumn = 0;
       
    29 typedef QList< QMap< int, QVariant > > UsbUiModelDataSource;
       
    30 
       
    31 class RUsb;
       
    32 class UsbUiModelActive;
       
    33 
       
    34 class UsbUiSettingModel : public QAbstractItemModel
       
    35 {
       
    36     Q_OBJECT
       
    37     friend class TestUsbUiModelActive;
       
    38  
       
    39 public:
       
    40 enum usbSettingsIndex {
       
    41         DefaultMode,
       
    42         Description,
       
    43         UsbModeList,
       
    44         EndOfSettings
       
    45     };
       
    46 enum SettingsRoleValues {
       
    47         SettingType = Qt::UserRole,
       
    48         SettingsModeNameList,
       
    49     };
       
    50 public:
       
    51     UsbUiSettingModel( QObject *parent = 0 );
       
    52     virtual ~UsbUiSettingModel();
       
    53 
       
    54     /*
       
    55      *  Returns the index of the item in the model specified by the given row, column and parent index.
       
    56      *  @param row is the row number of the specified item
       
    57      *  @param column is the column number of the specified item
       
    58      *  @param parent QModelIndex parent
       
    59      */   
       
    60     virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
       
    61     /*
       
    62      * Returns QModelIndex() because this model item has no parent
       
    63      * @param child is the index of item model, the parent of which is going to be returned
       
    64      * @param child is not used in here
       
    65      */
       
    66     virtual QModelIndex parent( const QModelIndex &child ) const;
       
    67     /*
       
    68      * Returns the number of rows under the given parent
       
    69      * @param parent QModelIndex parent
       
    70      */
       
    71     virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
       
    72     /*
       
    73      * Returns the number of columns for the children of the given parent.
       
    74      * @param parent QModelIndex parent
       
    75      */
       
    76     virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
       
    77     /*
       
    78      *Returns the data stored under the given role for the item referred to by the index. 
       
    79      */
       
    80     virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
       
    81     /*
       
    82      * Sets the role data for the item at index to value. Returns true if successful; otherwise returns false.
       
    83      */
       
    84     virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
       
    85 
       
    86     const QModelIndex* sourceData() const;
       
    87 
       
    88 public slots:
       
    89     /*
       
    90      * Provides notification of changes in selected usb mode
       
    91      * @param key is not used 
       
    92      * @param value is the value read from cenrep key 
       
    93      */
       
    94     void usbModeChanged( const XQSettingsKey &key, const QVariant &value );
       
    95     /*
       
    96      * it checks the response from usbwatcher to see if the new mode change has been successful
       
    97      * it will go back to the previous personality if it has not been successfull
       
    98      * @param status is the error code returned from usbwatcher
       
    99      */
       
   100     void setPersonalityCompleted (int status );
       
   101     
       
   102 private:
       
   103 	/*
       
   104 	 * creats the logical name of the modename string for the list
       
   105 	 * @param modeId is the usb personality id
       
   106 	 */   
       
   107     QString modeListName( int modeId );
       
   108     /*
       
   109      * Get the current USB personality ID
       
   110      * Returns 0, if the key is missing or the value cannot be converted 
       
   111      * to integer.
       
   112      * @return The current personality id
       
   113      */
       
   114     int currentMode(); 
       
   115     /*
       
   116      * sets the value to different roles of the model's first row
       
   117      */
       
   118     void setDefaultModeSetting();
       
   119     /*
       
   120      * sets the value to different roles of the model's description row
       
   121      */
       
   122     void setDescriptionSetting();
       
   123     /**
       
   124      * Set the USB mode list and the current selection in the list.
       
   125      * The personality IDs are stored to mPersonalityIds and the personality names
       
   126      * to mSettingsList.
       
   127      * @param modeId The current mode ID
       
   128      */
       
   129     bool setUsbModelistSetting( int modeId );
       
   130     /**
       
   131      * calls the model's set functions
       
   132      * @param modeId The current mode ID
       
   133      */
       
   134     void setUsbSettings( int modeId );
       
   135     /**
       
   136      * updates the model rows and emits signal datachanged
       
   137      * @param newPersonality is the new personality id
       
   138      */
       
   139     void setNewUsbMode(int newPersonality);
       
   140 	
       
   141     /**
       
   142      * Check from the USB Manager if the USB personality is hidden.
       
   143      * @param usbman Already opened USB Manager session
       
   144      * @param personalityId The ID of the personality to be checked.
       
   145      * @return For hidden personality, true is returned.
       
   146      */
       
   147     bool isPersonalityHidden(RUsb &usbman, TInt personalityId);
       
   148     
       
   149     /**
       
   150      * Check if the USB personality is hidden.
       
   151      * The personality is hidden, if it does not exist in mPersonalityIds.
       
   152      * @param personalityId The ID of the personality to be checked.
       
   153      * @return For hidden personality, true is returned.
       
   154      */
       
   155     bool isPersonalityHidden(TInt personalityId);
       
   156  private:
       
   157     
       
   158     UsbUiModelDataSource mSettingsList;
       
   159     int mCurrentMode;
       
   160     // stored, so that we can show the correct personality when it fails to set the new one
       
   161     int mPreviousMode; 
       
   162     
       
   163     XQSettingsManager mSettingsManager;
       
   164     QList<int> mPersonalityIds;
       
   165     UsbUiModelActive *mModelActive;
       
   166 };
       
   167 
       
   168 #endif // USBUISETTINGMODEL_H