radiohswidget/src/radiohswidget.cpp
author hgs
Fri, 23 Jul 2010 10:16:59 +0300
changeset 38 f8c3d4e6102c
parent 36 ba22309243a1
child 44 0a3ad94fc71c
permissions -rw-r--r--
201029
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
// System includes
hgs
parents:
diff changeset
    19
#include <HbPushButton>
hgs
parents:
diff changeset
    20
#include <HbLabel>
hgs
parents:
diff changeset
    21
#include <HbDocumentLoader>
hgs
parents:
diff changeset
    22
#include <HbFrameDrawer>
hgs
parents:
diff changeset
    23
#include <HbIcon>
hgs
parents:
diff changeset
    24
#include <HbIconAnimationManager>
hgs
parents:
diff changeset
    25
#include <HbIconAnimationDefinition>
hgs
parents:
diff changeset
    26
#include <HbColorScheme>
hgs
parents:
diff changeset
    27
#include <HbDeviceMessageBox>
hgs
parents:
diff changeset
    28
#include <QGraphicsLinearLayout>
hgs
parents:
diff changeset
    29
#include <QGraphicsItem>
hgs
parents:
diff changeset
    30
#include <QDesktopServices>
hgs
parents:
diff changeset
    31
#include <QSignalMapper>
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
// User includes
hgs
parents:
diff changeset
    34
#include "radiohswidget.h"
hgs
parents:
diff changeset
    35
#include "radiohswidgetprofilereader.h"
hgs
parents:
diff changeset
    36
#include "radiohswidgetradioserviceclient.h"
hgs
parents:
diff changeset
    37
#include "radioservicedef.h"
hgs
parents:
diff changeset
    38
#include "radio_global.h"
hgs
parents:
diff changeset
    39
#include "radiologger.h"
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
// Constants
hgs
parents:
diff changeset
    42
/** Path to docml file */
hgs
parents:
diff changeset
    43
const QString DOCML(":/ui/resource/fmradiohswidget.docml");
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
/**  DOCML object name for mainLayout */
hgs
parents:
diff changeset
    46
const QString DOCML_OBJECT_NAME_MAIN_LAYOUT("mainLayout");
hgs
parents:
diff changeset
    47
/**  DOCML object name for contentLayout */
hgs
parents:
diff changeset
    48
const QString DOCML_OBJECT_NAME_CONTENT_LAYOUT("contentLayout");
hgs
parents:
diff changeset
    49
/**  DOCML object name for tunerBackgroundPushButton */
hgs
parents:
diff changeset
    50
const QString DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON(
hgs
parents:
diff changeset
    51
    "tunerBackgroundPushButton");
hgs
parents:
diff changeset
    52
/**  DOCML object name for tunerStackedLayout */
hgs
parents:
diff changeset
    53
const QString DOCML_OBJECT_NAME_TUNER_STACKED_LAYOUT("tunerStackedLayout");
hgs
parents:
diff changeset
    54
/**  DOCML object name for tunerInformationStackedLayout */
hgs
parents:
diff changeset
    55
const QString DOCML_OBJECT_NAME_TUNER_INFORMATION_STACKED_LAYOUT(
hgs
parents:
diff changeset
    56
    "tunerInformationStackedLayout");
hgs
parents:
diff changeset
    57
/**  DOCML object name for controlButtons */
hgs
parents:
diff changeset
    58
const QString DOCML_OBJECT_NAME_CONTROL_BUTTONS_LAYOUT("controlButtons");
hgs
parents:
diff changeset
    59
/**  DOCML object name for powerToggleButton */
hgs
parents:
diff changeset
    60
const QString DOCML_OBJECT_NAME_POWER_BUTTON("powerButton");
hgs
parents:
diff changeset
    61
/**  DOCML object name for previousPushButton */
hgs
parents:
diff changeset
    62
const QString DOCML_OBJECT_NAME_PREVIOUS_BUTTON("previousPushButton");
hgs
parents:
diff changeset
    63
/**  DOCML object name for nextPushButton */
hgs
parents:
diff changeset
    64
const QString DOCML_OBJECT_NAME_NEXT_BUTTON("nextPushButton");
hgs
parents:
diff changeset
    65
/**  DOCML object name for twoRowsLayout */
hgs
parents:
diff changeset
    66
const QString DOCML_OBJECT_NAME_TWO_ROWS_LAYOUT("twoRowsLayout");
hgs
parents:
diff changeset
    67
/**  DOCML object name for firstRowLabel */
hgs
parents:
diff changeset
    68
const QString DOCML_OBJECT_NAME_FIRST_ROW_LABEL("firstRowLabel");
hgs
parents:
diff changeset
    69
/**  DOCML object name for secondRowLabel */
hgs
parents:
diff changeset
    70
const QString DOCML_OBJECT_NAME_SECOND_ROW_LABEL("secondRowLabel");
hgs
parents:
diff changeset
    71
/**  DOCML object name for lonelyRowLabel */
hgs
parents:
diff changeset
    72
const QString DOCML_OBJECT_NAME_LONELY_ROW_LABEL("lonelyRowLabel");
hgs
parents:
diff changeset
    73
/**  DOCML object name for animationIcon */
hgs
parents:
diff changeset
    74
const QString DOCML_OBJECT_NAME_ANIMATION_ICON("animationIcon");
hgs
parents:
diff changeset
    75
hgs
parents:
diff changeset
    76
/** Unknown favorite station count. */
hgs
parents:
diff changeset
    77
const int FAVORITE_STATION_COUNT_UNDEFINED(-1);
hgs
parents:
diff changeset
    78
/** One favorite station set. */
hgs
parents:
diff changeset
    79
const int FAVORITE_STATION_COUNT_ONE(1);
hgs
parents:
diff changeset
    80
/** Favorite station count lower boundary including this number. */
hgs
parents:
diff changeset
    81
const int FAVORITE_STATION_COUNT_LOWER_BOUNDARY(0);
hgs
parents:
diff changeset
    82
/** Favorite station count upper boundary including this number. */
hgs
parents:
diff changeset
    83
const int FAVORITE_STATION_COUNT_UPPER_BOUNDARY(100);
hgs
parents:
diff changeset
    84
hgs
parents:
diff changeset
    85
// Graphics identifiers for different push button states
hgs
parents:
diff changeset
    86
const QString CONTROL_BUTTON_GRAPHICS_NORMAL  ("qtg_fr_hsbutton_normal");
hgs
parents:
diff changeset
    87
const QString CONTROL_BUTTON_GRAPHICS_PRESSED ("qtg_fr_hsbutton_pressed");
hgs
parents:
diff changeset
    88
const QString CONTROL_BUTTON_GRAPHICS_DISABLED("qtg_fr_hsbutton_disabled");
hgs
parents:
diff changeset
    89
const QString CONTROL_BUTTON_GRAPHICS_LATCHED ("qtg_fr_hsbutton_latched");
hgs
parents:
diff changeset
    90
hgs
parents:
diff changeset
    91
// Push button icon colors for each of the states (normal, pressed, disabled
hgs
parents:
diff changeset
    92
// and latched)
hgs
parents:
diff changeset
    93
const QString CONTROL_BUTTON_ICON_COLOR_NORMAL  ("qtc_button_normal");
hgs
parents:
diff changeset
    94
const QString CONTROL_BUTTON_ICON_COLOR_PRESSED ("qtc_button_pressed");
hgs
parents:
diff changeset
    95
const QString CONTROL_BUTTON_ICON_COLOR_DISABLED("qtc_button_disabled");
hgs
parents:
diff changeset
    96
const QString CONTROL_BUTTON_ICON_COLOR_LATCHED ("qtc_button_latched");
hgs
parents:
diff changeset
    97
hgs
parents:
diff changeset
    98
// File name suffix lists for push buttons
hgs
parents:
diff changeset
    99
const QStringList POWER_BUTTON_SUFFIX(
hgs
parents:
diff changeset
   100
    (QStringList() << "_l" << "_c" << "_cr"));
hgs
parents:
diff changeset
   101
const QStringList PREVIOUS_BUTTON_SUFFIX(
hgs
parents:
diff changeset
   102
    (QStringList() << "_cl" << "_c" << "_cr"));
hgs
parents:
diff changeset
   103
const QStringList NEXT_BUTTON_SUFFIX(
hgs
parents:
diff changeset
   104
    (QStringList() << "_cl" << "_c" << "_r"));
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
/** Icon for power button off. */
hgs
parents:
diff changeset
   107
const QString POWER_BUTTON_ICON_OFF("qtg_mono_power"); 
hgs
parents:
diff changeset
   108
/** Icon for power button on. */
hgs
parents:
diff changeset
   109
const QString POWER_BUTTON_ICON_ON ("qtg_mono_power"); 
hgs
parents:
diff changeset
   110
hgs
parents:
diff changeset
   111
// Tuner background button graphics for different states.
hgs
parents:
diff changeset
   112
const QString TUNER_BUTTON_NORMAL_OFF("qtg_fr_tuner");
hgs
parents:
diff changeset
   113
const QString TUNER_BUTTON_NORMAL_ON("qtg_fr_tuner");
hgs
parents:
diff changeset
   114
const QString TUNER_BUTTON_NORMAL_PRESSED("qtg_fr_hsitems2_pressed");
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
/*!
hgs
parents:
diff changeset
   117
    \class RadioHsWidget
hgs
parents:
diff changeset
   118
    \brief Implementation of FM Radio home screen widget.
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
    RadioHsWidget implements needed functions for the FM Radio home screen
hgs
parents:
diff changeset
   121
    widget.
hgs
parents:
diff changeset
   122
*/
hgs
parents:
diff changeset
   123
hgs
parents:
diff changeset
   124
// ======== MEMBER FUNCTIONS ========
hgs
parents:
diff changeset
   125
hgs
parents:
diff changeset
   126
/*!
hgs
parents:
diff changeset
   127
    Constructs a widget which is a child of \a parent, with widget flags set
hgs
parents:
diff changeset
   128
    to \a flags.
hgs
parents:
diff changeset
   129
    
hgs
parents:
diff changeset
   130
    Constructor should be empty and all the actual construction should be
hgs
parents:
diff changeset
   131
    done in onInitialize().
hgs
parents:
diff changeset
   132
 */
hgs
parents:
diff changeset
   133
RadioHsWidget::RadioHsWidget(QGraphicsItem* parent, Qt::WindowFlags flags)
hgs
parents:
diff changeset
   134
    : HbWidget(parent, flags),
hgs
parents:
diff changeset
   135
      mInformationAreaBackgroundButton(NULL),
hgs
parents:
diff changeset
   136
      mPowerButton(NULL),
hgs
parents:
diff changeset
   137
      mPreviousButton(NULL),
