locationsystemui/locationsysui/possettings/possettingsengine/src/possettingsadvview.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:Implementation of the Positioning Settings Advanced View class 
       
    15  *
       
    16  */
       
    17 
       
    18 #include "possettingsadvview.h"
       
    19 #include "possettingspluginsloader.h"
       
    20 #include "possettingsgroupboxitem.h"
       
    21 #include <QDebug>
       
    22 #include <QFileSystemWatcher>
       
    23 
       
    24 #ifdef Q_OS_SYMBIAN
       
    25 #define PLUGIN_PATH QString("\\resource\\qt\\plugins\\positioningsettings")
       
    26 
       
    27 #else
       
    28 #define PLUGIN_PATH QString("C:\\qt\\plugins\\positioningsettings")
       
    29 #endif 
       
    30 
       
    31 //---------------------------------------------------------------------
       
    32 // PosSettingsAdvView::PosSettingsAdvView()
       
    33 // Constructor
       
    34 //---------------------------------------------------------------------
       
    35 PosSettingsAdvView::PosSettingsAdvView( QGraphicsItem *parent ):
       
    36 CpBaseSettingView(0,parent)
       
    37     {
       
    38     qDebug() << "+ PosSettingsAdvView::PosSettingsAdvView()";
       
    39     // create instance of HbDataForm
       
    40     mAdvancedDataForm = new HbDataForm();
       
    41     
       
    42     // Create an instance of HbDataFormModel
       
    43     HbDataFormModel* advancedDataFormModel = new HbDataFormModel();
       
    44 
       
    45     // set the model
       
    46     mAdvancedDataForm->setModel( advancedDataFormModel );
       
    47 
       
    48     // set the Advanced settings form for this view
       
    49     this->setWidget( mAdvancedDataForm );
       
    50     
       
    51     //set prototype for custom controls
       
    52     QList<HbAbstractViewItem *> protoTypeList = mAdvancedDataForm->itemPrototypes();
       
    53     protoTypeList.append(new PosSettingsGroupboxItem(this));  
       
    54     mAdvancedDataForm->setItemPrototypes(protoTypeList);
       
    55     
       
    56     //Heading                   
       
    57      mHeading = advancedDataFormModel->appendDataFormItem(static_cast<HbDataFormModelItem::DataItemType>(GroupboxItem),
       
    58                                                    QString(),
       
    59                                                    advancedDataFormModel->invisibleRootItem());
       
    60      mHeading->setContentWidgetData("heading",
       
    61                                 hbTrId("txt_loe_subtitle_advanced_positioning_settings"));
       
    62 
       
    63     
       
    64     
       
    65     // Create an instance of PosSettingsAdvancedOperation
       
    66     mAdvancedOperation = new PosSettingsAdvOp(this);
       
    67     
       
    68 
       
    69     mPluginsLoader = new PosSettingsPluginsLoader();
       
    70     // load the plugins
       
    71     mPluginsList = mPluginsLoader->loadPlugins();
       
    72     
       
    73     // for each plugin detected call the plugin's initialize method
       
    74    
       
    75     int cnt = mPluginsList.count();
       
    76     int error = 0;
       
    77     for(int i=0;i<cnt;i++)
       
    78         {
       
    79 				error = mPluginsList[i]->initialise(mAdvancedOperation );
       
    80         //pluging is unloaded if the there is an error, with exception for not found.
       
    81         if (error != 0 && error != -1)
       
    82             {
       
    83             delete mPluginsList[i];
       
    84             mPluginsList[i] = 0;
       
    85             mPluginsList.removeAt(i);
       
    86             --cnt;
       
    87             --i;
       
    88             }
       
    89         }
       
    90     // create a QFileSystemWatcher instance
       
    91     mWatcher = new QFileSystemWatcher();
       
    92     mWatcher->addPath(PLUGIN_PATH);
       
    93     
       
    94     // make connection to update the advanced view on change in the plugins
       
    95     QObject::connect(mWatcher,SIGNAL(fileChanged ( const QString & path )),
       
    96                     this,SLOT(updateAdvView()));
       
    97     qDebug() << "- PosSettingsAdvView::PosSettingsAdvView()";
       
    98     }
       
    99 
       
   100 //---------------------------------------------------------------------
       
   101 // PosSettingsAdvView::~PosSettingsAdvView()
       
   102 // Destructor
       
   103 //---------------------------------------------------------------------
       
   104 PosSettingsAdvView::~PosSettingsAdvView()
       
   105     {   
       
   106     qDebug() << "+ PosSettingsAdvView::~PosSettingsAdvView()";
       
   107   //  mAdvancedDataForm->removeAllConnection();	 
       
   108     delete mAdvancedDataForm;
       
   109     mAdvancedDataForm = NULL;
       
   110     
       
   111     
       
   112     delete mAdvancedOperation;
       
   113     mAdvancedOperation = NULL;
       
   114     
       
   115     delete mPluginsLoader;
       
   116     mPluginsLoader = NULL;
       
   117     
       
   118     // delete the list of plugins
       
   119     foreach( PosSettingsAdvInterface *plugin, mPluginsList )
       
   120             {
       
   121             delete plugin;
       
   122             plugin = 0;
       
   123             }
       
   124     mPluginsList.clear();
       
   125     
       
   126     //ToDo: disconnect mWatcher'signal
       
   127     delete mWatcher;
       
   128     mWatcher = NULL;
       
   129     qDebug() << "- PosSettingsAdvView::~PosSettingsAdvView()";    
       
   130     }
       
   131 
       
   132 //---------------------------------------------------------------------
       
   133 // PosSettingsAdvView::updateAdvView()
       
   134 // 
       
   135 //---------------------------------------------------------------------
       
   136 void PosSettingsAdvView::updateAdvView()
       
   137     {
       
   138     qDebug() << "+ PosSettingsAdvView::updateAdvView()";
       
   139     // clear the plugins list
       
   140     foreach( PosSettingsAdvInterface *plugin, mPluginsList )
       
   141         {
       
   142         delete plugin;
       
   143         plugin= NULL;
       
   144         }
       
   145     mPluginsList.clear();
       
   146     
       
   147     // reload the plugins again
       
   148     mPluginsList = mPluginsLoader->loadPlugins();
       
   149     
       
   150     int count = mPluginsList.count();
       
   151     
       
   152     // for each plugin detected call the plugin's initialize method
       
   153     for( int i=0;i<count;++i )
       
   154         {
       
   155         int error = mPluginsList[i]->initialise( mAdvancedOperation );
       
   156         if( error != KErrNone )
       
   157             {
       
   158             delete mPluginsList[i];
       
   159             mPluginsList[i] =NULL;
       
   160             }
       
   161         }
       
   162     qDebug() << "- PosSettingsAdvView::updateAdvView()";
       
   163     }