homescreenapp/hsdomainmodel/src/hsscene.cpp
changeset 77 4b195f3bea29
parent 61 2b1b11a301d2
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
   162 
   162 
   163     if (!mPages.contains(page)) {
   163     if (!mPages.contains(page)) {
   164         return true;
   164         return true;
   165     }
   165     }
   166 
   166 
   167     int index = mPages.indexOf(page) + 1;
   167     int nextIndex = mPages.indexOf(page) + 1;
   168 
   168 
   169     HsDatabase *db = HsDatabase::instance();
   169     HsDatabase *db = HsDatabase::instance();
   170     db->transaction();
   170     db->transaction();
   171 
   171     // update page indexes
   172     HsPageData data;
   172     HsPageData data;
   173     for (int i = index; i < mPages.count(); ++i) {
   173     int pageCount(mPages.count());
   174         data.id = mPages.at(i)->databaseId();
   174     for (;nextIndex < pageCount; ++nextIndex) {
   175         data.indexPosition = i - 1;
   175         data.id = mPages.at(nextIndex)->databaseId();
       
   176         data.indexPosition = nextIndex - 1;
   176         if (!db->updatePage(data)) {
   177         if (!db->updatePage(data)) {
   177             db->rollback();
   178             db->rollback();
   178             return false;
   179             return false;
   179         }
   180         }
   180     }
   181     }
   181 
   182     // page will remove itself from database
   182     if (!page->deleteFromDatabase()) {
   183     if (!page->deleteFromDatabase()) {
   183         db->rollback();
   184         db->rollback();
   184         return false;
   185         return false;
   185     }
   186     }
   186 
   187 
   187     db->commit();
   188     db->commit();
   188 
   189     // update internal list
       
   190     int index = mPages.indexOf(page);
       
   191     bool lastPage(mPages.last() == page);
   189     mPages.removeOne(page);
   192     mPages.removeOne(page);
       
   193     if (mPages.isEmpty()) {
       
   194         mActivePage = NULL;
       
   195     }else if (mActivePage == page) {
       
   196         if (lastPage) {
       
   197             index--;
       
   198         }
       
   199         setActivePageIndex(index);
       
   200     }
       
   201     
   190     return true;
   202     return true;
   191 }
   203 }
   192 
   204 
   193 /*!
   205 /*!
   194     Set active page \a page.
   206     Set active page \a page.
   307 }
   319 }
   308 
   320 
   309 /*!
   321 /*!
   310     Return main window.
   322     Return main window.
   311 */
   323 */
   312 HbMainWindow *HsScene::mainWindow()
   324 /*HbMainWindow *HsGui::instance()
   313 {
   325 {
   314     return hbInstance->allMainWindows().first();
   326     return hbInstance->allMainWindows().first();
   315 }
   327 }
   316 
   328 */
   317 /*!
   329 /*!
   318     Return current orientation.
   330     Return current orientation.
   319 */
   331 */
   320 Qt::Orientation HsScene::orientation()
   332 /*Qt::Orientation HsGui::instance()->orientation()
   321 {
   333 {
   322     return mainWindow()->orientation();
   334     return mainWindow()->orientation();
   323 }
   335 }*/
   324 
   336 
   325 /*!
   337 /*!
   326     Listens for application background/foreground changes.
   338     Listens for application background/foreground changes.
   327 */
   339 */
   328 bool HsScene::eventFilter(QObject *watched, QEvent *event)
   340 bool HsScene::eventFilter(QObject *watched, QEvent *event)