hgs
parents:
diff changeset
   138
      mNextButton(NULL),
hgs
parents:
diff changeset
   139
      mInformationAreaTwoRowsLayout(NULL),
hgs
parents:
diff changeset
   140
      mInformationLonelyRowLabel(NULL),
hgs
parents:
diff changeset
   141
      mInformationFirstRowLabel(NULL),
hgs
parents:
diff changeset
   142
      mInformationSecondRowLabel(NULL),
hgs
parents:
diff changeset
   143
      mAnimationIcon(NULL),
hgs
parents:
diff changeset
   144
      mFmRadioState(FmRadio::StateUndefined),
hgs
parents:
diff changeset
   145
      mFavoriteStationCount(FAVORITE_STATION_COUNT_UNDEFINED),
hgs
parents:
diff changeset
   146
      mCurrentStationIsFavorite(false),
hgs
parents:
diff changeset
   147
      mProfileMonitor(NULL),
hgs
parents:
diff changeset
   148
      mRadioServiceClient(NULL)
hgs
parents:
diff changeset
   149
{
hgs
parents:
diff changeset
   150
    LOG_METHOD;
hgs
parents:
diff changeset
   151
}
hgs
parents:
diff changeset
   152
hgs
parents:
diff changeset
   153
/*!
hgs
parents:
diff changeset
   154
    Destructor
hgs
parents:
diff changeset
   155
 */
hgs
parents:
diff changeset
   156
RadioHsWidget::~RadioHsWidget()
hgs
parents:
diff changeset
   157
{
hgs
parents:
diff changeset
   158
    LOG_METHOD;
hgs
parents:
diff changeset
   159
}
hgs
parents:
diff changeset
   160
hgs
parents:
diff changeset
   161
/*!
hgs
parents:
diff changeset
   162
    Handles changes in FM Radio information.
hgs
parents:
diff changeset
   163
hgs
parents:
diff changeset
   164
    \param informationType Type of changed information.
hgs
parents:
diff changeset
   165
    \param information Actual information.
hgs
parents:
diff changeset
   166
 */
hgs
parents:
diff changeset
   167
void RadioHsWidget::handleRadioInformationChange(const int informationType,
hgs
parents:
diff changeset
   168
    const QVariant &information)
hgs
parents:
diff changeset
   169
{
hgs
parents:
diff changeset
   170
    LOG_METHOD;
hgs
parents:
diff changeset
   171
    switch (informationType) {
hgs
parents:
diff changeset
   172
hgs
parents:
diff changeset
   173
    case RadioServiceNotification::FavoriteCount:
hgs
parents:
diff changeset
   174
        LOG("FavoriteCount");
hgs
parents:
diff changeset
   175
        if (information.canConvert(QVariant::Int) &&
hgs
parents:
diff changeset
   176
            information.toInt() >= FAVORITE_STATION_COUNT_LOWER_BOUNDARY &&
hgs
parents:
diff changeset
   177
            information.toInt() <= FAVORITE_STATION_COUNT_UPPER_BOUNDARY) {
hgs
parents:
diff changeset
   178
            mFavoriteStationCount = information.toInt();
hgs
parents:
diff changeset
   179
            // If there are favorite stations, enable the next/previous
hgs
parents:
diff changeset
   180
            // buttons.
hgs
parents:
diff changeset
   181
            LOG_FORMAT("mFavoriteStationCount: %d", mFavoriteStationCount);
hgs
parents:
diff changeset
   182
            // Enable or disable buttons only if favoriteCount differs
hgs
parents:
diff changeset
   183
            // from 1. CurrentIsFavorite case handles situation when there
hgs
parents:
diff changeset
   184
            // is only one favorite station.
hgs
parents:
diff changeset
   185
            if (mFavoriteStationCount != FAVORITE_STATION_COUNT_ONE) {
hgs
parents:
diff changeset
   186
                enableStationButtons();
hgs
parents:
diff changeset
   187
            }
hgs
parents:
diff changeset
   188
        } else {
hgs
parents:
diff changeset
   189
            mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
hgs
parents:
diff changeset
   190
        }
hgs
parents:
diff changeset
   191
        break;
hgs
parents:
diff changeset
   192
hgs
parents:
diff changeset
   193
    case RadioServiceNotification::CurrentIsFavorite:
hgs
parents:
diff changeset
   194
        LOG("CurrentIsFavorite");
hgs
parents:
diff changeset
   195
        if (information.canConvert(QVariant::Bool)) {
hgs
parents:
diff changeset
   196
            mCurrentStationIsFavorite = information.toBool();
hgs
parents:
diff changeset
   197
            LOG_FORMAT("currentIsFavorite: %d", mCurrentStationIsFavorite);
hgs
parents:
diff changeset
   198
            // If current station is favorite disable next/prev buttons.
hgs
parents:
diff changeset
   199
            // Radio sends this information only when there is only one
hgs
parents:
diff changeset
   200
            // favorite station set.
hgs
parents:
diff changeset
   201
            enableStationButtons();
hgs
parents:
diff changeset
   202
        }
hgs
parents:
diff changeset
   203
        break;
hgs
parents:
diff changeset
   204
hgs
parents:
diff changeset
   205
    case RadioServiceNotification::RadioStatus:
hgs
parents:
diff changeset
   206
        LOG("RadioStatus");
hgs
parents:
diff changeset
   207
        if (information.canConvert(QVariant::Int)) {
hgs
parents:
diff changeset
   208
            const int status = information.toInt();
hgs
parents:
diff changeset
   209
            switch (status) {
hgs
parents:
diff changeset
   210
            case RadioStatus::Playing:
hgs
parents:
diff changeset
   211
                LOG("Playing");
36
hgs
parents: 34
diff changeset
   212
                handleRadioStateChange(FmRadio::StateRunning);
34
hgs
parents:
diff changeset
   213
                break;
hgs
parents:
diff changeset
   214
            case RadioStatus::Muted:
hgs
parents:
diff changeset
   215
                LOG("Muted");
hgs
parents:
diff changeset
   216
                break;
hgs
parents:
diff changeset
   217
            case RadioStatus::Seeking:
hgs
parents:
diff changeset
   218
                LEVEL2(LOG("Seeking"));
hgs
parents:
diff changeset
   219
                handleRadioStateChange(FmRadio::StateSeeking);
hgs
parents:
diff changeset
   220
                break;
hgs
parents:
diff changeset
   221
            case RadioStatus::NoAntenna:
hgs
parents:
diff changeset
   222
                LEVEL2(LOG("NoAntenna"));
hgs
parents:
diff changeset
   223
                handleRadioStateChange(FmRadio::StateAntennaNotConnected);
hgs
parents:
diff changeset
   224
                break;
hgs
parents:
diff changeset
   225
            case RadioStatus::PoweringOff:
hgs
parents:
diff changeset
   226
                LEVEL2(LOG("PoweringOff"));
hgs
parents:
diff changeset
   227
                handleRadioStateChange(FmRadio::StateClosing);
hgs
parents:
diff changeset
   228
                break;
hgs
parents:
diff changeset
   229
            default:
hgs
parents:
diff changeset
   230
                LOG("default case at case RadioStatus");
hgs
parents:
diff changeset
   231
                break;
hgs
parents:
diff changeset
   232
            }
hgs
parents:
diff changeset
   233
        }
hgs
parents:
diff changeset
   234
        break;
hgs
parents:
diff changeset
   235
hgs
parents:
diff changeset
   236
    case RadioServiceNotification::Frequency:
hgs
parents:
diff changeset
   237
        LOG("Frequency");
hgs
parents:
diff changeset
   238
        // TODO: Should information.toString() be checked for too many characters? What's the limit?
hgs
parents:
diff changeset
   239
        if (information.canConvert(QVariant::String)) {
hgs
parents:
diff changeset
   240
            LOG_FORMAT("frequency: %s", GETSTRING(information.toString()));
hgs
parents:
diff changeset
   241
            // TODO: Remove comment when localisation is working on device.
hgs
parents:
diff changeset
   242
            //frequencyString = hbTrId("txt_fmradiohswidget_rad_list_l1_mhz").arg(freqString);
hgs
parents:
diff changeset
   243
            bool frequencyCleared = false;
36
hgs
parents: 34
diff changeset
   244
hgs
parents: 34
diff changeset
   245
            if (mRadioInformation.contains(Frequency)) {
hgs
parents: 34
diff changeset
   246
                // Clear all infromation.
34
hgs
parents:
diff changeset
   247
                clearRadioInformation();
hgs
parents:
diff changeset
   248
                frequencyCleared = true;
hgs
parents:
diff changeset
   249
            }
hgs
parents:
diff changeset
   250
            // If widget do not have any frquency information, update it.
hgs
parents:
diff changeset
   251
            bool frequencyUpdated = updateRadioInformation(Frequency,
hgs
parents:
diff changeset
   252
                information.toString());
hgs
parents:
diff changeset
   253
            if (frequencyCleared || frequencyUpdated) {
hgs
parents:
diff changeset
   254
                // Information changed, update the UI.
hgs
parents:
diff changeset
   255
                changeInRadioInformation();
36
hgs
parents: 34
diff changeset
   256
                mFmRadioState = FmRadio::StateRunning;
34
hgs
parents:
diff changeset
   257
            }
hgs
parents:
diff changeset
   258
        }
hgs
parents:
diff changeset
   259
        break;
hgs
parents:
diff changeset
   260
hgs
parents:
diff changeset
   261
    case RadioServiceNotification::Name:
hgs
parents:
diff changeset
   262
        LOG("Name");
hgs
parents:
diff changeset
   263
        handleSimilarRadioInformation(StationName, information);
hgs
parents:
diff changeset
   264
        break;
hgs
parents:
diff changeset
   265
hgs
parents:
diff changeset
   266
    case RadioServiceNotification::Genre:
hgs
parents:
diff changeset
   267
        LOG("Genre");
hgs
parents:
diff changeset
   268
        handleSimilarRadioInformation(Pty, information);
hgs
parents:
diff changeset
   269
        break;
hgs
parents:
diff changeset
   270
hgs
parents:
diff changeset
   271
    case RadioServiceNotification::RadioText:
hgs
parents:
diff changeset
   272
        LOG("RadioText");
hgs
parents:
diff changeset
   273
        handleSimilarRadioInformation(RadioText, information);
hgs
parents:
diff changeset
   274
        break;
hgs
parents:
diff changeset
   275
hgs
parents:
diff changeset
   276
    case RadioServiceNotification::DynamicPS:
hgs
parents:
diff changeset
   277
        LOG("DynamicPS");
hgs
parents:
diff changeset
   278
        handleSimilarRadioInformation(DynamicPsName, information);
hgs
parents:
diff changeset
   279
        break;
hgs
parents:
diff changeset
   280
hgs
parents:
diff changeset
   281
    default:
hgs
parents:
diff changeset
   282
        LOG("default case at notificationId");
hgs
parents:
diff changeset
   283
        break;
hgs
parents:
diff changeset
   284
    }
hgs
parents:
diff changeset
   285
}
hgs
parents:
diff changeset
   286
