homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsuninstallitemstate.cpp
changeset 77 4b195f3bea29
parent 61 2b1b11a301d2
child 85 35368b604b28
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
    22 #include <HbDocumentLoader>
    22 #include <HbDocumentLoader>
    23 #include <HbLabel>
    23 #include <HbLabel>
    24 #include <HbListView>
    24 #include <HbListView>
    25 #include <HbParameterLengthLimiter>
    25 #include <HbParameterLengthLimiter>
    26 
    26 
    27 
    27 #include <QScopedPointer>
    28 #include <QStandardItemModel>
    28 #include <QStandardItemModel>
    29 #include <QStandardItem>
    29 #include <QStandardItem>
    30 #include <casoftwareregistry.h>
    30 #include <casoftwareregistry.h>
    31 #include <caquery.h>
    31 #include <caquery.h>
    32 #include <canotifier.h>
    32 #include <canotifier.h>
    33 
    33 
    34 #include "hsuninstallitemstate.h"
    34 #include "hsuninstallitemstate.h"
    35 #include "hsmenuevent.h"
    35 #include "hsmenuevent.h"
    36 
    36 #include "hsmenudialogfactory.h"
       
    37 #include "hsmenuentryremovedhandler.h"
    37 /*!
    38 /*!
    38  \class HsUninstallItemState
    39  \class HsUninstallItemState
    39  \ingroup group_hsworkerstateplugin
    40  \ingroup group_hsworkerstateplugin
    40  \brief Uninstall Item State.
    41  \brief Uninstall Item State.
    41  Deletes app from collection.
    42  Deletes app from collection.
    46  \param parent Parent state.
    47  \param parent Parent state.
    47  */
    48  */
    48 HsUninstallItemState::HsUninstallItemState(QState *parent) :
    49 HsUninstallItemState::HsUninstallItemState(QState *parent) :
    49     QState(parent),
    50     QState(parent),
    50     mItemId(0),
    51     mItemId(0),
    51     mNotifier(NULL),
       
    52     mUninstallMessage(NULL),
    52     mUninstallMessage(NULL),
    53     mUninstallJavaMessage(NULL),
    53     mUninstallJavaMessage(NULL),
    54     mConfirmAction(NULL)
    54     mConfirmAction(NULL)
    55 {
    55 {
    56     construct();
    56     construct();
    72     setObjectName("/UninstallItemState");
    72     setObjectName("/UninstallItemState");
    73     if (this->parent()) {
    73     if (this->parent()) {
    74         setObjectName(this->parent()->objectName() + objectName());
    74         setObjectName(this->parent()->objectName() + objectName());
    75     }
    75     }
    76     connect(this, SIGNAL(exited()), SLOT(cleanUp()));
    76     connect(this, SIGNAL(exited()), SLOT(cleanUp()));
       
    77     
    77 }
    78 }
    78 
    79 
    79 /*!
    80 /*!
    80  Sets entry event.
    81  Sets entry event.
    81  \param event entry event.
    82  \param event entry event.
    96         createUninstallJavaMessage();
    97         createUninstallJavaMessage();
    97     } else {
    98     } else {
    98         // other
    99         // other
    99         createUninstallMessage();
   100         createUninstallMessage();
   100     }
   101     }
   101     
   102         
   102     subscribeForMemoryCardRemove();
       
   103 
       
   104     HSMENUTEST_FUNC_EXIT("HsUninstallItemState::onEntry");
   103     HSMENUTEST_FUNC_EXIT("HsUninstallItemState::onEntry");
   105 }
   104 }
   106 
   105 
   107 /*!
   106 /*!
   108  Action after closed confirmation dialog.
   107  Action after closed confirmation dialog.
   109  \param finishedAction chosen action.
   108  \param finishedAction chosen action.
   110  \retval void
   109  \retval void
   111  */
   110  */
   112 void HsUninstallItemState::uninstallMessageFinished(HbAction* finishedAction)
   111 void HsUninstallItemState::uninstallMessageFinished(HbAction* finishedAction)
   113 {
   112 {
   114     if (finishedAction == mConfirmAction) {
   113     if (static_cast<QAction*>(finishedAction) == mConfirmAction) {
   115         HsMenuService::executeAction(mItemId, removeActionIdentifier());
   114         HsMenuService::executeAction(mItemId, removeActionIdentifier());
   116     }
   115     }
       
   116     mConfirmAction = NULL;
       
   117     mUninstallMessage = NULL;
       
   118 	mUninstallJavaMessage = NULL;
   117     emit exit();
   119     emit exit();
   118 }
   120 }
   119 
   121 
   120 /*!
   122 /*!
   121  Return information about a component: component name, a list of names
   123  Return information about a component: component name, a list of names
   161         }
   163         }
   162     }
   164     }
   163     return retval;
   165     return retval;
   164 }
   166 }
   165 
   167 
   166 /*!
       
   167  Subscribe for memory card remove.
       
   168  */
       
   169 void HsUninstallItemState::subscribeForMemoryCardRemove()
       
   170 {
       
   171     CaNotifierFilter filter;
       
   172     filter.setIds(QList<int>() << mItemId);
       
   173     mNotifier = CaService::instance()->createNotifier(filter);
       
   174     mNotifier->setParent(this);
       
   175     connect(mNotifier,
       
   176         SIGNAL(entryChanged(CaEntry,ChangeType)),
       
   177         SIGNAL(exit()));
       
   178 }
       
   179 
   168 
   180 /*!
   169 /*!
   181  Slot launched after state has exited and in destructor.
   170  Slot launched after state has exited and in destructor.
   182  \retval void
   171  \retval void
   183  */
   172  */
   184 void HsUninstallItemState::cleanUp()
   173 void HsUninstallItemState::cleanUp()
   185 {
   174 {
   186     // Close messagebox if App key was pressed
   175     // Close messagebox if App key was pressed
   187     if (mUninstallMessage) {
   176     if (mUninstallMessage != NULL) {
   188         disconnect(mUninstallMessage, SIGNAL(finished(HbAction*)),
       
   189             this, SLOT(uninstallMessageFinished(HbAction*)));
       
   190         mUninstallMessage->close();
   177         mUninstallMessage->close();
   191         mUninstallMessage = NULL;
   178         mUninstallMessage = NULL;
   192     }
   179     }
   193     
   180     
   194     if (mUninstallJavaMessage) {
   181     if (mUninstallJavaMessage != NULL) {
   195         disconnect(mUninstallJavaMessage, SIGNAL(finished(HbAction*)), this, SLOT(uninstallMessageFinished(HbAction*)));
       
   196         mUninstallJavaMessage->close();
   182         mUninstallJavaMessage->close();
   197         mUninstallJavaMessage = NULL;
   183         mUninstallJavaMessage = NULL;
   198     }
   184     }
   199 
   185 
   200     delete mNotifier;
       
   201     mNotifier = NULL;
       
   202     mConfirmAction = NULL;
   186     mConfirmAction = NULL;
   203     mItemId = 0;
   187     mItemId = 0;
   204 }
   188 }
   205 
   189 
   206 /*!
   190 /*!
   224             HbParameterLengthLimiter("txt_applib_dialog_1_will_be_removed_from_phone_c").arg(
   208             HbParameterLengthLimiter("txt_applib_dialog_1_will_be_removed_from_phone_c").arg(
   225                 HsMenuService::getName(mItemId)));
   209                 HsMenuService::getName(mItemId)));
   226     }
   210     }
   227 
   211 
   228     // create and show message box
   212     // create and show message box
   229     mUninstallMessage = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   213     mUninstallMessage = HsMenuDialogFactory().create(message);
   230     mUninstallMessage->setAttribute(Qt::WA_DeleteOnClose);
   214     mConfirmAction = mUninstallMessage->actions().value(0);
   231 
   215     
   232     mUninstallMessage->setText(message);
   216     QScopedPointer<HsMenuEntryRemovedHandler> entryObserver(
   233 
   217         new HsMenuEntryRemovedHandler(mItemId, this, SIGNAL(exit())));
   234     mUninstallMessage->clearActions();
   218     entryObserver.take()->setParent(mUninstallMessage);
   235     mConfirmAction = new HbAction(hbTrId("txt_common_button_ok"),
   219     
   236             mUninstallMessage);
   220     mUninstallMessage->open(this, SLOT(uninstallMessageFinished(HbAction*)));
   237     mUninstallMessage->addAction(mConfirmAction);
   221 }
   238 
   222 
   239     HbAction *secondaryAction = new HbAction(hbTrId("txt_common_button_cancel"),
   223 /*!
   240             mUninstallMessage);
   224  Method create uninstall confirmation message.
   241     mUninstallMessage->addAction(secondaryAction);
   225  Used for java applications without deletion confirmation
       
   226  and with midlet name equal to app name
       
   227  \retval void
       
   228  */
       
   229 void HsUninstallItemState::createSimpleUninstallJavaMessage()
       
   230 {
       
   231     QString message;
       
   232     message.append(
       
   233         HbParameterLengthLimiter("txt_applib_dialog_1_will_be_removed_from_phone_c").arg(
       
   234             HsMenuService::getName(mItemId)));
       
   235 
       
   236     // create and show message box
       
   237     mUninstallMessage = HsMenuDialogFactory().create(message);
       
   238     
       
   239     QSharedPointer<CaEntry> entry = CaService::instance()->getEntry(mItemId);
       
   240     HbIcon icon = entry->makeIcon();
       
   241     mUninstallMessage->setIcon(icon);
       
   242     mConfirmAction = mUninstallMessage->actions().value(0);
       
   243 
       
   244     QScopedPointer<HsMenuEntryRemovedHandler> entryObserver(
       
   245         new HsMenuEntryRemovedHandler(mItemId, this, SIGNAL(exit())));
       
   246     entryObserver.take()->setParent(mUninstallMessage);
   242 
   247 
   243     mUninstallMessage->open(this, SLOT(uninstallMessageFinished(HbAction*)));
   248     mUninstallMessage->open(this, SLOT(uninstallMessageFinished(HbAction*)));
   244 }
   249 }
   245 
   250 
   246 /*!
   251 /*!
   249  */
   254  */
   250 void HsUninstallItemState::createUninstallJavaMessage()
   255 void HsUninstallItemState::createUninstallJavaMessage()
   251 {
   256 {
   252     HbDocumentLoader loader;
   257     HbDocumentLoader loader;
   253     bool loadStatusOk = false;
   258     bool loadStatusOk = false;
   254     mObjectList = loader.load(HS_UNINSTALL_DIALOG_LAYOUT, &loadStatusOk);
   259     loader.load(HS_UNINSTALL_DIALOG_LAYOUT, &loadStatusOk);
   255     
   260     
   256     Q_ASSERT_X(loadStatusOk,
   261     Q_ASSERT_X(loadStatusOk,
   257             HS_UNINSTALL_DIALOG_LAYOUT,
   262             HS_UNINSTALL_DIALOG_LAYOUT,
   258            "Error while loading docml file.");
   263            "Error while loading docml file.");
   259 
   264 
   261     QStringList applicationsNames;
   266     QStringList applicationsNames;
   262     QString detailsMessage;
   267     QString detailsMessage;
   263     getApplicationsNames(componentName, applicationsNames, detailsMessage);
   268     getApplicationsNames(componentName, applicationsNames, detailsMessage);
   264     
   269     
   265     QString section;
   270     QString section;
   266     if (applicationsNames.isEmpty() && detailsMessage.isEmpty()) {
   271     if (applicationsNames.isEmpty() && detailsMessage.isEmpty()) {        
   267         mDialogType = UninstallDialogDefinition01;
   272         createSimpleUninstallJavaMessage();        
   268         section = QString("uninstallDialogDefinition01");
   273     }
   269         mObjectList = loader.load(
   274     else {
       
   275         if ( (!applicationsNames.isEmpty()) && (!detailsMessage.isEmpty())) {
       
   276             mDialogType = UninstallDialogDefinition02;
       
   277             section = QString("uninstallDialogDefinition02");
       
   278             loader.load(
   270                 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk);
   279                 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk);
   271     } else if ( (!applicationsNames.isEmpty()) && (!detailsMessage.isEmpty())) {
   280         }
   272         mDialogType = UninstallDialogDefinition02;
   281         else if ( (!applicationsNames.isEmpty() && detailsMessage.isEmpty())) {
   273         section = QString("uninstallDialogDefinition02");
   282             mDialogType = UninstallDialogDefinition03;
   274         mObjectList = loader.load(
   283             section = QString("uninstallDialogDefinition03");
       
   284             loader.load(
   275                 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk);
   285                 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk);
   276     } else if ( (!applicationsNames.isEmpty() && detailsMessage.isEmpty())) {
   286         }
   277         mDialogType = UninstallDialogDefinition03;
   287         else if (applicationsNames.isEmpty() && (!detailsMessage.isEmpty())) {
   278         section = QString("uninstallDialogDefinition03");
   288             mDialogType = UninstallDialogDefinition04;
   279         mObjectList = loader.load(
   289             section = QString("uninstallDialogDefinition04");
       
   290             loader.load(
   280                 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk);
   291                 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk);
   281     } else if (applicationsNames.isEmpty()  && (!detailsMessage.isEmpty())) {
   292         }
   282         mDialogType = UninstallDialogDefinition04;
   293 
   283         section = QString("uninstallDialogDefinition04");
   294         mUninstallJavaMessage = qobject_cast<HbDialog*>(
   284         mObjectList = loader.load(
       
   285                 HS_UNINSTALL_DIALOG_LAYOUT, section, &loadStatusOk);
       
   286     }
       
   287  
       
   288     mUninstallJavaMessage = 
       
   289         qobject_cast<HbDialog*>(
       
   290             loader.findWidget(HS_UNINSTALL_DIALOG_NAME));
   295             loader.findWidget(HS_UNINSTALL_DIALOG_NAME));
   291     
   296 
   292     HbLabel* iconLabel = 
   297         if (mUninstallJavaMessage) {
   293         qobject_cast<HbLabel*>(
   298             mUninstallJavaMessage->setAttribute(Qt::WA_DeleteOnClose);
   294             loader.findWidget(HS_UNINSTALL_DIALOG_CONFIRMATION_DIALOG_ICON));
   299             mUninstallJavaMessage->setTimeout(HbPopup::NoTimeout);
   295     QSharedPointer<CaEntry> entry2 = CaService::instance()->getEntry(mItemId);
   300             mUninstallJavaMessage->actions()[0]->setParent(mUninstallJavaMessage);
   296     HbIcon icon = entry2->makeIcon();
   301             mUninstallJavaMessage->actions()[1]->setParent(mUninstallJavaMessage);
   297     iconLabel->setIcon(icon);
   302 
   298     
   303             HbLabel* iconLabel =
   299     HbLabel* textLabel = 
   304             qobject_cast<HbLabel*>(
   300         qobject_cast<HbLabel*>(
   305                 loader.findWidget(HS_UNINSTALL_DIALOG_CONFIRMATION_DIALOG_ICON));
   301             loader.findWidget(HS_UNINSTALL_DIALOG_CONFIRMATION_DIALOG_LABEL));
   306             QSharedPointer<CaEntry> entry2 = CaService::instance()->getEntry(mItemId);
   302     textLabel->setPlainText(textLabel->plainText().arg(componentName));
   307             HbIcon icon = entry2->makeIcon();
   303     
   308             iconLabel->setIcon(icon);
   304     HbLabel* detailsUninstalLabel;
   309 
   305     if ((mDialogType == UninstallDialogDefinition02) ||
   310             HbLabel* textLabel =
   306         (mDialogType == UninstallDialogDefinition04)) {
   311             qobject_cast<HbLabel*>(
   307         detailsUninstalLabel= qobject_cast<HbLabel*>(
   312                 loader.findWidget(HS_UNINSTALL_DIALOG_CONFIRMATION_DIALOG_LABEL));
   308                 loader.findWidget(HS_UNINSTALL_DIALOG_DELETE_LABEL));
   313             textLabel->setPlainText(textLabel->plainText().arg(componentName));
   309         detailsUninstalLabel->setPlainText(detailsMessage);
   314 
   310     }
   315             HbLabel* detailsUninstalLabel;
   311 
   316             if ((mDialogType == UninstallDialogDefinition02) ||
   312     HbLabel* listView;
   317                 (mDialogType == UninstallDialogDefinition04)) {
   313     QString applicationsList;
   318                 detailsUninstalLabel= qobject_cast<HbLabel*>(
   314     QString newLine("\n");
   319                     loader.findWidget(HS_UNINSTALL_DIALOG_DELETE_LABEL));
   315     if ((mDialogType == UninstallDialogDefinition02) ||
   320                 detailsUninstalLabel->setPlainText(detailsMessage);
   316         (mDialogType == UninstallDialogDefinition03)) {
   321             }
   317         listView = qobject_cast<HbLabel*>(
   322 
   318                 loader.findWidget(HS_UNINSTALL_DIALOG_LIST_VIEW_LABEL));
   323             HbLabel* listView;
   319 
   324             QString applicationsList;
   320         for (int i=0; i<applicationsNames.count(); i++) {
   325             QString newLine("\n");
   321             applicationsList = applicationsList + applicationsNames[i] + newLine;
   326             if ((mDialogType == UninstallDialogDefinition02) ||
   322         }
   327                 (mDialogType == UninstallDialogDefinition03)) {
   323         listView->setPlainText(applicationsList);
   328                 listView = qobject_cast<HbLabel*>(
   324     }
   329                     loader.findWidget(HS_UNINSTALL_DIALOG_LIST_VIEW_LABEL));
   325 
   330 
   326     mUninstallJavaMessage->setAttribute(Qt::WA_DeleteOnClose);
   331                 for (int i=0; i<applicationsNames.count(); i++) {
   327     mUninstallJavaMessage->setTimeout(HbPopup::NoTimeout);
   332                     applicationsList = applicationsList + applicationsNames[i] + newLine;
   328     mConfirmAction = qobject_cast<HbAction*>(loader.findObject(
   333                 }
   329             HS_UNINSTALL_DIALOG_CONFIRMATION_ACTION));
   334                 listView->setPlainText(applicationsList);
   330     
   335             }
   331     mUninstallJavaMessage->open(this, SLOT(uninstallMessageFinished(HbAction*)));
   336 
   332 }
   337             mConfirmAction = qobject_cast<HbAction*>(loader.findObject(
       
   338                     HS_UNINSTALL_DIALOG_CONFIRMATION_ACTION));
       
   339         
       
   340             QScopedPointer<HsMenuEntryRemovedHandler> entryObserver(
       
   341                 new HsMenuEntryRemovedHandler(mItemId, this, SIGNAL(exit())));
       
   342             entryObserver.take()->setParent(mUninstallJavaMessage);
       
   343             
       
   344             mUninstallJavaMessage->open(this, SLOT(uninstallMessageFinished(HbAction*)));
       
   345         }
       
   346     }
       
   347 }