Class: Y2Network::Widgets::AdditionalAddresses

Inherits:
CWM::CustomWidget
  • Object
show all
Defined in:
src/lib/y2network/widgets/additional_addresses.rb

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ AdditionalAddresses

Returns a new instance of AdditionalAddresses.



33
34
35
36
37
# File 'src/lib/y2network/widgets/additional_addresses.rb', line 33

def initialize(settings)
  super()
  textdomain "network"
  @settings = settings
end

Instance Method Details

#contentsObject



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
# File 'src/lib/y2network/widgets/additional_addresses.rb', line 39

def contents
  Frame(
    Id(:additional_addresses),
    # Frame label
    _("Additional Addresses"),
    HBox(
      HSpacing(3),
      VBox(
        # :-) this is a small trick to make ncurses in 80x25 happy :-)
        # it rounds spacing up or down to the nearest integer, 0.5 -> 1, 0.49 -> 0
        VSpacing(0.49),
        Table(
          Id(:address_table),
          Opt(:notify),
          Header(
            # Table header label
            _("Address Label"),
            # Table header label
            _("IP Address"),
            # Table header label
            _("Netmask")
          ),
          []
        ),
        Left(
          HBox(
            # PushButton label
            PushButton(Id(:add_address), _("Ad&d")),
            # PushButton label
            PushButton(Id(:edit_address), Opt(:disabled), _("&Edit")),
            # PushButton label
            PushButton(Id(:delete_address), Opt(:disabled), _("De&lete"))
          )
        ),
        VSpacing(0.49)
      ),
      HSpacing(3)
    )
  )
end

#handle(event) ⇒ Symbol?

Returns dialog result.

Returns:

  • (Symbol, nil)

    dialog result



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
# File 'src/lib/y2network/widgets/additional_addresses.rb', line 128

def handle(event)
  return nil if event["EventReason"] != "Activated"

  cur = Yast::UI.QueryWidget(Id(:address_table), :CurrentItem).to_i
  case event["ID"]
  when :edit_address
    ip_settings = settings_for(cur)
    if Dialogs::AdditionalAddress.new(@settings.name, ip_settings).run == :ok
      @settings.aliases[cur] = ip_settings.to_h
      refresh_table
      Yast::UI.ChangeWidget(Id(:address_table), :CurrentItem, cur)
    end
  when :add_address
    ip_settings = settings_for(nil)
    if Dialogs::AdditionalAddress.new(@settings.name, ip_settings).run == :ok
      @settings.aliases << ip_settings.to_h
      refresh_table
      Yast::UI.ChangeWidget(
        Id(:address_table),
        :CurrentItem,
        @settings.aliases.size - 1
      )
    end
  when :delete_address
    @settings.aliases.delete_at(cur)
    refresh_table
  end

  nil
end

#helpObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'src/lib/y2network/widgets/additional_addresses.rb', line 80

def help
  _(
    "<p><b><big>Additional Addresses</big></b></p>\n" \
    "<p>Configure additional addresses of an interface in this table.</p>\n"
  ) +
    # Aliases dialog help 2/4
    _(
      "<p>Enter an <b>IPv4 Address Label</b>, an <b>IP Address</b>, and\n" \
      "the <b>Netmask</b>.</p>"
    ) +
    # Aliases dialog help 3/4
    _(
      "<p><b>IPv4 Address Label</b>, formerly known as Alias Name, is " \
      "optional and legacy. The total\n" \
      "length of interface name (inclusive of the colon and label) is\n" \
      "limited to 15 characters. The obsolete ifconfig utility truncates " \
      "it after 9 characters.</p>"
    ) +
    # Aliases dialog help 3/4, #83766
    _(
      "<p>Do not include the interface name in the label. For example, " \
      "enter <b>foo</b> instead of <b>eth0:foo</b>.</p>"
    )
end

#initObject



105
106
107
# File 'src/lib/y2network/widgets/additional_addresses.rb', line 105

def init
  refresh_table
end

#refresh_tableObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'src/lib/y2network/widgets/additional_addresses.rb', line 109

def refresh_table
  table_items = @settings.aliases.each_with_index.map do |data, i|
    Item(Id(i), data[:label], data[:ip_address], data[:subnet_prefix])
  end

  Yast::UI.ChangeWidget(Id(:address_table), :Items, table_items)
  Yast::UI.ChangeWidget(
    Id(:edit_address),
    :Enabled,
    !@settings.aliases.empty?
  )
  Yast::UI.ChangeWidget(
    Id(:delete_address),
    :Enabled,
    !@settings.aliases.empty?
  )
end