hgs
parents:
diff changeset
   287
/*!
hgs
parents:
diff changeset
   288
    Handles changes in FM Radio state.
hgs
parents:
diff changeset
   289
hgs
parents:
diff changeset
   290
    \param value New state of the radio application.
hgs
parents:
diff changeset
   291
*/
hgs
parents:
diff changeset
   292
void RadioHsWidget::handleRadioStateChange(const QVariant &value)
hgs
parents:
diff changeset
   293
{
hgs
parents:
diff changeset
   294
    LOG_METHOD;
hgs
parents:
diff changeset
   295
    int state;
hgs
parents:
diff changeset
   296
    if (value.canConvert(QVariant::Int)) {
hgs
parents:
diff changeset
   297
        state = value.toInt();
hgs
parents:
diff changeset
   298
    } else {
hgs
parents:
diff changeset
   299
        return;
hgs
parents:
diff changeset
   300
    }
hgs
parents:
diff changeset
   301
hgs
parents:
diff changeset
   302
    if (state == mFmRadioState) {
hgs
parents:
diff changeset
   303
        // State did not change, so return.
hgs
parents:
diff changeset
   304
        return;
hgs
parents:
diff changeset
   305
    }
hgs
parents:
diff changeset
   306
hgs
parents:
diff changeset
   307
    switch (state) {
hgs
parents:
diff changeset
   308
    case FmRadio::StateUndefined:
hgs
parents:
diff changeset
   309
        LOG("FmRadio::StateUndefined");
hgs
parents:
diff changeset
   310
        // Something went wrong. Widget should not be in this state after onInitialize().
hgs
parents:
diff changeset
   311
        mFmRadioState = FmRadio::StateUndefined;
hgs
parents:
diff changeset
   312
        break;
hgs
parents:
diff changeset
   313
    case FmRadio::StateNotRunning:
hgs
parents:
diff changeset
   314
        LOG("FmRadio::StateNotRunning");
hgs
parents:
diff changeset
   315
        mFmRadioState = FmRadio::StateNotRunning;
hgs
parents:
diff changeset
   316
        mRadioServiceClient->stopMonitoring();
hgs
parents:
diff changeset
   317
        changePowerButtonOn(false);
hgs
parents:
diff changeset
   318
        mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
hgs
parents:
diff changeset
   319
        mCurrentStationIsFavorite = false;
hgs
parents:
diff changeset
   320
        enableStationButtons();
hgs
parents:
diff changeset
   321
        clearRadioInformation();
hgs
parents:
diff changeset
   322
        mInformationFirstRowLabel->setPlainText("");
hgs
parents:
diff changeset
   323
        mInformationSecondRowLabel->setPlainText("");
hgs
parents:
diff changeset
   324
        mInformationLonelyRowLabel->setPlainText(hbTrId("txt_fmradiohswidget_rad_list_fm_radio"));
hgs
parents:
diff changeset
   325
        changeInformationAreaLayout(OneRow);
hgs
parents:
diff changeset
   326
        break;
hgs
parents:
diff changeset
   327
    case FmRadio::StateStarting:
hgs
parents:
diff changeset
   328
        LOG("FmRadio::StateStarting");
hgs
parents:
diff changeset
   329
        mFmRadioState = FmRadio::StateStarting;
hgs
parents:
diff changeset
   330
        changePowerButtonOn(true);
hgs
parents:
diff changeset
   331
        mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
hgs
parents:
diff changeset
   332
        mCurrentStationIsFavorite = false;
hgs
parents:
diff changeset
   333
        enableStationButtons();
hgs
parents:
diff changeset
   334
        changeInformationAreaLayout(Animation);
hgs
parents:
diff changeset
   335
        break;
hgs
parents:
diff changeset
   336
    case FmRadio::StateRunning:
hgs
parents:
diff changeset
   337
        LOG("FmRadio::StateRunning");
hgs
parents:
diff changeset
   338
        mFmRadioState = FmRadio::StateRunning;
hgs
parents:
diff changeset
   339
        // Stop timer if it is running because radio is now running.
hgs
parents:
diff changeset
   340
        mRadioServiceClient->startMonitoring(
hgs
parents:
diff changeset
   341
            FmRadio::VisibiltyDoNotChange);
36
hgs
parents: 34
diff changeset
   342
        changeInRadioInformation();
34
hgs
parents:
diff changeset
   343
        changePowerButtonOn(true);
hgs
parents:
diff changeset
   344
        enableStationButtons();
hgs
parents:
diff changeset
   345
        changeInformationAreaLayout(OneRow);
hgs
parents:
diff changeset
   346
        break;
hgs
parents:
diff changeset
   347
    case FmRadio::StateSeeking:
hgs
parents:
diff changeset
   348
        LOG("FmRadio::StateSeeking");
hgs
parents:
diff changeset
   349
        mFmRadioState = FmRadio::StateSeeking;
hgs
parents:
diff changeset
   350
        mCurrentStationIsFavorite = false;
hgs
parents:
diff changeset
   351
        enableStationButtons();
hgs
parents:
diff changeset
   352
        changeInformationAreaLayout(Animation);
hgs
parents:
diff changeset
   353
        break;
hgs
parents:
diff changeset
   354
    case FmRadio::StateAntennaNotConnected:
hgs
parents:
diff changeset
   355
        LOG("FmRadio::StateAntennaNotConnected");
hgs
parents:
diff changeset
   356
        mFmRadioState = FmRadio::StateAntennaNotConnected;
hgs
parents:
diff changeset
   357
        mCurrentStationIsFavorite = false;
hgs
parents:
diff changeset
   358
        enableStationButtons();
hgs
parents:
diff changeset
   359
        mInformationFirstRowLabel->setPlainText("");
hgs
parents:
diff changeset
   360
        mInformationSecondRowLabel->setPlainText("");
hgs
parents:
diff changeset
   361
        mInformationLonelyRowLabel->setPlainText(hbTrId(
hgs
parents:
diff changeset
   362
            "txt_fmradiohswidget_rad_info_connect_wired_headset"));
hgs
parents:
diff changeset
   363
        changeInformationAreaLayout(OneRow);
hgs
parents:
diff changeset
   364
        break;
hgs
parents:
diff changeset
   365
    case FmRadio::StateClosing:
hgs
parents:
diff changeset
   366
        LOG("FmRadio::StateClosing");
hgs
parents:
diff changeset
   367
        mFmRadioState = FmRadio::StateClosing;
hgs
parents:
diff changeset
   368
        changePowerButtonOn(false);
hgs
parents:
diff changeset
   369
        mFavoriteStationCount = FAVORITE_STATION_COUNT_UNDEFINED;
hgs
parents:
diff changeset
   370
        mCurrentStationIsFavorite = false;
hgs
parents:
diff changeset
   371
        enableStationButtons();
hgs
parents:
diff changeset
   372
        clearRadioInformation();
hgs
parents:
diff changeset
   373
        mInformationFirstRowLabel->setPlainText("");
hgs
parents:
diff changeset
   374
        mInformationSecondRowLabel->setPlainText("");
hgs
parents:
diff changeset
   375
        mInformationLonelyRowLabel->setPlainText(hbTrId(
hgs
parents:
diff changeset
   376
            "txt_fmradiohswidget_rad_list_fm_radio"));
hgs
parents:
diff changeset
   377
        changeInformationAreaLayout(OneRow);
hgs
parents:
diff changeset
   378
        break;
hgs
parents:
diff changeset
   379
    default:
hgs
parents:
diff changeset
   380
        LOG_FORMAT("default case at state. State: %d", state);
hgs
parents:
diff changeset
   381
        break;
hgs
parents:
diff changeset
   382
    }
hgs
parents:
diff changeset
   383
}
hgs
parents:
diff changeset
   384
hgs
parents:
diff changeset
   385
/*!
hgs
parents:
diff changeset
   386
    Called when widget is initialized. Constructs objects and connects them.
hgs
parents:
diff changeset
   387
*/
hgs
parents:
diff changeset
   388
void RadioHsWidget::onInitialize()
hgs
parents:
diff changeset
   389
{
hgs
parents:
diff changeset
   390
    LOG_METHOD_ENTER;
hgs
parents:
diff changeset
   391
    mProfileMonitor = new RadioHsWidgetProfileReader(this);
hgs
parents:
diff changeset
   392
    mRadioServiceClient = new RadioHsWidgetRadioServiceClient(this);
hgs
parents:
diff changeset
   393
    
hgs
parents:
diff changeset
   394
    load(DOCML);
hgs
parents:
diff changeset
   395
    
hgs
parents:
diff changeset
   396
    // Use signal mapper to indicate button identifiers to button event
hgs
parents:
diff changeset
   397
    // slots. 
hgs
parents:
diff changeset
   398
    QSignalMapper* signalMapperPressed = new QSignalMapper(this); 
hgs
parents:
diff changeset
   399
    signalMapperPressed->setMapping(mPowerButton, Power);
hgs
parents:
diff changeset
   400
    signalMapperPressed->setMapping(mPreviousButton, Previous);
hgs
parents:
diff changeset
   401
    signalMapperPressed->setMapping(mNextButton, Next);
hgs
parents:
diff changeset
   402
hgs
parents:
diff changeset
   403
    // Need to use different signal mapper for pressed and released events, 
hgs
parents:
diff changeset
   404
    // both have same mappings but they are mapped to different slots.
hgs
parents:
diff changeset
   405
    QSignalMapper* signalMapperReleased = new QSignalMapper(this);
hgs
parents:
diff changeset
   406
    signalMapperReleased->setMapping(mPowerButton, Power);
hgs
parents:
diff changeset
   407
    signalMapperReleased->setMapping(mPreviousButton, Previous);
hgs
parents:
diff changeset
   408
    signalMapperReleased->setMapping(mNextButton, Next);
hgs
parents:
diff changeset
   409
hgs
parents:
diff changeset
   410
    // Connect button events to signal maps.
hgs
parents:
diff changeset
   411
    Radio::connect(mPowerButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map()));
hgs
parents:
diff changeset
   412
    Radio::connect(mPowerButton, SIGNAL(released()), signalMapperReleased, SLOT (map()));
hgs
parents:
diff changeset
   413
    Radio::connect(mPreviousButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map()));
hgs
parents:
diff changeset
   414
    Radio::connect(mPreviousButton, SIGNAL(released()), signalMapperReleased, SLOT (map()));
hgs
parents:
diff changeset
   415
    Radio::connect(mNextButton, SIGNAL(pressed()), signalMapperPressed, SLOT (map()));
