locationsystemui/locationsysui/possettings/possettingsengine/src/possettingsform.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class is for first basic view for positioning settings
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "possettingsform.h"
       
    20 #include "possettingspushbuttonitem.h"
       
    21 #include "possettingsgroupboxitem.h"
       
    22 #include "checkcustomviewitem.h"
       
    23 #include "possettingsengine.h"
       
    24 #include "possettingsadvview.h"
       
    25 #include <QDebug>
       
    26 #include <hbdataformmodelitem.h>
       
    27 #include <hbdataformmodel.h>
       
    28 #include <hbinstance.h>
       
    29 #include <hbaction.h>
       
    30 #include <hbstyleloader.h>
       
    31 
       
    32 static const QString FILE_PATH_CSS = ":/data";
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // PosSettingsForm::PosSettingsForm
       
    36 // Constructor
       
    37 // ---------------------------------------------------------------------------
       
    38 PosSettingsForm::PosSettingsForm( 
       
    39                                        PosSettingsEngine& settingsEngine,
       
    40                                        QGraphicsItem *parent ):
       
    41                                        HbDataForm( parent ),mSettingsEngine( settingsEngine )
       
    42     {
       
    43     qDebug() << "+ PosSettingsForm::PosSettingsForm()";
       
    44     //initialize the form model
       
    45     initSettingModel(); 
       
    46     
       
    47     // slots for required signals on required controls
       
    48     addConnection( mGpsPosType, SIGNAL(released()),
       
    49                     this, SLOT(onPressedGps()) );
       
    50     addConnection( mWirelessPosType, SIGNAL(released()),
       
    51                         this, SLOT(onPressedWireless()) );
       
    52     addConnection( mBgPosType, SIGNAL(released()),
       
    53                         this, SLOT(onPressedBackground()) );
       
    54     addConnection( mAdvancedSettings, SIGNAL(clicked()),
       
    55                         this, SLOT(onPressedAdvanced()) );   
       
    56     
       
    57     //to check runtime if any positioning technology installed/removed or if its visibility is changed.
       
    58     connect(&mSettingsEngine, SIGNAL(positionTechnologyChange()),this, SLOT(validateVisibility()) );
       
    59     
       
    60     //validate visibility of controls based on visibility of positioning technology
       
    61     validateVisibility();
       
    62     qDebug() << "- PosSettingsForm::PosSettingsForm()";
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // PosSettingsForm::~PosSettingsForm
       
    67 // Destructor
       
    68 // ---------------------------------------------------------------------------
       
    69 PosSettingsForm::~PosSettingsForm()
       
    70     {
       
    71     qDebug() << "+ PosSettingsForm::PosSettingsForm()";
       
    72     // Remove custom layouts
       
    73     HbStyleLoader::unregisterFilePath(FILE_PATH_CSS);
       
    74     
       
    75     //TODO Disconnect of mSettingsEngine positionTechnologyChange
       
    76     
       
    77     removeConnection( mAdvancedSettings, SIGNAL(clicked()),
       
    78                             this, SLOT(onPressedAdvanced()) );
       
    79     removeConnection( mGpsPosType, SIGNAL(released),
       
    80                         this, SLOT(onPressedGps()) );
       
    81     removeConnection( mWirelessPosType, SIGNAL(released),
       
    82                         this, SLOT(onPressedWireless()) );
       
    83     removeConnection( mBgPosType, SIGNAL(released),
       
    84                         this, SLOT(onPressedBackground()) );
       
    85     
       
    86     //ToDo: removeAllConnection crashes with Kern-Exec3 error 
       
    87     //removeAllConnection();
       
    88     qDebug() << "- PosSettingsForm::PosSettingsForm()";     
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // PosSettingsForm::initSettingModel
       
    93 // ---------------------------------------------------------------------------
       
    94 void PosSettingsForm::initSettingModel()
       
    95     {
       
    96     qDebug() << "+ PosSettingsForm::initSettingModel()";
       
    97     HbDataFormModel *model = new HbDataFormModel(0);
       
    98     this->setModel(model);
       
    99     
       
   100     //set prototype for custom controls
       
   101     QList<HbAbstractViewItem *> protoTypeList = this->itemPrototypes();
       
   102     protoTypeList.append(new PosSettingsPushButtonItem(this) );
       
   103     protoTypeList.append(new CheckCustomViewItem());  
       
   104     protoTypeList.append(new PosSettingsGroupboxItem(this));  
       
   105     this->setItemPrototypes(protoTypeList);
       
   106     
       
   107     // Set custom layouts
       
   108     HbStyleLoader::registerFilePath(FILE_PATH_CSS);    
       
   109     
       
   110     //Heading                   
       
   111     mHeading = model->appendDataFormItem(static_cast<HbDataFormModelItem::DataItemType>(GroupboxItem),
       
   112                                                   QString(),
       
   113                                                   model->invisibleRootItem());
       
   114     mHeading->setContentWidgetData("heading",
       
   115                                hbTrId("txt_loe_subtitle_positioning_settings"));
       
   116 
       
   117          
       
   118          
       
   119     //GPS
       
   120     createPosTypeModelItem(PosTypeIndexGps);
       
   121     model->appendDataFormItem(mGpsPosType, model->invisibleRootItem());    
       
   122     //Wireless
       
   123     createPosTypeModelItem(PosTypeIndexWireless);
       
   124     model->appendDataFormItem(mWirelessPosType, model->invisibleRootItem());           
       
   125     //Background
       
   126     createPosTypeModelItem(PosTypeIndexBackground);
       
   127     model->appendDataFormItem(mBgPosType, model->invisibleRootItem());       
       
   128  
       
   129     //Advance                   
       
   130     mAdvancedSettings = model->appendDataFormItem(static_cast<HbDataFormModelItem::DataItemType>(PushButtonItem),
       
   131                                                   QString(),
       
   132                                                   model->invisibleRootItem());
       
   133     mAdvancedSettings->setContentWidgetData("text",
       
   134                                hbTrId("txt_loe_button_advanced"));
       
   135 
       
   136          
       
   137     setPosTypeState(PosTypeIndexGps);
       
   138     setPosTypeState(PosTypeIndexWireless);
       
   139     setPosTypeState(PosTypeIndexBackground);
       
   140     qDebug() << "- PosSettingsForm::initSettingModel()";  
       
   141 	}
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // PosSettingsForm::onPressedAdvanced
       
   145 // ---------------------------------------------------------------------------
       
   146 void PosSettingsForm::onPressedAdvanced()
       
   147 {
       
   148     qDebug() << "+ PosSettingsForm::onPressedAdvanced()";
       
   149     mAdvancedView = new PosSettingsAdvView();
       
   150     HbMainWindow* mainWindow = hbInstance->allMainWindows().at(0);
       
   151 
       
   152     mainWindow->addView(mAdvancedView);
       
   153     mainWindow->setCurrentView(mAdvancedView);
       
   154      
       
   155     //take back action from controlpanel main window.
       
   156     mBackAction = new HbAction(Hb::BackNaviAction ,mAdvancedView);
       
   157     mAdvancedView->setNavigationAction(mBackAction);
       
   158 
       
   159     connect(mBackAction, SIGNAL(triggered()), this, SLOT(closeAdvancedView()));
       
   160     mAdvancedView->show();
       
   161     qDebug() << "- PosSettingsForm::onPressedAdvanced()"; 
       
   162 }
       
   163 // ---------------------------------------------------------------------------
       
   164 // PosSettingsForm::closeAdvancedView
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void PosSettingsForm::closeAdvancedView()
       
   168     {
       
   169     qDebug() << "+ PosSettingsForm::closeAdvancedView()";
       
   170     disconnect(mBackAction, SIGNAL(triggered()), this, SLOT(closeAdvancedView()));
       
   171 
       
   172     HbMainWindow* mainWindow = hbInstance->allMainWindows().at(0);
       
   173     mainWindow->removeView(mAdvancedView);
       
   174 
       
   175     mAdvancedView->setParent(NULL);
       
   176     
       
   177     delete mAdvancedView;
       
   178     mAdvancedView = NULL;
       
   179     
       
   180     // refresh first view 
       
   181     setPosTypeState( PosTypeIndexGps);
       
   182     setPosTypeState( PosTypeIndexWireless);
       
   183     setPosTypeState( PosTypeIndexBackground);
       
   184     validatePosTypeVisibility(PosTypeIndexBackground);  
       
   185     qDebug() << "- PosSettingsForm::closeAdvancedView()"; 
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // PosSettingsForm::onPressedGps
       
   190 // ---------------------------------------------------------------------------
       
   191 void PosSettingsForm::onPressedGps()
       
   192     { 
       
   193     qDebug() << "+ PosSettingsForm::onPressedGps()";	
       
   194     validatePosTypeVisibility(PosTypeIndexBackground);  	
       
   195     
       
   196      int state = mGpsPosType->contentWidgetData("checkState").toInt();
       
   197      if(state == Qt::Checked)
       
   198         {    //if Gps enable
       
   199         mSettingsEngine.setPositionTechnologyState(StateEnable, PositionTechnologyGps);
       
   200         }
       
   201     else 
       
   202         {    //if Gps disable
       
   203         mSettingsEngine.setPositionTechnologyState(StateDisable, PositionTechnologyGps);
       
   204         }
       
   205     qDebug() << "- PosSettingsForm::onPressedGps()";    
       
   206     }
       
   207 	
       
   208 // ---------------------------------------------------------------------------
       
   209 // PosSettingsForm::onPressedWireless
       
   210 // ---------------------------------------------------------------------------
       
   211 void PosSettingsForm::onPressedWireless()
       
   212     {  
       
   213     qDebug() << "+ PosSettingsForm::onPressedWireless()";
       
   214     validatePosTypeVisibility(PosTypeIndexBackground); 
       
   215     int state = mWirelessPosType->contentWidgetData("checkState").toInt();
       
   216      if(state == Qt::Checked)
       
   217         {
       
   218         //if Wireless enable
       
   219         mSettingsEngine.setPositionTechnologyState(StateEnable, PositionTechnologyNetwork);
       
   220         }
       
   221     else 
       
   222         {    //if Wireless disable
       
   223         mSettingsEngine.setPositionTechnologyState(StateDisable, PositionTechnologyNetwork);
       
   224         }
       
   225     qDebug() << "- PosSettingsForm::onPressedWireless()"; 
       
   226     }
       
   227 	
       
   228 // ---------------------------------------------------------------------------
       
   229 // PosSettingsForm::onPressedBackground
       
   230 // ---------------------------------------------------------------------------
       
   231 void PosSettingsForm::onPressedBackground()
       
   232     {
       
   233     qDebug() << "+ PosSettingsForm::onPressedBackground()";
       
   234     int state = mBgPosType->contentWidgetData("checkState").toInt();	
       
   235     if(state == Qt::Checked)
       
   236         {
       
   237         //if Bg enable
       
   238         mSettingsEngine.setBackGroundPositioningState(StateEnable);
       
   239         mSettingsEngine.setCRBackgroundPositioningStatus(StateEnable);
       
   240         }
       
   241      else 
       
   242         {    //if Bg disable;
       
   243         mSettingsEngine.setBackGroundPositioningState(StateDisable);
       
   244         mSettingsEngine.setCRBackgroundPositioningStatus(StateDisable);
       
   245         }
       
   246     qDebug() << "- PosSettingsForm::onPressedBackground()";
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // PosSettingsForm::validatePosTypeVisibility
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 void PosSettingsForm::validatePosTypeVisibility(PosTypeIndex posTypeModelItemIndex)
       
   254     {   
       
   255     qDebug() << "+ PosSettingsForm::validatePosTypeVisibility()";
       
   256     bool valid = false;
       
   257     HbDataFormModelItem* posTypeModelItem = NULL; //does not own
       
   258     int posIndex = posTypeModelItemIndex;
       
   259     switch(posTypeModelItemIndex) {
       
   260         case PosTypeIndexGps: {
       
   261             valid = mSettingsEngine.isPositionTechnologyAvailable(PositionTechnologyGps);
       
   262             posTypeModelItem = mGpsPosType;
       
   263             break;
       
   264             }
       
   265         case PosTypeIndexWireless: {
       
   266             valid = mSettingsEngine.isPositionTechnologyAvailable(PositionTechnologyNetwork);
       
   267             posTypeModelItem = mWirelessPosType;
       
   268             HbDataFormModel* model =  static_cast<HbDataFormModel*>(this->model());
       
   269             //if GPS is not there, it will be at position 1
       
   270              if(!model->indexFromItem(mGpsPosType).isValid()) {
       
   271              	 --posIndex ;
       
   272             	}
       
   273             break;
       
   274             }
       
   275         case  PosTypeIndexBackground: {
       
   276             //if Gps and Wireless are not marked, then make Background invisible            
       
   277             valid = (mGpsPosType->contentWidgetData("checkState").toInt() == Qt::Checked ||
       
   278                         mWirelessPosType->contentWidgetData("checkState").toInt() == Qt::Checked);
       
   279             posTypeModelItem = mBgPosType;
       
   280             HbDataFormModel* model =  static_cast<HbDataFormModel*>(this->model());
       
   281             
       
   282              //if GPS is not there, decremenet position
       
   283             if(!model->indexFromItem(mGpsPosType).isValid()) {
       
   284              		--posIndex;
       
   285             	}
       
   286             //if Wireless is not there, decremenet position 	
       
   287             if(!model->indexFromItem(mWirelessPosType).isValid()) {
       
   288              		--posIndex;
       
   289 				}
       
   290 			 //if no gps no wireless, quit control-panel application	
       
   291 			if(posIndex == PosTypeIndexGps-1) { 
       
   292              		qApp->quit();
       
   293              		}
       
   294             break;
       
   295             }
       
   296         default:{
       
   297             break;
       
   298             }
       
   299         
       
   300         }
       
   301    qDebug() << "valid =" << valid;	    
       
   302    insertOrRemovePosTypeModelItem(valid, posTypeModelItem, posTypeModelItemIndex, posIndex);
       
   303    qDebug() << "- PosSettingsForm::validatePosTypeVisibility()";
       
   304     }
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // PosSettingsForm::InsertOrRemovePosTypeModelItem
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 void PosSettingsForm::insertOrRemovePosTypeModelItem(bool insert, HbDataFormModelItem*  posTypeModelItem, 
       
   311 														PosTypeIndex posTypeModelItemIndex, int posIndex)
       
   312     {
       
   313     qDebug() << "+ PosSettingsForm::insertOrRemovePosTypeModelItem()";
       
   314     HbDataFormModel* model =  static_cast<HbDataFormModel*>(this->model());
       
   315     if(!insert) {
       
   316         if(model->indexFromItem(posTypeModelItem).isValid()) {
       
   317             if(model->removeItem(posTypeModelItem)) {
       
   318                 //Note: In removeItem, modelitem is removed and then deleted too.
       
   319                 // So next time when we want to check if it is present, we have to create dummy modelitem
       
   320                 // else with existing handle, we will get kern exec 3 error
       
   321                 createPosTypeModelItem(posTypeModelItemIndex);  
       
   322                 if(posTypeModelItemIndex == PosTypeIndexBackground) {
       
   323                         mSettingsEngine.setBackGroundPositioningState(StateDisable);
       
   324                     }
       
   325                 }
       
   326             }
       
   327         }
       
   328     else {
       
   329         if(!model->indexFromItem(posTypeModelItem).isValid()) { 
       
   330                 model->insertDataFormItem(posIndex,posTypeModelItem,model->invisibleRootItem());  
       
   331                 addPosTypeConnection(posTypeModelItem);
       
   332                 
       
   333                 if(posTypeModelItemIndex == PosTypeIndexBackground){
       
   334                     //Restore to old state in case of background positioning.
       
   335                     if(mSettingsEngine.cRBackgroundPositioningStatus()) {
       
   336                         mSettingsEngine.setBackGroundPositioningState(StateEnable);
       
   337                         }
       
   338                     else {
       
   339                         mSettingsEngine.setBackGroundPositioningState(StateDisable);                    
       
   340                         }
       
   341                     setPosTypeState(PosTypeIndexBackground);
       
   342                     }
       
   343                 else //Restore old state of GPS/Wireless
       
   344                     setPosTypeState(posTypeModelItemIndex); 
       
   345            }
       
   346         }
       
   347     qDebug() << "- PosSettingsForm::insertOrRemovePosTypeModelItem()";
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // PosSettingsForm::createPosTypeModelItem
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 void PosSettingsForm::createPosTypeModelItem(PosTypeIndex posTypeModelItemIndex)
       
   355     {
       
   356     qDebug() << "+ PosSettingsForm::createPosTypeModelItem()";
       
   357     HbDataFormModel* model =  static_cast<HbDataFormModel*>(this->model());
       
   358     switch(posTypeModelItemIndex) {
       
   359         case PosTypeIndexGps: {         
       
   360            
       
   361         mGpsPosType = new HbDataFormModelItem(HbDataFormModelItem::CheckBoxItem,
       
   362                         QString());     
       
   363            mGpsPosType->setData(HbDataFormModelItem::DescriptionRole, hbTrId("txt_loe_info_enable_for_most_accurate_positioning"));
       
   364            mGpsPosType->setContentWidgetData("text", hbTrId("txt_loe_list_gps"));
       
   365             break;
       
   366             }
       
   367         case PosTypeIndexWireless: {          
       
   368            
       
   369             mWirelessPosType = new HbDataFormModelItem(HbDataFormModelItem::CheckBoxItem,
       
   370                                 QString());    
       
   371             mWirelessPosType->setData(HbDataFormModelItem::DescriptionRole, hbTrId("txt_loe_info_use_wifi_and_mobile_networks_to_get"));
       
   372             mWirelessPosType->setContentWidgetData("text", hbTrId("txt_loe_list_wireless_networks"));   
       
   373            break;
       
   374            }
       
   375         case PosTypeIndexBackground:{  
       
   376             mBgPosType = new HbDataFormModelItem(HbDataFormModelItem::CheckBoxItem,
       
   377                                 QString());
       
   378 		    mBgPosType->setData(HbDataFormModelItem::DescriptionRole, hbTrId("txt_loe_info_enable_applications_and_services_upda"));
       
   379 		    mBgPosType->setContentWidgetData("text", hbTrId("txt_loe_list_background_positioning")); 		  	
       
   380            break;
       
   381            }
       
   382         default: {
       
   383             break;
       
   384            }
       
   385         }
       
   386     qDebug() << "- PosSettingsForm::createPosTypeModelItem()";
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // PosSettingsForm::validateVisibility
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void PosSettingsForm::validateVisibility()
       
   394     {  
       
   395     qDebug() << "+ PosSettingsForm::validateVisibility()";
       
   396     validatePosTypeVisibility(PosTypeIndexGps);
       
   397     validatePosTypeVisibility(PosTypeIndexWireless);
       
   398     validatePosTypeVisibility(PosTypeIndexBackground);
       
   399     qDebug() << "- PosSettingsForm::validateVisibility()";
       
   400     }
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // PosSettingsForm::setPosTypeState
       
   404 // ---------------------------------------------------------------------------
       
   405 void PosSettingsForm::setPosTypeState(PosTypeIndex posTypeModelItemIndex)
       
   406     {
       
   407     qDebug() << "+ PosSettingsForm::setPosTypeState()";
       
   408     int state = Qt::Unchecked;
       
   409     switch(posTypeModelItemIndex){
       
   410         case PosTypeIndexGps: {        
       
   411             if(mSettingsEngine.isPositionTechnologyEnabled(PositionTechnologyGps))
       
   412                 state = Qt::Checked;
       
   413             mGpsPosType->setContentWidgetData("checkState", state);      
       
   414             break;
       
   415             }
       
   416         case PosTypeIndexWireless: {
       
   417             if(mSettingsEngine.isPositionTechnologyEnabled(PositionTechnologyNetwork))
       
   418                    state = Qt::Checked;
       
   419             mWirelessPosType->setContentWidgetData("checkState",state);                    
       
   420             break;
       
   421             }
       
   422         case PosTypeIndexBackground: {
       
   423             if(mSettingsEngine.isBackGroundPositioningEnabled())
       
   424                   state = Qt::Checked;
       
   425             mBgPosType->setContentWidgetData("checkState",state);      
       
   426             break;
       
   427             }
       
   428         default : {
       
   429             break;
       
   430             }
       
   431         }
       
   432     qDebug() << "- PosSettingsForm::setPosTypeState()";
       
   433     }
       
   434 
       
   435 // ---------------------------------------------------------------------------
       
   436 // PosSettingsForm::addPosTypeConnection
       
   437 // ---------------------------------------------------------------------------
       
   438 void PosSettingsForm::addPosTypeConnection(HbDataFormModelItem*  posTypeModelItem)
       
   439     {
       
   440     qDebug() << "+ PosSettingsForm::addPosTypeConnection()";
       
   441     if(posTypeModelItem == mGpsPosType)
       
   442         {       
       
   443         addConnection( mGpsPosType, SIGNAL(released()),
       
   444                                                   this, SLOT(onPressedGps()) );
       
   445         qDebug() << "- PosSettingsForm::addPosTypeConnection()";
       
   446         return;
       
   447         }
       
   448     
       
   449     if(posTypeModelItem == mWirelessPosType)        
       
   450        {
       
   451        addConnection( mWirelessPosType, SIGNAL(released()),
       
   452                                                  this, SLOT(onPressedWireless()) );
       
   453        qDebug() << "- PosSettingsForm::addPosTypeConnection()";
       
   454        return;
       
   455        }
       
   456     if(posTypeModelItem == mBgPosType) 
       
   457        {
       
   458        addConnection( mBgPosType, SIGNAL(released()),
       
   459                                                  this, SLOT(onPressedBackground()) );
       
   460        qDebug() << "- PosSettingsForm::addPosTypeConnection()";
       
   461        return;
       
   462        }        
       
   463     }
       
   464 //EOF