homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hspreviewhswidgetstate.cpp
changeset 46 23b5d6a29cce
parent 39 4e8ebe173323
child 55 03646e8da489
equal deleted inserted replaced
39:4e8ebe173323 46:23b5d6a29cce
    25 #include <hbdialog.h>
    25 #include <hbdialog.h>
    26 #include <hbwidget.h>
    26 #include <hbwidget.h>
    27 #include <hbscrollarea.h>
    27 #include <hbscrollarea.h>
    28 #include <hbscrollbar.h>
    28 #include <hbscrollbar.h>
    29 #include <QtAlgorithms>
    29 #include <QtAlgorithms>
       
    30 #include <hbnotificationdialog.h>
    30 
    31 
    31 #include "hsmenueventfactory.h"
    32 #include "hsmenueventfactory.h"
    32 #include "hsmenuservice.h"
    33 #include "hsmenuservice.h"
    33 #include "hswidgethost.h"
    34 #include "hswidgethost.h"
    34 #include "hspreviewhswidgetstate.h"
    35 #include "hspreviewhswidgetstate.h"
    46 
    47 
    47 
    48 
    48 const char HS_PREVIEW_HS_WIDGET_STATE[] = "HsPreviewHSWidgetState";
    49 const char HS_PREVIEW_HS_WIDGET_STATE[] = "HsPreviewHSWidgetState";
    49 
    50 
    50 /*!
    51 /*!
       
    52  \class HsPreviewHSWidgetState
       
    53  \ingroup group_hsworkerstateplugin
       
    54  \brief Application Library State.
       
    55  Parent state for Application Library functionality (browsing applications and collections)
       
    56  \see StateMachine
       
    57  \lib ?library
       
    58  */
       
    59 
       
    60 /*!
    51  Constructor
    61  Constructor
    52  \param parent: parent state
    62  \param parent: parent state
    53  \retval void
    63  \retval void
    54  */
    64  */
    55 HsPreviewHSWidgetState::HsPreviewHSWidgetState(QState *parent) :
    65 HsPreviewHSWidgetState::HsPreviewHSWidgetState(QState *parent) :
    56     HsMenuBaseState(HS_PREVIEW_HS_WIDGET_STATE, parent),
    66     HsMenuBaseState(HS_PREVIEW_HS_WIDGET_STATE, parent),
    57     mPopupDialog(0),
    67     mPopupDialog(0),
    58     mNotifier(0),
    68     mNotifier(0),
    59     mScrollArea(0),
    69     mScrollArea(0),
    60     mWidget(0),
    70     mWidget(0),
    61     mEntryId(0)
    71     mEntryId(0),
       
    72     mCorruptedMessage(0)
    62 {
    73 {
    63     requestServices(QList<QVariant> () << CONTENT_SERVICE_KEY);
    74     requestServices(QList<QVariant> () << CONTENT_SERVICE_KEY);
       
    75     connect(this, SIGNAL(exited()), SLOT(cleanUp()));
    64 }
    76 }
    65 
    77 
    66 /*!
    78 /*!
    67  Destructor.
    79  Destructor.
    68  */
    80  */
    69 HsPreviewHSWidgetState::~HsPreviewHSWidgetState()
    81 HsPreviewHSWidgetState::~HsPreviewHSWidgetState()
    70 {
    82 {
    71     if (mNotifier) {
    83     cleanUp(); // in case of throw
    72         delete mNotifier;
       
    73     }
       
    74 }
    84 }
    75 
    85 
    76 /*!
    86 /*!
    77  onEntry method invoked on entering the state
    87  onEntry method invoked on entering the state
    78  Adds a widget or shortcut to the active page of home screen.
    88  Adds a widget or shortcut to the active page of home screen.
   122         mScrollArea =
   132         mScrollArea =
   123             qobject_cast<HbScrollArea*>(
   133             qobject_cast<HbScrollArea*>(
   124                 loader.findWidget(HS_WIDGET_PREVIEW_SCROLL_AREA_NAME));
   134                 loader.findWidget(HS_WIDGET_PREVIEW_SCROLL_AREA_NAME));
   125 
   135 
   126         // set parent to actions to delete them together with dialog
   136         // set parent to actions to delete them together with dialog
   127         mPopupDialog->primaryAction()->setParent(mPopupDialog);
   137         mPopupDialog->actions()[0]->setParent(mPopupDialog);
   128         mPopupDialog->secondaryAction()->setParent(mPopupDialog);
   138         mPopupDialog->actions()[1]->setParent(mPopupDialog);
   129 
   139 
   130         if (mPopupDialog != NULL && mScrollArea != NULL) {
   140         if (mPopupDialog != NULL && mScrollArea != NULL) {
   131             mPopupDialog->setContentWidget(mScrollArea); // ownership transferred
   141             mPopupDialog->setContentWidget(mScrollArea); // ownership transferred
   132             mPopupDialog->setTimeout(HbPopup::NoTimeout);
   142             mPopupDialog->setTimeout(HbPopup::NoTimeout);
   133             mPopupDialog->setAttribute(Qt::WA_DeleteOnClose, true);
   143             mPopupDialog->setAttribute(Qt::WA_DeleteOnClose, true);
   151 }
   161 }
   152 #ifdef COVERAGE_MEASUREMENT
   162 #ifdef COVERAGE_MEASUREMENT
   153 #pragma CTC ENDSKIP
   163 #pragma CTC ENDSKIP
   154 #endif //COVERAGE_MEASUREMENT
   164 #endif //COVERAGE_MEASUREMENT
   155 
   165 
   156 
   166 /*!
   157 /*!
   167  Slot launched after state has exited and in destructor.
   158  Memory card with instaled widget was removed.
   168  \retval void
   159  \retval void
   169  */
   160  */
   170 void HsPreviewHSWidgetState::cleanUp()
   161 void HsPreviewHSWidgetState::memoryCardRemoved()
   171 {
   162 {
   172     // Close popups if App key was pressed
   163     if (mPopupDialog) {
   173     if (mPopupDialog) {
   164         mPopupDialog->close();
   174         mPopupDialog->close();
   165     }
   175     }
       
   176 
       
   177     if (mCorruptedMessage) {
       
   178         mCorruptedMessage->close();
       
   179     }
       
   180 
       
   181     mPopupDialog = NULL;
       
   182     mScrollArea = NULL;
       
   183     mWidget = NULL;
       
   184     mCorruptedMessage = NULL;
       
   185 
       
   186     disconnect(mNotifier,
       
   187                SIGNAL(entryChanged(CaEntry,ChangeType)),
       
   188                this, SLOT(memoryCardRemoved()));
       
   189 
       
   190     delete mNotifier;
       
   191     mNotifier = NULL;
       
   192 }
       
   193 
       
   194 /*!
       
   195  Memory card with instaled widget was removed.
       
   196  \retval void
       
   197  */
       
   198 void HsPreviewHSWidgetState::memoryCardRemoved()
       
   199 {
       
   200     if (mPopupDialog) {
       
   201         mPopupDialog->close();
       
   202     }
       
   203     // exit not needed, it is called after dialog closed
       
   204 
   166 }
   205 }
   167 
   206 
   168 /*!
   207 /*!
   169  Slot launched on dismissing the preview dialog
   208  Slot launched on dismissing the preview dialog
   170  \retval void
   209  \retval void
   171  */
   210  */
   172 void HsPreviewHSWidgetState::previewDialogFinished(HbAction* finishedAction)
   211 void HsPreviewHSWidgetState::previewDialogFinished(HbAction* finishedAction)
   173 {
   212 {
   174     if (mPopupDialog != NULL) { 
   213     if (mPopupDialog != NULL) { 
   175         // (work-around for crash if more then one action is selected in HbDialog)
   214         // (work-around for crash if more then one action is selected in HbDialog)
   176         disconnect(mNotifier,
   215         if (finishedAction == mPopupDialog->actions().value(0)) {
   177                    SIGNAL(entryChanged(CaEntry,ChangeType)),
       
   178                    this, SLOT(memoryCardRemoved()));
       
   179 
       
   180         if (finishedAction == mPopupDialog->primaryAction()) {
       
   181             mWidget->hideWidget();
   216             mWidget->hideWidget();
   182             mScrollArea->takeContentWidget();
   217             mScrollArea->takeContentWidget();
   183             HsScene::instance()->activePage()->addNewWidget(
   218             HsScene::instance()->activePage()->addNewWidget(
   184                 mWidget); // ownership transferred
   219                 mWidget); // ownership transferred
       
   220             HbNotificationDialog *notificationDialog = new HbNotificationDialog();
       
   221             notificationDialog->setAttribute(Qt::WA_DeleteOnClose);
       
   222             notificationDialog->setTitle(hbTrId(
       
   223                                          "txt_applib_dpophead_added_to_homescreen") );
       
   224             notificationDialog->show();
   185         } else {
   225         } else {
   186             mWidget->uninitializeWidget();
   226             mWidget->uninitializeWidget();
   187             mWidget->deleteFromDatabase();
   227             mWidget->deleteFromDatabase();
   188         }
   228         }
   189         mPopupDialog = NULL;
   229         mPopupDialog = NULL;
   190         mScrollArea = NULL;
   230         emit exit();
   191         mWidget = NULL;
       
   192 
       
   193         delete mNotifier;
       
   194         mNotifier = NULL;
       
   195 
       
   196     } else {
   231     } else {
   197         // (work-around for crash if more then one action is selected in HbDialog)
   232         // (work-around for crash if more then one action is selected in HbDialog)
   198         qWarning("Another signal finished was emited.");
   233         qWarning("Another signal finished was emited.");
   199         }
   234     }
   200 }
   235 }
   201 
   236 
   202 
   237 
   203 
   238 
   204 /*!
   239 /*!
   228 #endif //COVERAGE_MEASUREMENT
   263 #endif //COVERAGE_MEASUREMENT
   229 void HsPreviewHSWidgetState::showMessageWidgetCorrupted()
   264 void HsPreviewHSWidgetState::showMessageWidgetCorrupted()
   230 {
   265 {
   231     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
   266     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
   232 
   267 
       
   268     mCorruptedMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   269     mCorruptedMessage->setAttribute(Qt::WA_DeleteOnClose);
       
   270 
   233     QString message(hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi"));
   271     QString message(hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi"));
   234     HbMessageBox::question(message, this,
   272     mCorruptedMessage->setText(message);
   235                 SLOT(messageWidgetCorruptedFinished(HbAction*)),
   273 
   236                 hbTrId("txt_common_button_ok"), hbTrId("txt_common_button_cancel"));
   274 	mCorruptedMessage->clearActions();
   237 
   275     HbAction *primaryAction = new HbAction(hbTrId("txt_common_button_ok"), mCorruptedMessage);
       
   276 	mCorruptedMessage->addAction(primaryAction);
       
   277 
       
   278     HbAction *secondaryAction = new HbAction(hbTrId("txt_common_button_cancel"), mCorruptedMessage);
       
   279     mCorruptedMessage->addAction(secondaryAction);
       
   280 
       
   281     mCorruptedMessage->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*)));
   238     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
   282     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
   239 }
   283 }
   240 #ifdef COVERAGE_MEASUREMENT
   284 #ifdef COVERAGE_MEASUREMENT
   241 #pragma CTC ENDSKIP
   285 #pragma CTC ENDSKIP
   242 #endif //COVERAGE_MEASUREMENT
   286 #endif //COVERAGE_MEASUREMENT
   243 
   287 
   244 
       
   245 /*!
   288 /*!
   246  Slot launched on dismissing the corrupted widget error note
   289  Slot launched on dismissing the corrupted widget error note
   247  \retval void
   290  \retval void
   248  */
   291  */
   249 void HsPreviewHSWidgetState::messageWidgetCorruptedFinished(HbAction* finishedAction)
   292 void HsPreviewHSWidgetState::messageWidgetCorruptedFinished(HbAction* finishedAction)
   250 {
   293 {
   251     if (finishedAction && qobject_cast<HbMessageBox*>(finishedAction->parent())->primaryAction() == finishedAction) {
   294     if (mCorruptedMessage) {
   252         HsMenuService::executeAction(mEntryId, removeActionIdentifier());
   295         if (finishedAction == mCorruptedMessage->actions().value(0)) {
   253     }
   296             HsMenuService::executeAction(mEntryId, removeActionIdentifier());
   254 }
   297         }
       
   298         mCorruptedMessage = NULL;
       
   299         emit exit();
       
   300     } else {
       
   301         // (work-around for crash if more then one action is selected in HbDialog)
       
   302         qWarning("Another signal finished was emited.");
       
   303     }
       
   304 }