From: Max Lapan Date: Wed, 17 Mar 2010 15:45:34 +0000 (+0300) Subject: Make settings a singleton. X-Git-Tag: v0.1~10 X-Git-Url: http://git.maemo.org/git/?p=yandex-traffic;a=commitdiff_plain;h=e777727be96dff1f949e7f920495b8093dbd9589 Make settings a singleton. --- diff --git a/mainwidget.cpp b/mainwidget.cpp index 2a97dbc..f4aa592 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -24,7 +24,7 @@ MainWidget::MainWidget () _traffic = new Traffic; _regions = new RegionsTable; - _settings = new Settings; + _settings = Settings::instance (); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget (_light); diff --git a/settings.cpp b/settings.cpp index a08f07f..021ea4f 100644 --- a/settings.cpp +++ b/settings.cpp @@ -2,6 +2,17 @@ #include +static Settings* _settings; + + +Settings* Settings::instance () +{ + if (!_settings) + _settings = new Settings; + return _settings; +} + + Settings::Settings () { load (); diff --git a/settings.hpp b/settings.hpp index 1953f76..19b00f4 100644 --- a/settings.hpp +++ b/settings.hpp @@ -58,8 +58,9 @@ private: int intervalIndex2Minutes (int index) const; int minutes2IntervalIndex (int minutes) const; -public: Settings (); +public: + static Settings* instance (); void load (); void save ();