homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsaddtohomescreenstate.cpp
changeset 62 341166945d65
parent 55 03646e8da489
child 63 52b0f64eeb51
equal deleted inserted replaced
57:2e2dc3d30ca8 62:341166945d65
    33 #include "caquery.h"
    33 #include "caquery.h"
    34 #include "hsmenuservice.h"
    34 #include "hsmenuservice.h"
    35 
    35 
    36 const char SHORTCUT_WIDGET_URI[] = "hsshortcutwidgetplugin";
    36 const char SHORTCUT_WIDGET_URI[] = "hsshortcutwidgetplugin";
    37 const char SHORTCUT_ID[] = "caEntryId";
    37 const char SHORTCUT_ID[] = "caEntryId";
    38 const char ADD_TO_HOMESCREEN_STATE[] = "AddToHomeScreenState";
    38 
    39 
    39 
    40 
    40 
    41 /*!
    41 /*!
    42  \class HsAddToHomeScreenState
    42  \class HsAddToHomeScreenState
    43  \ingroup group_hsmenustateplugin
    43  \ingroup group_hsmenustateplugin
    48  (browsing applications and collections)
    48  (browsing applications and collections)
    49  */
    49  */
    50 
    50 
    51 /*!
    51 /*!
    52  Constructor
    52  Constructor
    53  \param parent: parent state
    53  \param parent Parent state.
    54  \retval void
    54  \retval void
    55  */
    55  */
    56 HsAddToHomeScreenState::HsAddToHomeScreenState(QState *parent) :
    56 HsAddToHomeScreenState::HsAddToHomeScreenState(QState *parent) :
    57     HsMenuBaseState(ADD_TO_HOMESCREEN_STATE, parent), 
    57     QState(parent), 
    58     mCorruptedMessage(NULL), mConfirmAction(NULL),
    58     mCorruptedMessage(NULL), mConfirmAction(NULL),
    59     mMenuMode(NormalHsMenuMode),
    59     mMenuMode(NormalHsMenuMode),
    60     mNotifier(0)
    60     mNotifier(0)
    61 {
    61 {
    62     requestServices(QList<QVariant> () << SHORTCUT_SERVICE_KEY
    62     setObjectName("/AddToHomeScreenState");
    63                     << CONTENT_SERVICE_KEY);
    63     
       
    64     if (this->parent()) {
       
    65         setObjectName(this->parent()->objectName() + objectName());
       
    66     }
       
    67     
    64     connect(this, SIGNAL(exited()), SLOT(cleanUp()));
    68     connect(this, SIGNAL(exited()), SLOT(cleanUp()));
    65 }
    69 }
    66 
    70 
    67 /*!
    71 /*!
    68  Destructor. Empty one.
    72  Destructor. Empty one.
    84  \retval void
    88  \retval void
    85  */
    89  */
    86 void HsAddToHomeScreenState::onEntry(QEvent *event)
    90 void HsAddToHomeScreenState::onEntry(QEvent *event)
    87 {
    91 {
    88     HSMENUTEST_FUNC_ENTRY("HsAddToHomeScreenState::onEntry");
    92     HSMENUTEST_FUNC_ENTRY("HsAddToHomeScreenState::onEntry");
    89     HsMenuBaseState::onEntry(event);
    93     QState::onEntry(event);
    90     HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event);
    94     HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event);
    91     QVariantMap data = menuEvent->data();
    95     QVariantMap data = menuEvent->data();
    92 
    96 
    93     mEntryId = data.value(itemIdKey()).toInt();
    97     mEntryId = data.value(itemIdKey()).toInt();
    94     QSharedPointer<CaEntry> entry = CaService::instance()->getEntry(mEntryId);
    98     QSharedPointer<CaEntry> entry = CaService::instance()->getEntry(mEntryId);
    95     const QString entryTypeName = entry->entryTypeName();
    99     const QString entryTypeName = entry->entryTypeName();
    96     
   100     
    97     mMenuMode = static_cast<HsMenuMode>(data.value(menuModeType()).toInt());
   101     mMenuMode = static_cast<HsMenuMode>(data.value(menuModeType()).toInt());
       
   102     mToken = data.value(HOMESCREENDATA);
    98 
   103 
    99     bool success = false;
   104     bool success = false;
   100     if (entryTypeName == widgetTypeName()) {
   105     if (entryTypeName == widgetTypeName()) {
   101         const QString uri = entry->attribute(widgetUriAttributeName());
   106         const QString uri = entry->attribute(widgetUriAttributeName());
   102         success = addWidget(*contentService(), uri);
   107         success = addWidget(*HsContentService::instance(), uri);
   103         HsMenuService::touch(mEntryId);        
   108         HsMenuService::touch(mEntryId);        
   104     } else {
   109     } else {
   105         success = addApplication(*contentService(), *entry);
   110         success = addApplication(*HsContentService::instance(), *entry);
   106     }
   111     }
   107     
   112     
   108     if (success && (mMenuMode == NormalHsMenuMode)) {
   113     if (success && (mMenuMode == NormalHsMenuMode)) {
   109         HbNotificationDialog *notificationDialog = new HbNotificationDialog();
   114         HbNotificationDialog *notificationDialog = new HbNotificationDialog();
   110         notificationDialog->setAttribute(Qt::WA_DeleteOnClose);
   115         notificationDialog->setAttribute(Qt::WA_DeleteOnClose);
   130         const QString &uri)
   135         const QString &uri)
   131 {
   136 {
   132     HSMENUTEST_FUNC_ENTRY("HsAddToHomeScreenState::addWidget");
   137     HSMENUTEST_FUNC_ENTRY("HsAddToHomeScreenState::addWidget");
   133     QVariantHash params;
   138     QVariantHash params;
   134     params[URI] = uri;
   139     params[URI] = uri;
       
   140     params[HOMESCREENDATA] = mToken;
   135     bool success = contentService.createWidget(params);
   141     bool success = contentService.createWidget(params);
   136     if (!success) {
   142     if (!success) {
   137         subscribeForMemoryCardRemove();
   143         subscribeForMemoryCardRemove();
   138         showMessageWidgetCorrupted();
   144         showMessageWidgetCorrupted();
   139     } else {
   145     } else {
   151 /*!
   157 /*!
   152  Shows message about corrupted widget library. Deletes widget eventually
   158  Shows message about corrupted widget library. Deletes widget eventually
   153  \param itemId entryId of widget (needed to delete it)
   159  \param itemId entryId of widget (needed to delete it)
   154  \retval void
   160  \retval void
   155  */
   161  */
   156 #ifdef COVERAGE_MEASUREMENT
       
   157 #pragma CTC SKIP
       
   158 #endif //COVERAGE_MEASUREMENT
       
   159 void HsAddToHomeScreenState::showMessageWidgetCorrupted()
   162 void HsAddToHomeScreenState::showMessageWidgetCorrupted()
   160 {
   163 {
   161     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
   164     HSMENUTEST_FUNC_ENTRY("HsCollectionState::showMessageWidgetCorrupted");
   162 
   165 
   163     mCorruptedMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   166     mCorruptedMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   177 
   180 
   178     mCorruptedMessage->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*)));
   181     mCorruptedMessage->open(this, SLOT(messageWidgetCorruptedFinished(HbAction*)));
   179 
   182 
   180     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
   183     HSMENUTEST_FUNC_EXIT("HsCollectionState::showMessageWidgetCorrupted");
   181 }
   184 }
   182 #ifdef COVERAGE_MEASUREMENT
       
   183 #pragma CTC ENDSKIP
       
   184 #endif //COVERAGE_MEASUREMENT
       
   185 
   185 
   186 /*!
   186 /*!
   187  Slot launched on dismissing the corrupted widget error note
   187  Slot launched on dismissing the corrupted widget error note
   188  \retval void
   188  \retval void
   189  */
   189  */
   219                SIGNAL(entryChanged(CaEntry,ChangeType)),
   219                SIGNAL(entryChanged(CaEntry,ChangeType)),
   220                this, SLOT(memoryCardRemoved()));
   220                this, SLOT(memoryCardRemoved()));
   221 
   221 
   222     delete mNotifier;
   222     delete mNotifier;
   223     mNotifier = NULL;
   223     mNotifier = NULL;
       
   224     mToken = NULL;
   224 }
   225 }
   225 
   226 
   226 
   227 
   227 /*!
   228 /*!
   228  Adds a shortcut to active page of home screen
   229  Adds a shortcut to active page of home screen
   237     QVariantHash params;
   238     QVariantHash params;
   238     params[URI] = SHORTCUT_WIDGET_URI;
   239     params[URI] = SHORTCUT_WIDGET_URI;
   239     QVariantHash preferences;
   240     QVariantHash preferences;
   240     preferences[SHORTCUT_ID] = QString::number(mEntryId);
   241     preferences[SHORTCUT_ID] = QString::number(mEntryId);
   241     params[PREFERENCES] = preferences;
   242     params[PREFERENCES] = preferences;
       
   243     params[HOMESCREENDATA] = mToken;
   242     const bool result = contentService.createWidget(params);
   244     const bool result = contentService.createWidget(params);
   243     logActionResult("Adding shortcut", mEntryId, result);
   245     logActionResult("Adding shortcut", mEntryId, result);
   244     HSMENUTEST_FUNC_EXIT("HsAddToHomeScreenState::addShortcut");
   246     HSMENUTEST_FUNC_EXIT("HsAddToHomeScreenState::addShortcut");
   245     return result;
   247     return result;
   246 }
   248 }
   271             if (key.contains(widgetParam())) {
   273             if (key.contains(widgetParam())) {
   272                 preferences.insert(key.remove(widgetParam()),value);
   274                 preferences.insert(key.remove(widgetParam()),value);
   273             }
   275             }
   274         }
   276         }
   275         params[PREFERENCES] = preferences;
   277         params[PREFERENCES] = preferences;
       
   278         params[HOMESCREENDATA] = mToken;
   276 
   279 
   277         success = contentService.createWidget(params);
   280         success = contentService.createWidget(params);
   278         if (!success) {
   281         if (!success) {
   279             success = addShortcut(contentService);
   282             success = addShortcut(contentService);
   280         }
   283         }