9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Implementation for SQLite content store. |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #ifndef HSDATABASE_H |
18 #ifndef HSDATABASE_H |
19 #define HSDATABASE_H |
19 #define HSDATABASE_H |
20 |
20 |
|
21 #include <QObject> |
21 #include <QScopedPointer> |
22 #include <QScopedPointer> |
22 #include <QtSql> |
23 #include <QVariantHash> |
|
24 |
23 #include "hsdomainmodel_global.h" |
25 #include "hsdomainmodel_global.h" |
24 #include "hstest_global.h" |
|
25 |
|
26 HOMESCREEN_TEST_CLASS(TestRuntimeServices) |
|
27 HOMESCREEN_TEST_CLASS(HomeScreenStatePluginTest) |
|
28 |
26 |
29 class HsSceneData; |
27 class HsSceneData; |
30 class HsPageData; |
28 class HsPageData; |
31 class HsWidgetData; |
29 class HsWidgetData; |
32 class HsWidgetPresentationData; |
30 class HsWidgetPresentationData; |
33 |
31 |
34 class HSDOMAINMODEL_EXPORT HsDatabase : public QObject |
32 class HSDOMAINMODEL_EXPORT HsDatabase : public QObject |
35 { |
33 { |
36 Q_OBJECT |
34 Q_OBJECT |
|
35 Q_PROPERTY(QString connectionName READ connectionName WRITE setConnectionName) |
|
36 Q_PROPERTY(QString databaseName READ databaseName WRITE setDatabaseName) |
|
37 |
|
38 public: |
|
39 HsDatabase(QObject *parent = 0); |
|
40 ~HsDatabase(); |
37 |
41 |
38 public: |
42 void setConnectionName(const QString &name); |
39 static void setDatabaseName(const QString& dbName); |
43 QString connectionName() const; |
40 static HsDatabase *instance(); |
44 void setDatabaseName(const QString &name); |
41 ~HsDatabase(); |
45 QString databaseName() const; |
|
46 |
|
47 bool open(); |
|
48 void close(); |
42 |
49 |
43 bool transaction(); |
50 bool transaction(); |
44 bool rollback(); |
51 bool rollback(); |
45 bool commit(); |
52 bool commit(); |
46 |
53 |
47 bool scene(HsSceneData &scene); |
54 bool scene(HsSceneData &data); |
48 bool updateScene(const HsSceneData &scene); |
55 bool updateScene(const HsSceneData &data); |
|
56 |
|
57 bool pages(QList<HsPageData> &data); |
|
58 bool page(HsPageData &data); |
|
59 bool insertPage(HsPageData &data); |
|
60 bool updatePage(const HsPageData &data); |
|
61 bool deletePage(int id); |
49 |
62 |
50 bool pages(QList<HsPageData> &pages); |
63 bool widgets(int pageId, QList<HsWidgetData> &data); |
51 bool page(int id, HsPageData &page, bool getChildren = true); |
64 bool widgets(const QString &uri, QList<HsWidgetData> &data); |
52 bool insertPage(HsPageData &page); |
65 bool widget(HsWidgetData &data); |
53 bool updatePage(const HsPageData &page, bool updateChildren = true); |
66 bool insertWidget(HsWidgetData &data); |
54 bool deletePage(int id); |
67 bool updateWidget(const HsWidgetData &data); |
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); |
68 bool deleteWidget(int id); |
61 bool deleteWidgets(const QString &uri); |
69 bool deleteWidgets(const QString &uri); |
62 |
70 |
63 bool widgetPresentation(int widgetId, const QString &key, HsWidgetPresentationData &presentation); |
71 bool widgetPresentation(HsWidgetPresentationData &data); |
64 bool insertWidgetPresentation(HsWidgetPresentationData &presentation); |
72 bool setWidgetPresentation(const HsWidgetPresentationData &data); |
65 bool updateWidgetPresentation(const HsWidgetPresentationData &presentation); |
73 bool deleteWidgetPresentation(int widgetId, const QString &key); |
66 bool deleteWidgetPresentation(int id); |
|
67 |
74 |
68 bool setWidgetPreferenceForKey(int widgetId, const QString &key, const QString &value); |
75 bool widgetPreferences(int widgetId, QVariantHash &data); |
69 bool widgetPreferenceForKey(int widgetId, const QString &key, QString &value); |
76 bool widgetPreference(int widgetId, const QString &key, QVariant &value); |
70 bool setWidgetPreferences(int widgetId, const QVariantMap &preferences); |
77 bool setWidgetPreferences(int widgetId, const QVariantHash &data); |
71 bool widgetPreferences(int widgetId, QVariantMap &preferences); |
78 |
72 bool widgetIds(const QString &uri, QList<int>& ids); |
79 public: |
|
80 static void setInstance(HsDatabase *instance); |
|
81 static HsDatabase *instance(); |
|
82 static HsDatabase *takeInstance(); |
|
83 |
|
84 private: |
|
85 Q_DISABLE_COPY(HsDatabase) |
|
86 bool checkConnection() const; |
73 |
87 |
74 private: |
88 private: |
75 HsDatabase(); |
89 QString mConnectionName; |
76 bool openDatabase(const QString &databaseName); |
90 QString mDatabaseName; |
77 Q_DISABLE_COPY(HsDatabase) |
|
78 |
91 |
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; |
92 static QScopedPointer<HsDatabase> mInstance; |
88 static QString mDatabaseName; |
|
89 HOMESCREEN_TEST_FRIEND_CLASS(TestRuntimeServices) |
|
90 HOMESCREEN_TEST_FRIEND_CLASS(HomeScreenStatePluginTest) |
|
91 }; |
93 }; |
92 |
94 |
93 #endif // HSDATABASE_H |
95 #endif // HSDATABASE_H |