locationsystemui/locationsysui/posindicator/posindicatorplugin/src/posindicator.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 for positioning indicator plugin class
       
    15 *
       
    16 */
       
    17 
       
    18 #include "posindicator.h"
       
    19 #include "posindicatorinfo.h"
       
    20 #include "posgeoaddress.h"
       
    21 #include "apilogger.h"
       
    22 
       
    23 #include <QtPlugin>
       
    24 #include <QVariant>
       
    25 #include <QDebug>
       
    26 #include <QTranslator>
       
    27 #include <QTCore>
       
    28 
       
    29 
       
    30 Q_EXPORT_PLUGIN(PosIndicatorPlugin)
       
    31 
       
    32 // This plugin implements just one indicator type
       
    33 const QString typeOfIndicator ="com.nokia.positioning.indicatorplugin/1.0";
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // PosIndicatorPlugin::PosIndicatorPlugin
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 PosIndicatorPlugin::PosIndicatorPlugin() : mError(0), mTranslator(0)
       
    40 {
       
    41     #ifndef QT_NO_DEBUG_OUTPUT
       
    42     ApiLogger::OpenLogFile();
       
    43         #ifndef POSINDICATOR_NFT
       
    44         qInstallMsgHandler(ApiLogger::MyOutputHandler);
       
    45         #endif
       
    46     #endif
       
    47         
       
    48     qDebug() << "+ PosIndicatorPlugin::PosIndicatorPlugin()";
       
    49     
       
    50     mTranslator = new QTranslator();
       
    51     
       
    52     QString locale = QLocale::system().name();
       
    53     QString path = "z:/resource/qt/translations/";
       
    54     mTranslator->load(path + QString("lilocationmw_") + locale);
       
    55     qApp->installTranslator(mTranslator);
       
    56         
       
    57     mIndicatorTypes.append(typeOfIndicator);
       
    58     qDebug() << "- PosIndicatorPlugin::PosIndicatorPlugin()";
       
    59 
       
    60 }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // PosIndicatorPlugin::~PosIndicatorPlugin
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 PosIndicatorPlugin::~PosIndicatorPlugin()
       
    67 {   
       
    68     qDebug() << "+ PosIndicatorPlugin::~PosIndicatorPlugin()";
       
    69     if (mTranslator)
       
    70     {
       
    71     if (mTranslator->isEmpty() == false)
       
    72         qApp->removeTranslator(mTranslator);
       
    73     delete mTranslator;
       
    74     }
       
    75 	qInstallMsgHandler(0);
       
    76     ApiLogger::CloseLogFile();
       
    77 }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // PosIndicatorPlugin::indicatorTypes
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 QStringList PosIndicatorPlugin::indicatorTypes() const
       
    84 {
       
    85 	qDebug() << "+ PosIndicatorPlugin::indicatorTypes()";
       
    86 	// Return indicator types this plugin implements
       
    87     return mIndicatorTypes;
       
    88 }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // PosIndicatorPlugin::createIndicator
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 HbIndicatorInterface* PosIndicatorPlugin::createIndicator(
       
    95         const QString &indicatorType)
       
    96 {
       
    97 	qDebug() << "+ PosIndicatorPlugin::createIndicator()";
       
    98 	ApiLogger::NftLogger("Before launching indicator");
       
    99     PosIndicator* ind = new PosIndicator( indicatorType );
       
   100     ApiLogger::NftLogger("After launching indicator");
       
   101     return ind;
       
   102 }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // PosIndicatorPlugin::accessAllowed
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 bool PosIndicatorPlugin::accessAllowed(const QString &/*indicatorType*/, const QVariantMap &securityInfo) const
       
   109 {
       
   110 	qDebug() << "+ PosIndicatorPlugin::accessAllowed()";
       
   111 	QVariant value = securityInfo.value("sym-caps");
       
   112 	if ((value.toInt() && ECapabilityLocation) == true )
       
   113 	    {
       
   114         qDebug() << "Location capability present, pass";
       
   115         return true;
       
   116 	    }
       
   117 	else
       
   118 	    {
       
   119         qDebug() << "Location capability absent, fail";
       
   120         return false;
       
   121 	    }
       
   122 }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // PosIndicatorPlugin::error
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 int PosIndicatorPlugin::error() const
       
   129 {
       
   130 	qDebug() << "+ PosIndicatorPlugin::error()";
       
   131     return mError;
       
   132 }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // PosIndicator::PosIndicator
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 PosIndicator::PosIndicator(const QString &indicatorType) :
       
   139     HbIndicatorInterface(indicatorType, SettingCategory, NoInteraction),
       
   140     mDisplayString(QString(hbTrId("txt_loe_dblist_positioning_val_acquiring_position"))),
       
   141     mPosIndicatorInfo(0),
       
   142     processedAddess(false)
       
   143 {
       
   144 	qDebug() << "+ PosIndicator::PosIndicator()";
       
   145 	qDebug() << "- PosIndicator::PosIndicator()";
       
   146 }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // PosIndicator::RefreshPosIndicatorPane
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void PosIndicator::refreshPosIndicatorPane(PosGeoAddress& posGeoAddress, int error)
       
   153     {
       
   154 	qDebug() << "+ PosIndicator::refreshPosIndicatorPane()";
       
   155     if(error!=KErrNone)
       
   156         {
       
   157         qDebug() << "- PosIndicator::refreshPosIndicatorPane(),error code : "<<error;
       
   158         return;
       
   159         }
       
   160     qDebug() << "latitude : "<< posGeoAddress.latitude() << ", longitude : "<<posGeoAddress.longitude();
       
   161     TBool addressResolved = false;
       
   162     qDebug() << " No Errors.";
       
   163     mDisplayString.clear();
       
   164     if(!posGeoAddress.number().isEmpty())
       
   165         {
       
   166         qDebug() << "Number - %s"<<posGeoAddress.number();
       
   167 
       
   168         addressResolved = true;
       
   169         mDisplayString = mDisplayString + QString(posGeoAddress.number()) + QString(' '); 
       
   170         }
       
   171     if(!posGeoAddress.street().isEmpty())
       
   172         {
       
   173         qDebug() << "street - %d"<<posGeoAddress.street();
       
   174 
       
   175         addressResolved = true;
       
   176         mDisplayString = mDisplayString + QString(posGeoAddress.street()) + QString(' ');
       
   177         }
       
   178     if(!posGeoAddress.district().isEmpty())
       
   179         {
       
   180         qDebug() << "district - %s"<<posGeoAddress.district();
       
   181 
       
   182         addressResolved = true;
       
   183         mDisplayString = mDisplayString + QString(posGeoAddress.district()) + QString(' ');
       
   184         }
       
   185     if(!posGeoAddress.city().isEmpty())
       
   186         {
       
   187         qDebug() << "city - %s"<<posGeoAddress.city();
       
   188 
       
   189         addressResolved = true;
       
   190         mDisplayString = mDisplayString + QString(posGeoAddress.city()) + QString(' ');
       
   191         }
       
   192     if(!posGeoAddress.state().isEmpty())
       
   193         {
       
   194         qDebug() << "state - %s"<<posGeoAddress.state();
       
   195 
       
   196         addressResolved = true;
       
   197         mDisplayString = mDisplayString + QString(posGeoAddress.state()) + QString(' ');
       
   198         }
       
   199     if(!posGeoAddress.country().isEmpty())
       
   200         {
       
   201         qDebug() << "country - %s"<<posGeoAddress.country();
       
   202 
       
   203         addressResolved = true;
       
   204         mDisplayString = mDisplayString + QString(posGeoAddress.country());
       
   205         ApiLogger::NftLogger("address information available");
       
   206         }
       
   207     
       
   208     if(addressResolved == false)
       
   209             {
       
   210                 qDebug() << "Address Not available, displaying lat,long";
       
   211                 QString latitude, longitude;
       
   212                 latitude = QString("latitude");
       
   213                 ConvertToDMSFormat(latitude, posGeoAddress.latitude());
       
   214                 longitude = QString("longitude");
       
   215                 ConvertToDMSFormat(longitude, posGeoAddress.longitude());
       
   216 
       
   217                 QString comma(", ");
       
   218                 mDisplayString.clear();
       
   219                 mDisplayString.append(latitude);
       
   220                 mDisplayString.append(comma);
       
   221                 mDisplayString.append(longitude);
       
   222                 ApiLogger::NftLogger("Position information available");
       
   223             }
       
   224     
       
   225     if( processedAddess == true)
       
   226         {
       
   227         processedAddess = false;
       
   228         }
       
   229     else
       
   230         {
       
   231         processedAddess = true;
       
   232         }
       
   233     
       
   234     emit dataChanged();
       
   235 	qDebug() << "- PosIndicator::refreshPosIndicatorPane()";
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // PosIndicator::~PosIndicator
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 PosIndicator::~PosIndicator()
       
   243 {
       
   244     qDebug() << "+ PosIndicator::~PosIndicator()";
       
   245     if(mPosIndicatorInfo)
       
   246     		{
       
   247 			mPosIndicatorInfo->cancelPosInfo();
       
   248 		    delete mPosIndicatorInfo;
       
   249 		    mPosIndicatorInfo = 0;
       
   250 				}    			
       
   251     qDebug() << "- PosIndicator::~PosIndicator()";
       
   252 }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // PosIndicator::indicatorData
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 QVariant PosIndicator::indicatorData(int role) const
       
   259 {
       
   260    qDebug() << "+ PosIndicator::indicatorData(), role = "<< role;
       
   261 //    Q_UNUSED(role)
       
   262         
       
   263     if (role == PrimaryTextRole) {
       
   264         return QString(hbTrId("txt_loe_dblist_positioning"));
       
   265     } else if (role == SecondaryTextRole) {
       
   266         return mDisplayString;   
       
   267     } else if (role == DecorationNameRole) {
       
   268         return QString("qtg_mono_gps");
       
   269     } else if (role == MonoDecorationNameRole  ) {
       
   270         return QString("qtg_mono_gps");
       
   271     }
       
   272      else
       
   273         return QVariant();
       
   274 }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // PosIndicator::refreshData
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 bool PosIndicator::refreshData()
       
   281     {
       
   282     qDebug() << "+ PosIndicator::refreshData()";
       
   283     if(!mPosIndicatorInfo)
       
   284     {
       
   285     qDebug() << "First Call";
       
   286     	mPosIndicatorInfo = new PosIndicatorInfo();
       
   287 			if(!mPosIndicatorInfo)
       
   288 	    		{
       
   289                 qDebug() << "Error in constructing PosIndicatorInfo class";
       
   290                 throw;
       
   291 	    		}
       
   292 	    		
       
   293      	QObject::connect(mPosIndicatorInfo, SIGNAL(posInfoUpdated(PosGeoAddress&, int)), this, SLOT(refreshPosIndicatorPane(PosGeoAddress&, int))); 
       
   294 	  }
       
   295 		ApiLogger::NftLogger("Before requesting position information");
       
   296 	  qDebug() << "Call requestPosInfo()";
       
   297     mPosIndicatorInfo->requestPosInfo();
       
   298     return true;
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // PosIndicator::ConvertToDMSFormat
       
   303 // ---------------------------------------------------------------------------
       
   304 //
       
   305 void PosIndicator::ConvertToDMSFormat(QString &displayString, double decimal)
       
   306 {
       
   307     qDebug() << "+ PosIndicator::ConvertToDMSFormat()";
       
   308 
       
   309     int tempNum;
       
   310     QString temp;
       
   311     float tempDec;
       
   312     
       
   313     int degrees = (int)decimal;
       
   314     
       
   315     tempDec = decimal - degrees;
       
   316     tempDec = tempDec * 60;
       
   317     int minutes = (int)tempDec;
       
   318 
       
   319     tempDec = tempDec - minutes;
       
   320     tempDec = tempDec * 60;
       
   321     int seconds = (int)tempDec;
       
   322     
       
   323     tempDec = tempDec - seconds;
       
   324     tempNum = tempDec * 100;
       
   325  
       
   326     QVariant varDegrees(degrees);
       
   327     QVariant varMinutes(minutes);
       
   328     QVariant varSeconds(seconds);
       
   329     QVariant varTemp(tempNum);
       
   330        
       
   331     if (QString::compare(displayString, "latitude") == KErrNone)
       
   332     {
       
   333     displayString.clear();
       
   334 
       
   335     if (decimal>=0)
       
   336         {
       
   337         displayString = QString(hbTrId("txt_loe_list_l1l2l3l4n"))
       
   338                                 .arg(varDegrees.toString())
       
   339                                 .arg(varMinutes.toString())
       
   340                                 .arg(varSeconds.toString())
       
   341                                 .arg(varTemp.toString());
       
   342         }
       
   343     else
       
   344         {
       
   345         displayString = QString(hbTrId("txt_loe_list_l1l2l3l4s"))
       
   346                                 .arg(varDegrees.toString())
       
   347                                 .arg(varMinutes.toString())
       
   348                                 .arg(varSeconds.toString())
       
   349                                 .arg(varTemp.toString());
       
   350         }
       
   351     }
       
   352     else
       
   353         {
       
   354         displayString.clear();
       
   355         {
       
   356         if (decimal>=0)
       
   357             {
       
   358             displayString = QString(hbTrId("txt_loe_list_l1l2l3l4e"))
       
   359                                 .arg(varDegrees.toString())
       
   360                                 .arg(varMinutes.toString())
       
   361                                 .arg(varSeconds.toString())
       
   362                                 .arg(varTemp.toString());
       
   363             }
       
   364         else
       
   365             {
       
   366             displayString = QString(hbTrId("txt_loe_list_l1l2l3l4w"))
       
   367                                 .arg(varDegrees.toString())
       
   368                                 .arg(varMinutes.toString())
       
   369                                 .arg(varSeconds.toString())
       
   370                                 .arg(varTemp.toString());
       
   371             }
       
   372         }
       
   373         }
       
   374     qDebug() << "- PosIndicator::ConvertToDMSFormat()";
       
   375 }