AuthenticationSheet.qml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Róbert Márki
  4. **
  5. ** This file is part of Web Feeds.
  6. **
  7. ** Web Feeds is free software: you can redistribute it and/or modify
  8. ** it under the terms of the GNU General Public License as published by
  9. ** the Free Software Foundation, either version 3 of the License, or
  10. ** (at your option) any later version.
  11. **
  12. ** Web Feeds is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ** GNU General Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU General Public License
  18. ** along with Web Feeds. If not, see <http://www.gnu.org/licenses/>.
  19. ****************************************************************************/
  20. import QtQuick 1.1
  21. import com.nokia.meego 1.0
  22. import com.nokia.extras 1.1
  23. import WebFeeds 1.0
  24. import NewsBlur 1.0
  25. import "../../../../shared/qml" as Shared
  26. import "../../../../shared/qml/UIConstants.js" as UIConstants
  27. CommonNewsBlurSheet {
  28. id: root
  29. property bool authenticationDataValid: false
  30. acceptButtonText: qsTr("Sign in")
  31. rejectButtonText: qsTr("Cancel")
  32. title: root.service ? root.service.serviceName() : "";
  33. busyText: qsTr("Checking")
  34. iconSource: root.service ? root.service.serviceImageUrl() : "";
  35. Connections {
  36. target: root.service
  37. onAccountVerificationComplete: root.onAccountVerificationComplete(result)
  38. }
  39. function updateAcceptButtonStatus() {
  40. if(root.service) {
  41. root.acceptButton.enabled
  42. = ((userNameField.text.length > 0) && (passwordField.text.length > 0));
  43. }
  44. }
  45. function onAccountVerificationComplete(result) {
  46. if(result == NewsBlurEnum.SreNoError) {
  47. root.authenticationDataValid = true;
  48. root.close();
  49. return;
  50. } else if(result == NewsBlurEnum.SreAborted) {
  51. root.close();
  52. return;
  53. }
  54. root.busy = false;
  55. if(result == NewsBlurEnum.SreInvalidAccount) {
  56. root.showMessage(qsTr("Wrong username or password"));
  57. }
  58. else if(result == NewsBlurEnum.SreAborted) {
  59. root.close();
  60. }
  61. else if(result == NewsBlurEnum.SreNetworkError) {
  62. root.showMessage(qsTr("Network error"));
  63. }
  64. }
  65. onAccepted: {
  66. root.busy = true;
  67. root.open();
  68. root.service.verifyAuthenticationData(userNameField.text, passwordField.text);
  69. }
  70. onRejected: {
  71. if(root.busy)
  72. {
  73. root.open();
  74. root.service.abortVerification();
  75. }
  76. }
  77. onStatusChanged: {
  78. if((root.status == DialogStatus.Closed)
  79. && root.authenticationDataValid)
  80. root.service.setAuthenticationData(userNameField.text, passwordField.text);
  81. }
  82. function showMessage(message) {
  83. infoBanner.text = message;
  84. infoBanner.show();
  85. }
  86. InfoBanner {
  87. id: infoBanner
  88. }
  89. contentItem: Column {
  90. id: dataEntryItem
  91. anchors.fill: parent
  92. anchors.leftMargin: UIConstants.DEFAULT_MARGIN
  93. anchors.rightMargin: UIConstants.DEFAULT_MARGIN
  94. spacing: UIConstants.DEFAULT_HALF_MARGIN
  95. Column {
  96. width: parent.width
  97. Label {
  98. text: qsTr("Username")
  99. font.family: UIConstants.FONT_FAMILY_LIGHT
  100. }
  101. Shared.TextField {
  102. id: userNameField
  103. width: parent.width
  104. inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhPreferLowercase
  105. onTextChanged: {
  106. root.updateAcceptButtonStatus();
  107. }
  108. platformSipAttributes: SipAttributes {
  109. actionKeyEnabled: root.acceptButton.enabled
  110. actionKeyLabel: root.acceptButtonText
  111. actionKeyHighlighted: true
  112. }
  113. Keys.onReturnPressed: {
  114. if(root.acceptButton.enabled)
  115. root.accept();
  116. }
  117. }
  118. }
  119. Column {
  120. width: parent.width
  121. Label {
  122. text: qsTr("Password")
  123. font.family: UIConstants.FONT_FAMILY_LIGHT
  124. }
  125. Shared.TextField {
  126. id: passwordField
  127. width: parent.width
  128. echoMode: TextInput.Password
  129. inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhPreferLowercase
  130. onTextChanged: {
  131. root.updateAcceptButtonStatus();
  132. }
  133. platformSipAttributes: SipAttributes {
  134. actionKeyEnabled: root.acceptButton.enabled
  135. actionKeyLabel: root.acceptButtonText
  136. actionKeyHighlighted: true
  137. }
  138. Keys.onReturnPressed: {
  139. if(root.acceptButton.enabled)
  140. root.accept();
  141. }
  142. }
  143. }
  144. Column {
  145. width: parent.width
  146. spacing: UIConstants.DEFAULT_MARGIN
  147. Label {
  148. anchors.horizontalCenter: parent.horizontalCenter
  149. text: qsTr("Don't have an account yet?")
  150. }
  151. Label {
  152. anchors.horizontalCenter: parent.horizontalCenter
  153. text: '<a href="http://www.newsblur.com/">Get new account here</a>'
  154. font.bold: true
  155. onLinkActivated: Qt.openUrlExternally(link)
  156. }
  157. }
  158. Connections {
  159. target: root
  160. onStatusChanged: {
  161. if(root.status == DialogStatus.Open) {
  162. userNameField.forceActiveFocus();
  163. userNameField.platformOpenSoftwareInputPanel();
  164. }
  165. }
  166. }
  167. }
  168. }