DiscoverUM3Action.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. import UM 1.2 as UM
  2. import Cura 1.0 as Cura
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Layouts 1.1
  6. import QtQuick.Window 2.1
  7. Cura.MachineAction
  8. {
  9. id: base
  10. anchors.fill: parent;
  11. property var selectedPrinter: null
  12. property bool completeProperties: true
  13. property var connectingToPrinter: null
  14. Connections
  15. {
  16. target: dialog ? dialog : null
  17. ignoreUnknownSignals: true
  18. onNextClicked:
  19. {
  20. // Connect to the printer if the MachineAction is currently shown
  21. if(base.parent.wizard == dialog)
  22. {
  23. connectToPrinter();
  24. }
  25. }
  26. }
  27. function connectToPrinter()
  28. {
  29. if(base.selectedPrinter && base.completeProperties)
  30. {
  31. var printerKey = base.selectedPrinter.getKey()
  32. if(connectingToPrinter != printerKey) {
  33. // prevent an infinite loop
  34. connectingToPrinter = printerKey;
  35. manager.setKey(printerKey);
  36. completed();
  37. }
  38. }
  39. }
  40. Column
  41. {
  42. anchors.fill: parent;
  43. id: discoverUM3Action
  44. spacing: UM.Theme.getSize("default_margin").height
  45. SystemPalette { id: palette }
  46. UM.I18nCatalog { id: catalog; name:"cura" }
  47. Label
  48. {
  49. id: pageTitle
  50. width: parent.width
  51. text: catalog.i18nc("@title:window", "Connect to Networked Printer")
  52. wrapMode: Text.WordWrap
  53. font.pointSize: 18
  54. }
  55. Label
  56. {
  57. id: pageDescription
  58. width: parent.width
  59. wrapMode: Text.WordWrap
  60. text: catalog.i18nc("@label", "To print directly to your printer over the network, please make sure your printer is connected to the network using a network cable or by connecting your printer to your WIFI network. If you don't connect Cura with your printer, you can still use a USB drive to transfer g-code files to your printer.\n\nSelect your printer from the list below:")
  61. }
  62. Row
  63. {
  64. spacing: UM.Theme.getSize("default_lining").width
  65. Button
  66. {
  67. id: addButton
  68. text: catalog.i18nc("@action:button", "Add");
  69. onClicked:
  70. {
  71. manualPrinterDialog.showDialog("", "");
  72. }
  73. }
  74. Button
  75. {
  76. id: editButton
  77. text: catalog.i18nc("@action:button", "Edit")
  78. enabled: base.selectedPrinter != null && base.selectedPrinter.getProperty("manual") == "true"
  79. onClicked:
  80. {
  81. manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress);
  82. }
  83. }
  84. Button
  85. {
  86. id: removeButton
  87. text: catalog.i18nc("@action:button", "Remove")
  88. enabled: base.selectedPrinter != null && base.selectedPrinter.getProperty("manual") == "true"
  89. onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress)
  90. }
  91. Button
  92. {
  93. id: rediscoverButton
  94. text: catalog.i18nc("@action:button", "Refresh")
  95. onClicked: manager.restartDiscovery()
  96. }
  97. }
  98. Row
  99. {
  100. id: contentRow
  101. width: parent.width
  102. spacing: UM.Theme.getSize("default_margin").width
  103. Column
  104. {
  105. width: parent.width * 0.5
  106. spacing: UM.Theme.getSize("default_margin").height
  107. ScrollView
  108. {
  109. id: objectListContainer
  110. frameVisible: true
  111. width: parent.width
  112. height: base.height - contentRow.y - discoveryTip.height
  113. Rectangle
  114. {
  115. parent: viewport
  116. anchors.fill: parent
  117. color: palette.light
  118. }
  119. ListView
  120. {
  121. id: listview
  122. model: manager.foundDevices
  123. onModelChanged:
  124. {
  125. var selectedKey = manager.getStoredKey();
  126. for(var i = 0; i < model.length; i++) {
  127. if(model[i].getKey() == selectedKey)
  128. {
  129. currentIndex = i;
  130. return
  131. }
  132. }
  133. currentIndex = -1;
  134. }
  135. width: parent.width
  136. currentIndex: -1
  137. onCurrentIndexChanged:
  138. {
  139. base.selectedPrinter = listview.model[currentIndex];
  140. // Only allow connecting if the printer has responded to API query since the last refresh
  141. base.completeProperties = base.selectedPrinter != null && base.selectedPrinter.getProperty("incomplete") != "true";
  142. }
  143. Component.onCompleted: manager.startDiscovery()
  144. delegate: Rectangle
  145. {
  146. height: childrenRect.height
  147. color: ListView.isCurrentItem ? palette.highlight : index % 2 ? palette.base : palette.alternateBase
  148. width: parent.width
  149. Label
  150. {
  151. anchors.left: parent.left
  152. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  153. anchors.right: parent.right
  154. text: listview.model[index].name
  155. color: parent.ListView.isCurrentItem ? palette.highlightedText : palette.text
  156. elide: Text.ElideRight
  157. }
  158. MouseArea
  159. {
  160. anchors.fill: parent;
  161. onClicked:
  162. {
  163. if(!parent.ListView.isCurrentItem)
  164. {
  165. parent.ListView.view.currentIndex = index;
  166. }
  167. }
  168. }
  169. }
  170. }
  171. }
  172. Label
  173. {
  174. id: discoveryTip
  175. anchors.left: parent.left
  176. anchors.right: parent.right
  177. wrapMode: Text.WordWrap
  178. //: Tips label
  179. //TODO: get actual link from webteam
  180. text: catalog.i18nc("@label", "If your printer is not listed, read the <a href='%1'>network-printing troubleshooting guide</a>").arg("https://ultimaker.com/en/troubleshooting");
  181. onLinkActivated: Qt.openUrlExternally(link)
  182. }
  183. }
  184. Column
  185. {
  186. width: parent.width * 0.5
  187. visible: base.selectedPrinter ? true : false
  188. spacing: UM.Theme.getSize("default_margin").height
  189. Label
  190. {
  191. width: parent.width
  192. wrapMode: Text.WordWrap
  193. text: base.selectedPrinter ? base.selectedPrinter.name : ""
  194. font: UM.Theme.getFont("large")
  195. elide: Text.ElideRight
  196. }
  197. Grid
  198. {
  199. visible: base.completeProperties
  200. width: parent.width
  201. columns: 2
  202. Label
  203. {
  204. width: parent.width * 0.5
  205. wrapMode: Text.WordWrap
  206. text: catalog.i18nc("@label", "Type")
  207. }
  208. Label
  209. {
  210. width: parent.width * 0.5
  211. wrapMode: Text.WordWrap
  212. text:
  213. {
  214. if(base.selectedPrinter)
  215. {
  216. if(base.selectedPrinter.printerType == "ultimaker3")
  217. {
  218. return catalog.i18nc("@label", "Ultimaker 3")
  219. } else if(base.selectedPrinter.printerType == "ultimaker3_extended")
  220. {
  221. return catalog.i18nc("@label", "Ultimaker 3 Extended")
  222. } else
  223. {
  224. return catalog.i18nc("@label", "Unknown") // We have no idea what type it is. Should not happen 'in the field'
  225. }
  226. }
  227. else
  228. {
  229. return ""
  230. }
  231. }
  232. }
  233. Label
  234. {
  235. width: parent.width * 0.5
  236. wrapMode: Text.WordWrap
  237. text: catalog.i18nc("@label", "Firmware version")
  238. }
  239. Label
  240. {
  241. width: parent.width * 0.5
  242. wrapMode: Text.WordWrap
  243. text: base.selectedPrinter ? base.selectedPrinter.firmwareVersion : ""
  244. }
  245. Label
  246. {
  247. width: parent.width * 0.5
  248. wrapMode: Text.WordWrap
  249. text: catalog.i18nc("@label", "Address")
  250. }
  251. Label
  252. {
  253. width: parent.width * 0.5
  254. wrapMode: Text.WordWrap
  255. text: base.selectedPrinter ? base.selectedPrinter.ipAddress : ""
  256. }
  257. }
  258. Label
  259. {
  260. width: parent.width
  261. wrapMode: Text.WordWrap
  262. visible: base.selectedPrinter != null && !base.completeProperties
  263. text: catalog.i18nc("@label", "The printer at this address has not yet responded." )
  264. }
  265. Button
  266. {
  267. text: catalog.i18nc("@action:button", "Connect")
  268. enabled: (base.selectedPrinter && base.completeProperties) ? true : false
  269. onClicked: connectToPrinter()
  270. }
  271. }
  272. }
  273. }
  274. UM.Dialog
  275. {
  276. id: manualPrinterDialog
  277. property string printerKey
  278. property alias addressText: addressField.text
  279. title: catalog.i18nc("@title:window", "Printer Address")
  280. minimumWidth: 400 * Screen.devicePixelRatio
  281. minimumHeight: 120 * Screen.devicePixelRatio
  282. width: minimumWidth
  283. height: minimumHeight
  284. signal showDialog(string key, string address)
  285. onShowDialog:
  286. {
  287. printerKey = key;
  288. addressText = address;
  289. addressField.selectAll();
  290. addressField.focus = true;
  291. manualPrinterDialog.show();
  292. }
  293. onAccepted:
  294. {
  295. manager.setManualPrinter(printerKey, addressText)
  296. }
  297. Column {
  298. anchors.fill: parent
  299. spacing: UM.Theme.getSize("default_margin").height
  300. Label
  301. {
  302. text: catalog.i18nc("@alabel","Enter the IP address or hostname of your printer on the network.")
  303. width: parent.width
  304. wrapMode: Text.WordWrap
  305. }
  306. TextField
  307. {
  308. id: addressField
  309. width: parent.width
  310. maximumLength: 40
  311. validator: RegExpValidator
  312. {
  313. regExp: /[a-zA-Z0-9\.\-\_]*/
  314. }
  315. onAccepted: btnOk.clicked()
  316. }
  317. }
  318. rightButtons: [
  319. Button {
  320. text: catalog.i18nc("@action:button","Cancel")
  321. onClicked:
  322. {
  323. manualPrinterDialog.reject()
  324. manualPrinterDialog.hide()
  325. }
  326. },
  327. Button {
  328. id: btnOk
  329. text: catalog.i18nc("@action:button", "Ok")
  330. onClicked:
  331. {
  332. manualPrinterDialog.accept()
  333. manualPrinterDialog.hide()
  334. }
  335. enabled: manualPrinterDialog.addressText.trim() != ""
  336. isDefault: true
  337. }
  338. ]
  339. }
  340. }