main.qml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import gfa.plugins.qml.net 1.0
  4. Window {
  5. visible: true
  6. width: 640
  7. height: 480
  8. title: qsTr("Hello World")
  9. Text {
  10. id: idIpAddr
  11. x: 5
  12. y: 40
  13. color: "blue"
  14. font.pixelSize: 14
  15. text: idItf.interfaces[2].inet.stat.ipAddress.address
  16. }
  17. Text {
  18. id: idIfUpDownOut
  19. x: 5
  20. y: 60
  21. width: 630
  22. height: 300
  23. color: "black"
  24. font.pixelSize: 14
  25. text: ""
  26. }
  27. NetInterfaces {
  28. id: idItf
  29. // itfFilterName: "eth0"
  30. itfFilterAF: Interface.AF_Inet | Interface.AF_Inet6
  31. itfFilterMethod: Interface.IM_Static | Interface.IM_Manual
  32. onError:
  33. {
  34. console.error(msg);
  35. }
  36. onFilteredInterfacesChanged:
  37. {
  38. // console.warn("Filtered Interfaces may have changed!");
  39. }
  40. onIfUpDown:
  41. {
  42. idIfUpDownOut.text += msg;
  43. // console.log(msg);
  44. }
  45. onIfUpDownCompleted:
  46. {
  47. switch(ctx)
  48. {
  49. case NetInterfaces.UDC_Start:
  50. console.log("IfUp completed with code " + code);
  51. break;
  52. case NetInterfaces.UDC_Stop:
  53. console.log("IfDown completed with code " + code);
  54. break;
  55. case NetInterfaces.UDC_Restart:
  56. console.log("IfUpDown completed with code " + code);
  57. break;
  58. }
  59. }
  60. }
  61. MouseArea {
  62. anchors.fill: parent
  63. onClicked:
  64. {
  65. var ret;
  66. idIfUpDownOut.text = "";
  67. // idIfUpDownOut.update();
  68. // return;
  69. if(idItf.filteredInterfaces.length > 0)
  70. {
  71. idItf.filteredInterfaces[0].inet.stat.ipAddress.address = "155.18.2.156";
  72. idItf.filteredInterfaces[0].inet.stat.ipAddress.b2 = 255;
  73. // console.log(idItf.filteredInterfaces[0].inet.stat.ipAddress.address);
  74. }
  75. else
  76. {
  77. console.warn("No interface found!");
  78. }
  79. idItf.itfFilterMethod &= ~Interface.IM_Manual;
  80. idItf.itfFilterMethod |= Interface.IM_Dhcp;
  81. var itfn = idItf.newInterface("test1", Interface.AF_Inet6, Interface.IM_Dhcp);
  82. itfn.af = Interface.AF_Inet;
  83. itfn.method = Interface.IM_Static;
  84. itfn.inet.stat.ipAddress.address = "192.168.3.24";
  85. itfn.inet.stat.netMask.address = "255.255.254.0";
  86. itfn.inet.stat.netPrefix = 22;
  87. itfn.inet.stat.gateway.b0 = 192;
  88. itfn.inet.stat.gateway.b1 = 168;
  89. itfn.inet.stat.gateway.b2 = 0;
  90. itfn.inet.stat.gateway.b3 = 1;
  91. itfn.inet.stat.dnsServer[0].address = "8.8.8.8";
  92. itfn.inet.stat.dnsServer[1].address = "8.8.4.4";
  93. itfn.selCfg = Interface.SC_AllowHotplug | Interface.SC_NoAutoDown;
  94. itfn.selCfg = Interface.SC_Auto | Interface.SC_NoScripts | Interface.SC_AllowHotplug;
  95. // ret = idItf.stopInterface(idItf.interfaces[2]);
  96. if(idItf.ifUpDownInProgress)
  97. idItf.cancelStartStopInterface();
  98. else
  99. ret = idItf.restartInterface(idItf.interfaces[2]);
  100. // idItf.removeInterface(itfn);
  101. // idItf.saveAs("/home/wrk/share/gfanet/libgfanet/res/testitf");
  102. }
  103. }
  104. }