settings.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #ifndef SETTINGS_H
  2. #define SETTINGS_H
  3. #include <QList>
  4. #include <QMap>
  5. #include <QPair>
  6. #include <QSettings>
  7. #include <QString>
  8. #include <QVariant>
  9. class QScriptEngine;
  10. #include "defines.h"
  11. class Settings
  12. {
  13. public:
  14. enum ProxyConfigKind
  15. {
  16. PCK_UndefinedProxyConfig,
  17. PCK_NoProxy,
  18. PCK_SystemProxy,
  19. PCK_ManualProxy
  20. };
  21. enum Parameter {
  22. // Saved using QSettings
  23. // +-- generic settings
  24. LogFilePath,
  25. // +-- symbian settings
  26. QtEnvBatPath,
  27. FullS60SDK,
  28. UID3,
  29. PanningEnabled,
  30. TextSelectionEnabled,
  31. WidgetLayout,
  32. LastWidgetPath,
  33. LastDirectoryPath,
  34. // +-- maemo5 settings
  35. MaddePath,
  36. HybridAuthor,
  37. HybridEmail,
  38. Licence,
  39. HybridShortDesc,
  40. HybridLongDesc,
  41. // +-- network settings
  42. ForumNokiaUserName,
  43. ProxyConfig,
  44. ProxyUrl,
  45. ProxyPort,
  46. ProxyUserName,
  47. ProxyPassword,
  48. // +-- remote compiler persisted properties
  49. RcProperties,
  50. // Pseudo-settings, not saved using QSettings
  51. // +-- symbian settings
  52. ShowFullScreen,
  53. ShowSoftKeys,
  54. QtVersion,
  55. QtVersionString
  56. };
  57. enum LayoutMode {
  58. StatusPaneWithSoftKeys = 0,
  59. FullScreenWithSoftKeys = 1,
  60. FullScreenWithoutSoftKeys = 2
  61. };
  62. public:
  63. static Settings& instance()
  64. {
  65. static Settings singleton;
  66. return singleton;
  67. }
  68. /**
  69. * Gets the value for a key.
  70. *
  71. * Some settings are meant to be application (app name)
  72. * specific. In that case the final key used is the
  73. * concatenation of the app and key ("APP/KEY"), if app
  74. * is not NULL.
  75. *
  76. * @param key the key for the value to get
  77. *
  78. * @param app application name for app specific settings.
  79. * If given, then the app specific value for the key will
  80. * be returned. If defined, it should be a alphadigitial
  81. * ASCII string (no blanks).
  82. *
  83. * @return the value stored for the key (or <app,key> pair)
  84. * if app was given.
  85. */
  86. static QVariant get(Parameter key,
  87. QString app = QString(""));
  88. /**
  89. * Sets a value for a key, possibly application specific.
  90. *
  91. * See comments for get().
  92. *
  93. */
  94. static void set(Parameter key,
  95. QVariant value,
  96. QString app = QString(""));
  97. static void setTemporary(Parameter key, QVariant value);
  98. /**
  99. * Utility function using 'RcProperties'.
  100. *
  101. * This method loads the uninterpreted string for
  102. * RcProperties from settings and parses it. It
  103. * provides a map of (OS platform identifiers, OS
  104. * OS platorm human readable description) items that are
  105. * supported by the remote compiler.
  106. *
  107. * @param scriptEngine the engine to use for parsing
  108. */
  109. typedef QMap<QString, QString> OsDescMap;
  110. static OsDescMap RcOSes(QScriptEngine & scriptEngine);
  111. /**
  112. * Utility function using 'RcProperties'.
  113. *
  114. * This method loads the uninterpreted string of
  115. * RcProperties from settings and parses it. It
  116. * provides a list of (OS, Qt, WccParam) pairs. The OS
  117. * identifiers are the same as returned by method
  118. * 'RcOses'.
  119. *
  120. * @param scriptEngine the engine to use for parsing
  121. */
  122. struct OsQtPair
  123. {
  124. QString m_os;
  125. QString m_qt;
  126. OsQtPair(QString os,
  127. QString qt);
  128. /**
  129. * The wccparam to be encluded in URLs to remote compiler
  130. * targetting this particular OS with this particular Qt
  131. * version. Like "pSet[os]=maemo5&pSet[qt]=4_6_2".
  132. */
  133. QString wccParams() const;
  134. };
  135. typedef QList<OsQtPair> OsQtPairList;
  136. static OsQtPairList RcOsQtPairs(QScriptEngine & scriptEngine);
  137. /**
  138. * @return true if Forum Nokia user name and proxy configuration
  139. * are defined in settings.
  140. */
  141. static bool IsRcConfigured();
  142. private:
  143. Settings();
  144. ~Settings();
  145. Settings(const Settings&); // No copy
  146. Settings& operator=(const Settings&); // No assignment
  147. QSettings* getSettingObject();
  148. static QString getKey(Parameter key,
  149. const QString & app);
  150. QString guessQtEnvPath() const;
  151. QString guessMobilityPath() const;
  152. private:
  153. QSettings *m_settings;
  154. QMap<Settings::Parameter, QVariant> *m_overridingSettings;
  155. QString m_error;
  156. };
  157. #endif // SETTINGS_H