homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hscollectionnamestate.cpp
changeset 46 23b5d6a29cce
parent 39 4e8ebe173323
child 55 03646e8da489
equal deleted inserted replaced
39:4e8ebe173323 46:23b5d6a29cce
    29  \brief Rename Collection State.
    29  \brief Rename Collection State.
    30  Collection name state
    30  Collection name state
    31  */
    31  */
    32 
    32 
    33 /*!
    33 /*!
    34  \fn void commit(const QString &collectionName);
    34  \fn void HsCollectionNameState::commit(const QString &collectionName);
    35  Signal emitted when collection name is given.
    35  Signal emitted when collection name is given.
    36  \param collectionName name of collection.
    36  \param collectionName name of collection.
    37  */
    37  */
    38 
    38 
    39 /*!
    39 /*!
    40  \fn void commitCheckList(const QString &collectionName);
    40  \fn void HsCollectionNameState::commitCheckList(const QString &collectionName);
    41  Signal emitted when collection name is given - version to trigger
    41  Signal emitted when collection name is given - version to trigger
    42  transition to HsAppsCheckListState.
    42  transition to HsAppsCheckListState.
    43  \param collectionName name of collection.
    43  \param collectionName name of collection.
    44  */
    44  */
    45 
    45 
    46 /*!
    46 /*!
    47  \fn void cancel();
    47  \fn void HsCollectionNameState::cancel();
    48  Signal emitted when user selects cancel.
    48  Signal emitted when user selects cancel.
    49  */
    49  */
    50 
    50 
    51 /*!
    51 /*!
    52  Constructor
    52  Constructor
    53  \param parent owner
    53  \param parent owner
    54  \retval void
    54  \retval void
    55  */
    55  */
    56 HsCollectionNameState::HsCollectionNameState(QState *parent) :
    56 HsCollectionNameState::HsCollectionNameState(QState *parent) :
    57     QState(parent)
    57     QState(parent),
       
    58     mItemId(0), mCollectionNameDialog(NULL), mFinishedEntered(false)
    58 {
    59 {
    59     construct();
    60     construct();
    60 }
    61 }
    61 
    62 
    62 /*!
    63 /*!
    63  Destructor
    64  Destructor
    64  \retval void
    65  \retval void
    65  */
    66  */
    66 HsCollectionNameState::~HsCollectionNameState()
    67 HsCollectionNameState::~HsCollectionNameState()
    67 {
    68 {
       
    69     cleanUp();
    68 }
    70 }
    69 
    71 
    70 // ---------------------------------------------------------------------------
    72 /*!
    71 // ---------------------------------------------------------------------------
    73  Constructs contained objects.
    72 //
    74  */
    73 void HsCollectionNameState::construct()
    75 void HsCollectionNameState::construct()
    74 {
    76 {
    75     setObjectName(this->parent()->objectName() + "/collectionnamestate");
    77     setObjectName(this->parent()->objectName() + "/collectionnamestate");
       
    78     connect(this, SIGNAL(exited()), SLOT(cleanUp()));
       
    79 
    76 }
    80 }
    77 
    81 
    78 // ---------------------------------------------------------------------------
    82 /*!
    79 // ---------------------------------------------------------------------------
    83  Sets entry event.
    80 //
    84  \param event entry event.
       
    85  */
    81 #ifdef COVERAGE_MEASUREMENT
    86 #ifdef COVERAGE_MEASUREMENT
    82 #pragma CTC SKIP
    87 #pragma CTC SKIP
    83 #endif //COVERAGE_MEASUREMENT
    88 #endif //COVERAGE_MEASUREMENT
    84 void HsCollectionNameState::onEntry(QEvent *event)
    89 void HsCollectionNameState::onEntry(QEvent *event)
    85 {
    90 {
    86     qDebug("CollectionState::onEntry()");
    91     qDebug("CollectionState::onEntry()");
    87     HSMENUTEST_FUNC_ENTRY("HsCollectionNameState::onEntry");
    92     HSMENUTEST_FUNC_ENTRY("HsCollectionNameState::onEntry");
    88     QState::onEntry(event);
    93     QState::onEntry(event);
    89 
    94 
    90     int itemId = 0;
    95     mItemId = 0;
       
    96     mFinishedEntered = false;
    91     if (event->type() == HsMenuEvent::eventType()) {
    97     if (event->type() == HsMenuEvent::eventType()) {
    92         HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event);
    98         HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event);
    93         QVariantMap data = menuEvent->data();
    99         QVariantMap data = menuEvent->data();
    94 
   100 
    95         itemId = data.value(itemIdKey()).toInt();
   101         mItemId = data.value(itemIdKey()).toInt();
    96     }
   102     }
       
   103     mCollectionNameDialog = new HsCollectionNameDialog(mItemId);
       
   104     mCollectionNameDialog->open(this, SLOT(dialogFinished(HbAction*)));
    97 
   105 
    98     HsCollectionNameDialog editor(itemId);
       
    99 
       
   100     HbAction *result = editor.exec();
       
   101     if (result == editor.primaryAction()) {
       
   102         QString newName(editor.newName(editor.value().toString(), true));
       
   103         if (itemId) {
       
   104             if (newName != HsMenuService::getName(itemId)) {
       
   105                 HsMenuService::renameCollection(itemId, newName);
       
   106             }
       
   107         } else {
       
   108             HsMenuService::createCollection(newName);
       
   109         }
       
   110     }
       
   111     HSMENUTEST_FUNC_EXIT("HsCollectionNameState::onEntry");
   106     HSMENUTEST_FUNC_EXIT("HsCollectionNameState::onEntry");
   112 }
   107 }
   113 
   108 
   114 #ifdef COVERAGE_MEASUREMENT
   109 #ifdef COVERAGE_MEASUREMENT
   115 #pragma CTC ENDSKIP
   110 #pragma CTC ENDSKIP
   116 #endif //COVERAGE_MEASUREMENT
   111 #endif //COVERAGE_MEASUREMENT
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 void HsCollectionNameState::dialogFinished(HbAction* finishedAction)
       
   117 {
       
   118     if (!mFinishedEntered) {
       
   119         mFinishedEntered = true;
       
   120         if (finishedAction == mCollectionNameDialog->actions().value(0)) {
       
   121             QString newName(mCollectionNameDialog->newName(mCollectionNameDialog->value().toString(), true));
       
   122             if (mItemId) {
       
   123                 if (newName != HsMenuService::getName(mItemId)) {
       
   124                     HsMenuService::renameCollection(mItemId, newName);
       
   125                 }
       
   126             } else {
       
   127                 HsMenuService::createCollection(newName);
       
   128             }
       
   129         }
       
   130         mCollectionNameDialog = NULL; //set to NULL since this will be deleted atfer close
       
   131         emit exit();
       
   132     } else {
       
   133         // (work-around if more then one action is selected in HbDialog)
       
   134         qWarning("Another signal finished was emited.");
       
   135     }
       
   136 }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void HsCollectionNameState::cleanUp()
       
   142 {
       
   143     if (mCollectionNameDialog) {
       
   144         mCollectionNameDialog->close();
       
   145         mCollectionNameDialog = NULL;
       
   146     }
       
   147 }