|
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: MpMainWindow implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <hbapplication.h> |
|
20 #include <hbview.h> |
|
21 #include <mpxviewpluginqt.h> |
|
22 #include <xqpluginloader.h> |
|
23 #include <xqplugininfo.h> |
|
24 #include <xqserviceutil.h> |
|
25 |
|
26 #include "mpmainwindow.h" |
|
27 #include "mpmediakeyhandler.h" |
|
28 #include "mpcommondefs.h" |
|
29 #include "mpviewbase.h" |
|
30 #include "musicfetcher.h" |
|
31 #include "mptrace.h" |
|
32 |
|
33 /*! |
|
34 \class MpMainWindow |
|
35 \brief The MpMainWindow class provides Main Window functionalities. |
|
36 |
|
37 MpMainWindow handles activation of views |
|
38 |
|
39 */ |
|
40 |
|
41 /*! |
|
42 Constructs the main winsdow. |
|
43 */ |
|
44 |
|
45 MpMainWindow::MpMainWindow() |
|
46 : MpxViewFramework(), |
|
47 mMediaKeyHandler(0), |
|
48 mCollectionViewPlugin(0), |
|
49 mPlaybackViewPlugin(0), |
|
50 mCurrentViewPlugin(0), |
|
51 mPreviousViewPlugin(0), |
|
52 mMusicFetcher(0) |
|
53 { |
|
54 TX_LOG |
|
55 } |
|
56 |
|
57 /*! |
|
58 Destructs the main window. |
|
59 */ |
|
60 MpMainWindow::~MpMainWindow() |
|
61 { |
|
62 TX_ENTRY |
|
63 delete mMediaKeyHandler; |
|
64 delete mMusicFetcher; |
|
65 |
|
66 if (mCollectionViewPlugin) { |
|
67 mCollectionViewPlugin->destroyView(); |
|
68 delete mCollectionViewPlugin; |
|
69 } |
|
70 if (mPlaybackViewPlugin) { |
|
71 mPlaybackViewPlugin->destroyView(); |
|
72 delete mPlaybackViewPlugin; |
|
73 } |
|
74 |
|
75 TX_EXIT |
|
76 } |
|
77 |
|
78 |
|
79 /*! |
|
80 Initialize and activate the collection view |
|
81 */ |
|
82 void MpMainWindow::initialize() |
|
83 { |
|
84 TX_ENTRY |
|
85 |
|
86 #ifdef _DEBUG |
|
87 QList<XQPluginInfo> impls; |
|
88 XQPluginLoader::listImplementations("org.nokia.mmdt.MpxViewPlugin/1.0", impls); |
|
89 TX_LOG_ARGS("Available plugins:"); |
|
90 for ( int i = 0; i < impls.size(); i++ ) { |
|
91 TX_LOG_ARGS("Plugin " << i << ": " << impls[i].uid() << ", " << impls[i].dllName() ); |
|
92 } |
|
93 #endif // _DEBUG |
|
94 |
|
95 if ( XQServiceUtil::isService() ) { |
|
96 // Music Fetcher mode |
|
97 // Set the Collection View and Playback View to fetcher mode |
|
98 mMusicFetcher = new MusicFetcher(); |
|
99 } |
|
100 |
|
101 setViewSwitchingEnabled(false); |
|
102 XQPluginLoader collectionLoader(MpCommon::KCollectionViewUid); |
|
103 XQPluginLoader playbackLoader(MpCommon::KPlaybackViewUid); |
|
104 |
|
105 // Loading the collection plugin |
|
106 QObject* collectionInstance = collectionLoader.instance(); |
|
107 TX_LOG_ARGS("collection instance: " << reinterpret_cast<int>(collectionInstance)); |
|
108 mCollectionViewPlugin = qobject_cast<MpxViewPlugin*>( collectionInstance )->viewPlugin(); |
|
109 TX_LOG_ARGS("collection view plugin: " << reinterpret_cast<int>(mCollectionViewPlugin)); |
|
110 if ( mCollectionViewPlugin ) { |
|
111 mCollectionViewPlugin->createView(); |
|
112 MpViewBase* collectionView = reinterpret_cast<MpViewBase*>(mCollectionViewPlugin->getView()); |
|
113 if ( mMusicFetcher ) { |
|
114 collectionView->setViewMode(MpCommon::FetchView); |
|
115 collectionView->setTitle(mMusicFetcher->contextTitle()); |
|
116 int err = connect(collectionView, SIGNAL(songSelected(QString)), mMusicFetcher, SLOT(itemSelected(QString))); |
|
117 TX_LOG_ARGS("connection error: " << err); |
|
118 err = connect(mMusicFetcher, SIGNAL(titleReady(const QString&)), collectionView, SLOT(setTitle(const QString&))); |
|
119 TX_LOG_ARGS("connection error: " << err); |
|
120 } |
|
121 else { |
|
122 collectionView->setTitle("Music"); |
|
123 } |
|
124 // Collection view is the default view. |
|
125 activateView(MpMainWindow::CollectionView); |
|
126 } |
|
127 |
|
128 // Pre-load the playback plugin |
|
129 QObject* playbackInstance = playbackLoader.instance(); |
|
130 TX_LOG_ARGS("playback instance: " << reinterpret_cast<int>(playbackInstance)); |
|
131 mPlaybackViewPlugin = qobject_cast<MpxViewPlugin*>( playbackInstance )->viewPlugin(); |
|
132 TX_LOG_ARGS("playback view plugin: " << reinterpret_cast<int>(mPlaybackViewPlugin)); |
|
133 if ( mPlaybackViewPlugin ) { |
|
134 mPlaybackViewPlugin->createView(); |
|
135 MpViewBase* playbackView = reinterpret_cast<MpViewBase*>(mPlaybackViewPlugin->getView()); |
|
136 if ( mMusicFetcher ) { |
|
137 playbackView->setViewMode(MpCommon::FetchView); |
|
138 playbackView->setTitle(mMusicFetcher->contextTitle()); |
|
139 int err = connect(playbackView, SIGNAL(songSelected(QString)), mMusicFetcher, SLOT(itemSelected(QString))); |
|
140 TX_LOG_ARGS("connection error: " << err); |
|
141 err = connect(mMusicFetcher, SIGNAL(titleReady(const QString&)), playbackView, SLOT(setTitle(const QString&))); |
|
142 TX_LOG_ARGS("connection error: " << err); |
|
143 } |
|
144 else { |
|
145 playbackView->setTitle("Music"); |
|
146 } |
|
147 } |
|
148 |
|
149 mMediaKeyHandler = new MpMediaKeyHandler(); |
|
150 TX_EXIT |
|
151 } |
|
152 |
|
153 /*! |
|
154 Returns the current view plugin. |
|
155 */ |
|
156 MpxViewPlugin* MpMainWindow::currentViewPlugin() |
|
157 { |
|
158 TX_LOG |
|
159 return mCurrentViewPlugin; |
|
160 } |
|
161 |
|
162 /*! |
|
163 Handle the \a commandCode. |
|
164 */ |
|
165 void MpMainWindow::handleCommand( int commandCode ) |
|
166 { |
|
167 TX_ENTRY_ARGS("commandCode=" << commandCode ); |
|
168 |
|
169 switch ( commandCode ) { |
|
170 case MpCommon::Exit: |
|
171 if ( mCurrentViewPlugin ) { |
|
172 disconnectView(); |
|
173 } |
|
174 qApp->quit(); |
|
175 break; |
|
176 case MpCommon::ActivateCollectionView: |
|
177 activateView(CollectionView); |
|
178 break; |
|
179 case MpCommon::ActivatePlaybackView: |
|
180 activateView(PlaybackView); |
|
181 break; |
|
182 } |
|
183 TX_EXIT |
|
184 } |
|
185 |
|
186 /*! |
|
187 Activate the \a viewType view. |
|
188 */ |
|
189 void MpMainWindow::activateView(MpMainWindow::ViewType viewType) |
|
190 { |
|
191 TX_ENTRY_ARGS("viewType=" << viewType ); |
|
192 |
|
193 if ( mCurrentViewPlugin ) { |
|
194 |
|
195 disconnectView(); |
|
196 mCurrentViewPlugin->deactivateView(); |
|
197 mPreviousViewPlugin = mCurrentViewPlugin; |
|
198 mCurrentViewPlugin = 0; |
|
199 } |
|
200 |
|
201 if ( viewType == MpMainWindow::CollectionView && mCollectionViewPlugin ) { |
|
202 mCurrentViewPlugin = mCollectionViewPlugin; |
|
203 } |
|
204 else if ( viewType == MpMainWindow::PlaybackView && mPlaybackViewPlugin ) { |
|
205 mCurrentViewPlugin = mPlaybackViewPlugin; |
|
206 } |
|
207 |
|
208 if ( mCurrentViewPlugin ) { |
|
209 addView( mCurrentViewPlugin->getView() ); |
|
210 mCurrentViewPlugin->activateView(); |
|
211 connectView(); |
|
212 } |
|
213 |
|
214 if ( mPreviousViewPlugin ) { |
|
215 removeView( mPreviousViewPlugin->getView() ); |
|
216 } |
|
217 TX_EXIT |
|
218 } |
|
219 |
|
220 |
|
221 /*! |
|
222 Connect the signals to the current active view. |
|
223 */ |
|
224 void MpMainWindow::connectView() |
|
225 { |
|
226 TX_ENTRY |
|
227 |
|
228 QObject::connect(mCurrentViewPlugin, |
|
229 SIGNAL(command(int)), |
|
230 this, |
|
231 SLOT(handleCommand(int))); |
|
232 |
|
233 QObject::connect(this, |
|
234 SIGNAL( orientationChanged( Qt::Orientation ) ), |
|
235 mCurrentViewPlugin, |
|
236 SLOT( orientationChange( Qt::Orientation ) ) ); |
|
237 TX_EXIT |
|
238 } |
|
239 |
|
240 /*! |
|
241 Disonnect the signals from the current active view. |
|
242 */ |
|
243 void MpMainWindow::disconnectView() |
|
244 { |
|
245 TX_ENTRY |
|
246 |
|
247 QObject::disconnect(mCurrentViewPlugin, |
|
248 SIGNAL(command(int)), |
|
249 this, |
|
250 SLOT(handleCommand(int))); |
|
251 |
|
252 QObject::disconnect(this, |
|
253 SIGNAL( orientationChanged( Qt::Orientation ) ), |
|
254 mCurrentViewPlugin, |
|
255 SLOT( orientationChange( Qt::Orientation ) ) ); |
|
256 |
|
257 TX_EXIT |
|
258 } |
|
259 |