Module: Yast::PrinterAutoconfigInclude

Defined in:
../../src/include/printer/autoconfig.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) ApplyAutoconfigSettings



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File '../../src/include/printer/autoconfig.rb', line 173

def ApplyAutoconfigSettings
  package_name = "udev-configure-printer"
  if Convert.to_boolean(
      UI.QueryWidget(Id("udev_configure_printer_check_box"), :Value)
    )
    if !Printerlib.TestAndInstallPackage(package_name, "installed")
      Printerlib.TestAndInstallPackage(package_name, "install")
      # There is no "abort" functionality which does a sudden death of the whole module (see dialogs.ycp).
      # Unfortunately when the YaST package installer is run via Printerlib::TestAndInstallPackage
      # it leaves a misused "abort" button labeled "Skip Autorefresh" with WidgetID "`abort"
      # so that this leftover "abort" button must be explicitly hidden here:
      Wizard.HideAbortButton
    end
    if !Printerlib.TestAndInstallPackage(package_name, "installed")
      UI.ChangeWidget(Id("udev_configure_printer_check_box"), :Value, false)
      Popup.Error(_("Failed to install udev-configure-printer."))
      Builtins.y2milestone(
        "ApplyAutoconfigSettings failed to install '%1'",
        package_name
      )
      return false
    end
  else
    if Printerlib.TestAndInstallPackage(package_name, "installed")
      Printerlib.TestAndInstallPackage(package_name, "remove")
    end
    if Printerlib.TestAndInstallPackage(package_name, "installed")
      UI.ChangeWidget(Id("udev_configure_printer_check_box"), :Value, true)
      Popup.Error(_("Failed to remove udev-configure-printer."))
      Builtins.y2milestone(
        "ApplyAutoconfigSettings failed to remove '%1'",
        package_name
      )
      return false
    end
  end
  Builtins.y2milestone("leaving ApplyAutoconfigSettings successfully")
  true
end

- (Object) handleAutoconfig(key, event)



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File '../../src/include/printer/autoconfig.rb', line 213

def handleAutoconfig(key, event)
  event = deep_copy(event)
  Builtins.y2milestone(
    "entering handleAutoconfig with key '%1'\nand event '%2'",
    key,
    event
  )
  if "ValueChanged" == Ops.get_string(event, "EventReason", "")
    if "printer_proposal_check_box" == Ops.get_string(event, "WidgetID", "")
      queues_and_descriptions = ""
      # Call the YaST printer module autoconfig functionality:
      printer_proposal_result = Convert.to_map(
        WFM.CallFunction("printer_proposal", ["MakeProposal"])
      )
      Builtins.y2milestone(
        "handleAutoconfig printer_proposal_result = '%1'",
        printer_proposal_result
      )
      if printer_proposal_result != nil
        queues_and_descriptions_list = Convert.convert(
          Ops.get(printer_proposal_result, "raw_proposal") { [""] },
          :from => "any",
          :to   => "list <string>"
        )
        Builtins.foreach(queues_and_descriptions_list) do |queue_and_description|
          if "" != queue_and_description
            queues_and_descriptions = Ops.add(
              Ops.add(queues_and_descriptions, "\n"),
              queue_and_description
            )
          end
        end
      end
      if "" == queues_and_descriptions
        queues_and_descriptions = _(
          "The automated printer configuration was in vain."
        )
      end
      Popup.AnyMessage(
        _("Automated printer configuration results"),
        # Popup::AnyMessage message:
        queues_and_descriptions
      )
      # Re-set the CheckBox to trigger automatic configuration back to its initial state 'off':
      UI.ChangeWidget(Id("printer_proposal_check_box"), :Value, false)
    end
    if "udev_configure_printer_check_box" ==
        Ops.get_string(event, "WidgetID", "")
      ApplyAutoconfigSettings()
    end
  end
  if "Activated" == Ops.get_string(event, "EventReason", "")
    if :abort == Ops.get(event, "ID") || :cancel == Ops.get(event, "ID") ||
        :back == Ops.get(event, "ID")
      # There is only a "Cancel" functionality (via the "back" button) which goes back one step
      # and the button with the "abort" functionality is not shown at all (see dialogs.ycp).
      # Unfortunately when the YaST package installer is run via Printerlib::TestAndInstallPackage
      # it leaves a misused "abort" button labeled "Skip Autorefresh" with WidgetID "`abort"
      # so that this case is mapped to the "Cancel" functionality:
      return :autoconfig_back
    end
    return :autoconfig_next if :next == Ops.get(event, "ID")
  end
  nil
end

- (Object) initAutoconfig(key)



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File '../../src/include/printer/autoconfig.rb', line 85

