homescreenapp/serviceproviders/hsmenuserviceprovider/src/hsmenuitemmodel.cpp
changeset 77 4b195f3bea29
parent 61 2b1b11a301d2
child 85 35368b604b28
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
    14  * Description: hsmenuitemmodel.cpp
    14  * Description: hsmenuitemmodel.cpp
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include <hbnamespace.h>
    18 #include <hbnamespace.h>
       
    19 #include <cauninstallnotifier.h>
       
    20 #include <casoftwareregistry.h>
    19 
    21 
    20 #include "hsmenuitemmodel.h"
    22 #include "hsmenuitemmodel.h"
    21 #include "hsmenuserviceutils.h"
    23 #include "hsmenuserviceutils.h"
       
    24 #include "hsiconsidleloader.h"
    22 
    25 
    23 // Constants
    26 // Constants
    24 const QSize smallIconSize(55, 55);
    27 const QSize smallIconSize(55, 55);
    25 
    28 
    26 /*!
    29 /*!
    27  Constructor
    30  Constructor
    28  \param query used to create model
    31  \param query used to create model
    29  \param pointer to parent object
    32  \param pointer to parent object
    30  */
    33  */
    31 HsMenuItemModel::HsMenuItemModel(const CaQuery &query, QObject *parent) :
    34 HsMenuItemModel::HsMenuItemModel(const CaQuery &query, QObject *parent) :
    32     CaItemModel(query, parent)
    35     CaItemModel(query, parent),
       
    36     mIconsIdleLoader(NULL)
    33 {
    37 {
    34     setIconSize(smallIconSize);
    38     setIconSize(smallIconSize);
       
    39     mComponentId = 0;
       
    40     mUninstallNotifier = 
       
    41         CaSoftwareRegistry::create()->createUninstallNotifier();
       
    42     connect(mUninstallNotifier, SIGNAL(progressChange(int, int)),
       
    43             this, SLOT(uninstallChange(int, int)));
    35 }
    44 }
    36 
    45 
    37 /*!
    46 /*!
    38  Destructor
    47  Destructor
    39  */
    48  */
    40 HsMenuItemModel::~HsMenuItemModel()
    49 HsMenuItemModel::~HsMenuItemModel()
    41 {
    50 {
    42 
    51     if (!mIds.isEmpty()) {
       
    52         mIds.clear();
       
    53     }
    43 }
    54 }
    44 
    55 
    45 /*!
    56 /*!
    46  Sets sort order in the model
    57  Sets sort order in the model
    47  */
    58  */
    75 
    86 
    76         variant = QVariant(icons);
    87         variant = QVariant(icons);
    77     } else if (role == Hb::IndexFeedbackRole){
    88     } else if (role == Hb::IndexFeedbackRole){
    78         QVariant display = CaItemModel::data(index, Qt::DisplayRole);
    89         QVariant display = CaItemModel::data(index, Qt::DisplayRole);
    79         if (display.type() == QVariant::String){
    90         if (display.type() == QVariant::String){
    80             variant = display;
    91             variant = QVariant(display.toString().at(0).toUpper());;
    81         } else {
    92         } else {
    82             variant = QVariant(display.toList().at(0));
    93             variant = QVariant(display.toList().at(0).toString().at(0).toUpper());
    83         }
    94         }
    84     } else {
    95     } else {
    85         variant = CaItemModel::data(index, role);
    96         variant = CaItemModel::data(index, role);
    86     }
    97     }
    87     HSMENUTEST_FUNC_EXIT("HsMenuItemModel::data");
    98     HSMENUTEST_FUNC_EXIT("HsMenuItemModel::data");
   104         result = true;
   115         result = true;
   105     }
   116     }
   106     HSMENUTEST_FUNC_EXIT("HsMenuItemModel::newIconNeeded");
   117     HSMENUTEST_FUNC_EXIT("HsMenuItemModel::newIconNeeded");
   107     return result;
   118     return result;
   108 }
   119 }
       
   120 
       
   121 /*!
       
   122  Updating uninstall progress with value for each item
       
   123   \param componentId Component Id of installed item
       
   124   \param valueOfProgress % value of current progress
       
   125  */
       
   126 void HsMenuItemModel::uninstallChange(int componentId, int valueOfProgress)
       
   127 {
       
   128     if (componentId!=mComponentId) {
       
   129         if (!mIds.isEmpty()) {
       
   130             mIds.clear();
       
   131         }
       
   132         // get items list with same componentID
       
   133         mIds = CaItemModel::getUninstallingEntriesIds(componentId);
       
   134         mComponentId = componentId;
       
   135     }
       
   136     // update each item with progress value
       
   137     foreach (int id, mIds) {
       
   138         CaItemModel::updateProgress(id, valueOfProgress);
       
   139     }
       
   140 }
       
   141 
       
   142 
       
   143 /*!
       
   144  Start preloading icons if idle
       
   145  \param entry entry representing an item
       
   146  \retval void
       
   147  */
       
   148 void HsMenuItemModel::preloadIcons()
       
   149 {
       
   150     mIconsIdleLoader = new HsIconsIdleLoader(this, this);
       
   151 }