radioapp/radiowidgets/src/radiofrequencystrip.cpp
author hgs
Fri, 06 Aug 2010 09:29:48 +0300
changeset 39 ac7857bd5fdb
parent 38 f8c3d4e6102c
child 47 74b7c6e79031
permissions -rw-r--r--
201031
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
* All rights reserved.
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
* Initial Contributors:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
* Contributors:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
* Description:
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
*
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
*/
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
// System includes
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
39
hgs
parents: 38
diff changeset
    20
// User includes
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    21
#include "radiofrequencystrip.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
#include "radiouiengine.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
#include "radiostation.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
#include "radiostationmodel.h"
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    25
#include "radioutil.h"
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    26
#include "radiouiloader.h"
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
#include "radiologger.h"
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
RadioFrequencyStrip::RadioFrequencyStrip() :
39
hgs
parents: 38
diff changeset
    30
    RadioFrequencyStripBase(),
hgs
parents: 38
diff changeset
    31
    mUiEngine( NULL )
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
{
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    33
    RadioUtil::setFrequencyStrip( this );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    37
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
 */
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    39
void RadioFrequencyStrip::init( RadioUiEngine* engine, RadioUiLoader& uiLoader )
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
{
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
    mUiEngine = engine;
39
hgs
parents: 38
diff changeset
    42
    initbase( mUiEngine->minFrequency(), mUiEngine->maxFrequency(),
hgs
parents: 38
diff changeset
    43
              mUiEngine->frequencyStepSize(), RadioUiEngine::lastTunedFrequency() );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
39
hgs
parents: 38
diff changeset
    45
    createButtonsFromDocml( uiLoader, DOCML::MV_NAME_PREV_BUTTON, DOCML::MV_NAME_NEXT_BUTTON );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
    RadioStationModel* stationModel = &mUiEngine->stationModel();
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    48
    Radio::connect( stationModel,   SIGNAL(rowsInserted(QModelIndex,int,int)),
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
                    this,           SLOT(updateStation(QModelIndex,int,int)) );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    50
    Radio::connect( stationModel,   SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    51
                    this,           SLOT(removeStation(QModelIndex,int,int)) );
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    52
    Radio::connect( stationModel,   SIGNAL(modelReset()),
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    53
                    this,           SLOT(initEmptyItems()) );
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    54
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    55
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    56
/*!
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
 */
39
hgs
parents: 38
diff changeset
    59
void RadioFrequencyStrip::setFrequency( const uint newFrequency, int reason, Scroll::Direction direction )
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
{
39
hgs
parents: 38
diff changeset
    61
    Q_UNUSED( reason );
hgs
parents: 38
diff changeset
    62
    if ( newFrequency != frequency() || reason == TuneReason::Skip ) {
hgs
parents: 38
diff changeset
    63
        RadioFrequencyStripBase::setFrequency( newFrequency, reason, direction );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    64
    }
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    65
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    66
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    67
/*!
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    68
 * \reimp
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    69
 */
39
hgs
parents: 38
diff changeset
    70
bool RadioFrequencyStrip::isInitialized() const
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    71
{
39
hgs
parents: 38
diff changeset
    72
    return mUiEngine != NULL;
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    73
}
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    74
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
    75
/*!
39
hgs
parents: 38
diff changeset
    76
 * \reimp
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    77
 */
39
hgs
parents: 38
diff changeset
    78
QList<FrequencyStrip::StationMarker> RadioFrequencyStrip::stationsInRange( uint minFrequency, uint maxFrequency ) const
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    79
{
39
hgs
parents: 38
diff changeset
    80
    QList<RadioStation> stations = mUiEngine->stationsInRange( minFrequency, maxFrequency );
hgs
parents: 38
diff changeset
    81
    QList<FrequencyStrip::StationMarker> markers;
hgs
parents: 38
diff changeset
    82
    foreach ( const RadioStation& station, stations ) {
hgs
parents: 38
diff changeset
    83
        markers.append( FrequencyStrip::StationMarker( station.frequency(), station.isFavorite() ) );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
    }
39
hgs
parents: 38
diff changeset
    85
    return markers;
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    87
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    88
/*!
39
hgs
parents: 38
diff changeset
    89
 * \reimp
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    90
 */
39
hgs
parents: 38
diff changeset
    91
void RadioFrequencyStrip::emitFrequencyChanged( uint frequency, int reason, int direction )
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
{
39
hgs
parents: 38
diff changeset
    93
    int tuneReason = TuneReason::Unspecified;
hgs
parents: 38
diff changeset
    94
    if ( reason == FrequencyStrip::ManualSeekUpdate ) {
hgs
parents: 38
diff changeset
    95
        tuneReason = TuneReason::ManualSeekUpdate;
hgs
parents: 38
diff changeset
    96
    } else if ( reason == FrequencyStrip::ManualSeekTune ) {
hgs
parents: 38
diff changeset
    97
        tuneReason = TuneReason::ManualSeekTune;
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    98
    }
39
hgs
parents: 38
diff changeset
    99
hgs
parents: 38
diff changeset
   100
    emit frequencyChanged( frequency, tuneReason, direction );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   102
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   103
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
 */
39
hgs
parents: 38
diff changeset
   106
void RadioFrequencyStrip::skipToPrevious()
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   107
{
39
hgs
parents: 38
diff changeset
   108
    emit skipRequested( StationSkip::Previous );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   109
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   110
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   111
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   112
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   113
 */
39
hgs
parents: 38
diff changeset
   114
void RadioFrequencyStrip::skipToPreviousFavorite()
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   115
{
39
hgs
parents: 38
diff changeset
   116
    emit skipRequested( StationSkip::PreviousFavorite );
hgs
parents: 38
diff changeset
   117
}
28
075425b8d9a4 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 24
diff changeset
   118
39
hgs
parents: 38
diff changeset
   119
/*!
hgs
parents: 38
diff changeset
   120
 *
hgs
parents: 38
diff changeset
   121
 */
hgs
parents: 38
diff changeset
   122
void RadioFrequencyStrip::skipToNext()
hgs
parents: 38
diff changeset
   123
{
hgs
parents: 38
diff changeset
   124
    emit skipRequested( StationSkip::Next );
hgs
parents: 38
diff changeset
   125
}
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   126
39
hgs
parents: 38
diff changeset
   127
/*!
hgs
parents: 38
diff changeset
   128
 *
hgs
parents: 38
diff changeset
   129
 */
hgs
parents: 38
diff changeset
   130
void RadioFrequencyStrip::skipToNextFavorite()
hgs
parents: 38
diff changeset
   131
{
hgs
parents: 38
diff changeset
   132
    emit skipRequested( StationSkip::NextFavorite );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   133
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   134
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   135
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   136
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   137
 */
39
hgs
parents: 38
diff changeset
   138
void RadioFrequencyStrip::seekDown()
34
hgs
parents: 28
diff changeset
   139
{
39
hgs
parents: 38
diff changeset
   140
    emit seekRequested( Seek::Down );
34
hgs
parents: 28
diff changeset
   141
}
hgs
parents: 28
diff changeset
   142
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   143
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   144
/*!
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   145
 *
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   146
 */
39
hgs
parents: 38
diff changeset
   147
void RadioFrequencyStrip::seekUp()
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   148
{
39
hgs
parents: 38
diff changeset
   149
    emit seekRequested( Seek::Up );
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   150
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   151
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   152
/*!
39
hgs
parents: 38
diff changeset
   153
 * \reimp
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   154
 */
39
hgs
parents: 38
diff changeset
   155
bool RadioFrequencyStrip::isScanning() const
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   156
{
39
hgs
parents: 38
diff changeset
   157
    return RadioUtil::scanStatus() == Scan::ScanningInMainView;
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   158
}
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   159
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   160
/*!
39
hgs
parents: 38
diff changeset
   161
 * \reimp
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   162
 */
39
hgs
parents: 38
diff changeset
   163
uint RadioFrequencyStrip::frequencyAtIndex( int index ) const
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   164
{
39
hgs
parents: 38
diff changeset
   165
    RadioStationModel& model = mUiEngine->stationModel();
hgs
parents: 38
diff changeset
   166
    return model.data( model.index( index, 0, QModelIndex() ),
hgs
parents: 38
diff changeset
   167
                       RadioRole::RadioStationRole ).value<RadioStation>().frequency();
24
6df133bd92e1 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   168
}