|
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 <glxcommandhandlernewmedia.h> |
|
22 #include <glxcommandhandlers.hrh> |
|
23 |
|
24 #include <hbinputdialog.h> |
|
25 |
|
26 GlxCommandHandlerNewMedia::GlxCommandHandlerNewMedia():iNewMediaCreationError(KErrNone) , iNewMediaItemTitle(0) |
|
27 { |
|
28 qDebug("GlxCommandHandlerNewMedia::GlxCommandHandlerNewMedia() "); |
|
29 iSchedulerWait = new (ELeave) CActiveSchedulerWait(); |
|
30 } |
|
31 |
|
32 GlxCommandHandlerNewMedia::~GlxCommandHandlerNewMedia() |
|
33 { |
|
34 qDebug("GlxCommandHandlerNewMedia::~GlxCommandHandlerNewMedia() "); |
|
35 delete iSchedulerWait; |
|
36 delete iNewMediaItemTitle; |
|
37 } |
|
38 |
|
39 CMPXCommand* GlxCommandHandlerNewMedia::CreateCommandL(TInt aCommandId, MGlxMediaList& aMediaList, TBool& aConsume) const |
|
40 { |
|
41 qDebug("GlxCommandHandlerNewMedia::CreateCommandL"); |
|
42 CMPXCollectionPath* path = aMediaList.PathLC( NGlxListDefs::EPathParent ); |
|
43 CMPXCommand* command = NULL; |
|
44 |
|
45 _LIT(KName, "TEST"); |
|
46 HBufC* newMediaItemTitle = HBufC::NewL(40); |
|
47 TPtr newMediaItemTitleDes = newMediaItemTitle->Des(); |
|
48 newMediaItemTitleDes.Append(KName); |
|
49 |
|
50 delete iNewMediaItemTitle; |
|
51 iNewMediaItemTitle= NULL; |
|
52 iNewMediaItemTitle = newMediaItemTitle; |
|
53 |
|
54 QString title("NEW MEDIA"); |
|
55 QString mainPane = QString("Album %1").arg(qrand()); |
|
56 bool ok = false; |
|
57 |
|
58 QString mediaTitle = HbInputDialog::getText(title, mainPane, &ok); |
|
59 qDebug("GlxCommandHandlerNewMedia::CreateCommandL %d", ok); |
|
60 |
|
61 if(ok == true) { |
|
62 TPtr newMediaItemTitleDes = iNewMediaItemTitle->Des(); |
|
63 newMediaItemTitleDes = (reinterpret_cast<const TUint16*>(mediaTitle.utf16())); |
|
64 command = TGlxCommandFactory::AddContainerCommandLC(*iNewMediaItemTitle, path->Id(0)); |
|
65 CleanupStack::Pop(command); |
|
66 } |
|
67 else { |
|
68 iNewMediaCreationError = KErrCancel; |
|
69 } |
|
70 |
|
71 CleanupStack::PopAndDestroy(path); |
|
72 return command; |
|
73 } |
|
74 |
|
75 |
|
76 TInt GlxCommandHandlerNewMedia::ExecuteLD(TGlxMediaId& aNewMediaId) |
|
77 { |
|
78 qDebug("GlxCommandHandlerNewMedia::ExecuteLD() "); |
|
79 GlxMpxCommandHandler::executeCommand( EGlxCmdAddMedia,KGlxAlbumsMediaId); |
|
80 |
|
81 if (iNewMediaCreationError == KErrNone) { |
|
82 // The user pressed OK on the dialog. We need to wait for DoHandleCommandComplete() |
|
83 iSchedulerWait->Start(); |
|
84 |
|
85 if (iNewMediaCreationError == KErrNone) { |
|
86 aNewMediaId = iNewMediaId; |
|
87 } |
|
88 } |
|
89 |
|
90 TInt error = iNewMediaCreationError; |
|
91 return error; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CGlxCommandHandlerNewMedia::DoHandleCommandCompleteL |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void GlxCommandHandlerNewMedia::DoHandleCommandCompleteL(TAny* /*aSessionId*/, CMPXCommand* aCommandResult, |
|
99 TInt aError, MGlxMediaList* /*aList*/) |
|
100 { |
|
101 qDebug("GlxCommandHandlerNewMedia::DoHandleCommandCompleteL() "); |
|
102 if (aError == KErrNone && aCommandResult && aCommandResult->IsSupported(KMPXMediaGeneralId)) { |
|
103 iNewMediaId = TGlxMediaId(aCommandResult->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
104 } |
|
105 |
|
106 if (iSchedulerWait && aError != KErrAlreadyExists ) { |
|
107 // if iSchedulerWait exists then we know the command is being executed from |
|
108 // the ExecuteLD() method. |
|
109 iNewMediaCreationError = aError; |
|
110 iSchedulerWait->AsyncStop(); |
|
111 } |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // HandleItemAddedL |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void GlxCommandHandlerNewMedia::HandleItemAddedL(TInt aStartIndex, TInt aEndIndex, MGlxMediaList* aList) |
|
119 { |
|
120 qDebug("GlxCommandHandlerNewMedia::HandleItemAddedL() "); |
|
121 if(/*aList == &MediaList() && */iNewMediaId != KGlxCollectionRootId) { |
|
122 for (TInt i = aStartIndex; i <= aEndIndex; i++) { |
|
123 if (aList->Item(i).Id() == iNewMediaId) { |
|
124 qDebug("GlxCommandHandlerNewMedia::HandleItemAddedL()::SetFocusL index= %d ",i); |
|
125 aList->SetFocusL(NGlxListDefs::EAbsolute, i); // calls CGlxCommandHandlerNewMedia::SetFocusL asynchronously |
|
126 if (iSchedulerWait /*&& aError != KErrAlreadyExists*/ ) { |
|
127 // if iSchedulerWait exists then we know the command is being executed from |
|
128 // the ExecuteLD() method. |
|
129 iNewMediaCreationError = KErrNone; |
|
130 iSchedulerWait->AsyncStop(); |
|
131 } |
|
132 |
|
133 break; |
|
134 } |
|
135 } |
|
136 } |
|
137 } |