equal
deleted
inserted
replaced
113 bool RegionUpdateFilter::eventFilter(QObject* obj, QEvent *event) |
113 bool RegionUpdateFilter::eventFilter(QObject* obj, QEvent *event) |
114 { |
114 { |
115 if (event->type() == QEvent::QEvent::GraphicsSceneResize) { |
115 if (event->type() == QEvent::QEvent::GraphicsSceneResize) { |
116 HbPopup *popup = qobject_cast<HbPopup*>(obj); |
116 HbPopup *popup = qobject_cast<HbPopup*>(obj); |
117 if (popup) { |
117 if (popup) { |
118 QRectF rect = popup->rect(); |
118 QRectF rect = popup->mapToScene(popup->rect()).boundingRect(); |
119 rect.moveTo(popup->pos()); |
119 rect = mDeviceDialogManger->mMainWindow->mapFromScene(rect).boundingRect(); |
120 HbDeviceDialogsContainer::Dialog & dialog = mDeviceDialogManger->mDialogs.find(popup); |
120 HbDeviceDialogsContainer::Dialog & dialog = mDeviceDialogManger->mDialogs.find(popup); |
121 mDeviceDialogManger->addRegionRect(dialog.id(), rect); |
121 mDeviceDialogManger->addRegionRect(dialog.id(), rect); |
122 } |
122 } |
123 } |
123 } |
124 return false; |
124 return false; |
238 int HbDeviceDialogManagerPrivate::showDeviceDialog( |
238 int HbDeviceDialogManagerPrivate::showDeviceDialog( |
239 HbDeviceDialogServer::DialogParameters ¶meters) |
239 HbDeviceDialogServer::DialogParameters ¶meters) |
240 { |
240 { |
241 TRACE_ENTRY |
241 TRACE_ENTRY |
242 |
242 |
|
243 parameters.mError = HbDeviceDialogNoError; |
243 int id = 0; |
244 int id = 0; |
244 |
245 |
245 HbDeviceDialogPlugin::DeviceDialogInfo info; |
246 HbDeviceDialogPlugin::DeviceDialogInfo info; |
246 memset(&info, 0, sizeof(info)); |
247 memset(&info, 0, sizeof(info)); |
247 HbPopup *popup = 0; |
248 HbPopup *popup = 0; |
288 TRACE_ENTRY |
289 TRACE_ENTRY |
289 int ret = HbDeviceDialogNotFoundError; |
290 int ret = HbDeviceDialogNotFoundError; |
290 HbDeviceDialogsContainer::Dialog &dialog = mDialogs.find(id); |
291 HbDeviceDialogsContainer::Dialog &dialog = mDialogs.find(id); |
291 if (dialog.isValid()) { |
292 if (dialog.isValid()) { |
292 HbDeviceDialogInterface *interface = dialog.widget(); |
293 HbDeviceDialogInterface *interface = dialog.widget(); |
293 bool success = interface->setDeviceDialogParameters(parameters); |
294 bool success = false; |
294 if (!success) { |
295 bool catched = false; |
|
296 try { |
|
297 success = interface->setDeviceDialogParameters(parameters); |
|
298 } catch (const std::bad_alloc &) { |
|
299 catched = true; |
|
300 } |
|
301 if (catched) { |
|
302 ret = HbDeviceDialogGeneralError; |
|
303 } else if (!success) { |
295 ret = checkpluginerror(interface->deviceDialogError()); |
304 ret = checkpluginerror(interface->deviceDialogError()); |
296 } else { |
305 } else { |
297 ret = HbDeviceDialogNoError; |
306 ret = HbDeviceDialogNoError; |
298 } |
307 } |
299 } |
308 } |
312 if (dialog.isValid() && !(dialog.flags() & closeCalled)) { |
321 if (dialog.isValid() && !(dialog.flags() & closeCalled)) { |
313 dialog.setFlags(closeCalled); |
322 dialog.setFlags(closeCalled); |
314 if (!byClient) { |
323 if (!byClient) { |
315 dialog.setFlags(HbDeviceDialogsContainer::Dialog::ClosedByServer); |
324 dialog.setFlags(HbDeviceDialogsContainer::Dialog::ClosedByServer); |
316 } |
325 } |
317 dialog.widget()->closeDeviceDialog(byClient); |
326 ret = HbDeviceDialogNoError; |
|
327 try { |
|
328 dialog.widget()->closeDeviceDialog(byClient); |
|
329 } catch(const std::bad_alloc &) { |
|
330 ret = HbDeviceDialogGeneralError; |
|
331 } |
318 startHousekeeperTimer(); |
332 startHousekeeperTimer(); |
319 ret = HbDeviceDialogNoError; |
|
320 } |
333 } |
321 TRACE_EXIT |
334 TRACE_EXIT |
322 return ret; |
335 return ret; |
323 } |
336 } |
324 |
337 |
348 Activate indicator |
361 Activate indicator |
349 */ |
362 */ |
350 int HbDeviceDialogManagerPrivate::activateIndicator( |
363 int HbDeviceDialogManagerPrivate::activateIndicator( |
351 HbDeviceDialogServer::IndicatorParameters ¶meters) |
364 HbDeviceDialogServer::IndicatorParameters ¶meters) |
352 { |
365 { |
|
366 // In order to prevent dialogs/indicators trowing bad_alloc during execution, amount |
|
367 // of heap available is checked before activation is allowed. |
|
368 if (!heapAvailable(NormalLevelMinHeap)) { |
|
369 return HbDeviceDialogGeneralError; |
|
370 } |
353 QVariantMap credentials; |
371 QVariantMap credentials; |
354 addSecurityCredentials(parameters, credentials); |
372 addSecurityCredentials(parameters, credentials); |
355 int result = HbDeviceDialogNoError; |
373 int result = HbDeviceDialogNoError; |
356 mIndicatorPluginManager->addIndicator(parameters.mType, credentials, &result); |
374 mIndicatorPluginManager->addIndicator(parameters.mType, credentials, &result); |
357 if (result == HbDeviceDialogNoError) { |
375 if (result == HbDeviceDialogNoError) { |
459 void HbDeviceDialogManagerPrivate::resetWindowRegion() const |
477 void HbDeviceDialogManagerPrivate::resetWindowRegion() const |
460 { |
478 { |
461 RWindowBase *win = |
479 RWindowBase *win = |
462 static_cast<RWindowBase*>(mMainWindow->effectiveWinId()->DrawableWindow()); |
480 static_cast<RWindowBase*>(mMainWindow->effectiveWinId()->DrawableWindow()); |
463 if (win) { |
481 if (win) { |
464 RRegionBuf<1> windowRegion(QRectToTRect(mMainWindow->sceneRect())); |
482 RRegionBuf<1> windowRegion(QRectToTRect(mMainWindow->rect())); |
465 win->SetShape(windowRegion); |
483 win->SetShape(windowRegion); |
466 } |
484 } |
467 } |
485 } |
468 |
486 |
469 #else |
487 #else |
634 */ |
652 */ |
635 HbDeviceDialogInterface *HbDeviceDialogManagerPrivate::createDeviceDialog( |
653 HbDeviceDialogInterface *HbDeviceDialogManagerPrivate::createDeviceDialog( |
636 HbDeviceDialogServer::DialogParameters ¶meters, |
654 HbDeviceDialogServer::DialogParameters ¶meters, |
637 HbDeviceDialogPlugin::DeviceDialogInfo &deviceDialogInfo, HbPopup *&popup) |
655 HbDeviceDialogPlugin::DeviceDialogInfo &deviceDialogInfo, HbPopup *&popup) |
638 { |
656 { |
639 parameters.mError = HbDeviceDialogNoError; |
657 // In order to prevent a dialog trowing bad_alloc when it is executing, amount |
|
658 // of heap available is checked before new dialog is allowed. |
|
659 if (!heapAvailable(SecurityLevelMinHeap)) { |
|
660 parameters.mError = HbDeviceDialogGeneralError; |
|
661 return 0; |
|
662 } |
640 |
663 |
641 QString pluginFilePath; |
664 QString pluginFilePath; |
642 if (!mPluginManager.loadPlugin(parameters.mType, QString(), &pluginFilePath)) { |
665 if (!mPluginManager.loadPlugin(parameters.mType, QString(), &pluginFilePath)) { |
643 parameters.mError = HbDeviceDialogNotFoundError; |
666 parameters.mError = HbDeviceDialogNotFoundError; |
644 return 0; |
667 return 0; |
651 mPluginManager.unloadPlugin(pluginFilePath); |
674 mPluginManager.unloadPlugin(pluginFilePath); |
652 return 0; |
675 return 0; |
653 } |
676 } |
654 |
677 |
655 if (!checkDialogInfo(deviceDialogInfo)) { |
678 if (!checkDialogInfo(deviceDialogInfo)) { |
|
679 parameters.mError = HbDeviceDialogGeneralError; |
|
680 mPluginManager.unloadPlugin(pluginFilePath); |
|
681 return 0; |
|
682 } |
|
683 |
|
684 // Normal level device dialogs require bigger heap reserve in order to not to |
|
685 // block higher level dialogs. |
|
686 if (deviceDialogInfo.showLevel == HbDeviceDialogPlugin::NormalLevel && |
|
687 !heapAvailable(NormalLevelMinHeap)) { |
656 parameters.mError = HbDeviceDialogGeneralError; |
688 parameters.mError = HbDeviceDialogGeneralError; |
657 mPluginManager.unloadPlugin(pluginFilePath); |
689 mPluginManager.unloadPlugin(pluginFilePath); |
658 return 0; |
690 return 0; |
659 } |
691 } |
660 |
692 |
815 tmp = deviceDialogInfo.showLevel; |
847 tmp = deviceDialogInfo.showLevel; |
816 if (tmp > HbDeviceDialogPlugin::CriticalLevel) { |
848 if (tmp > HbDeviceDialogPlugin::CriticalLevel) { |
817 return false; |
849 return false; |
818 } |
850 } |
819 return true; |
851 return true; |
|
852 } |
|
853 |
|
854 // Check there is minimum amount of heap available |
|
855 bool HbDeviceDialogManagerPrivate::heapAvailable(int aBytes) |
|
856 { |
|
857 const int MaxFragments = 16; |
|
858 const int MinFragmentSize = 0x1000; // 4 kB |
|
859 int fragmentSize = aBytes / MaxFragments; |
|
860 if (fragmentSize < MinFragmentSize) { |
|
861 fragmentSize = MinFragmentSize; |
|
862 } |
|
863 char *fragments[MaxFragments]; |
|
864 memset(&fragments, 0, sizeof(fragments)); |
|
865 bool success = true; |
|
866 int i = 0; |
|
867 while(success && i < MaxFragments && aBytes >= 0) { |
|
868 try { |
|
869 fragments[i] = new char[fragmentSize]; |
|
870 } catch(const std::bad_alloc &) { |
|
871 success = false; |
|
872 } |
|
873 i++; |
|
874 aBytes -= fragmentSize; |
|
875 } |
|
876 for(--i; i >= 0; i--) { |
|
877 delete [] fragments[i]; |
|
878 } |
|
879 return success; |
820 } |
880 } |
821 |
881 |
822 // Called by device dialog widget to send some data to client. |
882 // Called by device dialog widget to send some data to client. |
823 void HbDeviceDialogManagerPrivate::deviceDialogUpdate(const QVariantMap &data) const |
883 void HbDeviceDialogManagerPrivate::deviceDialogUpdate(const QVariantMap &data) const |
824 { |
884 { |