Module: ShutdownDialog

Defined in:
lib/shutdown-dialog.rb

Class Method Summary collapse

Class Method Details

.show_windowObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
84
# File 'lib/shutdown-dialog.rb', line 6

def self.show_window
  icon_size = Gtk::IconSize.register('48x48', 48, 48)

  vbox = Gtk::VBox.new(false, 0)
  hbox = Gtk::HBox.new(true, 0)
  vbox1 = Gtk::VBox.new(false, 0)
  vbox2 = Gtk::VBox.new(false, 0)

  logout_button = Gtk::Button.new("Log Out")
  logout_image = Gtk::Image.new('gnome-logout', icon_size)
  logout_button.set_image(logout_image)
  logout_button.signal_connect("clicked") do
    Gtk.main_quit
    system "echo \"awesome.quit()\" | awesome-client"
  end

  reboot_button = Gtk::Button.new("Reboot")
  reboot_image = Gtk::Image.new('gnome-session-reboot', icon_size)
  reboot_button.set_image(reboot_image)
  reboot_button.signal_connect("clicked") do
    Gtk.main_quit
    system "sudo reboot"
  end
  vbox1.pack_end(reboot_button)

  poweroff_button = Gtk::Button.new("Power Off")
  poweroff_image = Gtk::Image.new('gnome-shutdown', icon_size)
  poweroff_button.set_image(poweroff_image)
  poweroff_button.signal_connect("clicked") do
    Gtk.main_quit
    system "sudo poweroff"
  end
  vbox2.pack_end(poweroff_button)

  suspend_button = Gtk::Button.new("Suspend")
  suspend_image = Gtk::Image.new('gnome-session-suspend', icon_size)
  suspend_button.set_image(suspend_image)
  suspend_button.signal_connect("clicked") do
    Gtk.main_quit
    system "sudo pm-suspend"
  end
  vbox1.pack_end(suspend_button)

  hibernate_button = Gtk::Button.new("Hibernate")
  hibernate_image = Gtk::Image.new('gnome-session-hibernate', icon_size)
  hibernate_button.set_image(hibernate_image)
  hibernate_button.signal_connect("clicked") do
    Gtk.main_quit
    system "sudo pm-hibernate"
  end
  vbox2.pack_end(hibernate_button)

  hbox.pack_start(vbox1)
  hbox.pack_start(vbox2)

  vbox.pack_start(logout_button)
  vbox.pack_start(hbox)

  window = Gtk::Window.new
  window.signal_connect("delete_event") { false }

  window.window_position = Gtk::Window::POS_CENTER_ALWAYS

  window.signal_connect("destroy") do
    Gtk.main_quit
  end

  window.border_width = 10

  window.add(vbox)

  window.set_type_hint Gdk::Window::TYPE_HINT_DIALOG
  window.set_default_size 500, 300
  window.set_focus logout_button

  window.show_all

  Gtk.main
end