|
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <eikenv.h> |
|
17 #include <msvapi.h> |
|
18 #include <mtclreg.h> |
|
19 #include <mtuireg.h> |
|
20 #include <mtclbase.h> |
|
21 #include <eikappui.h> |
|
22 #include <mturutils.h> |
|
23 #include "MTMUIBAS.H" |
|
24 #include "MTUDPAN.H" |
|
25 |
|
26 _LIT(KThreadName, "LaunchEditor"); |
|
27 const TInt KLaunchMinHeapSize=0x1000; |
|
28 const TInt KLaunchMaxHeapSize=0x80000; |
|
29 |
|
30 //********************************** |
|
31 // CMturEnv |
|
32 //********************************** |
|
33 |
|
34 class CMturEnv : public CEikonEnv |
|
35 { |
|
36 public: |
|
37 void DestroyEnvironment(); |
|
38 void ConstructL(); |
|
39 }; |
|
40 |
|
41 void CMturEnv::DestroyEnvironment() |
|
42 { |
|
43 CEikonEnv::DestroyEnvironment(); |
|
44 } |
|
45 |
|
46 void CMturEnv::ConstructL() |
|
47 { |
|
48 CEikonEnv::ConstructL(); |
|
49 SetAutoForwarding(ETrue); |
|
50 } |
|
51 |
|
52 //********************************** |
|
53 // CMturAppUi |
|
54 //********************************** |
|
55 |
|
56 class CMturAppUi : public CEikAppUi |
|
57 { |
|
58 public: |
|
59 ~CMturAppUi(); |
|
60 void ConstructL(); |
|
61 }; |
|
62 |
|
63 CMturAppUi::~CMturAppUi() |
|
64 { |
|
65 } |
|
66 |
|
67 void CMturAppUi::ConstructL() |
|
68 { |
|
69 CEikAppUi::BaseConstructL(ENoAppResourceFile); |
|
70 } |
|
71 |
|
72 //********************************** |
|
73 // CDummyObserver |
|
74 //********************************** |
|
75 |
|
76 class CDummyObserver : public CBase, public MMsvSessionObserver |
|
77 { |
|
78 public: |
|
79 void HandleSessionEventL(TMsvSessionEvent, TAny*, TAny*, TAny*) {}; |
|
80 }; |
|
81 |
|
82 //********************************** |
|
83 // Global |
|
84 //********************************** |
|
85 |
|
86 static void DoLaunchEditorL(TMsvId aId) |
|
87 { |
|
88 // Create an observer |
|
89 CDummyObserver* ob = new(ELeave)CDummyObserver; |
|
90 CleanupStack::PushL(ob); |
|
91 |
|
92 // Create a message server session |
|
93 CMsvSession* session = CMsvSession::OpenSyncL(*ob); |
|
94 CleanupStack::PushL(session); |
|
95 |
|
96 // Create a client registry |
|
97 CClientMtmRegistry* clientReg = CClientMtmRegistry::NewL(*session); |
|
98 CleanupStack::PushL(clientReg); |
|
99 |
|
100 // Create a client entry sitting on the message |
|
101 CMsvEntry* cEntry = CMsvEntry::NewL(*session, aId, TMsvSelectionOrdering()); |
|
102 CleanupStack::PushL(cEntry); |
|
103 |
|
104 // Create the required client Mtm |
|
105 CBaseMtm* client = clientReg->NewMtmL(cEntry->Entry().iMtm); |
|
106 CleanupStack::PushL(client); |
|
107 |
|
108 // Create a UI registry |
|
109 CMtmUiRegistry* uiReg = CMtmUiRegistry::NewL(*session); |
|
110 CleanupStack::PushL(uiReg); |
|
111 |
|
112 // Create the required UI |
|
113 CBaseMtmUi* ui = uiReg->NewMtmUiL(*client); |
|
114 CleanupStack::PushL(ui); |
|
115 |
|
116 // Give the client entry to the UI |
|
117 CleanupStack::Pop(); // cEntry |
|
118 client->SetCurrentEntryL(cEntry); |
|
119 |
|
120 // Start the waiter |
|
121 CMsvOperationWait* wait = CMsvOperationWait::NewLC(); |
|
122 wait->Start(); |
|
123 |
|
124 // Launch the editor |
|
125 CMsvOperation* op = NULL; |
|
126 TRAPD(error, op = ui->EditL(wait->iStatus)); |
|
127 if (error) |
|
128 { |
|
129 TRequestStatus* status = &(wait->iStatus); |
|
130 User::RequestComplete(status, KErrNone); |
|
131 } |
|
132 |
|
133 // Compete the operation |
|
134 CActiveScheduler::Start(); |
|
135 delete op; |
|
136 |
|
137 // Tidy up |
|
138 CleanupStack::Pop(7); // wait, ui, uiReg, client, clientReg, session, ob |
|
139 |
|
140 // Order of deletion is significant |
|
141 delete wait; |
|
142 delete ui; |
|
143 delete client; |
|
144 delete uiReg; |
|
145 delete clientReg; |
|
146 delete session; |
|
147 delete ob; |
|
148 } |
|
149 |
|
150 static TInt LaunchEditor(TMsvId aId) |
|
151 { |
|
152 TRAPD(error, DoLaunchEditorL(aId)); |
|
153 return error; |
|
154 } |
|
155 |
|
156 static TInt DoThreadStart(TAny* aParam) |
|
157 { |
|
158 CMturEnv* env = new CMturEnv; |
|
159 __ASSERT_ALWAYS(env, Panic(EMturThreadStartPanic1)); |
|
160 CMturAppUi* ui = new CMturAppUi; |
|
161 __ASSERT_ALWAYS(ui, Panic(EMturThreadStartPanic2)); |
|
162 |
|
163 TRAPD(error, env->ConstructL(); ui->ConstructL()); |
|
164 __ASSERT_ALWAYS(!error, Panic(EMturThreadStartPanic3)); |
|
165 env->DisableExitChecks(ETrue); |
|
166 |
|
167 LaunchEditor((TMsvId)aParam); |
|
168 |
|
169 ui->PrepareToExit(); |
|
170 env->DestroyEnvironment(); |
|
171 return KErrNone; |
|
172 } |
|
173 |
|
174 //********************************** |
|
175 // MturUtils |
|
176 //********************************** |
|
177 |
|
178 EXPORT_C void MturUtils::LaunchEditorL(TMsvId aId) |
|
179 { |
|
180 RThread thread; |
|
181 User::LeaveIfError(thread.Create(KThreadName, DoThreadStart, KDefaultStackSize, KLaunchMinHeapSize, KLaunchMaxHeapSize, (TAny*)aId, EOwnerThread)); |
|
182 thread.Resume(); |
|
183 thread.Close(); |
|
184 } |
|
185 |
|
186 EXPORT_C void MturUtils::LaunchEditorAndWaitL(TMsvId aId) |
|
187 { |
|
188 TRequestStatus aStatus; |
|
189 RThread thread; |
|
190 User::LeaveIfError(thread.Create(KThreadName, DoThreadStart, KDefaultStackSize, KLaunchMinHeapSize, KLaunchMaxHeapSize, (TAny*)aId, EOwnerThread)); |
|
191 thread.Logon(aStatus); |
|
192 thread.Resume(); |
|
193 User::WaitForRequest(aStatus); |
|
194 thread.Close(); |
|
195 } |
|
196 |
|
197 EXPORT_C void MturUtils::LaunchEditorL(TMsvId aId, RThread& aThread, TRequestStatus& aStatus) |
|
198 { |
|
199 User::LeaveIfError(aThread.Create(KThreadName, DoThreadStart, KDefaultStackSize, KLaunchMinHeapSize, KLaunchMaxHeapSize, (TAny*)aId, EOwnerThread)); |
|
200 aThread.Logon(aStatus); |
|
201 aThread.Resume(); |
|
202 } |