homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hspreviewhswidgetstate.cpp
changeset 96 458d8c8d9580
parent 85 35368b604b28
equal deleted inserted replaced
92:6727c5d0afc7 96:458d8c8d9580
    32 #include "hsmenueventfactory.h"
    32 #include "hsmenueventfactory.h"
    33 #include "hsmenuservice.h"
    33 #include "hsmenuservice.h"
    34 #include "hswidgethost.h"
    34 #include "hswidgethost.h"
    35 #include "hspreviewhswidgetstate.h"
    35 #include "hspreviewhswidgetstate.h"
    36 #include "hsmenuevent.h"
    36 #include "hsmenuevent.h"
    37 #include "hsmenudialogfactory.h"
    37 #include "hsdialogcontroller.h"
    38 #include "hsapp_defs.h"
    38 #include "hsapp_defs.h"
    39 #include "hsscene.h"
    39 #include "hsscene.h"
    40 #include "hspage.h"
    40 #include "hspage.h"
    41 
    41 
    42 
    42 
    61  \param parent Parent state.
    61  \param parent Parent state.
    62  \retval void
    62  \retval void
    63  */
    63  */
    64 HsPreviewHSWidgetState::HsPreviewHSWidgetState(QState *parent) :
    64 HsPreviewHSWidgetState::HsPreviewHSWidgetState(QState *parent) :
    65     QState(parent),
    65     QState(parent),
    66     mPreviewDialog(0),
       
    67     mEntryId(0),
    66     mEntryId(0),
    68     mCorruptedMessage(0),
       
    69     mConfirmRemovalAction(0),
       
    70     mAddToHomescreenAction(0),
       
    71     mToken(),
    67     mToken(),
    72     mUri()
    68     mUri()
    73 {
    69 {
    74     setObjectName("/HsPreviewHSWidgetState");
    70     setObjectName("/HsPreviewHSWidgetState");
    75     if (this->parent()) {
    71     if (this->parent()) {
    81 /*!
    77 /*!
    82  Destructor.
    78  Destructor.
    83  */
    79  */
    84 HsPreviewHSWidgetState::~HsPreviewHSWidgetState()
    80 HsPreviewHSWidgetState::~HsPreviewHSWidgetState()
    85 {
    81 {
    86     cleanUp(); // in case of throw
    82     QT_TRY {
       
    83         emit exit();
       
    84     } QT_CATCH (...) {
       
    85     }
    87 }
    86 }
    88 
    87 
    89 /*!
    88 /*!
    90  onEntry method invoked on entering the state
    89  onEntry method invoked on entering the state
    91  Adds a widget or shortcut to the active page of home screen.
    90  Adds a widget or shortcut to the active page of home screen.
   110     
   109     
   111         
   110         
   112     QSharedPointer<CaEntry> entry =
   111     QSharedPointer<CaEntry> entry =
   113         CaService::instance()->getEntry(mEntryId);
   112         CaService::instance()->getEntry(mEntryId);
   114     mUri = entry->attribute(Hs::widgetUriAttributeName);
   113     mUri = entry->attribute(Hs::widgetUriAttributeName);
   115     mPreviewDialog = buildPreviewDialog(*entry);
   114     QScopedPointer<HbDialog> previewDialog(buildPreviewDialog(*entry));
   116     mAddToHomescreenAction = mPreviewDialog->actions().value(0);
   115     
   117     
   116     if (!previewDialog.isNull()) {
   118     if (mPreviewDialog != NULL) {
       
   119         // Launch popup asyncronously
   117         // Launch popup asyncronously
   120         
   118 
   121         mEntryObserver.reset(
   119 
   122             new HsMenuEntryRemovedHandler(mEntryId, this, SIGNAL(exit())));
   120         QScopedPointer<HsDialogController> dialogController(
   123         
   121                 new HsDialogController(previewDialog.take(),
   124         mPreviewDialog->open(this, SLOT(previewDialogFinished(HbAction*)));
   122                     HsMenuDialogFactory::acceptActionIndex(),
       
   123                     HsMenuDialogFactory::rejectActionIndex()));
       
   124 
       
   125         connect(dialogController.data(),
       
   126                 SIGNAL(acceptActionTriggered(QAction*)),
       
   127                 this,
       
   128                 SLOT(addToHomeScreen()));
       
   129 
       
   130         connect(dialogController.data(),
       
   131                 SIGNAL(dialogCompleted()),
       
   132                 this,
       
   133                 SIGNAL(exit()));
       
   134 
       
   135         // ensure dialog is dismissed on app key pressed
       
   136         connect(this, SIGNAL(exited()),
       
   137                 dialogController.data(),
       
   138                 SLOT(dismissDialog()));
       
   139 
       
   140         dialogController.take()->openDialog(mEntryId);
   125     }
   141     }
   126     
   142     
   127     HSMENUTEST_FUNC_EXIT("HsPreviewHSWidgetState::onEntry");
   143     HSMENUTEST_FUNC_EXIT("HsPreviewHSWidgetState::onEntry");
   128 }
   144 }
   129 
   145 
   130 /*!
   146 /*!
   131  Slot launched after state has exited and in destructor.
   147  Slot launched after state has exited and in destructor.
   132  \retval void
   148  \retval void
   133  */
   149  */
   134 void HsPreviewHSWidgetState::cleanUp()
   150 void HsPreviewHSWidgetState::cleanUp()
   135 {
   151 {  
   136     if (mPreviewDialog != NULL) {
       
   137         mPreviewDialog->disconnect();
       
   138         mPreviewDialog ->close();
       
   139         mPreviewDialog = NULL;
       
   140     }
       
   141     
       
   142     if (mCorruptedMessage != NULL) {
       
   143         mCorruptedMessage->disconnect();
       
   144         mCorruptedMessage->close();
       
   145         mCorruptedMessage = NULL;
       
   146     }
       
   147     
       
   148     mToken = NULL;
   152     mToken = NULL;
   149 }
   153 }
   150 
   154 
   151 /*!
   155 /*!
   152  Slot launched on dismissing the preview dialog
   156  Slot. Adds the entry controlled by the state to Home Screen.
   153  \retval void
   157  \retval void
   154  */
   158  */
   155 void HsPreviewHSWidgetState::previewDialogFinished(HbAction* finishedAction)
   159 void HsPreviewHSWidgetState::addToHomeScreen()
   156 {
   160 {
   157     mPreviewDialog = NULL;
   161     QVariantHash widgetData;
   158 
   162     widgetData[Hs::uri] = mUri;
   159     if (finishedAction == mAddToHomescreenAction) {
   163     widgetData[Hs::homescreenData] = mToken;
   160 
   164 
   161         QVariantHash widgetData;
   165     bool success = HsContentService::instance()->createWidget(widgetData);
   162         widgetData[Hs::uri] = mUri;
   166 
   163         widgetData[Hs::homescreenData] = mToken;
   167     if (success) {
   164         
   168         HbNotificationDialog *notificationDialog = new HbNotificationDialog();
   165         bool success = HsContentService::instance()->createWidget(widgetData);
   169         notificationDialog->setAttribute(Qt::WA_DeleteOnClose);
   166         
   170         notificationDialog->setTitle(hbTrId("txt_applib_dpophead_added_to_homescreen"));
   167         if (success) {
   171         notificationDialog->show();
   168             HbNotificationDialog *notificationDialog = new HbNotificationDialog();
   172     }
   169             notificationDialog->setAttribute(Qt::WA_DeleteOnClose);
   173     else {
   170             notificationDialog->setTitle(hbTrId("txt_applib_dpophead_added_to_homescreen"));
   174         showMessageWidgetCorrupted();
   171             notificationDialog->show();
   175     }
   172             emit exit();
       
   173         }
       
   174         else {
       
   175             showMessageWidgetCorrupted();            
       
   176         }
       
   177     } else {
       
   178         emit exit();
       
   179     }
       
   180     mAddToHomescreenAction = 0;
       
   181 }
   176 }
   182 
   177 
   183 /*!
   178 /*!
   184  Shows message about corrupted widget library. Deletes widget eventually
   179  Shows message about corrupted widget library. Deletes widget eventually
   185  \retval void
   180  \retval void
   186  */
   181  */
   187 void HsPreviewHSWidgetState::showMessageWidgetCorrupted()
   182 void HsPreviewHSWidgetState::showMessageWidgetCorrupted()
   188 {
   183 {
   189     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
   184     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
   190 
   185 
   191     mCorruptedMessage = HsMenuDialogFactory().create(
   186     QScopedPointer<HsDialogController> dialogController(
   192             hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi"));
   187             new HsDialogController(
   193 
   188                 hbTrId(
   194     mConfirmRemovalAction = mCorruptedMessage->actions().value(0);
   189                     "txt_applib_dialog_file_corrupted_unable_to_use_wi")));
   195     mCorruptedMessage
   190 
   196         ->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*)));
   191     connect(dialogController.data(),
       
   192             SIGNAL(acceptActionTriggered(QAction*)),
       
   193             this,
       
   194             SLOT(removeWidget()));
       
   195 
       
   196     connect(dialogController.data(),
       
   197             SIGNAL(dialogCompleted()),
       
   198             this,
       
   199             SIGNAL(exit()));
       
   200 
       
   201     // ensure dialog is dismissed on app key pressed
       
   202     connect(this, SIGNAL(exited()),
       
   203             dialogController.data(),
       
   204             SLOT(dismissDialog()));
       
   205 
       
   206     dialogController.take()->openDialog(mEntryId);
   197 
   207 
   198     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
   208     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
   199 }
   209 }
   200 
   210 
   201 /*!
   211 /*!
   202  Slot launched on dismissing the corrupted widget error note
   212  Slot. Removes the entry controlled by the state from App Library.
   203  \retval void
   213  \retval void
   204  */
   214  */
   205 void HsPreviewHSWidgetState::messageWidgetCorruptedFinished(HbAction* finishedAction)
   215 #ifdef COVERAGE_MEASUREMENT
   206 {
   216 #pragma CTC SKIP
   207     mCorruptedMessage = NULL;
   217 #endif //COVERAGE_MEASUREMENT
   208 	
   218 
   209     if (static_cast<QAction*>(finishedAction) == mConfirmRemovalAction) {
   219 void HsPreviewHSWidgetState::removeWidget()
   210         HsMenuService::executeAction(mEntryId, Hs::removeActionIdentifier);
   220 {
   211     }
   221     HsMenuService::executeAction(mEntryId, Hs::removeActionIdentifier);
   212     emit exit();
   222 }
   213     
   223 #ifdef COVERAGE_MEASUREMENT
   214     mConfirmRemovalAction = NULL;
   224 #pragma CTC ENDSKIP
   215 }
   225 #endif //COVERAGE_MEASUREMENT
   216 
   226 
   217 /*!
   227 /*!
   218  \param entry The entry which is to be presented by the preview dialog.
   228  \param entry The entry which is to be presented by the preview dialog.
   219  \return Preview popup for a given entry on success, NULL otherwise. 
   229  \return Preview popup for a given entry on success, NULL otherwise. 
   220   Ownership is passed to the caller.
   230   Ownership is passed to the caller.