AddThirdPartyPrinter.qml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // Copyright (c) 2022 UltiMaker
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import UM 1.5 as UM
  6. import Cura 1.1 as Cura
  7. //
  8. // This component contains the content for the "Add a printer" (network) page of the welcome on-boarding process.
  9. //
  10. Item
  11. {
  12. UM.I18nCatalog { id: catalog; name: "cura" }
  13. property var goToUltimakerPrinter
  14. DropDownWidget
  15. {
  16. id: addNetworkPrinterDropDown
  17. anchors.top: parent.top
  18. anchors.left: parent.left
  19. anchors.right: parent.right
  20. anchors.topMargin: UM.Theme.getSize("wide_margin").height
  21. title: catalog.i18nc("@label", "Add a networked printer")
  22. contentShown: true // by default expand the network printer list
  23. onClicked:
  24. {
  25. addLocalPrinterDropDown.contentShown = !contentShown
  26. }
  27. contentComponent: networkPrinterListComponent
  28. Component
  29. {
  30. id: networkPrinterListComponent
  31. AddNetworkPrinterScrollView
  32. {
  33. id: networkPrinterScrollView
  34. maxItemCountAtOnce: 9 // show at max 9 items at once, otherwise you need to scroll.
  35. onRefreshButtonClicked:
  36. {
  37. UM.OutputDeviceManager.startDiscovery()
  38. }
  39. onAddByIpButtonClicked:
  40. {
  41. base.goToPage("add_printer_by_ip")
  42. }
  43. onAddCloudPrinterButtonClicked:
  44. {
  45. base.goToPage("add_cloud_printers")
  46. if (!Cura.API.account.isLoggedIn)
  47. {
  48. Cura.API.account.login()
  49. }
  50. }
  51. }
  52. }
  53. }
  54. DropDownWidget
  55. {
  56. id: addLocalPrinterDropDown
  57. anchors.top: addNetworkPrinterDropDown.bottom
  58. anchors.left: parent.left
  59. anchors.right: parent.right
  60. anchors.topMargin: UM.Theme.getSize("default_margin").height
  61. title: catalog.i18nc("@label", "Add a non-networked printer")
  62. onClicked:
  63. {
  64. addNetworkPrinterDropDown.contentShown = !contentShown
  65. }
  66. contentComponent: localPrinterListComponent
  67. Component
  68. {
  69. id: localPrinterListComponent
  70. AddLocalPrinterScrollView
  71. {
  72. id: localPrinterView
  73. height: backButton.y - addLocalPrinterDropDown.y - UM.Theme.getSize("expandable_component_content_header").height - UM.Theme.getSize("default_margin").height
  74. }
  75. }
  76. }
  77. Cura.SecondaryButton
  78. {
  79. id: backButton
  80. anchors.left: parent.left
  81. anchors.bottom: parent.bottom
  82. text: catalog.i18nc("@button", "Add UltiMaker printer via Digital Factory")
  83. onClicked: goToUltimakerPrinter()
  84. }
  85. Cura.PrimaryButton
  86. {
  87. id: nextButton
  88. anchors.right: parent.right
  89. anchors.bottom: parent.bottom
  90. enabled:
  91. {
  92. // If the network printer dropdown is expanded, make sure that there is a selected item
  93. if (addNetworkPrinterDropDown.contentShown)
  94. {
  95. return addNetworkPrinterDropDown.contentItem.currentItem != null
  96. }
  97. else
  98. {
  99. // Printer name cannot be empty
  100. const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
  101. const isPrinterNameValid = addLocalPrinterDropDown.contentItem.isPrinterNameValid
  102. return localPrinterItem != null && isPrinterNameValid
  103. }
  104. }
  105. text: base.currentItem.next_page_button_text
  106. onClicked:
  107. {
  108. // Create a network printer or a local printer according to the selection
  109. if (addNetworkPrinterDropDown.contentShown)
  110. {
  111. // Create a network printer
  112. const networkPrinterItem = addNetworkPrinterDropDown.contentItem.currentItem
  113. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(networkPrinterItem)
  114. // After the networked machine has been created, go to the next page
  115. base.showNextPage()
  116. }
  117. else
  118. {
  119. // Create a local printer
  120. const localPrinterItem = addLocalPrinterDropDown.contentItem.currentItem
  121. const printerName = addLocalPrinterDropDown.contentItem.printerName
  122. if(Cura.MachineManager.addMachine(localPrinterItem.id, printerName))
  123. {
  124. base.showNextPage()
  125. }
  126. }
  127. }
  128. }
  129. }