def initAutoconfig(key)
  Builtins.y2milestone("entering initAutoconfig with key '%1'", key)
  autoconfig_dialog_is_useless = false
  # The whole Automatic Configuration dialog is useless if it is a "client-only" config.
  # Determine whether or not it is currently a real client-only config
  # (i.e. a ServerName != "localhost/127.0.0.1" in /etc/cups/client.conf)
  # and ignore when it fails (i.e. use the fallback value silently):
  Printerlib.DetermineClientOnly
  if Printerlib.client_only
    if !Popup.YesNoHeadline(
        Builtins.sformat(
          # where %1 will be replaced by the server name:
          _("Disable Remote CUPS Server '%1'"),
          Printerlib.client_conf_server_name
        ), # PopupYesNoHeadline headline
        # PopupYesNoHeadline body:
        _(
          "A remote CUPS server setting conflicts with automatic configuration of printers for the local system."
        )
      )
      autoconfig_dialog_is_useless = true
      Builtins.y2milestone(
        "autoconfig_dialog_is_useless because user decided not to disable client-only CUPS server '%1'",
        Printerlib.client_conf_server_name
      )
    else
      if !Printerlib.ExecuteBashCommand(
          Ops.add(Printerlib.yast_bin_dir, "cups_client_only none")
        )
        Popup.ErrorDetails(
          _(
            "Failed to remove the 'ServerName' entry in /etc/cups/client.conf"
          ),
          Ops.add(
            Ops.add(Ops.get_string(Printerlib.result, "stderr", ""), "\n"),
            Ops.get_string(Printerlib.result, "stdout", "")
          )
        )
        autoconfig_dialog_is_useless = true
        Builtins.y2milestone(
          "autoconfig_dialog_is_useless because it failed to disable client-only CUPS server '%1'",
          Printerlib.client_conf_server_name
        )
      end
    end
  end
  # When it is no "client-only" config,
  # determine whether or not a local cupsd is accessible:
  if !autoconfig_dialog_is_useless
    if !Printerlib.GetAndSetCupsdStatus("")
      if !Printerlib.GetAndSetCupsdStatus("start")
        autoconfig_dialog_is_useless = true
        Builtins.y2milestone(
          "autoconfig_dialog_is_useless because 'rccups start' failed."
        )
      end
    end
  end
  # The CheckBox to trigger an automatic configuration of local connected printers
  # is initially off in any case:
  UI.ChangeWidget(Id("printer_proposal_check_box"), :Value, false)
  # Determine if udev-configure-printer is installed.
  udev_configure_printer_installed = Printerlib.TestAndInstallPackage(
    "udev-configure-printer",
    "installed"
  )
  # Avoid a flickering change of the udev_configure_printer_check_box value
  # by explicite if...else statements which do only one single UI::ChangeWidget
  # instead of a blind default setting which is changed afterwards:
  if udev_configure_printer_installed
    UI.ChangeWidget(Id("udev_configure_printer_check_box"), :Value, true)
  else
    UI.ChangeWidget(Id("udev_configure_printer_check_box"), :Value, false)
  end
  # Disable all widgets in the whole dialog if autoconfig_dialog_is_useless:
  if autoconfig_dialog_is_useless
    UI.ChangeWidget(Id("printer_proposal_check_box"), :Enabled, false)
    UI.ChangeWidget(Id("autoconfig_label"), :Enabled, false)
    UI.ChangeWidget(Id("udev_configure_printer_check_box"), :Enabled, false)
  end
  Builtins.y2milestone(
    "leaving initAutoconfig with udev_configure_printer_installed = '%1'",
    udev_configure_printer_installed
  )

  nil
end

- (Object) initialize_printer_autoconfig(include_target)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File '../../src/include/printer/autoconfig.rb', line 30

def initialize_printer_autoconfig(include_target)
  Yast.import "UI"

  textdomain "printer"

  Yast.import "Printerlib"
  Yast.import "Popup"
  Yast.import "Wizard"

  Yast.include include_target, "printer/helps.rb"

  @widgetAutoconfig = VBox(
    VStretch(),
    Left(
      CheckBox(
        Id("printer_proposal_check_box"),
        Opt(:notify),
        # CheckBox to trigger an automatic configuration of local connected printers
        # by calling the YaST printer module autoconfig functionality right now.
        _("&Do an automatic configuration of local connected printers now"),
        # This trigger CheckBox is initially off in any case:
        false
      ) # CheckBox to let YaST configure local connected printers automatically:
    ),
    # Have space between the two parts of of the dialog:
    VStretch(),
    Left(
      Label(
        Id("autoconfig_label"),
        # Header for a dialog section where the user can
        # specify if USB printers are configured automatically:
        _(
          "Specify if automatic USB printer configuration should happen when plug in"
        )
      )
    ),
    Left(
      CheckBox(
        # Since openSUSE 11.2 cups-autoconfig is no longer available,
        # see https://bugzilla.novell.com/show_bug.cgi?id=526657
        Id("udev_configure_printer_check_box"),
        Opt(:notify),
        # CheckBox for automatic configuration of USB printers
        # by installing or removing the RPM package udev-configure-printer.
        # Do not change or translate "udev-configure-printer", it is a RPM package name.
        _(
          "&Use the package udev-configure-printer for automatic USB printer configuration"
        )
      ) # CheckBox to install or remove udev-configure-printer.
    ),
    # Have space between the content and the bottom of the dialog:
    VStretch()
  ) # Have space between the top of the dialog and the content:
end