main.qml 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.meego 1.1
  6. import ConnectivityPlugin 1.0
  7. PageStackWindow {
  8. id: root
  9. showStatusBar: true
  10. showToolBar: true
  11. initialPage: Qt.resolvedUrl("MainPage.qml")
  12. Component.onCompleted: {
  13. theme.inverted = true
  14. }
  15. ListModel {
  16. id: discoveredServicesModel
  17. }
  18. // For storing chatmessages
  19. ListModel {
  20. id: myMessageModel
  21. }
  22. ConnectionManager {
  23. id: connectionManager
  24. maxConnections: 1
  25. property int prevStatus: ConnectionManager.NotConnected;
  26. property bool isBluetooth: (connectionManager.connectionType == ConnectionManager.Bluetooth);
  27. property bool isLAN : (connectionManager.connectionType == ConnectionManager.LAN);
  28. property bool isConnected: (connectionManager.status == ConnectionManager.Connected);
  29. onErrorChanged: {
  30. console.debug("ConnectionManager::onErrorChanged " + errorString)
  31. }
  32. onNetworkStatusChanged: {
  33. console.debug("ConnectionManager::networkStatus changed to " + networkStatus)
  34. }
  35. onStatusChanged: {
  36. console.debug("ConnectionManager::status changed to " + status);
  37. console.debug("ConnectionManager::prevStatus was " + connectionManager.prevStatus);
  38. if (status == ConnectionManager.Discovering) {
  39. var connectionTypeOk = connectionManager.isBluetooth || connectionManager.isLAN;
  40. var connectAsOk =
  41. (connectionManager.connectAs == ConnectionManager.Client) ||
  42. (connectionManager.connectAs == ConnectionManager.DontCare);
  43. if (connectionTypeOk && connectAsOk)
  44. {
  45. pageStack.push(Qt.resolvedUrl("DiscoveryPage.qml"));
  46. }
  47. }
  48. //If connectAs is DontCare and someone connects to us while
  49. //we are at discovery screen, we'll pop it back.
  50. if (status == ConnectionManager.Connected &&
  51. connectionManager.prevStatus == ConnectionManager.Discovering &&
  52. connectionManager.connectAs == ConnectionManager.DontCare)
  53. {
  54. pageStack.pop();
  55. }
  56. connectionManager.prevStatus = status;
  57. }
  58. onConnectionTypeChanged: {
  59. //When connection type changed we'll clear the servicesModel
  60. discoveredServicesModel.clear();
  61. }
  62. onDiscovered: {
  63. discoveredServicesModel.append({name : name});
  64. }
  65. onRemoved: {
  66. discoveredServicesModel.remove(index);
  67. }
  68. onReceived: {
  69. myMessageModel.append({"message": message, "me": false,
  70. "metaString": Qt.formatDateTime(new Date(),
  71. "hh:mm | dd.MM.yyyy")})
  72. }
  73. }
  74. }