Settings.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. GNU General Public License version 3 notice
  3. Copyright (C) 2012 Mihawk <luiz@netdome.biz>. All rights reserved.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see < http://www.gnu.org/licenses/ >.
  14. */
  15. #include "Settings.h"
  16. #include <QSettings>
  17. #include <QCoreApplication>
  18. #include <QStringList>
  19. Settings* Settings::ourInstance = NULL;
  20. QSettings* Settings::ourSettings;
  21. Settings::Settings()
  22. {
  23. ourSettings = new QSettings(QCoreApplication::applicationDirPath() + "/cimsqwbot.cfg", QSettings::IniFormat);
  24. }
  25. Settings::~Settings()
  26. {
  27. delete ourSettings;
  28. }
  29. Settings* Settings::globalInstance()
  30. {
  31. if(!ourInstance)
  32. ourInstance = new Settings();
  33. return ourInstance;
  34. }
  35. QStringList Settings::serverList()
  36. {
  37. QStringList list;
  38. int size = ourSettings->beginReadArray("servers");
  39. for(int i = 0; i < size; ++i)
  40. {
  41. ourSettings->setArrayIndex(i);
  42. list.append(ourSettings->value("address").toString());
  43. }
  44. ourSettings->endArray();
  45. return list;
  46. }
  47. void Settings::setServerList(QStringList &list)
  48. {
  49. ourSettings->beginWriteArray("servers");
  50. for(int i = 0; i < list.size(); ++i)
  51. {
  52. ourSettings->setArrayIndex(i);
  53. ourSettings->setValue("address", list.at(i));
  54. }
  55. ourSettings->endArray();
  56. }
  57. QString Settings::quakeFolder() const
  58. {
  59. return ourSettings->value("quakeFolder", QCoreApplication::applicationDirPath()).toString();
  60. }
  61. QString Settings::botName() const
  62. {
  63. return ourSettings->value("botName", "[ServeMe]").toString();
  64. }
  65. int Settings::botPing() const
  66. {
  67. return ourSettings->value("botPing", 666).toInt();
  68. }
  69. int Settings::botTopColor() const
  70. {
  71. return ourSettings->value("botTopColor", 11).toInt();
  72. }
  73. int Settings::botBottomColor() const
  74. {
  75. return ourSettings->value("botBottomColor", 12).toInt();
  76. }
  77. bool Settings::botSpectator() const
  78. {
  79. return ourSettings->value("botSpectator", true).toBool();
  80. }
  81. int Settings::floodProtTime() const
  82. {
  83. return qBound<int>(6, ourSettings->value("floodProtTime", 6).toInt(), 9999);
  84. }
  85. int Settings::qwFloodProtTime() const
  86. {
  87. return ourSettings->value("qwFloodProtTime", 600).toInt();
  88. }
  89. int Settings::spamFloodProtTime() const
  90. {
  91. return ourSettings->value("spamFloodProtTime", 300).toInt();
  92. }
  93. unsigned int Settings::queryInterval() const
  94. {
  95. return ourSettings->value("queryInterval", 1000).toUInt();
  96. }
  97. int Settings::timeToSayHiAfterConnected() const
  98. {
  99. return ourSettings->value("timeToSayHiAfterConnected", 7).toInt();
  100. }
  101. int Settings::timeToWaitForCountReply() const
  102. {
  103. return ourSettings->value("timeToWaitForCountReply", 7).toInt();
  104. }
  105. bool Settings::developerMode() const
  106. {
  107. return ourSettings->value("developerMode", false).toBool();
  108. }
  109. void Settings::save()
  110. {
  111. ourSettings->setValue("quakeFolder", quakeFolder());
  112. ourSettings->setValue("botName", botName());
  113. ourSettings->setValue("botPing", botPing());
  114. ourSettings->setValue("botTopColor", botTopColor());
  115. ourSettings->setValue("botBottomColor", botBottomColor());
  116. ourSettings->setValue("botSpectator", botSpectator());
  117. ourSettings->setValue("floodProtTime", floodProtTime());
  118. ourSettings->setValue("queryInterval", queryInterval());
  119. ourSettings->setValue("qwFloodProtTime", qwFloodProtTime());
  120. ourSettings->setValue("spamFloodProtTime", spamFloodProtTime());
  121. ourSettings->setValue("timeToSayHiAfterConnected", timeToSayHiAfterConnected());
  122. ourSettings->setValue("timeToWaitForCountReply", timeToWaitForCountReply());
  123. ourSettings->setValue("developerMode", developerMode());
  124. QStringList list = serverList();
  125. setServerList(list);
  126. }