hgs
parents:
diff changeset
   416
    Radio::connect(mNextButton, SIGNAL(released()), signalMapperReleased, SLOT (map()));
hgs
parents:
diff changeset
   417
    
hgs
parents:
diff changeset
   418
    // Connect mapper signals to self implemented slots.
hgs
parents:
diff changeset
   419
    Radio::connect(signalMapperPressed, SIGNAL(mapped(int)), this, SLOT(changeButtonToPressed(int)));
hgs
parents:
diff changeset
   420
    Radio::connect(signalMapperReleased, SIGNAL(mapped(int)), this, SLOT(changeButtonToReleased(int)));
hgs
parents:
diff changeset
   421
    
hgs
parents:
diff changeset
   422
    mProfileMonitor->startMonitoringRadioRunningStatus();
hgs
parents:
diff changeset
   423
}
hgs
parents:
diff changeset
   424
hgs
parents:
diff changeset
   425
/*!
hgs
parents:
diff changeset
   426
    Called when widget is shown in the home screen
hgs
parents:
diff changeset
   427
*/
hgs
parents:
diff changeset
   428
void RadioHsWidget::onShow()
hgs
parents:
diff changeset
   429
{
hgs
parents:
diff changeset
   430
    LOG_METHOD_ENTER;
hgs
parents:
diff changeset
   431
}
hgs
parents:
diff changeset
   432
hgs
parents:
diff changeset
   433
/*!
hgs
parents:
diff changeset
   434
    Called when widget is hidden from the home screen
hgs
parents:
diff changeset
   435
*/
hgs
parents:
diff changeset
   436
void RadioHsWidget::onHide()
hgs
parents:
diff changeset
   437
{
hgs
parents:
diff changeset
   438
    LOG_METHOD_ENTER;
hgs
parents:
diff changeset
   439
}
hgs
parents:
diff changeset
   440
hgs
parents:
diff changeset
   441
/*!
hgs
parents:
diff changeset
   442
    Emited from HbPushButton:pressed() signal, changes the button layout to
hgs
parents:
diff changeset
   443
    pressed state.
hgs
parents:
diff changeset
   444
 
hgs
parents:
diff changeset
   445
    \param hsButtonIdentifier Identifies the button which was pressed.
hgs
parents:
diff changeset
   446
 */
hgs
parents:
diff changeset
   447
void RadioHsWidget::changeButtonToPressed(int hsButtonIdentifier)
hgs
parents:
diff changeset
   448
{
hgs
parents:
diff changeset
   449
    LEVEL2(LOG_METHOD);
hgs
parents:
diff changeset
   450
    buttonEvent(static_cast<ControlButtonIdentifier>(hsButtonIdentifier), Pressed);
hgs
parents:
diff changeset
   451
}
hgs
parents:
diff changeset
   452
hgs
parents:
diff changeset
   453
/*!
hgs
parents:
diff changeset
   454
    Emited from HbPushButton:released() signal, changes the button layout to
hgs
parents:
diff changeset
   455
    normal state.
hgs
parents:
diff changeset
   456
 
hgs
parents:
diff changeset
   457
    \param hsButtonIdentifier Identifies the button which was released.
hgs
parents:
diff changeset
   458
 */
hgs
parents:
diff changeset
   459
void RadioHsWidget::changeButtonToReleased(int hsButtonIdentifier)
hgs
parents:
diff changeset
   460
{
hgs
parents:
diff changeset
   461
    LEVEL2(LOG_METHOD);
hgs
parents:
diff changeset
   462
    buttonEvent(static_cast<ControlButtonIdentifier>(hsButtonIdentifier), Normal);
hgs
parents:
diff changeset
   463
}
hgs
parents:
diff changeset
   464
hgs
parents:
diff changeset
   465
/*!
hgs
parents:
diff changeset
   466
    Slot for closing FM Radio application from power button.
hgs
parents:
diff changeset
   467
 */
hgs
parents:
diff changeset
   468
void RadioHsWidget::closeRadio()
hgs
parents:
diff changeset
   469
{
hgs
parents:
diff changeset
   470
    LOG_SLOT_CALLER;
hgs
parents:
diff changeset
   471
    mRadioServiceClient->commandFmRadio(RadioServiceCommand::PowerOff);
hgs
parents:
diff changeset
   472
}
hgs
parents:
diff changeset
   473
hgs
parents:
diff changeset
   474
/*!
hgs
parents:
diff changeset
   475
    Slot for previous button clicked.
hgs
parents:
diff changeset
   476
 */
hgs
parents:
diff changeset
   477
void RadioHsWidget::changeToPreviousStation()
hgs
parents:
diff changeset
   478
{
hgs
parents:
diff changeset
   479
    LOG_SLOT_CALLER;
hgs
parents:
diff changeset
   480
    clearRadioInformation();
hgs
parents:
diff changeset
   481
    mRadioServiceClient->commandFmRadio(RadioServiceCommand::Previous);
hgs
parents:
diff changeset
   482
}
hgs
parents:
diff changeset
   483
hgs
parents:
diff changeset
   484
/*!
hgs
parents:
diff changeset
   485
    Slot for next button clicked.
hgs
parents:
diff changeset
   486
 */
hgs
parents:
diff changeset
   487
void RadioHsWidget::changeToNextStation()
hgs
parents:
diff changeset
   488
{
hgs
parents:
diff changeset
   489
    LOG_SLOT_CALLER;
hgs
parents:
diff changeset
   490
    clearRadioInformation();
hgs
parents:
diff changeset
   491
    mRadioServiceClient->commandFmRadio(RadioServiceCommand::Next);
hgs
parents:
diff changeset
   492
hgs
parents:
diff changeset
   493
}
hgs
parents:
diff changeset
   494
hgs
parents:
diff changeset
   495
/*!
hgs
parents:
diff changeset
   496
    Slot for bringing the radio application to foreground.
hgs
parents:
diff changeset
   497
 */
hgs
parents:
diff changeset
   498
void RadioHsWidget::changeRadioToForeground()
hgs
parents:
diff changeset
   499
{
hgs
parents:
diff changeset
   500
    LOG_SLOT_CALLER;
hgs
parents:
diff changeset
   501
    // If radio is not running start it to foreground by monitor request.
hgs
parents:
diff changeset
   502
    if (mFmRadioState == FmRadio::StateNotRunning) {
hgs
parents:
diff changeset
   503
        bool okToStartRadio = radioStartPermission();
hgs
parents:
diff changeset
   504
        if (okToStartRadio) {
hgs
parents:
diff changeset
   505
            handleRadioStateChange(FmRadio::StateStarting);
hgs
parents:
diff changeset
   506
            mRadioServiceClient->startMonitoring(
hgs
parents:
diff changeset
   507
                FmRadio::VisibiltyToForeground);
hgs
parents:
diff changeset
   508
        }
hgs
parents:
diff changeset
   509
    }
hgs
parents:
diff changeset
   510
    else {
hgs
parents:
diff changeset
   511
        if (mFmRadioState == FmRadio::StateClosing) {
hgs
parents:
diff changeset
   512
            // Radio is closing but user wants to power it up again.
hgs
parents:
diff changeset
   513
            mRadioServiceClient->commandFmRadio(RadioServiceCommand::PowerOn);
hgs
parents:
diff changeset
   514
            // Stop and start monitoring to get refresh.
hgs
parents:
diff changeset
   515
            mRadioServiceClient->stopMonitoring();
hgs
parents:
diff changeset
   516
            mRadioServiceClient->startMonitoring(
hgs
parents:
diff changeset
   517
                FmRadio::VisibiltyToBackground);
hgs
parents:
diff changeset
   518
            handleRadioStateChange(FmRadio::StateRunning);
hgs
parents:
diff changeset
   519
        }
hgs
parents:
diff changeset
   520
        // If radio is running, bring it to the foreground.
hgs
parents:
diff changeset
   521
        mRadioServiceClient->commandFmRadio(RadioServiceCommand::Foreground);
hgs
parents:
diff changeset
   522
    }
hgs
parents:
diff changeset
   523
}
hgs
parents:
diff changeset
   524
hgs
parents:
diff changeset
   525
/*!
hgs
parents:
diff changeset
   526
    Slot for putting the radio application to the background.
hgs
parents:
diff changeset
   527
 */
hgs
parents:
diff changeset
   528
void RadioHsWidget::changeRadioToBackground()
hgs
parents:
diff changeset
   529
{
hgs
parents:
diff changeset
   530
    LOG_SLOT_CALLER;
hgs
parents:
diff changeset
   531
    // If radio is not running start it to background by monitor request.
hgs
parents:
diff changeset
   532
    if (mFmRadioState == FmRadio::StateNotRunning) {
hgs
parents:
diff changeset
   533
        bool okToStartRadio = radioStartPermission();
hgs
parents:
diff changeset
   534
        if (okToStartRadio) {
hgs
parents:
diff changeset
   535
            handleRadioStateChange(FmRadio::StateStarting);
hgs
parents:
diff changeset
   536
            mRadioServiceClient->startMonitoring(
hgs
parents:
diff changeset
   537
                FmRadio::VisibiltyToBackground);
hgs
parents:
diff changeset
   538
        }
hgs
parents:
diff changeset
   539
    }
hgs
parents:
diff changeset
   540
    else if (mFmRadioState == FmRadio::StateStarting) {
hgs
parents:
diff changeset
   541
        // Do nothing if radio is starting.
hgs
parents:
diff changeset
   542
    }
hgs
parents:
diff changeset
   543
    else if (mFmRadioState == FmRadio::StateClosing) {
hgs
parents:
diff changeset
   544
        // Radio is closing but user wants to power it up again.
hgs
parents:
diff changeset
   545
        mRadioServiceClient->commandFmRadio(RadioServiceCommand::PowerOn);
hgs
parents:
diff changeset
   546
        // Stop and start monitoring to get refresh.
hgs
parents:
diff changeset
   547
        mRadioServiceClient->stopMonitoring();
hgs
parents:
diff changeset
   548
        mRadioServiceClient->startMonitoring(
hgs
parents:
diff changeset
   549
            FmRadio::VisibiltyToBackground);
hgs
parents:
diff changeset
   550
        handleRadioStateChange(FmRadio::StateRunning);
hgs
parents:
diff changeset
   551
    }
hgs
parents:
diff changeset
   552
    else {
hgs
parents:
diff changeset
   553
        // If radio is running, put it to the background.
hgs
parents:
diff changeset
   554
        // This is little bit useless because the radio is in background if
hgs
parents:
diff changeset
   555
        // user is able to click the widget.
hgs
parents:
diff changeset
   556
        mRadioServiceClient->commandFmRadio(RadioServiceCommand::Background);
hgs
parents:
diff changeset
   557
    }
hgs
parents:
diff changeset
   558
}
hgs
parents:
diff changeset
   559
