homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hscollectionnamedialog.cpp
changeset 71 1db7cc813a4e
parent 62 341166945d65
child 81 7dd137878ff8
equal deleted inserted replaced
69:87476091b3f5 71:1db7cc813a4e
    52  \retval void
    52  \retval void
    53  */
    53  */
    54 HsCollectionNameDialog::HsCollectionNameDialog(const int &itemId)
    54 HsCollectionNameDialog::HsCollectionNameDialog(const int &itemId)
    55 {
    55 {
    56     HSMENUTEST_FUNC_ENTRY("HsInputDialog::HsInputDialog");
    56     HSMENUTEST_FUNC_ENTRY("HsInputDialog::HsInputDialog");
    57     mCollectionsNames = HsMenuService::getCollectionNames();
    57     mOtherCollectionsNames = HsMenuService::getCollectionNames();
       
    58 
       
    59 
    58     setInputMode(HbInputDialog::TextInput);
    60     setInputMode(HbInputDialog::TextInput);
    59     setPromptText(hbTrId("txt_applib_title_collection_name"));
    61     setPromptText(hbTrId("txt_applib_title_collection_name"));
    60     lineEdit()->setMaxLength(qMaxStrLength);
    62     lineEdit()->setMaxLength(qMaxStrLength);
    61     if (itemId) {
    63     if (itemId) {
    62         setValue(HsMenuService::getName(itemId));
    64         const QString currentCollectionName(
    63         mCollectionsNames.removeOne(value().toString());
    65                 HsMenuService::getName(itemId));
       
    66         setValue(currentCollectionName);
       
    67         mOtherCollectionsNames.removeOne(currentCollectionName);
       
    68         mSuggestedNames << currentCollectionName;
    64     } else {
    69     } else {
    65         setValue(hbTrId("txt_applib_dialog_entry_collection"));
    70         setValue(hbTrId("txt_applib_dialog_entry_collection"));
    66     }
    71     }
       
    72 
    67     HSMENUTEST_FUNC_EXIT("HsInputDialog::HsInputDialog");
    73     HSMENUTEST_FUNC_EXIT("HsInputDialog::HsInputDialog");
    68 }
    74 }
    69 
    75 
    70 /*!
    76 /*!
    71  Destructor
    77  Destructor
    72  */
    78  */
    73 HsCollectionNameDialog::~HsCollectionNameDialog()
    79 HsCollectionNameDialog::~HsCollectionNameDialog()
    74 {
    80 {
    75     mCollectionsNames.clear();
    81     mOtherCollectionsNames.clear();
    76     mLastCollectionName.clear();
    82     mSuggestedNames.clear();
    77 }
    83 }
    78 
    84 
    79 /*!
    85 /*!
    80  Gets new collection's name.
    86  Gets new collection's name.
    81  \param item_id Item's id.
    87  \param item_id Item's id.
    93 
    99 
    94     HSMENUTEST_FUNC_EXIT("HsCollectionNameDialog::open");
   100     HSMENUTEST_FUNC_EXIT("HsCollectionNameDialog::open");
    95 }
   101 }
    96 
   102 
    97 /*!
   103 /*!
       
   104   \return User input if it is unique collection name or an unique collection name being
       
   105   a combination of user name and a suffix matching following regular expression:
       
   106   "\([0-9][1-9]\)|\([1-9][0-9]+\)"
       
   107  */
       
   108 QString HsCollectionNameDialog::uniqueCollectionName() const
       
   109 {
       
   110     return generateUniqueCollectionName(value().toString());
       
   111 }
       
   112 
       
   113 /*!
    98     \reimp 
   114     \reimp 
    99     Disconnects signals and calls base class impl. which emits finished(HbAction*) 
   115     Disconnects signals and calls base class impl. which emits finished(HbAction*) 
   100  */
   116  */
   101 void HsCollectionNameDialog::closeEvent ( QCloseEvent * event )
   117 void HsCollectionNameDialog::closeEvent ( QCloseEvent * event )
   102 {
   118 {
   104     makeDisconnect();
   120     makeDisconnect();
   105     HbDialog::closeEvent(event); // emits finished(HbAction*) 
   121     HbDialog::closeEvent(event); // emits finished(HbAction*) 
   106 }
   122 }
   107 
   123 
   108 /*!
   124 /*!
   109  * Gets new collection's name.
   125   \param name Input string which is to be basename
   110  \param name name of collection.
   126     of resulting unique collection name.
   111  \param addLastName true
   127   \return Unique collection name.
   112  if last found name is need to add to validation
   128  */
   113  \retval new collection name.
   129 QString HsCollectionNameDialog::generateUniqueCollectionName(
   114  */
   130         const QString &name) const
   115 QString HsCollectionNameDialog::newName(const QString &name,
       
   116                                         bool addLastName)
       
   117 {
   131 {
   118     HSMENUTEST_FUNC_ENTRY("HsInputDialog::newName");
   132     HSMENUTEST_FUNC_ENTRY("HsInputDialog::newName");
       
   133 
   119     QString newName(name);
   134     QString newName(name);
   120     int numToAppend(1);
   135 
   121     if (addLastName && mLastCollectionName.length() > 0
   136     unsigned int numToAppend(1);
   122             && !mCollectionsNames.contains(mLastCollectionName)) {
   137 
   123         mCollectionsNames << mLastCollectionName;
   138     while (mOtherCollectionsNames.contains(newName)) {
   124     }
   139         newName =
   125     while (mCollectionsNames.contains(newName)) {
   140                 name
       
   141                 + QString("(%1)").arg(numToAppend, 2, 10, QLatin1Char('0'));
       
   142         numToAppend++;
       
   143     }
       
   144 
       
   145     HSMENUTEST_FUNC_EXIT("HsInputDialog::newName");
       
   146     return newName;
       
   147 }
       
   148 /*!
       
   149   \param name Input string which is to be basename
       
   150     for suggested collection name.
       
   151   \return Unique collection name if it was not yet proposed during lifetime of the dialog
       
   152    or \a name otherwise.
       
   153  */
       
   154 QString HsCollectionNameDialog::suggestedCollectionName(const QString &name)
       
   155 {
       
   156     HSMENUTEST_FUNC_ENTRY("HsInputDialog::processInput");
       
   157 
       
   158     QString newName = generateUniqueCollectionName(name);
       
   159 
       
   160     if (mSuggestedNames.contains(newName)) {
   126         newName = name;
   161         newName = name;
   127         newName.append("(");
   162     }
   128         if (numToAppend < 10) {
   163 
   129             newName.append("0");
   164     if (newName != name) {
   130         }
   165         mSuggestedNames << newName;
   131         newName.append(QString::number(numToAppend));
   166     }
   132         newName.append(")");
   167 
   133         numToAppend++;
   168     HSMENUTEST_FUNC_EXIT("HsInputDialog::validate");
   134         if (!addLastName) {
       
   135             if (mLastCollectionName.length() > 0
       
   136                     && !mCollectionsNames.contains(mLastCollectionName)) {
       
   137                 mCollectionsNames << mLastCollectionName;
       
   138             }
       
   139             mCollectionsNames.removeOne(name);
       
   140             mLastCollectionName = name;
       
   141         }
       
   142     }
       
   143     HSMENUTEST_FUNC_EXIT("HsInputDialog::newName");
       
   144     return newName;
   169     return newName;
   145 }
   170 }
   146 
   171 
   147 /*!
   172 /*!
   148  Connects edit line signals to slots.
   173  Connects edit line signals to slots.
   182 		actions()[0]->setEnabled(false);
   207 		actions()[0]->setEnabled(false);
   183     } else {
   208     } else {
   184         actions()[0]->setEnabled(true);
   209         actions()[0]->setEnabled(true);
   185     }
   210     }
   186 
   211 
   187     QString newText = newName(text);
   212     QString newText = suggestedCollectionName(text);
   188     if (newText != text) {
   213     if (newText != text) {
   189         makeDisconnect();
   214         makeDisconnect();
   190         lineEdit()->setText(newText);
   215         lineEdit()->setText(newText);
   191         lineEdit()->setSelection(text.length(), newText.length()
   216         lineEdit()->setSelection(text.length(), newText.length()
   192                                  - text.length());
   217                                  - text.length());