homescreenapp/hsdomainmodel/inc/hsdatabase.h
changeset 35 f9ce957a272c
child 36 cdae8c6c3876
equal deleted inserted replaced
5:c743ef5928ba 35:f9ce957a272c
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation for SQLite content store.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef HSDATABASE_H
       
    19 #define HSDATABASE_H
       
    20 
       
    21 #include <QScopedPointer>
       
    22 #include <QtSql>
       
    23 #include "hsdomainmodel_global.h"
       
    24 #include "hstest_global.h"
       
    25 
       
    26 HOMESCREEN_TEST_CLASS(TestRuntimeServices)
       
    27 HOMESCREEN_TEST_CLASS(HomeScreenStatePluginTest)
       
    28 
       
    29 class HsSceneData;
       
    30 class HsPageData;
       
    31 class HsWidgetData;
       
    32 class HsWidgetPresentationData;
       
    33 
       
    34 class HSDOMAINMODEL_EXPORT HsDatabase : public QObject
       
    35 {
       
    36     Q_OBJECT
       
    37 
       
    38 public:
       
    39     static void setDatabaseName(const QString& dbName);
       
    40     static HsDatabase *instance();
       
    41     ~HsDatabase();
       
    42 
       
    43     bool transaction();
       
    44     bool rollback();
       
    45     bool commit();
       
    46 
       
    47     bool scene(HsSceneData &scene);
       
    48     bool updateScene(const HsSceneData &scene);
       
    49     
       
    50     bool pages(QList<HsPageData> &pages);
       
    51     bool page(int id, HsPageData &page, bool getChildren = true);
       
    52     bool insertPage(HsPageData &page);
       
    53     bool updatePage(const HsPageData &page, bool updateChildren = true);
       
    54     bool deletePage(int id);
       
    55 
       
    56     bool widget(int id, HsWidgetData &widget, bool getChildren = true);
       
    57     bool insertWidget(HsWidgetData &widget);
       
    58     bool insertWidget(const HsWidgetData &widget,int &databaseId);
       
    59     bool updateWidget(const HsWidgetData &widget, bool updateChildren = true);
       
    60     bool deleteWidget(int id);
       
    61     bool deleteWidgets(const QString &uri);
       
    62 
       
    63     bool widgetPresentation(int widgetId, const QString &key, HsWidgetPresentationData &presentation);
       
    64     bool insertWidgetPresentation(HsWidgetPresentationData &presentation);
       
    65     bool updateWidgetPresentation(const HsWidgetPresentationData &presentation);
       
    66     bool deleteWidgetPresentation(int id);
       
    67 
       
    68     bool setWidgetPreferenceForKey(int widgetId, const QString &key, const QString &value);
       
    69     bool widgetPreferenceForKey(int widgetId, const QString &key, QString &value);
       
    70     bool setWidgetPreferences(int widgetId, const QVariantMap &preferences);
       
    71     bool widgetPreferences(int widgetId, QVariantMap &preferences);
       
    72     bool widgetIds(const QString &uri, QList<int>& ids);
       
    73 
       
    74 private:
       
    75     HsDatabase();
       
    76     bool openDatabase(const QString &databaseName);
       
    77     Q_DISABLE_COPY(HsDatabase)
       
    78 
       
    79     bool parsePage(const QSqlQuery &query, bool getChildren, HsPageData &page);
       
    80     bool parseWidget(const QSqlQuery &query, bool getChildren, HsWidgetData &widget);
       
    81     bool parseWidgetPresentation(const QSqlQuery &query, HsWidgetPresentationData &presentation);
       
    82 
       
    83     QVariant columnValue(const QSqlQuery &query, const QString &columnName) const;
       
    84     QSqlDatabase database() const;
       
    85 
       
    86 private:
       
    87     static QScopedPointer<HsDatabase> mInstance;
       
    88     static QString  mDatabaseName;
       
    89     HOMESCREEN_TEST_FRIEND_CLASS(TestRuntimeServices)
       
    90     HOMESCREEN_TEST_FRIEND_CLASS(HomeScreenStatePluginTest)
       
    91 };
       
    92 
       
    93 #endif // HSDATABASE_H