From 924cfc4b9c0934afab62e4ab58bf4fb026308fd7 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 13 Jul 2013 22:44:29 +0000 Subject: Adds the files containing the Settings class. --- src/settings.cc | 38 ++++++++++++++++++++++++++++++++++++++ src/settings.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/settings.cc create mode 100644 src/settings.h diff --git a/src/settings.cc b/src/settings.cc new file mode 100644 index 0000000..94504d2 --- /dev/null +++ b/src/settings.cc @@ -0,0 +1,38 @@ + +#ifdef _WIN32 +#include +#include +#endif + +#include "settings.h" + +Settings m_globalSettings; + +const Settings & globalSettings() +{ + return m_globalSettings; +} +Settings::Settings() : + m_homePath(), + m_colorInvalidValue(255, 0, 0), + m_colorInputError(195, 195, 195) +{ +#ifdef _WIN32 + // get the full path for "Applicaton Data" + TCHAR appdatapath[512]; + memset(appdatapath, 0, sizeof(appdatapath)); + SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, appdatapath); + + // FIXME detect Unicode support + // m_homePath = QString::fromAscii(appdatapath); + m_homePath = QString::fromUtf16((const ushort *)appdatapath); + m_homePath += "\\Sudoku Solver"; +#else + m_homePath = QDir::homePath() + "/.sudokusolver"; +#endif + QDir directory; + if (!directory.exists(m_homePath)) { + // create home directory + directory.mkdir(m_homePath); + } +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..319bcb1 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,33 @@ +#ifndef __INCLUDED_SUDOKUSOLVER_SETTINGS__ +#define __INCLUDED_SUDOKUSOLVER_SETTINGS__ + +#include + +class Settings { +public: + Settings(); + + inline const QString & homePath() const + { + return m_homePath; + } + + inline const QColor & colorInvalidValue() const + { + return m_colorInvalidValue; + } + + inline const QColor & colorInputError() const + { + return m_colorInputError; + } + +private: + QString m_homePath; + QColor m_colorInvalidValue; + QColor m_colorInputError; +}; + +const Settings & globalSettings(); + +#endif // __INCLUDED_SUDOKUSOLVER_SETTINGS__ -- cgit v1.2.3