1 /* |
|
2 * Copyright (c) 2006 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: Sending remote drive configuration entries |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <eikenv.h> |
|
20 #include <sendui.h> |
|
21 #include <CMessageData.h> |
|
22 #include <SendUiConsts.h> |
|
23 #include <txtrich.h> |
|
24 #include <utf.h> // for CnvUtfConverter |
|
25 #include <StringLoader.h> |
|
26 #include <AknQueryDialog.h> |
|
27 #include <sysutil.h> |
|
28 #include <rsfwgspluginrsc.rsg> |
|
29 #include <rsfwmountentry.h> |
|
30 |
|
31 #include "rsfwgsremotedrivesend.h" |
|
32 #include "rsfwmountutils.h" |
|
33 #include "rsfwgsplugin.hrh" |
|
34 |
|
35 |
|
36 // --------------------------------------------------------- |
|
37 // CRsfwGsRemoteDriveSend::NewL |
|
38 // Static constructor |
|
39 // (other items were commented in a header). |
|
40 // --------------------------------------------------------- |
|
41 // |
|
42 CRsfwGsRemoteDriveSend* CRsfwGsRemoteDriveSend::NewL(TInt aMenuCommandId) |
|
43 { |
|
44 CRsfwGsRemoteDriveSend* self = new (ELeave) CRsfwGsRemoteDriveSend(); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(aMenuCommandId); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------- |
|
52 // CRsfwGsRemoteDriveSend::CRsfwGsRemoteDriveSend |
|
53 // C++ constructor |
|
54 // (other items were commented in a header). |
|
55 // --------------------------------------------------------- |
|
56 // |
|
57 CRsfwGsRemoteDriveSend::CRsfwGsRemoteDriveSend() |
|
58 { |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // CRsfwGsRemoteDriveSend::ConstructL |
|
63 // 2nd phase constructor |
|
64 // (other items were commented in a header). |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 void CRsfwGsRemoteDriveSend::ConstructL(TInt aMenuCommandId) |
|
68 { |
|
69 iSendUi = CSendUi::NewL(); |
|
70 iSendAsCmdId=aMenuCommandId; |
|
71 iSendMtmsToDim = new (ELeave) CArrayFixFlat<TUid>(4); |
|
72 |
|
73 // for the time being, dim everything else but SMS |
|
74 // for some reason technology-group UIDs do not seem to work |
|
75 // e-mail Mtmss |
|
76 iSendMtmsToDim->AppendL(KSenduiMtmSmtpUid); |
|
77 iSendMtmsToDim->AppendL(KSenduiMtmImap4Uid); |
|
78 iSendMtmsToDim->AppendL(KSenduiMtmPop3Uid); |
|
79 |
|
80 // MMS, BT, Irda, Postcard |
|
81 iSendMtmsToDim->AppendL(KSenduiMtmMmsUid); |
|
82 iSendMtmsToDim->AppendL(KSenduiMtmPostcardUid); |
|
83 iSendMtmsToDim->AppendL(KSenduiMtmBtUid); |
|
84 iSendMtmsToDim->AppendL(KSenduiMtmIrUid); |
|
85 |
|
86 // Audio Message |
|
87 iSendMtmsToDim->AppendL(KSenduiMtmAudioMessageUid); |
|
88 |
|
89 iSendMtmsToDim->AppendL(KSenduiMtmSyncMLEmailUid ); |
|
90 |
|
91 // filters out EMail Via Exchange, as we only support SMS |
|
92 // for some reason this cannot be found from headers currently |
|
93 const TUid KEmailViaExchange = { 0x102826F8 }; |
|
94 iSendMtmsToDim->AppendL(KEmailViaExchange ); |
|
95 |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------- |
|
99 // CRsfwGsRemoteDriveSend::~CRsfwGsRemoteDriveSend |
|
100 // Destructor |
|
101 // (other items were commented in a header). |
|
102 // --------------------------------------------------------- |
|
103 // |
|
104 CRsfwGsRemoteDriveSend::~CRsfwGsRemoteDriveSend() |
|
105 { |
|
106 delete iSendUi; |
|
107 delete iSendMtmsToDim; |
|
108 } |
|
109 |
|
110 |
|
111 // --------------------------------------------------------- |
|
112 // CRsfwGsRemoteDriveSend::CanSendL |
|
113 // Check wheter sending is possible |
|
114 // (other items were commented in a header). |
|
115 // --------------------------------------------------------- |
|
116 // |
|
117 TBool CRsfwGsRemoteDriveSend::CanSend() |
|
118 { |
|
119 if( iSelectedMtmUid != KNullUid ) |
|
120 { |
|
121 return ETrue; |
|
122 } |
|
123 else |
|
124 { |
|
125 return EFalse; |
|
126 } |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------- |
|
130 // CRsfwGsRemoteDriveSend::DisplaySendMenuItemL |
|
131 // Show sendui menu |
|
132 // (other items were commented in a header). |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 void CRsfwGsRemoteDriveSend::DisplaySendMenuItemL(CEikMenuPane& aMenuPane, |
|
136 TInt aIndex) |
|
137 { |
|
138 iSendUi->AddSendMenuItemL( aMenuPane, aIndex, iSendAsCmdId, TSendingCapabilities() ); |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------- |
|
142 // CRsfwGsRemoteDriveSend::DisplaySendCascadeMenuL |
|
143 // Show send quesry / cascaded menu |
|
144 // (other items were commented in a header). |
|
145 // --------------------------------------------------------- |
|
146 // |
|
147 void CRsfwGsRemoteDriveSend::DisplaySendCascadeMenuL() |
|
148 { |
|
149 iSelectedMtmUid = iSendUi->ShowSendQueryL( NULL, KCapabilitiesForAllServices, iSendMtmsToDim, KNullDesC ); |
|
150 } |
|
151 |
|
152 |
|
153 |
|
154 // --------------------------------------------------------- |
|
155 // CRsfwGsRemoteDriveSend::SendL |
|
156 // Send a remote drive entry via SendUi |
|
157 // (other items were commented in a header). |
|
158 // --------------------------------------------------------- |
|
159 // |
|
160 void CRsfwGsRemoteDriveSend::SendL(const CRsfwMountEntry& anEntry) |
|
161 { |
|
162 |
|
163 // the old entry can be deleted in the middle of the operation |
|
164 // e.g. from the File Manager |
|
165 CRsfwMountEntry* entryToBeSent = anEntry.CloneL(); |
|
166 CleanupStack::PushL(entryToBeSent); |
|
167 |
|
168 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
|
169 CRichText* text = CRichText::NewL( |
|
170 eikonEnv->SystemParaFormatLayerL(), |
|
171 eikonEnv->SystemCharFormatLayerL()); |
|
172 CleanupStack::PushL(text); |
|
173 |
|
174 |
|
175 // if user name has been set |
|
176 // ask user whether he would like to send the login credentials |
|
177 TBool sendCredentials = EFalse; |
|
178 if ((entryToBeSent->Item(EMountEntryItemUserName))->Length() > 0) |
|
179 { |
|
180 HBufC* myDisplayMessage = NULL; |
|
181 myDisplayMessage = StringLoader::LoadLC(R_STR_RSFW_SEND_CREDENTIALS_QUERY); |
|
182 CAknQueryDialog* query = CAknQueryDialog::NewL |
|
183 (CAknQueryDialog::EConfirmationTone); |
|
184 sendCredentials = |
|
185 query->ExecuteLD( R_CONFIRMATION_QUERY, *myDisplayMessage); |
|
186 CleanupStack::PopAndDestroy(myDisplayMessage); |
|
187 } |
|
188 |
|
189 |
|
190 // Encode configuration entry |
|
191 HBufC* vcal = HBufC::NewLC(KMaxMountConfLength); |
|
192 TPtr p = vcal->Des(); |
|
193 RsfwMountUtils::ExportMountEntryL(*entryToBeSent, sendCredentials, p); |
|
194 |
|
195 // convert to 8-bit |
|
196 // note that safe conversion is needed both when sending |
|
197 // as an attachement and when sending as message text |
|
198 HBufC8* temp = ConvertToUtf7LC(p); |
|
199 |
|
200 TUid mtmUid = iSelectedMtmUid; |
|
201 TSendingCapabilities capabilities; |
|
202 iSendUi->ServiceCapabilitiesL( mtmUid, capabilities ); |
|
203 if (capabilities.iFlags & TSendingCapabilities::ESupportsAttachments) |
|
204 { |
|
205 // send as Attachment |
|
206 RFs fs; |
|
207 User::LeaveIfError( fs.Connect() ); |
|
208 CleanupClosePushL( fs ); |
|
209 // must share the handle between processes |
|
210 User::LeaveIfError( fs.ShareProtected() ); |
|
211 TInt err = fs.MkDirAll(KRemoteDriveAttachmentFilename); |
|
212 RFile file; |
|
213 err = file.Replace(fs,KRemoteDriveAttachmentFilename,EFileWrite | EFileShareAny ); |
|
214 CleanupClosePushL(file); |
|
215 TInt spaceNeeded = vcal->Size(); |
|
216 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &fs, spaceNeeded ) ) |
|
217 { |
|
218 // don't show any own notes here |
|
219 User::Leave( KErrDiskFull ); |
|
220 } |
|
221 |
|
222 User::LeaveIfError(file.Write(*temp)); |
|
223 |
|
224 TParse parse; |
|
225 User::LeaveIfError(parse.SetNoWild(KRemoteDriveAttachmentFilename, |
|
226 NULL, NULL)); |
|
227 |
|
228 CMessageData* messageData = CMessageData::NewL(); |
|
229 CleanupStack::PushL( messageData ); |
|
230 messageData->AppendAttachmentHandleL(file); |
|
231 iSendUi->CreateAndSendMessageL( iSelectedMtmUid, messageData, KUidBIOMountConfMsg, ETrue ); |
|
232 |
|
233 CleanupStack::PopAndDestroy( 2 ); // messageData, file |
|
234 fs.Delete(parse.FullName()); |
|
235 CleanupStack::PopAndDestroy( &fs );; |
|
236 } |
|
237 else |
|
238 { |
|
239 // send as message body |
|
240 // message data interface is 16-bit |
|
241 // however, along the way 8-bit interface is used |
|
242 // to pass the data without safe conversion |
|
243 // so the unicode conversion above is still needed |
|
244 HBufC* bufCnv = HBufC::NewLC(temp->Length()); |
|
245 TPtr16 des(bufCnv->Des()); |
|
246 des.Copy(p); |
|
247 text->InsertL(0, des); |
|
248 |
|
249 CMessageData* messageData = CMessageData::NewL(); |
|
250 CleanupStack::PushL( messageData ); |
|
251 messageData->SetBodyTextL( text ); |
|
252 iSendUi->CreateAndSendMessageL( iSelectedMtmUid, messageData, KUidBIOMountConfMsg, ETrue ); |
|
253 CleanupStack::PopAndDestroy(2); // messageData, bufCnv |
|
254 } |
|
255 |
|
256 CleanupStack::PopAndDestroy(4); // entryToBeSent, text, vcal, temp |
|
257 |
|
258 } |
|
259 |
|
260 // ------------------------------------------------------------------------------------------------ |
|
261 // HBufC* CRsfwGsRemoteDriveSend::ConvertToUtf7LC |
|
262 // Encodes from Unicode UCS-2 to UTF-8 |
|
263 // ------------------------------------------------------------------------------------------------ |
|
264 HBufC8* CRsfwGsRemoteDriveSend::ConvertToUtf7LC(const TDesC16& aText) |
|
265 { |
|
266 TPtrC16 remainder( aText ); |
|
267 TBuf8<20> utfBuffer; |
|
268 HBufC8 *ret = 0; |
|
269 CBufFlat *buffer = CBufFlat::NewL( 128 ); |
|
270 CleanupStack::PushL( buffer ); |
|
271 |
|
272 TBool finish = EFalse; |
|
273 while( !finish ) |
|
274 { |
|
275 utfBuffer.Zero(); |
|
276 TInt unconverted = CnvUtfConverter::ConvertFromUnicodeToUtf7(utfBuffer, remainder, EFalse ); |
|
277 if( unconverted >= 0 ) |
|
278 { |
|
279 remainder.Set( remainder.Right( unconverted ) ); |
|
280 buffer->InsertL( buffer->Size(), utfBuffer ); |
|
281 finish = (unconverted == 0); |
|
282 } |
|
283 else |
|
284 { |
|
285 User::Leave( unconverted ); |
|
286 } |
|
287 } |
|
288 |
|
289 buffer->Compress(); |
|
290 ret = buffer->Ptr( 0 ).Alloc(); |
|
291 CleanupStack::PopAndDestroy( buffer ); |
|
292 CleanupStack::PushL( ret ); |
|
293 return ret; |
|
294 } |
|
295 |
|
296 |
|
297 |
|
298 // end of file |
|