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