hgs
parents:
diff changeset
   560
/*!
hgs
parents:
diff changeset
   561
    Powering off or on the radio.
hgs
parents:
diff changeset
   562
 */
hgs
parents:
diff changeset
   563
void RadioHsWidget::toggleRadioPower()
hgs
parents:
diff changeset
   564
{
hgs
parents:
diff changeset
   565
    LOG_SLOT_CALLER;
hgs
parents:
diff changeset
   566
    // If radio is not running start it to background by monitor request.
hgs
parents:
diff changeset
   567
    if (mFmRadioState == FmRadio::StateNotRunning || mFmRadioState == FmRadio::StateClosing) {
hgs
parents:
diff changeset
   568
        LEVEL2(LOG("Power on"));
hgs
parents:
diff changeset
   569
        // Start radio
hgs
parents:
diff changeset
   570
        changeRadioToBackground();
hgs
parents:
diff changeset
   571
    } else {
hgs
parents:
diff changeset
   572
        LEVEL2(LOG("Power off"));
hgs
parents:
diff changeset
   573
        // Close radio
hgs
parents:
diff changeset
   574
        closeRadio();
hgs
parents:
diff changeset
   575
    }
hgs
parents:
diff changeset
   576
}
hgs
parents:
diff changeset
   577
hgs
parents:
diff changeset
   578
/*!
hgs
parents:
diff changeset
   579
    Loads docml file.
hgs
parents:
diff changeset
   580
 
hgs
parents:
diff changeset
   581
    \param docml Docml filename to be loaded.
hgs
parents:
diff changeset
   582
 */
hgs
parents:
diff changeset
   583
void RadioHsWidget::load(const QString &docml)
hgs
parents:
diff changeset
   584
{
hgs
parents:
diff changeset
   585
    LOG_METHOD_ENTER;
hgs
parents:
diff changeset
   586
hgs
parents:
diff changeset
   587
    QScopedPointer<HbDocumentLoader> documentLoader(new HbDocumentLoader());
hgs
parents:
diff changeset
   588
    bool loaded = false;
hgs
parents:
diff changeset
   589
    documentLoader->load(docml, &loaded);
hgs
parents:
diff changeset
   590
    if (loaded) {
hgs
parents:
diff changeset
   591
        // Find mainLayout
hgs
parents:
diff changeset
   592
        HbWidget *mainLayout = qobject_cast<HbWidget*> (
hgs
parents:
diff changeset
   593
            documentLoader->findWidget(DOCML_OBJECT_NAME_MAIN_LAYOUT));
hgs
parents:
diff changeset
   594
hgs
parents:
diff changeset
   595
        if (mainLayout) {
hgs
parents:
diff changeset
   596
            QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(
hgs
parents:
diff changeset
   597
                Qt::Vertical, this);
hgs
parents:
diff changeset
   598
            widgetLayout->addItem(mainLayout);
hgs
parents:
diff changeset
   599
            setLayout(widgetLayout);
hgs
parents:
diff changeset
   600
        }
hgs
parents:
diff changeset
   601
hgs
parents:
diff changeset
   602
        // Find contentLayout
hgs
parents:
diff changeset
   603
        HbWidget *contentLayout = qobject_cast<HbWidget*> (
hgs
parents:
diff changeset
   604
            documentLoader->findWidget(DOCML_OBJECT_NAME_CONTENT_LAYOUT));
hgs
parents:
diff changeset
   605
        if (contentLayout) {
hgs
parents:
diff changeset
   606
hgs
parents:
diff changeset
   607
            // Find stacked layout for tuner area.
hgs
parents:
diff changeset
   608
            HbWidget *tunerStackedLayout = qobject_cast<HbWidget*> (
hgs
parents:
diff changeset
   609
                documentLoader->findWidget(
hgs
parents:
diff changeset
   610
                    DOCML_OBJECT_NAME_TUNER_STACKED_LAYOUT));
hgs
parents:
diff changeset
   611
            if (tunerStackedLayout) {
hgs
parents:
diff changeset
   612
hgs
parents:
diff changeset
   613
                // Find stacked layout for information area.
hgs
parents:
diff changeset
   614
                HbWidget *tunerInformationStackedLayout = qobject_cast<
hgs
parents:
diff changeset
   615
                    HbWidget*> (documentLoader->findWidget(
hgs
parents:
diff changeset
   616
                    DOCML_OBJECT_NAME_TUNER_INFORMATION_STACKED_LAYOUT));
hgs
parents:
diff changeset
   617
                if (tunerInformationStackedLayout) {
hgs
parents:
diff changeset
   618
                }
hgs
parents:
diff changeset
   619
hgs
parents:
diff changeset
   620
                // Find lonely label
hgs
parents:
diff changeset
   621
                mInformationLonelyRowLabel = qobject_cast<HbLabel *> (
hgs
parents:
diff changeset
   622
                    documentLoader->findWidget(
hgs
parents:
diff changeset
   623
                        DOCML_OBJECT_NAME_LONELY_ROW_LABEL));
hgs
parents:
diff changeset
   624
                if (mInformationLonelyRowLabel) {
hgs
parents:
diff changeset
   625
                    // TODO: Set the color in docml when application designer supports it.
hgs
parents:
diff changeset
   626
                    QColor color = HbColorScheme::color(
hgs
parents:
diff changeset
   627
                        "qtc_radio_tuner_normal");
hgs
parents:
diff changeset
   628
                    mInformationLonelyRowLabel->setTextColor(color);
hgs
parents:
diff changeset
   629
                }
hgs
parents:
diff changeset
   630
hgs
parents:
diff changeset
   631
                // Find layout for two rows
hgs
parents:
diff changeset
   632
                mInformationAreaTwoRowsLayout = qobject_cast<
hgs
parents:
diff changeset
   633
                    QGraphicsWidget *> (documentLoader->findObject(
hgs
parents:
diff changeset
   634
                    DOCML_OBJECT_NAME_TWO_ROWS_LAYOUT));
hgs
parents:
diff changeset
   635
                if (mInformationAreaTwoRowsLayout) {
hgs
parents:
diff changeset
   636
                    // Find first row
hgs
parents:
diff changeset
   637
                    mInformationFirstRowLabel = qobject_cast<HbLabel *> (
hgs
parents:
diff changeset
   638
                        documentLoader->findWidget(
hgs
parents:
diff changeset
   639
                            DOCML_OBJECT_NAME_FIRST_ROW_LABEL));
hgs
parents:
diff changeset
   640
                    if (mInformationFirstRowLabel) {
hgs
parents:
diff changeset
   641
                        // TODO: Set the color in docml when application designer supports it.
hgs
parents:
diff changeset
   642
                        QColor color = HbColorScheme::color(
hgs
parents:
diff changeset
   643
                            "qtc_radio_tuner_normal");
hgs
parents:
diff changeset
   644
                        mInformationFirstRowLabel->setTextColor(color);
hgs
parents:
diff changeset
   645
                    }
hgs
parents:
diff changeset
   646
hgs
parents:
diff changeset
   647
                    // Find second row
hgs
parents:
diff changeset
   648
                    mInformationSecondRowLabel = qobject_cast<HbLabel *> (
hgs
parents:
diff changeset
   649
                        documentLoader->findWidget(
hgs
parents:
diff changeset
   650
                            DOCML_OBJECT_NAME_SECOND_ROW_LABEL));
hgs
parents:
diff changeset
   651
                    if (mInformationSecondRowLabel) {
hgs
parents:
diff changeset
   652
                        // TODO: Set the color in docml when application designer supports it.
hgs
parents:
diff changeset
   653
                        QColor color = HbColorScheme::color(
hgs
parents:
diff changeset
   654
                            "qtc_radio_tuner_normal");
hgs
parents:
diff changeset
   655
                        mInformationSecondRowLabel->setTextColor(color);
hgs
parents:
diff changeset
   656
                    }
hgs
parents:
diff changeset
   657
                }
hgs
parents:
diff changeset
   658
hgs
parents:
diff changeset
   659
                mAnimationIcon = qobject_cast<HbLabel *> (
hgs
parents:
diff changeset
   660
                    documentLoader->findWidget(
hgs
parents:
diff changeset
   661
                        DOCML_OBJECT_NAME_ANIMATION_ICON));
hgs
parents:
diff changeset
   662
                if (mAnimationIcon) {
hgs
parents:
diff changeset
   663
                    // Use animation manager to access anim loading animation.
hgs
parents:
diff changeset
   664
                    HbIconAnimationManager *animationManager =
hgs
parents:
diff changeset
   665
                        HbIconAnimationManager::global();
hgs
parents:
diff changeset
   666
                    // TODO: Axml extension can be removed after wk24 release.
hgs
parents:
diff changeset
   667
                    animationManager->addDefinitionFile(QLatin1String(
hgs
parents:
diff changeset
   668
                        "qtg_anim_loading.axml"));
hgs
parents:
diff changeset
   669
                    mAnimationIcon->setIcon(HbIcon("qtg_anim_loading"));
hgs
parents:
diff changeset
   670
                }
hgs
parents:
diff changeset
   671
            }
hgs
parents:
diff changeset
   672
hgs
parents:
diff changeset
   673
            // Find push button for tuner area.
hgs
parents:
diff changeset
   674
            mInformationAreaBackgroundButton = qobject_cast<HbPushButton*> (
hgs
parents:
diff changeset
   675
                documentLoader->findWidget(
hgs
parents:
diff changeset
   676
                    DOCML_OBJECT_NAME_TUNER_BACKGROUND_BUTTON));
hgs
parents:
diff changeset
   677
            if (mInformationAreaBackgroundButton) {
hgs
parents:
diff changeset
   678
                // Use the frame background.
hgs
parents:
diff changeset
   679
                HbFrameDrawer *tunerBackgroundButtonFrameDrawer =
hgs
parents:
diff changeset
   680
                    new HbFrameDrawer("qtg_fr_tuner",
hgs
parents:
diff changeset
   681
                        HbFrameDrawer::ThreePiecesHorizontal);
hgs
parents:
diff changeset
   682
                tunerBackgroundButtonFrameDrawer->setFillWholeRect(true);
hgs
parents:
diff changeset
   683
                mInformationAreaBackgroundButton->setFrameBackground(
hgs
parents:
diff changeset
   684
                    tunerBackgroundButtonFrameDrawer);
hgs
parents:
diff changeset
   685
                // Connect the button's clicked signal. 
hgs
parents:
diff changeset
   686
                Radio::connect(mInformationAreaBackgroundButton,
hgs
parents:
diff changeset
   687
                    SIGNAL(clicked()), this, SLOT(changeRadioToForeground()));
hgs
parents:
diff changeset
   688
            }
hgs
parents:
diff changeset
   689
hgs
parents:
diff changeset
   690
            // Find layout for control buttons.
hgs
parents:
diff changeset
   691
            HbWidget *controlButtonsLayout = qobject_cast<HbWidget*> (
hgs
parents:
diff changeset
   692
                documentLoader->findWidget(
hgs
parents:
diff changeset
   693
                    DOCML_OBJECT_NAME_CONTROL_BUTTONS_LAYOUT));
hgs
parents:
diff changeset
   694
            if (controlButtonsLayout) {
hgs
parents:
diff changeset
   695
hgs
parents:
diff changeset
   696
                // Find power button.
hgs
parents:
diff changeset
   697
                mPowerButton
hgs
parents:
diff changeset
   698
                    = qobject_cast<HbPushButton *> (
hgs
parents:
diff changeset
   699
                        documentLoader->findWidget(
hgs
parents:
diff changeset
   700
                            DOCML_OBJECT_NAME_POWER_BUTTON));
hgs
parents:
diff changeset
   701
                if (mPowerButton) {
hgs
parents:
diff changeset
   702
                    defineButton(*mPowerButton,
hgs
parents:
diff changeset
   703
                        CONTROL_BUTTON_GRAPHICS_NORMAL, POWER_BUTTON_SUFFIX,
hgs
parents:
diff changeset
   704
                        POWER_BUTTON_ICON_ON,
hgs
parents:
diff changeset
   705
                        CONTROL_BUTTON_ICON_COLOR_NORMAL);
hgs
parents:
diff changeset
   706
                    // Connect the button's clicked signal.
hgs
parents:
diff changeset
   707
                    Radio::connect(mPowerButton, SIGNAL(clicked()), this,
hgs
parents:
diff changeset
   708
                        SLOT(toggleRadioPower()));
hgs
parents:
diff changeset
   709
                }
hgs
parents:
diff changeset
   710
hgs
parents:
diff changeset
   711
                // Find previous button.
hgs
parents:
diff changeset
   712
                mPreviousButton = qobject_cast<HbPushButton *> (
hgs
parents:
diff changeset
   713
                    documentLoader->findWidget(
hgs
parents:
diff changeset
   714
                        DOCML_OBJECT_NAME_PREVIOUS_BUTTON));
hgs
parents:
diff changeset
   715
                if (mPreviousButton) {
hgs
parents:
diff changeset
   716
                    defineButton(*mPreviousButton,
hgs
parents:
diff changeset
   717
                        CONTROL_BUTTON_GRAPHICS_DISABLED,
hgs
parents:
diff changeset
   718
                        PREVIOUS_BUTTON_SUFFIX, NULL,
hgs
parents:
diff changeset
   719
                        CONTROL_BUTTON_ICON_COLOR_DISABLED);
hgs
parents:
diff changeset
   720
                    // Connect the button's clicked signal.
hgs
parents:
diff changeset
   721
                    Radio::connect(mPreviousButton, SIGNAL(clicked()), this,
hgs
parents:
diff changeset
   722
                        SLOT(changeToPreviousStation()));
hgs
parents:
diff changeset
   723
                }
hgs
parents:
diff changeset
   724
hgs
parents:
diff changeset
   725
                // Find next button.
hgs
parents:
diff changeset
   726
                mNextButton
hgs
parents:
diff changeset
   727
                    = qobject_cast<HbPushButton *> (
hgs
parents:
diff changeset
   728
                        documentLoader->findWidget(
hgs
parents:
diff changeset
   729
                            DOCML_OBJECT_NAME_NEXT_BUTTON));
hgs
parents:
diff changeset
   730
                if (mNextButton) {
hgs
parents:
diff changeset
   731
                    defineButton(*mNextButton,
hgs
parents:
diff changeset
   732
                        CONTROL_BUTTON_GRAPHICS_DISABLED, NEXT_BUTTON_SUFFIX,
hgs
parents:
diff changeset
   733
                        NULL, CONTROL_BUTTON_ICON_COLOR_DISABLED);
hgs
parents:
diff changeset
   734
                    // Connect the button's clicked signal.
hgs
parents:
diff changeset
   735
                    Radio::connect(mNextButton, SIGNAL(clicked()), this,
hgs
parents:
diff changeset
   736
                        SLOT(changeToNextStation()));
hgs
parents:
diff changeset
   737
                }
hgs
parents:
diff changeset
   738
            }
hgs
parents:
diff changeset
   739
        }
hgs
parents:
diff changeset
   740
    }
hgs
parents:
diff changeset
   741
    else {
hgs
parents:
diff changeset
   742
        // Docml was not succesfully loaded. UI cannot be displayed.
hgs
parents:
diff changeset
   743
        // Emit error to home screen framework, which removes the widget. 
hgs
parents:
diff changeset
   744
        emit error();
hgs
parents:
diff changeset
   745
    }
hgs
parents:
diff changeset
   746
}
hgs
parents:
diff changeset
   747
