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