homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hspreviewhswidgetstate.cpp
changeset 69 87476091b3f5
parent 63 52b0f64eeb51
child 71 1db7cc813a4e
equal deleted inserted replaced
67:474929a40a0f 69:87476091b3f5
    13 *
    13 *
    14 * Description:  Menu Application Library state.
    14 * Description:  Menu Application Library state.
    15  *
    15  *
    16 */
    16 */
    17 
    17 
    18 
       
    19 #include <hblabel.h>
    18 #include <hblabel.h>
    20 #include <hbmessagebox.h>
    19 #include <hbmessagebox.h>
    21 #include <qstatemachine.h>
    20 #include <qstatemachine.h>
    22 #include <hbaction.h>
    21 #include <hbaction.h>
    23 #include <HbDocumentLoader>
    22 #include <HbDocumentLoader>
    38 #include "hsmenudialogfactory.h"
    37 #include "hsmenudialogfactory.h"
    39 #include "hsapp_defs.h"
    38 #include "hsapp_defs.h"
    40 #include "hsscene.h"
    39 #include "hsscene.h"
    41 #include "hspage.h"
    40 #include "hspage.h"
    42 
    41 
       
    42 
    43 #include "canotifier.h"
    43 #include "canotifier.h"
    44 #include "canotifierfilter.h"
    44 #include "canotifierfilter.h"
    45 #include "caservice.h"
    45 #include "caservice.h"
    46 #include "hsdomainmodel_global.h"
    46 #include "hsdomainmodel_global.h"
    47 #include <hscontentservice.h>
    47 #include <hscontentservice.h>
    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),
    66     mPreviewDialog(0),
    67     mNotifier(0),
       
    68     mEntryId(0),
    67     mEntryId(0),
    69     mCorruptedMessage(0),
    68     mCorruptedMessage(0),
       
    69     mConfirmRemovalAction(0),
       
    70     mAddToHomescreenAction(0),
    70     mToken(),
    71     mToken(),
    71     mUri()
    72     mUri()
    72 {
    73 {
    73     setObjectName("/HsPreviewHSWidgetState");
    74     setObjectName("/HsPreviewHSWidgetState");
    74     if (this->parent()) {
    75     if (this->parent()) {
   110         
   111         
   111     QSharedPointer<CaEntry> entry =
   112     QSharedPointer<CaEntry> entry =
   112         CaService::instance()->getEntry(mEntryId);
   113         CaService::instance()->getEntry(mEntryId);
   113     mUri = entry->attribute(widgetUriAttributeName());
   114     mUri = entry->attribute(widgetUriAttributeName());
   114     mPreviewDialog = buildPreviewDialog(*entry);
   115     mPreviewDialog = buildPreviewDialog(*entry);
   115 
   116     mAddToHomescreenAction = mPreviewDialog->actions().value(0);
       
   117     
   116     if (mPreviewDialog != NULL) {
   118     if (mPreviewDialog != NULL) {
   117         subscribeForMemoryCardRemove();
       
   118         // Launch popup asyncronously
   119         // Launch popup asyncronously
       
   120         
       
   121         mEntryObserver.reset(
       
   122             new HsMenuEntryRemovedHandler(mEntryId, this, SIGNAL(exit())));
       
   123         
   119         mPreviewDialog->open(this, SLOT(previewDialogFinished(HbAction*)));
   124         mPreviewDialog->open(this, SLOT(previewDialogFinished(HbAction*)));
   120     }
   125     }
   121 
   126 
   122     HSMENUTEST_FUNC_EXIT("HsPreviewHSWidgetState::onEntry");
   127     HSMENUTEST_FUNC_EXIT("HsPreviewHSWidgetState::onEntry");
   123 }
   128 }
   126  Slot launched after state has exited and in destructor.
   131  Slot launched after state has exited and in destructor.
   127  \retval void
   132  \retval void
   128  */
   133  */
   129 void HsPreviewHSWidgetState::cleanUp()
   134 void HsPreviewHSWidgetState::cleanUp()
   130 {
   135 {
   131     // Close popups if App key was pressed or memory card removed
   136     if (mPreviewDialog != NULL) {
   132     if (mPreviewDialog) {
       
   133         disconnect(mPreviewDialog, SIGNAL(finished(HbAction*)), 
       
   134             this, SLOT(previewDialogFinished(HbAction*)));
       
   135         mPreviewDialog->close();
   137         mPreviewDialog->close();
   136         mPreviewDialog = NULL;
   138         mPreviewDialog = NULL;
   137     }
   139     }
   138 
   140     
   139     if (mCorruptedMessage) {
   141     if (mCorruptedMessage != NULL) {
   140         disconnect(mCorruptedMessage, SIGNAL(finished(HbAction*)), 
       
   141             this, SLOT(messageWidgetCorruptedFinished(HbAction*)));
       
   142         mCorruptedMessage->close();
   142         mCorruptedMessage->close();
   143         mCorruptedMessage = NULL;
   143         mCorruptedMessage = NULL;
   144     }
   144     }
   145 
   145     mEntryObserver.reset(0);
   146     mToken = NULL;
   146     mToken = NULL;
   147 
       
   148     disconnect(mNotifier,
       
   149                SIGNAL(entryChanged(CaEntry,ChangeType)),
       
   150                this, SIGNAL(exit()));
       
   151 
       
   152     delete mNotifier;
       
   153     mNotifier = NULL;
       
   154 }
   147 }
   155 
   148 
   156 /*!
   149 /*!
   157  Slot launched on dismissing the preview dialog
   150  Slot launched on dismissing the preview dialog
   158  \retval void
   151  \retval void
   159  */
   152  */
   160 void HsPreviewHSWidgetState::previewDialogFinished(HbAction* finishedAction)
   153 void HsPreviewHSWidgetState::previewDialogFinished(HbAction* finishedAction)
   161 {
   154 {
   162     if (static_cast<QAction*>(finishedAction) == mPreviewDialog->actions().value(0)) {
   155     mPreviewDialog = NULL;
       
   156 
       
   157     if (finishedAction == mAddToHomescreenAction) {
   163 
   158 
   164         QVariantHash widgetData;
   159         QVariantHash widgetData;
   165         widgetData[URI] = mUri;
   160         widgetData[URI] = mUri;
   166         widgetData[HOMESCREENDATA] = mToken;
   161         widgetData[HOMESCREENDATA] = mToken;
   167         
   162         
   173             notificationDialog->setTitle(hbTrId("txt_applib_dpophead_added_to_homescreen"));
   168             notificationDialog->setTitle(hbTrId("txt_applib_dpophead_added_to_homescreen"));
   174             notificationDialog->show();
   169             notificationDialog->show();
   175             emit exit();
   170             emit exit();
   176         }
   171         }
   177         else {
   172         else {
   178             mPreviewDialog = NULL;
       
   179             showMessageWidgetCorrupted();            
   173             showMessageWidgetCorrupted();            
   180         }
   174         }
   181     } else {
   175     } else {
   182         emit exit();
   176         emit exit();
   183     }
   177     }
   184 }
   178     mAddToHomescreenAction = 0;
   185 
       
   186 /*!
       
   187  Subscribe for memory card remove.
       
   188  \retval void
       
   189  */
       
   190 void HsPreviewHSWidgetState::subscribeForMemoryCardRemove()
       
   191 {
       
   192     CaNotifierFilter filter;
       
   193     QList<int> entryIds;
       
   194     entryIds.append(mEntryId);
       
   195     filter.setIds(entryIds);
       
   196     mNotifier = CaService::instance()->createNotifier(filter);
       
   197     mNotifier->setParent(this);
       
   198     connect(mNotifier,
       
   199             SIGNAL(entryChanged(CaEntry,ChangeType)),
       
   200             SIGNAL(exit()));
       
   201 }
   179 }
   202 
   180 
   203 /*!
   181 /*!
   204  Shows message about corrupted widget library. Deletes widget eventually
   182  Shows message about corrupted widget library. Deletes widget eventually
   205  \retval void
   183  \retval void
   209     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
   187     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
   210 
   188 
   211     mCorruptedMessage = HsMenuDialogFactory().create(
   189     mCorruptedMessage = HsMenuDialogFactory().create(
   212             hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi"));
   190             hbTrId("txt_applib_dialog_file_corrupted_unable_to_use_wi"));
   213 
   191 
   214     mCorruptedMessage->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*)));
   192     mConfirmRemovalAction = mCorruptedMessage->actions().value(0);
       
   193     mCorruptedMessage
       
   194         ->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*)));
   215 
   195 
   216     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
   196     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
   217 }
   197 }
   218 
   198 
   219 /*!
   199 /*!
   220  Slot launched on dismissing the corrupted widget error note
   200  Slot launched on dismissing the corrupted widget error note
   221  \retval void
   201  \retval void
   222  */
   202  */
   223 void HsPreviewHSWidgetState::messageWidgetCorruptedFinished(HbAction* finishedAction)
   203 void HsPreviewHSWidgetState::messageWidgetCorruptedFinished(HbAction* finishedAction)
   224 {
   204 {
   225     if (static_cast<QAction*>(finishedAction) == mCorruptedMessage->actions().value(0)) {
   205     mCorruptedMessage = NULL;
       
   206 	
       
   207     if (static_cast<QAction*>(finishedAction) == mConfirmRemovalAction) {
   226         HsMenuService::executeAction(mEntryId, removeActionIdentifier());
   208         HsMenuService::executeAction(mEntryId, removeActionIdentifier());
   227     }
   209     }
   228     emit exit();
   210     emit exit();
       
   211     
       
   212     mConfirmRemovalAction = NULL;
   229 }
   213 }
   230 
   214 
   231 /*!
   215 /*!
   232  \param entry The entry which is to be presented by the preview dialog.
   216  \param entry The entry which is to be presented by the preview dialog.
   233  \return Preview popup for a given entry on success, NULL otherwise. 
   217  \return Preview popup for a given entry on success, NULL otherwise. 
   247         qobject_cast<HbLabel*>(
   231         qobject_cast<HbLabel*>(
   248             loader.findWidget(HS_WIDGET_PREVIEW_LABEL_NAME));
   232             loader.findWidget(HS_WIDGET_PREVIEW_LABEL_NAME));
   249     HbLabel *const iconBox =
   233     HbLabel *const iconBox =
   250         qobject_cast<HbLabel*>(
   234         qobject_cast<HbLabel*>(
   251             loader.findWidget(HS_WIDGET_PREVIEW_ICON_BOX_NAME));
   235             loader.findWidget(HS_WIDGET_PREVIEW_ICON_BOX_NAME));
   252     
   236 
   253     loadStatusOk = loadStatusOk && (previewDialog != NULL)
   237     loadStatusOk = loadStatusOk && (previewDialog != NULL)
   254         && (headingLabel != NULL) && (iconBox != NULL);
   238         && (headingLabel != NULL) && (iconBox != NULL);
   255     
   239     
   256     Q_ASSERT_X(loadStatusOk,
   240     Q_ASSERT_X(loadStatusOk,
   257         HS_WIDGET_PREVIEW_DIALOG_LAYOUT,
   241         HS_WIDGET_PREVIEW_DIALOG_LAYOUT,
   258            "Cannot initialize widgets based on docml file.");
   242            "Cannot initialize widgets based on docml file.");
   259     
   243     
   260     if (loadStatusOk) {
   244     if (loadStatusOk) {
   261         previewDialog->actions()[0]->setParent(previewDialog);
   245         previewDialog->actions().value(0)->setParent(previewDialog);
   262         previewDialog->actions()[1]->setParent(previewDialog);
   246         previewDialog->actions().value(1)->setParent(previewDialog);
   263         
   247         
   264         previewDialog->setTimeout(HbPopup::NoTimeout);
   248         previewDialog->setTimeout(HbPopup::NoTimeout);
   265         previewDialog->setAttribute(Qt::WA_DeleteOnClose, true);
   249         previewDialog->setAttribute(Qt::WA_DeleteOnClose, true);
   266         
   250         
   267         headingLabel->setPlainText(entry.text());
   251         headingLabel->setPlainText(entry.text());