Class: SetupWindow

Inherits:
Gtk::Window
  • Object
show all
Defined in:
lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb

Instance Method Summary collapse

Constructor Details

#initializeSetupWindow

Returns a new instance of SetupWindow.



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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb', line 21

def initialize
  super(Gtk::Window::TOPLEVEL)
  self.title = "GtkMUCClient setup"
  signal_connect("delete_event") { cancel }

  vbox = Gtk::VBox.new
  vbox.set_border_width(4)
  add(vbox)
  vbox.show

  frame1 = Gtk::Frame.new('Jabber Account Settings')
  frame1.set_border_width(4)
  frame1.show
  vbox.add(frame1)

  layout1 = Gtk::Table.new(4, 2)
  layout1.row_spacings = 4
  layout1.column_spacings = 8
  layout1.show
  frame1.add(layout1)

  layout1.attach(Gtk::Label.new_show('Jabber ID:'), 0, 1, 1, 2)
  @entry_jid = Gtk::Entry.new
  @entry_jid.text = '[email protected]'
  @entry_jid.show
  layout1.attach(@entry_jid, 1, 2, 1, 2)

  layout1.attach(Gtk::Label.new_show('Password:'), 0, 1, 2, 3)
  @entry_password = Gtk::Entry.new
  @entry_password.visibility = false
  @entry_password.show
  layout1.attach(@entry_password, 1, 2, 2, 3)

  layout1.attach(Gtk::Label.new_show('Resource:'), 0, 1, 3, 4)
  @entry_resource = Gtk::Entry.new
  @entry_resource.text = 'gtkmucclient'
  @entry_resource.show
  layout1.attach(@entry_resource, 1, 2, 3, 4)


  frame2 = Gtk::Frame.new('Multi-User Chat Settings')
  frame2.set_border_width(4)
  frame2.show
  vbox.add(frame2)

  layout2 = Gtk::Table.new(3, 2)
  layout2.row_spacings = 4
  layout2.column_spacings = 8
  layout2.show
  frame2.add(layout2)

  layout2.attach(Gtk::Label.new_show('Room:'), 0, 1, 1, 2)
  @entry_room = Gtk::Entry.new
  @entry_room.text = '[email protected]'
  @entry_room.show
  layout2.attach(@entry_room, 1, 2, 1, 2)

  layout2.attach(Gtk::Label.new_show('Nick:'), 0, 1, 2, 3)
  @entry_nick = Gtk::Entry.new
  @entry_nick.text = 'XMPP4R-Fan'
  @entry_nick.show
  layout2.attach(@entry_nick, 1, 2, 2, 3)


  hbox = Gtk::HBox.new
  hbox.show
  vbox.add(hbox)

  button_ok = Gtk::Button.new("Ok")
  button_ok.set_border_width(4)
  hbox.add(button_ok)
  button_ok.signal_connect("clicked") { ok }
  button_ok.can_default = true
  button_ok.grab_default
  button_ok.show
  button_cancel = Gtk::Button.new("Cancel")
  button_cancel.set_border_width(4)
  hbox.add(button_cancel)
  button_cancel.signal_connect("clicked") { cancel }
  button_cancel.show
end

Instance Method Details

#cancelObject



136
137
138
139
# File 'lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb', line 136

def cancel
  destroy
  Gtk.main_quit
end

#error_dialog(msg) ⇒ Object



103
104
105
106
107
# File 'lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb', line 103

def error_dialog(msg)
  dialog = Gtk::MessageDialog.new(self, Gtk::Dialog::MODAL, Gtk::MessageDialog::ERROR, Gtk::MessageDialog::BUTTONS_OK, msg)
  dialog.signal_connect("response") { dialog.destroy }
  dialog.run
end

#okObject



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
# File 'lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb', line 109

def ok
  jid = Jabber::JID.new(@entry_jid.text)
  mucjid = Jabber::JID.new(@entry_room.text)

  if jid.node.nil?
    error_dialog("Your Jabber ID must contain a user name and therefore contain one @ character.")
  elsif jid.resource
    error_dialog("If you intend to set a custom resource, put that in the right text field. Remove the slash!")
  elsif @entry_resource.text.empty?
    error_dialog("Please set a resource. This is a somewhat unimportant setting...")
  elsif mucjid.node.nil?
    error_dialog("Please set a room name, e.g. [email protected]")
  elsif mucjid.resource
    error_dialog("The MUC room must not contain a resource. Remove the slash!")
  elsif @entry_nick.text.empty?
    error_dialog("Please set a nick for MUC.")
  else
    jid.resource = @entry_resource.text
    mucjid.resource = @entry_nick.text
    password = @entry_password.text

    destroy

    ChatWindow.new(jid, password, mucjid).show
  end
end