profileFunctions.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /**
  2. * Copyright © 2010 Digia Plc
  3. * Copyright © 2010 Nokia Corporation
  4. *
  5. * All rights reserved.
  6. *
  7. * Nokia and Nokia Connecting People are registered trademarks of
  8. * Nokia Corporation.
  9. * Java and all Java-based marks are trademarks or registered
  10. * trademarks of
  11. * Sun Microsystems, Inc. Other product and company names
  12. * mentioned herein may be
  13. * trademarks or trade names of their respective owners.
  14. *
  15. *
  16. * Subject to the conditions below, you may, without charge:
  17. *
  18. * · Use, copy, modify and/or merge copies of this software and
  19. * associated documentation files (the "Software")
  20. *
  21. * · Publish, distribute, sub-licence and/or sell new software
  22. * derived from or incorporating the Software.
  23. *
  24. *
  25. * This file, unmodified, shall be included with all copies or
  26. * substantial portions
  27. * of the Software that are distributed in source code form.
  28. *
  29. * The Software cannot constitute the primary value of any new
  30. * software derived
  31. * from or incorporating the Software.
  32. *
  33. * Any person dealing with the Software shall not misrepresent
  34. * the source of the Software.
  35. *
  36. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  37. * KIND, EXPRESS OR IMPLIED,
  38. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  39. * MERCHANTABILITY, FITNESS FOR A
  40. * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  41. * AUTHORS OR COPYRIGHT
  42. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  43. * WHETHER IN AN ACTION
  44. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  45. * CONNECTION WITH THE
  46. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  47. */
  48. /**
  49. * Changes current profile
  50. *
  51. * @param newProfile The profile to use
  52. * @return Nothing
  53. */
  54. function changeCurrent(newProfile) {
  55. hideAll();
  56. structure.currentMode = newProfile;
  57. }
  58. /**
  59. * Hides all the rows
  60. *
  61. * @return Nothing
  62. */
  63. function hideAll() {
  64. rowTemp.visible = false;
  65. rowLight.visible = false;
  66. rowLightDim.visible = false;
  67. rowVolume.visible = false;
  68. rowVolumeMovie.visible = false;
  69. rowSaunaOff.visible = false;
  70. rowLockOpen.visible = false;
  71. rowLockClosed.visible = false;
  72. rowAlarmOn.visible = false;
  73. rowAlarmOff.visible = false;
  74. }
  75. /**
  76. * Sets current mode to Normal
  77. *
  78. * @return Nothing
  79. */
  80. function normalMode() {
  81. changeCurrent( "Home" );
  82. rowTemp.theTemperature = 22;
  83. rowTemp.visible = true;
  84. rowLockOpen.visible = true;
  85. rowAlarmOff.visible = true;
  86. var db = openDatabaseSync("HomeControl", "1.0", "CoDe Qt Quick application", 1000000);
  87. db.transaction(
  88. function(tx) {
  89. tx.executeSql('UPDATE RoomTable SET temp=22');
  90. tx.executeSql('UPDATE Security SET alarmOn="false", doorsLocked="false"');
  91. }
  92. )
  93. }
  94. /**
  95. * Sets current mode to Night
  96. *
  97. * @return Nothing
  98. */
  99. function nightMode() {
  100. changeCurrent( "Night" );
  101. rowTemp.theTemperature = 20;
  102. rowTemp.visible = true;
  103. rowLight.visible = true;
  104. rowVolume.visible = true;
  105. rowSaunaOff.visible = true;
  106. rowLockClosed.visible = true;
  107. structure.saunaTurnedOff();
  108. var db = openDatabaseSync("HomeControl", "1.0", "CoDe Qt Quick application", 1000000);
  109. db.transaction(
  110. function(tx) {
  111. tx.executeSql('UPDATE RoomTable SET light=0 WHERE roomCode="kitchen" OR roomCode="livingroom" OR roomCode="khh" OR roomCode="kph" OR roomCode="sauna"');
  112. tx.executeSql('UPDATE RoomTable SET temp=20, mute="true"');
  113. tx.executeSql('UPDATE Sauna SET saunaOn="false"');
  114. tx.executeSql('UPDATE Security SET doorsLocked="true"');
  115. }
  116. )
  117. }
  118. /**
  119. * Sets current mode to Away
  120. *
  121. * @return Nothing
  122. */
  123. function awayMode() {
  124. changeCurrent("Away");
  125. rowTemp.theTemperature = 20;
  126. rowTemp.visible = true;
  127. rowLight.visible = true;
  128. rowVolume.visible = true;
  129. rowLockClosed.visible = true;
  130. structure.saunaTurnedOff();
  131. var db = openDatabaseSync("HomeControl", "1.0", "CoDe Qt Quick application", 1000000);
  132. db.transaction(
  133. function(tx) {
  134. tx.executeSql('UPDATE RoomTable SET temp=20, mute="true", light=0');
  135. tx.executeSql('UPDATE Security SET alarmOn="false", doorsLocked="true"');
  136. }
  137. )
  138. }
  139. /**
  140. * Sets current mode to Away (long)
  141. *
  142. * @return Nothing
  143. */
  144. function awayLongMode() {
  145. changeCurrent("Away (long)");
  146. rowTemp.theTemperature = 18;
  147. rowTemp.visible = true;
  148. rowLight.visible = true;
  149. rowVolume.visible = true;
  150. rowSaunaOff.visible = true;
  151. rowLockClosed.visible = true;
  152. rowAlarmOn.visible = true;
  153. structure.saunaTurnedOff();
  154. var db = openDatabaseSync("HomeControl", "1.0", "CoDe Qt Quick application", 1000000);
  155. db.transaction(
  156. function(tx) {
  157. tx.executeSql('UPDATE RoomTable SET temp=18, light=0, volume=0');
  158. tx.executeSql('UPDATE Sauna SET saunaOn="false"');
  159. tx.executeSql('UPDATE Security SET alarmOn="true", doorsLocked="true"');
  160. }
  161. )
  162. }
  163. /**
  164. * Sets current mode to Movie
  165. *
  166. * @return Nothing
  167. */
  168. function movieMode() {
  169. changeCurrent("Movie");
  170. rowLight.visible = true;
  171. rowLightDim.visible = true;
  172. rowVolume.visible = true;
  173. rowVolumeMovie.visible = true;
  174. var db = openDatabaseSync("HomeControl", "1.0", "CoDe Qt Quick application", 1000000);
  175. db.transaction(
  176. function(tx) {
  177. tx.executeSql('UPDATE RoomTable SET light=0, mute="true"');
  178. tx.executeSql('UPDATE RoomTable SET light=10, volume=80, mute="false" WHERE roomCode="livingroom"');
  179. tx.executeSql('UPDATE Security SET alarmOn="false"');
  180. }
  181. )
  182. }