|
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: Music Player now playing widget - Private. |
|
15 * |
|
16 */ |
|
17 #include <QPainter> |
|
18 #include <QGraphicsSceneMouseEvent> |
|
19 |
|
20 #include <hbstackedlayout.h> |
|
21 #include <hblabel.h> |
|
22 #include <hbicon.h> |
|
23 #include <hbiconitem.h> |
|
24 #include <hbdocumentloader.h> |
|
25 #include <hbinstance.h> |
|
26 |
|
27 #include "mpnowplayingwidget_p.h" |
|
28 #include "mpnowplayingwidget.h" |
|
29 #include "mpnowplayingbackend.h" |
|
30 #include "mptrace.h" |
|
31 |
|
32 const char *NOW_PLAYING_XML = ":/xml/nowplaying.docml"; |
|
33 |
|
34 /*! |
|
35 \internal |
|
36 \class MpNowPlayingWidgetPrivate |
|
37 \brief Custom HB widget that displays currently playing song information. |
|
38 |
|
39 This is a composite widget made out of HB widgets, it displays information |
|
40 for the current playing song on the playback engine indicated at |
|
41 construction time. |
|
42 */ |
|
43 |
|
44 /*! |
|
45 \internal |
|
46 Constructs the now playing widget private. |
|
47 */ |
|
48 MpNowPlayingWidgetPrivate::MpNowPlayingWidgetPrivate(long int playerId, MpNowPlayingWidget *qq ) |
|
49 : q_ptr( qq ), |
|
50 mPrimaryText(0), |
|
51 mSecondaryText(0), |
|
52 mState( NotPlaying ), |
|
53 mIcon(0), |
|
54 mDocumentLoader(0) |
|
55 { |
|
56 TX_ENTRY_ARGS( "Player ID =" << playerId << " Q pointer=" << ( void * )qq ) |
|
57 QGraphicsWidget *widget; |
|
58 bool widgetsOk = false; |
|
59 |
|
60 |
|
61 mPlayIcon = new HbIcon( QString(":/icons/play.png")); |
|
62 mPauseIcon = new HbIcon( QString(":/icons/pause.png")); |
|
63 |
|
64 mDocumentLoader = new HbDocumentLoader(); |
|
65 if (mDocumentLoader) { |
|
66 mDocumentLoader->load( NOW_PLAYING_XML, &widgetsOk); |
|
67 } |
|
68 |
|
69 if (widgetsOk) { |
|
70 |
|
71 // find the main widget container and all of its child items |
|
72 widget = mDocumentLoader->findWidget(QString("nowPlayingContainer")); |
|
73 HbWidget* container = qobject_cast<HbWidget*>(widget); |
|
74 container->setParentItem(q_ptr); |
|
75 |
|
76 widget = mDocumentLoader->findWidget(QString("primaryText")); |
|
77 mPrimaryText = qobject_cast<HbLabel*>(widget); |
|
78 |
|
79 widget = mDocumentLoader->findWidget(QString("secondaryText")); |
|
80 mSecondaryText = qobject_cast<HbLabel*>(widget); |
|
81 |
|
82 widget = mDocumentLoader->findWidget(QString("playPause")); |
|
83 mIcon = qobject_cast<HbLabel*>(widget); |
|
84 |
|
85 HbStackedLayout *mylayout; |
|
86 mylayout = new HbStackedLayout(q_ptr); |
|
87 mylayout->addItem( container ); |
|
88 |
|
89 q_ptr->setLayout( mylayout ); |
|
90 } |
|
91 else { |
|
92 TX_LOG_ARGS("Error: invalid xml file."); |
|
93 Q_ASSERT_X(widgetsOk, "MpNowPlayingWidgetPrivate", "invalid xml file"); |
|
94 } |
|
95 |
|
96 mBackEnd = new MpNowPlayingBackEnd( playerId ); |
|
97 setEnabled(true); |
|
98 TX_EXIT |
|
99 } |
|
100 |
|
101 |
|
102 /*! |
|
103 \internal |
|
104 Destructs the now playing widget private. |
|
105 */ |
|
106 MpNowPlayingWidgetPrivate::~MpNowPlayingWidgetPrivate() |
|
107 { |
|
108 TX_ENTRY |
|
109 delete mBackEnd; |
|
110 delete mPlayIcon; |
|
111 delete mPauseIcon; |
|
112 delete mDocumentLoader; |
|
113 TX_EXIT |
|
114 } |
|
115 |
|
116 /*! |
|
117 If \a enabled is true, the item is enabled; otherwise, it is disabled. |
|
118 Item is enabled by default. |
|
119 */ |
|
120 void MpNowPlayingWidgetPrivate::setEnabled( bool enabled ) |
|
121 { |
|
122 if ( enabled ) { |
|
123 connect( mBackEnd, SIGNAL(stateUpdate(SimplifiedPlayerState)), |
|
124 this, SLOT(setState(SimplifiedPlayerState)) ); |
|
125 |
|
126 connect( mBackEnd, SIGNAL(titleChanged(QString)), |
|
127 mPrimaryText, SLOT(setPlainText(QString)) ); |
|
128 |
|
129 connect( mBackEnd, SIGNAL(artistChanged(QString)), |
|
130 mSecondaryText, SLOT(setPlainText(QString)) ); |
|
131 mBackEnd->update(); |
|
132 } |
|
133 else { |
|
134 disconnect( mBackEnd, SIGNAL(stateUpdate(SimplifiedPlayerState)), |
|
135 this, SLOT(setState(SimplifiedPlayerState)) ); |
|
136 |
|
137 disconnect( mBackEnd, SIGNAL(titleChanged(QString)), |
|
138 mPrimaryText, SLOT(setPlainText(QString)) ); |
|
139 |
|
140 disconnect( mBackEnd, SIGNAL(artistChanged(QString)), |
|
141 mSecondaryText, SLOT(setPlainText(QString)) ); |
|
142 } |
|
143 } |
|
144 |
|
145 /*! |
|
146 \internal |
|
147 Offers click \a event to the widget privated side, if event is consumed it returns true. |
|
148 */ |
|
149 bool MpNowPlayingWidgetPrivate::handleClickEvent(QGraphicsSceneMouseEvent *event) |
|
150 { |
|
151 if ( mIcon->windowFrameGeometry().contains( event->pos() ) ) { |
|
152 mBackEnd->playPause(); |
|
153 return true; |
|
154 } |
|
155 else { |
|
156 return false; |
|
157 } |
|
158 } |
|
159 |
|
160 |
|
161 /*! |
|
162 \internal |
|
163 Sets the simplified playback \a state. |
|
164 */ |
|
165 void MpNowPlayingWidgetPrivate::setState( SimplifiedPlayerState state ) |
|
166 { |
|
167 TX_ENTRY_ARGS( "State = " << state ) |
|
168 switch ( state ) { |
|
169 case NotPlaying: |
|
170 if ( mState != NotPlaying ) |
|
171 emit q_ptr->playbackAttachmentChanged( false ); |
|
172 break; |
|
173 case Playing: |
|
174 mIcon->setIcon(*mPauseIcon); |
|
175 if (mState == NotPlaying) |
|
176 emit q_ptr->playbackAttachmentChanged( true ); |
|
177 break; |
|
178 case Paused: |
|
179 mIcon->setIcon(*mPlayIcon); |
|
180 if (mState == NotPlaying) |
|
181 emit q_ptr->playbackAttachmentChanged( true ); |
|
182 break; |
|
183 default: |
|
184 break; |
|
185 } |
|
186 mState = state; |
|
187 TX_EXIT |
|
188 } |
|
189 |
|
190 |