homescreenapp/hsutils/src/hstitleresolver.cpp
changeset 39 4e8ebe173323
child 60 30f14686fb04
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
       
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QDebug>
       
    19 #include <QGraphicsLinearLayout>
       
    20 #include <HbTextItem>
       
    21 
       
    22 #include "hstitleresolver.h"
       
    23 #include "hsdeviceinfolistener.h"
       
    24 #include <QDebug>
       
    25 
       
    26 namespace
       
    27 {
       
    28     //Offline text in home screen view title
       
    29     const char hsLocTextId_Title_Offline[] = "txt_homescreen_title_offline";
       
    30     
       
    31     //Text in home screen view title, when device is out of network coverage or no SIM card present
       
    32     const char hsLocTextId_Title_NoService[] = "txt_homescreen_title_no_service";
       
    33 }
       
    34 
       
    35 /*!
       
    36 
       
    37 */
       
    38 HsTitleResolver::HsTitleResolver(QObject *parent)
       
    39     : QObject(parent),
       
    40       mCurrentStatus(HsDeviceInfoListener::NoService)
       
    41 {
       
    42     mDeviceInfoListener = new HsDeviceInfoListener(this);
       
    43     mOperatorName = mDeviceInfoListener->operatorName();
       
    44     mOfflineText = hbTrId(hsLocTextId_Title_Offline);
       
    45     mNoServiceText = hbTrId(hsLocTextId_Title_NoService);
       
    46     
       
    47     connect(mDeviceInfoListener, SIGNAL(networkNameChanged(QString)), SLOT(onNetworkNameChanged(QString)));
       
    48     connect(mDeviceInfoListener, SIGNAL(statusChanged(HsDeviceInfoListener::HsDeviceInfoStatus)), SLOT(onStatusChanged(HsDeviceInfoListener::HsDeviceInfoStatus)));
       
    49     mCurrentStatus = mDeviceInfoListener->status();
       
    50 }
       
    51 
       
    52 /*!
       
    53 
       
    54 */
       
    55 HsTitleResolver::~HsTitleResolver()
       
    56 {
       
    57 }
       
    58 
       
    59 /*!
       
    60 
       
    61 */
       
    62 QString HsTitleResolver::title()
       
    63 {
       
    64     QString titleText;
       
    65     switch (mCurrentStatus) {
       
    66         case HsDeviceInfoListener::NoService:
       
    67             titleText = mNoServiceText;
       
    68             break;
       
    69         case HsDeviceInfoListener::OfflineProfile:
       
    70             titleText = mOfflineText;
       
    71             break;
       
    72         default:
       
    73             if(mOperatorName.isEmpty()) {
       
    74                 //Sometimes devicelistener has not get operatorNameChanged signal when
       
    75                 //profile is changed from Offline to another which has active connections.
       
    76                 mOperatorName = mDeviceInfoListener->operatorName();
       
    77             }
       
    78             titleText = mOperatorName;
       
    79             break;
       
    80     };
       
    81     qDebug() << "HsTitleResolver::title() - " << titleText;    
       
    82     return titleText;
       
    83 }
       
    84 
       
    85 /*!
       
    86 
       
    87 */
       
    88 void HsTitleResolver::onNetworkNameChanged(const QString& name)
       
    89 {
       
    90     qDebug() << "HsTitleResolver::onNetworkNameChanged() - Entry";
       
    91     if (mOperatorName != name && (mCurrentStatus == HsDeviceInfoListener::ServiceAvailable)) {
       
    92         qDebug() << "HsTitleResolver::onNetworkNameChanged() - Emitting: " << name;
       
    93         mOperatorName = name;
       
    94         emit titleChanged(name);
       
    95     }
       
    96     qDebug() << "HsTitleResolver::onNetworkNameChanged() - Exit";
       
    97 }
       
    98 
       
    99 /*!
       
   100 
       
   101 */
       
   102 void HsTitleResolver::onStatusChanged(HsDeviceInfoListener::HsDeviceInfoStatus status)
       
   103 {   
       
   104     qDebug() << "HsTitleResolver::onStatusChanged() - Entry";
       
   105     if (mCurrentStatus != status) {
       
   106         mCurrentStatus = status;
       
   107         qDebug() << "HsTitleResolver::onStatusChanged() - Emitting: " << title();
       
   108         emit titleChanged(title());
       
   109     }
       
   110     qDebug() << "HsTitleResolver::onStatusChanged() - Exit";
       
   111 }
       
   112