ifedit.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 2.0
  4. //import QtQuick.Controls 1.5
  5. import QtQuick.Controls 1.4 as Ctrl14
  6. import QtQuick.Controls.Styles 1.4
  7. import com.gfa.ipc.appctrl 1.0
  8. import "globals.js" as Globals
  9. import QtQuick.FreeVirtualKeyboard 1.0
  10. Rectangle {
  11. id: idEdit
  12. width: Screen.width
  13. height: Screen.height
  14. property bool isDirty: false
  15. property bool ifUpDownInProgress: false
  16. function updateUI(sel)
  17. {
  18. if(sel >= 0)
  19. {
  20. switch(qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[sel].method)
  21. {
  22. case QInterface.IM_Static:
  23. idStatic.visible = true;
  24. idDhcp.visible = false;
  25. idMethStatic.checked = true;
  26. idIfUpDownOutput.visible = true;
  27. break;
  28. case QInterface.IM_Dhcp:
  29. idStatic.visible = false;
  30. idDhcp.visible = true;
  31. idMethDhcp.checked = true;
  32. idIfUpDownOutput.visible = true;
  33. break;
  34. default:
  35. idStatic.visible = false;
  36. idDhcp.visible = false;
  37. idMethStatic.checked = false;
  38. idMethDhcp.checked = false;
  39. idIfUpDownOutput.visible = false;
  40. break;
  41. }
  42. if(sel > 0)
  43. {
  44. idAddrS.address = qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[sel].inet.stat.ipAddress.addr;
  45. idSubnetS.address = qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[sel].inet.stat.netMask.addr;
  46. idGateS.address = qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[sel].inet.stat.gateway.addr;
  47. idDnsS1.address = qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[sel].inet.stat.dnsServer[0].addr;
  48. idDnsS2.address = qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[sel].inet.stat.dnsServer[1].addr;
  49. idDnsS3.address = qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[sel].inet.stat.dnsServer[2].addr;
  50. }
  51. }
  52. }
  53. Connections {
  54. target: qGfaAppCtrl.sysInfo.netInterfaceInfo
  55. onIfUpDown: {
  56. console.log("IfUpDown: " + msg);
  57. idIfUpDownText.append(msg.trim());
  58. }
  59. onIfUpDownCompleted: {
  60. switch(ctx)
  61. {
  62. case QNetworkInterfaces.UDC_Start:
  63. console.log("ifup: " + code);
  64. ifUpDownInProgress = false;
  65. break;
  66. case QNetworkInterfaces.UDC_Stop:
  67. console.log("ifdown: " + code);
  68. ifUpDownInProgress = false;
  69. break;
  70. case QNetworkInterfaces.UDC_Restart:
  71. console.log("ifupdown: " + code);
  72. ifUpDownInProgress = false;
  73. break;
  74. }
  75. }
  76. onError: {
  77. console.log("Error: " + msg);
  78. }
  79. }
  80. /////////////////////////////////////////////////////////////////////////////////////////////////
  81. TabBar {
  82. id: idTabBar
  83. width: parent.width
  84. currentIndex: 2
  85. Repeater {
  86. id: idRep
  87. model: Globals.tabBarModel
  88. NavButton {
  89. text: modelData[0]
  90. onClicked: { idPageLoader.source = modelData[1]; }
  91. width: idTabBar.width / idRep.count
  92. }
  93. }
  94. }
  95. /////////////////////////////////////////////////////////////////////////////////////////////////
  96. Ctrl14.TableView {
  97. id: idItfList
  98. height: 420
  99. width: 180
  100. x: 10
  101. y: 50
  102. headerVisible: false
  103. style: TableViewStyle {
  104. itemDelegate: idTableViewItemStyle
  105. }
  106. model: qGfaAppCtrl.sysInfo.netInterfaceInfo.schemaModel
  107. selection.onSelectionChanged:
  108. {
  109. idIfUpDownText.text = "";
  110. updateUI(idItfList.currentRow);
  111. }
  112. Ctrl14.TableViewColumn {
  113. role: "name"
  114. }
  115. }
  116. /////////////////////////////////////////////////////////////////////////////////////////////////
  117. Ctrl14.ExclusiveGroup { id: idMethExGroup }
  118. Rectangle {
  119. id: idMethGroup
  120. x: 200
  121. y: 50
  122. width: 590
  123. height: 45
  124. radius: 5
  125. border.width: 1
  126. border.color: "black"
  127. visible: (idItfList.currentRow > 0)
  128. property int method: (idItfList.currentRow > 0) ? qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow].method : 0
  129. Ctrl14.RadioButton {
  130. x: 10
  131. y: 10
  132. id: idMethStatic
  133. exclusiveGroup: idMethExGroup
  134. style: RadioButtonStyle {
  135. label: Text {
  136. text: qsTr("Static")
  137. font.pointSize: 8
  138. }
  139. }
  140. onClicked: {
  141. if(idItfList.currentRow > 0)
  142. {
  143. if(checked)
  144. {
  145. qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow].method = QInterface.IM_Static;
  146. idStatic.visible = true;
  147. idDhcp.visible = false;
  148. isDirty = true;
  149. }
  150. }
  151. }
  152. }
  153. Ctrl14.RadioButton {
  154. x: 100
  155. y: 10
  156. id: idMethDhcp
  157. exclusiveGroup: idMethExGroup
  158. style: RadioButtonStyle {
  159. label: Text {
  160. text: qsTr("DHCP")
  161. font.pointSize: 8
  162. }
  163. }
  164. onClicked: {
  165. if(idItfList.currentRow > 0)
  166. {
  167. if(checked)
  168. {
  169. qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow].method = QInterface.IM_Dhcp;
  170. idStatic.visible = false;
  171. idDhcp.visible = true;
  172. isDirty = true;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. /////////////////////////////////////////////////////////////////////////////////////////////////
  179. Rectangle {
  180. id: idStatic
  181. x: 200
  182. y: 105
  183. width: 590
  184. height: 115
  185. radius: 5
  186. border.width: 1
  187. border.color: "black"
  188. visible: false
  189. Text {
  190. x: 10
  191. y: 10
  192. font.pointSize: 8
  193. verticalAlignment: Text.AlignVCenter
  194. text: "Address:"
  195. }
  196. Ip4Address {
  197. id: idAddrS
  198. x: 90
  199. y: 10
  200. address: 0
  201. onAddressModified: {
  202. isDirty = true;
  203. console.log("Address modified: " + address);
  204. if(idItfList.currentRow > 0)
  205. qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow].inet.stat.ipAddress.addr = idAddrS.address;
  206. }
  207. }
  208. Text {
  209. x: 10
  210. y: 45
  211. font.pointSize: 8
  212. verticalAlignment: Text.AlignVCenter
  213. text: "Netmask:"
  214. }
  215. Ip4Address {
  216. id: idSubnetS
  217. x: 90
  218. y: 45
  219. address: 0
  220. onAddressModified: {
  221. isDirty = true;
  222. console.log("Netmask modified: " + address);
  223. if(idItfList.currentRow > 0)
  224. qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow].inet.stat.netMask.addr = idSubnetS.address;
  225. }
  226. }
  227. Text {
  228. x: 10
  229. y: 80
  230. font.pointSize: 8
  231. verticalAlignment: Text.AlignVCenter
  232. text: "Gateway:"
  233. }
  234. Ip4Address {
  235. id: idGateS
  236. x: 90
  237. y: 80
  238. address: 0
  239. onAddressModified: {
  240. isDirty = true;
  241. console.log("Gateway modified: " + address);
  242. if(idItfList.currentRow > 0)
  243. qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow].inet.stat.gateway.addr = idGateS.address;
  244. }
  245. }
  246. Text {
  247. x: 330
  248. y: 10
  249. font.pointSize: 8
  250. verticalAlignment: Text.AlignVCenter
  251. text: "DNS 1:"
  252. }
  253. Ip4Address {
  254. id: idDnsS1
  255. x: 390
  256. y: 10
  257. address: 0
  258. onAddressModified: {
  259. isDirty = true;
  260. console.log("DNS 1 modified: " + address);
  261. if(idItfList.currentRow > 0)
  262. qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow].inet.stat.dnsServer[0].addr = idDnsS1.address;
  263. }
  264. }
  265. Text {
  266. x: 330
  267. y: 45
  268. font.pointSize: 8
  269. verticalAlignment: Text.AlignVCenter
  270. text: "DNS 2:"
  271. }
  272. Ip4Address {
  273. id: idDnsS2
  274. x: 390
  275. y: 45
  276. address: 0
  277. onAddressModified: {
  278. isDirty = true;
  279. console.log("DNS 2 modified: " + address);
  280. if(idItfList.currentRow > 0)
  281. qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow].inet.stat.dnsServer[1].addr = idDnsS2.address;
  282. }
  283. }
  284. Text {
  285. x: 330
  286. y: 80
  287. font.pointSize: 8
  288. verticalAlignment: Text.AlignVCenter
  289. text: "DNS 3:"
  290. }
  291. Ip4Address {
  292. id: idDnsS3
  293. x: 390
  294. y: 80
  295. address: 0
  296. onAddressModified: {
  297. isDirty = true;
  298. console.log("DNS 3 modified: " + address);
  299. if(idItfList.currentRow > 0)
  300. qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow].inet.stat.dnsServer[2].addr = idDnsS3.address;
  301. }
  302. }
  303. }
  304. /////////////////////////////////////////////////////////////////////////////////////////////////
  305. Rectangle {
  306. id: idDhcp
  307. x: 200
  308. y: 105
  309. width: 590
  310. height: 115
  311. radius: 5
  312. border.width: 1
  313. border.color: "black"
  314. visible: false
  315. }
  316. /////////////////////////////////////////////////////////////////////////////////////////////////
  317. Rectangle {
  318. id: idIfUpDownOutput
  319. x: 200
  320. y: 230
  321. width: 590
  322. height: 180
  323. visible: false
  324. TextArea {
  325. id: idIfUpDownText
  326. anchors.fill: parent
  327. readOnly: true
  328. selectByMouse: false
  329. selectByKeyboard: false
  330. font.pointSize: 8
  331. }
  332. }
  333. /////////////////////////////////////////////////////////////////////////////////////////////////
  334. Rectangle {
  335. id: idButtons
  336. x: 200
  337. y: 420
  338. width: 590
  339. height: 50
  340. radius: 5
  341. border.width: 1
  342. border.color: "black"
  343. Ctrl14.Button {
  344. x: 10
  345. y: 10
  346. width: 100
  347. text: "Save"
  348. enabled: isDirty && !ifUpDownInProgress
  349. onClicked: {
  350. var itf = qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow];
  351. isDirty = false;
  352. console.log("Save");
  353. qGfaAppCtrl.sysInfo.netInterfaceInfo.save();
  354. }
  355. style: idButtonStyle
  356. }
  357. Ctrl14.Button {
  358. x: 120
  359. y: 10
  360. width: 100
  361. text: "Cancel"
  362. enabled: isDirty && !ifUpDownInProgress
  363. onClicked: {
  364. isDirty = false;
  365. console.log("Cancel");
  366. qGfaAppCtrl.sysInfo.netInterfaceInfo.reload();
  367. updateUI(idItfList.currentRow);
  368. }
  369. style: idButtonStyle
  370. }
  371. Ctrl14.Button {
  372. x: 260
  373. y: 10
  374. width: 100
  375. text: "Start"
  376. enabled: !isDirty && !ifUpDownInProgress && (idItfList.currentRow > 0)
  377. onClicked: {
  378. var itf = qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow];
  379. console.log("Start");
  380. ifUpDownInProgress = true;
  381. idIfUpDownText.text = "";
  382. qGfaAppCtrl.sysInfo.netInterfaceInfo.startInterface(itf);
  383. }
  384. style: idButtonStyle
  385. }
  386. Ctrl14.Button {
  387. x: 370
  388. y: 10
  389. width: 100
  390. text: "Stop"
  391. enabled: !isDirty && !ifUpDownInProgress && (idItfList.currentRow > 0)
  392. onClicked: {
  393. var itf = qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow];
  394. console.log("Stop");
  395. ifUpDownInProgress = true;
  396. idIfUpDownText.text = "";
  397. qGfaAppCtrl.sysInfo.netInterfaceInfo.stopInterface(itf);
  398. }
  399. style: idButtonStyle
  400. }
  401. Ctrl14.Button {
  402. x: 480
  403. y: 10
  404. width: 100
  405. text: "Restart"
  406. enabled: !isDirty && !ifUpDownInProgress && (idItfList.currentRow > 0)
  407. onClicked: {
  408. var itf = qGfaAppCtrl.sysInfo.netInterfaceInfo.interfaces[idItfList.currentRow];
  409. console.log("Restart");
  410. ifUpDownInProgress = true;
  411. idIfUpDownText.text = "";
  412. qGfaAppCtrl.sysInfo.netInterfaceInfo.restartInterface(itf);
  413. }
  414. style: idButtonStyle
  415. }
  416. }
  417. /////////////////////////////////////////////////////////////////////////////////////////////////
  418. InputPanel {
  419. id: inputPanel
  420. z: 99
  421. y: idEdit.height
  422. anchors.left: parent.left
  423. anchors.right: parent.right
  424. states: State {
  425. name: "visible"
  426. when: Qt.inputMethod.visible
  427. PropertyChanges {
  428. target: inputPanel
  429. y: idEdit.height - inputPanel.height
  430. }
  431. }
  432. transitions: Transition {
  433. from: ""
  434. to: "visible"
  435. reversible: true
  436. ParallelAnimation {
  437. NumberAnimation {
  438. properties: "y"
  439. duration: 150
  440. easing.type: Easing.InOutQuad
  441. }
  442. }
  443. }
  444. }
  445. }