summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdriano Rezende <adriano.rezende@openbossa.org>2009-11-17 12:40:34 -0300
committerAdriano Rezende <adriano.rezende@openbossa.org>2009-11-17 13:43:23 -0300
commita1ab255d5e5c93652998c4e6085094d5bdcfea14 (patch)
treeb1e11ed195188c6a61645417c8d761f9100e58ea
parentf1c16d44f28fc7d41f44aa0e7ad06449e514eb41 (diff)
Shared: Added Resource class
This class is a helper that creates a singleton resource which access data and pixmap. Signed-off-by: Adriano Rezende <adriano.rezende@openbossa.org>
-rw-r--r--shared/resource.cpp108
-rw-r--r--shared/resource.h67
2 files changed, 175 insertions, 0 deletions
diff --git a/shared/resource.cpp b/shared/resource.cpp
new file mode 100644
index 0000000..1687cd1
--- /dev/null
+++ b/shared/resource.cpp
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: openBossa - INdT (renato.chencarek@openbossa.org)
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** the openBossa stream from INdT (renato.chencarek@openbossa.org).
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QSettings>
+
+#include "resource.h"
+
+
+Resource::Resource()
+ : settings(new QSettings()),
+ pixmapPrefix(":/")
+{
+
+}
+
+Resource::~Resource()
+{
+ delete settings;
+}
+
+Resource *Resource::instance()
+{
+ static Resource result;
+ return &result;
+}
+
+void Resource::setIniFile(const QString &fileName)
+{
+ Resource *d = instance();
+
+ if (d->settings)
+ delete d->settings;
+
+ d->settings = new QSettings(fileName, QSettings::IniFormat);
+}
+
+QPixmap Resource::pixmap(const QString &path)
+{
+ Resource *d = instance();
+ return QPixmap(QString("%1%2").arg(d->pixmapPrefix, path));
+}
+
+void Resource::setPixmapPrefix(const QString &prefix)
+{
+ Resource *d = instance();
+ d->pixmapPrefix = prefix;
+}
+
+bool Resource::containsValue(const QString &key)
+{
+ Resource *d = instance();
+ return d->settings->contains(key);
+}
+
+QVariant Resource::value(const QString &key, const QVariant &value)
+{
+ Resource *d = instance();
+
+ if (d->settings->contains(key))
+ return d->settings->value(key, value);
+ else {
+ qWarning("Resource: key '%s' not found", key.toLatin1().data());
+ return QVariant();
+ }
+}
+
+int Resource::intValue(const QString &key, int value)
+{
+ return Resource::value(key, value).toInt();
+}
+
+double Resource::doubleValue(const QString &key, double value)
+{
+ return Resource::value(key, value).toDouble();
+}
+
+QString Resource::stringValue(const QString &key, const QString &value)
+{
+ return Resource::value(key, value).toString();
+}
diff --git a/shared/resource.h b/shared/resource.h
new file mode 100644
index 0000000..6376c5b
--- /dev/null
+++ b/shared/resource.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: openBossa - INdT (renato.chencarek@openbossa.org)
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** the openBossa stream from INdT (renato.chencarek@openbossa.org).
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RESOURCE_H
+#define RESOURCE_H
+
+#include <QPixmap>
+#include <QVariant>
+
+
+class QSettings;
+
+
+class Resource
+{
+public:
+ static void setIniFile(const QString &fileName);
+
+ static QPixmap pixmap(const QString &path);
+ static void setPixmapPrefix(const QString &prefix);
+
+ static bool containsValue(const QString &key);
+
+ static QVariant value(const QString &key, const QVariant &value = QVariant());
+
+ static int intValue(const QString &key, int value = 0);
+ static double doubleValue(const QString &key, double value = 0);
+ static QString stringValue(const QString &key, const QString &value = QString());
+
+private:
+ Resource();
+ ~Resource();
+ static Resource *instance();
+
+ QSettings *settings;
+ QString pixmapPrefix;
+};
+
+#endif