phoneplugins/infowidgetplugin/infowidget/src/infowidget.cpp
branchRCL_3
changeset 24 41a7f70b3818
equal deleted inserted replaced
23:40a3f856b14d 24:41a7f70b3818
       
     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 "infowidget.h"
       
    19 #include <hbiconitem.h>
       
    20 #include <hbmarqueeitem.h>
       
    21 #include <hbfontspec.h>
       
    22 #include <hbaction.h>
       
    23 #include <hbcheckbox.h>
       
    24 #include <hbevent.h>
       
    25 #include <hbcolorscheme.h>
       
    26 #include <hbdialog.h>
       
    27 #include <hbmessagebox.h>
       
    28 #include <hbframedrawer.h>
       
    29 #include <hbframeitem.h>
       
    30 #include <hbtapgesture.h>
       
    31 #include <QPainter>
       
    32 #include <QPainterPath>
       
    33 #include <QBrush>
       
    34 #include <QGraphicsLinearLayout>
       
    35 #include <QApplication>
       
    36 #include <QLocale>
       
    37 #include <QScopedPointer>
       
    38 #include <QGesture>
       
    39 #include "infowidgetlogging.h"
       
    40 #include "infowidgetengine.h"
       
    41 #include "infowidgetlayoutmanager.h"
       
    42 #include "infowidgetpreferences.h"
       
    43 
       
    44 /*!
       
    45   \class InfoWidget
       
    46   \brief Operator info widget main class. 
       
    47 
       
    48    Implements HomeScreen specific slots and 
       
    49    graphical representation of the 
       
    50    Operator Info widget. 
       
    51     
       
    52 */
       
    53 
       
    54 // Local constants 
       
    55 const int INFOWIDGET_DEFAULT_HEIGHT = 100;
       
    56 const int INFOWIDGET_DEFAULT_WIDTH = 200;
       
    57 const int INFOWIDGET_MARQUEE_START_DELAY = 5000; 
       
    58 const char *BACKGROUND_FRAME_NAME = "qtg_fr_hswidget_normal"; 
       
    59 
       
    60 /*!
       
    61     Constructor.  
       
    62 */
       
    63 InfoWidget::InfoWidget(QGraphicsItem* parent, Qt::WindowFlags flags)
       
    64     : HbWidget(parent, flags),
       
    65     m_animationState(AnimationIdle), 
       
    66     m_engine(NULL), 
       
    67     m_preferences(NULL),
       
    68     m_layoutManager(NULL),
       
    69     m_layout(NULL),
       
    70     m_backgroundFrameItem(NULL),
       
    71     m_timerId(0),
       
    72     m_layoutChanging(false),
       
    73     m_initialized(false)
       
    74 {
       
    75     INSTALL_TRACE_MSG_HANDLER; 
       
    76     DPRINT;
       
    77  
       
    78     // Create layout & child-widget manager 
       
    79     m_layoutManager.reset(new InfoWidgetLayoutManager);
       
    80     
       
    81     // Create widget engine 
       
    82     m_engine.reset(new InfoWidgetEngine);
       
    83     
       
    84     // Create preference store and start listening signal(s) 
       
    85     m_preferences.reset(new InfoWidgetPreferences);
       
    86     QObject::connect(m_preferences.data(), 
       
    87             SIGNAL(preferencesChanged(InfoWidgetPreferences::Options)),
       
    88                 m_engine.data(), 
       
    89             SLOT(handlePreferencesChanged(
       
    90                 InfoWidgetPreferences::Options)));
       
    91 
       
    92     // Setup widget main layout 
       
    93     m_layout = new QGraphicsLinearLayout;    
       
    94     m_layout->setSpacing(0); 
       
    95     m_layout->setContentsMargins(0,0,0,0); 
       
    96     setLayout(m_layout);
       
    97   
       
    98     // Create and set background frame drawer
       
    99     QScopedPointer<HbFrameDrawer> backgroundFrameDrawer(
       
   100             new HbFrameDrawer(
       
   101                     BACKGROUND_FRAME_NAME, 
       
   102                     HbFrameDrawer::NinePieces));
       
   103     Q_ASSERT(!backgroundFrameDrawer.isNull()); 
       
   104     
       
   105     // Set widget initial size
       
   106     resize(INFOWIDGET_DEFAULT_WIDTH,
       
   107            INFOWIDGET_DEFAULT_HEIGHT); 
       
   108 
       
   109     // Ownership of frame drawer is 
       
   110     // transferred for frame item
       
   111     m_backgroundFrameItem = new HbFrameItem(
       
   112             backgroundFrameDrawer.take(), this);  
       
   113     
       
   114     setBackgroundItem(m_backgroundFrameItem);
       
   115     
       
   116     // Listen for tap events 
       
   117     grabGesture(Qt::TapGesture);
       
   118 }
       
   119 
       
   120 /*!
       
   121     Destructor.  
       
   122 */
       
   123 InfoWidget::~InfoWidget()
       
   124 {
       
   125     DPRINT;
       
   126     // Force layout manager to delete widgets 
       
   127     // before InfoWidget is destroyed   
       
   128     m_layoutManager->destroyWidgets(); 
       
   129     UNINSTALL_TRACE_MSG_HANDLER;
       
   130 }
       
   131 
       
   132 /*!
       
   133     Called by HS framework, saved preference data
       
   134     is available when onInitialize() is called and 
       
   135     meta-object data reading should be done here.       
       
   136 */
       
   137 void InfoWidget::onInitialize()
       
   138 {
       
   139     DPRINT; 
       
   140     m_initialized = true; 
       
   141     // Initialize preferences from meta-object data
       
   142     if (!readPersistentPreferences()) {
       
   143         // Reading failed, initialize default values  
       
   144         m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, 
       
   145                 DISPLAY_SETTING_ON);
       
   146         m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, 
       
   147                 DISPLAY_SETTING_ON);
       
   148         m_preferences->setPreference(InfoWidgetPreferences::DisplaySatText, 
       
   149                 DISPLAY_SETTING_ON);
       
   150     } 
       
   151     m_preferences->storePreferences(); 
       
   152     
       
   153     // Layout components 
       
   154     layoutInfoDisplay();
       
   155     
       
   156     // Update background frame size  
       
   157     m_backgroundFrameItem->resize(size());
       
   158     
       
   159     // Listen for model changes 
       
   160     QObject::connect(m_engine.data(), SIGNAL(modelChanged()), 
       
   161             this, SLOT(readModel()), Qt::UniqueConnection); 
       
   162 }
       
   163 
       
   164 /*!
       
   165     This slot is called by HomeScreen framework 
       
   166     when the widget is uninstalled.    
       
   167 */
       
   168 void InfoWidget::onUninitialize()
       
   169 {
       
   170     DPRINT;
       
   171     stopMarquees();
       
   172     m_initialized = false; 
       
   173     m_engine->suspend();
       
   174 }
       
   175 
       
   176 /*!
       
   177     This slot is called by HomeScreen framework 
       
   178     when the widget visibility is gained.    
       
   179 */
       
   180 void InfoWidget::onShow()
       
   181 {
       
   182     DPRINT;
       
   183     if (m_initialized) { 
       
   184         m_engine->resume();
       
   185         updateInfoDisplay(); 
       
   186     }
       
   187 }
       
   188 
       
   189 /*!
       
   190     This slot is called by HomeScreen framework 
       
   191     when the widget visibility is lost.    
       
   192 */
       
   193 void InfoWidget::onHide()
       
   194 {
       
   195     DPRINT;
       
   196     if (m_initialized) { 
       
   197         m_engine->suspend();
       
   198         stopMarquees(); 
       
   199     }
       
   200 }
       
   201 
       
   202 /*!
       
   203     Handles timer events.  
       
   204 */
       
   205 void InfoWidget::timerEvent(QTimerEvent *event)
       
   206 {
       
   207     Q_UNUSED(event); 
       
   208     if (m_animationState == AnimationStarting) {
       
   209         // Execute delayed start of marquee animation 
       
   210         if (m_animatingItem) {
       
   211             m_animationState = AnimationOngoing;
       
   212             m_animatingItem->startAnimation(); 
       
   213         } 
       
   214     }
       
   215     
       
   216     if (m_timerId) {
       
   217         killTimer(m_timerId);
       
   218         m_timerId = 0;
       
   219     }
       
   220 }
       
   221 
       
   222 /*!
       
   223     Returns bounding rect. 
       
   224 */
       
   225 QRectF InfoWidget::boundingRect() const
       
   226 {   
       
   227     return rect();
       
   228 }
       
   229 
       
   230 /*!
       
   231     Calculate widget size hint based on visible row count.  
       
   232 */
       
   233 QSizeF InfoWidget::sizeHint(Qt::SizeHint which, 
       
   234         const QSizeF & constraint) const   
       
   235 {
       
   236     Q_UNUSED(which);
       
   237     Q_UNUSED(constraint); 
       
   238     
       
   239     QSizeF requiredSize(
       
   240             INFOWIDGET_DEFAULT_WIDTH,
       
   241             INFOWIDGET_DEFAULT_HEIGHT);
       
   242     
       
   243     if (m_initialized) { 
       
   244         // Read size hint from docml content
       
   245         requiredSize = m_layoutManager->contentWidget()->minimumSize();
       
   246         // Height according number of rows, if 0 or 1 row use minimum size
       
   247         int rowCount = m_preferences->visibleItemCount();
       
   248         if (1 < rowCount) {
       
   249                 requiredSize.rheight() += (rowCount-1)*
       
   250                         m_layoutManager->layoutRowHeight();
       
   251         }
       
   252         
       
   253         // Update background frame size 
       
   254         // if widget size is changing
       
   255         if (size() != requiredSize) {
       
   256             m_backgroundFrameItem->resize(requiredSize);
       
   257         }
       
   258     }
       
   259     return requiredSize; 
       
   260 }
       
   261 
       
   262 /*!
       
   263     Returns size polizy for the widget.   
       
   264 */
       
   265 QSizePolicy InfoWidget::sizePolicy () const 
       
   266 {
       
   267     DPRINT;
       
   268     return QSizePolicy(
       
   269             QSizePolicy::Fixed, 
       
   270             QSizePolicy::Fixed); 
       
   271 }
       
   272 
       
   273 /*!
       
   274     Update item visibility based on display preferences.   
       
   275 */
       
   276 void InfoWidget::updateItemsVisibility()
       
   277 {
       
   278     DPRINT; 
       
   279     if (m_preferences->preference(InfoWidgetPreferences::DisplaySpn).compare(
       
   280             DISPLAY_SETTING_OFF) == 0) {
       
   281         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnMarqueeItem); 
       
   282         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnIcon); 
       
   283     }
       
   284     
       
   285     if (m_preferences->preference(InfoWidgetPreferences::DisplayMcn).compare(
       
   286             DISPLAY_SETTING_OFF) == 0) {
       
   287         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnMarqueeItem); 
       
   288         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnIcon); 
       
   289     }
       
   290     
       
   291     if (m_preferences->preference(InfoWidgetPreferences::DisplaySatText).compare(
       
   292             DISPLAY_SETTING_OFF) == 0) {
       
   293         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatMarqueeItem); 
       
   294         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatTextIcon); 
       
   295     }
       
   296 }
       
   297 
       
   298 /*!
       
   299     Layout info display.    
       
   300 */
       
   301 void InfoWidget::layoutInfoDisplay()
       
   302 {  
       
   303     DPRINT;
       
   304     QGraphicsWidget *infoDisplay = 
       
   305         m_layoutManager->layoutInfoDisplay(); 
       
   306     if ((!m_layout->count()) && infoDisplay) {
       
   307             m_layout->addItem(infoDisplay);
       
   308         }
       
   309 
       
   310     updateItemsVisibility(); 
       
   311     endChanges();
       
   312 }
       
   313 
       
   314 /*!
       
   315     Layout and display settings dialog.    
       
   316 */
       
   317 void InfoWidget::layoutSettingsDialog()
       
   318 {  
       
   319     DPRINT;
       
   320     startChanges();
       
   321     HbDialog *settingsDialog =
       
   322             qobject_cast<HbDialog *>(
       
   323                     m_layoutManager->layoutSettingsDialog()); 
       
   324 
       
   325     if (settingsDialog) {
       
   326         initializeSettingsDialogItems();
       
   327         settingsDialog->setDismissPolicy(HbDialog::NoDismiss); 
       
   328         settingsDialog->setTimeout(HbDialog::NoTimeout);
       
   329         settingsDialog->open(this, 
       
   330                 SLOT(settingsDialogClosed(HbAction *))); 
       
   331         }
       
   332 }
       
   333 
       
   334 /*!
       
   335     Set up initial check box states 
       
   336     and connect signals to local slots.  
       
   337 */
       
   338 void InfoWidget::initializeSettingsDialogItems()
       
   339 {  
       
   340     DPRINT;
       
   341     // Connect display setting check boxes
       
   342     HbCheckBox *spnCheckBox = 
       
   343             qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   344                     InfoWidgetLayoutManager::RoleSpnCheckBox));
       
   345     if (spnCheckBox) {
       
   346         spnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   347                 InfoWidgetPreferences::DisplaySpn));
       
   348         
       
   349         QObject::connect(spnCheckBox, SIGNAL(stateChanged(int)), 
       
   350                 this, SLOT(spnDisplaySettingChanged(int)), 
       
   351                 Qt::UniqueConnection); 
       
   352     }
       
   353     
       
   354     HbCheckBox *mcnCheckBox = 
       
   355             qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   356                     InfoWidgetLayoutManager::RoleMcnCheckBox));
       
   357     if (mcnCheckBox) {
       
   358         mcnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   359                 InfoWidgetPreferences::DisplayMcn));
       
   360         
       
   361         QObject::connect(mcnCheckBox, SIGNAL(stateChanged(int)), 
       
   362                 this, SLOT(mcnDisplaySettingChanged(int)), 
       
   363                 Qt::UniqueConnection); 
       
   364     }
       
   365     
       
   366     HbCheckBox *satTextCheckBox = 
       
   367             qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   368                     InfoWidgetLayoutManager::RoleSatTextCheckBox));
       
   369     if (satTextCheckBox) {
       
   370         satTextCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   371                 InfoWidgetPreferences::DisplaySatText));
       
   372         
       
   373         QObject::connect(satTextCheckBox, SIGNAL(stateChanged(int)), 
       
   374                 this, SLOT(satDisplaySettingChanged(int)), 
       
   375                 Qt::UniqueConnection); 
       
   376     }
       
   377 }
       
   378 
       
   379 /*!
       
   380     Fetch widget based on item role and update 
       
   381     item specific data. 
       
   382 */
       
   383 void InfoWidget::updateInfoDisplayItem(
       
   384         InfoWidgetLayoutManager::LayoutItemRole itemRole, 
       
   385         QString text)
       
   386 {
       
   387     DPRINT; 
       
   388     HbMarqueeItem *marqueeItem = qobject_cast<HbMarqueeItem *>(
       
   389             m_layoutManager->getWidget(itemRole));
       
   390     if (marqueeItem) {
       
   391         marqueeItem->setText(text);
       
   392         marqueeItem->setTextColor( HbColorScheme::color(
       
   393                 "qtc_hs_list_item_title_normal"));
       
   394         
       
   395         // Update widget effective size
       
   396         marqueeItem->adjustSize();
       
   397         if (!m_layoutManager->textFitsToRect(
       
   398                 text,
       
   399                 marqueeItem->font(), 
       
   400                 marqueeItem->rect())) {
       
   401             DPRINT << ": enable marquee animation";
       
   402             m_animatingItems.append(marqueeItem);
       
   403         }
       
   404     }
       
   405 }
       
   406 
       
   407 /*!
       
   408     Model or visibility data has changed, 
       
   409     update info display widgets accordingly. 
       
   410 */
       
   411 void InfoWidget::updateInfoDisplay()
       
   412 {
       
   413     DPRINT; 
       
   414     if (m_initialized) {
       
   415         stopMarquees();
       
   416         
       
   417         if (m_layoutManager->currentDisplayRole() == 
       
   418                 InfoWidgetLayoutManager::InfoDisplay) {
       
   419             
       
   420             InfoWidgetEngine::ModelData modelData = m_engine->modelData(); 
       
   421         
       
   422             // Update service provider name item
       
   423             QString text = modelData.serviceProviderName();
       
   424             updateInfoDisplayItem(
       
   425                     InfoWidgetLayoutManager::RoleSpnMarqueeItem, text); 
       
   426 
       
   427             // Update MCN name item
       
   428             text = modelData.mcnName();
       
   429             updateInfoDisplayItem(
       
   430                     InfoWidgetLayoutManager::RoleMcnMarqueeItem, text); 
       
   431             
       
   432             // Update SAT display text item
       
   433             text = modelData.satDisplayText();
       
   434             updateInfoDisplayItem(
       
   435                     InfoWidgetLayoutManager::RoleSatMarqueeItem, text); 
       
   436         }
       
   437         
       
   438         if (m_animatingItems.count() > 0) {
       
   439             startMarquees(); 
       
   440         }
       
   441     }
       
   442 }
       
   443 
       
   444 /*!
       
   445     Read model data. 
       
   446     Model's modelChanged - signal is connected to this slot.  
       
   447 */
       
   448 void InfoWidget::readModel()
       
   449 {
       
   450     DPRINT; 
       
   451     if (m_layoutManager->currentDisplayRole() == 
       
   452             InfoWidgetLayoutManager::InfoDisplay) { 
       
   453         updateInfoDisplay(); 
       
   454     }
       
   455 }
       
   456 
       
   457 /*!
       
   458     Model error signal is connected to this slot. 
       
   459 */
       
   460 void InfoWidget::handleModelError(int operation,int errorCode)
       
   461 {
       
   462     DWARNING << ": operation: " << operation << 
       
   463                 " error: " << errorCode; 
       
   464 }
       
   465 
       
   466 /*!
       
   467     Tap gesture handler.   
       
   468 */
       
   469 void InfoWidget::gestureEvent(QGestureEvent *event)
       
   470 {
       
   471 HbTapGesture *gesture = qobject_cast<HbTapGesture *>(
       
   472         event->gesture(Qt::TapGesture));
       
   473 
       
   474 if(!gesture)return;
       
   475 switch (gesture->state()) {
       
   476     case Qt::GestureFinished:
       
   477         if (gesture->tapStyleHint() == HbTapGesture::Tap) {
       
   478             if (m_layoutManager->currentDisplayRole() == 
       
   479                             InfoWidgetLayoutManager::InfoDisplay) {
       
   480                   DPRINT << ": layout and display settings dialog";
       
   481                   layoutSettingsDialog();
       
   482               } 
       
   483         }
       
   484     break;
       
   485     
       
   486     default: 
       
   487         break;
       
   488     }
       
   489 }
       
   490 
       
   491 /*!
       
   492     Slot for handling Spn display setting change.  
       
   493 */
       
   494 void InfoWidget::spnDisplaySettingChanged(int state)
       
   495 {
       
   496     DPRINT << ": state: " << state;
       
   497     if (state == Qt::Checked){
       
   498         m_preferences->setPreference(
       
   499                 InfoWidgetPreferences::DisplaySpn, DISPLAY_SETTING_ON);
       
   500     } else {
       
   501         m_preferences->setPreference(
       
   502                 InfoWidgetPreferences::DisplaySpn, DISPLAY_SETTING_OFF);
       
   503     }
       
   504 }
       
   505 
       
   506 /*!
       
   507     Slot for handling Mcn display setting change. 
       
   508 */
       
   509 void InfoWidget::mcnDisplaySettingChanged(int state)
       
   510 {
       
   511     DPRINT << ": state: " << state; 
       
   512     if (state == Qt::Checked){
       
   513         m_preferences->setPreference(
       
   514                 InfoWidgetPreferences::DisplayMcn, DISPLAY_SETTING_ON);
       
   515     } else {
       
   516         m_preferences->setPreference(
       
   517                 InfoWidgetPreferences::DisplayMcn, DISPLAY_SETTING_OFF);
       
   518     }
       
   519 }
       
   520 
       
   521 /*!
       
   522     Slot for handling SAT display setting change. 
       
   523 */
       
   524 void InfoWidget::satDisplaySettingChanged(int state)
       
   525 {
       
   526     DPRINT << ": state: " << state; 
       
   527     if (state == Qt::Checked){
       
   528         m_preferences->setPreference(
       
   529                 InfoWidgetPreferences::DisplaySatText, DISPLAY_SETTING_ON);
       
   530     } else {
       
   531         m_preferences->setPreference(
       
   532                 InfoWidgetPreferences::DisplaySatText, DISPLAY_SETTING_OFF);
       
   533     }
       
   534 }
       
   535 
       
   536 /*!
       
   537     Getter function for Meta-object property "mcnDisplay"
       
   538 */
       
   539 QString InfoWidget::mcnDisplay()
       
   540 {
       
   541     DPRINT; 
       
   542     return m_preferences->preference(
       
   543             InfoWidgetPreferences::DisplayMcn); 
       
   544 }
       
   545 
       
   546 /*!
       
   547     Setter function for Meta-object property "mcnDisplay"
       
   548 */
       
   549 void InfoWidget::setMcnDisplay(QString value)
       
   550 {
       
   551     DPRINT;
       
   552     m_preferences->setPreference(
       
   553             InfoWidgetPreferences::DisplayMcn, value);
       
   554     }
       
   555 
       
   556 /*!
       
   557     Getter function for Meta-object property "homeZoneDisplay"
       
   558 */
       
   559 QString InfoWidget::homeZoneDisplay()
       
   560 {
       
   561     DPRINT; 
       
   562     return m_preferences->preference(
       
   563             InfoWidgetPreferences::DisplayHomeZone); 
       
   564 }
       
   565 
       
   566 /*!
       
   567     Setter function for Meta-object property "homeZoneDisplay" 
       
   568 */
       
   569 void InfoWidget::setHomeZoneDisplay(QString value)
       
   570 {
       
   571     DPRINT; 
       
   572     m_preferences->setPreference(
       
   573             InfoWidgetPreferences::DisplayHomeZone, value);
       
   574 }
       
   575 
       
   576 /*!
       
   577     Getter function for Meta-object property "activeLineDisplay"
       
   578 */
       
   579 QString InfoWidget::activeLineDisplay()
       
   580 {
       
   581     DPRINT; 
       
   582     return m_preferences->preference(
       
   583             InfoWidgetPreferences::DisplayActiveLine);
       
   584 }
       
   585 
       
   586 /*!
       
   587     Setter function for Meta-object property "activeLineDisplay"
       
   588 */
       
   589 void InfoWidget::setActiveLineDisplay(QString value)
       
   590 {
       
   591     DPRINT; 
       
   592     m_preferences->setPreference(
       
   593             InfoWidgetPreferences::DisplayActiveLine, value);
       
   594 }
       
   595 
       
   596 /*!
       
   597     InfoWidget::satDisplay()
       
   598     
       
   599     Getter function for Meta-object property "satDisplay" 
       
   600 */
       
   601 QString InfoWidget::satDisplay()
       
   602 {
       
   603     DPRINT; 
       
   604     return m_preferences->preference(
       
   605             InfoWidgetPreferences::DisplaySatText);
       
   606 }
       
   607 
       
   608 /*!
       
   609     Setter function for Meta-object property "satDisplay" 
       
   610 */
       
   611 void InfoWidget::setSatDisplay(QString value)
       
   612 {
       
   613     DPRINT;
       
   614     m_preferences->setPreference(
       
   615             InfoWidgetPreferences::DisplaySatText, value);
       
   616 }
       
   617 
       
   618 /*!
       
   619     Getter function for Meta-object property "spnDisplay" 
       
   620 */
       
   621 QString InfoWidget::spnDisplay()
       
   622 {
       
   623     DPRINT; 
       
   624     return m_preferences->preference(
       
   625             InfoWidgetPreferences::DisplaySpn);
       
   626 }
       
   627 
       
   628 /*!
       
   629     Setter function for Meta-object property "spnDisplay" 
       
   630 */
       
   631 void InfoWidget::setSpnDisplay(QString value)
       
   632 {
       
   633     DPRINT;
       
   634     m_preferences->setPreference(
       
   635             InfoWidgetPreferences::DisplaySpn, value);
       
   636 }
       
   637 
       
   638 /*!
       
   639     Read Meta-object properties and store to preference handler. 
       
   640     Restores preferences from previous session.   
       
   641 */
       
   642 bool InfoWidget::readPersistentPreferences()
       
   643 {
       
   644     DPRINT;
       
   645     bool changed(false);
       
   646 
       
   647     QString propertyValue = QObject::property("homeZoneDisplay").toString();
       
   648     m_preferences->setPreference(InfoWidgetPreferences::DisplayHomeZone, 
       
   649             propertyValue);
       
   650     
       
   651     propertyValue = QObject::property("mcnDisplay").toString();
       
   652     m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, 
       
   653             propertyValue);
       
   654     
       
   655     propertyValue = QObject::property("activeLineDisplay").toString();
       
   656     m_preferences->setPreference(InfoWidgetPreferences::DisplayActiveLine, 
       
   657             propertyValue);
       
   658     
       
   659     propertyValue = QObject::property("satDisplay").toString();
       
   660     m_preferences->setPreference(InfoWidgetPreferences::DisplaySatText, 
       
   661             propertyValue);
       
   662 
       
   663     propertyValue = QObject::property("spnDisplay").toString();
       
   664     m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, 
       
   665             propertyValue);
       
   666 
       
   667     // Check that at least one item is set visible and  
       
   668     // store preferences if true 
       
   669     if (m_preferences->validate()) {
       
   670         changed = m_preferences->storePreferences(); 
       
   671     } 
       
   672         
       
   673     return changed; 
       
   674 }
       
   675 
       
   676 /*!
       
   677     Read display settings from preference store 
       
   678     and set check box initial states accordingly. 
       
   679 */
       
   680 void InfoWidget::initializeCheckBoxStates()
       
   681 {
       
   682     DPRINT;
       
   683     HbCheckBox *spnCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   684             InfoWidgetLayoutManager::RoleSpnCheckBox));
       
   685     if (spnCheckBox) {
       
   686         spnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   687                 InfoWidgetPreferences::DisplaySpn));
       
   688     }
       
   689     
       
   690     HbCheckBox *mcnCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   691             InfoWidgetLayoutManager::RoleMcnCheckBox));
       
   692     if (mcnCheckBox) {
       
   693         mcnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   694                 InfoWidgetPreferences::DisplayMcn));
       
   695     }
       
   696     
       
   697     HbCheckBox *satTextCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   698             InfoWidgetLayoutManager::RoleSatTextCheckBox));
       
   699     if (satTextCheckBox) {
       
   700         satTextCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   701                 InfoWidgetPreferences::DisplaySatText));
       
   702     }
       
   703 }
       
   704 
       
   705 /*!
       
   706     Handles settings validating and storing
       
   707     when the settings dialog is closed with Ok action.   
       
   708 */
       
   709 void InfoWidget::settingsEditingFinished()
       
   710 {
       
   711     DPRINT;
       
   712     if (m_preferences->validate()) {
       
   713 
       
   714         // Signal HS framework to store Meta-object 
       
   715         // preferences if preferences have changed. 
       
   716         if (m_preferences->storePreferences()) {
       
   717             emit setPreferences(
       
   718                     m_preferences->preferenceNames());
       
   719             }
       
   720         
       
   721         // Visible item configuration changed, reload 
       
   722         // widgets. Restores deleted items.  
       
   723         m_layoutManager->loadWidgets(
       
   724                 InfoWidgetLayoutManager::InfoDisplay);
       
   725         m_layoutManager->removeWidget(
       
   726                 InfoWidgetLayoutManager::RoleSettingsDialog,
       
   727                 true);
       
   728         
       
   729     } else {
       
   730         // Cancel edit mode 
       
   731         settingsEditingCancelled();
       
   732         
       
   733         // Display warning note
       
   734         settingsValidationFailed();
       
   735     }
       
   736 }
       
   737 
       
   738 /*!
       
   739     Slot to be called when settings editing 
       
   740     shouldn't cause change set of visible items. 
       
   741     Restores previous state.  
       
   742 */
       
   743 void InfoWidget::settingsEditingCancelled()
       
   744 {
       
   745     DPRINT;
       
   746     m_preferences->restorePreferences(); 
       
   747     
       
   748     m_layoutManager->loadWidgets(
       
   749             InfoWidgetLayoutManager::InfoDisplay);
       
   750     m_layoutManager->removeWidget(
       
   751             InfoWidgetLayoutManager::RoleSettingsDialog,
       
   752             true); 
       
   753 }
       
   754 
       
   755 /*!
       
   756     Slot to be called when settings dialog is about to close. 
       
   757 */
       
   758 void InfoWidget::settingsDialogClosed(HbAction* action)
       
   759 {
       
   760     DPRINT;
       
   761     if (action) {
       
   762         if (action->text() == hbTrId("txt_common_button_ok")) {
       
   763             settingsEditingFinished(); 
       
   764         } else if (action->text() == hbTrId("txt_common_button_cancel")) {
       
   765             settingsEditingCancelled(); 
       
   766         }       
       
   767     } else {
       
   768         settingsEditingCancelled(); 
       
   769     }
       
   770      
       
   771     // Switch to info display 
       
   772     layoutInfoDisplay();
       
   773 }
       
   774 
       
   775 /*!
       
   776     Handle start of changes, called when settings dialog
       
   777     is shown and layout changes are expected.      
       
   778 */
       
   779 void InfoWidget::startChanges()
       
   780 {
       
   781     DPRINT;
       
   782     m_layoutChanging = true;
       
   783     if (m_animationState != AnimationIdle) {
       
   784         stopMarquees(); 
       
   785     }
       
   786 }
       
   787 
       
   788 /*!
       
   789     Handle end of changes, called when settings dialog
       
   790     is closed and layout changes are to be finished.      
       
   791 */
       
   792 void InfoWidget::endChanges()
       
   793 {
       
   794     DPRINT;
       
   795     updateGeometry();
       
   796     updateInfoDisplay();
       
   797     m_layoutChanging = false;
       
   798 }
       
   799 
       
   800 /*!
       
   801    Listen for theme change event. 
       
   802 */
       
   803 void InfoWidget::changeEvent(QEvent *event)
       
   804 {
       
   805    DPRINT;
       
   806    if (event->type() == HbEvent::ThemeChanged) {
       
   807        DPRINT << ": HbEvent::ThemeChanged";
       
   808        updateInfoDisplay(); 
       
   809    }
       
   810    HbWidget::changeEvent(event);
       
   811 }
       
   812 
       
   813 /*!
       
   814    Slot to be called when preference validation has failed. 
       
   815 */
       
   816 void InfoWidget::settingsValidationFailed()
       
   817 {
       
   818    DPRINT;
       
   819    if (m_initialized) {
       
   820        HbMessageBox::warning(
       
   821                hbTrId("txt_operatorwidget_info_select_one"));
       
   822    }
       
   823 }
       
   824 
       
   825 /*!
       
   826    Start marquee animations. 
       
   827 */
       
   828 bool InfoWidget::startMarquees()
       
   829 {  
       
   830     DPRINT;
       
   831     bool started(true); 
       
   832     
       
   833     if (m_animationState == AnimationOngoing || 
       
   834         m_animationState == AnimationStarting) {
       
   835         return false; 
       
   836         }
       
   837       
       
   838     int animatingItemsCount = m_animatingItems.count();  
       
   839     if (animatingItemsCount > 0) {
       
   840         foreach (HbMarqueeItem *marqueeItem, m_animatingItems) {
       
   841             if (marqueeItem) {
       
   842                 if (animatingItemsCount > 1) {
       
   843                     // Multiple items, connect to marqueeNext() 
       
   844                     // sequence logic
       
   845                     QObject::connect(
       
   846                             marqueeItem, SIGNAL(animationStopped()),
       
   847                             this, SLOT(marqueeNext()), 
       
   848                             Qt::QueuedConnection);
       
   849                     marqueeItem->setLoopCount(1); 
       
   850                 } else if (animatingItemsCount == 1){
       
   851                     // Single item, set continuous marquee mode 
       
   852                     marqueeItem->setLoopCount(-1); 
       
   853                 }
       
   854             }
       
   855         }
       
   856         
       
   857         // Store marquee sequence start item 
       
   858         m_animatingItem = m_animatingItems.first();
       
   859         m_animationState = AnimationStarting;
       
   860         m_timerId = startTimer(INFOWIDGET_MARQUEE_START_DELAY);
       
   861     } else {
       
   862         DPRINT << ": not started, no animating items";
       
   863         m_animatingItem = NULL; 
       
   864         started = false;
       
   865     }
       
   866     return started; 
       
   867 }
       
   868 
       
   869 /*!
       
   870    Stop all marquee animations and reset 
       
   871    animation state. 
       
   872 */
       
   873 void InfoWidget::stopMarquees()
       
   874 {  
       
   875     DPRINT;
       
   876     if (m_animationState != AnimationIdle && 
       
   877         m_animatingItems.count() > 0) {
       
   878         foreach (HbMarqueeItem *marqueeItem, m_animatingItems) {
       
   879             if (marqueeItem) {
       
   880                 QObject::disconnect(
       
   881                     marqueeItem, SIGNAL(animationStopped()),
       
   882                     this, SLOT(marqueeNext()));
       
   883                 
       
   884                 if (marqueeItem->isAnimating()) {
       
   885                     marqueeItem->stopAnimation();
       
   886                 }
       
   887             }
       
   888         }
       
   889     }
       
   890     
       
   891     // Stop timer 
       
   892     if (m_timerId) {
       
   893         killTimer(m_timerId); 
       
   894         m_timerId = 0; 
       
   895     }
       
   896     
       
   897     m_animationState = AnimationIdle;
       
   898     m_animatingItems.clear();
       
   899     m_animatingItem = NULL; 
       
   900 }
       
   901 
       
   902 /*!
       
   903    Starts marquee animation for 
       
   904    next item in sequence. Called if there are 
       
   905    multiple text items needing marquee and animation 
       
   906    start/stop logic is needed.    
       
   907 */
       
   908 void InfoWidget::marqueeNext()
       
   909 {  
       
   910     DPRINT;
       
   911     if (m_animationState == AnimationOngoing) {
       
   912         QListIterator<HbMarqueeItem *> i(m_animatingItems);
       
   913         if (i.findNext(m_animatingItem)) {
       
   914             if (i.hasNext()) {
       
   915                 m_animatingItem = i.peekNext();
       
   916             } else {
       
   917                 // Was last item, loop back to first item
       
   918                 i.toFront();
       
   919                 m_animatingItem = i.peekNext();  
       
   920             }
       
   921         } else {
       
   922             DWARNING << ": animating item not found from list"; 
       
   923             m_animatingItem = NULL; 
       
   924         }
       
   925           
       
   926         if (m_animatingItem) {
       
   927             if (!m_animatingItem->isAnimating()) {
       
   928                 m_animatingItem->setLoopCount(1); 
       
   929                 m_animatingItem->startAnimation();
       
   930             }
       
   931         }
       
   932     }
       
   933 }
       
   934 
       
   935 // End of File. 
       
   936