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