radiohswidget/inc/radiohswidget.h
changeset 32 189d20c34778
child 33 11b6825f0862
equal deleted inserted replaced
28:075425b8d9a4 32:189d20c34778
       
     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:  FM Radio home screen widget
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef RADIOHSWIDGET_H
       
    19 #define RADIOHSWIDGET_H
       
    20 
       
    21 // System includes
       
    22 #include <HbWidget>
       
    23 
       
    24 // Forward declarations
       
    25 class HbLabel;
       
    26 class HbPushButton;
       
    27 class HbMarqueeItem;
       
    28 class XQSettingsManager;
       
    29 class XQSettingsKey;
       
    30 class RadioHsWidgetProfileReader;
       
    31 class RadioHsWidgetRadioServiceClient;
       
    32 class QGraphicsLinearLayout;
       
    33 
       
    34 /*!
       
    35     \namespace FmRadio
       
    36     \brief Wraps enumerators for radio state and service request visibility. 
       
    37  */
       
    38 namespace FmRadio
       
    39 {
       
    40     /*! Enum for radio application states. */
       
    41     enum State
       
    42     {
       
    43         StateUndefined,
       
    44         StateNotRunning,
       
    45         StateStarting,
       
    46         StateRunning,
       
    47         //StateControllingAudio, // TODO: Remove, this is not needed anymore.
       
    48         //StateNotControllingAudio,// TODO: Remove, this is not needed anymore.
       
    49         StateSeeking,
       
    50         StateAntennaNotConnected,
       
    51         StateClosing
       
    52     };
       
    53     
       
    54     /*! Enum for controlling the visibility of the radio application. */
       
    55     enum VisibiltyAfterRequest
       
    56     {
       
    57         VisibiltyDoNotChange,
       
    58         VisibiltyToForeground,
       
    59         VisibiltyToBackground
       
    60     };
       
    61 
       
    62 }
       
    63 
       
    64 class RadioHsWidget : public HbWidget
       
    65 {
       
    66     Q_OBJECT
       
    67     
       
    68 public:
       
    69     RadioHsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags flags = 0);
       
    70     ~RadioHsWidget();
       
    71     
       
    72     void handleRadioInformationChange(const int informationType,
       
    73         const QVariant &information);
       
    74     void handleRadioStateChange(const QVariant &value);
       
    75 
       
    76 private:
       
    77     /*! Enum for information area layout states. */
       
    78     enum InformationAreaLayout
       
    79     {
       
    80         OneRow,
       
    81         TwoRows,
       
    82         Animation
       
    83     };
       
    84 
       
    85     /*! Enum for control button identifier. */
       
    86     enum ControlButtonIdentifier{
       
    87         Power,
       
    88         Previous,
       
    89         Next
       
    90     };
       
    91     
       
    92     /*! Enum for control button state. */
       
    93     enum ControlButtonState{
       
    94         Normal,
       
    95         Pressed,
       
    96         Disabled,
       
    97         Latched
       
    98     };
       
    99 
       
   100 
       
   101     /*! Enum for information types published by radio. */
       
   102     enum FmRadioInformationType {
       
   103         Frequency,
       
   104         StationName,
       
   105         RadioText,
       
   106         DynamicPsName,
       
   107         Pty
       
   108     };
       
   109     
       
   110 signals:
       
   111 
       
   112     /*
       
   113        This signal allows your widget to save its properties persistently.
       
   114        Once properties are saved, the user may close and reopen the widget,
       
   115        and the stored properties will still be available. The names
       
   116        parameter contains names for the properties you want to store. The
       
   117        home screen framework reads the corresponding property values from
       
   118        the widget by calling QObject::property() method. Currently only
       
   119        QString type properties are supported. The home screen framework
       
   120        writes widget's properties just before calling the onInitialize slot.
       
   121        Both compile-time and dynamic properties are supported. Optional.
       
   122      */
       
   123     //void setPreferences(const QStringList &names);
       
   124 
       
   125     /*
       
   126        Your widget can notify the home screen framework about its completion
       
   127        by emitting this signal. With the current implementation, the
       
   128        framework removes the widget after receiving this signal. Optional.
       
   129      */
       
   130     //void finished();
       
   131 
       
   132     /*!
       
   133        Widget can notify the home screen framework about errors in its
       
   134        execution by emitting this signal. With the current implementation,
       
   135        the framework removes the widget after receiving this signal.
       
   136        Optional.
       
   137      */
       
   138     void error();
       
   139 
       
   140 public slots:
       
   141     /* These slots (prefixed with "on") are called by the home screen
       
   142      * framework for controlling the widget's state during its lifetime.
       
   143      * They are automatically connected by the framework.
       
   144      */
       
   145 
       
   146     /* Implement this slot if you want to be notified when your widget is
       
   147      * added to the home screen. Upon receiving this event, your widget can
       
   148      * perform any necessary initialization operations, such as preparing
       
   149      * connections and allocating resources. Optional.
       
   150      */
       
   151     void onInitialize();
       
   152     
       
   153     /* This slot is called when your widget is shown in the home screen. You
       
   154      * use this slot to activate your widget and begin processing data again
       
   155      * after being quiescent. Each home screen compatible widget must define
       
   156      * this slot. Mandatory.
       
   157      */
       
   158     void onShow();
       
   159     
       
   160     /* This slot is called when your widget is hidden from the home screen.
       
   161      * You use this function to deactivate your widget and put it into a
       
   162      * quiescent state. Each home screen compatible widget must define this
       
   163      * slot. Mandatory.
       
   164      */
       
   165     void onHide();
       
   166     
       
   167     /* Implement this slot if you want to be notified when your widget is
       
   168      * removed from the home screen. Upon receiving this event, your widget
       
   169      * should perform any necessary cleanup operations, such as remove cache
       
   170      * files, and release any resources it currently holds. Optional.
       
   171      */
       
   172     //void onUninitialize(); 
       
   173     
       
   174     
       
   175     void changeButtonToPressed(int controlButtonId);
       
   176     void changeButtonToReleased(int controlButtonId);
       
   177 
       
   178 private slots:
       
   179     void closeRadio();
       
   180     void changeToPreviousStation();
       
   181     void changeToNextStation();
       
   182     void changeRadioToForeground();
       
   183     void changeRadioToBackground();
       
   184     void toggleRadioPower();
       
   185 
       
   186 private:
       
   187     void load(const QString &docml);
       
   188     
       
   189     void handleSimilarRadioInformation(
       
   190         const FmRadioInformationType informationType,
       
   191         const QVariant &information);
       
   192     bool updateRadioInformation(const FmRadioInformationType informationType,
       
   193         const QString &information);
       
   194     void changeInRadioInformation();
       
   195     void clearRadioInformation();
       
   196     
       
   197     void changeInformationAreaLayout(const InformationAreaLayout layout);
       
   198     void changePowerButtonOn(const bool isPowerOn);
       
   199     void enableStationButtons();
       
   200     void defineButton(HbPushButton &target, const QString &graphicsId,
       
   201         const QStringList &suffix, const QString &icon,
       
   202         const QString &iconColor);
       
   203     void buttonEvent(ControlButtonIdentifier buttonId,
       
   204         const ControlButtonState state);
       
   205     void changeButtonToDisabled(int controlButtonId);
       
   206     void changeButtonToEnabled(int controlButtonId);
       
   207     
       
   208     bool radioStartPermission();
       
   209 
       
   210 private:
       
   211     // Data
       
   212     Q_DISABLE_COPY(RadioHsWidget)
       
   213     
       
   214     // UI components.
       
   215     /*! Button for capturing taps on information area. */
       
   216     HbPushButton *mInformationAreaBackgroundButton;
       
   217     /*! Control button for power. */
       
   218     HbPushButton *mPowerButton;
       
   219     /*! Control button for previous station. */
       
   220     HbPushButton *mPreviousButton;
       
   221     /*! Control button for next station. */
       
   222     HbPushButton *mNextButton;
       
   223     /*! Layout for information area. */
       
   224     QGraphicsWidget *mInformationAreaTwoRowsLayout;
       
   225     /*! Label that is shown when there is only one row of information. */
       
   226     HbLabel *mInformationLonelyRowLabel;
       
   227     /*! Label for first row when there is two rows of information. */
       
   228     HbLabel *mInformationFirstRowLabel;
       
   229     // TODO: This label should be modified to support marquee scrolling when Orbit supports it.
       
   230     /*! Label for first second when there is two rows of information. */
       
   231     HbLabel *mInformationSecondRowLabel;
       
   232     /*! Label for displaying animation. */
       
   233     HbLabel *mAnimationIcon;
       
   234     
       
   235     /*! Stores the state of the FM Radio application. */
       
   236     FmRadio::State mFmRadioState;
       
   237 
       
   238     /*! Stores the count of favorite stations. */
       
   239     int mFavoriteStationCount;
       
   240     /*! Stores the value whether the current station is favorite or not. */
       
   241     bool mCurrentStationIsFavorite;
       
   242 
       
   243     /*! Stores the radio information. */
       
   244     QHash<FmRadioInformationType, QString> mRadioInformation;
       
   245     /*! 
       
   246        String is used to format the text shown on first or only row from
       
   247        radio information.
       
   248      */
       
   249     QString mRadioInformationFirstRow;
       
   250     /*! 
       
   251        String is used to format the text shown on second row from
       
   252        radio information.
       
   253      */
       
   254     QString mRadioInformationSecondRow;
       
   255 
       
   256     /*! Profile monitor is used to read P&S keys and profile information. */
       
   257     RadioHsWidgetProfileReader *mProfileMonitor;
       
   258     
       
   259     /*! For communicating with the FM Radio through Qt Highway. */
       
   260     RadioHsWidgetRadioServiceClient *mRadioServiceClient;
       
   261     
       
   262 };
       
   263 
       
   264 #endif // RADIOHSWIDGET_H