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