iaupdate/IAD/ui/src/iaupdatemainview.cpp
changeset 52 92f864ef0288
parent 42 d17dc5398051
child 53 ae54820ef82c
equal deleted inserted replaced
42:d17dc5398051 52:92f864ef0288
    25 #include <hbtoolbar.h>
    25 #include <hbtoolbar.h>
    26 #include <hbmenu.h>
    26 #include <hbmenu.h>
    27 #include <hbdocumentloader.h>
    27 #include <hbdocumentloader.h>
    28 #include <xqconversions.h>
    28 #include <xqconversions.h>
    29 #include <hbmessagebox.h>
    29 #include <hbmessagebox.h>
    30 #include <hbtextitem.h>
    30 #include <hblabel.h>
    31 
    31 
    32 #include "iaupdatemainview.h"
    32 #include "iaupdatemainview.h"
    33 #include "iaupdateengine.h"
    33 #include "iaupdateengine.h"
    34 #include "iaupdateagreement.h"
    34 #include "iaupdateagreement.h"
    35 #include "iaupdatedeputils.h"
    35 #include "iaupdatedeputils.h"
   106 // -----------------------------------------------------------------------------
   106 // -----------------------------------------------------------------------------
   107 //    
   107 //    
   108 void IAUpdateMainView::refresh( const RPointerArray<MIAUpdateNode> &nodes,
   108 void IAUpdateMainView::refresh( const RPointerArray<MIAUpdateNode> &nodes,
   109                                 const RPointerArray<MIAUpdateFwNode> &fwNodes,
   109                                 const RPointerArray<MIAUpdateFwNode> &fwNodes,
   110                                 int /*error*/ )
   110                                 int /*error*/ )
   111     {   
   111 {   
   112     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh begin");
   112     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh begin");
   113        
   113        
   114     mAllNodes.Reset();
   114     mAllNodes.Reset();
   115         
   115         
   116     if ( fwNodes.Count() > 0 )
   116     if (fwNodes.Count() > 0)
   117         {
   117     {
   118         IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh hard code importance");
   118         IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh hard code importance");
   119         //hardcode the importance of firmware as Critical
   119         //hardcode the importance of firmware as Critical
   120         for ( TInt i = 0; i < fwNodes.Count(); i++ )
   120         for (int i = 0; i < fwNodes.Count(); i++)
   121              {
   121         {
   122              fwNodes[i]->Base().SetImportance( MIAUpdateBaseNode::ECritical );
   122             fwNodes[i]->Base().SetImportance(MIAUpdateBaseNode::ECritical);
   123              }
   123         }
   124          
   124          
   125         //either NSU or FOTA available
   125         //either NSU or FOTA available
   126         if ( fwNodes.Count() == 1 )
   126         if (fwNodes.Count() == 1)
   127             {
   127         {
   128             IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh either NSU or FOTA available");
   128             IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh either NSU or FOTA available");
   129             MIAUpdateAnyNode* node = fwNodes[0];
   129             MIAUpdateAnyNode *node = fwNodes[0];
   130             mAllNodes.Append( node );
   130             mAllNodes.Append(node);
   131             }
   131         }
   132         
   132         
   133         //both NSU and FOTA available, show only FOTA node
   133         //both NSU and FOTA available, show only FOTA node
   134         if ( fwNodes.Count() == 2 )
   134         if (fwNodes.Count() == 2)
   135             {
   135         {
   136             IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh both NSU and FOTA available");
   136             IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh both NSU and FOTA available");
   137             MIAUpdateAnyNode* node1 = fwNodes[0];
   137             MIAUpdateAnyNode *node1 = fwNodes[0];
   138             MIAUpdateFwNode* fwnode = static_cast<MIAUpdateFwNode*>( node1 );
   138             MIAUpdateFwNode *fwnode = static_cast<MIAUpdateFwNode*>(node1);
   139             if ( fwnode->FwType() == MIAUpdateFwNode::EFotaDp2  )
   139             if (fwnode->FwType() == MIAUpdateFwNode::EFotaDp2)
   140                 {
   140             {
   141                 mAllNodes.Append( node1 );
   141                 mAllNodes.Append(node1);
   142                 }
   142             }
   143             else
   143             else
   144                 {
   144             {
   145                 MIAUpdateAnyNode* node2 = fwNodes[1];
   145                 MIAUpdateAnyNode* node2 = fwNodes[1];
   146                 mAllNodes.Append( node2 );
   146                 mAllNodes.Append(node2);
   147                 }
   147             }
   148             }
   148         }
   149         }
   149     }
   150     
   150     
   151    
   151    
   152     for( int i = 0; i < nodes.Count(); ++i ) 
   152     for(int i = 0; i < nodes.Count(); ++i) 
   153         {
   153     {
   154         MIAUpdateAnyNode* node = nodes[i];
   154         MIAUpdateAnyNode *node = nodes[i];
   155         mAllNodes.Append( node );
   155         mAllNodes.Append(node);
   156         }
   156     }
   157         
   157         
   158     mListView->clear();
   158     mListView->clear();
   159     QItemSelectionModel *selectionModel = mListView->selectionModel();  
   159     QItemSelectionModel *selectionModel = mListView->selectionModel();  
   160     selectionModel->clear();
   160     selectionModel->clear();
   161     HbIcon icon(QString(":/icons/qgn_menu_swupdate"));
   161     HbIcon icon(QString(":/icons/qgn_menu_swupdate"));
   162     
   162     
   163     for( int j = 0; j < mAllNodes.Count(); ++j ) 
   163     for(int j = 0; j < mAllNodes.Count(); ++j) 
   164         {
   164     {
   165         MIAUpdateAnyNode* node = mAllNodes[j];
   165         MIAUpdateAnyNode *node = mAllNodes[j];
   166         int sizeInBytes = node->Base().ContentSizeL();
   166            
   167 
       
   168         int size = 0;
       
   169         TBool shownInMegabytes = EFalse;        
       
   170         if ( sizeInBytes >= KMaxShownInKiloBytes )
       
   171             {
       
   172             shownInMegabytes = ETrue;
       
   173             size = sizeInBytes / KMegaByte;
       
   174             if ( sizeInBytes % KMegaByte != 0 )
       
   175                 {
       
   176                 size++;
       
   177                 }
       
   178             }
       
   179         else 
       
   180             {
       
   181             size = sizeInBytes / KKiloByte;
       
   182             if ( sizeInBytes % KKiloByte != 0 )
       
   183                 {
       
   184                 size++;
       
   185                 }  
       
   186             }
       
   187         QString sizeString;
       
   188         sizeString.setNum(size);        
       
   189         QString importanceDescription;
   167         QString importanceDescription;
   190         switch( node->Base().Importance() )
   168         MIAUpdateNode::TUIUpdateState uiState = MIAUpdateNode::ENormal;
   191             {        
   169         if (node->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal)
   192             case MIAUpdateBaseNode::EMandatory:
   170         {
   193                 {
   171             MIAUpdateNode *updateNode = static_cast<MIAUpdateNode*>(node);
   194                 importanceDescription = "Required ";
   172             uiState = updateNode->UiState();
   195                 importanceDescription.append(sizeString);
   173         }
   196                 if ( shownInMegabytes )
   174         if (uiState == MIAUpdateNode::ENormal)
   197                     {
   175         {
   198                     importanceDescription.append(" MB" );
   176             setImportance(node, importanceDescription);
   199                     }
   177         }
   200                 else 
   178         else
   201                     {
   179         {
   202                     importanceDescription.append(" kB" );
   180             if(uiState == MIAUpdateNode::EUpdated)
   203                     }  
   181             {
   204                 break;
   182                 importanceDescription = "Updated";
   205                 }
   183             }
   206             
   184             else if(uiState == MIAUpdateNode::EFailed)
   207             
   185             {
   208             case MIAUpdateBaseNode::ECritical:
   186                 importanceDescription = "Failed";
   209                 {
   187             }
   210                 bool isNSU = false;
   188             else if(uiState == MIAUpdateNode::EDownloaded)
   211                 if( node->NodeType() == MIAUpdateAnyNode::ENodeTypeFw )
   189             {
   212                     {
   190                 importanceDescription = "Downloaded";
   213                     MIAUpdateFwNode* fwnode = static_cast<MIAUpdateFwNode*>( node );          
   191             }
   214                     if ( fwnode->FwType() == MIAUpdateFwNode::EFotiNsu )
   192         }
   215                         {
   193         
   216                         isNSU = true;
   194         
   217                         }
   195              
   218                     }
   196         HbListWidgetItem *item = new HbListWidgetItem();    
   219                 
   197         QString name;
   220                 importanceDescription = "Important ";
   198         if (node->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal)
   221                 if ( !size || isNSU )
   199         {  
   222                     {
   200             MIAUpdateNode *updateNode = static_cast<MIAUpdateNode*>(node);
   223                     //for firmware when size info is not provided by server
   201             if (updateNode->UiState() == MIAUpdateNode::EDownloading)
   224                     }
   202             {
   225                 else
   203                 name = QString("Downloading ");
   226                     {
   204             }
   227                     importanceDescription.append(sizeString);
   205             else if (updateNode->UiState() == MIAUpdateNode::EInstalling)
   228                     if ( shownInMegabytes )
   206             {
   229                         {
   207                 name = QString("Installing ");
   230                         importanceDescription.append(" MB" );
   208             }
   231                         }
   209         }
   232                     else 
   210         name.append(XQConversions::s60DescToQString(node->Base().Name()));
   233                         {
   211         if (node->NodeType() == MIAUpdateAnyNode::ENodeTypeFw) 
   234                         importanceDescription.append(" kB" );
   212         {
   235                         } 
   213             name.append(" DEVICE SOFTWARE");
   236                     }
   214         }
   237      
   215         item->setText(name);
   238                 break;
   216         item->setSecondaryText(importanceDescription);
   239                 }
   217         item->setIcon(icon);
   240         
   218         mListView->addItem(item); 
   241             case MIAUpdateBaseNode::ERecommended:
       
   242                 {
       
   243                 importanceDescription = "Recommended ";
       
   244                 importanceDescription.append(sizeString);
       
   245                 if ( shownInMegabytes )
       
   246                     {
       
   247                     importanceDescription.append(" MB" );
       
   248                     }
       
   249                 else 
       
   250                     {
       
   251                     importanceDescription.append(" kB" );
       
   252                     }  
       
   253                 break;
       
   254                 }
       
   255         
       
   256             case MIAUpdateBaseNode::ENormal:
       
   257                 {
       
   258                 importanceDescription = "Optional ";
       
   259                 importanceDescription.append(sizeString);
       
   260                 if ( shownInMegabytes )
       
   261                     {
       
   262                      importanceDescription.append(" MB" );
       
   263                     }
       
   264                 else 
       
   265                     {
       
   266                     importanceDescription.append(" kB" );
       
   267                     }  
       
   268                 break;
       
   269                 }
       
   270 
       
   271             default:
       
   272                 {
       
   273                 break;
       
   274                 }
       
   275             }
       
   276             
       
   277             //AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );    
       
   278             
       
   279             HbListWidgetItem *item = new HbListWidgetItem();    
       
   280             QString name = XQConversions::s60DescToQString(node->Base().Name());
       
   281             if ( node->NodeType() == MIAUpdateAnyNode::ENodeTypeFw ) 
       
   282                 {
       
   283                 name.append(" DEVICE SOFTWARE");
       
   284                 }
       
   285             item->setText(name);
       
   286             item->setSecondaryText(importanceDescription);
       
   287             item->setIcon(icon);
       
   288              mListView->addItem(item); 
       
   289  
   219  
   290             if ( node->Base().IsSelected() )
   220         if (node->Base().IsSelected())
   291                 {
   221         {
   292                 int count = mListView->count();
   222             int count = mListView->count();
   293                 QModelIndex modelIndex = mListView->model()->index(count-1,0);
   223             QModelIndex modelIndex = mListView->model()->index(count-1,0);
   294                 selectionModel->select(modelIndex, QItemSelectionModel::Select);
   224             selectionModel->select(modelIndex, QItemSelectionModel::Select);
   295                 }
   225         }
   296 
   226 
   297                
   227     }
   298             
   228     connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
   299         /*if ( nodes.Count() == 0 )
       
   300             {
       
   301             HBufC* emptyText = NULL;
       
   302             if ( aError )
       
   303                 {
       
   304                 if ( aError == KErrCancel || aError == KErrAbort )
       
   305                     {
       
   306                     emptyText = KNullDesC().AllocLC();
       
   307                     }
       
   308                 else
       
   309                     {
       
   310                     emptyText = StringLoader::LoadLC( R_IAUPDATE_REFRESH_FAILED );  
       
   311                     }
       
   312                 }
       
   313             else
       
   314                 {
       
   315                 emptyText = StringLoader::LoadLC( R_IAUPDATE_TEXT_NO_UPDATES ); 
       
   316                 }
       
   317             
       
   318             iListBox->View()->SetListEmptyTextL( *emptyText );
       
   319             CleanupStack::PopAndDestroy( emptyText );
       
   320             iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
   321                     CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff );  
       
   322             }
       
   323         else
       
   324             {
       
   325             if ( iListBox->CurrentItemIndex() == KErrNotFound )
       
   326                 {
       
   327                 iListBox->SetCurrentItemIndex( aNodes.Count() - 1 );
       
   328                 }
       
   329             }*/
       
   330             
       
   331         //iListBox->HandleItemAdditionL();
       
   332         }
       
   333      connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
       
   334                     this, SLOT(handleSelectionChanged(QItemSelection,QItemSelection)));     
   229                     this, SLOT(handleSelectionChanged(QItemSelection,QItemSelection)));     
   335     
   230     
   336      IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh end");
   231     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::refresh end");
   337      }
   232 }
   338 
   233 
   339 
   234 
   340 
   235 
   341 
   236 
   342 void IAUpdateMainView::handleStartUpdate()
   237 void IAUpdateMainView::handleStartUpdate()
   353             //at the same time.
   248             //at the same time.
   354             firmwareUpdate = true;
   249             firmwareUpdate = true;
   355             }
   250             }
   356         }
   251         }
   357     selectedNodes.Close();
   252     selectedNodes.Close();
   358     //mEngine->StartUpdate(firmwareUpdate);
   253     mEngine->StartUpdate(firmwareUpdate);
   359     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleStartUpdate() end");
   254     IAUPDATE_TRACE("[IAUPDATE] IAUpdateMainView::handleStartUpdate() end");
   360 }
   255 }
   361 
   256 
   362 
   257 
   363 void IAUpdateMainView::handleSettings()
   258 void IAUpdateMainView::handleSettings()
   725 }
   620 }
   726 
   621 
   727 void IAUpdateMainView::showDependenciesFoundDialog(QString &text)
   622 void IAUpdateMainView::showDependenciesFoundDialog(QString &text)
   728 {
   623 {
   729     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   624     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   625     HbLabel *label = new HbLabel(messageBox);
       
   626     label->setHtml(QString("Depencencies"));
       
   627     messageBox->setHeadingWidget(label);
       
   628     //messageBox->setIconVisible(false);
       
   629         
   730     messageBox->setText(text);
   630     messageBox->setText(text);
   731     int actionCount = messageBox->actions().count();
   631     int actionCount = messageBox->actions().count();
   732     for (int i=actionCount-1; i >= 0; i--)
   632     for (int i=actionCount-1; i >= 0; i--)
   733     { 
   633     { 
   734         messageBox->removeAction(messageBox->actions().at(i));
   634         messageBox->removeAction(messageBox->actions().at(i));
   780 }
   680 }
   781                 
   681                 
   782 void IAUpdateMainView::showDetails(MIAUpdateAnyNode& node)
   682 void IAUpdateMainView::showDetails(MIAUpdateAnyNode& node)
   783 {  
   683 {  
   784     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeInformation);
   684     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeInformation);
       
   685     HbLabel *label = new HbLabel(messageBox);
       
   686     label->setHtml(QString("Details"));
       
   687     messageBox->setHeadingWidget(label);
       
   688        
   785     messageBox->setIconVisible(false);
   689     messageBox->setIconVisible(false);
   786             
   690             
   787     QString text;
   691     QString text;
   788     constructDetailsText(node,text); 
   692     constructDetailsText(node,text); 
   789     messageBox->setText(text);
   693     messageBox->setText(text);
   790     int actionCount = messageBox->actions().count();
       
   791     
       
   792     for (int i=actionCount-1; i >= 0; i--)
       
   793     { 
       
   794         messageBox->removeAction(messageBox->actions().at(i));
       
   795     }
       
   796     HbAction *okAction = NULL;
       
   797     okAction = new HbAction("Ok");
       
   798     messageBox->addAction(okAction);
       
   799     messageBox->setTimeout(HbPopup::NoTimeout);
   694     messageBox->setTimeout(HbPopup::NoTimeout);
   800     messageBox->setAttribute(Qt::WA_DeleteOnClose);
   695     messageBox->setAttribute(Qt::WA_DeleteOnClose);
   801     mDialogState = Details;
   696     mDialogState = Details;
   802     messageBox->open(this, SLOT(dialogFinished(HbAction*)));                
   697     messageBox->open(this, SLOT(dialogFinished(HbAction*)));                
   803 }                
   698 }                
   910             }   
   805             }   
   911         }
   806         }
   912     text.setNum(size);
   807     text.setNum(size);
   913     text.append(stringUnit); 
   808     text.append(stringUnit); 
   914 }
   809 }
       
   810 
       
   811 void IAUpdateMainView::setImportance(MIAUpdateAnyNode *node, QString &importanceDescription)
       
   812 {
       
   813     int sizeInBytes = node->Base().ContentSizeL();
       
   814     int size = 0;
       
   815     bool shownInMegabytes = false;        
       
   816     if (sizeInBytes >= KMaxShownInKiloBytes)
       
   817     {
       
   818         shownInMegabytes = true;
       
   819         size = sizeInBytes / KMegaByte;
       
   820         if (sizeInBytes % KMegaByte != 0)
       
   821         {
       
   822            size++;
       
   823         }
       
   824     }
       
   825     else 
       
   826     {
       
   827         size = sizeInBytes / KKiloByte;
       
   828         if (sizeInBytes % KKiloByte != 0)
       
   829         {
       
   830             size++;
       
   831         }  
       
   832     }
       
   833     QString sizeString;
       
   834     sizeString.setNum(size);     
       
   835     switch(node->Base().Importance())
       
   836     {        
       
   837         case MIAUpdateBaseNode::EMandatory:
       
   838         {
       
   839             importanceDescription = "Required ";
       
   840             importanceDescription.append(sizeString);
       
   841             if (shownInMegabytes)
       
   842             {
       
   843                 importanceDescription.append(" MB" );
       
   844             }
       
   845             else 
       
   846             {
       
   847                 importanceDescription.append(" kB" );
       
   848             }  
       
   849             break;
       
   850         }
       
   851                 
       
   852         case MIAUpdateBaseNode::ECritical:
       
   853         {
       
   854             bool isNSU = false;
       
   855             if(node->NodeType() == MIAUpdateAnyNode::ENodeTypeFw)
       
   856             {
       
   857                 MIAUpdateFwNode *fwnode = static_cast<MIAUpdateFwNode*>(node);          
       
   858                 if (fwnode->FwType() == MIAUpdateFwNode::EFotiNsu)
       
   859                 {
       
   860                    isNSU = true;
       
   861                 }
       
   862             }
       
   863             importanceDescription = "Important ";
       
   864             if (!size || isNSU)
       
   865             {
       
   866                 //for firmware when size info is not provided by server
       
   867             }
       
   868             else
       
   869             {
       
   870                 importanceDescription.append(sizeString);
       
   871                 if (shownInMegabytes)
       
   872                 {
       
   873                     importanceDescription.append(" MB" );
       
   874                 }
       
   875                 else 
       
   876                 {
       
   877                     importanceDescription.append(" kB" );
       
   878                 } 
       
   879             }
       
   880             break;
       
   881         }
       
   882             
       
   883         case MIAUpdateBaseNode::ERecommended:
       
   884         {
       
   885             importanceDescription = "Recommended ";
       
   886             importanceDescription.append(sizeString);
       
   887             if (shownInMegabytes)
       
   888             {
       
   889                 importanceDescription.append(" MB" );
       
   890             }
       
   891             else 
       
   892             {
       
   893                 importanceDescription.append(" kB" );
       
   894             }  
       
   895             break;
       
   896         }
       
   897             
       
   898         case MIAUpdateBaseNode::ENormal:
       
   899         {
       
   900             importanceDescription = "Optional ";
       
   901             importanceDescription.append(sizeString);
       
   902             if (shownInMegabytes)
       
   903             {
       
   904                 importanceDescription.append(" MB" );
       
   905             }
       
   906             else 
       
   907             {
       
   908                 importanceDescription.append(" kB" );
       
   909             }  
       
   910             break;
       
   911         }
       
   912 
       
   913         default:
       
   914         {
       
   915             break;
       
   916         }
       
   917     }
       
   918 }    
       
   919