homescreenapp/hsdomainmodel/inc/hsdatabase.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 16 Apr 2010 14:54:01 +0300
changeset 36 cdae8c6c3876
parent 35 f9ce957a272c
child 46 23b5d6a29cce
permissions -rw-r--r--
Revision: 201011 Kit: 201015

/*
* 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"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/

#ifndef HSDATABASE_H
#define HSDATABASE_H

#include <QObject>
#include <QScopedPointer>
#include <QVariantHash>

#include "hsdomainmodel_global.h"

class HsSceneData;
class HsPageData;
class HsWidgetData;
class HsWidgetPresentationData;

class HSDOMAINMODEL_EXPORT HsDatabase : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString connectionName READ connectionName WRITE setConnectionName)
    Q_PROPERTY(QString databaseName READ databaseName WRITE setDatabaseName)
    
public:
    HsDatabase(QObject *parent = 0);
    ~HsDatabase();

    void setConnectionName(const QString &name);
    QString connectionName() const;    
    void setDatabaseName(const QString &name);
    QString databaseName() const;

    bool open();
    void close();

    bool transaction();
    bool rollback();
    bool commit();

    bool scene(HsSceneData &data);
    bool updateScene(const HsSceneData &data);

    bool pages(QList<HsPageData> &data);
    bool page(HsPageData &data);
    bool insertPage(HsPageData &data);
    bool updatePage(const HsPageData &data);
    bool deletePage(int id);
    
    bool widgets(int pageId, QList<HsWidgetData> &data);
    bool widgets(const QString &uri, QList<HsWidgetData> &data);
    bool widget(HsWidgetData &data);
    bool insertWidget(HsWidgetData &data);
    bool updateWidget(const HsWidgetData &data);
    bool deleteWidget(int id);
    bool deleteWidgets(const QString &uri);

    bool widgetPresentation(HsWidgetPresentationData &data);
    bool setWidgetPresentation(const HsWidgetPresentationData &data);
    bool deleteWidgetPresentation(int widgetId, const QString &key);

    bool widgetPreferences(int widgetId, QVariantHash &data);
    bool widgetPreference(int widgetId, const QString &key, QVariant &value);
    bool setWidgetPreferences(int widgetId, const QVariantHash &data);
            
public:
    static void setInstance(HsDatabase *instance);
    static HsDatabase *instance();
    static HsDatabase *takeInstance();

private:    
    Q_DISABLE_COPY(HsDatabase)
    bool checkConnection() const;

private:
    QString mConnectionName;
    QString mDatabaseName;

    static QScopedPointer<HsDatabase> mInstance;
};

#endif // HSDATABASE_H