iaupdate/IAD/ui/src/iaupdatemainview.cpp
changeset 53 ae54820ef82c
parent 52 92f864ef0288
child 67 3a625661d1ce
equal deleted inserted replaced
52:92f864ef0288 53:ae54820ef82c
    15 *                class member functions.
    15 *                class member functions.
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 #include <hbaction.h>
    19 #include <hbaction.h>
    20 #include <QgraphicsWidget>
    20 #include <QGraphicsWidget>
    21 
    21 #include <QGraphicsLayout>
       
    22 #include <QGraphicsLayoutItem>
       
    23 #include <QGraphicsLinearLayout>
       
    24 
       
    25 #include <hbdockwidget.h>
    22 #include <hblistwidget.h>
    26 #include <hblistwidget.h>
    23 #include <hblistviewitem.h>
    27 #include <hblistviewitem.h>
    24 #include <hblistwidgetitem.h>
    28 #include <hblistwidgetitem.h>
    25 #include <hbtoolbar.h>
    29 #include <hbtoolbar.h>
    26 #include <hbmenu.h>
    30 #include <hbmenu.h>
    27 #include <hbdocumentloader.h>
    31 #include <hbdocumentloader.h>
    28 #include <xqconversions.h>
    32 #include <xqconversions.h>
    29 #include <hbmessagebox.h>
    33 #include <hbmessagebox.h>
    30 #include <hblabel.h>
    34 #include <hblabel.h>
       
    35 #include <hbgroupbox.h>
       
    36 #include <hbdataform.h>
    31 
    37 
    32 #include "iaupdatemainview.h"
    38 #include "iaupdatemainview.h"
    33 #include "iaupdateengine.h"
    39 #include "iaupdateengine.h"
    34 #include "iaupdateagreement.h"
    40 #include "iaupdateagreement.h"
    35 #include "iaupdatedeputils.h"
    41 #include "iaupdatedeputils.h"
    46 
    52 
    47 
    53 
    48 IAUpdateMainView::IAUpdateMainView(IAUpdateEngine *engine):
    54 IAUpdateMainView::IAUpdateMainView(IAUpdateEngine *engine):
    49 mEngine(engine)        
    55 mEngine(engine)        
    50 {
    56 {
       
    57     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::IAUpdateMainView() begin");
       
    58     mFwListView = NULL;
       
    59     mApplicationUpdatesGroupBox = NULL;;
       
    60     mFwNSUGroupBox = NULL;
       
    61     mContentDataForm = NULL;
    51     mDialogUtil = NULL;
    62     mDialogUtil = NULL;
    52     mDialogState = NoDialog;
    63     mDialogState = NoDialog;
    53     mPrimaryAction = NULL;
    64     mPrimaryAction = NULL;
    54     mNode = NULL;
    65     mNode = NULL;
    55     mSelectionUpdate = false;
    66     mSelectionUpdate = false;
       
    67     mSelectionConnect = false;
    56     
    68     
    57     HbDocumentLoader loader;
    69     HbDocumentLoader loader;
    58     bool ok = false;
    70     bool ok = false;
    59     loader.load(":/xml/iaupdate_mainview.docml", &ok);
    71     loader.load(":/xml/iaupdate_mainview.docml", &ok);
    60         
    72         
    61     // Exit if the file format is invalid
    73     // Exit if the file format is invalid
    62     Q_ASSERT_X(ok, "Software update", "Invalid docml file");
    74     Q_ASSERT_X(ok, "Software update", "Invalid docml file");
    63     // Create the view from DocML
    75     // Create the view from DocML
    64     
    76     
    65     HbView* widget = qobject_cast<HbView*>(loader.findWidget("view"));
    77     HbView* loadedWidget = qobject_cast<HbView*>(loader.findWidget("view"));
    66     Q_ASSERT_X(widget != 0, "Software update", "View not found");
    78     Q_ASSERT_X(loadedWidget != 0, "Software update", "View not found");
    67     QString viewTitle(widget->title());
    79     QString viewTitle(loadedWidget->title());
    68     // Set the IAUpdateMainView view to be the widget that was loaded from the xml
    80     // Set the IAUpdateMainView view to be the widget that was loaded from the xml
    69     setWidget(widget);
    81     setWidget(loadedWidget);
    70     setTitle(viewTitle);
    82     setTitle(viewTitle);
    71       
    83       
    72     HbToolBar *toolBar = qobject_cast< HbToolBar*>( loader.findWidget("viewToolbar") );
    84     HbToolBar *toolBar = qobject_cast< HbToolBar*>( loader.findWidget("viewToolbar") );
    73     setToolBar(toolBar);
    85     //setToolBar(toolBar);
    74     
    86     
    75     HbMenu *menu = qobject_cast< HbMenu*>( loader.findWidget("viewMenu") );
    87     HbMenu *menu = qobject_cast< HbMenu*>( loader.findWidget("viewMenu") );
    76     setMenu(menu);
    88     setMenu(menu);
    77     
    89     
    78     //Get the Action objects from the docml file
    90     //Get the Action objects from the docml file
    81     HbAction *action_2 = qobject_cast<HbAction*>(loader.findObject("action_2"));
    93     HbAction *action_2 = qobject_cast<HbAction*>(loader.findObject("action_2"));
    82     
    94     
    83     connect(action, SIGNAL(triggered()), this, SLOT(handleStartUpdate()));
    95     connect(action, SIGNAL(triggered()), this, SLOT(handleStartUpdate()));
    84     connect(action_1, SIGNAL(triggered()), this, SLOT(handleSettings()));
    96     connect(action_1, SIGNAL(triggered()), this, SLOT(handleSettings()));
    85     connect(action_2, SIGNAL(triggered()), this, SLOT(handleDisclaimer()));
    97     connect(action_2, SIGNAL(triggered()), this, SLOT(handleDisclaimer()));
    86 
    98         
       
    99     mContent = qobject_cast< HbWidget*>( loader.findWidget("content") );
       
   100            
    87     mListView = qobject_cast<HbListWidget*>( loader.findWidget("listWidget") );
   101     mListView = qobject_cast<HbListWidget*>( loader.findWidget("listWidget") );
    88     mListView->setSelectionMode( HbAbstractItemView::MultiSelection );
   102     mListView->setSelectionMode( HbAbstractItemView::MultiSelection );
    89     
   103     
    90     connect( mListView, SIGNAL( longPressed( HbAbstractViewItem *, const QPointF & ) ),
   104     connect( mListView, SIGNAL( longPressed( HbAbstractViewItem *, const QPointF & ) ),
    91             this, SLOT( handleDetails( HbAbstractViewItem *, const QPointF & ) ) ); 
   105             this, SLOT( handleDetails( HbAbstractViewItem *, const QPointF & ) ) ); 
    92     
   106         
    93     HbListViewItem *prototype = mListView->listItemPrototype();
   107     HbListViewItem *prototype = mListView->listItemPrototype();
    94 
   108 
    95     prototype->setGraphicsSize(HbListViewItem::LargeIcon);
   109     prototype->setGraphicsSize(HbListViewItem::LargeIcon);
    96 
   110     
       
   111     HbDockWidget *dock = new HbDockWidget(this);
       
   112     HbWidget *dockContainer = new HbWidget(dock);
       
   113     QGraphicsLinearLayout *dockLayout = new QGraphicsLinearLayout(dockContainer);
       
   114     dockLayout->setOrientation(Qt::Vertical);
       
   115     dockContainer->setLayout(dockLayout);
       
   116     
       
   117     mSelections = new HbGroupBox(dockContainer);
       
   118     mSelections->setHeading("Selected 0/0 (0 kB)");
       
   119     
       
   120     dockLayout->addItem( mSelections);
       
   121     
       
   122     dockLayout->addItem(toolBar);
       
   123     
       
   124     dock->setWidget(dockContainer);
       
   125     
       
   126     setDockWidget(dock);
       
   127 
       
   128 
       
   129     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::IAUpdateMainView() end");
    97 }
   130 }
    98     
   131     
    99 IAUpdateMainView::~IAUpdateMainView()
   132 IAUpdateMainView::~IAUpdateMainView()
   100 {
   133 {
       
   134     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::~IAUpdateMainView() begin");
       
   135     
       
   136     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::~IAUpdateMainView() end");
   101 }
   137 }
   102 
   138 
   103 // -----------------------------------------------------------------------------
   139 // -----------------------------------------------------------------------------
   104 // IAUpdateMainView::refresh
   140 // IAUpdateMainView::refresh
   105 // Refreshes update list
   141 // Refreshes update list
   106 // -----------------------------------------------------------------------------
   142 // -----------------------------------------------------------------------------
   107 //    
   143 //    
   108 void IAUpdateMainView::refresh( const RPointerArray<MIAUpdateNode> &nodes,
   144 void IAUpdateMainView::refresh(const RPointerArray<MIAUpdateNode> &nodes,
   109                                 const RPointerArray<MIAUpdateFwNode> &fwNodes,
   145                                const RPointerArray<MIAUpdateFwNode> &fwNodes,
   110                                 int /*error*/ )
   146                                int error)
   111 {   
   147 {   
   112     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh begin");
   148     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh() begin");
   113        
   149     removeCurrentContentLayout();
   114     mAllNodes.Reset();
       
   115         
   150         
   116     if (fwNodes.Count() > 0)
   151     refreshFirmwareUpdates(fwNodes);
   117     {
   152     
   118         IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh hard code importance");
   153     refreshApplicationUpdates(nodes);
   119         //hardcode the importance of firmware as Critical
   154     
   120         for (int i = 0; i < fwNodes.Count(); i++)
   155     if (nodes.Count() == 0 && fwNodes.Count() == 0 && 
   121         {
   156         error != KErrCancel && error != KErrAbort)
   122             fwNodes[i]->Base().SetImportance(MIAUpdateBaseNode::ECritical);
   157     {    
   123         }
   158         if (!mContentDataForm)
   124          
   159         {
   125         //either NSU or FOTA available
   160             mContentDataForm  = new HbDataForm(mContent); 
   126         if (fwNodes.Count() == 1)
   161         }
   127         {
   162         QGraphicsLinearLayout *linearLayout = (QGraphicsLinearLayout*) mContent->layout();
   128             IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh either NSU or FOTA available");
   163         linearLayout->addItem(mContentDataForm);
   129             MIAUpdateAnyNode *node = fwNodes[0];
   164         QString formText;
   130             mAllNodes.Append(node);
       
   131         }
       
   132         
   165         
   133         //both NSU and FOTA available, show only FOTA node
   166         if (error == KErrNone)
   134         if (fwNodes.Count() == 2)
   167         {
   135         {
   168             formText = QString("Applications are up to date");
   136             IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh both NSU and FOTA available");
       
   137             MIAUpdateAnyNode *node1 = fwNodes[0];
       
   138             MIAUpdateFwNode *fwnode = static_cast<MIAUpdateFwNode*>(node1);
       
   139             if (fwnode->FwType() == MIAUpdateFwNode::EFotaDp2)
       
   140             {
       
   141                 mAllNodes.Append(node1);
       
   142             }
       
   143             else
       
   144             {
       
   145                 MIAUpdateAnyNode* node2 = fwNodes[1];
       
   146                 mAllNodes.Append(node2);
       
   147             }
       
   148         }
       
   149     }
       
   150     
       
   151    
       
   152     for(int i = 0; i < nodes.Count(); ++i) 
       
   153     {
       
   154         MIAUpdateAnyNode *node = nodes[i];
       
   155         mAllNodes.Append(node);
       
   156     }
       
   157         
       
   158     mListView->clear();
       
   159     QItemSelectionModel *selectionModel = mListView->selectionModel();  
       
   160     selectionModel->clear();
       
   161     HbIcon icon(QString(":/icons/qgn_menu_swupdate"));
       
   162     
       
   163     for(int j = 0; j < mAllNodes.Count(); ++j) 
       
   164     {
       
   165         MIAUpdateAnyNode *node = mAllNodes[j];
       
   166            
       
   167         QString importanceDescription;
       
   168         MIAUpdateNode::TUIUpdateState uiState = MIAUpdateNode::ENormal;
       
   169         if (node->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal)
       
   170         {
       
   171             MIAUpdateNode *updateNode = static_cast<MIAUpdateNode*>(node);
       
   172             uiState = updateNode->UiState();
       
   173         }
       
   174         if (uiState == MIAUpdateNode::ENormal)
       
   175         {
       
   176             setImportance(node, importanceDescription);
       
   177         }
   169         }
   178         else
   170         else
   179         {
   171         {
   180             if(uiState == MIAUpdateNode::EUpdated)
   172             formText = QString("Refreshing failed. Try again later.");
   181             {
   173         }
   182                 importanceDescription = "Updated";
   174         mContentDataForm->setDescription(formText);
   183             }
   175     }
   184             else if(uiState == MIAUpdateNode::EFailed)
   176     updateSelectionInfoInDock();  
   185             {
   177     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh() end");
   186                 importanceDescription = "Failed";
       
   187             }
       
   188             else if(uiState == MIAUpdateNode::EDownloaded)
       
   189             {
       
   190                 importanceDescription = "Downloaded";
       
   191             }
       
   192         }
       
   193         
       
   194         
       
   195              
       
   196         HbListWidgetItem *item = new HbListWidgetItem();    
       
   197         QString name;
       
   198         if (node->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal)
       
   199         {  
       
   200             MIAUpdateNode *updateNode = static_cast<MIAUpdateNode*>(node);
       
   201             if (updateNode->UiState() == MIAUpdateNode::EDownloading)
       
   202             {
       
   203                 name = QString("Downloading ");
       
   204             }
       
   205             else if (updateNode->UiState() == MIAUpdateNode::EInstalling)
       
   206             {
       
   207                 name = QString("Installing ");
       
   208             }
       
   209         }
       
   210         name.append(XQConversions::s60DescToQString(node->Base().Name()));
       
   211         if (node->NodeType() == MIAUpdateAnyNode::ENodeTypeFw) 
       
   212         {
       
   213             name.append(" DEVICE SOFTWARE");
       
   214         }
       
   215         item->setText(name);
       
   216         item->setSecondaryText(importanceDescription);
       
   217         item->setIcon(icon);
       
   218         mListView->addItem(item); 
       
   219  
       
   220         if (node->Base().IsSelected())
       
   221         {
       
   222             int count = mListView->count();
       
   223             QModelIndex modelIndex = mListView->model()->index(count-1,0);
       
   224             selectionModel->select(modelIndex, QItemSelectionModel::Select);
       
   225         }
       
   226 
       
   227     }
       
   228     connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
       
   229                     this, SLOT(handleSelectionChanged(QItemSelection,QItemSelection)));     
       
   230     
       
   231     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh end");
       
   232 }
   178 }
   233 
   179 
   234 
   180 
   235 
   181 
   236 
   182 
   237 void IAUpdateMainView::handleStartUpdate()
   183 void IAUpdateMainView::handleStartUpdate()
   238 {
   184 {
   239     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleStartUpdate() begin");
   185     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleStartUpdate() begin");
   240     bool firmwareUpdate = false; 
   186     mEngine->StartUpdate(fotaSelected());
   241     RPointerArray<MIAUpdateAnyNode> selectedNodes;
       
   242     getSelectedNodes(selectedNodes);
       
   243     if (selectedNodes.Count() > 0)
       
   244         {
       
   245         if ( selectedNodes[0]->NodeType() == MIAUpdateAnyNode::ENodeTypeFw )
       
   246             {
       
   247             //the marking logic will make sure firmware won't be marked with normal sis updates
       
   248             //at the same time.
       
   249             firmwareUpdate = true;
       
   250             }
       
   251         }
       
   252     selectedNodes.Close();
       
   253     mEngine->StartUpdate(firmwareUpdate);
       
   254     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleStartUpdate() end");
   187     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleStartUpdate() end");
   255 }
   188 }
   256 
   189 
   257 
   190 
   258 void IAUpdateMainView::handleSettings()
   191 void IAUpdateMainView::handleSettings()
   259 {
   192 {
       
   193     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleSettings() begin");
   260     emit toSettingView();
   194     emit toSettingView();
       
   195     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleSettings() end");
   261 }
   196 }
   262 
   197 
   263 void IAUpdateMainView::handleDisclaimer()
   198 void IAUpdateMainView::handleDisclaimer()
   264 {
   199 {
       
   200     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleDisclaimer() begin");
   265     if (!mDialogUtil)
   201     if (!mDialogUtil)
   266     {
   202     {
   267         mDialogUtil = new IAUpdateDialogUtil(this);
   203         mDialogUtil = new IAUpdateDialogUtil(this);
   268     }
   204     }
   269     if (mDialogUtil)
   205     if (mDialogUtil)
   270     {
   206     {
   271         HbAction *primaryAction = new HbAction("OK");
   207         HbAction *primaryAction = new HbAction("OK");
   272         mDialogUtil->showAgreement(primaryAction);
   208         mDialogUtil->showAgreement(primaryAction);
   273     }
   209     }
   274 }
   210     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleDisclaimer() end");
   275 
   211 }
   276 void IAUpdateMainView::handleDetails( HbAbstractViewItem * item, const QPointF & )
   212 
   277 {
   213 void IAUpdateMainView::handleDetails(HbAbstractViewItem * item, const QPointF &)
   278  
   214 {
   279     
   215     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleDetails() begin");
   280     int ind = item->modelIndex().row();
   216     int ind = item->modelIndex().row();
   281     if (getNode(ind) != NULL)
   217     if (getApplicationNode(ind) != NULL)
   282     {    
   218     {    
   283         showDetails(*getNode(ind));
   219         showDetails(*getApplicationNode(ind));
   284     }
   220     }
       
   221     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleDetails() end");
       
   222 }
       
   223 
       
   224 void IAUpdateMainView::handleFotaDetails(HbAbstractViewItem *, const QPointF &)
       
   225 {
       
   226     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleFotaDetails begin");
       
   227     //only one FOTA item in a list, just use it
       
   228     for (int i = 0; i < mFwNodes.Count(); i++)
       
   229     {
       
   230         if (mFwNodes[i]->FwType() == MIAUpdateFwNode::EFotaDp2)
       
   231         {
       
   232             showDetails(*mFwNodes[i]);
       
   233         }
       
   234     }
       
   235     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleFotaDetails end");
   285 }
   236 }
   286 
   237 
   287 
   238 
   288 void IAUpdateMainView::handleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
   239 void IAUpdateMainView::handleSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
   289 {
   240 {
       
   241     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleSelectionChanged begin");
   290     if (!mSelectionUpdate)
   242     if (!mSelectionUpdate)
   291     {
   243     {
   292         bool changedItemFound = false; 
   244         bool changedItemFound = false; 
   293         QModelIndexList indexList = selected.indexes();
   245         QModelIndexList indexList = selected.indexes();
   294         for (int i = 0; !changedItemFound && i < indexList.count(); ++i)
   246         for (int i = 0; !changedItemFound && i < indexList.count(); ++i)
   304                 changedItemFound = true;
   256                 changedItemFound = true;
   305                 markListItem(false, indexList.at(i).row());
   257                 markListItem(false, indexList.at(i).row());
   306             }
   258             }
   307         }
   259         }
   308     }
   260     }
       
   261     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleSelectionChanged end");
       
   262 }
       
   263 
       
   264 void IAUpdateMainView::handleFwSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
       
   265 {
       
   266     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleFwSelectionChanged begin");
       
   267     if (!mSelectionUpdate)
       
   268     {
       
   269         bool changedItemFound = false; 
       
   270         QModelIndexList indexList = selected.indexes();
       
   271         for (int i = 0; !changedItemFound && i < indexList.count(); ++i)
       
   272         {    
       
   273             changedItemFound = true;
       
   274             markFotaItem(true);
       
   275         }
       
   276         if (!changedItemFound)
       
   277         {
       
   278             indexList = deselected.indexes();
       
   279             for (int i = 0; !changedItemFound && i < indexList.count(); ++i)
       
   280             {    
       
   281                 changedItemFound = true;
       
   282                 markFotaItem(false);
       
   283             }
       
   284         }
       
   285     }
       
   286     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleFwSelectionChanged end");
   309 }
   287 }
   310 
   288 
   311 
   289 
   312 void IAUpdateMainView::dialogFinished(HbAction *action)
   290 void IAUpdateMainView::dialogFinished(HbAction *action)
   313 {
   291 {
       
   292     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::dialogFinished begin");
   314     DialogState dialogState = mDialogState;
   293     DialogState dialogState = mDialogState;
   315     mDialogState = NoDialog;
   294     mDialogState = NoDialog;
   316     
   295     
   317     switch ( dialogState )
   296     switch ( dialogState )
   318     {
   297     {
   320             if (action == mPrimaryAction)
   299             if (action == mPrimaryAction)
   321             {
   300             {
   322                 updateSelectionsToNodeArray(*mNode,mMark);
   301                 updateSelectionsToNodeArray(*mNode,mMark);
   323             }
   302             }
   324             updateSelectionsToList();
   303             updateSelectionsToList();
       
   304             updateSelectionInfoInDock();
   325             break;
   305             break;
   326         case CannotOmit:    
   306         case CannotOmit:    
   327             break;
   307             break;
   328         case Details:
   308         case Details:
   329             break; 
   309             break; 
   330         default: 
   310         default: 
   331             break;
   311             break;
   332     }
   312     }
   333 }
   313     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::dialogFinished end");
   334 
   314 }
   335 
   315 
   336 void IAUpdateMainView::getSelectedNodes(RPointerArray<MIAUpdateAnyNode> &selectedNodes) const
   316 bool IAUpdateMainView::fotaSelected() const
   337 {
   317 {
   338     for (int i = 0; i < mAllNodes.Count(); ++i)
   318     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::fotaSelected() begin");
   339     {
   319     bool selected = false;
   340         if (mAllNodes[i]->Base().IsSelected())
   320     for (int i = 0; i < mFwNodes.Count() && !selected; ++i)
   341         {
   321     {
   342             selectedNodes.Append(mAllNodes[i]);
   322         if ( mFwNodes[i]->FwType() == MIAUpdateFwNode::EFotaDp2 && mFwNodes[i]->Base().IsSelected() )
   343         }
   323         {    
   344     }
   324             selected = true;
   345 }
   325         }
       
   326     }
       
   327     if (selected)
       
   328         {
       
   329         IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::fotaSelected() Fota item is selected");
       
   330         }
       
   331     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::fotaSelected() end");
       
   332     return selected;
       
   333 }
       
   334 
       
   335 
   346 
   336 
   347 void IAUpdateMainView::markListItem(bool mark, int index)
   337 void IAUpdateMainView::markListItem(bool mark, int index)
   348 {
   338 {
       
   339     IAUPDATE_TRACE_2("[IAUPDATE] IAUpdateMainView::markListItem() begin mark: %d index %d", mark, index);
   349     if (mark)
   340     if (mark)
   350     {
   341     {
   351         //It's Mark Command
   342         //It's Mark Command
   352         RPointerArray<MIAUpdateAnyNode> selectedNodes;
   343         if (fotaSelected())
   353         getSelectedNodes(selectedNodes); 
   344         {    
       
   345             //FOTA item is selected, unmark FOTA item
       
   346             //FOTA item and application update items can't be selected at the same time 
       
   347             markFotaItem(false);
       
   348         }    
       
   349     }
       
   350        
       
   351     bool accepted = false;
   354         
   352         
   355         //There are selected items already and type are different with the current one
   353     if(index > -1)
   356         if (selectedNodes.Count() > 0 && (mAllNodes[index]->NodeType() != selectedNodes[0]->NodeType()))
   354     {
   357         {       
   355         accepted = true;
   358             // firmware item and normal sis items can't be selected at the same time
   356         MIAUpdateNode* node = mNodes[index];
   359             // unmark the selected nodes.
   357         RPointerArray<MIAUpdateNode> mands;
   360             for (int i = 0; i < selectedNodes.Count(); i++)
   358         RPointerArray<MIAUpdateNode> deps;
   361             {                
       
   362                 int index = mAllNodes.Find(selectedNodes[i]);
       
   363                 mAllNodes[index]->Base().SetSelected(false);
       
   364             }
       
   365         }
       
   366         selectedNodes.Close();
       
   367     }
       
   368     
       
   369     //there is no selected items or the type is the same with the current one
       
   370     
       
   371     if (mAllNodes[index]->NodeType() == MIAUpdateAnyNode::ENodeTypeFw )
       
   372     {
       
   373         mAllNodes[index]->Base().SetSelected(mark);   
       
   374         updateSelectionsToList();
       
   375         return;
       
   376     }
       
   377     
       
   378     if (mAllNodes[index]->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal )
       
   379     {
       
   380         bool accepted = false;
       
   381         
       
   382         if(index > -1)
       
   383         {
       
   384             accepted = true;
       
   385             
       
   386             MIAUpdateNode* node = static_cast<MIAUpdateNode*>(mAllNodes[index]);
       
   387             RPointerArray<MIAUpdateAnyNode> mands;
       
   388             RPointerArray<MIAUpdateNode> deps;
       
   389            
   359            
       
   360         if (mark)
       
   361         {
       
   362             TRAPD(err,IAUpdateDepUtils::GetDependenciesL(*node, mNodes, deps));
       
   363             if (err != KErrNone)
       
   364             {
       
   365                 deps.Close();
       
   366                 updateSelectionsToList();
       
   367                 IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::markListItem() return end");
       
   368                 return;
       
   369             }
       
   370             if (!getMandatoryNodes(mands))
       
   371                 {
       
   372                 // error when creating mandatory node list
       
   373                 mands.Close();
       
   374                 updateSelectionsToList();
       
   375                 IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::markListItem() return end");
       
   376                 return;
       
   377                 }
       
   378         }
       
   379         else
       
   380         {
       
   381             //mandatory item is not allowed to be unmarked
       
   382             if (mNodes[index]->Base().Importance() == MIAUpdateBaseNode::EMandatory)
       
   383             {
       
   384                 //show dialog  
       
   385                 showUpdateCannotOmitDialog();
       
   386                 updateSelectionsToList();
       
   387                 IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::markListItem() return end");
       
   388                 return;
       
   389             }
       
   390             TRAPD(err,IAUpdateDepUtils::GetDependantsL(*node, mNodes, deps));  
       
   391             if (err != KErrNone)
       
   392             {
       
   393                 deps.Close();
       
   394                 updateSelectionsToList();
       
   395                 IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::markListItem() return end");
       
   396                 return;
       
   397             }
       
   398             // item is not allowed to be unmarked if its dependant is mandatory
       
   399             bool mandatoryDependantFound = false;
       
   400             for(int i = 0; i < deps.Count() && !mandatoryDependantFound; i++)
       
   401             {
       
   402                 if (deps[i]->Base().Importance() == MIAUpdateBaseNode::EMandatory)
       
   403                 {
       
   404                     mandatoryDependantFound = true;
       
   405                 }
       
   406             }
       
   407             if (mandatoryDependantFound)
       
   408             {
       
   409                 showUpdateCannotOmitDialog();
       
   410                 deps.Close();
       
   411                 updateSelectionsToList();
       
   412                 IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::markListItem() return end");
       
   413                 return;
       
   414             }
       
   415         }
       
   416              
       
   417         int depCount = deps.Count();
       
   418            
       
   419         if (depCount > 0)
       
   420         {
       
   421             QString text;
       
   422             QString names;
       
   423             MIAUpdateNode* depNode = NULL;
       
   424             QString separator(",");
       
   425                        
       
   426             for(int i = 0; i < depCount; i++)  
       
   427             {
       
   428                 depNode = deps[i];
       
   429                 if (i > 0)
       
   430                 {
       
   431                     names.append(separator);
       
   432                     names.append(QString(" "));
       
   433                 }
       
   434                 names.append(XQConversions::s60DescToQString(depNode->Base().Name()));
       
   435             }
       
   436 
   390             if (mark)
   437             if (mark)
   391             {
   438             {
   392                 TRAPD(err,IAUpdateDepUtils::GetDependenciesL(*node, mAllNodes, deps));
   439                 if (depCount > 1) 
   393                 if (err != KErrNone)
       
   394                 {
   440                 {
   395                     deps.Close();
   441                     text.append("This update needs also updates "); 
   396                     updateSelectionsToList();
   442                     text.append(names);
   397                     return;
   443                     text.append(" for working");
   398                 }
   444                 } 
   399                 if (!getMandatoryNodes(mands))
   445                 else
   400                 {
   446                 {
   401                     // error when creating mandatory node list
   447                     text.append("This update needs also \""); 
   402                     mands.Close();
   448                     text.append(names);
   403                     updateSelectionsToList();
   449                     text.append("\" for working");
   404                     return;
       
   405                 }
       
   406             }
       
   407             else
       
   408             {
       
   409                 //mandatory item is not allowed to be unmarked
       
   410                 if (mAllNodes[index]->Base().Importance() == MIAUpdateBaseNode::EMandatory)
       
   411                 {
       
   412                     //show dialog  
       
   413                     showUpdateCannotOmitDialog();
       
   414                     updateSelectionsToList();
       
   415                     return;
       
   416                 }
       
   417                 
       
   418                 //CleanupClosePushL( deps );
       
   419                 TRAPD(err,IAUpdateDepUtils::GetDependantsL(*node, mAllNodes, deps));  
       
   420                 if (err != KErrNone)
       
   421                 {
       
   422                     deps.Close();
       
   423                     updateSelectionsToList();
       
   424                     return;
       
   425                 }
       
   426                 // item is not allowed to be unmarked if its dependant is mandatory
       
   427                 bool mandatoryDependantFound = false;
       
   428                 for(int i = 0; i < deps.Count() && !mandatoryDependantFound; i++)
       
   429                 {
       
   430                     if (deps[i]->Base().Importance() == MIAUpdateBaseNode::EMandatory)
       
   431                     {
       
   432                         mandatoryDependantFound = true;
       
   433                     }
   450                     }
   434                 }
   451                 }
   435                 if (mandatoryDependantFound)
   452             else
       
   453             {
       
   454                 if (depCount > 1) 
   436                 {
   455                 {
   437                     showUpdateCannotOmitDialog();
   456                     text.append("Updates "); 
   438                     deps.Close();
   457                     text.append(names);
   439                     updateSelectionsToList();
   458                     text.append(" need this update for working");
   440                     return;
   459                 } 
   441                 }
       
   442             }
       
   443              
       
   444             int depCount = deps.Count();
       
   445            
       
   446             if (depCount > 0)
       
   447             {
       
   448                 QString text;
       
   449                 QString names;
       
   450                 MIAUpdateNode* depNode = NULL;
       
   451                 QString separator(",");
       
   452                        
       
   453                 for(int i = 0; i < depCount; i++)  
       
   454                 {
       
   455                     depNode = deps[i];
       
   456                     if (i > 0)
       
   457                     {
       
   458                         names.append(separator);
       
   459                         names.append(QString(" "));
       
   460                     }
       
   461                     names.append(XQConversions::s60DescToQString(depNode->Base().Name()));
       
   462                 }
       
   463                 
       
   464 
       
   465                 if (mark)
       
   466                 {
       
   467                     if (depCount > 1) 
       
   468                     {
       
   469                         text.append("This update needs also updates "); 
       
   470                         text.append(names);
       
   471                         text.append(" for working");
       
   472                         //resourceId = R_IAUPDATE_DEPENDENCY_MARK_MANY;
       
   473                     } 
       
   474                     else
       
   475                     {
       
   476                         text.append("This update needs also \""); 
       
   477                         text.append(names);
       
   478                         text.append("\" for working");
       
   479                         //resourceId = R_IAUPDATE_DEPENDENCY_MARK_ONE;    
       
   480                     }
       
   481                 }
       
   482                 else
   460                 else
   483                 {
   461                 {
   484                     if (depCount > 1) 
   462                     text.append("Update \""); 
   485                     {
   463                     text.append(names);
   486                         text.append("Updates "); 
   464                     text.append("\" needs this update for working");
   487                         text.append(names);
   465                 }   
   488                         text.append(" need this update for working");
   466             }
   489                         //resourceId = R_IAUPDATE_DEPENDENCY_UNMARK_MANY;
       
   490                     } 
       
   491                     else
       
   492                     {
       
   493                         text.append("Update \""); 
       
   494                         text.append(names);
       
   495                         text.append("\" needs this update for working");
       
   496                         //resourceId = R_IAUPDATE_DEPENDENCY_UNMARK_ONE;  
       
   497                     }   
       
   498                 }
       
   499                 
   467                 
   500                 if (mark && mAllNodes[index]->Base().Importance() == MIAUpdateBaseNode::EMandatory)
   468             if (mark && mNodes[index]->Base().Importance() == MIAUpdateBaseNode::EMandatory)
   501                 {
   469             {
   502                     // depencencies of mandatory update are also selected without showing dialog
   470                 // depencencies of mandatory update are also selected without showing dialog
   503                     accepted = true;
   471                 accepted = true;
   504                 }
   472             }
   505                 else
   473             else
   506                 {
   474             {
   507                     mNode = node;
   475                 mNode = node;
   508                     mMark = mark;
   476                 mMark = mark;
   509                     showDependenciesFoundDialog(text);
   477                 accepted = false;
   510                     return;
   478                 showDependenciesFoundDialog(text);
   511                 }
   479             }
   512             }
   480         }
   513             if (accepted)
   481         if (accepted)
   514             {    
   482         {    
   515                 updateSelectionsToNodeArray(*node, mark);   
   483             updateSelectionsToNodeArray(*node, mark);   
   516             }
   484         }
   517         }
   485     }
   518         
   486     if (accepted)
   519     }
   487     {    
   520     updateSelectionsToList();
   488         updateSelectionsToList();
       
   489         updateSelectionInfoInDock();
       
   490     }
       
   491     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::markListItem() end");
   521 }       
   492 }       
   522     
   493 
       
   494 
       
   495 void IAUpdateMainView::markFotaItem(bool mark)
       
   496 {
       
   497     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateMainView::markFotaItem() begin mark: %d", mark);
       
   498     if (mark)
       
   499     {
       
   500         //It's Mark Command
       
   501                 
       
   502         //if some of application update item(s) are selected, unmark them
       
   503         //FOTA item and application update items can't be selected at the same time 
       
   504         bool deselected = false;
       
   505         for (int i = 0; i < mNodes.Count(); ++i)
       
   506         {
       
   507             if (mNodes[i]->Base().IsSelected())
       
   508             {
       
   509                 mNodes[i]->Base().SetSelected(false);
       
   510             }
       
   511         } 
       
   512         if (deselected)
       
   513         {    
       
   514             // umnmarked items to be updated also to UI
       
   515             updateSelectionsToList();
       
   516         }    
       
   517     }
       
   518     for (int j = 0; j < mFwNodes.Count(); ++j)
       
   519     {    
       
   520         if (mFwNodes[j]->FwType() == MIAUpdateFwNode::EFotaDp2)
       
   521         {
       
   522             mFwNodes[j]->Base().SetSelected(mark);
       
   523             if (mark)
       
   524             {
       
   525                 mFwListView->selectionModel()->select(mFwListView->model()->index(0,0),QItemSelectionModel::Select);
       
   526             }
       
   527             else
       
   528             {
       
   529                 mFwListView->selectionModel()->select(mFwListView->model()->index(0,0),QItemSelectionModel::Deselect);
       
   530             }
       
   531         }
       
   532     }
       
   533     updateSelectionInfoInDock();
       
   534     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::markFotaItem() end");
       
   535 }
       
   536 
       
   537 
       
   538 
       
   539 
       
   540 
   523 void IAUpdateMainView::updateSelectionsToNodeArray(MIAUpdateNode &node, bool mark)   
   541 void IAUpdateMainView::updateSelectionsToNodeArray(MIAUpdateNode &node, bool mark)   
   524 {    
   542 {
       
   543     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::updateSelectionsToNodeArray() begin");
   525     RPointerArray<MIAUpdateNode> deps;  
   544     RPointerArray<MIAUpdateNode> deps;  
   526     TInt err = KErrNone;
   545     TInt err = KErrNone;
   527     if (mark)
   546     if (mark)
   528     {
   547     {
   529         TRAP(err,IAUpdateDepUtils::GetDependenciesL(node, mAllNodes, deps));
   548         TRAP(err,IAUpdateDepUtils::GetDependenciesL(node, mNodes, deps));
   530     }
   549     }
   531     else
   550     else
   532     {
   551     {
   533         TRAP(err,IAUpdateDepUtils::GetDependantsL(node, mAllNodes, deps)); 
   552         TRAP(err,IAUpdateDepUtils::GetDependantsL(node, mNodes, deps)); 
   534     }
   553     }
   535     if (err  == KErrNone )
   554     if (err  == KErrNone )
   536     {    
   555     {    
   537         int depCount = deps.Count(); 
   556         int depCount = deps.Count(); 
   538         for(int i = 0; i < depCount; i++)
   557         for(int i = 0; i < depCount; i++)
   539         {
   558         {
   540             int depNodeInd = mAllNodes.Find(deps[i]);
   559             int depNodeInd = mNodes.Find(deps[i]);
   541             mAllNodes[depNodeInd]->Base().SetSelected(mark);
   560             mNodes[depNodeInd]->Base().SetSelected(mark);
   542         }
   561         }
   543         deps.Close();
   562         deps.Close();
   544         int nodeInd = mAllNodes.Find(&node);
   563         int nodeInd = mNodes.Find(&node);
   545         mAllNodes[nodeInd]->Base().SetSelected(mark);
   564         mNodes[nodeInd]->Base().SetSelected(mark);
   546     }                
   565     }                
   547     
   566     
   548     //mark all of the mandatory items
   567     //mark all of the mandatory items
   549     if ( mark )
   568     if ( mark )
   550     {    
   569     {    
   551         RPointerArray<MIAUpdateAnyNode> mands;    
   570         RPointerArray<MIAUpdateNode> mands;    
   552         if (getMandatoryNodes(mands))
   571         if (getMandatoryNodes(mands))
   553         {
   572         {
   554             int mandCount = mands.Count();
   573             int mandCount = mands.Count();
   555             if (mandCount > 0)
   574             if (mandCount > 0)
   556             {
   575             {
   557                 for(int i = 0; i < mandCount; i++)
   576                 for(int i = 0; i < mandCount; i++)
   558                 {
   577                 {
   559                     int mandNodeInd = mAllNodes.Find(mands[i]);
   578                     int mandNodeInd = mNodes.Find(mands[i]);
   560                     mAllNodes[mandNodeInd]->Base().SetSelected(mark);
   579                     mNodes[mandNodeInd]->Base().SetSelected(mark);
   561                     if (mAllNodes[mandNodeInd]->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal)
   580                     if (mNodes[mandNodeInd]->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal)
   562                     {
   581                     {
   563                         // mark also all dependencies of a mandatory item
   582                         // mark also all dependencies of a mandatory item
   564                         MIAUpdateNode* dependencyNode = static_cast<MIAUpdateNode*>(mAllNodes[mandNodeInd]);
   583                         MIAUpdateNode* dependencyNode = mNodes[mandNodeInd];
   565                         RPointerArray<MIAUpdateNode> dependencies;
   584                         RPointerArray<MIAUpdateNode> dependencies;
   566                         TRAPD(err,IAUpdateDepUtils::GetDependenciesL(*dependencyNode, mAllNodes, dependencies));
   585                         TRAPD(err,IAUpdateDepUtils::GetDependenciesL(*dependencyNode, mNodes, dependencies));
   567                         if (err)
   586                         if (err)
   568                         {
   587                         {
   569                             dependencies.Close(); 
   588                             dependencies.Close(); 
   570                             mands.Close();
   589                             mands.Close();
   571                             return;
   590                             return;
   572                         }
   591                         }
   573                         for(int j = 0; j < dependencies.Count(); j++)
   592                         for(int j = 0; j < dependencies.Count(); j++)
   574                         {
   593                         {
   575                             int depNodeInd = mAllNodes.Find(dependencies[j]);
   594                             int depNodeInd = mNodes.Find(dependencies[j]);
   576                             mAllNodes[depNodeInd]->Base().SetSelected(true);
   595                             mNodes[depNodeInd]->Base().SetSelected(true);
   577                         }
   596                         }
   578                         dependencies.Close();
   597                         dependencies.Close();
   579                     }
   598                     }
   580                 }
   599                 }
   581             }
   600             }
   582         }
   601         }
   583         mands.Close();
   602         mands.Close();
   584     }  
   603     }
   585 }
   604     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::updateSelectionsToNodeArray() end");
   586 
   605 }
   587 
   606 
   588 bool IAUpdateMainView::getMandatoryNodes(RPointerArray<MIAUpdateAnyNode> &mandNodes) const
   607 
   589 {
   608 bool IAUpdateMainView::getMandatoryNodes(RPointerArray<MIAUpdateNode> &mandNodes) const
       
   609 {
       
   610     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::getMandatoryNodes() begin");
   590     bool ret = true;
   611     bool ret = true;
   591     for(int i = 0; i < mAllNodes.Count(); ++i)
   612     for(int i = 0; i < mNodes.Count(); ++i)
   592     {
   613     {
   593         if (mAllNodes[i]->Base().Importance() == MIAUpdateBaseNode::EMandatory)
   614         if (mNodes[i]->Base().Importance() == MIAUpdateBaseNode::EMandatory)
   594         {
   615         {
   595             if (mandNodes.Append(mAllNodes[i]) != KErrNone)
   616             if (mandNodes.Append(mNodes[i]) != KErrNone)
   596             {
   617             {
   597                 ret = false; 
   618                 ret = false; 
   598             }
   619             }
   599         }
   620         }
   600     }
   621     }
       
   622     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::getMandatoryNodes() end");
   601     return ret;
   623     return ret;
   602 }
   624 }
   603 
   625 
   604 void IAUpdateMainView::showUpdateCannotOmitDialog()
   626 void IAUpdateMainView::showUpdateCannotOmitDialog()
   605 {
   627 {
       
   628     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::showUpdateCannotOmitDialog() begin");
   606     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeInformation);
   629     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeInformation);
   607     messageBox->setText(QString("This required update cannot be omitted"));
   630     messageBox->setText(QString("This required update cannot be omitted"));
   608     int actionCount = messageBox->actions().count();
   631     int actionCount = messageBox->actions().count();
   609     for (int i=actionCount-1; i >= 0; i--)
   632     for (int i=actionCount-1; i >= 0; i--)
   610     { 
   633     { 
   615     messageBox->addAction(okAction);
   638     messageBox->addAction(okAction);
   616     messageBox->setTimeout(HbPopup::StandardTimeout);
   639     messageBox->setTimeout(HbPopup::StandardTimeout);
   617     messageBox->setAttribute(Qt::WA_DeleteOnClose);
   640     messageBox->setAttribute(Qt::WA_DeleteOnClose);
   618     mDialogState = CannotOmit;
   641     mDialogState = CannotOmit;
   619     messageBox->open(this, SLOT(dialogFinished(HbAction*)));
   642     messageBox->open(this, SLOT(dialogFinished(HbAction*)));
       
   643     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::showUpdateCannotOmitDialog() end");
   620 }
   644 }
   621 
   645 
   622 void IAUpdateMainView::showDependenciesFoundDialog(QString &text)
   646 void IAUpdateMainView::showDependenciesFoundDialog(QString &text)
   623 {
   647 {
       
   648     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::showDependenciesFoundDialog() begin");
   624     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   649     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   625     HbLabel *label = new HbLabel(messageBox);
   650     HbLabel *label = new HbLabel(messageBox);
   626     label->setHtml(QString("Depencencies"));
   651     label->setHtml(QString("Depencencies"));
   627     messageBox->setHeadingWidget(label);
   652     messageBox->setHeadingWidget(label);
   628     //messageBox->setIconVisible(false);
   653     //messageBox->setIconVisible(false);
   641     messageBox->addAction(secondaryAction);
   666     messageBox->addAction(secondaryAction);
   642     messageBox->setTimeout(HbPopup::NoTimeout);
   667     messageBox->setTimeout(HbPopup::NoTimeout);
   643     messageBox->setAttribute(Qt::WA_DeleteOnClose);
   668     messageBox->setAttribute(Qt::WA_DeleteOnClose);
   644     mDialogState = Dependencies;
   669     mDialogState = Dependencies;
   645     messageBox->open(this, SLOT(dialogFinished(HbAction*)));
   670     messageBox->open(this, SLOT(dialogFinished(HbAction*)));
       
   671     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::showDependenciesFoundDialog() end");
   646 }
   672 }
   647 
   673 
   648 void IAUpdateMainView::updateSelectionsToList()
   674 void IAUpdateMainView::updateSelectionsToList()
   649 {
   675 {
       
   676     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::updateSelectionsToList() begin");
   650     mSelectionUpdate = true;
   677     mSelectionUpdate = true;
   651     for(int i = 0; i < mAllNodes.Count(); ++i)
   678     for(int i = 0; i < mNodes.Count(); ++i)
   652     {
   679     {
   653         if ( mAllNodes[i]->Base().IsSelected() != mListView->selectionModel()->isSelected(mListView->model()->index(i,0)))
   680         if ( mNodes[i]->Base().IsSelected() != mListView->selectionModel()->isSelected(mListView->model()->index(i,0)))
   654         {    
   681         {    
   655             QItemSelectionModel::SelectionFlag selectionFlag;
   682             QItemSelectionModel::SelectionFlag selectionFlag;
   656             if ( mAllNodes[i]->Base().IsSelected())
   683             if ( mNodes[i]->Base().IsSelected())
   657             {
   684             {
   658                 selectionFlag = QItemSelectionModel::Select;
   685                 selectionFlag = QItemSelectionModel::Select;
   659             }
   686             }
   660             else
   687             else
   661             {
   688             {
   663             }
   690             }
   664             mListView->selectionModel()->select(mListView->model()->index(i,0),selectionFlag);   
   691             mListView->selectionModel()->select(mListView->model()->index(i,0),selectionFlag);   
   665         }
   692         }
   666     }
   693     }
   667     mSelectionUpdate = false;
   694     mSelectionUpdate = false;
   668 }
   695     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::updateSelectionsToList() end");
   669 
   696 }
   670 
   697 
   671 MIAUpdateAnyNode* IAUpdateMainView::getNode(int index) const
   698 
   672 {
   699 MIAUpdateNode* IAUpdateMainView::getApplicationNode(int index) const
   673     MIAUpdateAnyNode *currentNode = NULL;
   700 {
       
   701     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateMainView::getApplicationNode() begin index: %d", index);
       
   702     MIAUpdateNode *currentNode = NULL;
   674      
   703      
   675     if (index >= 0 && index < mAllNodes.Count())
   704     if (index >= 0 && index < mNodes.Count())
   676     {
   705     {
   677         currentNode = mAllNodes[index];
   706         currentNode = mNodes[index];
   678     }
   707     }
       
   708     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::getApplicationNode() end");
   679     return currentNode;
   709     return currentNode;
   680 }
   710 }
   681                 
   711                 
   682 void IAUpdateMainView::showDetails(MIAUpdateAnyNode& node)
   712 void IAUpdateMainView::showDetails(MIAUpdateAnyNode& node)
   683 {  
   713 {  
       
   714     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::showDetails() begin");
   684     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeInformation);
   715     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeInformation);
   685     HbLabel *label = new HbLabel(messageBox);
   716     HbLabel *label = new HbLabel(messageBox);
   686     label->setHtml(QString("Details"));
   717     label->setHtml(QString("Details"));
   687     messageBox->setHeadingWidget(label);
   718     messageBox->setHeadingWidget(label);
   688        
   719        
   692     constructDetailsText(node,text); 
   723     constructDetailsText(node,text); 
   693     messageBox->setText(text);
   724     messageBox->setText(text);
   694     messageBox->setTimeout(HbPopup::NoTimeout);
   725     messageBox->setTimeout(HbPopup::NoTimeout);
   695     messageBox->setAttribute(Qt::WA_DeleteOnClose);
   726     messageBox->setAttribute(Qt::WA_DeleteOnClose);
   696     mDialogState = Details;
   727     mDialogState = Details;
   697     messageBox->open(this, SLOT(dialogFinished(HbAction*)));                
   728     messageBox->open(this, SLOT(dialogFinished(HbAction*)));    
       
   729     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::showDetails() end");
   698 }                
   730 }                
   699         
   731         
   700 
   732 
   701 void IAUpdateMainView::constructDetailsText(MIAUpdateAnyNode &node, QString &text)
   733 void IAUpdateMainView::constructDetailsText(MIAUpdateAnyNode &node, QString &text)
   702 {
   734 {
   703     
   735     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::constructDetailsText() begin");
   704     text.append(QString("Name:"));
   736     text.append(QString("Name:"));
   705     text.append(QString("<br />"));
   737     text.append(QString("<br />"));
   706     QString name = XQConversions::s60DescToQString(node.Base().Name());
   738     QString name = XQConversions::s60DescToQString(node.Base().Name());
   707     text.append(name);
   739     text.append(name);
   708     if (node.NodeType() == MIAUpdateAnyNode::ENodeTypeFw)
   740     if (node.NodeType() == MIAUpdateAnyNode::ENodeTypeFw)
   761         text.append(QString("<br />"));
   793         text.append(QString("<br />"));
   762         QString textFileSize;
   794         QString textFileSize;
   763         fileSizeText(contentSize, textFileSize);
   795         fileSizeText(contentSize, textFileSize);
   764         text.append(textFileSize);
   796         text.append(textFileSize);
   765     }
   797     }
       
   798     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::constructDetailsText() end");
   766 }
   799 }
   767 
   800 
   768 void IAUpdateMainView::versionText(const TIAUpdateVersion &version, QString &versionText)
   801 void IAUpdateMainView::versionText(const TIAUpdateVersion &version, QString &versionText)
   769 {
   802 {
       
   803     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::versionText() begin");
   770     QString stringMajor;
   804     QString stringMajor;
   771     stringMajor.setNum(version.iMajor);
   805     stringMajor.setNum(version.iMajor);
   772     versionText.append(stringMajor);
   806     versionText.append(stringMajor);
   773     versionText.append(QString("."));
   807     versionText.append(QString("."));
   774     QString stringMinor;
   808     QString stringMinor;
   777     versionText.append(QString("("));
   811     versionText.append(QString("("));
   778     QString stringBuild;
   812     QString stringBuild;
   779     stringBuild.setNum(version.iBuild);
   813     stringBuild.setNum(version.iBuild);
   780     versionText.append(stringBuild);
   814     versionText.append(stringBuild);
   781     versionText.append(QString(")"));
   815     versionText.append(QString(")"));
       
   816     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::versionText() end");
   782 }
   817 }
   783 
   818 
   784 void IAUpdateMainView::fileSizeText(int fileSize, QString &text)
   819 void IAUpdateMainView::fileSizeText(int fileSize, QString &text)
   785 {
   820 {
       
   821     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::fileSizeText() begin");
   786     int size = 0;
   822     int size = 0;
   787     QString stringUnit;
   823     QString stringUnit;
   788     
   824     
   789     if (fileSize >= KMaxShownInKiloBytes )
   825     if (fileSize >= KMaxShownInKiloBytes )
   790         {
   826         {
   804             size++;
   840             size++;
   805             }   
   841             }   
   806         }
   842         }
   807     text.setNum(size);
   843     text.setNum(size);
   808     text.append(stringUnit); 
   844     text.append(stringUnit); 
       
   845     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::fileSizeText() end");
   809 }
   846 }
   810 
   847 
   811 void IAUpdateMainView::setImportance(MIAUpdateAnyNode *node, QString &importanceDescription)
   848 void IAUpdateMainView::setImportance(MIAUpdateAnyNode *node, QString &importanceDescription)
   812 {
   849 {
       
   850     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::setImportance() begin");
   813     int sizeInBytes = node->Base().ContentSizeL();
   851     int sizeInBytes = node->Base().ContentSizeL();
   814     int size = 0;
   852     int size = 0;
   815     bool shownInMegabytes = false;        
   853     bool shownInMegabytes = false;        
   816     if (sizeInBytes >= KMaxShownInKiloBytes)
   854     if (sizeInBytes >= KMaxShownInKiloBytes)
   817     {
   855     {
   913         default:
   951         default:
   914         {
   952         {
   915             break;
   953             break;
   916         }
   954         }
   917     }
   955     }
       
   956     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::setImportance() end");
   918 }    
   957 }    
   919 
   958 
       
   959 void IAUpdateMainView::removeCurrentContentLayout()
       
   960 {
       
   961     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::removeCurrentContentLayout() begin");
       
   962     int itemCount = mContent->layout()->count();
       
   963     for (int i = 0; i < itemCount; i++)    
       
   964     {
       
   965         mContent->layout()->removeAt(i);
       
   966     }
       
   967     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::removeCurrentContentLayout() end");    
       
   968 }
       
   969 
       
   970 void IAUpdateMainView::refreshFirmwareUpdates(const RPointerArray<MIAUpdateFwNode> &fwNodes)
       
   971 {
       
   972     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refreshFirmwareUpdates() begin");
       
   973     mFwNodes.Reset();
       
   974             
       
   975     for (int i = 0; i < fwNodes.Count(); i++)
       
   976     {
       
   977         MIAUpdateFwNode *fwnode = (fwNodes[i]);
       
   978         mFwNodes.Append(fwnode);
       
   979         fwnode->Base().SetImportance(MIAUpdateBaseNode::ECritical);
       
   980         if (fwnode->FwType() == MIAUpdateFwNode::EFotaDp2)
       
   981         {
       
   982             refreshFotaUpdate(*fwnode );
       
   983         }
       
   984         else if (fwNodes.Count() == 1 && fwnode->FwType() == MIAUpdateFwNode::EFotiNsu)
       
   985         {
       
   986             refreshNsuUpdate();
       
   987         }
       
   988     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refreshFirmwareUpdates() end");    
       
   989     }    
       
   990 }
       
   991 
       
   992 void IAUpdateMainView::refreshFotaUpdate(MIAUpdateFwNode& fwNode)
       
   993 {
       
   994     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refreshFotaUpdate() begin");
       
   995     if (!mFwListView)
       
   996     {
       
   997         mFwListView  = new HbListWidget(mContent);
       
   998         mFwListView->setSelectionMode( HbAbstractItemView::MultiSelection );
       
   999         connect( mFwListView, SIGNAL( longPressed( HbAbstractViewItem *, const QPointF & ) ),
       
  1000         this, SLOT( handleFotaDetails( HbAbstractViewItem *, const QPointF & ) ) ); 
       
  1001         mFwListView->listItemPrototype()->setGraphicsSize(HbListViewItem::LargeIcon);   
       
  1002         mFwListView->listItemPrototype()->setStretchingStyle(HbListViewItem::NoStretching);
       
  1003         connect(mFwListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
       
  1004         this, SLOT(handleFwSelectionChanged(QItemSelection,QItemSelection)));     
       
  1005     }
       
  1006     QGraphicsLinearLayout *linearLayout = (QGraphicsLinearLayout*) mContent->layout();
       
  1007     linearLayout->addItem(mFwListView);
       
  1008     mFwListView->clear();
       
  1009     QItemSelectionModel *selectionModel = mFwListView->selectionModel();  
       
  1010     selectionModel->clear();
       
  1011     HbListWidgetItem *fwItem = new HbListWidgetItem();
       
  1012     QString name(XQConversions::s60DescToQString(fwNode.Base().Name()));
       
  1013     name.append(" DEVICE SOFTWARE");
       
  1014     fwItem->setText(name);
       
  1015     QString importanceDescription;
       
  1016     setImportance(&fwNode, importanceDescription);
       
  1017     fwItem->setSecondaryText(importanceDescription);
       
  1018     HbIcon icon(QString(":/icons/qgn_menu_swupdate"));
       
  1019     fwItem->setIcon(icon);
       
  1020     if (fwNode.Base().IsSelected())
       
  1021     {
       
  1022         QModelIndex modelIndex = mFwListView->model()->index(0,0);
       
  1023         selectionModel->select(modelIndex, QItemSelectionModel::Select);
       
  1024     }
       
  1025     mFwListView->addItem(fwItem); 
       
  1026     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refreshFotaUpdate() end");
       
  1027 }
       
  1028 
       
  1029 void IAUpdateMainView::refreshNsuUpdate()
       
  1030 {
       
  1031     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refreshNsuUpdate() begin");
       
  1032     if (!mFwNSUGroupBox)
       
  1033     {
       
  1034         mFwNSUGroupBox = new HbGroupBox(mContent);
       
  1035         mFwNSUGroupBox->setHeading("Device software available");
       
  1036         HbDataForm *dataForm  = new HbDataForm(mFwNSUGroupBox); 
       
  1037         mFwNSUGroupBox->setContentWidget(dataForm);
       
  1038         dataForm->setDescription("Use your PC to update the device software ([version %L]) from address www.nokia.com/softwareupdate");
       
  1039     }
       
  1040     QGraphicsLinearLayout *linearLayout = (QGraphicsLinearLayout*) mContent->layout();
       
  1041     linearLayout->addItem(mFwNSUGroupBox);
       
  1042     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refreshNsuUpdate() end");
       
  1043 }
       
  1044 
       
  1045 void IAUpdateMainView::refreshApplicationUpdates(const RPointerArray<MIAUpdateNode> &nodes)
       
  1046 {
       
  1047     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refreshApplicationUpdates() begin");
       
  1048     if (nodes.Count() > 0)
       
  1049     {
       
  1050         if (!mApplicationUpdatesGroupBox)
       
  1051         {
       
  1052             mApplicationUpdatesGroupBox = new HbGroupBox(mContent);
       
  1053             mApplicationUpdatesGroupBox->setHeading("Application updates");
       
  1054         }
       
  1055         QGraphicsLinearLayout *linearLayout = (QGraphicsLinearLayout*) mContent->layout();
       
  1056         linearLayout->addItem(mApplicationUpdatesGroupBox);
       
  1057         linearLayout->addItem(mListView);
       
  1058     }
       
  1059     mListView->clear();
       
  1060     QItemSelectionModel *selectionModel = mListView->selectionModel();  
       
  1061     selectionModel->clear();
       
  1062     HbIcon icon(QString(":/icons/qgn_menu_swupdate"));
       
  1063     mNodes.Reset();
       
  1064     for(int i = 0; i < nodes.Count(); ++i) 
       
  1065     {
       
  1066         MIAUpdateNode *node = nodes[i];
       
  1067         mNodes.Append(node);
       
  1068         QString importanceDescription;
       
  1069         MIAUpdateNode::TUIUpdateState uiState = node->UiState();
       
  1070         if (uiState == MIAUpdateNode::ENormal)
       
  1071         {
       
  1072             setImportance(node, importanceDescription);
       
  1073         }
       
  1074         else if (uiState == MIAUpdateNode::EUpdated)
       
  1075         {
       
  1076             importanceDescription = "Updated";
       
  1077         }
       
  1078         else if (uiState == MIAUpdateNode::EFailed)
       
  1079         {
       
  1080             importanceDescription = "Failed";
       
  1081         }
       
  1082         else if (uiState == MIAUpdateNode::EDownloaded)
       
  1083         {
       
  1084             importanceDescription = "Downloaded";
       
  1085         }
       
  1086         HbListWidgetItem *item = new HbListWidgetItem();    
       
  1087         QString name;
       
  1088         if (uiState == MIAUpdateNode::EDownloading)
       
  1089         {
       
  1090             name = QString("Downloading ");
       
  1091         }
       
  1092         else if (uiState == MIAUpdateNode::EInstalling)
       
  1093         {
       
  1094             name = QString("Installing ");
       
  1095         }
       
  1096         name.append(XQConversions::s60DescToQString(node->Base().Name()));
       
  1097         item->setText(name);
       
  1098         item->setSecondaryText(importanceDescription);
       
  1099         item->setIcon(icon);
       
  1100         mListView->addItem(item); 
       
  1101          
       
  1102         if (node->Base().IsSelected())
       
  1103         {
       
  1104             int count = mListView->count();
       
  1105             QModelIndex modelIndex = mListView->model()->index(count-1,0);
       
  1106             selectionModel->select(modelIndex, QItemSelectionModel::Select);
       
  1107         }
       
  1108     }
       
  1109     if (!mSelectionConnect)
       
  1110     {    
       
  1111         mSelectionConnect = connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
       
  1112                         this, SLOT(handleSelectionChanged(QItemSelection,QItemSelection)));     
       
  1113     }
       
  1114     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refreshApplicationUpdates() end");
       
  1115 }
       
  1116 
       
  1117 void IAUpdateMainView::updateSelectionInfoInDock()
       
  1118 {
       
  1119     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::updateSelectionInfoInDock() begin");
       
  1120     int countOfSelectedItems = 0;
       
  1121     int countOfAllItems = 0;
       
  1122     int selectedSizeInBytes = 0;
       
  1123     for (int i = 0; i < mFwNodes.Count(); ++i)
       
  1124     {
       
  1125         if (mFwNodes[i]->FwType() == MIAUpdateFwNode::EFotaDp2)
       
  1126         {
       
  1127             countOfAllItems++;
       
  1128             if (mFwNodes[i]->Base().IsSelected())
       
  1129             {
       
  1130                 countOfSelectedItems++;
       
  1131                 selectedSizeInBytes += mFwNodes[i]->Base().ContentSizeL();
       
  1132             }
       
  1133         }
       
  1134     } 
       
  1135     countOfAllItems += mNodes.Count();
       
  1136     for (int j = 0; j < mNodes.Count(); ++j)
       
  1137     {    
       
  1138         if (mNodes[j]->Base().IsSelected())
       
  1139         {
       
  1140             countOfSelectedItems++;
       
  1141             selectedSizeInBytes += mNodes[j]->Base().ContentSizeL();
       
  1142         }
       
  1143     }    
       
  1144     
       
  1145     int selectedSize = 0;
       
  1146     QString unit;
       
  1147     if (selectedSizeInBytes >= KMaxShownInKiloBytes)
       
  1148     {
       
  1149         unit = "MB";
       
  1150         selectedSize = selectedSizeInBytes / KMegaByte;
       
  1151         if (selectedSizeInBytes % KMegaByte != 0)
       
  1152         {
       
  1153             selectedSize++;
       
  1154         }
       
  1155     }
       
  1156     else 
       
  1157     {
       
  1158         unit = "kB";
       
  1159         selectedSize = selectedSizeInBytes / KKiloByte;
       
  1160         if (selectedSizeInBytes % KKiloByte != 0)
       
  1161         {
       
  1162             selectedSize++;
       
  1163         }
       
  1164     }
       
  1165     QString selectionString; 
       
  1166     selectionString.append("Selected ");
       
  1167     QString numText;
       
  1168     numText.setNum(countOfSelectedItems);
       
  1169     selectionString.append(numText);
       
  1170     selectionString.append("/");
       
  1171     numText.setNum(countOfAllItems);
       
  1172     selectionString.append(numText);
       
  1173     if (selectedSize > 0)
       
  1174     {
       
  1175         selectionString.append(" (");
       
  1176         numText.setNum(selectedSize);
       
  1177         selectionString.append(numText);
       
  1178         selectionString.append(" ");
       
  1179         selectionString.append(unit);
       
  1180         selectionString.append(")");
       
  1181     }
       
  1182     mSelections->setHeading(selectionString);
       
  1183     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::updateSelectionInfoInDock() end");
       
  1184 }