homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hspreviewhswidgetstate.cpp
changeset 46 23b5d6a29cce
parent 39 4e8ebe173323
child 55 03646e8da489
--- a/homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hspreviewhswidgetstate.cpp	Mon May 03 12:24:59 2010 +0300
+++ b/homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hspreviewhswidgetstate.cpp	Fri May 14 15:43:04 2010 +0300
@@ -27,6 +27,7 @@
 #include <hbscrollarea.h>
 #include <hbscrollbar.h>
 #include <QtAlgorithms>
+#include <hbnotificationdialog.h>
 
 #include "hsmenueventfactory.h"
 #include "hsmenuservice.h"
@@ -48,6 +49,15 @@
 const char HS_PREVIEW_HS_WIDGET_STATE[] = "HsPreviewHSWidgetState";
 
 /*!
+ \class HsPreviewHSWidgetState
+ \ingroup group_hsworkerstateplugin
+ \brief Application Library State.
+ Parent state for Application Library functionality (browsing applications and collections)
+ \see StateMachine
+ \lib ?library
+ */
+
+/*!
  Constructor
  \param parent: parent state
  \retval void
@@ -58,9 +68,11 @@
     mNotifier(0),
     mScrollArea(0),
     mWidget(0),
-    mEntryId(0)
+    mEntryId(0),
+    mCorruptedMessage(0)
 {
     requestServices(QList<QVariant> () << CONTENT_SERVICE_KEY);
+    connect(this, SIGNAL(exited()), SLOT(cleanUp()));
 }
 
 /*!
@@ -68,9 +80,7 @@
  */
 HsPreviewHSWidgetState::~HsPreviewHSWidgetState()
 {
-    if (mNotifier) {
-        delete mNotifier;
-    }
+    cleanUp(); // in case of throw
 }
 
 /*!
@@ -124,8 +134,8 @@
                 loader.findWidget(HS_WIDGET_PREVIEW_SCROLL_AREA_NAME));
 
         // set parent to actions to delete them together with dialog
-        mPopupDialog->primaryAction()->setParent(mPopupDialog);
-        mPopupDialog->secondaryAction()->setParent(mPopupDialog);
+        mPopupDialog->actions()[0]->setParent(mPopupDialog);
+        mPopupDialog->actions()[1]->setParent(mPopupDialog);
 
         if (mPopupDialog != NULL && mScrollArea != NULL) {
             mPopupDialog->setContentWidget(mScrollArea); // ownership transferred
@@ -153,6 +163,33 @@
 #pragma CTC ENDSKIP
 #endif //COVERAGE_MEASUREMENT
 
+/*!
+ Slot launched after state has exited and in destructor.
+ \retval void
+ */
+void HsPreviewHSWidgetState::cleanUp()
+{
+    // Close popups if App key was pressed
+    if (mPopupDialog) {
+        mPopupDialog->close();
+    }
+
+    if (mCorruptedMessage) {
+        mCorruptedMessage->close();
+    }
+
+    mPopupDialog = NULL;
+    mScrollArea = NULL;
+    mWidget = NULL;
+    mCorruptedMessage = NULL;
+
+    disconnect(mNotifier,
+               SIGNAL(entryChanged(CaEntry,ChangeType)),
+               this, SLOT(memoryCardRemoved()));
+
+    delete mNotifier;
+    mNotifier = NULL;
+}
 
 /*!
  Memory card with instaled widget was removed.
@@ -163,6 +200,8 @@
     if (mPopupDialog) {
         mPopupDialog->close();
     }
+    // exit not needed, it is called after dialog closed
+
 }
 
 /*!
@@ -173,30 +212,26 @@
 {
     if (mPopupDialog != NULL) { 
         // (work-around for crash if more then one action is selected in HbDialog)
-        disconnect(mNotifier,
-                   SIGNAL(entryChanged(CaEntry,ChangeType)),
-                   this, SLOT(memoryCardRemoved()));
-
-        if (finishedAction == mPopupDialog->primaryAction()) {
+        if (finishedAction == mPopupDialog->actions().value(0)) {
             mWidget->hideWidget();
             mScrollArea->takeContentWidget();
             HsScene::instance()->activePage()->addNewWidget(
                 mWidget); // ownership transferred
+            HbNotificationDialog *notificationDialog = new HbNotificationDialog();
+            notificationDialog->setAttribute(Qt::WA_DeleteOnClose);
+            notificationDialog->setTitle(hbTrId(
+                                         "txt_applib_dpophead_added_to_homescreen") );
+            notificationDialog->show();
         } else {
             mWidget->uninitializeWidget();
             mWidget->deleteFromDatabase();
         }
         mPopupDialog = NULL;
-        mScrollArea = NULL;
-        mWidget = NULL;
-
-        delete mNotifier;
-        mNotifier = NULL;
-
+        emit exit();
     } else {
         // (work-around for crash if more then one action is selected in HbDialog)
         qWarning("Another signal finished was emited.");
-        }
+    }
 }
 
 
@@ -230,25 +265,40 @@
 {
     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
 
+    mCorruptedMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
+    mCorruptedMessage->setAttribute(Qt::WA_DeleteOnClose);
+
     QString message(hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi"));
-    HbMessageBox::question(message, this,
-                SLOT(messageWidgetCorruptedFinished(HbAction*)),
-                hbTrId("txt_common_button_ok"), hbTrId("txt_common_button_cancel"));
+    mCorruptedMessage->setText(message);
 
+	mCorruptedMessage->clearActions();
+    HbAction *primaryAction = new HbAction(hbTrId("txt_common_button_ok"), mCorruptedMessage);
+	mCorruptedMessage->addAction(primaryAction);
+
+    HbAction *secondaryAction = new HbAction(hbTrId("txt_common_button_cancel"), mCorruptedMessage);
+    mCorruptedMessage->addAction(secondaryAction);
+
+    mCorruptedMessage->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*)));
     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
 }
 #ifdef COVERAGE_MEASUREMENT
 #pragma CTC ENDSKIP
 #endif //COVERAGE_MEASUREMENT
 
-
 /*!
  Slot launched on dismissing the corrupted widget error note
  \retval void
  */
 void HsPreviewHSWidgetState::messageWidgetCorruptedFinished(HbAction* finishedAction)
 {
-    if (finishedAction && qobject_cast<HbMessageBox*>(finishedAction->parent())->primaryAction() == finishedAction) {
-        HsMenuService::executeAction(mEntryId, removeActionIdentifier());
+    if (mCorruptedMessage) {
+        if (finishedAction == mCorruptedMessage->actions().value(0)) {
+            HsMenuService::executeAction(mEntryId, removeActionIdentifier());
+        }
+        mCorruptedMessage = NULL;
+        emit exit();
+    } else {
+        // (work-around for crash if more then one action is selected in HbDialog)
+        qWarning("Another signal finished was emited.");
     }
 }