homescreenapp/hsdomainmodel/src/hsdatabase.cpp
changeset 55 03646e8da489
parent 51 4785f57bf3d4
child 60 30f14686fb04
child 62 341166945d65
equal deleted inserted replaced
51:4785f57bf3d4 55:03646e8da489
   183     }
   183     }
   184 
   184 
   185     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   185     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   186 
   186 
   187     QString statement =
   187     QString statement =
   188         "SELECT id, portraitWallpaper, landscapeWallpaper, defaultPageId, "
   188         "SELECT id, portraitWallpaper, landscapeWallpaper "
   189         "maximumPageCount, maximumWidgetHeight, maximumWidgetWidth, "
       
   190         "minimumWidgetHeight, minimumWidgetWidth "
       
   191         "FROM Scene";
   189         "FROM Scene";
   192     
   190     
   193     if (query.prepare(statement) && query.exec() && query.next()) {        
   191     if (query.prepare(statement) && query.exec() && query.next()) {        
   194         data.id                  = query.value(0).toInt();
   192         data.id                  = query.value(0).toInt();
   195         data.portraitWallpaper   = query.value(1).toString();
   193         data.portraitWallpaper   = query.value(1).toString();
   196         data.landscapeWallpaper  = query.value(2).toString();
   194         data.landscapeWallpaper  = query.value(2).toString();
   197         data.defaultPageId       = query.value(3).toInt();
       
   198         data.maximumPageCount    = query.value(4).toInt();
       
   199         data.maximumWidgetHeight = query.value(5).toReal();
       
   200         data.maximumWidgetWidth  = query.value(6).toReal();
       
   201         data.minimumWidgetHeight = query.value(7).toReal();
       
   202         data.minimumWidgetWidth  = query.value(8).toReal();
       
   203         return true;
   195         return true;
   204     }
   196     }
   205     
   197     
   206     return false;
   198     return false;
   207 }
   199 }
   571 {
   563 {
   572     if (!checkConnection()) {
   564     if (!checkConnection()) {
   573         return false;
   565         return false;
   574     }
   566     }
   575 
   567 
       
   568     QString key = data.orientation == Qt::Vertical ?
       
   569         QLatin1String("portrait") : QLatin1String("landscape");
       
   570 
   576     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   571     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   577 
   572 
   578     QString statement =
   573     QString statement =
   579         "SELECT x, y, zValue "
   574         "SELECT x, y, zValue "
   580         "FROM WidgetPresentations "
   575         "FROM WidgetPresentations "
   581         "WHERE key = ? AND widgetId = ?";
   576         "WHERE key = ? AND widgetId = ?";
   582 
   577 
   583     if (query.prepare(statement)) {
   578     if (query.prepare(statement)) {
   584         query.addBindValue(data.key);
   579         query.addBindValue(key);
   585         query.addBindValue(data.widgetId);
   580         query.addBindValue(data.widgetId);
   586         if (query.exec() && query.next()) {
   581         if (query.exec() && query.next()) {
   587             data.x      = query.value(0).toReal();
   582             data.x      = query.value(0).toReal();
   588             data.y      = query.value(1).toReal();
   583             data.y      = query.value(1).toReal();
   589             data.zValue = query.value(2).toReal();
   584             data.zValue = query.value(2).toReal();
   601 {
   596 {
   602     if (!checkConnection()) {
   597     if (!checkConnection()) {
   603         return false;
   598         return false;
   604     }
   599     }
   605 
   600 
       
   601     QString key = data.orientation == Qt::Vertical ?
       
   602         QLatin1String("portrait") : QLatin1String("landscape");
       
   603 
   606     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   604     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   607 
   605 
   608     QString statement =
   606     QString statement =
   609         "REPLACE INTO WidgetPresentations "
   607         "REPLACE INTO WidgetPresentations "
   610         "(key, x, y, zValue, widgetId) "
   608         "(key, x, y, zValue, widgetId) "
   611         "VALUES (?, ?, ?, ?, ?)";
   609         "VALUES (?, ?, ?, ?, ?)";
   612 
   610 
   613     if (query.prepare(statement)) {
   611     if (query.prepare(statement)) {
   614         query.addBindValue(data.key);
   612         query.addBindValue(key);
   615         query.addBindValue(data.x);
   613         query.addBindValue(data.x);
   616         query.addBindValue(data.y);
   614         query.addBindValue(data.y);
   617         query.addBindValue(data.zValue);
   615         query.addBindValue(data.zValue);
   618         query.addBindValue(data.widgetId);
   616         query.addBindValue(data.widgetId);
   619         return query.exec();
   617         return query.exec();
   623 }
   621 }
   624 
   622 
   625 /*!
   623 /*!
   626 
   624 
   627 */
   625 */
   628 bool HsDatabase::deleteWidgetPresentation(int widgetId, const QString &key)
   626 bool HsDatabase::deleteWidgetPresentation(int widgetId, Qt::Orientation orientation)
   629 {
   627 {
   630     if (!checkConnection()) {
   628     if (!checkConnection()) {
   631         return false;
   629         return false;
   632     }
   630     }
       
   631 
       
   632     QString key = orientation == Qt::Vertical ?
       
   633         QLatin1String("portrait") : QLatin1String("landscape");
   633 
   634 
   634     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   635     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   635 
   636 
   636     QString statement =
   637     QString statement =
   637         "DELETE FROM WidgetPresentations "
   638         "DELETE FROM WidgetPresentations "
   774         "SELECT bounceEffect, tapAndHoldDistance, widgetTapAndHoldTimeout, sceneTapAndHoldTimeout, "
   775         "SELECT bounceEffect, tapAndHoldDistance, widgetTapAndHoldTimeout, sceneTapAndHoldTimeout, "
   775         "pageChangeZoneWidth, "
   776         "pageChangeZoneWidth, "
   776         "pageIndicatorSpacing, pageChangeAnimationDuration, pageChangeZoneAnimationDuration, "
   777         "pageIndicatorSpacing, pageChangeAnimationDuration, pageChangeZoneAnimationDuration, "
   777         "pageChangeZoneReverseAnimationDuration, "
   778         "pageChangeZoneReverseAnimationDuration, "
   778         "pageRemovedAnimationDuration, newPageAddedAnimationDuration, widgetDragEffectDuration, "
   779         "pageRemovedAnimationDuration, newPageAddedAnimationDuration, widgetDragEffectDuration, "
   779         "widgetDropEffectDuration, boundaryFeedbackEffectDistance "
   780         "widgetDropEffectDuration, boundaryFeedbackEffectDistance, "
       
   781         "defaultPageId, maximumPageCount, maximumWidgetHeight, maximumWidgetWidth, "
       
   782         "minimumWidgetHeight, minimumWidgetWidth, shortcutLabelsVisible,  "
       
   783         "pageChangePanDistance "
   780         "FROM GeneralConfiguration";
   784         "FROM GeneralConfiguration";
   781 
   785 
   782     if (query.prepare(statement) && query.exec() && query.next()) {        
   786     if (query.prepare(statement) && query.exec() && query.next()) {        
   783         data.bounceEffect                           = query.value(0).toInt();
   787         data.bounceEffect                           = query.value(0).toInt();
   784         data.tapAndHoldDistance                     = query.value(1).toInt();
   788         data.tapAndHoldDistance                     = query.value(1).toReal();
   785         data.widgetTapAndHoldTimeout                = query.value(2).toInt();
   789         data.widgetTapAndHoldTimeout                = query.value(2).toInt();
   786         data.sceneTapAndHoldTimeout                 = query.value(3).toInt();
   790         data.sceneTapAndHoldTimeout                 = query.value(3).toInt();
   787         data.pageChangeZoneWidth                    = query.value(4).toInt();
   791         data.pageChangeZoneWidth                    = query.value(4).toReal();
   788         data.pageIndicatorSpacing                   = query.value(5).toInt();
   792         data.pageIndicatorSpacing                   = query.value(5).toReal();
   789         data.pageChangeAnimationDuration            = query.value(6).toInt();
   793         data.pageChangeAnimationDuration            = query.value(6).toInt();
   790         data.pageChangeZoneAnimationDuration        = query.value(7).toInt();
   794         data.pageChangeZoneAnimationDuration        = query.value(7).toInt();
   791         data.pageChangeZoneReverseAnimationDuration = query.value(8).toInt();
   795         data.pageChangeZoneReverseAnimationDuration = query.value(8).toInt();
   792         data.pageRemovedAnimationDuration           = query.value(9).toInt();
   796         data.pageRemovedAnimationDuration           = query.value(9).toInt();
   793         data.newPageAddedAnimationDuration          = query.value(10).toInt();
   797         data.newPageAddedAnimationDuration          = query.value(10).toInt();
   794         data.widgetDragEffectDuration               = query.value(11).toInt();
   798         data.widgetDragEffectDuration               = query.value(11).toInt();
   795         data.widgetDropEffectDuration               = query.value(12).toInt();
   799         data.widgetDropEffectDuration               = query.value(12).toInt();
   796         data.boundaryFeedbackEffectDistance         = query.value(13).toInt();
   800         data.boundaryFeedbackEffectDistance         = query.value(13).toInt();
       
   801         data.defaultPageId                          = query.value(14).toInt();
       
   802         data.maximumPageCount                       = query.value(15).toInt();
       
   803         data.maximumWidgetHeight                    = query.value(16).toReal();
       
   804         data.maximumWidgetWidth                     = query.value(17).toReal();
       
   805         data.minimumWidgetHeight                    = query.value(18).toReal();
       
   806         data.minimumWidgetWidth                     = query.value(19).toReal();
       
   807         data.shortcutLabelsVisible                  = query.value(20).toBool();
       
   808         data.pageChangePanDistance                  = query.value(21).toReal();
   797         return true;
   809         return true;
   798     }
   810     }
   799     
   811     
   800     return false;
   812     return false;
   801 }
   813 }
   846     QString statement =
   858     QString statement =
   847         "SELECT snappingEnabled, snapForce, snapGap, borderGap, timeout "
   859         "SELECT snappingEnabled, snapForce, snapGap, borderGap, timeout "
   848         "FROM SnapConfiguration";
   860         "FROM SnapConfiguration";
   849 
   861 
   850     if (query.prepare(statement) && query.exec() && query.next()) {
   862     if (query.prepare(statement) && query.exec() && query.next()) {
   851         data.snappingEnabled = false;
   863         data.snappingEnabled = query.value(0).toBool();
   852         if (query.value(0).toInt() == 1) {
       
   853             data.snappingEnabled = true;
       
   854         }
       
   855         data.snapForce = query.value(1).toReal();
   864         data.snapForce = query.value(1).toReal();
   856         data.snapGap   = query.value(2).toReal();
   865         data.snapGap   = query.value(2).toReal();
   857         data.borderGap = query.value(3).toReal();
   866         data.borderGap = query.value(3).toReal();
   858         data.timeout   = query.value(4).toInt();
   867         data.timeout   = query.value(4).toInt();
   859         return true;
   868         return true;
   865     Sets the database instance. The existing instance
   874     Sets the database instance. The existing instance
   866     will be deleted.
   875     will be deleted.
   867 */
   876 */
   868 void HsDatabase::setInstance(HsDatabase *instance)
   877 void HsDatabase::setInstance(HsDatabase *instance)
   869 {
   878 {
   870     mInstance.reset(instance);
   879     if (mInstance != instance) {
       
   880         HsDatabase *oldInstance = mInstance;
       
   881         mInstance = instance;
       
   882         delete oldInstance;
       
   883     }
   871 }
   884 }
   872 
   885 
   873 /*!
   886 /*!
   874     Returns the database instance.
   887     Returns the database instance.
   875 */
   888 */
   876 HsDatabase *HsDatabase::instance()
   889 HsDatabase *HsDatabase::instance()
   877 {
   890 {
   878     return mInstance.data();
   891     return mInstance;
   879 }
   892 }
   880 
   893 
   881 /*!
   894 /*!
   882     Returns the current database instance. Callers of this 
   895     Returns the current database instance. Callers of this 
   883     function take ownership of the instance. The current 
   896     function take ownership of the instance. The current 
   884     database instance will be reset to null.    
   897     database instance will be reset to null.    
   885 */
   898 */
   886 HsDatabase *HsDatabase::takeInstance()
   899 HsDatabase *HsDatabase::takeInstance()
   887 {
   900 {
   888     return mInstance.take();
   901     HsDatabase *instance = mInstance;
       
   902     mInstance = 0;
       
   903     return instance;
   889 }
   904 }
   890   
   905   
   891 /*!
   906 /*!
   892     Checks the connection validity. Returns true if the 
   907     Checks the connection validity. Returns true if the 
   893     connection is valid.
   908     connection is valid.
   898 }
   913 }
   899 
   914 
   900 /*!
   915 /*!
   901     Points to the database instance.
   916     Points to the database instance.
   902 */
   917 */
   903 QScopedPointer<HsDatabase> HsDatabase::mInstance(0);
   918 HsDatabase *HsDatabase::mInstance(0);