--- a/homescreenapp/hsdomainmodel/src/hsconfiguration.cpp Fri Jun 11 13:30:16 2010 +0300
+++ b/homescreenapp/hsdomainmodel/src/hsconfiguration.cpp Wed Jun 23 18:03:36 2010 +0300
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
@@ -14,115 +14,231 @@
* Description:
*
*/
+
+#include <QMetaObject>
+#include <QMetaProperty>
+#include <QTextStream>
+#include <QFile>
+
+#include <HbDeviceProfile>
+
#include "hsconfiguration.h"
-#include "hsdomainmodeldatastructures.h"
#include "hsdatabase.h"
-#include <HbInstantFeedback>
+/*!
+ \class HsConfiguration
+ \ingroup group_hsdomainmodel
+ \brief
+*/
/*!
- Loads configuration data from database.
+
*/
-void HsConfiguration::loadConfiguration()
-{
- HsDatabase *db = HsDatabase::instance();
+HsConfiguration::HsConfiguration(QObject *parent)
+ : QObject(parent),
+ mBounceEffect(20),
+ mWidgetTapAndHoldTimeout(500),
+ mSceneTapAndHoldTimeout(500),
+ mPageChangeAnimationDuration(200),
+ mPageChangeZoneAnimationDuration(800),
+ mPageChangeZoneReverseAnimationDuration(200),
+ mPageRemovedAnimationDuration(200),
+ mNewPageAddedAnimationDuration(200),
+ mWidgetDragEffectDuration(200),
+ mWidgetDropEffectDuration(200),
+ mDefaultPageId(1),
+ mMaximumPageCount(8),
+ mIsShortcutLabelVisible(true),
+ mBounceFeedbackEffectDistance(3),
+ mPageChangePanDistanceInPixels(120),
+ mTapAndHoldDistance(16),
+ mPageChangeZoneWidth(60),
+ mPageIndicatorSpacing(8),
+ mMaximumWidgetHeight(39),
+ mMaximumWidgetWidth(48),
+ mMinimumWidgetHeight(8.75),
+ mMinimumWidgetWidth(8.75),
+ mPageChangePanDistance(17.91),
+ mPageChangeFeedbackEffect(HbFeedback::Sensitive),
+ mWidgetPickFeedbackEffect(HbFeedback::ItemPick),
+ mWidgetDropFeedbackEffect(HbFeedback::ItemDrop),
+ mWidgetRepositionFeedbackEffect(HbFeedback::BounceEffect),
+ mWidgetOverTrashbinFeedbackEffect(HbFeedback::ItemMoveOver),
+ mWidgetDropToTrashbinFeedbackEffect(HbFeedback::ItemDrop),
+ mShortcutWidgetTapFeedbackEffect(HbFeedback::BasicItem),
+ mWidgetMoveBlockedFeedbackEffect(HbFeedback::Basic),
+ mClockWidgetTapFeedbackEffect(HbFeedback::BasicItem),
+ mWidgetSnappingFeedbackEffect(HbFeedback::ItemMoveOver),
+ mIsSnapEnabled(true),
+ mSnapTimeout(500),
+ mSnapForce(30),
+ mSnapGap(6),
+ mSnapBorderGap(0),
+ mSnapLineFadeInDuration(200),
+ mSnapLineFadeOutDuration(100),
+ mIsSnapEffectsEnabled(true),
+ mSceneType(PageWallpapers)
+{
+}
+
+/*!
- HsGeneralConfiguration generalConfiguration;
- if (db->generalConfiguration(generalConfiguration)) {
- mBounceEffect = generalConfiguration.bounceEffect;
- mTapAndHoldDistance = generalConfiguration.tapAndHoldDistance;
- mWidgetTapAndHoldTimeout = generalConfiguration.widgetTapAndHoldTimeout;
- mSceneTapAndHoldTimeout = generalConfiguration.sceneTapAndHoldTimeout;
- mPageChangeZoneWidth = generalConfiguration.pageChangeZoneWidth;
- mPageIndicatorSpacing = generalConfiguration.pageIndicatorSpacing;
- mPageChangeAnimationDuration = generalConfiguration.pageChangeAnimationDuration;
- mPageChangeZoneAnimationDuration = generalConfiguration.pageChangeZoneAnimationDuration;
- mPageChangeZoneReverseAnimationDuration = generalConfiguration.pageChangeZoneReverseAnimationDuration;
- mPageRemovedAnimationDuration = generalConfiguration.pageRemovedAnimationDuration;
- mNewPageAddedAnimationDuration = generalConfiguration.newPageAddedAnimationDuration;
- mWidgetDragEffectDuration = generalConfiguration.widgetDragEffectDuration;
- mWidgetDropEffectDuration = generalConfiguration.widgetDropEffectDuration;
- mBounceFeedbackEffectDistance = generalConfiguration.boundaryFeedbackEffectDistance;
- mDefaultPageId = generalConfiguration.defaultPageId;
- mMaximumPageCount = generalConfiguration.maximumPageCount;
- mMaximumWidgetHeight = generalConfiguration.maximumWidgetHeight;
- mMaximumWidgetWidth = generalConfiguration.maximumWidgetWidth;
- mMinimumWidgetHeight = generalConfiguration.minimumWidgetHeight;
- mMinimumWidgetWidth = generalConfiguration.minimumWidgetWidth;
- mShortcutLabelsVisible = generalConfiguration.shortcutLabelsVisible;
- mPageChangePanDistance = generalConfiguration.pageChangePanDistance;
- mPageChangePanDistanceInPixels = mPageChangePanDistance * HbDeviceProfile::current().unitValue();
- } else {
- Q_ASSERT_X(1, "Configuration", "Homescreen configuration could not be loaded from database");
+*/
+HsConfiguration::~HsConfiguration()
+{
+}
+
+/*!
+
+*/
+QSizeF HsConfiguration::minimumWidgetSizeInUnits() const
+{
+ return QSizeF(mMinimumWidgetWidth, mMinimumWidgetHeight);
+}
+
+/*!
+
+*/
+QSizeF HsConfiguration::maximumWidgetSizeInUnits() const
+{
+ return QSizeF(mMaximumWidgetWidth, mMaximumWidgetHeight);
+}
+
+/*!
+
+*/
+QSizeF HsConfiguration::minimumWidgetSizeInPixels() const
+{
+ HbDeviceProfile profile;
+ qreal factor = profile.unitValue();
+ return factor * minimumWidgetSizeInUnits();
+}
+
+/*!
+
+*/
+QSizeF HsConfiguration::maximumWidgetSizeInPixels() const
+{
+ HbDeviceProfile profile;
+ qreal factor = profile.unitValue();
+ return factor * maximumWidgetSizeInUnits();
+}
+
+/*!
+
+*/
+bool HsConfiguration::load()
+{
+ QVariantHash configuration;
+
+ HsDatabase *db = HsDatabase::instance();
+ if (!db->configuration(configuration)) {
+ return false;
}
- HsFeedbackConfiguration feedbackConfiguration;
- if (db->feedbackConfiguration(feedbackConfiguration)) {
- mPageChangeFeedbackType = feedbackConfiguration.pageChangeFeedbackType;
- mWidgetPickFeedbackType = feedbackConfiguration.widgetPickFeedbackType;
- mWidgetDropFeedbackType = feedbackConfiguration.widgetDropFeedbackType;
- mWidgetRepositionFeedbackType = feedbackConfiguration.widgetRepositionFeedbackType;
- mWidgetOverTrashbinFeedbackType = feedbackConfiguration.widgetOverTrashbinFeedbackType;
- mWidgetDropToTrashbinFeedbackType = feedbackConfiguration.widgetDropToTrashbinFeedbackType;
- mShortcutWidgetTapFeedbackType = feedbackConfiguration.shortcutWidgetTapFeedbackType;
- mWidgetMoveBlockedFeedbackType = feedbackConfiguration.widgetMoveBlockedFeedbackType;
- mClockWidgetTapFeedbackType = feedbackConfiguration.clockWidgetTapFeedbackType;
- mWidgetSnappingFeedbackType = feedbackConfiguration.widgetSnappingFeedbackType;
- } else {
- Q_ASSERT_X(1, "Configuration", "Homescreen feedback cnfiguration could not be loaded from database");
+ const QMetaObject *mo = metaObject();
+ QHashIterator<QString, QVariant> i(configuration);
+ while (i.hasNext()) {
+ i.next();
+ QByteArray name = i.key().toLatin1();
+ QVariant value = i.value();
+ QMetaProperty mp = mo->property(mo->indexOfProperty(name));
+ if (mp.isEnumType()) {
+ bool ok;
+ value.toString().toInt(&ok);
+ if (ok) {
+ setProperty(name, value.toInt());
+ } else {
+ setProperty(name, mp.enumerator().keyToValue(value.toString().toLatin1()));
+ }
+ } else {
+ setProperty(name, value);
+ }
}
- HsSnapConfiguration snapConfiguration;
- if (db->snapConfiguration(snapConfiguration)) {
- mSnapEnabled = snapConfiguration.snappingEnabled;
- mSnapForce = snapConfiguration.snapForce;
- mSnapGap = snapConfiguration.snapGap;
- mSnapBorderGap = snapConfiguration.borderGap;
- mSnapTimeout = snapConfiguration.timeout;
- } else {
- Q_ASSERT_X(1, "Configuration", "Homescreen snap configuration could not be loaded from database");
+ return true;
+}
+
+/*!
+
+*/
+bool HsConfiguration::importFromFile(const QString &path)
+{
+ QFile file(path);
+ if (!file.open(QIODevice::ReadOnly)) {
+ return false;
}
+ QTextStream in(&file);
+
+ const QMetaObject *mo = metaObject();
+ while (!in.atEnd()) {
+ QStringList list = in.readLine().split(QLatin1String(" = "));
+ QByteArray name = list.at(0).toLatin1();
+ QByteArray value = list.at(1).toLatin1();
+ QMetaProperty mp = mo->property(mo->indexOfProperty(name));
+ if (mp.isEnumType()) {
+ setProperty(name, mp.enumerator().keyToValue(value));
+ } else {
+ setProperty(name, value);
+ }
+ }
+
+ return true;
}
-// static member variables initilized here, these values will be used if fetching from database fails
-int HsConfiguration::mBounceEffect = 20;
-qreal HsConfiguration::mTapAndHoldDistance = 16.0;
-int HsConfiguration::mWidgetTapAndHoldTimeout = 500;
-int HsConfiguration::mSceneTapAndHoldTimeout = 500;
-qreal HsConfiguration::mPageChangeZoneWidth = 60.0;
-qreal HsConfiguration::mPageIndicatorSpacing = 8.0;
-int HsConfiguration::mPageChangeAnimationDuration = 200;
-int HsConfiguration::mPageChangeZoneAnimationDuration = 800;
-int HsConfiguration::mPageChangeZoneReverseAnimationDuration = 200;
-int HsConfiguration::mPageRemovedAnimationDuration = 200;
-int HsConfiguration::mNewPageAddedAnimationDuration = 700;
-int HsConfiguration::mWidgetDragEffectDuration = 200;
-int HsConfiguration::mWidgetDropEffectDuration = 200;
-int HsConfiguration::mBounceFeedbackEffectDistance = 3;
-int HsConfiguration::mDefaultPageId = 1;
-int HsConfiguration::mMaximumPageCount = 8;
-qreal HsConfiguration::mMaximumWidgetHeight = 39;
-qreal HsConfiguration::mMaximumWidgetWidth = 48;
-qreal HsConfiguration::mMinimumWidgetHeight = 8.75;
-qreal HsConfiguration::mMinimumWidgetWidth = 8.75;
-bool HsConfiguration::mShortcutLabelsVisible = false;
-qreal HsConfiguration::mPageChangePanDistance = 17.91;
-int HsConfiguration::mPageChangePanDistanceInPixels = 120;
+/*!
+
+*/
+bool HsConfiguration::exportToFile(const QString &path)
+{
+ QFile file(path);
+ if (!file.open(QIODevice::WriteOnly)) {
+ return false;
+ }
+ QTextStream out(&file);
+
+ const QMetaObject *mo = this->metaObject();
+ for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) {
+ QMetaProperty mp = mo->property(i);
+ out << mp.name() << " = ";
+ if (mp.isEnumType()) {
+ out << mp.enumerator().valueToKey(mp.read(this).toInt());
+ } else {
+ out << mp.read(this).toString();
+ }
+ out << endl;
+ }
+
+ return true;
+}
+
+/*!
-HbFeedback::InstantEffect HsConfiguration::mPageChangeFeedbackType = HbFeedback::None;
-HbFeedback::InstantEffect HsConfiguration::mWidgetPickFeedbackType = HbFeedback::None;
-HbFeedback::InstantEffect HsConfiguration::mWidgetDropFeedbackType = HbFeedback::None;
-HbFeedback::InstantEffect HsConfiguration::mWidgetRepositionFeedbackType = HbFeedback::None;
-HbFeedback::InstantEffect HsConfiguration::mWidgetOverTrashbinFeedbackType = HbFeedback::None;
-HbFeedback::InstantEffect HsConfiguration::mWidgetDropToTrashbinFeedbackType = HbFeedback::None;
-HbFeedback::InstantEffect HsConfiguration::mShortcutWidgetTapFeedbackType = HbFeedback::None;
-HbFeedback::InstantEffect HsConfiguration::mWidgetMoveBlockedFeedbackType = HbFeedback::None;
-HbFeedback::InstantEffect HsConfiguration::mClockWidgetTapFeedbackType = HbFeedback::None;
-HbFeedback::InstantEffect HsConfiguration::mWidgetSnappingFeedbackType = HbFeedback::None;
+*/
+HsConfiguration *HsConfiguration::instance()
+{
+ return mInstance;
+}
+
+/*!
-bool HsConfiguration::mSnapEnabled = false;
-qreal HsConfiguration::mSnapForce = 0;
-qreal HsConfiguration::mSnapGap = 0;
-qreal HsConfiguration::mSnapBorderGap = 0;
-int HsConfiguration::mSnapTimeout = 0;
+*/
+HsConfiguration *HsConfiguration::takeInstance()
+{
+ HsConfiguration *instance = mInstance;
+ mInstance = 0;
+ return instance;
+}
+
+/*!
+*/
+void HsConfiguration::setInstance(HsConfiguration *instance)
+{
+ if (mInstance != instance) {
+ delete mInstance;
+ mInstance = instance;
+ }
+}
+
+HsConfiguration *HsConfiguration::mInstance(0);