homescreenapp/hsdomainmodel/src/hsdatabase.cpp
changeset 51 4785f57bf3d4
parent 46 23b5d6a29cce
child 55 03646e8da489
equal deleted inserted replaced
46:23b5d6a29cce 51:4785f57bf3d4
    21 #include <QVariantHash>
    21 #include <QVariantHash>
    22 #include <QDir>
    22 #include <QDir>
    23 
    23 
    24 #include "hsdatabase.h"
    24 #include "hsdatabase.h"
    25 #include "hsdomainmodeldatastructures.h"
    25 #include "hsdomainmodeldatastructures.h"
       
    26 #include "hsbackuprestoreobserver.h"
    26 
    27 
    27 namespace
    28 namespace
    28 {
    29 {
    29     template<class T>
    30     template<class T>
    30     QVariantList toVariantList(const QList<T> &list)
    31     QVariantList toVariantList(const QList<T> &list)
    50 
    51 
    51 /*!
    52 /*!
    52     Constructs a new database with the given \a parent object.
    53     Constructs a new database with the given \a parent object.
    53 */
    54 */
    54 HsDatabase::HsDatabase(QObject *parent)
    55 HsDatabase::HsDatabase(QObject *parent)
    55   : QObject(parent),
    56   : QObject(parent)
    56   	mBlocked(false)
       
    57 {
    57 {
    58 }
    58 }
    59 
    59 
    60 /*!
    60 /*!
    61     Destroys this database.
    61     Destroys this database.
   101     Opens the database connection using the current connection
   101     Opens the database connection using the current connection
   102     values. Returns true on success, otherwise returns false.
   102     values. Returns true on success, otherwise returns false.
   103 */  
   103 */  
   104 bool HsDatabase::open()
   104 bool HsDatabase::open()
   105 {
   105 {
   106 	if (mBlocked) {
   106 	HsBackupRestoreObserver *brObserver = HsBackupRestoreObserver::instance();
       
   107 	if (brObserver->checkBUR()) {	
   107 		return false;
   108 		return false;
   108 	}
   109 	}
   109 
   110 
   110     QSqlDatabase database;
   111     QSqlDatabase database;
   111     if (QSqlDatabase::contains(mConnectionName)) {
   112     if (QSqlDatabase::contains(mConnectionName)) {
   757 
   758 
   758     return true;
   759     return true;
   759 }
   760 }
   760 
   761 
   761 /*!
   762 /*!
   762     Sets the database blocked or unblocked.
   763 
   763 */
   764 */
   764 void HsDatabase::setDataBaseBlocked(bool blocked)
   765 bool HsDatabase::generalConfiguration(HsGeneralConfiguration &data)
   765 {
   766 {
   766 	mBlocked = blocked;
   767     if (!checkConnection()) {
   767 }
   768         return false;
   768 
   769     }
   769 /*!
   770 
   770     Returns is the database blocked.
   771     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   771     Return value true if blocked.
   772 
   772 */
   773     QString statement =
   773 bool HsDatabase::getDataBaseBlocked()
   774         "SELECT bounceEffect, tapAndHoldDistance, widgetTapAndHoldTimeout, sceneTapAndHoldTimeout, "
   774 {
   775         "pageChangeZoneWidth, "
   775 	return mBlocked;
   776         "pageIndicatorSpacing, pageChangeAnimationDuration, pageChangeZoneAnimationDuration, "
       
   777         "pageChangeZoneReverseAnimationDuration, "
       
   778         "pageRemovedAnimationDuration, newPageAddedAnimationDuration, widgetDragEffectDuration, "
       
   779         "widgetDropEffectDuration, boundaryFeedbackEffectDistance "
       
   780         "FROM GeneralConfiguration";
       
   781 
       
   782     if (query.prepare(statement) && query.exec() && query.next()) {        
       
   783         data.bounceEffect                           = query.value(0).toInt();
       
   784         data.tapAndHoldDistance                     = query.value(1).toInt();
       
   785         data.widgetTapAndHoldTimeout                = query.value(2).toInt();
       
   786         data.sceneTapAndHoldTimeout                 = query.value(3).toInt();
       
   787         data.pageChangeZoneWidth                    = query.value(4).toInt();
       
   788         data.pageIndicatorSpacing                   = query.value(5).toInt();
       
   789         data.pageChangeAnimationDuration            = query.value(6).toInt();
       
   790         data.pageChangeZoneAnimationDuration        = query.value(7).toInt();
       
   791         data.pageChangeZoneReverseAnimationDuration = query.value(8).toInt();
       
   792         data.pageRemovedAnimationDuration           = query.value(9).toInt();
       
   793         data.newPageAddedAnimationDuration          = query.value(10).toInt();
       
   794         data.widgetDragEffectDuration               = query.value(11).toInt();
       
   795         data.widgetDropEffectDuration               = query.value(12).toInt();
       
   796         data.boundaryFeedbackEffectDistance         = query.value(13).toInt();
       
   797         return true;
       
   798     }
       
   799     
       
   800     return false;
       
   801 }
       
   802 
       
   803 /*!
       
   804 
       
   805 */
       
   806 bool HsDatabase::feedbackConfiguration(HsFeedbackConfiguration &data)
       
   807 {
       
   808     if (!checkConnection()) {
       
   809         return false;
       
   810     }
       
   811 
       
   812     QSqlQuery query(QSqlDatabase::database(mConnectionName));
       
   813 
       
   814     QString statement =
       
   815         "SELECT pageChangeFeedbackType, widgetPickFeedbackType, widgetDropFeedbackType,  "
       
   816         "widgetRepositionFeedbackType, widgetOverTrashbinFeedbackType, widgetDropToTrashbinFeedbackType,  "
       
   817         "shortcutWidgetTapFeedbackType, widgetMoveBlockedFeedbackType, clockWidgetTapFeedbackType, "
       
   818         "widgetSnappingFeedbackType "
       
   819         "FROM FeedbackConfiguration";
       
   820 
       
   821     if (query.prepare(statement) && query.exec() && query.next()) {        
       
   822         data.pageChangeFeedbackType           = data.feedbackFromString(query.value(0).toString());
       
   823         data.widgetPickFeedbackType           = data.feedbackFromString(query.value(1).toString());
       
   824         data.widgetDropFeedbackType           = data.feedbackFromString(query.value(2).toString());
       
   825         data.widgetRepositionFeedbackType     = data.feedbackFromString(query.value(3).toString());
       
   826         data.widgetOverTrashbinFeedbackType   = data.feedbackFromString(query.value(4).toString());
       
   827         data.widgetDropToTrashbinFeedbackType = data.feedbackFromString(query.value(5).toString());
       
   828         data.shortcutWidgetTapFeedbackType    = data.feedbackFromString(query.value(6).toString());
       
   829         data.widgetMoveBlockedFeedbackType    = data.feedbackFromString(query.value(7).toString());
       
   830         data.clockWidgetTapFeedbackType       = data.feedbackFromString(query.value(8).toString());
       
   831         data.widgetSnappingFeedbackType       = data.feedbackFromString(query.value(9).toString());
       
   832         return true;
       
   833     }
       
   834     
       
   835     return false;
       
   836 }
       
   837 
       
   838 bool HsDatabase::snapConfiguration(HsSnapConfiguration &data)
       
   839 {   
       
   840     if (!checkConnection()) {
       
   841         return false;
       
   842     }
       
   843 
       
   844     QSqlQuery query(QSqlDatabase::database(mConnectionName));
       
   845 
       
   846     QString statement =
       
   847         "SELECT snappingEnabled, snapForce, snapGap, borderGap, timeout "
       
   848         "FROM SnapConfiguration";
       
   849 
       
   850     if (query.prepare(statement) && query.exec() && query.next()) {
       
   851         data.snappingEnabled = false;
       
   852         if (query.value(0).toInt() == 1) {
       
   853             data.snappingEnabled = true;
       
   854         }
       
   855         data.snapForce = query.value(1).toReal();
       
   856         data.snapGap   = query.value(2).toReal();
       
   857         data.borderGap = query.value(3).toReal();
       
   858         data.timeout   = query.value(4).toInt();
       
   859         return true;
       
   860     }
       
   861     return false;
   776 }
   862 }
   777 
   863 
   778 /*!
   864 /*!
   779     Sets the database instance. The existing instance
   865     Sets the database instance. The existing instance
   780     will be deleted.
   866     will be deleted.