main.qml 3.0 KB

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