1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 |
|
20 // User includes |
|
21 #include "radiocarouselmodel.h" |
|
22 #include "radiocarouselmodel_p.h" |
|
23 #include "radiostationmodel.h" |
|
24 #include "radiouiengine.h" |
|
25 #include "radiostation.h" |
|
26 #include "radio_global.h" |
|
27 #include "radiologger.h" |
|
28 |
|
29 /*! |
|
30 * |
|
31 */ |
|
32 RadioCarouselModel::RadioCarouselModel( RadioUiEngine& uiEngine, RadioStationModel& stationModel ) : |
|
33 QAbstractListModel( &uiEngine ), |
|
34 d_ptr( new RadioCarouselModelPrivate( this, uiEngine, stationModel ) ) |
|
35 { |
|
36 connectAndTest( &stationModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
37 this, SIGNAL(dataChanged(QModelIndex,QModelIndex)) ); |
|
38 connectAndTest( &stationModel, SIGNAL(layoutAboutToBeChanged()), |
|
39 this, SIGNAL(layoutAboutToBeChanged()) ); |
|
40 connectAndTest( &stationModel, SIGNAL(layoutChanged()), |
|
41 this, SIGNAL(layoutChanged()) ); |
|
42 connectAndTest( &stationModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), |
|
43 this, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)) ); |
|
44 connectAndTest( &stationModel, SIGNAL(rowsInserted(QModelIndex,int,int)), |
|
45 this, SIGNAL(rowsInserted(QModelIndex,int,int)) ); |
|
46 connectAndTest( &stationModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
47 this, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)) ); |
|
48 connectAndTest( &stationModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
|
49 this, SIGNAL(rowsRemoved(QModelIndex,int,int)) ); |
|
50 connectAndTest( &stationModel, SIGNAL(modelAboutToBeReset()), |
|
51 this, SIGNAL(modelAboutToBeReset()) ); |
|
52 connectAndTest( &stationModel, SIGNAL(modelReset()), |
|
53 this, SIGNAL(modelReset()) ); |
|
54 |
|
55 // connectAndTest( model(), SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
56 // this, SLOT(removeFrequency(QModelIndex,int,int)) ); |
|
57 } |
|
58 |
|
59 /*! |
|
60 * |
|
61 */ |
|
62 RadioCarouselModel::~RadioCarouselModel() |
|
63 { |
|
64 delete d_ptr; |
|
65 } |
|
66 |
|
67 /*! |
|
68 * \reimp |
|
69 */ |
|
70 int RadioCarouselModel::rowCount( const QModelIndex& parent ) const |
|
71 { |
|
72 Q_UNUSED( parent ); |
|
73 Q_D( const RadioCarouselModel ); |
|
74 const int rowCount = d->mStationModel.rowCount(); |
|
75 if ( rowCount == 0 ) { |
|
76 return 1; |
|
77 } |
|
78 return rowCount; |
|
79 } |
|
80 |
|
81 /*! |
|
82 * \reimp |
|
83 */ |
|
84 QVariant RadioCarouselModel::data( const QModelIndex& index, int role ) const |
|
85 { |
|
86 if ( !index.isValid() ) { |
|
87 return QVariant(); |
|
88 } |
|
89 |
|
90 Q_D( const RadioCarouselModel ); |
|
91 if ( role == RadioStationModel::RadioStationRole ) { |
|
92 const int rowCount = d->mStationModel.rowCount(); |
|
93 if ( rowCount == 0 ) { |
|
94 QVariant variant; |
|
95 variant.setValue( d->mStationModel.currentStation() ); |
|
96 return variant; |
|
97 } else { |
|
98 return d->mStationModel.data( index, role ); |
|
99 } |
|
100 } |
|
101 |
|
102 return QVariant(); |
|
103 } |
|
104 |
|
105 /*! |
|
106 * Finds the closest station from the given frequency |
|
107 */ |
|
108 RadioStation RadioCarouselModel::findClosest( const uint frequency, StationSkip::Mode mode ) |
|
109 { |
|
110 Q_D( RadioCarouselModel ); |
|
111 return d->mStationModel.findClosest( frequency, mode ); |
|
112 } |
|
113 |
|
114 /*! |
|
115 * Returns the model index corresponding to the given frequency |
|
116 */ |
|
117 QModelIndex RadioCarouselModel::modelIndexFromFrequency( uint frequency ) |
|
118 { |
|
119 Q_D( RadioCarouselModel ); |
|
120 if ( d->mStationModel.rowCount() == 0 ) { |
|
121 return index( 0, 0 ); |
|
122 } else { |
|
123 RadioStation station; |
|
124 if ( d->mStationModel.findFrequency( frequency, station ) ) { |
|
125 return index( d->mStationModel.findPresetIndex( station.presetIndex() ), 0 ); |
|
126 } |
|
127 } |
|
128 |
|
129 return QModelIndex(); |
|
130 } |
|
131 |
|
132 /*! |
|
133 * \reimp |
|
134 */ |
|
135 void RadioCarouselModel::removeFrequency( const QModelIndex& parent, int first, int last ) |
|
136 { |
|
137 Q_UNUSED( parent ); |
|
138 Q_UNUSED( first ); |
|
139 Q_UNUSED( last ); |
|
140 } |
|