hgs
parents:
diff changeset
   748
/*!
hgs
parents:
diff changeset
   749
    Groups handling of similar kind of radio information (textual) to one
hgs
parents:
diff changeset
   750
    function.
hgs
parents:
diff changeset
   751
hgs
parents:
diff changeset
   752
    \param informationType Type of changed information.
hgs
parents:
diff changeset
   753
    \param information Actual textual information.
hgs
parents:
diff changeset
   754
 */
hgs
parents:
diff changeset
   755
void RadioHsWidget::handleSimilarRadioInformation(
hgs
parents:
diff changeset
   756
    const FmRadioInformationType informationType, const QVariant &information)
hgs
parents:
diff changeset
   757
{
hgs
parents:
diff changeset
   758
    LOG_METHOD_ENTER;
hgs
parents:
diff changeset
   759
    // TODO: Should information.toString() be checked for too many characters? What's the limit?
hgs
parents:
diff changeset
   760
    if (information.canConvert(QVariant::String) && updateRadioInformation(
hgs
parents:
diff changeset
   761
        informationType, information.toString())) {
hgs
parents:
diff changeset
   762
        LOG_FORMAT("informationType: %d, information: %s", informationType, GETSTRING(information.toString()));
hgs
parents:
diff changeset
   763
        changeInRadioInformation();
hgs
parents:
diff changeset
   764
    }
hgs
parents:
diff changeset
   765
}
hgs
parents:
diff changeset
   766
hgs
parents:
diff changeset
   767
/*!
hgs
parents:
diff changeset
   768
    Check if the the radio information is changed. If it is changed, it is
hgs
parents:
diff changeset
   769
    also updated.
hgs
parents:
diff changeset
   770
hgs
parents:
diff changeset
   771
    \param informationType Type of the information.
hgs
parents:
diff changeset
   772
    \param information  Information text.
hgs
parents:
diff changeset
   773
hgs
parents:
diff changeset
   774
    \returns Returns \c true, if information is updated. Returns \c false otherwise.
hgs
parents:
diff changeset
   775
 */
hgs
parents:
diff changeset
   776
bool RadioHsWidget::updateRadioInformation(const FmRadioInformationType informationType,
hgs
parents:
diff changeset
   777
    const QString &information)
hgs
parents:
diff changeset
   778
{
hgs
parents:
diff changeset
   779
    LOG_METHOD_RET("%d");
hgs
parents:
diff changeset
   780
    // If hash contains this type of information.
hgs
parents:
diff changeset
   781
    if (mRadioInformation.contains(informationType)) {
hgs
parents:
diff changeset
   782
        // If new information is empty.
hgs
parents:
diff changeset
   783
        if (information.isEmpty()) {
hgs
parents:
diff changeset
   784
            // Remove old information from the hash.
hgs
parents:
diff changeset
   785
            LEVEL2(LOG_FORMAT("informationType: %s removed", GETSTRING(informationType)));
hgs
parents:
diff changeset
   786
            mRadioInformation.remove(informationType);
hgs
parents:
diff changeset
   787
            // Return true to indicate the change.
hgs
parents:
diff changeset
   788
            return true;
hgs
parents:
diff changeset
   789
        }
hgs
parents:
diff changeset
   790
        // If new information differs from the old one.
hgs
parents:
diff changeset
   791
        if (mRadioInformation[informationType].compare(information) != 0) {
hgs
parents:
diff changeset
   792
            // Update the information.
hgs
parents:
diff changeset
   793
            LEVEL2(LOG_FORMAT("informationType: %s = %s", GETSTRING(informationType), GETSTRING(information)));
hgs
parents:
diff changeset
   794
            mRadioInformation[informationType] = information;
hgs
parents:
diff changeset
   795
            // And return true to indicate the change.
hgs
parents:
diff changeset
   796
            return true;
hgs
parents:
diff changeset
   797
        }
hgs
parents:
diff changeset
   798
    } else { // Hash do not contain this type of information.
hgs
parents:
diff changeset
   799
        // If new information is not empty.
hgs
parents:
diff changeset
   800
        if (!information.isEmpty()) {
hgs
parents:
diff changeset
   801
            // Add it to the hash.
hgs
parents:
diff changeset
   802
            LEVEL2(LOG_FORMAT("informationType: %s = %s", GETSTRING(informationType), GETSTRING(information)));
hgs
parents:
diff changeset
   803
            mRadioInformation[informationType] = information;
hgs
parents:
diff changeset
   804
            // Return true to indicate the change.
hgs
parents:
diff changeset
   805
            return true;
hgs
parents:
diff changeset
   806
        }
hgs
parents:
diff changeset
   807
    }
hgs
parents:
diff changeset
   808
    // Return false to indicate that nothing changed.
hgs
parents:
diff changeset
   809
    return false;
hgs
parents:
diff changeset
   810
}
hgs
parents:
diff changeset
   811
hgs
parents:
diff changeset
   812
/*!
hgs
parents:
diff changeset
   813
    Formatting radio information texts after a change.
hgs
parents:
diff changeset
   814
 */
hgs
parents:
diff changeset
   815
