47 static const char caTypeWidget[] = "widget"; |
47 static const char caTypeWidget[] = "widget"; |
48 static const char caAttrView[] = "view"; |
48 static const char caAttrView[] = "view"; |
49 static const char caCmdClose[] = "close"; |
49 static const char caCmdClose[] = "close"; |
50 static const char caAttrWindowGroupId[] = "window_group_id"; |
50 static const char caAttrWindowGroupId[] = "window_group_id"; |
51 static const char caAttrComponentId[] = "component_id"; |
51 static const char caAttrComponentId[] = "component_id"; |
52 static const char caCmdRemove[] = "remove"; |
52 |
53 |
53 /*! |
54 // --------------------------------------------------------- |
54 * Command handler for application entries. |
55 // |
55 * |
56 // --------------------------------------------------------- |
56 * \lib caclient.lib |
57 // |
57 */ |
|
58 |
|
59 /*! |
|
60 * Constructor. |
|
61 */ |
58 CaAppHandler::CaAppHandler(QObject *parent): |
62 CaAppHandler::CaAppHandler(QObject *parent): |
59 iEikEnv(CEikonEnv::Static()), |
63 iEikEnv(CEikonEnv::Static()), |
60 iUsifUninstallOperation(NULL) |
64 iUsifUninstallOperation(NULL) |
61 { |
65 { |
62 Q_UNUSED(parent); |
66 Q_UNUSED(parent); |
63 } |
67 } |
64 |
68 |
65 // --------------------------------------------------------------------------- |
69 /*! |
66 // |
70 * Destructor. |
67 // --------------------------------------------------------------------------- |
71 */ |
68 // |
|
69 CaAppHandler::~CaAppHandler() |
72 CaAppHandler::~CaAppHandler() |
70 { |
73 { |
71 delete iUsifUninstallOperation; |
74 delete iUsifUninstallOperation; |
72 } |
75 } |
73 |
76 |
|
77 /*! |
|
78 * Execute a given command. |
|
79 * \param entry a reference to a CaEntry instance. |
|
80 * \param command a given command. |
|
81 * \retval an error code. |
|
82 */ |
74 int CaAppHandler::execute(const CaEntry &entry, const QString &command) |
83 int CaAppHandler::execute(const CaEntry &entry, const QString &command) |
75 { |
84 { |
76 int result(KErrGeneral); |
85 int result(KErrGeneral); |
77 if (command == caCmdOpen && entry.entryTypeName() == caTypeApp) { |
86 if (command == caCmdOpen && entry.entryTypeName() == caTypeApp) { |
78 QString viewIdValue = entry.attribute(caAttrView); |
87 QString viewIdValue = entry.attribute(caAttrView); |
102 } |
111 } |
103 |
112 |
104 return result; |
113 return result; |
105 } |
114 } |
106 |
115 |
107 // --------------------------------------------------------------------------- |
116 /*! |
108 // |
117 * Launch application |
109 // --------------------------------------------------------------------------- |
118 * \param uid UID of the application to launch. |
110 // |
119 * \param viewId id of the view the application is to start in. |
111 void CaAppHandler::launchApplicationL(const TUid aUid, TInt aViewId) |
120 */ |
112 { |
121 void CaAppHandler::launchApplicationL(const TUid uid, TInt viewId) |
113 if( aViewId > 0 && iEikEnv ) |
122 { |
114 { |
123 if (viewId > 0 && iEikEnv) { |
115 TUid viewId = TUid::Uid( aViewId ); |
124 TVwsViewId view(uid, TUid::Uid(viewId)); |
116 TVwsViewId view( aUid, viewId ); |
|
117 iEikEnv->EikAppUi()->ActivateViewL( view ); |
125 iEikEnv->EikAppUi()->ActivateViewL( view ); |
118 } |
126 } else { |
119 else |
|
120 { |
|
121 RWsSession wsSession; |
127 RWsSession wsSession; |
122 User::LeaveIfError( wsSession.Connect() ); |
128 User::LeaveIfError(wsSession.Connect()); |
123 CleanupClosePushL<RWsSession>( wsSession ); |
129 CleanupClosePushL<RWsSession>(wsSession); |
124 |
130 |
125 CCaTaskList* taskList = CCaTaskList::NewLC( wsSession ); |
131 CCaTaskList* taskList = CCaTaskList::NewLC(wsSession); |
126 TApaTask task = taskList->FindRootApp( aUid ); |
132 TApaTask task = taskList->FindRootApp(uid); |
127 CleanupStack::PopAndDestroy( taskList ); |
133 CleanupStack::PopAndDestroy(taskList); |
128 |
134 |
129 if( task.Exists() ) |
135 if (task.Exists()) { |
130 { |
|
131 task.BringToForeground(); |
136 task.BringToForeground(); |
132 } |
137 } else { |
133 else |
|
134 { |
|
135 // TApaAppInfo size is greater then 1024 bytes |
138 // TApaAppInfo size is greater then 1024 bytes |
136 // so its instances should not be created on the stack. |
139 // so its instances should not be created on the stack. |
137 TApaAppInfo* appInfo = new( ELeave ) TApaAppInfo; |
140 TApaAppInfo* appInfo = new(ELeave) TApaAppInfo; |
138 CleanupStack::PushL( appInfo ); |
141 CleanupStack::PushL(appInfo); |
139 TApaAppCapabilityBuf capabilityBuf; |
142 TApaAppCapabilityBuf capabilityBuf; |
140 RApaLsSession appArcSession; |
143 RApaLsSession appArcSession; |
141 User::LeaveIfError( appArcSession.Connect() ); |
144 User::LeaveIfError(appArcSession.Connect()); |
142 CleanupClosePushL<RApaLsSession>( appArcSession ); |
145 CleanupClosePushL<RApaLsSession>(appArcSession); |
143 |
146 |
144 User::LeaveIfError( appArcSession.GetAppInfo( *appInfo, aUid ) ); |
147 User::LeaveIfError(appArcSession.GetAppInfo(*appInfo, uid)); |
145 User::LeaveIfError( appArcSession.GetAppCapability( |
148 User::LeaveIfError(appArcSession.GetAppCapability( |
146 capabilityBuf, aUid ) ); |
149 capabilityBuf, uid)); |
147 |
150 |
148 TApaAppCapability &caps = capabilityBuf(); |
151 TApaAppCapability &caps = capabilityBuf(); |
149 CApaCommandLine *cmdLine = CApaCommandLine::NewLC(); |
152 CApaCommandLine *cmdLine = CApaCommandLine::NewLC(); |
150 cmdLine->SetExecutableNameL( appInfo->iFullName ); |
153 cmdLine->SetExecutableNameL(appInfo->iFullName); |
151 |
154 |
152 if( caps.iLaunchInBackground ) |
155 if (caps.iLaunchInBackground) { |
153 { |
156 cmdLine->SetCommandL(EApaCommandBackground); |
154 cmdLine->SetCommandL( EApaCommandBackground ); |
157 } else { |
155 } |
158 cmdLine->SetCommandL(EApaCommandRun); |
156 else |
159 } |
157 { |
160 |
158 cmdLine->SetCommandL( EApaCommandRun ); |
161 cmdLine->SetTailEndL(KNullDesC8); |
159 } |
162 |
160 |
163 User::LeaveIfError(appArcSession.StartApp(*cmdLine)); |
161 cmdLine->SetTailEndL( KNullDesC8 ); |
164 |
162 |
165 CleanupStack::PopAndDestroy(cmdLine); |
163 User::LeaveIfError( appArcSession.StartApp( *cmdLine ) ); |
166 CleanupStack::PopAndDestroy(&appArcSession); |
164 |
167 CleanupStack::PopAndDestroy(appInfo); |
165 CleanupStack::PopAndDestroy( cmdLine ); |
|
166 CleanupStack::PopAndDestroy( &appArcSession ); |
|
167 CleanupStack::PopAndDestroy( appInfo ); |
|
168 } |
168 } |
169 CleanupStack::PopAndDestroy( &wsSession ); |
169 CleanupStack::PopAndDestroy( &wsSession ); |
170 } |
170 } |
171 } |
171 } |
172 |
172 |
173 // --------------------------------------------------------------------------- |
173 /*! |
174 // |
174 * Closes application. |
175 // --------------------------------------------------------------------------- |
175 * \param flags an entry flags. |
176 // |
176 * \param windowGroupId window group id. |
|
177 * \retval an error code. |
|
178 */ |
177 int CaAppHandler::closeApplication(const EntryFlags &flags, int windowGroupId) |
179 int CaAppHandler::closeApplication(const EntryFlags &flags, int windowGroupId) |
178 { |
180 { |
179 int result(KErrNone); |
181 int result(KErrNone); |
180 if (flags.testFlag(RunningEntryFlag) |
182 if (flags.testFlag(RunningEntryFlag) && windowGroupId > 0) { |
181 && !( flags.testFlag(SystemEntryFlag)) |
|
182 && windowGroupId > 0) { |
|
183 RWsSession wsSession; |
183 RWsSession wsSession; |
184 result = wsSession.Connect(); |
184 result = wsSession.Connect(); |
185 if (result==KErrNone) { |
185 if (result==KErrNone) { |
186 TWsEvent event; |
186 TWsEvent event; |
187 event.SetTimeNow(); |
187 event.SetTimeNow(); |
188 event.SetType( KAknShutOrHideApp ); |
188 event.SetType(KAknShutOrHideApp); |
189 wsSession.SendEventToWindowGroup( windowGroupId, event ); |
189 wsSession.SendEventToWindowGroup(windowGroupId, event); |
190 } |
190 } |
191 wsSession.Close(); |
191 wsSession.Close(); |
192 } |
192 } |
193 return result; |
193 return result; |
194 } |
194 } |
195 |
195 |
196 // --------------------------------------------------------------------------- |
196 /*! |
197 // |
197 * Uninstall application. |
198 // --------------------------------------------------------------------------- |
198 * \param flags flags of the application which is to uninstall. |
199 // |
199 * \param typeName type name of the entry. |
|
200 * \param componentId component id. |
|
201 * \retval an error code. |
|
202 */ |
200 int CaAppHandler::handleRemove(const EntryFlags &flags, |
203 int CaAppHandler::handleRemove(const EntryFlags &flags, |
201 const QString &typeName, |
204 const QString &typeName, |
202 const QString &componentId) |
205 const QString &componentId) |
203 { |
206 { |
204 int result(KErrNone); |
207 int result(KErrNone); |