AddThirdPartyPrinter.qml 4.8 KB

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