void RadioHsWidget::changeInRadioInformation()
hgs
parents:
diff changeset
   816
{
hgs
parents:
diff changeset
   817
    LOG_METHOD_ENTER;
hgs
parents:
diff changeset
   818
    // Clear the rows.
hgs
parents:
diff changeset
   819
    mRadioInformationFirstRow.clear();
hgs
parents:
diff changeset
   820
    mRadioInformationSecondRow.clear();
hgs
parents:
diff changeset
   821
hgs
parents:
diff changeset
   822
    // First row contains station name.
hgs
parents:
diff changeset
   823
    if (mRadioInformation.contains(StationName)) {
hgs
parents:
diff changeset
   824
        mRadioInformationFirstRow.append(mRadioInformation.value(StationName));
hgs
parents:
diff changeset
   825
    }
hgs
parents:
diff changeset
   826
    else if (mRadioInformation.contains(Frequency)) {
hgs
parents:
diff changeset
   827
        // Or frequency.
hgs
parents:
diff changeset
   828
        mRadioInformationFirstRow.append(mRadioInformation.value(Frequency));
hgs
parents:
diff changeset
   829
    } LEVEL2(LOG_FORMAT("mRadioInformationFirstRow: %s", GETSTRING(mRadioInformationFirstRow)));
hgs
parents:
diff changeset
   830
hgs
parents:
diff changeset
   831
    // Second row of information contains radio text.
hgs
parents:
diff changeset
   832
    if (mRadioInformation.contains(RadioText)) {
hgs
parents:
diff changeset
   833
        mRadioInformationSecondRow.append(mRadioInformation.value(RadioText));
hgs
parents:
diff changeset
   834
    }
hgs
parents:
diff changeset
   835
    else if (mRadioInformation.contains(DynamicPsName)) {
hgs
parents:
diff changeset
   836
        // Or Dynamic PS name.
hgs
parents:
diff changeset
   837
        mRadioInformationSecondRow.append(mRadioInformation.value(DynamicPsName));
hgs
parents:
diff changeset
   838
    }
hgs
parents:
diff changeset
   839
    else if (mRadioInformation.contains(Pty)) {
hgs
parents:
diff changeset
   840
        // Or PTY.
hgs
parents:
diff changeset
   841
        mRadioInformationSecondRow.append(mRadioInformation.value(Pty));
hgs
parents:
diff changeset
   842
    }
hgs
parents:
diff changeset
   843
    LEVEL2(LOG_FORMAT("mRadioInformationSecondRow: %s", GETSTRING(mRadioInformationSecondRow)));
hgs
parents:
diff changeset
   844
    
hgs
parents:
diff changeset
   845
    // If second row is empty.
hgs
parents:
diff changeset
   846
    if (mRadioInformationSecondRow.isEmpty()) {
hgs
parents:
diff changeset
   847
        // Show only the lonely row.
hgs
parents:
diff changeset
   848
        mInformationLonelyRowLabel->setPlainText(mRadioInformationFirstRow);
hgs
parents:
diff changeset
   849
        changeInformationAreaLayout(OneRow);
hgs
parents:
diff changeset
   850
    }
hgs
parents:
diff changeset
   851
    else {
hgs
parents:
diff changeset
   852
        // Else display both rows.
hgs
parents:
diff changeset
   853
        mInformationFirstRowLabel->setPlainText(mRadioInformationFirstRow);
hgs
parents:
diff changeset
   854
        mInformationSecondRowLabel->setPlainText(mRadioInformationSecondRow);
hgs
parents:
diff changeset
   855
        changeInformationAreaLayout(TwoRows);
hgs
parents:
diff changeset
   856
    }
hgs
parents:
diff changeset
   857
}
hgs
parents:
diff changeset
   858
hgs
parents:
diff changeset
   859
/*!
hgs
parents:
diff changeset
   860
    Clears the radio station information. For example, when the station is
hgs
parents:
diff changeset
   861
    changed, old information should be cleared.
hgs
parents:
diff changeset
   862
 */
hgs
parents:
diff changeset
   863
void RadioHsWidget::clearRadioInformation()
hgs
parents:
diff changeset
   864
{
hgs
parents:
diff changeset
   865
    LOG_METHOD_ENTER;
hgs
parents:
diff changeset
   866
    mRadioInformation.clear();
hgs
parents:
diff changeset
   867
}
hgs
parents:
diff changeset
   868
hgs
parents:
diff changeset
   869
/*!
hgs
parents:
diff changeset
   870
    Changes visible widgets of information area stacked layout.
hgs
parents:
diff changeset
   871
hgs
parents:
diff changeset
   872
    \param layout The layout to switch visible.
hgs
parents:
diff changeset
   873
 */
hgs
parents:
diff changeset
   874
void RadioHsWidget::changeInformationAreaLayout(const InformationAreaLayout layout)
hgs
parents:
diff changeset
   875
{
hgs
parents:
diff changeset
   876
    LOG_METHOD_ENTER;
hgs
parents:
diff changeset
   877
    mInformationLonelyRowLabel->setVisible(layout == OneRow);
hgs
parents:
diff changeset
   878
    mInformationAreaTwoRowsLayout->setVisible(layout == TwoRows);
hgs
parents:
diff changeset
   879
    mAnimationIcon->setVisible(layout == Animation);
hgs
parents:
diff changeset
   880
}
hgs
parents:
diff changeset
   881
hgs
parents:
diff changeset
   882
/*!
hgs
parents:
diff changeset
   883
    Changes state of power button.
hgs
parents:
diff changeset
   884
    
hgs
parents:
diff changeset
   885
    \param isPowerOn \c true the power is on and \c false the power is off.
hgs
parents:
diff changeset
   886
 */
hgs
parents:
diff changeset
   887
void RadioHsWidget::changePowerButtonOn(const bool isPowerOn)
hgs
parents:
diff changeset
   888
{
hgs
parents:
diff changeset
   889
    LEVEL2(LOG_METHOD);
hgs
parents:
diff changeset
   890
    if (isPowerOn) {
hgs
parents:
diff changeset
   891
        LEVEL2(LOG("Power on"));
hgs
parents:
diff changeset
   892
        // TODO: Temporarily set the text to clarify the action it performs.
hgs
parents:
diff changeset
   893
        // Remove when graphics displays the difference.
hgs
parents:
diff changeset
   894
        mPowerButton->setText("Off");
hgs
parents:
diff changeset
   895
        buttonEvent(Power, Latched);
hgs
parents:
diff changeset
   896
    } else {
hgs
parents:
diff changeset
   897
        LEVEL2(LOG("Power off"));
hgs
parents:
diff changeset
   898
        // TODO: Temporarily set the text to clarify the action it performs.
hgs
parents:
diff changeset
   899
        // Remove when graphics displays the difference.
hgs
parents:
diff changeset
   900
        mPowerButton->setText("On");
hgs
parents:
diff changeset
   901
        buttonEvent(Power, Normal);
hgs
parents:
diff changeset
   902
    }
hgs
parents:
diff changeset
   903
}
hgs
parents:
diff changeset
   904
hgs
parents:
diff changeset
   905
/*!
hgs
parents:
diff changeset
   906
    Changes enabled state of station buttons.
hgs
parents:
diff changeset
   907
 */
hgs
parents:
diff changeset
   908
void RadioHsWidget::enableStationButtons()
hgs
parents:
diff changeset
   909
{
hgs
parents:
diff changeset
   910
    LEVEL2(LOG_METHOD_ENTER);
36
hgs
parents: 34
diff changeset
   911
    LOG_FORMAT("RadioHsWidget::enableStationButtons count: %d", mFavoriteStationCount);
hgs
parents: 34
diff changeset
   912
    if (mFmRadioState == FmRadio::StateAntennaNotConnected){
hgs
parents: 34
diff changeset
   913
        changeButtonToDisabled(Next);
hgs
parents: 34
diff changeset
   914
        changeButtonToDisabled(Previous);
hgs
parents: 34
diff changeset
   915
    }
hgs
parents: 34
diff changeset
   916
    else if ((mFavoriteStationCount > 1) || (mFavoriteStationCount == 1
34
hgs
parents:
diff changeset
   917
        && !mCurrentStationIsFavorite)) {
hgs
parents:
diff changeset
   918
        changeButtonToEnabled(Next);
hgs
parents:
diff changeset
   919
        changeButtonToEnabled(Previous);
hgs
parents:
diff changeset
   920
    }
hgs
parents:
diff changeset
   921
    else if ((mFavoriteStationCount == 1 && mCurrentStationIsFavorite)
hgs
parents:
diff changeset
   922
        || (mFavoriteStationCount < 1)) {
hgs
parents:
diff changeset
   923
        changeButtonToDisabled(Next);
hgs
parents:
diff changeset
   924
        changeButtonToDisabled(Previous);
hgs
parents:
diff changeset
   925
    }
hgs
parents:
diff changeset
   926
}
hgs
parents:
diff changeset
   927
hgs
parents:
diff changeset
   928
/*!
hgs
parents:
diff changeset
   929
    Makes homescreen specific push button based on parameters.
hgs
parents:
diff changeset
   930
 
hgs
parents:
diff changeset
   931
    \param target Target push button to modify. Must not be NULL.
hgs
parents:
diff changeset
   932
    \param graphicsId Defines the target button background graphics.
hgs
parents:
diff changeset
   933
    \param suffix Defines the suffix for the target button background graphics.
hgs
parents:
diff changeset
   934
    \param icon Defines the icon for the target button. 
hgs
parents:
diff changeset
   935
    \param iconColor Defines the icon color for the target button. 
hgs
parents:
diff changeset
   936
 */
hgs
parents:
diff changeset
   937
void RadioHsWidget::defineButton(HbPushButton &target, const QString &graphicsId,
hgs
parents:
diff changeset
   938
    const QStringList &suffix, const QString &icon, const QString &iconColor)
hgs
parents:
diff changeset
   939
{
hgs
parents:
diff changeset
   940
    LEVEL2(LOG_METHOD);
hgs
parents:
diff changeset
   941
    HbFrameDrawer* drawer = NULL;
hgs
parents:
diff changeset
   942
hgs
parents:
diff changeset
   943
    // First check if the drawer is already created for this push button
hgs
parents:
diff changeset
   944
    if (!target.frameBackground()) {
hgs
parents:
diff changeset
   945
        LEVEL2(LOG("Creating new frame background."));
hgs
parents:
diff changeset
   946
        // Nope, create one now
hgs
parents:
diff changeset
   947
        drawer = new HbFrameDrawer(graphicsId,
hgs
parents:
diff changeset
   948
            HbFrameDrawer::ThreePiecesHorizontal);
hgs
parents:
diff changeset
   949
        target.setFrameBackground(drawer);
hgs
parents:
diff changeset
   950
    }
hgs
parents:
diff changeset
   951
    else {
hgs
parents:
diff changeset
   952
        // Frame drawer already created, only need to update frame graphics
hgs
parents:
diff changeset
   953
        drawer = target.frameBackground();
hgs
parents:
diff changeset
   954
        drawer->setFrameGraphicsName(graphicsId);
hgs
parents:
diff changeset
   955
    }
hgs
parents:
diff changeset
   956
hgs
parents:
diff changeset
   957
    // Set file name suffix list, so that drawer can load correct 3-piece graphic files 
hgs
parents:
diff changeset
   958
    drawer->setFileNameSuffixList(suffix);
hgs
parents:
diff changeset
   959
    
hgs
parents:
diff changeset
   960
    // Set the icon, if it is not NULL
hgs
parents:
diff changeset
   961
    if (!icon.isNull()) {
hgs
parents:
diff changeset
   962
        target.setIcon(HbIcon(icon));
hgs
parents:
diff changeset
   963
    }
hgs
parents:
diff changeset
   964
hgs
parents:
diff changeset
   965
    // Update also the icon color
hgs
parents:
diff changeset
   966
    QColor color = HbColorScheme::color(iconColor);
hgs
parents:
diff changeset
   967
    target.icon().setColor(color);
hgs
parents:
diff changeset
   968
hgs
parents:
diff changeset
   969
    // Lastly, check if the buttton is disabled
hgs
parents:
diff changeset
   970
    if (iconColor == CONTROL_BUTTON_ICON_COLOR_DISABLED) {
hgs
parents:
diff changeset
   971
        target.setEnabled(false);
hgs
parents:
diff changeset
   972
    }
hgs
parents:
diff changeset
   973
    else {
hgs
parents:
diff changeset
   974
        target.setEnabled(true);
hgs
parents:
diff changeset
   975
    }
hgs
parents:
diff changeset
   976
}
hgs
parents:
diff changeset
   977
