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