|
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 #include <mpxcollectionpath.h> |
|
19 #include <mglxmedialist.h> |
|
20 #include <glxcommandfactory.h> |
|
21 #include <glxcommandhandleraddtocontainer.h> |
|
22 #include <glxcommandhandlernewmedia.h> |
|
23 |
|
24 #include <QStringListModel> |
|
25 #include <hblabel.h> |
|
26 #include <hbaction.h> |
|
27 |
|
28 #include <glxalbummodel.h> |
|
29 #include <glxcollectionpluginalbums.hrh> |
|
30 #include <glxmodelparm.h> |
|
31 #include <QDebug> |
|
32 #include <glxfilterfactory.h> |
|
33 |
|
34 |
|
35 #include <hblistwidget.h> |
|
36 #include <hbview.h> |
|
37 #include <hbpushbutton.h> |
|
38 #include <QGraphicsGridLayout> |
|
39 #include <hbdialog.h> |
|
40 |
|
41 TInt GlxCommandHandlerAddToContainer::iSelectionCount = 0; |
|
42 |
|
43 const TInt KSelectionPopupListHierarchy = 5; |
|
44 |
|
45 GlxQueryContentWidget::GlxQueryContentWidget(QGraphicsItem* parent):QGraphicsWidget(parent), |
|
46 mButton(0), mListView(0), mGrid(0) |
|
47 { |
|
48 mGrid = new QGraphicsGridLayout; |
|
49 mGrid->setContentsMargins(0,0,0,0); |
|
50 |
|
51 mButton = new HbPushButton("New Item"); |
|
52 mListView = new HbListView(this); |
|
53 mListView->setSelectionMode(HbAbstractItemView::MultiSelection); |
|
54 mListView->setMinimumSize(QSize(360, 180)); |
|
55 mListView->setMaximumSize(QSize(360, 180)); |
|
56 |
|
57 mGrid->addItem(mButton, 0,0); |
|
58 mGrid->addItem(mListView, 1,0); |
|
59 setLayout(mGrid); //ownership transfered |
|
60 |
|
61 setPreferredWidth(360); |
|
62 } |
|
63 |
|
64 GlxQueryContentWidget::~GlxQueryContentWidget() |
|
65 { |
|
66 qDebug("GlxQueryContentWidget::~GlxQueryContentWidget() "); |
|
67 delete mListView; |
|
68 delete mButton; |
|
69 qDebug("GlxQueryContentWidget::~GlxQueryContentWidget() exit"); |
|
70 } |
|
71 |
|
72 GlxCommandHandlerAddToContainer::GlxCommandHandlerAddToContainer():mNewMediaAdded(false) |
|
73 { |
|
74 mTargetContainers = NULL; |
|
75 qDebug("GlxCommandHandlerAddToContainer::GlxCommandHandlerAddToContainer() "); |
|
76 } |
|
77 |
|
78 GlxCommandHandlerAddToContainer::~GlxCommandHandlerAddToContainer() |
|
79 { |
|
80 delete mTargetContainers; |
|
81 qDebug("GlxCommandHandlerAddToContainer::~GlxCommandHandlerAddToContainer() "); |
|
82 } |
|
83 |
|
84 CMPXCommand* GlxCommandHandlerAddToContainer::CreateCommandL(TInt aCommandId, MGlxMediaList& aMediaList, TBool& aConsume) const |
|
85 { |
|
86 qDebug("GlxCommandHandlerAddToContainer::CreateCommandL"); |
|
87 iSelectionCount = 0; |
|
88 |
|
89 CMPXCollectionPath* sourceItems = aMediaList.PathLC( NGlxListDefs::EPathFocusOrSelection ); |
|
90 bool ok = false; |
|
91 |
|
92 |
|
93 //create target medialist |
|
94 CMPXCollectionPath* path = CMPXCollectionPath::NewL(); |
|
95 CleanupStack::PushL( path ); |
|
96 path->AppendL(KGlxCollectionPluginAlbumsImplementationUid); |
|
97 |
|
98 CMPXFilter* filter = TGlxFilterFactory::CreateCameraAlbumExclusionFilterL(); |
|
99 CleanupStack::PushL(filter); |
|
100 |
|
101 // Create the media list |
|
102 MGlxMediaList* targetMediaList = MGlxMediaList::InstanceL( *path, |
|
103 TGlxHierarchyId(KSelectionPopupListHierarchy), filter ); //todo take actual hierarchy |
|
104 CleanupStack::PopAndDestroy( filter ); |
|
105 CleanupStack::PopAndDestroy(path); |
|
106 |
|
107 //create target model |
|
108 GlxModelParm modelParm (KGlxCollectionPluginAlbumsImplementationUid, KSelectionPopupListHierarchy,EGlxFilterExcludeCamera); |
|
109 GlxAlbumModel *albumMediaModel = new GlxAlbumModel (modelParm); |
|
110 albumMediaModel->setData(QModelIndex(), (int)GlxContextSelectionList, GlxContextRole ); |
|
111 |
|
112 //QModelIndexList selectedModelIndexes; |
|
113 QModelIndexList modelList = GetSelectionList(albumMediaModel,&ok); |
|
114 |
|
115 CMPXCommand* command = NULL; |
|
116 qDebug("GlxCommandHandlerAddToContainer::CreateCommandL OK %d new media added %d", ok, mNewMediaAdded); |
|
117 |
|
118 if (ok|| mNewMediaAdded) { |
|
119 int count = modelList.count(); |
|
120 |
|
121 for(int i = 0 ; i < count ; i++) { |
|
122 albumMediaModel->setData( modelList[i], modelList[i].row(), GlxSelectedIndexRole ); |
|
123 } |
|
124 |
|
125 if(!mNewMediaAdded) { |
|
126 CMPXCollectionPath* targetContainers = targetMediaList->PathLC( NGlxListDefs::EPathFocusOrSelection ); |
|
127 CleanupStack::Pop(targetContainers); |
|
128 delete mTargetContainers; |
|
129 mTargetContainers = NULL; |
|
130 mTargetContainers = targetContainers; |
|
131 } |
|
132 |
|
133 command = TGlxCommandFactory::AddToContainerCommandLC(*sourceItems, *mTargetContainers); |
|
134 CleanupStack::Pop(command); |
|
135 mNewMediaAdded = false; |
|
136 } |
|
137 |
|
138 MGlxMediaList::UnmarkAllL(*targetMediaList); |
|
139 targetMediaList->Close(); |
|
140 CleanupStack::PopAndDestroy(sourceItems); |
|
141 delete albumMediaModel; |
|
142 return command; |
|
143 } |
|
144 |
|
145 QModelIndexList GlxCommandHandlerAddToContainer::GetSelectionList(GlxAlbumModel *model,bool *ok) const |
|
146 { |
|
147 // Create a popup |
|
148 HbDialog popup; |
|
149 |
|
150 // Set dismiss policy that determines what tap events will cause the popup |
|
151 // to be dismissed |
|
152 popup.setDismissPolicy(HbDialog::NoDismiss); |
|
153 |
|
154 // Set timeout to zero to wait user to either click Ok or Cancel |
|
155 popup.setTimeout(HbDialog::NoTimeout); |
|
156 popup.setHeadingWidget(new HbLabel("Selection List")); |
|
157 |
|
158 GlxQueryContentWidget* view = new GlxQueryContentWidget(); |
|
159 view->mListView->setModel(model); |
|
160 |
|
161 qDebug("GlxCommandHandlerAddToContainer::GetSelectionList model setting done row count %d",model->rowCount() ); |
|
162 connect(view->mButton, SIGNAL(released ()), &popup, SLOT(close())); |
|
163 connect(view->mButton, SIGNAL(released ()), this, SLOT(createNewMedia())); |
|
164 |
|
165 HbAction *primary = new HbAction("OK"); |
|
166 popup.setPrimaryAction(primary); |
|
167 |
|
168 HbAction *secondary = new HbAction("Cancel"); |
|
169 popup.setSecondaryAction(secondary); |
|
170 |
|
171 popup.setContentWidget(view); //ownership transfer |
|
172 qDebug("GlxCommandHandlerAddToContainer::GetSelectionList after popup.setContentWidget "); |
|
173 view->mListView->show(); |
|
174 QModelIndexList selectedIndexes; |
|
175 |
|
176 do { |
|
177 HbAction* action = popup.exec(); |
|
178 if(action == popup.primaryAction()){ |
|
179 *ok = true; |
|
180 } |
|
181 else { |
|
182 *ok = false; |
|
183 } |
|
184 |
|
185 qDebug("GlxCommandHandlerAddToContainer::GetSelectionList after exec user action %d ", *ok); |
|
186 |
|
187 if( *ok ) { |
|
188 GlxQueryContentWidget* cWidget = qobject_cast<GlxQueryContentWidget*>(popup.contentWidget()); |
|
189 QItemSelectionModel* selModel = cWidget->mListView->selectionModel(); |
|
190 qDebug("GlxCommandHandlerAddToContainer::GetSelectionList selection model %d", selModel); |
|
191 selectedIndexes = selModel->selectedIndexes(); |
|
192 } |
|
193 } while ( *ok && selectedIndexes.count() == 0); //continue until user select one album list or new item |
|
194 |
|
195 delete primary; |
|
196 delete secondary; |
|
197 qDebug("GlxCommandHandlerAddToContainer::GetSelectionList exit "); |
|
198 |
|
199 return selectedIndexes; |
|
200 } |
|
201 |
|
202 void GlxCommandHandlerAddToContainer::createNewMedia() |
|
203 { |
|
204 qDebug("GlxCommandHandlerAddToContainer::createNewMedia "); |
|
205 GlxCommandHandlerNewMedia* commandHandlerNewMedia = new GlxCommandHandlerNewMedia(); |
|
206 TGlxMediaId newMediaId; |
|
207 TInt error = commandHandlerNewMedia->ExecuteLD(newMediaId); |
|
208 |
|
209 if (error == KErrNone) { |
|
210 CMPXCollectionPath* path = CMPXCollectionPath::NewL(); |
|
211 CleanupStack::PushL( path ); |
|
212 path->AppendL(KGlxCollectionPluginAlbumsImplementationUid); |
|
213 path->AppendL(newMediaId.Value()); |
|
214 CleanupStack::Pop(path); |
|
215 delete mTargetContainers; |
|
216 mTargetContainers = NULL; |
|
217 mTargetContainers = path; |
|
218 mNewMediaAdded = true; |
|
219 } |
|
220 } |