hgs
parents:
diff changeset
   978
/*!
hgs
parents:
diff changeset
   979
    Prepares the information needed for displaying the button correctly
hgs
parents:
diff changeset
   980
    reflecting its state.
hgs
parents:
diff changeset
   981
 
hgs
parents:
diff changeset
   982
    \param buttonId Identifies the button.
hgs
parents:
diff changeset
   983
    \param state Tells in what state the button is.
hgs
parents:
diff changeset
   984
 */
hgs
parents:
diff changeset
   985
void RadioHsWidget::buttonEvent(ControlButtonIdentifier buttonId,
hgs
parents:
diff changeset
   986
    const ControlButtonState state)
hgs
parents:
diff changeset
   987
{
hgs
parents:
diff changeset
   988
    LEVEL2(LOG_METHOD);
hgs
parents:
diff changeset
   989
    HbPushButton* target = NULL;
hgs
parents:
diff changeset
   990
    QStringList suffix;
hgs
parents:
diff changeset
   991
    QString icon;
hgs
parents:
diff changeset
   992
hgs
parents:
diff changeset
   993
    switch (buttonId) {
hgs
parents:
diff changeset
   994
    case Power:
hgs
parents:
diff changeset
   995
        LEVEL2(LOG("Power"));
hgs
parents:
diff changeset
   996
        target = mPowerButton;
hgs
parents:
diff changeset
   997
        icon = POWER_BUTTON_ICON_ON;
hgs
parents:
diff changeset
   998
        suffix = POWER_BUTTON_SUFFIX;
hgs
parents:
diff changeset
   999
        break;
hgs
parents:
diff changeset
  1000
    case Previous:
hgs
parents:
diff changeset
  1001
        LEVEL2(LOG("Previous"));
hgs
parents:
diff changeset
  1002
        target = mPreviousButton;
hgs
parents:
diff changeset
  1003
        suffix = PREVIOUS_BUTTON_SUFFIX;
hgs
parents:
diff changeset
  1004
        break;
hgs
parents:
diff changeset
  1005
    case Next:
hgs
parents:
diff changeset
  1006
        LEVEL2(LOG("Next"));
hgs
parents:
diff changeset
  1007
        target = mNextButton;
hgs
parents:
diff changeset
  1008
        suffix = NEXT_BUTTON_SUFFIX;
hgs
parents:
diff changeset
  1009
        break;
hgs
parents:
diff changeset
  1010
    default:
hgs
parents:
diff changeset
  1011
        LOG("default case at buttonId");
hgs
parents:
diff changeset
  1012
        break;
hgs
parents:
diff changeset
  1013
    }
hgs
parents:
diff changeset
  1014
    
hgs
parents:
diff changeset
  1015
    QString buttonBackgroundGraphics;
hgs
parents:
diff changeset
  1016
    QString buttonIconColors;
hgs
parents:
diff changeset
  1017
    switch (state) {
hgs
parents:
diff changeset
  1018
    case Normal:
hgs
parents:
diff changeset
  1019
        LEVEL2(LOG("Normal"));
hgs
parents:
diff changeset
  1020
        target->setProperty("state", "normal");
hgs
parents:
diff changeset
  1021
        buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_NORMAL;
hgs
parents:
diff changeset
  1022
        buttonIconColors = CONTROL_BUTTON_ICON_COLOR_NORMAL;
hgs
parents:
diff changeset
  1023
        break;
hgs
parents:
diff changeset
  1024
    case Pressed:
hgs
parents:
diff changeset
  1025
        LEVEL2(LOG("Pressed"));
hgs
parents:
diff changeset
  1026
        target->setProperty("state", "pressed");
hgs
parents:
diff changeset
  1027
        buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_PRESSED;
hgs
parents:
diff changeset
  1028
        buttonIconColors = CONTROL_BUTTON_ICON_COLOR_PRESSED;
hgs
parents:
diff changeset
  1029
        break;
hgs
parents:
diff changeset
  1030
    case Disabled:
hgs
parents:
diff changeset
  1031
        LEVEL2(LOG("Disabled"));
hgs
parents:
diff changeset
  1032
        target->setProperty("state", "disabled");
hgs
parents:
diff changeset
  1033
        buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_DISABLED;
hgs
parents:
diff changeset
  1034
        buttonIconColors = CONTROL_BUTTON_ICON_COLOR_DISABLED;
hgs
parents:
diff changeset
  1035
        break;
hgs
parents:
diff changeset
  1036
    case Latched:
hgs
parents:
diff changeset
  1037
        LEVEL2(LOG("Latched"));
hgs
parents:
diff changeset
  1038
        target->setProperty("state", "latched");
hgs
parents:
diff changeset
  1039
        buttonBackgroundGraphics = CONTROL_BUTTON_GRAPHICS_LATCHED;
hgs
parents:
diff changeset
  1040
        buttonIconColors = CONTROL_BUTTON_ICON_COLOR_LATCHED;
hgs
parents:
diff changeset
  1041
        break;
hgs
parents:
diff changeset
  1042
    default:
hgs
parents:
diff changeset
  1043
        LOG("default case at button state");
hgs
parents:
diff changeset
  1044
        break;
hgs
parents:
diff changeset
  1045
    }
hgs
parents:
diff changeset
  1046
hgs
parents:
diff changeset
  1047
    RadioHsWidget::defineButton(*target, buttonBackgroundGraphics,
hgs
parents:
diff changeset
  1048
        suffix, icon, buttonIconColors);
hgs
parents:
diff changeset
  1049
}
hgs
parents:
diff changeset
  1050
hgs
parents:
diff changeset
  1051
/*!
hgs
parents:
diff changeset
  1052
    Disables specified push button.
hgs
parents:
diff changeset
  1053
 
hgs
parents:
diff changeset
  1054
    \param hsButtonIdentifier Which button is to be disabled.
hgs
parents:
diff changeset
  1055
 */
hgs
parents:
diff changeset
  1056
void RadioHsWidget::changeButtonToDisabled(int hsButtonIdentifier)
hgs
parents:
diff changeset
  1057
{
hgs
parents:
diff changeset
  1058
    LEVEL2(LOG_METHOD_ENTER);
hgs
parents:
diff changeset
  1059
    buttonEvent(static_cast<ControlButtonIdentifier>(hsButtonIdentifier), Disabled);
hgs
parents:
diff changeset
  1060
}
hgs
parents:
diff changeset
  1061
hgs
parents:
diff changeset
  1062
/*!
hgs
parents:
diff changeset
  1063
    Enabled specified push button.
hgs
parents:
diff changeset
  1064
 
hgs
parents:
diff changeset
  1065
    \param hsButtonIdentifier Which button is to be enabled.
hgs
parents:
diff changeset
  1066
 */
hgs
parents:
diff changeset
  1067
void RadioHsWidget::changeButtonToEnabled(int hsButtonIdentifier)
hgs
parents:
diff changeset
  1068
{
hgs
parents:
diff changeset
  1069
    LEVEL2(LOG_METHOD_ENTER);
hgs
parents:
diff changeset
  1070
    changeButtonToReleased(hsButtonIdentifier);
hgs
parents:
diff changeset
  1071
}
hgs
parents:
diff changeset
  1072
hgs
parents:
diff changeset
  1073
/*!
hgs
parents:
diff changeset
  1074
    Checks the profile of the device. If profile is offline, user is asked a
hgs
parents:
diff changeset
  1075
    permission to start the radio in offline profile. Dialog is shown on
hgs
parents:
diff changeset
  1076
    behalf of the radio asking the permission.    
hgs
parents:
diff changeset
  1077
    
hgs
parents:
diff changeset
  1078
    \returns \c true if radio can be started, \c false if device is in
hgs
parents:
diff changeset
  1079
    offline profile and user didn't gave permission to start the radio.  
hgs
parents:
diff changeset
  1080
 */
hgs
parents:
diff changeset
  1081
bool RadioHsWidget::radioStartPermission()
hgs
parents:
diff changeset
  1082
{
hgs
parents:
diff changeset
  1083
    LOG_METHOD_ENTER;
hgs
parents:
diff changeset
  1084
    // This is true by default because we might not be in offline profile and
hgs
parents:
diff changeset
  1085
    // starting the radio is allowed in other profiles without asking a
hgs
parents:
diff changeset
  1086
    // permission.
hgs
parents:
diff changeset
  1087
    bool radioStartPermssion = true;
38
hgs
parents: 36
diff changeset
  1088
    if (mProfileMonitor->isInOfflineMode()) {
34
hgs
parents:
diff changeset
  1089
        // Device is in offline profile, ask the user for permission to start
hgs
parents:
diff changeset
  1090
        HbDeviceMessageBox box(hbTrId(
hgs
parents:
diff changeset
  1091
            "txt_fmradiohswidget_rad_info_activate_radio_in_offline_mode_hs"),
hgs
parents:
diff changeset
  1092
            HbMessageBox::MessageTypeQuestion);
hgs
parents:
diff changeset
  1093
        box.setTimeout(HbPopup::NoTimeout);
hgs
parents:
diff changeset
  1094
        box.exec();
hgs
parents:
diff changeset
  1095
        // radioStartPermssion is now true or false, depending what the user
hgs
parents:
diff changeset
  1096
        // selected. If user didn't gave permission, then radio is not
hgs
parents:
diff changeset
  1097
        // started.
hgs
parents:
diff changeset
  1098
        radioStartPermssion = box.isAcceptAction(box.triggeredAction());
hgs
parents:
diff changeset
  1099
    }
hgs
parents:
diff changeset
  1100
    return radioStartPermssion;
hgs
parents:
diff changeset
  1101
}