connectionmonitoring/cellularindicatorplugin/src/cellularindicatorplugin.cpp
changeset 18 fcbbe021d614
child 20 9c97ad6591ae
equal deleted inserted replaced
4:77415202bfc8 18:fcbbe021d614
       
     1 /*
       
     2  * Copyright (c) 2009 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:
       
    15  * 
       
    16  */
       
    17 
       
    18 #include <QtPlugin>
       
    19 #include <QTranslator>
       
    20 #include <QLocale>
       
    21 #include <QList>
       
    22 #include <HbLabel>
       
    23 #include <HbDialog>
       
    24 #include <HbDocumentLoader>
       
    25 #include <HbPushButton>
       
    26 #include <HbView>
       
    27 #include <HbApplication>
       
    28 #include "cellularindicatorplugin.h"
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "cellularindicatorpluginTraces.h"
       
    32 #endif
       
    33 
       
    34 Q_EXPORT_PLUGIN(CellularIndicatorPlugin)
       
    35 
       
    36 const static char IndicatorType[] =
       
    37     "com.nokia.hb.indicator.connectivity.cellularindicatorplugin/1.0";
       
    38 
       
    39 /*!
       
    40     CellularIndicatorPlugin::CellularIndicatorPlugin
       
    41  */
       
    42 CellularIndicatorPlugin::CellularIndicatorPlugin() :
       
    43     HbIndicatorInterface(IndicatorType, GroupPriorityAverage,
       
    44         InteractionActivated),
       
    45     mError(0)
       
    46 {
       
    47     OstTraceFunctionEntry0( CELLULARINDICATORPLUGIN_CELLULARINDICATORPLUGIN_ENTRY );
       
    48     mIndicatorTypes <<
       
    49         "com.nokia.hb.indicator.connectivity.cellularindicatorplugin/1.0";
       
    50     OstTraceFunctionExit0( CELLULARINDICATORPLUGIN_CELLULARINDICATORPLUGIN_EXIT );
       
    51 }
       
    52 
       
    53 /*!
       
    54     CellularIndicatorPlugin::~CellularIndicatorPlugin
       
    55  */
       
    56 CellularIndicatorPlugin::~CellularIndicatorPlugin()
       
    57 {
       
    58     OstTraceFunctionEntry0( CELLULARINDICATORPLUGIN_DCELLULARINDICATORPLUGIN_ENTRY );
       
    59     OstTraceFunctionExit0( CELLULARINDICATORPLUGIN_DCELLULARINDICATORPLUGIN_EXIT );
       
    60 }
       
    61 
       
    62 /*!
       
    63     CellularIndicatorPlugin::indicatorTypes
       
    64  */
       
    65 QStringList CellularIndicatorPlugin::indicatorTypes() const
       
    66 {
       
    67     OstTraceFunctionEntry0( CELLULARINDICATORPLUGIN_INDICATORTYPES_ENTRY );
       
    68     OstTraceFunctionExit0( CELLULARINDICATORPLUGIN_INDICATORTYPES_EXIT );
       
    69     return mIndicatorTypes;
       
    70 }
       
    71 
       
    72 /*!
       
    73     CellularIndicatorPlugin::accessAllowed
       
    74  */
       
    75 bool CellularIndicatorPlugin::accessAllowed(const QString &indicatorType,
       
    76     const HbSecurityInfo *securityInfo) const
       
    77 {
       
    78     OstTraceFunctionEntry0( CELLULARINDICATORPLUGIN_ACCESSALLOWED_ENTRY );
       
    79     Q_UNUSED(indicatorType)
       
    80     Q_UNUSED(securityInfo)
       
    81 
       
    82     OstTraceFunctionExit0( CELLULARINDICATORPLUGIN_ACCESSALLOWED_EXIT );
       
    83     return true;
       
    84 }
       
    85 
       
    86 /*!
       
    87     CellularIndicatorPlugin::createIndicator
       
    88  */
       
    89 HbIndicatorInterface* CellularIndicatorPlugin::createIndicator(
       
    90     const QString &indicatorType)
       
    91 {
       
    92     OstTraceFunctionEntry0( CELLULARINDICATORPLUGIN_CREATEINDICATOR_ENTRY );
       
    93     
       
    94     Q_UNUSED(indicatorType)
       
    95     
       
    96     // Install localization
       
    97     QTranslator *translator = new QTranslator(this);
       
    98 
       
    99     QString lang = QLocale::system().name(); 
       
   100     QString path = "Z:/resource/qt/translations/"; 
       
   101     translator->load("cellularindicatorplugin_" + lang, path);
       
   102     qApp->installTranslator(translator);
       
   103     
       
   104     OstTraceFunctionExit0( CELLULARINDICATORPLUGIN_CREATEINDICATOR_EXIT );
       
   105     return this;
       
   106 }
       
   107 
       
   108 /*!
       
   109     CellularIndicatorPlugin::error
       
   110  */
       
   111 int CellularIndicatorPlugin::error() const
       
   112 {
       
   113     OstTraceFunctionEntry0( CELLULARINDICATORPLUGIN_ERROR_ENTRY );
       
   114     OstTraceFunctionExit0( CELLULARINDICATORPLUGIN_ERROR_EXIT );
       
   115     return mError;
       
   116 }
       
   117 
       
   118 /*!
       
   119     CellularIndicatorPlugin::handleClientRequest
       
   120  */
       
   121 bool CellularIndicatorPlugin::handleClientRequest(RequestType type,
       
   122     const QVariant &parameter)
       
   123 {
       
   124     OstTraceFunctionEntry0( CELLULARINDICATORPLUGIN_HANDLECLIENTREQUEST_ENTRY );
       
   125     
       
   126     bool handled(false);
       
   127 
       
   128     switch (type) {
       
   129     case RequestActivate:
       
   130         if (mParameter != parameter) {
       
   131             mParameter = parameter;
       
   132             emit dataChanged();
       
   133         }
       
   134         handled =  true;
       
   135         break;
       
   136     
       
   137     case RequestDeactivate:
       
   138         mParameter.clear();
       
   139         break;
       
   140         
       
   141     default:
       
   142         // Do nothing
       
   143         break;
       
   144     }
       
   145 
       
   146     OstTraceFunctionExit0( CELLULARINDICATORPLUGIN_HANDLECLIENTREQUEST_EXIT );
       
   147     return handled;
       
   148 }
       
   149 
       
   150 /*!
       
   151     CellularIndicatorPlugin::handleInteraction
       
   152  */
       
   153 bool CellularIndicatorPlugin::handleInteraction(InteractionType type)
       
   154 {
       
   155     OstTraceFunctionEntry0( CELLULARINDICATORPLUGIN_HANDLEINTERACTION_ENTRY );
       
   156     
       
   157     Q_UNUSED(type)
       
   158     bool handled = false;
       
   159     
       
   160     switch(type) {
       
   161     case InteractionActivated:
       
   162         //connect error() to slot processError() to get error, 
       
   163         QObject::connect( &process, SIGNAL(error(QProcess::ProcessError)),                       
       
   164                           this, SLOT(processError(QProcess::ProcessError)));
       
   165 
       
   166         // Show connection view
       
   167         process.start("connview");
       
   168         handled = true;
       
   169         break;
       
   170     
       
   171     default:
       
   172         break;
       
   173     }
       
   174 
       
   175     OstTraceFunctionExit0( CELLULARINDICATORPLUGIN_HANDLEINTERACTION_EXIT );
       
   176     return handled;
       
   177 }
       
   178 
       
   179 /*!
       
   180     CellularIndicatorPlugin::indicatorData
       
   181 */
       
   182 QVariant CellularIndicatorPlugin::indicatorData(int role) const
       
   183 {
       
   184     OstTraceFunctionEntry0( CELLULARINDICATORPLUGIN_INDICATORDATA_ENTRY );
       
   185     QVariant ret = NULL;
       
   186     
       
   187     switch(role) {
       
   188     case PrimaryTextRole:
       
   189         ret = QString(hbTrId("txt_occ_dblist_cellular_data"));
       
   190         break;
       
   191 
       
   192     case SecondaryTextRole:
       
   193         if (mParameter.isValid() && (mParameter.type() == QVariant::List)) {
       
   194 
       
   195             QList<QVariant> indicatorInfo; 
       
   196             indicatorInfo = mParameter.toList();
       
   197 
       
   198             if (!indicatorInfo.count()) {
       
   199                 // No entries on the list -> don't even try to use this
       
   200                 break;
       
   201             }
       
   202             
       
   203             if ( (indicatorInfo[0].toInt() > 1) && indicatorInfo.count() ) {
       
   204                 
       
   205                 // More than one connection -> show number of connections
       
   206                 QString str = QString(hbTrId("txt_occ_dblist_cellular_data_val_l1_connections"));
       
   207                 ret = str.arg(indicatorInfo[0].toInt());
       
   208             }
       
   209             else if ( indicatorInfo[0].toInt() && (indicatorInfo.count() >= 2)) {
       
   210                 
       
   211                 // Only one connection -> show name of the iap
       
   212                 QString iapName;
       
   213                 iapName = indicatorInfo[1].toString();
       
   214                 QString str = QString(hbTrId("txt_occ_dblist_cellular_data_val_1_connected"));
       
   215                 ret = str.arg(iapName);
       
   216             }
       
   217         }
       
   218         break;
       
   219 
       
   220     case IconNameRole:
       
   221     case DecorationNameRole:
       
   222         // Return the icon
       
   223         ret = HbIcon("qtg_small_gprs");
       
   224         break;
       
   225     
       
   226     default:
       
   227         // Do nothing
       
   228         break;
       
   229     }
       
   230     
       
   231     OstTraceFunctionExit0( CELLULARINDICATORPLUGIN_INDICATORDATA_EXIT );
       
   232     return ret;
       
   233 }
       
   234 
       
   235 /*!
       
   236     The processError is a handler for error codes.
       
   237 */
       
   238 void CellularIndicatorPlugin::processError(QProcess::ProcessError err)
       
   239     {
       
   240     OstTraceFunctionEntry1(CELLULARINDICATORPLUGIN_PROCESSERROR_ENTRY, this);
       
   241   
       
   242     switch (err) {   
       
   243         case QProcess::FailedToStart: 
       
   244         case QProcess::Crashed: 
       
   245         case QProcess::Timedout: 
       
   246         case QProcess::ReadError: 
       
   247         case QProcess::WriteError: 
       
   248         case QProcess::UnknownError:
       
   249             OstTrace1( CELLULARINDICATORPLUGIN_ERR,PROCESSERROR_KNOWN,"Process Error %u", err);
       
   250             break;  
       
   251         default:
       
   252         OstTrace1( CELLULARINDICATORPLUGIN_ERR,PROCESSERROR_UNKNOWN,"Unknown Process Error %u", err);
       
   253             break;
       
   254         }
       
   255     OstTraceFunctionExit1(CELLULARINDICATORPLUGIN_PROCESSERROR_EXIT, this);
       
   256     }
       
   257