Class: ManabuDesktop::Screens::Components::ServerListItem

Inherits:
Object
  • Object
show all
Defined in:
lib/screens/components/server_list_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, user, server, port = 80) ⇒ ServerListItem

Returns a new instance of ServerListItem.



9
10
11
12
13
14
15
16
# File 'lib/screens/components/server_list_item.rb', line 9

def initialize(client, user, server, port = 80)
  @client = client
  @user = user
  @server = server
  @port = port
  super()
  _generate()
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/screens/components/server_list_item.rb', line 7

def client
  @client
end

#labelObject (readonly)

Returns the value of attribute label.



7
8
9
# File 'lib/screens/components/server_list_item.rb', line 7

def label
  @label
end

#list_box_rowObject (readonly)

Returns the value of attribute list_box_row.



7
8
9
# File 'lib/screens/components/server_list_item.rb', line 7

def list_box_row
  @list_box_row
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/screens/components/server_list_item.rb', line 7

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



7
8
9
# File 'lib/screens/components/server_list_item.rb', line 7

def server
  @server
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/screens/components/server_list_item.rb', line 7

def user
  @user
end

Instance Method Details

#_build_ability_menu_lbr(ability) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/screens/components/server_list_item.rb', line 45

def _build_ability_menu_lbr(ability)
  builder = Gtk::Builder.new()
  builder.add_from_file("#{__dir__}/../../../layouts/server_menu_item.glade")
  menu_item = builder.get_object('server_menu_item.ListBoxRow')
  # TODO find the *actual* way to git children by ID
  box = menu_item.children[0]
  box.children[0].set_pixbuf(_get_ability_icon(ability))
  box.children[2].label = I18n.t("g.#{ability.to_s}")
  #menu_item.ability = ability
  #menu_item.signal_connect 'set-focus-child' do |item|
  #  ManabuDesktop::Screens.const_get(ability).new(@client)
  #end
  menu_item
end

#_generateObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/screens/components/server_list_item.rb', line 18

def _generate()
  sib_builder = Gtk::Builder.new()
  sib_builder.add_from_file("#{__dir__}/../../../layouts/server_listbox.glade")
  @list_box_row = sib_builder.get_object('server_instance.ListBoxRow')
  @label = sib_builder.get_object('server_id.Label')
  @label.set_label("#{@user}@#{@server}:#{@port}")
  @menu_button = sib_builder.get_object('server_menu.Button')
  @menu_popover = sib_builder.get_object('server_menu.Popover')
  _populate_menu(sib_builder)
  @list_box_row.show_all()
end

#_get_ability_icon(ability) ⇒ Object



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 'lib/screens/components/server_list_item.rb', line 60

def _get_ability_icon(ability)
  case ability
  when :Toolbox
    pixbuf = GdkPixbuf::Pixbuf.new(
      file: ManabuDesktop::Tools.emojidex.emoji[:hammer_wrench].paths[:png][:px16])
  when :Roster
    pixbuf = GdkPixbuf::Pixbuf.new(
      file: ManabuDesktop::Tools.emojidex.emoji[:student].paths[:png][:px16])
  when :Courses
    pixbuf = GdkPixbuf::Pixbuf.new(
      file: ManabuDesktop::Tools.emojidex.emoji[:notebook].paths[:png][:px16])
  when :Exams
    pixbuf = GdkPixbuf::Pixbuf.new(
      file: ManabuDesktop::Tools.emojidex.emoji[:white_check_mark].paths[:png][:px16])
  when :Administration
    pixbuf = GdkPixbuf::Pixbuf.new(
      file: ManabuDesktop::Tools.emojidex.emoji[:wrench].paths[:png][:px16])
  else
    pixbuf = GdkPixbuf::Pixbuf.new(
      file: ManabuDesktop::Tools.emojidex.emoji[:question].paths[:png][:px16])
  end

  pixbuf
end

#_populate_menu(builder) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/screens/components/server_list_item.rb', line 30

def _populate_menu(builder)
  list_box = builder.get_object('server_menu.ListBox')
  list_box.add(_build_ability_menu_lbr(:Toolbox))
  list_box.add(_build_ability_menu_lbr(:Roster))
  list_box.add(_build_ability_menu_lbr(:Courses))
  list_box.add(_build_ability_menu_lbr(:Exams))
  list_box.add(_build_ability_menu_lbr(:Administration))
  list_box.show_all()

  @menu_button.signal_connect 'clicked' do |button|
    ManabuDesktop::Screens.Toolbox.new(@client)
    @menu_popover.visible = true
  end
end