diff options
| author | Anton <anton@picapica> | 2017-12-01 21:55:53 +0400 |
|---|---|---|
| committer | Anton <anton@picapica> | 2017-12-01 21:55:53 +0400 |
| commit | ac041927bc0c82e33acaa9e15fd46ecca0b77172 (patch) | |
| tree | 742f1bf43917e79dae43c78684a2a3d055214e76 /pica-client/settings.cpp | |
| parent | 32e742ed040c5a70edb4cbfb947581f1e192d5a6 (diff) | |
| parent | 9c0a5bf2bbd94539427ece7eb1cb8ea82c6c3dec (diff) | |
| download | pica-pica-ac041927bc0c82e33acaa9e15fd46ecca0b77172.tar.gz pica-pica-ac041927bc0c82e33acaa9e15fd46ecca0b77172.zip | |
Merge branch 'direct_c2c_connections'
Diffstat (limited to 'pica-client/settings.cpp')
| -rw-r--r-- | pica-client/settings.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/pica-client/settings.cpp b/pica-client/settings.cpp new file mode 100644 index 0000000..4b5485d --- /dev/null +++ b/pica-client/settings.cpp @@ -0,0 +1,69 @@ +#include "settings.h" + +Settings::Settings(QString storage) +{ + dbconn=QSqlDatabase::addDatabase("QSQLITE"); + dbconn.setDatabaseName(storage); + + if (!dbconn.open()) + { + lasterr=dbconn.lastError(); + return; + } + +} + +QString Settings::GetLastError() +{ + return lasterr.text(); +} + +bool Settings::isEmpty() +{ + QSqlQuery query; + + query.exec("select count(*) from settings"); + + lasterr = query.lastError(); + + query.next(); + + if (query.isValid() && query.value(0).toInt() == 0) + { + return true; + } + + return false; +} + +QVariant Settings::loadValue(QString name, QVariant defval) +{ + QSqlQuery query; + + query.prepare("select value from settings where name = :name"); + query.bindValue(":name", name); + query.exec(); + + lasterr = query.lastError(); + + query.next(); + + if (!query.isValid()) + { + return defval; + } + + return query.value(0); +} + +void Settings::storeValue(QString name, QString val) +{ + QSqlQuery query; + + query.prepare("insert into settings (name, value) values (:name, :val)"); + query.bindValue(":addr", name); + query.bindValue(":val", val); + query.exec(); + + lasterr = query.lastError(); +} |
