|
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 collection container factory. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbdocumentloader.h> |
|
19 |
|
20 #include "mpcollectioncontainerfactory.h" |
|
21 #include "mpcollectionview.h" |
|
22 #include "mpcollectioncontainer.h" |
|
23 #include "mpcollectioncontainerallsongs.h" |
|
24 #include "mpcollectioncontainerartists.h" |
|
25 #include "mpcollectioncontainerplaylists.h" |
|
26 #include "mpcollectioncontainergenres.h" |
|
27 #include "mptrace.h" |
|
28 |
|
29 /*! |
|
30 \class MpCollectionContainerFactory |
|
31 \brief Music Player collection container factory. |
|
32 |
|
33 Collection container factory is responsible for creating different |
|
34 collection containers according to the current context. It is also |
|
35 responsible for making decisions whether to create a new container |
|
36 or reuse the existing container depending on the context transition. |
|
37 |
|
38 \sa MpCollectionContainer |
|
39 */ |
|
40 |
|
41 /*! |
|
42 Constructs the collection container factory. |
|
43 */ |
|
44 MpCollectionContainerFactory::MpCollectionContainerFactory( MpCollectionView *view, HbDocumentLoader *loader, QObject *parent ) |
|
45 : QObject(parent), |
|
46 mView(view), |
|
47 mCurrentContainer(0), |
|
48 mCurrentContext(ECollectionContextUnknown), |
|
49 mDocumentLoader(loader) |
|
50 { |
|
51 TX_LOG |
|
52 } |
|
53 |
|
54 /*! |
|
55 Destructs the collection container factory. |
|
56 */ |
|
57 MpCollectionContainerFactory::~MpCollectionContainerFactory() |
|
58 { |
|
59 TX_LOG |
|
60 } |
|
61 |
|
62 /*! |
|
63 Creates a container for the given \a context. |
|
64 */ |
|
65 MpCollectionContainer *MpCollectionContainerFactory::createContainer( |
|
66 TCollectionContext context ) |
|
67 { |
|
68 TX_ENTRY_ARGS("context=" << context); |
|
69 |
|
70 switch ( context ) { |
|
71 case ECollectionContextAllSongs: |
|
72 deleteCurrentContainer(); |
|
73 mCurrentContainer = new MpCollectionContainerAllSongs(mDocumentLoader); |
|
74 mCurrentContainer->initialize(); |
|
75 connect( mCurrentContainer, SIGNAL(itemActivated(int)), mView, SLOT(openIndex(int)) ); |
|
76 connect( mCurrentContainer, SIGNAL(itemLongPressed(int, QPointF)), mView, SLOT(openContextMenu(int, QPointF)) ); |
|
77 break; |
|
78 case ECollectionContextArtistAlbums: |
|
79 if ( mCurrentContext != ECollectionContextAlbumSongs ) { |
|
80 deleteCurrentContainer(); |
|
81 mCurrentContainer = new MpCollectionContainerArtists(mDocumentLoader); |
|
82 mCurrentContainer->initialize(); |
|
83 connect( mCurrentContainer, SIGNAL(itemActivated(int)), mView, SLOT(openIndex(int)) ); |
|
84 connect( mCurrentContainer, SIGNAL(itemLongPressed(int, QPointF)), mView, SLOT(openContextMenu(int, QPointF)) ); |
|
85 } |
|
86 break; |
|
87 case ECollectionContextPlaylists: |
|
88 if ( mCurrentContext != ECollectionContextPlaylistSongs ) { |
|
89 deleteCurrentContainer(); |
|
90 mCurrentContainer = new MpCollectionContainerPlaylists(mDocumentLoader); |
|
91 mCurrentContainer->initialize(); |
|
92 connect( mCurrentContainer, SIGNAL(itemActivated(int)), mView, SLOT(openIndex(int)) ); |
|
93 connect( mCurrentContainer, SIGNAL(itemLongPressed(int, QPointF)), mView, SLOT(openContextMenu(int, QPointF)) ); |
|
94 } |
|
95 break; |
|
96 case ECollectionContextGenres: |
|
97 if ( mCurrentContext != ECollectionContextGenreSongs ) { |
|
98 deleteCurrentContainer(); |
|
99 mCurrentContainer = new MpCollectionContainerGenres(mDocumentLoader); |
|
100 mCurrentContainer->initialize(); |
|
101 connect( mCurrentContainer, SIGNAL(itemActivated(int)), mView, SLOT(openIndex(int)) ); |
|
102 //connect( mCurrentContainer, SIGNAL(itemLongPressed(int, QPointF)), mView, SLOT(openContextMenu(int, QPointF)) ); |
|
103 } |
|
104 break; |
|
105 case ECollectionContextAlbumSongs: |
|
106 case ECollectionContextPlaylistSongs: |
|
107 case ECollectionContextGenreSongs: |
|
108 // For this contexts, reuse the same container. |
|
109 break; |
|
110 } |
|
111 TX_EXIT |
|
112 mCurrentContext = context; |
|
113 return mCurrentContainer; |
|
114 } |
|
115 |
|
116 /*! |
|
117 \internal |
|
118 */ |
|
119 void MpCollectionContainerFactory::deleteCurrentContainer() |
|
120 { |
|
121 TX_ENTRY_ARGS("mCurrentContext=" << mCurrentContext); |
|
122 switch ( mCurrentContext ) { |
|
123 case ECollectionContextAllSongs: |
|
124 delete static_cast<MpCollectionContainerAllSongs *>(mCurrentContainer); |
|
125 break; |
|
126 case ECollectionContextArtistAlbums: |
|
127 case ECollectionContextAlbumSongs: |
|
128 delete static_cast<MpCollectionContainerArtists *>(mCurrentContainer); |
|
129 break; |
|
130 case ECollectionContextPlaylists: |
|
131 case ECollectionContextPlaylistSongs: |
|
132 delete static_cast<MpCollectionContainerPlaylists *>(mCurrentContainer); |
|
133 break; |
|
134 case ECollectionContextGenres: |
|
135 case ECollectionContextGenreSongs: |
|
136 delete static_cast<MpCollectionContainerGenres *>(mCurrentContainer); |
|
137 break; |
|
138 } |
|
139 TX_EXIT |
|
140 } |
|
141 |