|
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 <hbmessagebox.h> |
|
19 #include <hblabel.h> |
|
20 |
|
21 #include <mpxcollectionpath.h> |
|
22 #include <mglxmedialist.h> |
|
23 #include <glxcommandfactory.h> |
|
24 #include <glxcommandhandlercomment.h> |
|
25 #include <glxattributecontext.h> |
|
26 #include <glxattributeretriever.h> |
|
27 #include <glxfetchcontextremover.h> |
|
28 #include <glxcommondialogs.h> |
|
29 #include "glxlocalisationstrings.h" |
|
30 |
|
31 GlxCommandHandlerComment::GlxCommandHandlerComment() |
|
32 { |
|
33 } |
|
34 |
|
35 GlxCommandHandlerComment::~GlxCommandHandlerComment() |
|
36 { |
|
37 } |
|
38 |
|
39 CMPXCommand* GlxCommandHandlerComment::CreateCommandL(TInt aCommandId, |
|
40 MGlxMediaList& aMediaList, TBool& aConsume) const |
|
41 { |
|
42 Q_UNUSED(aCommandId); |
|
43 Q_UNUSED(aConsume); |
|
44 |
|
45 CMPXCommand* command = NULL; |
|
46 QString mainPane = GetName(aMediaList); |
|
47 QString title(GLX_DETAILS_DESCRIPTION); |
|
48 QString mediaTitle = NULL; |
|
49 bool ok = false; |
|
50 GlxTextInputDialog* dlg = new GlxTextInputDialog(); |
|
51 mediaTitle = dlg->getText(title, mainPane, &ok); |
|
52 delete dlg; |
|
53 |
|
54 if(ok == true) |
|
55 { |
|
56 TPtrC16 newMediaItemTitleDes |
|
57 = (reinterpret_cast<const TUint16*> (mediaTitle.utf16())); |
|
58 |
|
59 HBufC* newMediaItemTitle = newMediaItemTitleDes.Alloc(); |
|
60 CleanupStack::PushL(newMediaItemTitle); |
|
61 |
|
62 CMPXCollectionPath* path = aMediaList.PathLC( |
|
63 NGlxListDefs::EPathFocusOrSelection); |
|
64 command = |
|
65 TGlxCommandFactory::SetDescriptionCommandLC(*newMediaItemTitle,*path); |
|
66 CleanupStack::Pop(command); |
|
67 CleanupStack::PopAndDestroy(path); |
|
68 CleanupStack::PopAndDestroy(newMediaItemTitle); |
|
69 } |
|
70 return command; |
|
71 } |
|
72 |
|
73 QString GlxCommandHandlerComment::CompletionTextL() const |
|
74 { |
|
75 //return command completion text |
|
76 return QString(); |
|
77 } |
|
78 |
|
79 QString GlxCommandHandlerComment::GetName(MGlxMediaList& aMediaList) const |
|
80 { |
|
81 // Create an iterator to retrieve the relevant attribute |
|
82 TGlxSelectionIterator iterator; |
|
83 // only want the title of one item |
|
84 iterator.SetRange( 1 ); |
|
85 CGlxAttributeContext* context = new( ELeave ) |
|
86 CGlxAttributeContext( &iterator ); |
|
87 CleanupStack::PushL( context ); |
|
88 |
|
89 // Want to read the title attribute |
|
90 // Configure the context |
|
91 context->AddAttributeL( KMPXMediaGeneralComment ); |
|
92 |
|
93 // Add the context to the media list |
|
94 aMediaList.AddContextL( context, KGlxFetchContextPriorityBlocking ); |
|
95 |
|
96 // TGlxContextRemover will remove the context when it goes out of scope |
|
97 // Used here to avoid a trap and still have safe cleanup |
|
98 TGlxFetchContextRemover contextRemover( context, aMediaList ); |
|
99 // put to cleanupstack as cleanupstack is emptied before stack objects |
|
100 // are deleted |
|
101 CleanupClosePushL( contextRemover ); |
|
102 // Yuck - a leave and a return code! |
|
103 // EFalse => don't show a progress dialog |
|
104 TInt err = GlxAttributeRetriever::RetrieveL( *context, aMediaList, EFalse ); |
|
105 // Using a distinct error value as "LeaveIfError( FuncL() );" looks bad |
|
106 User::LeaveIfError( err ); |
|
107 // context off the list |
|
108 CleanupStack::PopAndDestroy( &contextRemover ); |
|
109 |
|
110 // Now get the title of the relevant item: if *an* item is selected use its |
|
111 // title, otherwise use the item with focus |
|
112 // Get the index of the item to rename |
|
113 TInt index = KErrNotFound; |
|
114 QString title = NULL; |
|
115 // first see if there's a selected item... |
|
116 if ( aMediaList.SelectionCount() == 1 ) |
|
117 { |
|
118 // Find the index of the selected item |
|
119 index = aMediaList.Count(); |
|
120 do |
|
121 { |
|
122 --index; |
|
123 } |
|
124 while ( !aMediaList.IsSelected( index ) && index > 0 ); |
|
125 } |
|
126 else |
|
127 { |
|
128 // Use the index of the item with focus |
|
129 index = aMediaList.FocusIndex(); |
|
130 } |
|
131 |
|
132 if ( index != KErrNotFound ) |
|
133 { |
|
134 // use iterator to get the right item |
|
135 iterator.SetToFirst( &aMediaList ); |
|
136 const CGlxMedia* media = aMediaList.Item( iterator++ ).Properties(); |
|
137 if( media ) |
|
138 { |
|
139 // found the item's media properties, extract the title |
|
140 const TDesC& titleDesc = media->ValueText(KMPXMediaGeneralComment); |
|
141 title = QString::fromUtf16(titleDesc.Ptr(), |
|
142 titleDesc.Length()); |
|
143 } |
|
144 } |
|
145 CleanupStack::PopAndDestroy( context ); |
|
146 |
|
147 return title; |
|
148 } |
|
149 |
|
150 void GlxCommandHandlerComment::HandleErrorL(TInt aErrorCode) |
|
151 { |
|
152 if(aErrorCode == KErrAlreadyExists) |
|
153 { |
|
154 HbMessageBox::warning("Name Already Exist!!!", new HbLabel( |
|
155 "Rename")); |
|
156 } |
|
157 else{ |
|
158 GlxMpxCommandHandler::HandleErrorL(aErrorCode); |
|
159 } |
|
160 } |
|
161 |